Solved Capture the flag handler

Discussion in 'Plugin Development' started by HackintoshMan, Apr 12, 2013.

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

    HackintoshMan

    I am making a capture the flag handler class and the capture points are set by an command. They are stored to the config and they are the location of the player(the block so it is just and int), but Im having trouble comparing the players location to the capture point locations.

    Config:
    Code:
    Capture Points:
      '3':
        X: 1119
        Y: 63
        Z: -7
        World: World
      '2':
        X: 1117
        Y: 63
        Z: -11
        World: World
      '1':
        X: 795
        Y: 66
        Z: -22
        World: World
    Spawn Points:
      Red:
        x: 1110
        y: 63
        z: 0
        yaw: 108.29797
        pitch: 75.59999
        World: World
      Blue:
        x: 1112
        y: 63
        z: 0
        yaw: 217.49805
        pitch: 87.45
        world: World
    
    Code:
    Code:java
    1.  
    2. public class CaptureTheFlagHandler implements Listener {
    3. public int captureTime;
    4. public int X1;
    5. public int X2;
    6. public int X3;
    7. public int Y1;
    8. public int Y2;
    9. public int Y3;
    10. public int Z1;
    11. public int Z2;
    12. public int Z3;
    13. public World world1;
    14. public World world2;
    15. public World world3;
    16. Location p1 = new Location(world1, X1, Y1, Z1);
    17. Location p2 = new Location(world2, X2, Y2, Z2);
    18. Location p3 = new Location(world1, X3, Y3, Z3);
    19. public boolean hasBeenCaptured1 = false;
    20. public boolean hasBeenCaptured2 = false;
    21. public boolean hasBeenCaptured3 = false;
    22.  
    23. private String PREFIX = ChatColor.GREEN + "[WarFighter] ";
    24. private WarFighter plugin;
    25.  
    26. public CaptureTheFlagHandler(WarFighter plugin) {
    27. this.plugin = plugin;
    28. }
    29.  
    30. public void getPointOneLocation(){
    31. X1 = plugin.getConfig().getInt(
    32. "Capture Points.1.X");
    33. Y1 = plugin.getConfig()
    34. .getInt("Capture Points.1.Y");
    35. Z1 = plugin.getConfig()
    36. .getInt("Capture Points.1.Z");
    37. world1 = Bukkit.getWorld(
    38. "Capture Points.1.World");
    39. }
    40.  
    41. public void getPointTwoLocation(){
    42. X2 = plugin.getConfig().getInt(
    43. "Capture Points.2.X");
    44. Y2 = plugin.getConfig()
    45. .getInt("Capture Points.2.Y");
    46. Z2 = plugin.getConfig()
    47. .getInt("Capture Points.2.Z");
    48. world2 = Bukkit.getWorld(
    49. "Capture Points.2.World");
    50. }
    51.  
    52. public void getPointThreeLocation(){
    53. X3 = plugin.getConfig().getInt(
    54. "Capture Points.3.X");
    55. Y3 = plugin.getConfig()
    56. .getInt("Capture Points.3.Y");
    57. Z3 = plugin.getConfig()
    58. .getInt("Capture Points.3.Z");
    59. world3 = Bukkit.getWorld(
    60. "Capture Points.3.World");
    61. }
    62.  
    63. @EventHandler(priority = EventPriority.MONITOR)
    64. public void onPlayerMove(PlayerMoveEvent event) {
    65. Player player = event.getPlayer();
    66. if (player.getLocation().equals(p1)) {
    67. System.out.println("Player location = point location!");
    68. if (WarFighter.blue.contains(player)) {
    69. System.out.println("Player = blue team!");
    70. if (hasBeenCaptured2 == false && hasBeenCaptured3 == false) {
    71. // timer start
    72. Bukkit.broadcastMessage(PREFIX + player
    73. + " is capturing point 1!");
    74. if (captureTime == 0) {
    75. Bukkit.broadcastMessage(PREFIX + player
    76. + " has captured point 1!");
    77. hasBeenCaptured1 = true;
    78. }
    79. if (p1 =! player.getLocation()) {
    80. //timer reset
    81. Bukkit.broadcastMessage(PREFIX + player
    82. + " has lost control of point 1!");
    83. }
    84. } else {
    85. player.sendMessage(PREFIX
    86. + "You must capture point 1!");
    87. }
    88. } else {
    89. player.sendMessage(PREFIX
    90. + "This is your own point! try to defend this point.");
    91. }
    92. }
    93. /*if (player.getLocation() == p2) {
    94. // timer start
    95. if (player.getLocation() == p2) {
    96. // timer reset
    97. }
    98. }
    99. if (player.getLocation() == p3) {
    100. // timer start
    101. if (player.getLocation() == p3) {
    102. // timer reset
    103. }
    104. }*/
    105. }
    106. }
    107. [/syntax=java]
     
  2. Try this:
    int tolerance = 1.1; //the tolerance between being valid or not
    Location check=(player location);
    Location flag=(use for() to work this out);
    If(check.getX() > (flag.getX()-tolerance) && check.getX < (flag.getX()+tolerance) && check.getZ() > (flag.getZ()-tolerance) && check.getZ() < (flag.getZ()+tolerance)){ //x and z are valid. If y needed then just do the same again!
    //code to be executed
    }
    Hope this helps :D
     
    HackintoshMan likes this.
  3. Offline

    HackintoshMan

    I don't need the tolerance…The capture point is the block position(25,85,69) not (25.6549613, 85.6513, 69.68463)
     
  4. Well I then fail to see the point in this thread because you can easily just compare the x, y and z using the == function. (Not === - exactly equal).

    Look at how i made a ctf game for my friends server (minecraftmg.com) https://github.com/storm345/ac/tree/master/src/com/amazar. Feel free to copy. The code is on MinigameUpdateEvent in the listener.


    Btw .equals() is checking if the object is the same. -which will never return true! You need to compare x,y and z. Then if its player location you need tolerances.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  5. There's a significant diference when you mix entity locations with block locations...

    Block locations are a block space, yes, but when you, for example, teleport an entity to that location, the entity will be in the corner of the block.

    So basically a block's location is between X/Y/Z and X+1/Y+1/Z+1 for entities, so you basically need to make a small cuboid of 2 locations and check if player is in between them.

    storm345(forums)
    Proper implementation of equals() suggests that it compares values, which should give you proper results, if equals() is not implemented for that object, only then it isn't reliable.
     
    HackintoshMan likes this.
  6. Indeed, however when i have worked with locations .equals() doesnt work reliably.
     
  7. storm345(forums)
    Because for Location it checks for absolute equality, yes, but the way you put it sounded like '==' comparator :p
     
  8. Anyway... Back to the question... He (or she) should probably use a little tolerance check (like i did earlier) to check if they are in the boundary (you mentioned earlier). Then if so execute the code!
     
  9. Offline

    HackintoshMan

    well i have runs some tests…debug messages… and I have found that my error lies in getting the coordinates from the config file. When I set the XYZ values manually in the if statement it worked perfectly, so now every time a player moves it displayed the X1 values…which is supposed to be the one from the config. but every time it outputs 0…I don't understand what is wrong with
    Code:
    X1 = plugin.getConfig().getInt("Capture Points.1.X");
    Code:
    Capture Points:
      '3':
        X: 1119
        Y: 63
        Z: -7
        World: World
      '2':
        X: 1117
        Y: 63
        Z: -11
        World: World
      '1':
        X: 795
        Y: 66
        Z: -22
        World: World
    I am still stumped as to why
    Code:
    X1 = plugin.getConfig().getInt("Capture Points.1.X");
    returns the value of zero when it should return 795
    Code:
    Capture Points:
      '3':
        X: 1119
        Y: 63
        Z: -7
        World: World
      '2':
        X: 1117
        Y: 63
        Z: -11
        World: World
      '1':
        X: 795
        Y: 66
        Z: -22
        World: World
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  10. You have a space imbetween capture and points. -not sure if it matters... But... Maybe try without space...?
     
  11. Offline

    HackintoshMan

    Thats not it. When i set those variables it works fine with that string path.
     
  12. Are you calling saveConfig() after you generate it? (Probably are). Also possibly check the case(upper or lower)? Its basically just spot the error.... Do the others (not x) return correctly?
     
  13. Most likely the path is invalid with getting... try using cp1 instead of just 1, maybe that's the issue.
     
  14. Offline

    HackintoshMan

    Ok I will try this out. Does it not like the numerical values?
     
  15. The numeric values may confuse the type that the key is being read as (string/int)
     
  16. Offline

    HackintoshMan

    Ok I will try this in a moment and let you guys know if it works. Also, on the player move event I have the console get the value from that path and I get this error…a NPE

    Code:
    [SEVERE] Could not pass event PlayerMoveEvent to WarFighter v1.2
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:220)
        at net.minecraft.server.v1_5_R2.Packet10Flying.handle(SourceFile:136)
        at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:113)
        at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:580)
        at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
        at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:476)
        at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:409)
        at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at de.mrpixeldream.bukkit.tdm.CaptureTheFlagHandler.onPlayerMove(CaptureTheFlagHandler.java:77)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 14 more
    
     
  17. Whats on listener line 77? Please can we see all the new listener code and config generation? (With line numbers would be great)
     
  18. Offline

    HackintoshMan

    Line 77 is the first System.out…. and I get 4 NPE's, one for each getConfig() line

    Code:
    @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            System.out.println(plugin.getConfig().getInt(
                    "Capture Points.1.X"));
            System.out.println(plugin.getConfig().getInt(
                    "Capture Points.1.Y"));
            System.out.println(plugin.getConfig().getInt(
                    "Capture Points.1.Z"));
            System.out.println(plugin.getConfig().getString(
                    "Capture Points.1.World"));
            if (player.getLocation().getBlockX() == X1){
                System.out.println("Player location = point location!");
                if (WarFighter.blue.contains(player.getName())) {
                    System.out.println("Player = blue team!");
                    if (hasBeenCaptured1 == false && hasBeenCaptured2 == false && hasBeenCaptured3 == false) {
                        // timer start
                        Bukkit.broadcastMessage(PREFIX + player
                                + " is capturing point 1!");
    config:
    Code:
    Capture Points:
      '3':
        X: 1119
        Y: 63
        Z: -7
        World: World
      '2':
        X: 1117
        Y: 63
        Z: -11
        World: World
      '1':
        X: 795
        Y: 66
        Z: -22
        World: World
     
  19. That means that the config.get method(s) are returning null. Maybe save a variable config as opposed to getConfig everytime (not the problem but a performance suggestion) and try renaming the keys so they arent just numbers. Aka locX, locY, etc...
     
  20. Offline

    HackintoshMan

    I have 3 methods and 12 variables. The first method gets the first point XYZ and World values from the config. And the other 2 do the same except for points 2 and 3. I have X1 X2 X3 and so on so that it loads the variables from the config. But all along those variables were zero because I just found out that the config is returning null.

    I have debugged more. I changed the config to
    Code:
    General:
      friendly_fire: false
    CapturePoints:
      Point1:
        LocX: 833
        LocY: 66
        LocZ: 801
        World: World
      Point2:
        LocX: 826
        LocY: 73
        LocZ: 836
        World: World
      Point3:
        LocX: 828
        LocY: 73
        LocZ: 828
        World: World
    
    I got rid of the spaces and changed names. When I display the values of X1 Y1 Z1 and world1, (X1 = LocX, ect.) It displays 0,0,0,null (X1,Y1,Z1,world1) What is the problem?!?!?!?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  21. No, that's not what it means, using null values is perfectly fine unless you try to use methods on them, since 'null.method()' can't happen you get a NPE.

    HackintoshMan
    A NPE is when you call a method or variable on a pointer that is not asigned or asigned to null...
    In that code, most likely your 'plugin' field is null and when you're using plugin.getConfig() it throws the NPE.

    getConfig() throws a diferent exception if it doesn't function properly.

    You should post your entire class where you've debugged because apparently you're doing something wrong since it can't find the values.
     
  22. Offline

    HackintoshMan

    is the plugin instance incorrect here?
    Code:
    public CaptureTheFlagHandler(MCFTF2 plugin) {
            this.plugin = plugin;
        }
     
  23. That seems correct, maybe you're doing something else wrong, I can't know what that is from snippets.

    I suggest you add this in your event or something to see where the problem really is:
    Code:
    System.out.print("plugin = " + plugin);
    System.out.print("plugin.getConfig() = " + plugin.getConfig());
    
    If it prints 'plugin = null' you should post your entire class.
    But if it prints 'plugin.getConfig() = null' then your 'plugin' variable is not your main class, but I doubt that's the case since it should throw a diferent error instead of returning null...
     
  24. Offline

    HackintoshMan

    Digi

    Code:
    [INFO] plugin = null
    19:53:00 [SEVERE] Could not pass event PlayerMoveEvent to MCFTF2 v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:220)
        at net.minecraft.server.v1_5_R2.Packet10Flying.handle(SourceFile:136)
        at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:113)
        at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:580)
        at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
        at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:476)
        at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:409)
        at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at com.hackintoshman.mcftf2.CaptureTheFlagHandler.onPlayerMove(CaptureTheFlagHandler.java:46)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 14 more
    
    Code:
    package com.hackintoshman.mcftf2;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
     
    import com.hackintoshman.mcftf2.MCFTF2;
     
    public class CaptureTheFlagHandler implements Listener {
        public int captureTime;
        public int X1;
        public int X2;
        public int X3;
        public int Y1;
        public int Y2;
        public int Y3;
        public int Z1;
        public int Z2;
        public int Z3;
        public String world1;
        public String world2;
        public String world3;
        public boolean hasBeenCaptured1 = false;
        public boolean hasBeenCaptured2 = false;
        public boolean hasBeenCaptured3 = false;
     
        private MCFTF2 plugin;
     
        public CaptureTheFlagHandler(MCFTF2 plugin) {
            this.plugin = plugin;
        }
     
        public void getPointOneLocation(){
            X1 = plugin.getConfig().getInt("CapturePoints.Point1.LocX");
            Y1 = plugin.getConfig().getInt("CapturePoints.Point1.LocY");
            Z1 = plugin.getConfig().getInt("CapturePoints.Point1.LocZ");
            world1 = plugin.getConfig().getString("CapturePoints.Loc1.World");
        }
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            System.out.print("plugin = " + plugin);
            System.out.print("plugin.getConfig() = " + plugin.getConfig());
            if (player.getLocation().getBlockX() == X1 && player.getLocation().getBlockY() == Y1 && player.getLocation().getBlockZ() == Z1 && player.getLocation().getWorld().getName().equals(world1)){
                System.out.println("Player location = point location!");
                if (MCFTF2.blue.contains(player.getName())) {
                    System.out.println("Player = blue team!");
                    if (hasBeenCaptured1 == false && hasBeenCaptured2 == false && hasBeenCaptured3 == false) {
                        // timer start
                        Bukkit.broadcastMessage(plugin.PREFIX + player
                                + " is capturing point 1!");
                        if (captureTime == 0) {
                            Bukkit.broadcastMessage(plugin.PREFIX + player
                                    + " has captured point 1!");
                            hasBeenCaptured1 = true;
                        }
                        if (X1 == 8) {
                            Bukkit.broadcastMessage(plugin.PREFIX + player
                                    + " has lost control of point 1!");
                        }
                    } else {
                        player.sendMessage(plugin.PREFIX
                                + "You must capture point 1!");
                    }
                } else {
                    player.sendMessage(plugin.PREFIX
                            + "This is your own point! try to defend this point.");
                }
            }
        }
    }
    
     
  25. Hmm, and where do you create an instance of that class ? Because the class looks fine, you must be parsing 'null' into the constructor.
     
  26. Offline

    HackintoshMan

    Digi
    I don't think that I create an instance of the class. How would I do that?

    Should
    Code:
    private MCFTF2 plugin;
    be
    Code:
    public MCFTF2 plugin;
    ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  27. HackintoshMan
    How are you even using it if you didn't create an instance of it ?

    You must've created an instance if you registered the event on it... post your main class then.

    That field is good as private, you'd have compile errors (instead of runtime exceptions) if you're trying to access a private field from another class, which means your IDE would highlight it as red.
     
  28. Offline

    HackintoshMan

    Ok, here is the main class. I have registered the event in the onEnable() method.

    Code:java
    1.  
    2. package com.hackintoshman.mcftf2;
    3.  
    4. import com.hackintoshman.mcftf2.commands.*;
    5.  
    6. import java.io.File;
    7. import java.util.ArrayList;
    8. import java.util.HashMap;
    9. import java.util.LinkedList;
    10.  
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.entity.Entity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.PlayerDeathEvent;
    17. import org.bukkit.event.player.PlayerJoinEvent;
    18. import org.bukkit.event.player.PlayerQuitEvent;
    19. import org.bukkit.event.player.PlayerRespawnEvent;
    20. import org.bukkit.inventory.ItemStack;
    21. import org.bukkit.plugin.java.JavaPlugin;
    22.  
    23. public class MCFTF2 extends JavaPlugin implements Listener {
    24.  
    25. public String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[MCFTF2] " + ChatColor.AQUA;
    26. public static LinkedList<Entity> red;
    27. public static LinkedList<Entity> blue;
    28. public static ArrayList<Entity> dead;
    29. public static ArrayList<Integer> respawn_left;
    30. public static HashMap<Player, Integer> scores;
    31. public static HashMap<Player, Integer> deaths;
    32. public int redScore;
    33. public int blueScore;
    34. public boolean isCTF;
    35.  
    36. public void onEnable() {
    37. System.out.println(PREFIX + "Enabling MCFTF2...");
    38.  
    39. red = new LinkedList<Entity>();
    40. blue = new LinkedList<Entity>();
    41.  
    42. dead = new ArrayList<Entity>();
    43. respawn_left = new ArrayList<Integer>();
    44.  
    45. scores = new HashMap<Player, Integer>();
    46. deaths = new HashMap<Player, Integer>();
    47.  
    48. System.out.println(PREFIX + "Loading config...");
    49.  
    50. loadConfig();
    51.  
    52. System.out.println(PREFIX + "Registering events...");
    53.  
    54. getCommand("kd").setExecutor(new CommandKD(this));
    55. getCommand("ratio").setExecutor(new CommandKD(this));
    56. getCommand("stats").setExecutor(new CommandStats(this));
    57. getCommand("team").setExecutor(new CommandTeam(this));
    58. getCommand("setpoint").setExecutor(new CommandSetPoints(this));
    59. getServer().getPluginManager().registerEvents(this,this);
    60. getServer().getPluginManager().registerEvents(new CaptureTheFlagHandler(null), this);
    61.  
    62. System.out.println(PREFIX + "Events successfully registered!");
    63. System.out.println(PREFIX + "Thanks for using MCFTF2!");
    64. }
    65.  
    66. public void onDisable() {
    67. System.out.println(PREFIX + "Disabling MCFTF2...");
    68.  
    69. System.out.println(PREFIX + "MCFTF2 succesfully disabled!");
    70. System.out.println(PREFIX + "Thanks for using!");
    71. saveConfig();
    72. }
    73.  
    74. public void loadConfig() {
    75. boolean configFileExistant = false;
    76.  
    77. if (new File("plugins/MCFTF2/").exists()) {
    78. configFileExistant = true;
    79. }
    80.  
    81. getConfig().options().copyDefaults(true);
    82.  
    83. if (!configFileExistant) {
    84. getConfig().addDefault("General.friendly_fire",
    85. Boolean.valueOf(false));
    86.  
    87. }
    88.  
    89. saveConfig();
    90. }
    91.  
    92. @EventHandler
    93. public void onPlayerJoin(PlayerJoinEvent e) {
    94. String player_display_name = e.getPlayer().getDisplayName();
    95.  
    96. if (red.size() > blue.size()) {
    97. e.setJoinMessage(this.PREFIX + ChatColor.BLUE
    98. + e.getPlayer().getName() + ChatColor.GOLD
    99. + " joined the game!");
    100.  
    101. blue.add(e.getPlayer());
    102. e.getPlayer().sendMessage(
    103. this.PREFIX + ChatColor.BLUE + "You joined team blue!");
    104. e.getPlayer().getInventory()
    105. .setHelmet(new ItemStack(35, 1, (short) 11));
    106.  
    107. e.getPlayer().setDisplayName(ChatColor.BLUE + player_display_name);
    108. } else {
    109. e.setJoinMessage(this.PREFIX + ChatColor.RED
    110. + e.getPlayer().getName() + ChatColor.GOLD
    111. + " joined the game!");
    112.  
    113. red.add(e.getPlayer());
    114. e.getPlayer().sendMessage(
    115. this.PREFIX + ChatColor.RED + "You joined team red!");
    116. e.getPlayer().getInventory()
    117. .setHelmet(new ItemStack(35, 1, (short) 14));
    118.  
    119. e.getPlayer().setDisplayName(ChatColor.RED + player_display_name);
    120. }
    121.  
    122. e.getPlayer().sendMessage(
    123. this.PREFIX + ChatColor.AQUA + "Have fun and good luck!");
    124. }
    125.  
    126. @EventHandler
    127. public void onPlayerQuit(PlayerQuitEvent e) {
    128. if (red.contains(e.getPlayer())) {
    129. e.setQuitMessage(this.PREFIX + ChatColor.RED
    130. + e.getPlayer().getName() + ChatColor.GOLD
    131. + " left the game!");
    132. } else {
    133. e.setQuitMessage(this.PREFIX + ChatColor.BLUE
    134. + e.getPlayer().getName() + ChatColor.GOLD
    135. + " left the game!");
    136. }
    137.  
    138. if (blue.contains(e.getPlayer())) {
    139. blue.remove(e.getPlayer());
    140. } else {
    141. red.remove(e.getPlayer());
    142. }
    143.  
    144. saveConfig();
    145.  
    146. }
    147.  
    148. @EventHandler
    149. public void onPlayerKilled(PlayerDeathEvent e) {
    150. Player killed = e.getEntity();
    151. String killed_name = killed.getName();
    152.  
    153. dead.add(killed);
    154. respawn_left.add(Integer.valueOf(0));
    155.  
    156. if (red.contains(killed.getKiller())) {
    157. redScore++;
    158. e.setDeathMessage(this.PREFIX + ChatColor.RED
    159. + "Red team scored one point!");
    160. getServer().broadcastMessage(
    161. this.PREFIX + ChatColor.RED
    162. + e.getEntity().getKiller().getName() + " killed "
    163. + killed_name + " with "
    164. + killed.getKiller().getItemInHand().getType());
    165. } else {
    166. blueScore++;
    167. e.setDeathMessage(this.PREFIX + ChatColor.BLUE
    168. + "Blue team scored one point!");
    169. getServer().broadcastMessage(
    170. this.PREFIX + ChatColor.BLUE
    171. + e.getEntity().getKiller().getName() + " killed "
    172. + killed_name + " with "
    173. + killed.getKiller().getItemInHand().getType());
    174. }
    175.  
    176. saveConfig();
    177. e.getDrops().clear();
    178. }
    179.  
    180. public void gameWin() {
    181.  
    182. }
    183.  
    184. @EventHandler
    185. public void onPlayerRespawn(PlayerRespawnEvent e) {
    186. if (red.contains(e.getPlayer())) {
    187. e.getPlayer().getInventory()
    188. .setHelmet(new ItemStack(35, 1, (short) 14));
    189. } else {
    190. e.getPlayer().getInventory()
    191. .setHelmet(new ItemStack(35, 1, (short) 11));
    192. }
    193. }
    194. }
    195. [/syntax=java]
    196.  
    197. I just noticed this:
    198. [CODE]getServer().getPluginManager().registerEvents(new CaptureTheFlagHandler(null), this);[/CODE]
    199.  
    200. It has null, could that be the issue?
    201.  
    202. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  29. HackintoshMan
    Well, obviously you're asigning plugin to null... so yeah, it's a problem.
    Change it to 'this'.
     
  30. Offline

    HackintoshMan

Thread Status:
Not open for further replies.

Share This Page