Changed name

This commit is contained in:
Jimmy 2021-04-21 20:43:02 +12:00
parent a10d758a5c
commit f231eb7237
2 changed files with 79 additions and 51 deletions

View File

@ -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);
}
}
}

View File

@ -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++;
}
}