ArrayList problems

Discussion in 'Plugin Development' started by JellyYods, Jul 14, 2014.

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

    JellyYods

    I am making spawn protection for my kit server and the arrayLists Dont seems to be working all that well. Yes Everything is registered and I have a plugin.yml
    Code:java
    1. package Bods.Main;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    12. import org.bukkit.event.entity.EntityDamageEvent;
    13. import org.bukkit.event.entity.EntityShootBowEvent;
    14. import org.bukkit.event.entity.PlayerDeathEvent;
    15. import org.bukkit.event.player.PlayerJoinEvent;
    16. import org.bukkit.event.player.PlayerMoveEvent;
    17.  
    18. public class SpawnProt implements Listener {
    19.  
    20. ArrayList<Player> Protection = new ArrayList<Player>();
    21.  
    22. public static Location Spawn = new Location(Bukkit.getWorld("World"), 0.5,
    23. 5, 0.5);
    24.  
    25. public static boolean border(Location loc) {
    26. return isInSpawn(loc, 11);
    27. }
    28.  
    29. public static boolean isInSpawn(Location loc, int radius) {
    30. if (loc == null) {
    31. return false;
    32. }
    33. int x = Math.abs(loc.getBlockX() - Spawn.getBlockX());
    34. int z = Math.abs(loc.getBlockZ() - Spawn.getBlockZ());
    35. return (x < radius && z < radius);
    36. }
    37.  
    38. @EventHandler
    39. public void Damage(EntityDamageEvent e) {
    40. if (e.getEntity() instanceof Player) {
    41. Player player = (Player) e.getEntity();
    42. if (SpawnProt.border(player.getLocation())
    43. && Protection.contains(player)) {
    44. e.setCancelled(true);
    45. } else {
    46. e.setCancelled(false);
    47. }
    48. }
    49. }
    50.  
    51. @EventHandler
    52. public void BowDamage(EntityShootBowEvent e) {
    53. if (e.getEntity() instanceof Player) {
    54. Player player = (Player) e.getEntity();
    55. if (SpawnProt.border(player.getLocation())
    56. && Protection.contains(player)) {
    57. e.setCancelled(true);
    58. } else {
    59. e.setCancelled(false);
    60. }
    61. }
    62. }
    63.  
    64. @EventHandler
    65. public void DamageOthers(EntityDamageByEntityEvent e) {
    66. if(e.getEntity() instanceof Player) {
    67. Player player = (Player) e.getEntity();
    68. if (Protection.contains(player)) {
    69. e.setCancelled(true);
    70. } else {
    71. if(Protection.contains(player) == false) {
    72. e.setCancelled(false);
    73. }
    74. }
    75. }
    76. }
    77.  
    78. @EventHandler
    79. public void onSpawnLeave(PlayerMoveEvent event) {
    80. Player player = event.getPlayer();
    81. Location from = event.getFrom();
    82. Location to = event.getTo();
    83. if (SpawnProt.border(from) && !SpawnProt.border(to)) {
    84. player.sendMessage(ChatColor.GRAY
    85. + "You have lost Spawn Protection!");
    86. Protection.remove(player);
    87. }
    88. }
    89.  
    90. @EventHandler
    91. public void onJoin(PlayerJoinEvent e) {
    92. Player player = e.getPlayer();
    93. Protection.add(player);
    94. }
    95.  
    96. @EventHandler
    97. public void onDeath(PlayerDeathEvent e) {
    98. Player player = e.getEntity();
    99. Protection.add(player);
    100. }
    101.  
    102. }
    103.  
     
  2. Offline

    CorrieKay

    First things first, you should never store a reference to an actual player object. This can cause some serious problems for your server. Lastly, what exactly is the problem? What is the code doing that it shouldnt be doing, and what are you expecting it to do?
     
  3. Offline

    JellyYods

    CorrieKay I want the player to spawn at the center which I already have in another class, but In the spawn area the player has spawn prot. no player can damage the player till he leaves the spawn then the player can damage other player that have left the spawn too. Also when the player comes back in the spawn they can still be killed
     
  4. Offline

    ZodiacTheories

  5. Offline

    CorrieKay

    Okay, so we know what you want it to do, but what exactly is it doing wrong? Where is the problem?

    Most people aren't going to want to crawl through your code looking for any and all bugs, my friend :\
     
  6. Offline

    JellyYods

    CorrieKay The problem is People can still be attacked in spawn area
     
Thread Status:
Not open for further replies.

Share This Page