Solved Specified Locations

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, Apr 7, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    2008Choco

    I seem to have an issue revolving around locations, and I can't figure it out at all. I will give you all the code I have so far, but really all you need to pay attention to is the PlayerInteractEvent. That's the place I'm having issues with. Everything else is working fine.

    Code:
    package me.choco.arenamanager;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ArenaManager extends JavaPlugin implements Listener{
    
        static World hub = Bukkit.getServer().getWorld("hub");
      
        static Location doomed = new Location(hub, 208, 63, 292);
        static Location ender = new Location(hub, 208, 63, 268);
        static Location frost = new Location(hub, 208, 63, 244);
        static Location bow = new Location(hub, 208, 63, 220);
      
        static Location doomedArena = new Location(hub, 779, 68, 190.5);
        static Location enderArena = new Location(hub, 768.5, 19, 774.5);
        static Location frostArena = new Location(hub, 749.5, 47, 1302.5);
        static Location bowArena = new Location(hub, 859.5, 57, 1792.5);
      
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        }
      
        @Override
        public void onDisable(){
            //Stub
        }
    
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            if (event.getPlayer().getLocation() == doomed && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.doomed.enterDoomed(event.getPlayer());
            }//If hit the doomed pressure plate
          
            if (event.getPlayer().getLocation() == ender && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.ender.enterEnder(event.getPlayer());
            }//If hit the ender pressure plate
          
            if (event.getPlayer().getLocation() == frost && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.frost.enterFrost(event.getPlayer());
            }//If hit the frost pressure plate
          
            if (event.getPlayer().getLocation() == bow && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.bow.enterBow(event.getPlayer());
            }//If hit the bow pressure plate
            else {
                return;
            }//If it's none of the arenas
        }//Close PlayerInteractEvent
      
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event){
            if (event.getInventory().getName().equals(ChatColor.RED + "AWOL Arena Selector")){
                if (event.getCurrentItem().getType() == Material.LAVA_BUCKET && event.getCurrentItem().getItemMeta().hasLore()){
                    me.choco.arenamanager.arenas.doomed.enterDoomed((Player) event.getWhoClicked());
                    event.getWhoClicked().closeInventory();
                    event.setCancelled(true);
                }//Doomed Display Item
                if (event.getCurrentItem().getType() == Material.EYE_OF_ENDER && event.getCurrentItem().getItemMeta().hasLore()){
                    me.choco.arenamanager.arenas.ender.enterEnder((Player) event.getWhoClicked());
                    event.getWhoClicked().closeInventory();
                    event.setCancelled(true);
                }//Ender Display Item
                if (event.getCurrentItem().getType() == Material.ICE && event.getCurrentItem().getItemMeta().hasLore()){
                    me.choco.arenamanager.arenas.frost.enterFrost((Player) event.getWhoClicked());
                    event.getWhoClicked().closeInventory();
                    event.setCancelled(true);
                }//Frost Display Item
                if (event.getCurrentItem().getType() == Material.BOW && event.getCurrentItem().getItemMeta().hasLore()){
                    me.choco.arenamanager.arenas.bow.enterBow((Player) event.getWhoClicked());
                    event.getWhoClicked().closeInventory();
                    event.setCancelled(true);
                }//Bow Display Item
                if (event.getCurrentItem().getType() == Material.WOOL && event.getCurrentItem().getItemMeta().hasLore()){
                    event.getWhoClicked().setHealth(0);
                }//Suicide Button Item
                if (event.getCurrentItem().getType() == null || event.getCurrentItem().getType() == Material.AIR
                        || event.getCurrentItem().getItemMeta().hasLore() == false){
                    event.getWhoClicked().closeInventory();
                    event.getWhoClicked().sendMessage(ChatColor.GOLD + "AWOL " + ChatColor.YELLOW + ">> "
                            + ChatColor.GRAY + "Invalid selection. Not a valid arena");
                }//If its any other inventory item
            }//Close if inventory's name == "AWOL Arena Selector"
        }//Close InventoryClickEvent
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if (commandLabel.equalsIgnoreCase("arenas") || commandLabel.equalsIgnoreCase("arena")){
                Player player = (Player) sender;
                if (args.length == 0){
                    if (player.getWorld().equals(hub)){
                        me.choco.arenamanager.utils.Inventories.arenaGUIWithKill(player);
                        return true;
                    }
                    else{
                        me.choco.arenamanager.utils.Inventories.arenaGUI(player);
                        return true;
                    }
                }//Close if there no arguments
              
                if (args.length == 1){
                    if (args[0].equalsIgnoreCase("doomed") || args[0].equalsIgnoreCase("doomedmountain")
                            || args[0].equalsIgnoreCase("doomed_mountain")){
                        me.choco.arenamanager.arenas.doomed.enterDoomed(player);
                        return true;
                    }//If the argument was "doomed" or "doomedmountain" or "doomed_mountain"
                    if (args[0].equalsIgnoreCase("ender") || args[0].equalsIgnoreCase("enderrun") ||
                            args[0].equalsIgnoreCase("ender_run")){
                        me.choco.arenamanager.arenas.ender.enterEnder(player);
                        return true;
                    }//If the argument was "ender" or "enderrun" or "ender_run"
                    if (args[0].equalsIgnoreCase("frost") || args[0].equalsIgnoreCase("frostbite")){
                        me.choco.arenamanager.arenas.frost.enterFrost(player);
                        return true;
                    }//If the argument was "frost" or "frostbite"
                    if (args[0].equalsIgnoreCase("bow") || args[0].equalsIgnoreCase("bowstrav") ||
                            args[0].equalsIgnoreCase("bowstravaganza")){
                        me.choco.arenamanager.arenas.bow.enterBow(player);
                        return true;
                    }//If the argument was "bow" or "bowstrav" or "bowstravaganza"
                }//If an arena is specified
            }//Close arena command
            return false;
        }//Close commands
    }//Close clas
    
    /* FUTURE IDEAS
    *
    */
    
    /* NEXT VERSION - CHANGELOG
    * Fixed not checking players armour slots before entering the arenas
    * Added selective arena command. If an arena is specified in the /arena command, it will send you there
    * Created a safe guard on the GUI. If the GUI isn't named x, the event won't fire
    * If a player clicks on a slot that isn't an arena item, it closes the inventory and sends them a message
    * Made a different class for the arenas to clean up a bit of code
    * If the player opens the ArenaGUI in the Hub, there will be a Suicide button to escape the arenas
    */
    So basically, what I'm trying to accomplish, is if a player steps on one of the four specified pressure plates, it sends them to a specified location (which I have in another class). The issue is that whenever I step on any of the pressure plates, it sends me to the first arena every time. I know it's an issue with the locations not being exact because you can step on any pressure plate in that world, and it will send you into the first arena.

    I know for sure it's not an issue with the other class that handles the teleportation, because I used it for a GUI as well, which works fine :)

    If anyone could let me know how to specify one exact location? That would be fantastic
     
  2. Offline

    BizarrePlatinum

    I believe you need to use a math helper and have it round the player's location, right now, it will only fire if the player's location is exactly those coordinates. If that's not the problem, are you using the correct Action?
     
  3. Offline

    2008Choco

    @BizarrePlatinum I am checking if a player steps on a Stone Pressure Plate. :p I assumed that was a PHYSICAL action. I had that same thought as well, but found no method to round. I know there's one built into the Java API, but am I really obligated to use that? Is it my only option? There must be a different way

    Edit: I seem to have fixed the teleportation. Instead of testing where the player was, I instead tested for if the event occured where the pressure plate was. Seems to work okay. But there is a new issue. Whenever I click in the air, I get a null pointer exception. New code:
    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            if (event.getClickedBlock().getLocation().getBlockX() == 208
                    && event.getClickedBlock().getLocation().getBlockZ() == 292
                    && event.getClickedBlock().getWorld() == hub
                    && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.doomed.enterDoomed(event.getPlayer());
            }//If hit the doomed pressure plate
           
            else if (event.getClickedBlock().getLocation().getBlockX() == 208
                    && event.getClickedBlock().getLocation().getBlockZ() == 268
                    && event.getClickedBlock().getWorld() == hub
                    && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.ender.enterEnder(event.getPlayer());
            }//If hit the ender pressure plate
           
            else if (event.getClickedBlock().getLocation().getBlockX() == 208
                    && event.getClickedBlock().getLocation().getBlockZ() == 244
                    && event.getClickedBlock().getWorld() == hub
                    && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.frost.enterFrost(event.getPlayer());
            }//If hit the frost pressure plate
           
            else if (event.getClickedBlock().getLocation().getBlockX() == 208
                    && event.getClickedBlock().getLocation().getBlockZ() == 220
                    && event.getClickedBlock().getWorld() == hub
                    && event.getAction() == Action.PHYSICAL){
                me.choco.arenamanager.arenas.bow.enterBow(event.getPlayer());
            }//If hit the bow pressure plate
        }//Close PlayerInteractEvent
     
    Last edited: Apr 7, 2015
  4. Offline

    BizarrePlatinum

    I haven't gone too deep into actions, looking into it, you're using the correct one (gotta rule out all other possibilities). I suppose try getting the block under the player's location instead of the player's location.
     
  5. Offline

    2008Choco

    @BizarrePlatinum Nah I've got all that figured out. The individual pressure plates work now. But the only issue I have existing in the plugin, is when a player punches in the air, a NullPointException occurs, and I'm not sure how to fix it. I've tried putting an else, and if(event.getAction() == Action.LEFT_CLICK_AIR){return}, but neither of them fixed it. Sooo :p I have no idea what's causing it
     
  6. Offline

    BizarrePlatinum

    @2008Choco try checking if the block is not equal to null before testing the locations
     
  7. Offline

    2008Choco

    @BizarrePlatinum Thank you so much for the help! That worked :) I appreciate the help on this one because I was stuck for a while :p <3
     
  8. Locked, upon request.
     
Thread Status:
Not open for further replies.

Share This Page