Basically in my plugin when a player clicks i kit i make it change the state which changes the scoreboard to pvp mode but its not separate to the player here is my code of trying to set a individual player state Code (Text): package gg.kisurimc.kitpvp.state; import java.util.UUID; public enum PlayerState { LOBBY, FIGHTING, PRAC_LOBBY, PRAC_FIGHTING; private static PlayerState currentState; public static PlayerState setType(PlayerState state, UUID uuid) { return PlayerState.currentState = state; } public static PlayerState getState(UUID uuid) { return currentState; } }
Do you know the meaning of the word static ? https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html private static PlayerState currentState; This will be shared across all instances it it will be the same. If i was you i would have 2 classes.. Your enum and a "Manager Class" In the manager class add a NON static hashmap called "States" storing <PlayerUUID,StateEnum> When when you need to set a player state ad it to the hashmap with there uuid and the state you can also then get the state back after the event.
Ive tried using hashmaps and it still made it so both player have a the same scoreboard and its not separate
Like this.. ? Code (Java): public enum States { One,Two,Three; } public class Manager { HashMap<UUID, States> playerStates = new HashMap<>(); public void SetState(UUID playerUUID, States state) { playerStates.put(playerUUID, state ); } public void GetState(UUID playerUUID) { playerStates.getOrDefault(playerUUID, States.One); //States.One in the above line is the DEFAULT value if the player has not had a state set. } }
Ok would this would when doing something like if(Manager.playerstates.getState(playernlaha) == State.one) { //do this? }
I really don't want to start I fight as I know there are many think I shouldn't say this, but please learn JAVA: HashMaps and the meaning of the word static are basic concepts.