Importing integer from config file

Discussion in 'Plugin Development' started by J_Man40, Feb 24, 2014.

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

    J_Man40

    I am working on a plugin just for experience's sake that is like a world guard plugin. All I am struggling with is when you type '/mark' it saves to a config file, the location and the radius you want, It's working perfectly until the radius part. There are no errors when saved and compiled but in the game it doesn't let me place stuff within the radius I want. It doesn't let me place stuff anywhere.


    Code:java
    1. package me.Jordan.Arena;
    2.  
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.BlockBreakEvent;
    12. import org.bukkit.event.block.BlockPlaceEvent;
    13. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    14.  
    15. public class PlayerListener implements Listener{
    16.  
    17. public Main plugin;
    18.  
    19. public static Material[] banList = {Material.TNT};
    20.  
    21. public PlayerListener(Main instance){
    22. plugin = instance;
    23. }
    24.  
    25. //int r = 10;
    26. @EventHandler
    27. public void onDamage(EntityDamageByEntityEvent event){
    28.  
    29. Player player = (Player) event.getEntity();
    30.  
    31. if (event.getEntity() instanceof Player && event.getDamager() instanceof Player){
    32. int r = plugin.getConfig().getInt("radius.x");
    33. int x = plugin.getConfig().getInt("locations.1.x");
    34. int y = plugin.getConfig().getInt("locations.1.y");
    35. int z = plugin.getConfig().getInt("locations.1.z");
    36. Location loc = new Location(player.getWorld(), x, y, z);
    37. if(player.getLocation().distance(loc) <= r){
    38. event.setCancelled(false);
    39. player.sendMessage("debug message:)");
    40.  
    41. }else{
    42. event.setCancelled(true);
    43. }
    44. }
    45. }
    46. @EventHandler
    47. public void onBlockPlace(BlockPlaceEvent event){
    48. Block block = event.getBlock();
    49. Material mat = block.getType();
    50. Player player = event.getPlayer();
    51. int r = plugin.getConfig().getInt("radius.x");
    52. int x = plugin.getConfig().getInt("locations.1.x");
    53. int y = plugin.getConfig().getInt("locations.1.y");
    54. int z = plugin.getConfig().getInt("locations.1.z");
    55. Location loc = new Location(player.getWorld(), x, y, z);
    56.  
    57. if(mat == mat && !player.isOp()) {
    58. player.sendMessage(ChatColor.RED + "debug message");
    59. if(player.getLocation().distance(loc) <= r){
    60. event.setCancelled(false);
    61. player.sendMessage("debug message:)");
    62.  
    63. }else{
    64. event.setCancelled(true);
    65. }
    66. }
    67. }
    68. @EventHandler
    69. public void onBlockBreak(BlockBreakEvent event) {
    70. Block block = event.getBlock();
    71. Material mat = block.getType();
    72. Player player = event.getPlayer();
    73.  
    74. int r = plugin.getConfig().getInt("radius.x");
    75. int x = plugin.getConfig().getInt("locations.1.x");
    76. int y = plugin.getConfig().getInt("locations.1.y");
    77. int z = plugin.getConfig().getInt("locations.1.z");
    78. Location loc = new Location(player.getWorld(), x, y, z);
    79.  
    80. if (mat == mat && !player.isOp()) {
    81. player.sendMessage(ChatColor.RED + "debug message");
    82. if(player.getLocation().distance(loc) <= r){
    83. event.setCancelled(false);
    84. player.sendMessage("debug message:)");
    85. }else{
    86. event.setCancelled(true);
    87. }
    88. }
    89. }
    90. }
     
Thread Status:
Not open for further replies.

Share This Page