From f231eb7237a0f51ea5d2ca63f5bcbb83be3d3673 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 21 Apr 2021 20:43:02 +1200 Subject: [PATCH] Changed name --- .../gg/wildfrontier/goldpanning/GoldPan.java | 79 +++++++++++++++++++ .../wildfrontier/goldpanning/PopulatePan.java | 51 ------------ 2 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 src/main/java/gg/wildfrontier/goldpanning/GoldPan.java delete mode 100644 src/main/java/gg/wildfrontier/goldpanning/PopulatePan.java diff --git a/src/main/java/gg/wildfrontier/goldpanning/GoldPan.java b/src/main/java/gg/wildfrontier/goldpanning/GoldPan.java new file mode 100644 index 0000000..e847cb0 --- /dev/null +++ b/src/main/java/gg/wildfrontier/goldpanning/GoldPan.java @@ -0,0 +1,79 @@ +package gg.wildfrontier.goldpanning; +import java.io.Console; +import java.util.logging.Level; + +import org.bukkit.Bukkit; +import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.Material; + +public class GoldPan implements Runnable { + JavaPlugin plugin; + Inventory goldpan; + Player player; + int count = 0; + int maxcount; + public GoldPan(JavaPlugin plugin, Player player, String name) { + this.plugin = plugin; + this.player = player; + this.maxcount = (int)(Math.random()*50+5); + + this.goldpan = Bukkit.createInventory(this.player, 54, name); + this.player.openInventory(this.goldpan); + run(); + } + + public void run() { + ItemStack goldnugget = new ItemStack(Material.getMaterial("GOLD_NUGGET"), 1); + ItemStack gravel = new ItemStack(Material.GRAVEL, 1); + + if(count>maxcount) { + player.closeInventory(); + return; + } + + int slot = (int)(Math.random()*54); + if((Math.random()*100)<75) { + new AddItem(slot, goldnugget); + } + slot = (int)(Math.random()*54); + if((Math.random()*100)<90) { + new AddItem(slot, gravel); + } + Bukkit.getScheduler().runTaskLater(plugin, this, (int)(Math.random()*25+5)); + plugin.getLogger().log(Level.INFO, String.valueOf(count)); + count++; + } + + private class AddItem implements Runnable { + int slot; + ItemStack item; + private AddItem(int slot, ItemStack item) { + this.slot = slot; + this.item = item; + Bukkit.getScheduler().runTaskLater(plugin, this, (int)(Math.random()*25+5)); + } + public void run() { + goldpan.setItem(slot, item); + new RemoveItem(slot); + } + } + + private class RemoveItem implements Runnable { + int slot; + private RemoveItem(int slot) { + this.slot = slot; + Bukkit.getScheduler().runTaskLater(plugin, this, (int)(Math.random()*25+5)); + } + public void run() { + goldpan.setItem(slot, null); + + } + } + + +} diff --git a/src/main/java/gg/wildfrontier/goldpanning/PopulatePan.java b/src/main/java/gg/wildfrontier/goldpanning/PopulatePan.java deleted file mode 100644 index 45ce026..0000000 --- a/src/main/java/gg/wildfrontier/goldpanning/PopulatePan.java +++ /dev/null @@ -1,51 +0,0 @@ -package gg.wildfrontier.goldpanning; -import java.io.Console; -import java.util.logging.Level; - -import org.bukkit.Bukkit; -import org.bukkit.inventory.Inventory; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.Material; - -public class PopulatePan implements Runnable { - JavaPlugin plugin; - Inventory goldpan; - Player player; - int count = 0; - int maxcount; - int lastslot; - public PopulatePan(JavaPlugin plugin, Inventory goldpan, Player player) { - this.plugin = plugin; - this.goldpan = goldpan; - this.player = player; - maxcount = (int)(Math.random()*50+5); - run(); - } - - public void run() { - ItemStack goldnugget = new ItemStack(Material.GOLD_NUGGET, 1); - int slot = (int)(Math.random()*54); - goldpan.setItem(lastslot, null); - lastslot = slot; - goldpan.setItem(slot, goldnugget); - if(count>maxcount) { - player.closeInventory(); - return; - } - int delay = (int)(Math.random()*25+5); - Bukkit.getScheduler().runTaskLater(plugin, this, delay); - - plugin.getLogger().log(Level.INFO, String.valueOf(count)); - count++; - - - - } - - - -}