telekinesis

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

lucky_tho

New Member
Aug 25, 2021
7
0
1
33
How can I make a telekinesis plugin that When I mine a block it goes straight into my inventory?
 
How can I make a telekinesis plugin that When I mine a block it goes straight into my inventory?

Haven't touched Java in a good minute let alone Plugin Development but here's my untested code to do that:

Java:
// https://jd.papermc.io/paper/1.20/org/bukkit/event/block/BlockBreakEvent.html
public void onMine(BlockBreakEvent event) {
    if (true) { // check for telekinesis here
        event.setDropItems(false); // no vanilla drops
        Player player = event.getPlayer(); // player
        PlayerInventory inventory = player.getInventory(); // inventory
        Block block = event.getBlock(); // block
        inventory.addItem(block.getDrops(inventory.getItemInMainHand(), player) // add items to inventory
                .toArray(new ItemStack[0])) // collection to array
                .forEach((remainingItem) -> {
                block.getWorld(block.getLocation(),remainingItem); // natually drops the items that did not fit in the inventory
            });
    }
}

Make sure to turn this into a listener, check Spigot's Event API for that.