So I'm experimenting with hashmaps/sets and I can't get my event class to recognize the contents of my hashset. The toggle command works (identifies and sends back correct results of if the player is in the set or not) but, the event when I cast the rod always returns the else part of the code (always stating false) rather than using the data from the set to check if the player is there or not. (code will be below)
Yes my events and commands are all registered
What I've tried
changing players.add(p.getUniqueId()); to players.add(p.getName()); and vice versa multiple if statements random small changes to how the hashset is created/checked
Code:
TOGGLE COMMAND*
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.UUID;
public class HashCommand implements CommandExecutor {
HashSet<UUID> players = new HashSet<UUID>();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage("Players Only");
}else{
Player p = (Player) sender;
boolean check = players.contains(p.getUniqueId());
if(!check){
players.add(p.getUniqueId());
p.sendMessage("Toggled On");
}else{
players.remove(p.getUniqueId());
p.sendMessage("Toggled Off");
}
}
return false;
}
}
EVENT COMMAND
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerFishEvent;
public class Event implements Listener {
public HashCommand hashCommand = new HashCommand();
@EventHandler
public void onCast(PlayerFishEvent e){
Player p = e.getPlayer();
if (hashCommand.players.contains(p.getUniqueId())) {
p.sendMessage("Fish");
}else{
p.sendMessage("You do not have it enabled!");
}
}
}