Compass Event

Discussion in 'Plugin Development' started by icedmoca, Mar 2, 2016.

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


    Can someone post a event for a compass to track the nearest player? if player1 is 4 blocks away and player 2 is 20 blocks away, make it track player1, if player two and one switch spots the compass would track player2.

    I need this as a event handler if you can, Please do not refer me to a plugin!
  2. Offline


  3. Offline


    can you send all the code in a pastebin?
  4. Offline


    Does this mean you're the try of coder that doesn't code? We don't provide code here. Look at this link if you do not understand why.

    If you want someone else to code for you, post in the Plugin Request forum.
  5. Offline


    Look Man, I do code its just I need major help with this: My Compass Plugin Is causing a lot of console errors:

    1:24 [Server] WARN Task #67 for wCompass v1.0 generated an exception
    02.03 23:41:24 [Server] INFO at Source) [?:1.7.0_72]
    02.03 23:41:24 [Server] INFO at [CraftBukkit188.jar:git-Bukkit-e1ebe52]
    02.03 23:41:24 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A( [CraftBukkit188.jar:git-Bukkit-e1ebe52]
    02.03 23:41:24 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B( [CraftBukkit188.jar:git-Bukkit-e1ebe52]
    02.03 23:41:24 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B( [CraftBukkit188.jar:git-Bukkit-e1ebe52]
    02.03 23:41:24 [Server] INFO at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat( [CraftBukkit188.jar:git-Bukkit-e1ebe52]
    02.03 23:41:24 [Server] INFO at ~[CraftBukkit188.jar:git-Bukkit-e1ebe52]
    02.03 23:41:24 [Server] INFO at ~[?:?]
    02.03 23:41:24 [Server] INFO at java.util.ArrayList.get(Unknown Source) ~[?:1.7.0_72]
    02.03 23:41:24 [Server] INFO at java.util.ArrayList.rangeCheck(Unknown Source)

    if (Bukkit.getOnlinePlayers().size() =< 1)
         player.sendMessage("Nope! You're lonely");
    } else
         // Run code
    The class:

    Any Ideas?
  6. Offline


    Try whenever it updates so anywhere you can get like a player join and disconnect.
    Also do it in a method instead of copy and pasting the code in both events opls.

    Or if your doing a mini game thing create a thread off bukkit(schedular bad english sorry) and link to nearest player or whatever.

    To get the nearest player Im sure you can do some cool stuff with vectors.

    Thats my ideas I'll report back when I get any more.
  7. Offline


    Your array that you use is out of range, check the length/size of the array before doing something with a value. Please learn how to read a stacktrace...

    Where don't spoon feed code, please debug the code you already have by checking where the error comes from. This can be done by adding 'System.out.println("Here your debug message");' and adding some values that will be printed in the console.

    Btw, since when is there a 1.8 craftbukkit version available?
  8. Offline


    So can you just tell me where to put a System.out.printin?
  9. There is a 1.8 version of CraftBukkit, however, it was made by Spigot. :p
    Obviously you need to learn Java. This is all so simple to do. (These are all in my personal definition)
    Obviously you don't code if you don't know where to put code. And I'm sorry if this sounds harsh, but it's the truth. At least put some time and effort into learning.
    Lightspeed likes this.
  10. Offline


    Thanks Man!

    Would this work?:

                                              @EventHandler public void onPlayerInteract(PlayerInteractEvent event) {
                                                    if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                                                        if(event.getPlayer().getItemInHand() != null && event.getPlayer().getItemInHand().getType().equals(Material.COMPASS)) {
                                                            Player closest = getNearestPlayer(event.getPlayer());
                                                            if(closest != null) {
                                                                Player player = event.getPlayer();
                                                                event.getPlayer().sendMessage(ChatColor.BOLD + player.getName() + ChatColor.GOLD + " is closest to you!");
                                                            }else {
                                                                event.getPlayer().sendMessage(ChatColor.RED + "No Players Nearby :(");
                                            private Player getNearestPlayer(Player player) {
                                                // TODO Auto-generated method stub
                                                return null;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Mar 3, 2016
  11. Yes, it would, however, you seem to have a bit of code missing to make it fully functional. Maybe do a bit of googling to see how you would get a radius (if that's what you want, of course), and implement that into your code.
Thread Status:
Not open for further replies.

Share This Page