plugin code problem

Hello, im trying to make a plugin where if item falls on black_stained_glass pane to be teleported at x y z but it doesn't work if you drop the item from a high level
7 Replies
Admincraft Meta
Thanks for asking your question!
Make sure to provide as much helpful information as possible such as logs/what you tried and what your exact issue is
Make sure to mark solved when issue is solved!!!
/close !close !solved !answered
Requested by itzerpandx#0
ItzErpandX
ItzErpandXOP2y ago
here is the code:
package tridentbox.itzerpandx.itemteleportplugin;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class Itemteleportplugin extends JavaPlugin implements Listener {

@Override
public void onEnable() {
getLogger().info("ItemTeleportPlugin has been enabled!");
getServer().getPluginManager().registerEvents(this, this);
}

@Override
public void onDisable() {
getLogger().info("ItemTeleportPlugin has been disabled!");
}

@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
final Item droppedItem = event.getItemDrop();
new BukkitRunnable() {
@Override
public void run() {
checkAndTeleport(droppedItem);
}
}.runTaskLater(this, 20L); // Delay for 1 second (20 ticks)
}

private void checkAndTeleport(Item item) {
Location itemLocation = item.getLocation();
Material blockBelowType = itemLocation.getBlock().getRelative(0, -1, 0).getType();

if (blockBelowType == Material.BLACK_STAINED_GLASS) {
teleportItem(item);
}
}

private void teleportItem(Item item) {
World world = item.getWorld();
Location teleportLocation = new Location(world, 183, 92, 8);
item.teleport(teleportLocation);
}
}
package tridentbox.itzerpandx.itemteleportplugin;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class Itemteleportplugin extends JavaPlugin implements Listener {

@Override
public void onEnable() {
getLogger().info("ItemTeleportPlugin has been enabled!");
getServer().getPluginManager().registerEvents(this, this);
}

@Override
public void onDisable() {
getLogger().info("ItemTeleportPlugin has been disabled!");
}

@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
final Item droppedItem = event.getItemDrop();
new BukkitRunnable() {
@Override
public void run() {
checkAndTeleport(droppedItem);
}
}.runTaskLater(this, 20L); // Delay for 1 second (20 ticks)
}

private void checkAndTeleport(Item item) {
Location itemLocation = item.getLocation();
Material blockBelowType = itemLocation.getBlock().getRelative(0, -1, 0).getType();

if (blockBelowType == Material.BLACK_STAINED_GLASS) {
teleportItem(item);
}
}

private void teleportItem(Item item) {
World world = item.getWorld();
Location teleportLocation = new Location(world, 183, 92, 8);
item.teleport(teleportLocation);
}
}
ProGamingDk
ProGamingDk2y ago
is this chatgpt again
ItzErpandX
ItzErpandXOP2y ago
(A little bit modified from me but yeah still xD) so it works fine but if you drop the item from high Y it won't work should i clip it? if you can't understand what do i mean
ItzErpandX
ItzErpandXOP2y ago
ItzErpandX
ItzErpandXOP2y ago
Here is this normal? ;-; alr i will wait ;d
Cooleg
Cooleg2y ago
its because for it to work how chatgpt made it the block below it must be the glass within 1 second of you dropping it so if you are low down it can get there fast enough but if you are high up it takes too long to fall you could just increase the delay if you want to let it take longer

Did you find this page helpful?