Disable spam clicking
This commit is contained in:
parent
0797d0f9eb
commit
0769d68ded
|
@ -1,44 +1,59 @@
|
|||
package gg.wildfrontier.goldpanning;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
|
||||
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 java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
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;
|
||||
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
|
||||
public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor{
|
||||
HashMap<String, BukkitTask> tasks = new HashMap<String, BukkitTask>();
|
||||
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")) {
|
||||
this.config = getConfig();
|
||||
locadConfig();
|
||||
sender.sendMessage(ChatColor.GREEN+"Reloaded Gold Panning");
|
||||
}
|
||||
return true;
|
||||
|
@ -50,25 +65,28 @@ public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor
|
|||
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();
|
||||
|
||||
this.getLogger().log(Level.INFO, item.toString());
|
||||
|
||||
String name = "Gold Pan";
|
||||
if(config.contains("pans."+item.getType().name()+".name")) {
|
||||
name = config.getString("pans."+item.getType().name()+".name");
|
||||
}
|
||||
new GoldPan(this, player, name);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void panShiftClickEvent(InventoryClickEvent event) {
|
||||
if(event.getView().getTitle() == "Gold Pan" && event.isShiftClick()) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue