can someone who know java help me? :D

Hello, im trying to make plugin where you drop item on black stained glass, the item to be teleported at X: 100, Y: 70, Z: 100, but it doesn't work and i don't know why... can you help me?
7 Replies
Admincraft Meta
Admincraft Meta•2y ago
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
ItzErpandXOP•2y ago
Btw here's the code:
package tridentbox.itzerpandx.itemteleportplugin;

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

public class Itemteleportplugin extends JavaPlugin implements Listener {

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

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

@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (!event.getPlayer().getWorld().getName().equalsIgnoreCase("boxx")) {
return;
}

if (event.getItemDrop().getLocation().getBlock().getType() == Material.BLACK_STAINED_GLASS) {
teleportItem(event.getItemDrop());
}
}

private void teleportItem(org.bukkit.entity.Item item) {
World world = item.getWorld();
Location teleportLocation = new Location(world, 100, 70, 100);
item.teleport(teleportLocation);
}
}
package tridentbox.itzerpandx.itemteleportplugin;

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

public class Itemteleportplugin extends JavaPlugin implements Listener {

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

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

@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (!event.getPlayer().getWorld().getName().equalsIgnoreCase("boxx")) {
return;
}

if (event.getItemDrop().getLocation().getBlock().getType() == Material.BLACK_STAINED_GLASS) {
teleportItem(event.getItemDrop());
}
}

private void teleportItem(org.bukkit.entity.Item item) {
World world = item.getWorld();
Location teleportLocation = new Location(world, 100, 70, 100);
item.teleport(teleportLocation);
}
}
(don't ask why im trying to make that type of plugin :D)
lazycaps
lazycaps•2y ago
you could ask in the spigot discord server, or helpchat not much of a developer myself
luketeam5
luketeam5•2y ago
Isn't the getItemDrop() called for the air as the item is not at the location of the stained glass?
ItzErpandX
ItzErpandXOP•2y ago
i want it to work with any item dropped on the stained glass ;-;
MrMcyeet
MrMcyeet•2y ago
Two things stick out 1) The event is called when the item is dropped, not when it lands (I think, anyway) So unless your head is in a glass block when you drop the item, this wont work to fix that, you could just wait a second or two before running your code (via a bukkit scheduler) - 2) You are checking the block the item is in, not the block below it to fix that, just get the block at the items location, and check the material of the block below it @ItzErpandX
ItzErpandX
ItzErpandXOP•2y ago
I will try, thanks It works thanks 😄

Did you find this page helpful?