package gg.wildfrontier.goldpanning; import java.util.HashSet; import java.util.Set; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; 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 pans = new HashSet(); public FileConfiguration config; //List 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(); Block block = event.getClickedBlock().getRelative(event.getBlockFace()); //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; //check water is clicked if(block.getType() != Material.WATER) 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); } } }