DropZone Plugin please help don't ignore!

Discussion in 'Plugin Development' started by Slideroller, Dec 30, 2013.

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

    Slideroller

    Hello I've been given this code and I've been stumped on this code setting on my desk looking arround the code I see no mistakes (well there are some mistakes) the forcedrop commands doesn't actually forcedrop and the intervals aren't working (Bukkit Tasks?)

    Here are all the classes please help

    DROPZONE.JAVA:
    Code:java
    1. package me.slideroller;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Iterator;
    5. import java.util.List;
    6. import java.util.Random;
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Location;
    10. import org.bukkit.Material;
    11. import org.bukkit.Server;
    12. import org.bukkit.World;
    13. import org.bukkit.command.Command;
    14. import org.bukkit.command.CommandSender;
    15. import org.bukkit.command.ConsoleCommandSender;
    16. import org.bukkit.configuration.file.FileConfiguration;
    17. import org.bukkit.enchantments.Enchantment;
    18. import org.bukkit.enchantments.EnchantmentWrapper;
    19. import org.bukkit.entity.Player;
    20. import org.bukkit.inventory.ItemStack;
    21. import org.bukkit.plugin.PluginManager;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23. import org.bukkit.scheduler.BukkitRunnable;
    24. import org.bukkit.scheduler.BukkitScheduler;
    25.  
    26. public class DropZone extends JavaPlugin
    27. {
    28. String prefix = "Meow";
    29. List<Player> droppers = new ArrayList();
    30. Random random = new Random();
    31. boolean dropping = false;
    32. DropListener dl = new DropListener(this);
    33. List<ItemStack> drops = new ArrayList();
    34. int totalDrop = 0;
    35.  
    36. public void onEnable() {
    37. BukkitScheduler scheduler = getServer().getScheduler();
    38. prefix = getConfig().getString("prefix");
    39. prefix = format(prefix);
    40. saveDefaultConfig();
    41. Bukkit.getConsoleSender().sendMessage(prefix + " " + ChatColor.GREEN + "has been enabled!");
    42. scheduler.runTaskLater(this, new PreDrop(this), 20L);
    43. getServer().getPluginManager().registerEvents(dl, this);
    44. }
    45.  
    46. public void onDisable() {
    47. Bukkit.getConsoleSender().sendMessage(prefix + " " + ChatColor.RED + "has been disabled!");
    48. }
    49. public static String format(String format) {
    50. return ChatColor.translateAlternateColorCodes('&', format);
    51. }
    52. public void updateDrops() {
    53. List ids = getConfig().getIntegerList("items");
    54. totalDrop = 0;
    55. for (Iterator localIterator = ids.iterator(); localIterator.hasNext(); ) { int id = ((Integer)localIterator.next()).intValue();
    56. ItemStack dropItem = new ItemStack(id);
    57. drops.add(dropItem);
    58. totalDrop += 1; }
    59. }
    60.  
    61. public ItemStack getDrop() {
    62. updateDrops();
    63. int item = random.nextInt(totalDrop) + 1;
    64. ItemStack newItem = (ItemStack)drops.get(item);
    65. return newItem;
    66. }
    67.  
    68. public ItemStack formatDrop(ItemStack toFormat) {
    69. Material f = toFormat.getType();
    70. ItemStack formatted = toFormat;
    71. Enchantment protection = new EnchantmentWrapper(0);
    72. Enchantment sharpness = new EnchantmentWrapper(16);
    73. Enchantment power = new EnchantmentWrapper(48);
    74. Enchantment flame = Enchantment.FIRE_ASPECT;
    75. Enchantment infinity = new EnchantmentWrapper(51);
    76. int maxLevel = getConfig().getInt("maxLevel");
    77. int useLevel = random.nextInt(maxLevel) + 1;
    78. int chance = random.nextInt(11);
    79. if ((f.equals(Material.DIAMOND_SWORD)) || (f.equals(Material.DIAMOND_AXE))) {
    80. List weaponEnchants = new ArrayList();
    81. weaponEnchants.add(sharpness);
    82. weaponEnchants.add(flame);
    83. Enchantment inUse = (Enchantment)weaponEnchants.get(random.nextInt(weaponEnchants.size()));
    84. formatted.addUnsafeEnchantment(inUse, useLevel);
    85. }
    86. else if ((f.equals(Material.DIAMOND_CHESTPLATE)) || (f.equals(Material.DIAMOND_CHESTPLATE)) || (f.equals(Material.DIAMOND_LEGGINGS)) || (f.equals(Material.DIAMOND_BOOTS))) {
    87. formatted.addUnsafeEnchantment(protection, useLevel);
    88. }
    89. if (chance == 3) {
    90. formatDrop(formatted);
    91. }
    92. return formatted;
    93. }
    94.  
    95. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    96. if ((sender instanceof Player)) {
    97. final Player player = (Player)sender;
    98. if ((cmd.getName().equalsIgnoreCase("max")) && (sender.hasPermission("DropZone.admin"))) {
    99. getConfig().set("drop.maxX", Integer.valueOf(player.getLocation().getBlockX()));
    100. getConfig().set("drop.maxY", Integer.valueOf(player.getLocation().getBlockY()));
    101. getConfig().set("drop.maxZ", Integer.valueOf(player.getLocation().getBlockZ()));
    102. getConfig().set("drop.world", player.getWorld().getName());
    103. saveConfig();
    104. player.sendMessage(prefix + " Max Set!");
    105. return true;
    106. }
    107. if ((cmd.getName().equalsIgnoreCase("min")) && (sender.hasPermission("DropZone.admin"))) {
    108. getConfig().set("drop.minX", Integer.valueOf(player.getLocation().getBlockX()));
    109. getConfig().set("drop.minY", Integer.valueOf(player.getLocation().getBlockY()));
    110. getConfig().set("drop.minZ", Integer.valueOf(player.getLocation().getBlockZ()));
    111. saveConfig();
    112. player.sendMessage(prefix + " Min Set!");
    113. return true;
    114. }
    115. if ((cmd.getName().equalsIgnoreCase("forcedrop")) && (sender.hasPermission("DropZone.admin"))) {
    116. Bukkit.broadcastMessage(prefix + ChatColor.GOLD + " The DropZone will fall in 5 seconds. Do /dropzone now to be taken to the fight!");
    117. Bukkit.broadcastMessage(prefix + ChatColor.GOLD + " The DropZone will fall now!");
    118. Location l = player.getLocation();
    119. l.setX(2090.21546D);
    120. l.setY(119.0D);
    121. l.setZ(-428.38075D);
    122. l.setYaw(179.89999F);
    123. l.setPitch(1.0F);
    124. player.teleport(l);
    125. new BukkitRunnable() {
    126. Drop x = new Drop(new DropZone());
    127.  
    128. public void run() { x.drop(); }
    129. }
    130. .runTaskLater(this, 100L);
    131. return true;
    132. }
    133. if (cmd.getName().equalsIgnoreCase("dropzone")) {
    134. droppers.add(player);
    135. player.sendMessage(prefix + ChatColor.GREEN + " You will be teleported shortly. Watch for an announcement!");
    136. return true;
    137. }
    138. if (cmd.getName().equalsIgnoreCase("wild")) {
    139. int bigX = 0;
    140. int bigZ = 0;
    141. int smallX = 0;
    142. int smallZ = 0;
    143. int maxX = getConfig().getInt("drop.maxX");
    144. int maxZ = getConfig().getInt("drop.maxZ");
    145. int minX = getConfig().getInt("drop.minX");
    146. int minZ = getConfig().getInt("drop.minZ");
    147. if (maxX > minX) {
    148. bigX = maxX;
    149. smallX = minX;
    150. }
    151. else if (maxX < minX) {
    152. bigX = minX;
    153. smallX = maxX;
    154. }
    155. if (maxZ > minZ) {
    156. bigZ = maxZ;
    157. smallZ = minZ;
    158. }
    159. else if (maxZ < minZ) {
    160. bigZ = minZ;
    161. smallZ = maxZ;
    162. }
    163. Random random = new Random();
    164. int dropX = random.nextInt(bigX - smallX + 1) + smallX;
    165. int dropZ = random.nextInt(bigZ - smallZ + 1) + smallZ;
    166. final World dropWorld = Bukkit.getWorld("world");
    167. int dropY = 255;
    168. Location bonerton = new Location(dropWorld, dropX, dropY, dropZ);
    169. final int tpX = dropX + random.nextInt(25);
    170. final int tpZ = dropZ - random.nextInt(25);
    171. final int tpY = dropWorld.getHighestBlockYAt(tpX, tpZ) + 2;
    172. player.sendMessage(ChatColor.GOLD + " Teleporting in 5...");
    173. new BukkitRunnable() {
    174. public void run() {
    175. player.teleport(new Location(dropWorld, tpX, tpY, tpZ));
    176. }
    177. }
    178. .runTaskLater(this, 100L);
    179. }
    180. return true;
    181. }
    182. return false;
    183. }
    184. }

    DROP.JAVA
    Code:java
    1. package me.slideroller;
    2.  
    3. import java.util.List;
    4. import java.util.Random;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.World;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.FallingBlock;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.inventory.ItemStack;
    14.  
    15. public class Drop
    16. {
    17. DropZone plugin;
    18.  
    19. public Drop(DropZone plugin)
    20. {
    21. this.plugin = plugin;
    22. }
    23. public void drop() {
    24. int bigX = 0;
    25. int bigZ = 0;
    26. int smallX = 0;
    27. int smallZ = 0;
    28. int maxX = plugin.getConfig().getInt("drop.maxX");
    29. int maxZ = plugin.getConfig().getInt("drop.maxZ");
    30. int minX = plugin.getConfig().getInt("drop.minX");
    31. int minZ = plugin.getConfig().getInt("drop.minZ");
    32. if (maxX > minX) {
    33. bigX = maxX;
    34. smallX = minX;
    35. }
    36. else if (maxX < minX) {
    37. bigX = minX;
    38. smallX = maxX;
    39. }
    40. if (maxZ > minZ) {
    41. bigZ = maxZ;
    42. smallZ = minZ;
    43. }
    44. else if (maxZ < minZ) {
    45. bigZ = minZ;
    46. smallZ = maxZ;
    47. }
    48. Random random = new Random();
    49. int dropX = random.nextInt(bigX - smallX + 1) + smallX;
    50. int dropY = 255;
    51. int dropZ = random.nextInt(bigZ - smallZ + 1) + smallZ;
    52. World dropWorld = Bukkit.getWorld(plugin.getConfig().getString("drop.world"));
    53. for (Player p : plugin.droppers) {
    54. int tpX = dropX + random.nextInt(25);
    55. int tpZ = dropZ - random.nextInt(25);
    56. int tpY = dropWorld.getHighestBlockYAt(tpX, tpZ) + 2;
    57. p.teleport(new Location(dropWorld, tpX, tpY, tpZ));
    58. }
    59. ItemStack crate = new ItemStack(Material.PISTON_BASE);
    60. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX, dropY - 1, dropZ), crate.getType(), (byte)6).setDropItem(false);
    61. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 3, dropY + 2, dropZ - 3), crate.getType(), (byte)6).setDropItem(false);
    62. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 4, dropY, dropZ + 1), crate.getType(), (byte)6).setDropItem(false);
    63. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 6, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    64. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 2, dropY, dropZ - 2), crate.getType(), (byte)6).setDropItem(false);
    65. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX - 2, dropY, dropZ + 2), crate.getType(), (byte)6).setDropItem(false);
    66. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    67. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 3, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    68. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 4, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    69. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 6, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    70. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 2, dropY, dropZ - 2), crate.getType(), (byte)6).setDropItem(false);
    71. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX - 2, dropY, dropZ + 2), crate.getType(), (byte)6).setDropItem(false);
    72. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    73. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 3, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    74. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 4, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    75. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 6, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    76. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 2, dropY, dropZ - 2), crate.getType(), (byte)6).setDropItem(false);
    77. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX - 2, dropY, dropZ + 2), crate.getType(), (byte)6).setDropItem(false);
    78. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    79. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 3, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    80. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 4, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    81. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 6, dropY, dropZ), crate.getType(), (byte)6).setDropItem(false);
    82. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX + 2, dropY, dropZ - 2), crate.getType(), (byte)6).setDropItem(false);
    83. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX - 3, dropY, dropZ + 2), crate.getType(), (byte)6).setDropItem(false);
    84. dropWorld.spawnFallingBlock(new Location(dropWorld, dropX - 2, dropY, dropZ + 2), crate.getType(), (byte)6).setDropItem(false);
    85. Bukkit.broadcastMessage(plugin.prefix + ChatColor.GREEN + " A dropzone has been called!");
    86. plugin.droppers.clear();
    87. }
    88. }

    DROPLISTENER.JAVA
    Code:java
    1. package me.slideroller;
    2.  
    3. import java.util.Random;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    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.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.Inventory;
    15. import org.bukkit.inventory.ItemStack;
    16.  
    17. public class DropListener
    18. implements Listener
    19. {
    20. private DropZone plugin;
    21.  
    22. public DropListener(DropZone plugin)
    23. {
    24. this.plugin = plugin;
    25. }
    26. @EventHandler
    27. public void onInteract(PlayerInteractEvent boner) {
    28. Player nigwig = boner.getPlayer();
    29. if ((boner.getClickedBlock() instanceof Block)) {
    30. Block clickedBlock = boner.getClickedBlock();
    31. if ((clickedBlock.getType().equals(Material.PISTON_BASE)) && (clickedBlock.getData() == 6)) {
    32. Inventory meowmix = Bukkit.createInventory(nigwig, 9, ChatColor.AQUA + "Care Package");
    33. meowmix.addItem(new ItemStack[] { plugin.formatDrop(plugin.getDrop()) });
    34. nigwig.openInventory(meowmix);
    35. clickedBlock.setType(Material.AIR);
    36. Random random = new Random();
    37. int meow = random.nextInt(11) + 1;
    38. if (meow == 5)
    39. nigwig.getWorld().createExplosion(nigwig.getLocation(), 2.0F, false);
    40. }
    41. }
    42. }
    43.  
    44. @EventHandler
    45. public void onBreak(BlockBreakEvent event)
    46. {
    47. if ((event.getBlock().getType().equals(Material.PISTON_BASE)) && (event.getBlock().getData() == 6))
    48. event.setCancelled(true);
    49. }
    50. }

    PREDROP.JAVA
    Code:java
    1. package me.slideroller;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.configuration.file.FileConfiguration;
    6. import org.bukkit.scheduler.BukkitRunnable;
    7.  
    8. public class PreDrop extends BukkitRunnable
    9. {
    10. DropZone plugin;
    11.  
    12. public PreDrop(DropZone plugin)
    13. {
    14. this.plugin = plugin;
    15. }
    16. public static String format(String format) {
    17. return ChatColor.translateAlternateColorCodes('&', format);
    18. }
    19.  
    20. public void run() {
    21. final String countdowns = plugin.getConfig().getString("countdown");
    22. String teleport = plugin.getConfig().getString("teleport");
    23. long dropInterval = plugin.getConfig().getLong("interval");
    24. teleport = format(teleport);
    25. int ii = 72000;
    26. new BukkitRunnable() {
    27. int i = 7200;
    28.  
    29. public void run() { String countdown = PreDrop.format(countdowns);
    30. i -= 1;
    31. if (i == 300) {
    32. Bukkit.broadcastMessage(plugin.prefix + " " + countdown + ChatColor.GREEN + " 5 minutes! Type " + ChatColor.AQUA + "/dropzone" + ChatColor.GREEN + " to be teleported when it arrives!");
    33. }
    34. if (i == 180) {
    35. Bukkit.broadcastMessage(plugin.prefix + " " + countdown + ChatColor.GREEN + " 3 minutes! Type " + ChatColor.AQUA + "/dropzone" + ChatColor.GREEN + " to be teleported when it arrives!");
    36. }
    37. if (i == 60) {
    38. Bukkit.broadcastMessage(plugin.prefix + " " + countdown + ChatColor.GREEN + " 1 minute! Type " + ChatColor.AQUA + "/dropzone" + ChatColor.GREEN + " to be teleported when it arrives!");
    39. }
    40. if (i == 30) {
    41. Bukkit.broadcastMessage(plugin.prefix + " " + countdown + ChatColor.GREEN + " 30 seconds! Type " + ChatColor.AQUA + "/dropzone" + ChatColor.GREEN + " to be teleported soon!");
    42. }
    43. if (i == 10) {
    44. Bukkit.broadcastMessage(plugin.prefix + " " + countdown + ChatColor.GREEN + " 10 seconds! Type " + ChatColor.AQUA + "/dropzone" + ChatColor.GREEN + " to be teleported soon!");
    45. }
    46. if (i == 5) {
    47. Bukkit.broadcastMessage(plugin.prefix + " " + countdown + ChatColor.GREEN + " 5 seconds! Type " + ChatColor.AQUA + "/dropzone" + ChatColor.GREEN + " to be teleported soon!");
    48. }
    49. if (i == 1) {
    50. Bukkit.broadcastMessage(plugin.prefix + " " + ChatColor.GREEN + "Teleporting now!");
    51. }
    52. if (i == 0) {
    53. new Drop(plugin).drop();
    54. i = 600;
    55. } }
    56. }
    57. .runTaskTimer(plugin, 20L, 20L);
    58. }
    59. }


    Like I've said before I've been stumped looking arround the code for 2 whole days. Please help if you have the time help me fix my errors within the code? or send me the fixed versions (not trying to sound greedy just tired of looking at the code).

    Thanks, Slideroller
     
  2. Offline

    inventorman101 Retired Staff

  3. Offline

    Slideroller

    Huh? (I know few stuff on coding)
     
  4. Offline

    inventorman101 Retired Staff

  5. Offline

    Slideroller

    Yeah I can tell that theres lots of errors within the code but I need it fixed :I it was working fine for 1.6.4 atleast this is what I was told.
     
  6. Offline

    inventorman101 Retired Staff

  7. Offline

    Slideroller

    Yes it does it runs but it doesn't perform what the code is told to (the forcedrop command)
     
  8. Offline

    inventorman101 Retired Staff

  9. Offline

    HyrulesLegend

    Show us the error in console.
     
  10. Offline

    Slideroller

    http://puu.sh/64fo4.png There's some errors.

    http://puu.sh/64fo4.png

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

    JRL1004

    Slideroller
    your error is on line 28 of Drop.Java (and will most likely occur on the two lines folliowng that as well)
    plugin.getConfig().<whatever> is returning null on the file. make sure that the config you are trying to pull information from exists before calling it.
     
  12. Offline

    Slideroller

    Er, I really don't know much about configs,bukkit tasks,timers that sort of stuff so I don't know what to do in plugin.getConfig().<whatever> all the knowledge I know about configs is to reload them.
     
  13. Offline

    AoH_Ruthless

  14. Offline

    WhippyCleric

    1. Make sure you have config.yml file (this should be in the same location as your plugin.yml , see AoH_Ruthless link for more details
    2. In your onEnable method add the following line:
    Code:
    saveDefaultConfig()
     
  15. Offline

    Slideroller

    Thanks, now to find out the error on line 28 still quite stumped.
    I'll look into it.
     
  16. Offline

    WhippyCleric

    The error on line 28 is because the config.yml file does not exist. Once you have created it and saved it you should no longer get this error
     
  17. Offline

    Slideroller

    So just add the code saveDefaultConfig(); ?
     
  18. Offline

    WhippyCleric

    And create a config.yml file at the same location asyour plugin.yml
     
  19. Offline

    Slideroller

    I did should all be all set?
     
  20. Offline

    WhippyCleric

    Give it a try and let us know if it works. If not please post an updated stack trace
     
  21. Offline

    Slideroller

    Just realized it was already saveDefaultConfig(); in onEnable and the config was already made where the plugin.yml is.

    Read Above

    Anybody else have ideas?

    Sort of figured everything is now working EXCEPT for the /forcedrop :I any clues?

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

    AoH_Ruthless

    Slideroller
    You have to tell us what isn't working (along with a stacktrace).
     
  23. Offline

    Slideroller

  24. Offline

    xTigerRebornx

    Slideroller you should really learn how to read stacktraces
    Code:
        new BukkitRunnable() {
              Drop x = new Drop(new DropZone());
     
              public void run() { x.drop(); }
            }
    You are making a new instance of your plugin, which will have no config file. use "this" instead of new DropZone();, you should never create a new instance of your plugin.
     
Thread Status:
Not open for further replies.

Share This Page