PlayerMoveEvent help

Discussion in 'Plugin Development' started by mouz_, Nov 16, 2015.

Thread Status:
Not open for further replies.
  1. Hi,

    I'm editing a plugin, some kind of CastleWars. I'm looking for the way to update signs, which are teleporting player to games. I'm trying to do it in PlayerMoveEvent, but it's not working.

    Code:
    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onMovePlayer(final PlayerMoveEvent e) {
            final Player player = e.getPlayer();
            int radius = 5;
            Location loc = player.getLocation();
       
            for(int x = (int) (loc.getX() - radius); x < loc.getX() + radius; x++ ) {
                 for(int y = (int) (loc.getY() - radius); y < loc.getY() + radius; y++ ) {
                     for (int z = (int) (loc.getZ() - radius); z < loc.getZ() + radius; z++ ) {
                         if (player.getWorld().getBlockAt(x, y, z).getType().equals(Material.WALL_SIGN) || player.getWorld().getBlockAt(x, y, z).getType().equals(Material.WALL_SIGN) ) {
                             final FileConfiguration config = this.plugin.getConfig();
                             final List<String> arena = (List<String>)config.getStringList("ArenaList");
                             Sign sign = (Sign) player.getWorld().getBlockAt(x, y, z).getState();
                         
                              if (sign.getLine(0).contains("[Castle]")) {
                                  String map = null;
                                  map = sign.getLine(1);
                                  for (int i = 0; i < this.arenaList.size(); ++i) {
                                      if ((map == null || this.arenaList.get(i).getName().equalsIgnoreCase(map)) && (this.arenaList.get(i).getPlayerList().size() < this.arenaList.get(i).getToStart() || (player.hasPermission("castlewars.vip") && this.arenaList.get(i).getPlayerList().size() < this.arenaList.get(i).getToStart() + 4))) {
                                             sign.setLine(3, "" + ChatColor.WHITE + this.arenaList.get(i).getPlayerList().size() + ChatColor.DARK_GRAY + "/" + ChatColor.WHITE + this.arenaList.get(i).getToStart());
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.DISABLED) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Disabled");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.ERROR) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Error");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.FINISHING) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Finishing");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.INACTIVE) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Inactive");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.INGAME) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Ingame.");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.LOADING) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Loading");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.RESETING) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Reseting");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.STARTING) {
                                                 sign.setLine(2, ChatColor.DARK_RED + "Starting");
                                             }
                                             if (this.arenaList.get(i).getMode() == Arena.GameMode.WAITING) {
                                                 sign.setLine(2, ChatColor.GREEN + "Waiting");
                                             }
                                             sign.update();
                                      }
                                  }
                              }
                         }
                     }
                 }
            }
    Error:
    Code:
    [02:00:42] [Server thread/ERROR]: Could not pass event PlayerMoveEvent to Castle vBeta
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:252) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PacketPlayInFlying.a(SourceFile:137) [cpvpEngine.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PacketPlayInPosition.handle(PacketPlayInPosition.java:35) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:189) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:795) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:643) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:549) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [PaperSpigot.jar:git-PaperSpigot-1f7d532]
    Caused by: java.lang.NullPointerException
        at net.wars.castle.events.MoveEvent.onMovePlayer(MoveEvent.java:85) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[PaperSpigot.jar:git-PaperSpigot-1f7d532]
        ... 13 more
    Do you have any solutions or maybe other ways to do it?
     
    Last edited: Nov 17, 2015
  2. Offline

    Zombie_Striker

  3. Offline

    Scimiguy

    1. Caused by: java.lang.NullPointerException
    2. at net.wars.castle.events.MoveEvent.onMovePlayer(MoveEvent.java:85) ~[?:?]
    That's your problem
     
  4. Solved.
     
    Last edited: Nov 21, 2015
  5. Offline

    Zombie_Striker

  6. Offline

    grrocks

    @Scimiguy How does this go with white space in your IDE? With the line number.
     
  7. Offline

    Scimiguy

    @grrocks
    If you copy and paste the full code from your IDE, then the line number will be represented correctly
    The only things that mess with line numbering is comments (possibly only block comments, I haven't looked into it too much)
     
    grrocks likes this.
  8. Offline

    Xerox262

    You do have permission to edit the plugin, right? Also why not ask the original creator to add the updating signs feature?

    P.S. There's a much better way of doing this that doesn't include player move events
     
  9. I want it now to update every couple seconds, how to do it?
     
  10. Offline

    Zombie_Striker

    @mouz_
    Schedule a repeating task, with a delay of 20 ticks.
     
  11. Offline

    WinX64

    My suggestion to you:

    Code:
    1) Store the sign positions somewhere you can access later.
    2) Schedule a task to be executed every few seconds, the amount is up to you.
    3) Iterate though the sign positions and check if the block in that position is still a sign, continue if they're, remove from the list if not.
    4) Update the sign as you wish to.
     
  12. Offline

    Xerox262

    I still don't get it, why update every few seconds rather than when a state changes? If you done it when the state changed then instead of something checking every second/every few seconds it would just change the sign the instant a state is changed.
     
    Zombie_Striker likes this.
  13. I don't know how to do it.
     
  14. Offline

    Scimiguy

Thread Status:
Not open for further replies.

Share This Page