Compare commits
8 Commits
c9e95ec8cd
...
8e6dcee55f
Author | SHA1 | Date |
---|---|---|
Jimmy | 8e6dcee55f | |
Jimmy | 0769d68ded | |
Jimmy | 0797d0f9eb | |
Jimmy | d18c504825 | |
Jimmy | 7df836845d | |
Jimmy | f231eb7237 | |
Jimmy | a10d758a5c | |
Jimmy | 2edee3cc1a |
|
@ -0,0 +1,97 @@
|
||||||
|
package gg.wildfrontier.goldpanning;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class GoldPan implements Runnable {
|
||||||
|
JavaPlugin plugin;
|
||||||
|
Inventory goldpan;
|
||||||
|
String pan;
|
||||||
|
Player player;
|
||||||
|
int count = 0;
|
||||||
|
int cycles, delaymin, delaymax;
|
||||||
|
List<PanItem> items = new ArrayList<PanItem>();
|
||||||
|
public GoldPan(JavaPlugin plugin, Player player, String pan) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.player = player;
|
||||||
|
this.pan = pan;
|
||||||
|
int cyclesmin = plugin.getConfig().getInt("cycles.min");
|
||||||
|
int cyclesmax = plugin.getConfig().getInt("cycles.max");
|
||||||
|
this.cycles = (int)(Math.random()*cyclesmax+cyclesmin);
|
||||||
|
this.delaymin = plugin.getConfig().getInt("cycles.delaymin");
|
||||||
|
this.delaymax = plugin.getConfig().getInt("cycles.delaymax");
|
||||||
|
|
||||||
|
ConfigurationSection items = plugin.getConfig().getConfigurationSection("pans."+pan+".items");
|
||||||
|
for (String item : items.getKeys(false)) {
|
||||||
|
int chance = plugin.getConfig().getInt("pans."+pan+".items."+item+".chance");
|
||||||
|
int adddelaymin = plugin.getConfig().getInt("pans."+pan+".items."+item+".delay.add.min");
|
||||||
|
int adddelaymax = plugin.getConfig().getInt("pans."+pan+".items."+item+".delay.add.max");
|
||||||
|
int removedelaymin = plugin.getConfig().getInt("pans."+pan+".items."+item+".delay.remove.min");
|
||||||
|
int removedelaymax = plugin.getConfig().getInt("pans."+pan+".items."+item+".delay.remove.max");
|
||||||
|
plugin.getLogger().log(Level.INFO, item+String.valueOf(chance));
|
||||||
|
this.items.add(new PanItem(item, chance, adddelaymin, adddelaymax,
|
||||||
|
removedelaymin, removedelaymax));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//create and open an inventory
|
||||||
|
String displayname = plugin.getConfig().getString("pans."+pan+".name");
|
||||||
|
this.goldpan = Bukkit.createInventory(this.player, 54, displayname);
|
||||||
|
this.player.openInventory(this.goldpan);
|
||||||
|
//kick it off
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
if(count>cycles) {
|
||||||
|
player.closeInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (PanItem item : this.items) {
|
||||||
|
int slot = (int)(Math.random()*54);
|
||||||
|
if(item.spawn()) {
|
||||||
|
new AddItem(slot, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, this, (int)(Math.random()*delaymax+delaymin));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AddItem implements Runnable {
|
||||||
|
int slot;
|
||||||
|
PanItem item;
|
||||||
|
private AddItem(int slot, PanItem item) {
|
||||||
|
this.slot = slot;
|
||||||
|
this.item = item;
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, this, item.getAddDelay());
|
||||||
|
}
|
||||||
|
public void run() {
|
||||||
|
goldpan.setItem(slot, item);
|
||||||
|
new RemoveItem(slot, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RemoveItem implements Runnable {
|
||||||
|
int slot;
|
||||||
|
private RemoveItem(int slot, PanItem item) {
|
||||||
|
this.slot = slot;
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, this, item.getRemoveDelay());
|
||||||
|
}
|
||||||
|
public void run() {
|
||||||
|
goldpan.setItem(slot, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,33 +1,62 @@
|
||||||
package gg.wildfrontier.goldpanning;
|
package gg.wildfrontier.goldpanning;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class GoldPanning extends JavaPlugin implements Listener{
|
|
||||||
HashMap<String, BukkitTask> tasks = new HashMap<String, BukkitTask>();
|
|
||||||
@Override
|
public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor{
|
||||||
|
Set<String> pans = new HashSet<String>();
|
||||||
|
public FileConfiguration config;
|
||||||
|
//List<PanItem> panitems;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
saveDefaultConfig();
|
||||||
|
locadConfig();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void locadConfig() {
|
||||||
|
this.config = getConfig();
|
||||||
|
//get all of the pan names from the config and store the for panClickEvent
|
||||||
|
ConfigurationSection sec = getConfig().getConfigurationSection("pans");
|
||||||
|
for (String key : sec.getKeys(false)) {
|
||||||
|
String panname = "pans."+key+".name";
|
||||||
|
pans.add(config.getString(panname));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if(command.getName().equals("gpreload")) {
|
||||||
|
locadConfig();
|
||||||
|
sender.sendMessage(ChatColor.GREEN+"Reloaded Gold Panning");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -36,26 +65,28 @@ public class GoldPanning extends JavaPlugin implements Listener{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
Action action = event.getAction();
|
Action action = event.getAction();
|
||||||
if(item == null || !item.getType().equals(Material.BOWL) || !action.equals(Action.RIGHT_CLICK_BLOCK))
|
//check if item is a pan that has been right clicked
|
||||||
return;
|
if(item == null || !config.contains("pans."+item.getType().name()) || !action.equals(Action.RIGHT_CLICK_BLOCK))
|
||||||
|
return;
|
||||||
|
//get pan name
|
||||||
|
String name = item.getType().name();
|
||||||
|
|
||||||
this.getLogger().log(Level.INFO, item.toString());
|
new GoldPan(this, player, name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Inventory goldpan = Bukkit.createInventory(player, 54, "Gold Pan");
|
|
||||||
player.openInventory(goldpan);
|
|
||||||
|
|
||||||
new PopulatePan(this, goldpan, player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void panShiftClickEvent(InventoryClickEvent event) {
|
public void panClickEvent(InventoryClickEvent event) {
|
||||||
if(event.getView().getTitle() == "Gold Pan" && event.isShiftClick()) {
|
//check if inventory is a gold pan
|
||||||
event.setCancelled(true);
|
if(pans.contains(event.getView().getTitle())) {
|
||||||
|
//disable shift click
|
||||||
|
if(event.isShiftClick())
|
||||||
|
event.setCancelled(true);
|
||||||
|
//stop spam clicking
|
||||||
|
else if(event.getAction().equals(InventoryAction.COLLECT_TO_CURSOR))
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package gg.wildfrontier.goldpanning;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class PanItem extends ItemStack{
|
||||||
|
int chance, adddelaymin, adddelaymax, removedelaymin, removedelaymax;
|
||||||
|
public PanItem(String material, int chance, int adddelaymin, int adddelaymax, int removedelaymin, int removedelaymax) {
|
||||||
|
super(Material.getMaterial(material), 1);
|
||||||
|
this.chance = chance;
|
||||||
|
this.adddelaymin = adddelaymin;
|
||||||
|
this.adddelaymax = adddelaymax;
|
||||||
|
this.removedelaymin = removedelaymin;
|
||||||
|
this.removedelaymax = removedelaymax;
|
||||||
|
|
||||||
|
}
|
||||||
|
public Boolean spawn() {
|
||||||
|
return (Math.random()*100)<chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAddDelay() {
|
||||||
|
return (int) (Math.random()*adddelaymax+adddelaymin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRemoveDelay() {
|
||||||
|
return (int) (Math.random()*removedelaymax+removedelaymin);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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++;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
cycles:
|
||||||
|
min: 5
|
||||||
|
max: 50
|
||||||
|
delaymin: 5
|
||||||
|
delaymax: 50
|
||||||
|
|
||||||
|
pans:
|
||||||
|
BOWL:
|
||||||
|
name: Wooden Pan
|
||||||
|
items:
|
||||||
|
GOLD_NUGGET:
|
||||||
|
chance: 50
|
||||||
|
delay:
|
||||||
|
add:
|
||||||
|
min: 5
|
||||||
|
max: 20
|
||||||
|
remove:
|
||||||
|
min: 5
|
||||||
|
max: 20
|
||||||
|
GRAVEL:
|
||||||
|
chance: 100
|
||||||
|
delay:
|
||||||
|
add:
|
||||||
|
min: 5
|
||||||
|
max: 20
|
||||||
|
remove:
|
||||||
|
min: 5
|
||||||
|
max: 20
|
|
@ -6,28 +6,14 @@ author: ${author}
|
||||||
website: ${url}
|
website: ${url}
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
spawn:
|
gpreload:
|
||||||
description: Teleports you to spawn
|
description: Reloads Gold Panning Config
|
||||||
usage: /spawn
|
usage: /gpreload
|
||||||
permission: easyspawn.spawn
|
permission: goldpanning.reload
|
||||||
permission-message: You are not allowed
|
permission-message: You are not allowed to reload Gold Panning
|
||||||
bed:
|
|
||||||
description: Teleports you to your bed
|
|
||||||
usage: /bed
|
|
||||||
permission: easyspawn.bed
|
|
||||||
permission-message: You are not allowed
|
|
||||||
setspawn:
|
|
||||||
description: Sets spawn location
|
|
||||||
usage: /setspawn
|
|
||||||
permission: easyspawn.setspawn
|
|
||||||
permission-message: You are not allowed
|
|
||||||
permissions:
|
permissions:
|
||||||
easyspawn.spawn:
|
goldpanning.reload:
|
||||||
description: Teleports you to spawn
|
description: Reloads Gold Panning Config
|
||||||
default: true
|
|
||||||
easyspawn.bed:
|
|
||||||
description: Teleports you to your bed
|
|
||||||
default: true
|
|
||||||
easyspawn.setspawn:
|
|
||||||
description: Sets spawn location
|
|
||||||
default: op
|
default: op
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue