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.

        @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("") && 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");
    [02:00:42] [Server thread/ERROR]: Could not pass event PlayerMoveEvent to Castle vBeta
        at$1.execute( ~[PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.RegisteredListener.callEvent( ~[PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.SimplePluginManager.fireEvent( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at org.bukkit.plugin.SimplePluginManager.callEvent( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a( [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( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.NetworkManager.a( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.ServerConnection.c( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u( [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at [PaperSpigot.jar:git-PaperSpigot-1f7d532]
        at [PaperSpigot.jar:git-PaperSpigot-1f7d532]
    Caused by: java.lang.NullPointerException
        at ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_60]
        at java.lang.reflect.Method.invoke( ~[?:1.8.0_60]
        at$1.execute( ~[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


  3. Offline


    1. Caused by: java.lang.NullPointerException
    2. at ~[?:?]
    That's your problem
  4. Solved.
    Last edited: Nov 21, 2015
  5. Offline


  6. Offline


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


    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


    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


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


    My suggestion to you:

    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


    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


Thread Status:
Not open for further replies.

Share This Page