93 lines
2.5 KiB
Java
93 lines
2.5 KiB
Java
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.Listener;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor{
|
|
Set<String> pans = new HashSet<String>();
|
|
public FileConfiguration config;
|
|
//List<PanItem> panitems;
|
|
|
|
@Override
|
|
public void onEnable(){
|
|
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
|
|
public void panEvent(PlayerInteractEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
ItemStack item = event.getItem();
|
|
Action action = event.getAction();
|
|
//check if item is a pan that has been right clicked
|
|
if(item == null || !config.contains("pans."+item.getType().name()) || !action.equals(Action.RIGHT_CLICK_BLOCK))
|
|
return;
|
|
//get pan name
|
|
String name = item.getType().name();
|
|
|
|
new GoldPan(this, player, name);
|
|
}
|
|
|
|
@EventHandler
|
|
public void panClickEvent(InventoryClickEvent event) {
|
|
//check if inventory is a gold pan
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|