Development Assistance Help with Parkour plugin about Events and Config Files

Discussion in 'Plugin Help/Development/Requests' started by The_Nesko, Jul 31, 2015.

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

    The_Nesko

    Hello fellow Bukkiteers i need help with my code so i was hoping you cold help me. :)

    So i want to make a PlayerMoveEvent that gets player's Location and then starts a for loop where it compare the playerLocation and locations from the config file but even tho i get 0 errors it's still dose not displays the message.I don't know if you understood me but here is the code.Any help wold be appreciated. :)


    Here's the code:

    This is the Main Class:
    Code:
    public class Main extends JavaPlugin {
    
        SettingsManager settings = SettingsManager.getInstance();
    
        public void onEnable() {
            settings.setup(this);
            new BlockListener(this);
            }
    
    
        public boolean onCommand(CommandSender sender,Command cmd,String lable,String[] args) {  
      
            if(!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Commands form this plugin are only for Player use!");
                return true;
            }
      
            Player player = (Player) sender;
      
            if (cmd.getName().equalsIgnoreCase("pCreateParkour")) {
          
                if (args.length == 0) {
                    player.sendMessage(ChatColor.RED + "Enter a name of the parkour!");
                    return true;
                } else if (args.length > 1) {
                    player.sendMessage(ChatColor.RED + "You entered too many arguments!");
                    return true;
                }
          
                settings.getData().set("NameTempHolder", args[0]);
                settings.getData().set("ParkourMap." + args[0] + ".x", player.getLocation().getX());
                settings.getData().set("ParkourMap." + args[0] + ".y", player.getLocation().getY());
                settings.getData().set("ParkourMap." + args[0] + ".z", player.getLocation().getZ());
                settings.getData().set("ParkourMap." + args[0] + ".world", player.getLocation().getWorld().getName());
                settings.saveData();
                player.sendMessage(ChatColor.DARK_GREEN + "-----------------------------------------------------");
                player.sendMessage(ChatColor.AQUA + "Now make a sign and type next:");
                player.sendMessage(ChatColor.GOLD + "In line 1 type " + ChatColor.DARK_RED + "'[setJoinSign]' " + ChatColor.GOLD + "without the qoutation marks.");
                player.sendMessage(ChatColor.DARK_GREEN + "-----------------------------------------------------");
               return true;
            }
    
            if (cmd.getName().equalsIgnoreCase("pSetFinish")) {
          
                if (args.length == 0) {
                    player.sendMessage(ChatColor.RED + "Enter a name of the parkour!");
                    return true;
                } else if (args.length > 1) {
                    player.sendMessage(ChatColor.RED + "You entered too many arguments!");
                    return true;
                } else if (settings.getData().getString("ParkourMap." + args[0]) == null) {
                    player.sendMessage(ChatColor.RED + "This parkour map does not exist!");
                    return true;
                }
          
                settings.getData().set("ParkourMap." + args[0] + ".finish.x", player.getLocation().getX());
                settings.getData().set("ParkourMap." + args[0] + ".finish.y", player.getLocation().getY());
                settings.getData().set("ParkourMap." + args[0] + ".finish.z", player.getLocation().getZ());
                settings.getData().set("ParkourMap." + args[0] + ".finish.world",  player.getLocation().getWorld().getName());  
                settings.saveData();
                player.sendMessage(ChatColor.GREEN + "Finish for the parkour " + args[0] + " has been set!");
                return true;
            }
         return false;
         }
    }
    

    This is the BlockListener Class:
    Code:
    public class BlockListener implements Listener {
    
        SettingsManager settings = SettingsManager.getInstance();
        ArrayList<String> parkourNames = new ArrayList<String>();
    
        public void BlockListener(Main plugin) {
            plugin.getServer.getPluginManager.registerEvents(this, plugin);
        }
    
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
            if (e.getLine(0).equalsIgnoreCase("[setJoinSign]")) {
                String name = settings.getData().getString("NameTempHolder");
                e.setLine(0, name );
                e.setLine(2, "§3Click here");
                e.setLine(3, "§3to join the map");
                parkourNames.add(name);
                settings.getData().set("parkourName", parkourNames);
                settings.getData().set("NameTempHolder", null);
                settings.saveData();
                e.getPlayer().sendMessage(ChatColor.GREEN + "Sucsessfuly created new Parkour map!");
            }
      
        }
    
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e) {
            Player player = e.getPlayer();
            Location playerLoc = player.getLocation();
      
            double playerX = playerLoc.getX();
            double playerY = playerLoc.getY();
            double playerZ = playerLoc.getZ();
            World playerWorld = Bukkit.getServer().getWorld(playerLoc.getWorld().getName());
      
            Math.floor(playerX);
            Math.floor(playerY);
            Math.floor(playerZ);
    
            Location playerLocation = new Location(playerWorld, playerX, playerY, playerZ);
      
            for (String names : parkourNames) {
           
                World finishWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMap." +  names + ".finish.world"));
                double finishX = settings.getData().getDouble("ParkourMap." + names + ".finish.x");
                double finishY = settings.getData().getDouble("ParkourMap." + names + ".finish.y");
                double finishZ = settings.getData().getDouble("ParkourMap." + names + ".finish.z");
          
                Math.floor(finishX);
                Math.floor(finishY);
                Math.floor(finishZ);
          
                Location finishLocation = new Location(finishWorld, finishX, finishY, finishZ);
      
               if (playerLocation == finishLocation) {
                   player.sendMessage(ChatColor.GREEN + "Test");
          
                 }
            }
        }
    }
    
     
    Last edited: Aug 1, 2015
  2. Offline

    Boomer

    Code:
    public class BlockListener implements Listener {
    
    SettingsManager settings = SettingsManager.getInstance();
    ArrayList<String> parkourNames = new ArrayList<String>();
    
    public void BlockListenre(Main plugin) {
    plugin.getServer.getPluginManager.registerEvents(this, plugin);
    }
    
    Never happens.
    Your class is BlockListener
    Your constructor is BlockListenre
    You call a new BlockListener(plugin)
    But that constructor does not exist, (which is why its surprising you dont have any errors, or at least warnings in your IDE about that), so I would imagine it is then defaulting to the default constructor, where nothing is executed.

    Please use [co de] and [/co de] tags around your code (minus the spaces)
     
  3. Offline

    The_Nesko

    Actually in my code i wrote it correctly but when i pasted the code here i forgotten to paste the
    Code:
    public void BlockListenre(Main plugin) {
    plugin.getServer.getPluginManager.registerEvents(this, plugin);
    }
    
    so i wrote it i guess i made mistake there but i checked my code and it's written correctly but still i have the same problem.
     
  4. Offline

    Boomer

    What Im getting at is the spelling - one is spelled differently than the other. blocklistenER() vs blocklistenRE()
    You can't possibly copy/ paste into here and have the spelling change into something new, so what you pasted from must have the differential in the spelling.

    Until I'm certain that the origin of the copy/paste was the source of it being misspelled in one part of the post but not the other, I'm sticking with this as being a typo in your code. Your 'clarification post' just now does not convey any confidence that what you have is what you have posted or is not what you posted, or what you meant, etc... If need be, try again, pastebin the entire class modules as two separate pastebins.. something to confirm that if the typo is ONLY as result of posting on this page, and is NOT physically in your plugin... then focus is to shift elsewhere. Right now, focus is still on misspelled classname usage resulting in an empty constructor being used that does NOT call any initialzation/event registration code
     
  5. Offline

    The_Nesko

    No you didn't understood me i pasted the code and made this thread but then when i looked at the thread i saw i forgot to paste in the public void BlockListener(Main plugin) so i edited the thread and wrote it manually i didn't copy it. I apologize if i'm not being completely clear English is not my first language. :)
     
  6. Offline

    Boomer

    Okay, I think I get it - you initially copied the bottom 90% of the code and forgot the 10% at the top, then edited your paste by manually typing this part in... though you did paste the other part of the code above it? Or did you manually type everythign in in the few lines above that as well, and just did the pasting at @EventHandler forward?

    [​IMG]
    Can you please edit your post to put [co de] [/co de] blocks around the blocks of code, so as to preserve the format of the code and be more readable? It looks like having to dig in to find the problem is going to take some effort; it was a rather simple solution if they had been misspelled in you rprogram
     
  7. Offline

    The_Nesko


    I pasted everything except this part:
    Code:
        public void BlockListenre(Main plugin) {
            plugin.getServer.getPluginManager.registerEvents(this, plugin);
            }
    
    I also edited the thread to BlockListener so now that's not the problem and trust me if i was a spelling problem i would not post it here. :)
     
  8. Offline

    Boomer

    Okay, a lot of going back and forth here (and will be easier to read when formatted), its a bit hard to follow the flowpath, but I think that it looks like you have no problems using the commands to create the arena, and set the fnish point for that arena, and create the sign for that arena? I'm actually going to assume there are no problems with that part of the process right now...

    I will also assume you have code somewhere else for those players to click on the sign, and parse the info from it in order to put them into an arena, and into the right place?

    The player move event code is really... a lot. And I mean, a lot of computational work to be performing on every single player-move event on the entire server - no matter if they are in a game or not, you're doing a lot of processing to convert their position coordinates, create new location objects out of that before even checking if the player is a parkour player at all..
    You are then reloading values from the config each and every time that you cycle through the loop of parkour arenas, to create more location objects, to then compare to the player. The player-move-event is a super-high frequency event that will probabably spend 99.8% of its lifetime fired when no one is playing parkour, so a new player that logs onto the server and walks around trying to read any signs you have and such... thousands and thousands and thousands of times over his first couple minutes online, you will be comparing his position to every parkour-game final position, even though he isn't playing a game, or anywhere near the arena...
    Try to think about ways to escape out of the event as soon as possible, with checks that will have incredibly good ability to slice the event into a pool of "defintely not worth doing any more checking on" and "contains the events that need further checking", and then subdivide more out with a second check there if possible reducing those first test fallthroughs to be divided as ' definiely not worth checking any more on THESE conditions...' and 'all the events i want are within here still to be processed'

    Such has finding a way to keep track of who is playing in an arena, so that only this player movements will be checked, and when he is no longer playing the arena, you dont keep track of him anymore.

    Also, cut down on the work that has to be done in the loops in that high frequency process - you are constantly constantly checking the config to pull values out, in order to then create a location object each time. Why not instead prepare a collection of active arenas final-locations as players join them, which has the arena final location already constructed as a location object. Or less involved, just create the list of all arena final locations in a collection fresh each time an arena starts (this makes it redundant process just a handful of times per hour rather than a thousand times per minute).

    And finally - you say you dont get the message in the end there that shows the player matched the final location...
    As you would see from trying to add a broadcastMessage or player sendMessage() message for debugging within the playermoveevent, it will be high-frequency spam, but, you should probabably do it. But I would suggest this approach:

    1) Add a one-time run code in your plugin on-enable process that does the work of this code (you will have to replace the loop code in order to actually get all the parkour entries in the config to loop through, but everything else is the same. Then output the location object toString()
    [​IMG]

    2) Inside your playermoveevent, add an output after
    Location playerLocation = new Location(playerWorld, playerX, playerY, playerZ);
    that displays the playerLocation.toString() as well

    This will let you then be able to compare the location strings (You visually comparing) from the config to the location strings that this convoluted mathematical modification does on the player location. You might see that the difference is the number of decimal points, or that everything is off by a y value of 1, or some other thing. Because you want to compare the location to a location, and I assume you are testing by landing exactly where you want and moving around on it, and see nothing happen - nothing will if the two objects have the same IDEA of what the location is, but do not precisely match exactly the decimal points -- in fact, the different methods may give identical position results, but have different precision values for the rotational components, since a location object also has pitch and yaw, just if not set here, they would be defauled to something (likely zero, but 0 ? 0.0? 0.0000000000 ? 0.00?)
     
    Last edited: Aug 1, 2015
  9. Offline

    The_Nesko


    I'm not sure i completely understood you can you please show me an example ?
     
  10. Offline

    Boomer

    The basic bottom line summary of where to start troubleshooting is to output the location objects that you create from the coordinates from the config, to a string -- and instead of doing that 1000 times a second in the moveventcode, output the results as soon as the plugin starts up so that they are locked away in your server log file to reference.
    Do that by 'copying' the loop you have in the move event (The code that I highlighted in my post) into the onEnable method temporarily (and naturally, at a point after the settings are taken care of)
    Then add a System.err.println(finishLocation.toString()); after the Location finishLocation = .... part

    You then need to modify the loop below, since parkourNames is not populated at this point, and you dont want to mess around with that array at this time - but we do need to replace it with something that gives us a list of parkour names to use. So we change
    Code:
    for (String names: parkourNames) {  
    loop to to use a different collection/array which you grab directly from the config keys themselves. I'm used to using a configuration object, not a settings manager, so this is where you may need to do some exploration for something similar looking to work, but at least you'll have an idea of something to look at the objects and methods available, or be able to google and try...
    Code:
    for(String names : settings.getData().getConfigurationSection("ParkourMap").getKeys(false)){ 
    (Reference to https://bukkit.org/threads/solved-loop-through-yml.73690/ to see how this is supposed to work, to process yml stored data structures as you have, it may just need a different object to work on rather than getData(), etc..

    Once you manage to modify this for-loop code with something that works right, when you run the plugin it should - without any java errors - spit out a bunch of location strings as 'warnings' in your server log, much like this:
    Code:
    [02:20:28 WARN]: Location{world=CraftWorld{name=world},x=123.0,y=45.0,z=567.0,pitch=0.0,yaw=0.0}  
    Once you have successfully done that, you are ready to move onto PART 2

    PART 2:

    At this point in the troubleshooting - datagathering - researching --- what we are wanting to do is research your process by which you are creating location objects from configuration files, and creating other location objects by doing some manipulation of player locations, and comparing those two location objects to each other. If the location objects are exactly the same, then they willl have the exact same toString() outputs. So having started the server with a working Part 1 done, you have a list of strings from your server log representing the finished block locations.
    I would suggest to copy/paste that part of your server log into a text file and saving for the end of this process, and then you can go ahead and remove (rather, comment it out until we're sure you wont need it again) that code you just put in the onEnable in part 1.

    --
    Now, go to the player move event, and this time, comment-out the entire loop code that checks the configuration and builds the locations - just to simplify a process at this time. You want to keep all the code that processes the player posiion and generates a new location for him, but, you will also then output the location object as a string -- you can use a variety of methods to push a string to the screen or logs here, but lets use the same system.err.println() as used in the on-enable part 1 process:
    So the actual code part of your player-move event method should look like the following (I have removed the code that you will comment out, to simplify):
    Code:
     
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e) {
      Player player = e.getPlayer();
      Location playerLoc = player.getLocation();
      double playerX = playerLoc.getX();
      double playerY = playerLoc.getY();
      double playerZ = playerLoc.getZ();
      World playerWorld = Bukkit.getServer().getWorld(playerLoc.getWorld().getName());
      Math.floor(playerX);
      Math.floor(playerY);
      Math.floor(playerZ);
      Location playerLocation = new Location(playerWorld, playerX, playerY, playerZ);
      System.err.println(playerLocation.toString());   
    }
    
    Now, your server log is going to be spammed horrifically but that will just go to show you how often this method gets touched, and why you will need to make an ultimate goal to escape out of this method as soon as possible when you do not NEED to be processing player location data like this for every single movement event thrown on the server.

    But.. your end goal is to get your player into the exact position where you believe that he has reached the spot that SHOULD be the winning, final-location for one of your parkour games. So get him to that location, and once you are there, standing on the spot that should BE the right spot... type something into the chat so it appears in the log, then turn its head left or right a small bit without changing its standing position - that will throw player move events to the log as he rotates, which should hopefully all be the same xyz coordinates still.

    Now, copy the first location string output that occurs after your typed message shows in the log, and paste that into your text document that has the list of strings representing your finalLocation locations from the config.

    Now you have a text file that has string representations of each of your parkour final location objects as you have been building them up from the configuration data...
    ... and a string representation of the location object you have made by 'cleaning up' the player location.

    Identify which of your parkour location strings it should correspond to, and then compare those two strings character y character. Look for any differences between them. Does the one string have 0.0 for pitch and yaw, and the other one have just 0? Does one string have 134.00 for an x coordinate, while the other has 134.0 or 134?

    Compare the two string representations for what should be the SAME LOCATION in the game. If they are perfectly identical, then you have successfully demonstrated that yes, you are able to create matching location objects and in which case, your code SHOULD have worked to compare the two locations and generate the green message.

    If they are NOT perfectly matched, how are they not. What is the nature of the difference, and can you then see a way to modify the creation of either the player location or the location from the configs so as to force the matching (ie, precision of numbers reported). Or is there something wrong with the math and what you believe to be exactly the right spot to stand at is registering as a y-value exactly 1 bigger or lower than the other location y posititon? Or worse, is it shifting your x or z to a block beside it?

    Once you manage to conduct that research and determine the results, determine the source of failure to be due to trying to match two things that never will match as they are, and for what reason, and can then modify things to make both location strings the same
    For example, if your y value is off by one, perhaps its because you defined the target as the solid block to stand on, while your position of the player is in the space above that, so you simply add or subtract 1 from the y value before making its location to compare.

    Once you have your research done, and perhaps even work out what the changes need to be, then it will be possible to move forward and come up with better, enhanced ways to improve the code [ a collection/set of parkour locations populated on-demand as needed rather than constructing n location objects in a loop hundreds of times a second; making a set of active parkour players for rapidly deciding to process or ignore their movements, etc...]


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  11. Offline

    The_Nesko


    About the part 1 i wrote this in my onEnable()

    Code:
    public void onEnable() {
            settings.setup(this);
            new BlockListener(this);
          
            ConfigurationSection parkourNames = settings.getData().getConfigurationSection("ParkourMap");
          
            for (String names : parkourNames.getKeys(false)) {
                
                  World finishWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMap." +  names + ".finish.world"));
                  double finishX = Math.floor(settings.getData().getDouble("ParkourMap." + names + ".finish.x"));
                  double finishY = Math.floor(settings.getData().getDouble("ParkourMap." + names + ".finish.y"));
                  double finishZ = Math.floor(settings.getData().getDouble("ParkourMap." + names + ".finish.z"));
          
                  Location finishLocation = new Location(finishWorld, finishX, finishY, finishZ);
                  System.err.println(finishLocation.toString());
              }
        }
    
    
    This is what i had in my data.yml file:

    Code:
    
    ParkourMap:
      Heaven:
        x: 220.19349216643974
        y: 64.0
        z: -320.42312686278086
        world: world
      Natural:
        x: 220.61145951421003
        y: 64.0
        z: -321.43353292563467
        world: world
      Ice:
        x: 220.45227687147624
        y: 64.0
        z: -322.31556519825955
        world: world
    
    
    And this is what i get when i start the server:

    Code:
    [17:26:16 ERROR]: Error occurred while enabling parkourManager v1.0 (Is it up to
     date?)
    java.lang.IllegalArgumentException: Name cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot_
    server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.getWorld(CraftServer.java:
    1013) ~[spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at me.thenesko.awesomeparkour.Main.onEnable(Main.java:26) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[s
    pigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:340) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:405) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.jav
    a:356) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.
    java:316) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:74
    0) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot_server.jar:git-Spig
    ot-6c9b0a1-de5c261]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    25) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
    r.java:640) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:1162) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :997) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_25]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot_ser
    ver.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    14) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    74) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    53) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :556) [spigot_server.jar:git-Spigot-6c9b0a1-de5c261]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    
    Never mind i'm stupid i forgot to set .finishX, .finishZ... in my config.


    I v'e done part 2 too and i checked the strings they are identical and this is how my PlayerMoveEvent looks now:
    Code:
    @EventHandler
        public void onPlayerMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if (!(inParkour.contains(p.getName()))) return;
           
            if (inParkour.contains(p.getName())) {
               
                double playerX = Math.floor(p.getLocation().getX());
                double playerY = Math.floor(p.getLocation().getY());
                double playerZ = Math.floor(p.getLocation().getZ());
                World playerWorld = Bukkit.getServer().getWorld(p.getLocation().getWorld().getName());
           
                Location playerLocation = new Location(playerWorld, playerX, playerY, playerZ);
                System.err.println(playerLocation.toString());
             
                ConfigurationSection parkourNames = settings.getData().getConfigurationSection("parkourNames");
           
                for (String n : parkourNames.getKeys(false)) {
                               
                   double finishX = settings.getData().getDouble("ParkourMap." + n + ".finish.x");
                   double finishY = settings.getData().getDouble("ParkourMap." + n + ".finish.y");
                   double finishZ = settings.getData().getDouble("ParkourMap." + n + ".finish.z");
                   World finishWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMap." + n + ".finish.world"));
                   
                   Location finishLocation = new Location(finishWorld, finishX, finishY, finishZ);
    
                   p.sendMessage(ChatColor.BLUE + finishLocation.toString());
                   p.sendMessage(ChatColor.RED + playerLocation.toString());
    
                   if (playerLocation.toString() == finishLocation.toString()) {
                        Bukkit.broadcastMessage("Test");
                     
                   }
                }
           }
        }
    
    But even tho String are identical i still don't get the message i also tried changing
    Code:
         p.sendMessage(ChatColor.BLUE + finishLocation.toString());
         p.sendMessage(ChatColor.RED + playerLocation.toString());
    
    to comments so that the spam in the chat would go away but still not message then i changed
    Code:
    if (playerLocation == finishLocation) {
    
    and still nothing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  12. Offline

    Boomer

    This part is technically redundant, because you return if the set does not have the playername - that means, only if the set has the playername, you will continue with the next line of code. 100% of the time. So to then check if the set has the playername you've just now gone redundant and unnecsseary, as well, eliminating if-block wrappers where possible makes it easier to follow the code.
    Code:
            if (!(inParkour.contains(p.getName()))) return;
          
            if (inParkour.contains(p.getName())) {
    
    ====
    Otherwise, I will take your word for it that you are getting identical string representations - and thus even the switching to location strings is a good idea for the troubleshooting... but since you know the strings ARE able to be identical... what could the problem be?

    IF you are seeing alternating red and blue messsages of the locations (and at least one back-to-back pairing matches exactly as they should)... then the problem is in the use of == to compare strings. Try if (string1.equals(string2)) construction for the test cause using strings in tests is a bit trickier...
    The strings were really just for researching any miniscule differences or proving equality can be achieved in your setup, and not that you were off by 1 on the y-axis or a decimal-precision.

    There might be special ways to compare locations - the two may represent the same data, but are not technically teh same object in memory, so may fail such == tests. Trying some tests right now..

    Made two location objects in a test plugin from the same player location.
    The == does not work for them, the .equals does so:

    if (playerLocation.equals(finishLocation) ){ should be true for you

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  13. Offline

    The_Nesko

    I't works finally, thanks for all the help :D
    Here's a diamond [diamond] xD
     
Thread Status:
Not open for further replies.

Share This Page