Going Insane. Cant find the issue!

Discussion in 'Plugin Development' started by ChrisStarr32, Apr 18, 2014.

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

    ChrisStarr32

    So my code as you see is supposed to work as a Duel Pvp plugin. Now I can get the command stuff to work and adding players to the Queue list array but nothing after that. If you have the time to can you please tell me what is going on.

    DOWNLOAD LINK: <Edit by Moderator: Redacted mediafire url>
    REQUIRES BarAPI: [HERE]

    CRAFTBUKKIT VERSION: [HERE]
    CODE:

    Code:java
    1. package net.dualpvp.main;
    2.  
    3.  
    4. import java.util.ArrayList;
    5. import java.util.Random;
    6. import me.confuser.barapi.BarAPI;
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Location;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.entity.PlayerDeathEvent;
    16. import org.bukkit.event.player.PlayerJoinEvent;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class Main extends JavaPlugin implements Listener
    20. {
    21. //-------------------------------------------------------------------------
    22. ArrayList <Player> duellist = new ArrayList<Player>();
    23. ArrayList <Player> queuelist = new ArrayList<Player>();
    24. ArrayList <Player> duelone = new ArrayList<Player>();
    25. ArrayList <Player> dueltwo = new ArrayList<Player>();
    26. //-------------------------------------------------------------------------
    27. Player r1;
    28. Player r2;
    29. //-------------------------------------------------------------------------
    30. ChatColor red = ChatColor.RED;
    31. ChatColor green = ChatColor.GREEN;
    32. ChatColor blue = ChatColor.BLUE;
    33. ChatColor white = ChatColor.WHITE;
    34. ChatColor gray = ChatColor.GRAY;
    35. ChatColor daqua = ChatColor.DARK_AQUA;
    36. ChatColor dgray = ChatColor.DARK_GRAY;
    37. //-------------------------------------------------------------------------
    38. Location spawn = new Location(Bukkit.getWorld("world"), 0, 40, 0);
    39. Location duel1loc1 = new Location(Bukkit.getWorld("world"), 0, 60, 0);
    40. Location duel1loc2 = new Location(Bukkit.getWorld("world"), 0, 60, 0);
    41. Location duel2loc1 = new Location(Bukkit.getWorld("world"), 0, 80, 0);
    42. Location duel2loc2 = new Location(Bukkit.getWorld("world"), 0, 80, 0);
    43. //-------------------------------------------------------------------------
    44. String dp = ChatColor.AQUA + " • " + ChatColor.RESET;
    45.  
    46. public void onEnable(){
    47. System.out.println("---------------------");
    48. System.out.println("DuelPvP Main Enabled!");
    49. System.out.println("Current Version: 1.3 ");
    50. System.out.println("---------------------");
    51. getServer().getPluginManager().registerEvents(this, this);}
    52.  
    53. public void onDisable(){
    54. System.out.println("----------------------");
    55. System.out.println("DuelPvP Main Disabled!");
    56. System.out.println("Current Version: 1.3 ");
    57. System.out.println("----------------------");}
    58.  
    59. @EventHandler
    60. public void onPlayerJoinEvent(PlayerJoinEvent event){
    61. event.setJoinMessage(dp + ChatColor.GRAY + event.getPlayer().getDisplayName() + " has joined DuelPVP!");}
    62.  
    63.  
    64. @Override
    65. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    66. {
    67. Player p = (Player)sender;
    68. if (cmd.getName().equalsIgnoreCase("randomduel")) {
    69. if(queuelist.contains(p)){
    70. sender.sendMessage(dp + red + "You are already queued for a duel!");
    71. if (duelone.isEmpty() && queuelist.size() > 2 || dueltwo.isEmpty() && queuelist.size() > 2){
    72. DuelAreaEmpty();}}
    73. if(!queuelist.contains(p)){
    74. sender.sendMessage(dp + gray + "You have been queued for a duel!");
    75. queuelist.add(p);
    76. if (duelone.isEmpty() && queuelist.size() > 2 || dueltwo.isEmpty() && queuelist.size() > 2){
    77. DuelAreaEmpty();}
    78. }return true; }
    79. return false;
    80. }
    81.  
    82. @EventHandler
    83. public void onPlayerDeath(PlayerDeathEvent event){
    84. if(event.getEntity() instanceof Player){
    85. Player player = event.getEntity();
    86. Player killer = player.getKiller();
    87. String KillBlurt = red + player.getDisplayName() + gray + " was defeated by " + green + player.getKiller().getDisplayName();
    88. if (duelone.contains(player) && duelone.contains(killer))
    89. {
    90. duelone.remove(player);
    91. duelone.remove(killer);
    92. player.teleport(spawn);
    93. killer.teleport(spawn);
    94. player.sendMessage(dp + "You have been defeated. You have lost " + red + "10" + gray + " points!");
    95. killer.sendMessage(dp + "You have one the battle. You gained " + green + "20" + gray + " points!");
    96. for(Player p : Bukkit.getOnlinePlayers()){BarAPI.setMessage(p, KillBlurt);}
    97. }
    98. else if (dueltwo.contains(player) && dueltwo.contains(killer))
    99. {
    100. dueltwo.remove(player);
    101. dueltwo.remove(killer);
    102. player.teleport(spawn);
    103. killer.teleport(spawn);
    104. player.sendMessage(dp + "You have been defeated. You have lost " + red + "10" + gray + " points!");
    105. killer.sendMessage(dp + "You have one the battle. You gained " + green + "20" + gray + " points!");
    106. for(Player p : Bukkit.getOnlinePlayers()){BarAPI.setMessage(p, KillBlurt);}
    107.  
    108. }
    109. }
    110. }
    111.  
    112. public void DuelAreaEmpty()
    113. {
    114. r1 = queuelist.get(new Random().nextInt(queuelist.size()));
    115. queuelist.remove(r1);
    116. if (duelone.size() <= 1){
    117. duelone.add(r1);
    118. DuelOneTeleport();}
    119. else if (dueltwo.size() <= 1){
    120. dueltwo.add(r1);
    121. DuelTwoTeleport();
    122. }
    123.  
    124. r2 = queuelist.get(new Random().nextInt(queuelist.size()));
    125. queuelist.remove(r2);
    126. if (duelone.size() <= 1){
    127. duelone.add(r2);
    128. DuelOneTeleport();}
    129. else if (dueltwo.size() <= 1){
    130. dueltwo.add(r2);
    131. DuelTwoTeleport();}
    132. }
    133.  
    134. public void DuelOneTeleport()
    135. {
    136. r1.teleport(duel1loc1);
    137. r2.teleport(duel1loc2);
    138. r1.sendMessage(dp + "You have joined the 1v1 duel");
    139. r2.sendMessage(dp + "You have joined the 1v1 duel");
    140. r1.sendMessage(dp + red + "OBJECTIVE:" + gray + " Fight " + white + r2.getDisplayName() + gray + "!");
    141. r2.sendMessage(dp + red + "OBJECTIVE:" + gray + " Fight " + white + r1.getDisplayName() + gray + "!");
    142. }
    143.  
    144. public void DuelTwoTeleport()
    145. {
    146. r1.teleport(duel2loc1);
    147. r2.teleport(duel2loc2);
    148. r1.sendMessage(dp + "You have joined the 1v1 duel");
    149. r2.sendMessage(dp + "You have joined the 1v1 duel");
    150. r1.sendMessage(dp + red + "OBJECTIVE:" + gray + " Fight " + white + r2.getDisplayName() + gray + "!");
    151. r2.sendMessage(dp + red + "OBJECTIVE:" + gray + " Fight " + white + r1.getDisplayName() + gray + "!");
    152. }
    153.  
    154.  
    155. }
    156.  
    157.  
    158.  
    159.  
    160.  
    161.  
    162.  
    163.  
    164.  
    165.  
    166.  
    167.  
    168.  


    Thank You! I really appreciate it!

    Bump

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

    Plo124

    ChrisStarr32
    1. An arraylist is constructed without a space
    so where you do ArrayList <Player>
    should have no space

    2. NEVER EVER NEVER EVER NEVER NEVER NEVER store player instances in any sort of Map. This will only ever lead to memory leaks. Alternatively, use a string as the player username, or if you are saving to a config file e.t.c., use player.getUUID()

    3. When using the random() method, you could call the same player twice, making him duel himself. Use [arraylist].get(0), and .get(1), to get the first ones on the queue, this also means the ones who queue to duel first will be in the duel first.

    4. The PlayerDeathEvent, e.getEntity() is a player, so you dont need to check for if they are a player.

    5. Dont bump threads within 24 hours please

    My suggestion is to add debug to your code (either using Bukkit.broadcastMessage() or this.getLogger().info()) to see where your code jams up,and then reply here with the stage it stops. Also it is good to post any errors in a spoiler in your thread, but I assume this isnt giving off any errors.
     
  3. Offline

    RawCode

    zero debug messages...
     
Thread Status:
Not open for further replies.

Share This Page