Pan only work on water

This commit is contained in:
Jimmy 2021-05-19 17:43:58 +12:00
parent 8e6dcee55f
commit 064321ffd2
1 changed files with 8 additions and 11 deletions

View File

@ -1,16 +1,13 @@
package gg.wildfrontier.goldpanning; package gg.wildfrontier.goldpanning;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -24,8 +21,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor{ public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor{
Set<String> pans = new HashSet<String>(); Set<String> pans = new HashSet<String>();
public FileConfiguration config; public FileConfiguration config;
@ -36,8 +31,6 @@ public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor
getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(this, this);
saveDefaultConfig(); saveDefaultConfig();
locadConfig(); locadConfig();
} }
private void locadConfig() { private void locadConfig() {
@ -61,13 +54,18 @@ public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor
@EventHandler @EventHandler
public void panEvent(PlayerInteractEvent event) { public void panEvent(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = event.getItem(); ItemStack item = event.getItem();
Action action = event.getAction(); Action action = event.getAction();
Block block = event.getClickedBlock().getRelative(event.getBlockFace());
//check if item is a pan that has been right clicked //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)) if(item == null || !config.contains("pans."+item.getType().name()) || !action.equals(Action.RIGHT_CLICK_BLOCK))
return; return;
//check water is clicked
if(block.getType() != Material.WATER)
return;
//get pan name //get pan name
String name = item.getType().name(); String name = item.getType().name();
@ -86,7 +84,6 @@ public class GoldPanning extends JavaPlugin implements Listener, CommandExecutor
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }