Help...

Discussion in 'Plugin Development' started by 544nick101, Jan 7, 2012.

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

    544nick101

    Hello i am remaking the plugin bananaprotect and i got stuck on a bug can any one help me, thanks.

    This is the class file Protection
    Code:java
    1. package me.nick.plugins.myblocks;
    2.  
    3. import java.io.File;
    4. import java.util.ArrayList;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Chunk;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.Event;
    14. import org.bukkit.plugin.PluginDescriptionFile;
    15. import org.bukkit.plugin.PluginManager;
    16. import org.bukkit.util.config.Configuration;
    17.  
    18. public class Protection extends org.bukkit.plugin.java.JavaPlugin
    19. {
    20. AntiGrief playerListener = new AntiGrief(this);
    21. EntityHandler playerInteract = new EntityHandler(this);
    22. ArrayList<String> exempt = new ArrayList();
    23. ArrayList<String> exemptWorlds = new ArrayList();
    24. public void onDisable() {
    25. PluginDescriptionFile pdfFile = getDescription();
    26. System.out.println("[" + pdfFile.getName() + "]" + " version " +
    27. pdfFile.getVersion() + " is now disabled!");
    28. }
    29. public Location getNextAirSpace(Location blockloc) {
    30. Location blockl = blockloc;
    31. Location blockl2 = blockl;
    32. for (int i = blockloc.getBlockY(); i < 127; i++) {
    33. blockl.setY(i);
    34. blockl2.setY(i + 1);
    35. if ((blockl.getBlock().getTypeId() == 0) &&
    36. (blockl2.getBlock().getTypeId() == 0)) {
    37. return blockl;
    38. }
    39. }
    40. return null;
    41. }
    42. public String[] whoPlaced(Block block, File pluginpath) {
    43. World world = block.getWorld();
    44. Chunk chunk = world.getChunkAt(block.getLocation());
    45. String cname = String.valueOf(chunk.getX()) + "." + chunk.getZ() + ".yml";
    46. String cpath = String.valueOf(block.getLocation().getBlockX()) + "," +
    47. block.getLocation().getBlockY() + "," +
    48. block.getLocation().getBlockZ();
    49. Configuration pC = getConfig(new File(pluginpath + "/" + cname));
    50. String[] strings = { pC.getString(String.valueOf(cpath) + ".player", ""), pC.getString(String.valueOf(cpath) + ".type", "") };
    51. return strings;
    52. }
    53. protected Configuration getConfig(File filepath) {
    54. if (!filepath.exists()) {
    55. try
    56. {
    57. filepath.createNewFile();
    58. }
    59. catch (java.io.IOException e) {
    60. e.printStackTrace();
    61. }
    62. }
    63. Configuration c = new Configuration(filepath);
    64. c.load();
    65. return c;
    66. }
    67.  
    68. public void onEnable()
    69. {
    70. Configuration c = getConfiguration();
    71. c.load();
    72. c.setProperty("worlds." + ((World)getServer().getWorlds().get(0)).getName(), Boolean.valueOf(c.getBoolean("worlds." + ((World)getServer().getWorlds().get(0)).getName(), true)));
    73. c.save();
    74. PluginDescriptionFile pdfFile = getDescription();
    75. PluginManager pm = getServer().getPluginManager();
    76. pm.registerEvent(Event.Type.BLOCK_PLACE, this.playerListener,
    77. Event.Priority.Normal, this);
    78. pm.registerEvent(Event.Type.BLOCK_PHYSICS, this.playerListener,
    79. Event.Priority.Low, this);
    80. pm.registerEvent(Event.Type.BLOCK_BREAK, this.playerListener,
    81. Event.Priority.High, this);
    82. pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.playerListener,
    83. Event.Priority.Normal, this);
    84. pm.registerEvent(Event.Type.BLOCK_IGNITE, this.playerListener,
    85. Event.Priority.Normal, this);
    86. pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerInteract,
    87. Event.Priority.Normal, this);
    88. System.out.println("[" + pdfFile.getName() + "]" + " version " +
    89. pdfFile.getVersion() + " is now enabled!");
    90. if (!pdfFile.getName().equalsIgnoreCase("MyBlocks")) {
    91. System.err.print("This plugin was stolen. Report it to 544nick101");
    92. System.exit(-1);
    93. }
    94. }
    95.  
    96. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    97. {
    98. if ((cmd.getName().equalsIgnoreCase("addfriend")) &&
    99. ((sender instanceof Player)) &&
    100. (args.length == 1))
    101. {
    102. Player player = (Player)sender;
    103. Configuration pC = getConfiguration();
    104. pC.setProperty("allow." + player.getName() + "." + args[0].toLowerCase(), Boolean.valueOf(true));
    105. pC.save();
    106. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    107. ChatColor.DARK_BLUE + args[0] + " added to friend list.");
    108. return true;
    109. }
    110.  
    111.  
    112.  
    113.  
    114.  
    115. if ((cmd.getName().equalsIgnoreCase("removefriend")) &&
    116. ((sender instanceof Player)) &&
    117. ((sender instanceof Player)) &&
    118. (args.length == 1))
    119. {
    120. Player player = (Player)sender;
    121. Configuration pC = getConfiguration();
    122. pC.removeProperty("allow." + player.getName() + "." + args[0].toLowerCase());
    123. try {
    124. pC.save();
    125. }
    126. catch (Exception e)
    127. {
    128. System.err.print(String.valueOf(player.getName()) + " cannot type properly.");
    129. System.err.print(e);
    130. }
    131. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    132. ChatColor.DARK_BLUE + args[0] + " removed from friend list.");
    133. return true;
    134. }
    135.  
    136.  
    137.  
    138.  
    139. if ((cmd.getName().equalsIgnoreCase("protection")) &&
    140. ((sender instanceof Player))) {
    141. Player player = (Player)sender;
    142. String name = player.getName();
    143. if (this.exempt.contains(name))
    144. {
    145. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    146. ChatColor.DARK_BLUE + "Your protection has been toggled on.");
    147. this.exempt.remove(name);
    148. return true;
    149. }
    150.  
    151. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    152. ChatColor.DARK_BLUE + "You protection has been toggled off.");
    153. this.exempt.add(name);
    154. return true;
    155. }
    156.  
    157.  
    158. if (cmd.getName().equalsIgnoreCase("rollback")) {
    159. if ((sender instanceof Player)) {
    160. Player player = (Player)sender;
    161. if ((player.hasPermission("myblocks.rollback")) || (player.isOp())) {
    162. System.out.println(String.valueOf(player.getName()) +
    163. " used command /rollback at coordinates " +
    164. player.getLocation().getBlockX() + "," +
    165. player.getLocation().getBlockY() + "," +
    166. player.getLocation().getBlockZ());
    167. if (args.length == 2) {
    168. int radius = Integer.parseInt(args[0]);
    169. if (radius > 10)
    170. radius = 10;
    171. File pluginpath = new File("plugins/MyBlocks");
    172. Chunk chunk = player.getWorld().getChunkAt(
    173. player.getLocation());
    174. int chunkX = chunk.getX();
    175. int chunkZ = chunk.getZ();
    176. int count = 0;
    177. for (int x = 0 - radius; x < radius; x++) {
    178. for (int z = 0 - radius; z < radius; z++) {
    179. String cname = String.valueOf(chunkX + x) + "." + (
    180. chunkZ + z) + ".yml";
    181. Configuration pC = getConfig(new File(
    182. pluginpath + "/" + player.getWorld().getName() + "/" + cname));
    183. for (String key : pC.getKeys())
    184. {
    185. String playername = pC.getString(String.valueOf(key) +
    186. ".player", "");
    187.  
    188. if (playername.equalsIgnoreCase(args[1])) {
    189. String[] locXYZ = key.split(",");
    190. count++;
    191. Block block = player
    192. .getWorld()
    193. .getBlockAt(
    194. Integer.parseInt(locXYZ[0]),
    195. Integer.parseInt(locXYZ[1]),
    196. Integer.parseInt(locXYZ[2]));
    197. if (block.getY() < 63)
    198. block.setTypeId(1);
    199. if (block.getY() == 63)
    200. block.setTypeId(2);
    201. if (block.getY() > 63)
    202. block.setTypeId(0);
    203. pC.removeProperty(key);
    204. }
    205. }
    206. pC.save();
    207. }
    208. }
    209. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    210. " changes have been rolled back.");
    211. return true;
    212. }
    213. if (args.length == 3) {
    214. int radius = Integer.parseInt(args[0]);
    215. if (radius > 10)
    216. radius = 10;
    217. File pluginpath = new File("plugins/CreativeBlocks");
    218. Chunk chunk = player.getWorld().getChunkAt(
    219. player.getLocation());
    220. int chunkX = chunk.getX();
    221. int chunkZ = chunk.getZ();
    222. int count = 0;
    223. for (int x = 0 - radius; x < radius; x++) {
    224. for (int z = 0 - radius; z < radius; z++) {
    225. String cname = String.valueOf(chunkX + x) + "." + (
    226. chunkZ + z) + ".yml";
    227. Configuration pC = getConfig(new File(
    228. pluginpath + "/" + cname));
    229. for (String key : pC.getKeys())
    230. {
    231. String playername = pC.getString(String.valueOf(key) +
    232. ".player", "");
    233. String blocktype = pC.getString(String.valueOf(key) +
    234. ".type", "");
    235. if ((playername.equalsIgnoreCase(args[1])) &&
    236. (blocktype.equals(args[2]))) {
    237. String[] locXYZ = key.split(",");
    238. count++;
    239. Block block = player
    240. .getWorld()
    241. .getBlockAt(
    242. Integer.parseInt(locXYZ[0]),
    243. Integer.parseInt(locXYZ[1]),
    244. Integer.parseInt(locXYZ[2]));
    245. if (block.getY() < 63)
    246. block.setTypeId(1);
    247. if (block.getY() == 63)
    248. block.setTypeId(2);
    249. if (block.getY() > 63)
    250. block.setTypeId(0);
    251. pC.removeProperty(key);
    252. }
    253. }
    254. pC.save();
    255. }
    256. }
    257. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    258. ChatColor.DARK_BLUE + count +
    259. " changes have been rolled back.");
    260. return true;
    261. }
    262. return false;
    263. }
    264. sender.sendMessage(ChatColor.DARK_RED + "[Note] " +
    265. ChatColor.DARK_BLUE +
    266. "You don't have permission to use this command.");
    267. return true;
    268. }
    269. return false;
    270. }
    271. if (cmd.getName().equalsIgnoreCase("regen")) {
    272. if (!(sender instanceof Player)) {
    273. sender.sendMessage(ChatColor.DARK_RED + "You have to be a player to use this command.");
    274. return true;
    275. }
    276. Player player = (Player)sender;
    277. if ((player.hasPermission("myblocks.regen")) || (player.isOp())) {
    278. player.sendMessage(ChatColor.DARK_RED + "[Note] " +
    279. ChatColor.DARK_BLUE + "Regenerating chunk...");
    280. player.getWorld().regenerateChunk(
    281. player.getWorld().getChunkAt(player.getLocation())
    282. .getX(),
    283. player.getWorld().getChunkAt(player.getLocation())
    284. .getZ());
    285. return true;
    286. }
    287. player.sendMessage(ChatColor.DARK_RED + "[Note] " +
    288. ChatColor.DARK_BLUE +
    289. "You don't have permission to use this command.");
    290. return true;
    291. }
    292. return false;
    293. }
    294. }
    295.  


    This is the class file EntityHandler
    Code:java
    1. package me.nick.plugins.myblocks;
    2.  
    3. import java.io.File;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9.  
    10. public class EntityHandler extends org.bukkit.event.player.PlayerListener
    11. {
    12. private final Protection plugin;
    13. public EntityHandler(Protection callbackPlugin)
    14. {
    15. this.plugin = callbackPlugin;
    16. }
    17. public void onPlayerInteract(PlayerInteractEvent event)
    18. {
    19. Player player = event.getPlayer();
    20. File pluginpath = new File("plugins/MyBlocks");
    21. if ((event.getAction() == Action.LEFT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getClickedBlock().getType()==Material.CHEST || event.getClickedBlock().getType()==Material.FURNACE || event.getClickedBlock().getType()==Material.DISPENSER || event.getClickedBlock().getType()==Material.JUKEBOX || event.getClickedBlock().getType()==Material.CAKE))
    22. {
    23.  
    24.  
    25.  
    26.  
    27. if ((event.getClickedBlock().getType() != Material.LEVER) && (event.getClickedBlock().getType() != Material.STONE_BUTTON) && (event.getClickedBlock().getTypeId() != 64))
    28. {
    29.  
    30. if ((event.getClickedBlock().getTypeId() == 71) || (event.getClickedBlock().getType() == Material.CHEST) || (event.getClickedBlock().getType() == Material.FURNACE) || (event.getClickedBlock().getType() == Material.DISPENSER || event.getClickedBlock().getType()==Material.JUKEBOX || event.getClickedBlock().getType()==Material.CAKE))
    31. {
    32. if ((!player.hasPermission("myblocks.admin")) && (!player.isOp()))
    33. {
    34. String[] whostuff = this.plugin.whoPlaced(event.getClickedBlock(), new File(pluginpath + "/" + event.getClickedBlock().getWorld().getName() + "/"));
    35. String whoplaced = whostuff[0];
    36. if (whoplaced.length() > 0)
    37. {
    38. if (!whoplaced.equals(player.getName()))
    39. {
    40. player.sendMessage(ChatColor.DARK_RED + "That " + ChatColor.DARK_RED + "is locked with a magical spell.");
    41. event.setCancelled(true);
    42. }
    43. }
    44. }
    45. }
    46. } }
    47. if (((player.hasPermission("myblocks.admin")) || (player.isOp())) && (event.getAction() == Action.RIGHT_CLICK_BLOCK) && (player.getItemInHand().getType() == Material.IRON_PICKAXE)) {
    48. String[] whostuff = this.plugin.whoPlaced(event.getClickedBlock(), new File(pluginpath + "/" + player.getWorld().getName()));
    49. String whoplaced = whostuff[0];
    50. if (whoplaced.length() == 0) player.sendMessage(ChatColor.DARK_RED + "[Note] " + ChatColor.DARK_BLUE + "The block at " + event.getClickedBlock().getLocation().getBlockX() + "," + event.getClickedBlock().getLocation().getBlockY() + "," + event.getClickedBlock().getLocation().getBlockZ() + " is native."); else {
    51. player.sendMessage(ChatColor.DARK_RED + "[Note] " + ChatColor.DARK_BLUE + "The " + event.getClickedBlock().getType().name().toLowerCase().replace("_", " ") + " at " + event.getClickedBlock().getLocation().getBlockX() + "," + event.getClickedBlock().getLocation().getBlockY() + "," + event.getClickedBlock().getLocation().getBlockZ() + " was placed by " + whoplaced + ".");
    52. }
    53. }
    54. }
    55. }
    56.  


    This is the class file AntiGrief
    Code:java
    1. package me.nick.plugins.myblocks;
    2.  
    3. import java.io.File;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Chunk;
    6. import org.bukkit.Material;
    7. import org.bukkit.World;
    8. import org.bukkit.block.Block;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.block.BlockBreakEvent;
    11. import org.bukkit.event.block.BlockPlaceEvent;
    12. import org.bukkit.util.config.Configuration;
    13.  
    14. public class AntiGrief extends org.bukkit.event.block.BlockListener
    15. {
    16. private final Protection plugin;
    17. private final String pluginpath = "plugins/MyBlocks";
    18.  
    19.  
    20. public AntiGrief(Protection callbackPlugin)
    21. {
    22. this.plugin = callbackPlugin;
    23. }
    24.  
    25. {
    26. }
    27.  
    28. public void onBlockBreak(BlockBreakEvent event)
    29. {
    30. if (!this.plugin.getConfiguration().getBoolean("worlds." + event.getBlock().getWorld().getName(), true))
    31. {
    32. return;
    33. }
    34. Player player = event.getPlayer();
    35. if ((!player.hasPermission("myblocks.admin")) && (!player.isOp()))
    36. {
    37. Block block = event.getBlock();
    38. World world = block.getWorld();
    39. File worldpath = new File("plugins/MyBlocks/" + world.getName());
    40. Chunk chunk = world.getChunkAt(block.getLocation());
    41. String cname = String.valueOf(chunk.getX()) + "." + chunk.getZ() + ".yml";
    42. String cpath = String.valueOf(block.getLocation().getBlockX()) + "," + block.getLocation().getBlockY() + "," + block.getLocation().getBlockZ();
    43. String cpath2 = String.valueOf(block.getLocation().getBlockX()) + "," + (block.getLocation().getBlockY() + 1) + "," + block.getLocation().getBlockZ();
    44. Configuration pC = this.plugin.getConfig(new File(worldpath + "/" + cname));
    45. if ((!this.plugin.getConfiguration().getBoolean("allow." + pC.getString(new StringBuilder(String.valueOf(cpath)).append(".player").toString(), "") + "." + player.getName().toLowerCase(), false)) && (pC.getString(String.valueOf(cpath) + ".player", "").length() > 0))
    46. {
    47. if ((!pC.getString(String.valueOf(cpath) + ".player", "").equals(player.getName())) && (pC.getString(String.valueOf(cpath) + ".player", "").length() != 0)) { event.setCancelled(true);
    48. } else if ((block.getRelative(0, 1, 0).getTypeId() == 71) || (block.getRelative(0, 1, 0).getTypeId() == 64)) if ((!pC.getString(String.valueOf(cpath2) + ".player", "").equals(player.getName())) && (pC.getString(String.valueOf(cpath2) + ".player", "").length() != 0)) { event.setCancelled(true);
    49. } else { pC.removeProperty(cpath);
    50. pC.save();
    51. }
    52. }
    53. }
    54. }
    55. public void onBlockPlace(BlockPlaceEvent event)
    56. {
    57. if (event.getBlock().getType() == Material.SAPLING)
    58. {
    59.  
    60. return;
    61. }
    62.  
    63.  
    64. if (!this.plugin.getConfiguration().getBoolean("worlds." + event.getBlock().getWorld().getName(), true))
    65. {
    66. return;
    67. }
    68. if (!this.plugin.exempt.contains(event.getPlayer().getName()))
    69. {
    70. Player player = event.getPlayer();
    71. if (((player.hasPermission("myblocks.admin")) || (player.isOp())) && (event.getBlock().getTypeId() == 95)) {
    72. event.setCancelled(true);
    73. String[] whostuff = this.plugin.whoPlaced(event.getBlock().getLocation().getBlock(), new File("plugins/BananaProtect/" + player.getWorld().getName()));
    74. String whoplaced = whostuff[0];
    75. if (whoplaced.length() == 0) player.sendMessage(ChatColor.DARK_RED + "[Note] " + ChatColor.DARK_BLUE + "The block at " + event.getBlock().getLocation().getBlockX() + "," + event.getBlock().getLocation().getBlockY() + "," + event.getBlock().getLocation().getBlockZ() + " is native."); else {
    76. player.sendMessage(ChatColor.DARK_RED + "[Note] " + ChatColor.DARK_BLUE + "The " + Material.getMaterial(Integer.parseInt(whostuff[1])).name().toLowerCase().replace("_", " ") + " at " + event.getBlock().getLocation().getBlockX() + "," + event.getBlock().getLocation().getBlockY() + "," + event.getBlock().getLocation().getBlockZ() + " was placed by " + whoplaced + ".");
    77. }
    78. } else if (event.getBlock().getTypeId() == 52) {
    79. if ((!player.hasPermission("myblcks.admin")) && (!player.isOp())) event.setCancelled(true);
    80. }
    81. else {
    82. Block block = event.getBlock();
    83. World world = block.getWorld();
    84. File worldpath = new File("plugins/MyBlocks/" + world.getName());
    85. Chunk chunk = world.getChunkAt(block.getLocation());
    86. String cname = String.valueOf(chunk.getX()) + "." + chunk.getZ() + ".yml";
    87. String cpath = String.valueOf(block.getLocation().getBlockX()) + "," + block.getLocation().getBlockY() + "," + block.getLocation().getBlockZ();
    88. if (!worldpath.exists()) worldpath.mkdir();
    89. Configuration pC = this.plugin.getConfig(new File(worldpath + "/" + cname));
    90. pC.setProperty(String.valueOf(cpath) + ".player", player.getName());
    91. pC.setProperty(String.valueOf(cpath) + ".type", Integer.valueOf(event.getBlock().getTypeId()));
    92. if ((block.getTypeId() == 71) || (block.getTypeId() == 64))
    93. {
    94. String cpath2 = String.valueOf(block.getLocation().getBlockX()) + "," + (block.getLocation().getBlockY() + 1) + "," + block.getLocation().getBlockZ();
    95. pC.setProperty(String.valueOf(cpath2) + ".player", player.getName());
    96. pC.setProperty(String.valueOf(cpath2) + ".type", Integer.valueOf(event.getBlock().getTypeId()));
    97. }
    98. pC.save();
    99. }
    100. }
    101.  
    102.  
    103.  
    104.  
    105.  
    106.  
    107. if (event.getBlock().getType() == Material.CHEST)
    108. {
    109.  
    110. Block chest = event.getBlock();
    111. Block closeby1 = chest.getRelative(-1, 0, 0);
    112. Block closeby2 = chest.getRelative(1, 0, 0);
    113. Block closeby3 = chest.getRelative(0, 0, 1);
    114. Block closeby4 = chest.getRelative(0, 0, -1);
    115. World world = chest.getWorld();
    116. Player player = event.getPlayer();
    117. File worldpath = new File("plugins/MyBlocks/" + world.getName());
    118. Chunk chunk = world.getChunkAt(chest.getLocation());
    119. String cname = String.valueOf(chunk.getX()) + "." + chunk.getZ() + ".yml";
    120. String cpath = String.valueOf(closeby1.getLocation().getBlockX()) + "," + closeby1.getLocation().getBlockY() + "," + closeby1.getLocation().getBlockZ();
    121. String cpath1 = String.valueOf(closeby2.getLocation().getBlockX()) + "," + closeby2.getLocation().getBlockY() + "," + closeby2.getLocation().getBlockZ();
    122. String cpath2 = String.valueOf(closeby3.getLocation().getBlockX()) + "," + closeby3.getLocation().getBlockY() + "," + closeby3.getLocation().getBlockZ();
    123. String cpath3 = String.valueOf(closeby4.getLocation().getBlockX()) + "," + closeby4.getLocation().getBlockY() + "," + closeby4.getLocation().getBlockZ();
    124. if (!worldpath.exists()) worldpath.mkdir();
    125. Configuration pC = this.plugin.getConfig(new File(worldpath + "/" + cname));
    126. if ((!this.plugin.getConfiguration().getBoolean("allow." + pC.getString(new StringBuilder(String.valueOf(cpath)).append(".player").toString(), "") + "." + player.getName().toLowerCase(), false)) && (pC.getString(String.valueOf(cpath) + ".player", "").length() > 0))
    127. {
    128. if ((!pC.getString(String.valueOf(cpath) + ".player", "").equals(player.getName())) && (pC.getString(String.valueOf(cpath) + ".player", "").length() != 0)) event.setCancelled(true);
    129. }
    130.  
    131. if ((!this.plugin.getConfiguration().getBoolean("allow." + pC.getString(new StringBuilder(String.valueOf(cpath1)).append(".player").toString(), "") + "." + player.getName().toLowerCase(), false)) && (pC.getString(String.valueOf(cpath1) + ".player", "").length() > 0))
    132. {
    133. if ((!pC.getString(String.valueOf(cpath1) + ".player", "").equals(player.getName())) && (pC.getString(String.valueOf(cpath1) + ".player", "").length() != 0)) event.setCancelled(true);
    134. }
    135.  
    136. if ((!this.plugin.getConfiguration().getBoolean("allow." + pC.getString(new StringBuilder(String.valueOf(cpath2)).append(".player").toString(), "") + "." + player.getName().toLowerCase(), false)) && (pC.getString(String.valueOf(cpath2) + ".player", "").length() > 0))
    137. {
    138. if ((!pC.getString(String.valueOf(cpath2) + ".player", "").equals(player.getName())) && (pC.getString(String.valueOf(cpath2) + ".player", "").length() != 0)) event.setCancelled(true);
    139. }
    140. if ((!this.plugin.getConfiguration().getBoolean("allow." + pC.getString(new StringBuilder(String.valueOf(cpath3)).append(".player").toString(), "") + "." + player.getName().toLowerCase(), false)) && (pC.getString(String.valueOf(cpath3) + ".player", "").length() > 0))
    141. {
    142. if ((!pC.getString(String.valueOf(cpath3) + ".player", "").equals(player.getName())) && (pC.getString(String.valueOf(cpath3) + ".player", "").length() != 0)) event.setCancelled(true);
    143. }
    144.  
    145.  
    146.  
    147.  
    148. if ((closeby1.getType() != Material.CHEST) && (closeby2.getType() != Material.CHEST) && (closeby3.getType() != Material.CHEST)) closeby4.getType();
    149. }
    150. }
    151. }
    152.  


    This is the plugin.yml

    Code:
    name: MyBlocks
    author: 544nick101
    website: http://nickcraftsmp.weebly.com/
    description: MyBlocks - Protects every block any one places
    main: me.plugins.nick.myblocks.Protection
    version: 1.0
    load: startup
    commands:
        addfriend:
            description: Lets you add people.
            usage: <command> playername
    
        removefriend:
            description: Lets you remove people.
            usage: <command> playername
    
        rollback:
            description: Lets you rollback a player.
            usage: <command> chunks name (type id)
    
        protection:
            description: Toggles your block protection.
            usage: <command>
        regen:
            description: Regernates a chunck.
            usage: <command> 
     
  2. Offline

    Technius

    Exactly WHAT is the bug?
     
  3. Offline

    544nick101

    Gets a error on start up
    Code:
    [SEVERE] Could not load 'plugins\MyBlocks.jar' in folder 'plugins':
    java.lang.ClassNotFoundException: nickcraftsmp.net.Protection
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.net.URLClassLoader$1.run(Unknown Source)
    And there is yellow errors in eclipse
     
  4. Offline

    Technius

    You don't have a class called "Protection".

    [SEVERE] Could not load 'plugins\MyBlocks.jar' in folder 'plugins':
    java.lang.ClassNotFoundException: nickcraftsmp.net.Protection
     
  5. Offline

    544nick101

    But i do...

    Can you copy and paste my code in your eclipse and see if you can fix it?(If you do ill make sure to list you as a myblocks author.)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  6. Offline

    Technius

    Make sure you are exporting your files when you export!
     
  7. Offline

    544nick101

    I have every thing clicked but .settings

    And do yellow errors mean anything?(Sorry i'm kinda a noob to java)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  8. Offline

    Zimp

    main: me.plugins.nick.myblocks.Protection
    package me.nick.plugins.myblocks;
     
  9. Offline

    544nick101

    so i just put me.nick.plugins.myblocks.Protection; and that should fix it?
     
  10. Offline

    Zimp

    I'm not brave enough to say it will fix it but I would wager it's worth a try
     
  11. Offline

    544nick101

    Damn didn't work :( but i think i know what will :)
     
  12. Offline

    Technius

    Make sure your files are in a package, first.
     
  13. Offline

    544nick101

    Ok now i get this error(its called myblock1 becuse i can't have 2 named my blocks)
    Code:
    [SEVERE] Error occurred while enabling MyBlocks1 v1.0 (Is it up to date?): Index: 0, Size: 0
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    	at java.util.ArrayList.rangeCheck(Unknown Source)
    	at java.util.ArrayList.get(Unknown Source)
    	at com.nick.myblocks.Protection.onEnable(Protection.java:81)
    	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
    	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
    	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
    	at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
    	at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:128)
    	at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:399)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    
    They are(its not my first plugin, lol...)

    And i am using the newest RB of bukkit

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  14. Offline

    tomjw64

    When you initialized the ArrayList fields exempt and exemptWorlds you left off the second <String>

    For example:

    Replace this:
    Code:java
    1. ArrayList<String> exempt=new ArrayList();

    With this:
    Code:java
    1. ArrayList<String> exempt=new ArrayList<String>();
     
  15. Offline

    544nick101

    Did that still getting
    Code:
    [SEVERE] Error occurred while enabling MyBlocks1 v1.0 (Is it up to date?): Index: 0, Size: 0
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    	at java.util.ArrayList.rangeCheck(Unknown Source)
    	at java.util.ArrayList.get(Unknown Source)
    	at com.nick.myblocks.Protection.onEnable(Protection.java:81)
    	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
    	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
    	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
    	at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
    	at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:128)
    	at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:399)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    
    Yeah i know i just want to do this quick....
     
  16. Offline

    tomjw64

    spacing?
    Also, you should probably tell him where he puts the ; before the () so that he can fix the problem, right?
     
  17. Not understanding stuff is NOT quick at all.

    For example, that error you're getting says exacly what's wrong with your code.

    You're using get(0) on a array that has 0 records, meaning you can't use get() on it !
    Find where you're using get() without checking if size() > 0.


    EDIT:
    @tomjw64
    He posted another reply just before mine but then he deleted it, he wrote something about what to do between:
    Code:
    ArrayList<String> exempt=new ArrayList<String>;() // that's how he wrote it
    // or
    ArrayList<String> exempt = new ArrayList<String>;()
    And that's why I posted that and it was addressed to him, not you :p... confusion on deleted posts :) I should probably delete mine too :)
     
  18. Offline

    544nick101

    I deleted it because i realized it was a stupid question. So if i'm hearing you right my code should be
    Code:
     ArrayList<String> exempt = new ArrayList<String>;
    
    I'm not that sure....

    Sorry for me not knowing much(if anything) about java. Any good guides on java?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  19. Offline

    tomjw64

    Books work great. :) And no, keep it like i said, it was just a misunderstanding.

    Also, many of these things could be fixed by using a decent IDE. There are some good AND free ones out there.

    @Digi Sorry for the misunderstanding :p
     
  20. Offline

    Sagacious_Zed Bukkit Docs

    Your not that sure how to construct objects?

    Lets go over basic Java.

    Declaring a variable of type 'ArrayList of String'
    Code:
    ArrayList<String> list;
    Initializing the variable with a new ArrayList of String
    Code:
    list = new ArrayList<String>();
    Initializing the variable with a new ArrayList of String with an initial capacity of 10
    Code:
    list = new ArrayList<String>(10);
    If you want you can declare and initialize in one line.
    Code:
    ArrayList<String> list = new ArrayList<String>();
     
  21. Offline

    544nick101

    Well this is the code i have
    Code:
    ArrayList<String> exempt = new ArrayList<String>();
    
    Isn't that whats suppose to be there?
     
  22. Offline

    Sagacious_Zed Bukkit Docs

    @544nick101
    please not the missing set of parens in my quoted post.
     
Thread Status:
Not open for further replies.

Share This Page