Solved If in world doesnt work

Discussion in 'Spigot Plugin Development' started by Jaffaaaa, Aug 9, 2018.

Thread Status:
Not open for further replies.
  1. Even if I'm in the world "Mines" it doesnt let me do my event. I get my error "you are not in a mine"
    Code (Java):
    package xyz.theducc.play.TNT;

    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.TNTPrimed;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.util.Vector;

    import net.md_5.bungee.api.ChatColor;

    public class ThrowableTNT implements Listener {

        @EventHandler
        public boolean onInteract(final PlayerInteractEvent event) {
            Player player = event.getPlayer();
            World world = player.getWorld();
            ItemStack item = player.getInventory().getItemInHand();
         
            if (!(player.getLocation().getWorld().equals("Mines"))) {
                player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Ducc" + ChatColor.DARK_RED + "" + ChatColor.BOLD + "TNT >>" + ChatColor.RED + " You are not in a mine.");
                return false;
            }
         
            if (!player.hasPermission("DuccTNT.throw")) {
                player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Ducc" + ChatColor.DARK_RED + "" + ChatColor.BOLD + "TNT >>" + ChatColor.RED + " You do not have permission to do this.");
                return false;
            }
                 
            if ((event.getAction() == Action.RIGHT_CLICK_AIR
                    || event.getAction() == Action.LEFT_CLICK_AIR
                    || event.getAction() == Action.RIGHT_CLICK_BLOCK
                    || event.getAction() == Action.LEFT_CLICK_BLOCK) && item.getType() == Material.TNT) {
                event.setCancelled(true);
                if (item.getAmount() == 1) {
                    player.getInventory().remove(item);
                }
                else {
                    item.setAmount(item.getAmount() - 1);
                }
                @SuppressWarnings({ "unchecked", "rawtypes" })
                TNTPrimed tnt = (TNTPrimed)world.spawn(player.getLocation(), (Class)TNTPrimed.class);
                Vector playerDirection = player.getLocation().getDirection();
                Vector smallerVector = playerDirection.multiply(0.9);
                tnt.setVelocity(smallerVector);
             
                return false;
            }
         
            player.sendMessage("null, contact admin");
        return true;
        }
    }
     
     
  2. Optic_Fusion1

    Resource Staff

    replace .equals("Mines");
    with .getName().equals("Mines");
     
    • Agree Agree x 1
  3. FrostedSnowman

    Resource Staff

    You're comparing the world object with a string.

    Use:

    Code (Java):

    if (!(player.getLocation().getWorld().getName().equals("Mines"))) {
     
    • Like Like x 1
    • Informative Informative x 1
Thread Status:
Not open for further replies.