Skip to content

Commit 6348326

Browse files
authored
Merge pull request #38 from Tebrox/master
Improved Playersafe in PlayerMenuUtilityMap and PlayerMenuUtility
2 parents 29fdd1f + 6b2fbcd commit 6348326

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/main/java/me/kodysimpson/simpapi/menu/MenuManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
import java.lang.reflect.InvocationTargetException;
1212
import java.util.HashMap;
13+
import java.util.UUID;
1314

1415
/**
1516
* Used to interface with the Menu Manager API
1617
*/
1718
public class MenuManager {
1819

1920
//each player will be assigned their own PlayerMenuUtility object
20-
private static final HashMap<Player, PlayerMenuUtility> playerMenuUtilityMap = new HashMap<>();
21+
private static final HashMap<UUID, PlayerMenuUtility> playerMenuUtilityMap = new HashMap<>();
2122
private static boolean isSetup = false;
2223

2324
private static void registerMenuListener(Server server, Plugin plugin) {
@@ -70,15 +71,15 @@ public static PlayerMenuUtility getPlayerMenuUtility(Player p) throws MenuManage
7071
}
7172

7273
PlayerMenuUtility playerMenuUtility;
73-
if (!(playerMenuUtilityMap.containsKey(p))) { //See if the player has a pmu "saved" for them
74+
if (!(playerMenuUtilityMap.containsKey(p.getUniqueId()))) { //See if the player has a pmu "saved" for them
7475

7576
//Construct PMU
7677
playerMenuUtility = new PlayerMenuUtility(p);
77-
playerMenuUtilityMap.put(p, playerMenuUtility);
78+
playerMenuUtilityMap.put(p.getUniqueId(), playerMenuUtility);
7879

7980
return playerMenuUtility;
8081
} else {
81-
return playerMenuUtilityMap.get(p); //Return the object by using the provided player
82+
return playerMenuUtilityMap.get(p.getUniqueId()); //Return the object by using the provided player
8283
}
8384
}
8485

src/main/java/me/kodysimpson/simpapi/menu/PlayerMenuUtility.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@
77
Each player has one of these objects, and only one.
88
*/
99

10+
import org.bukkit.Bukkit;
1011
import org.bukkit.entity.Player;
1112

1213
import java.util.HashMap;
1314
import java.util.Stack;
15+
import java.util.UUID;
1416

1517
public class PlayerMenuUtility {
1618

17-
private final Player owner;
19+
private final UUID owner;
1820
private final HashMap<String, Object> dataMap = new HashMap<>();
1921
private final Stack<Menu> history = new Stack<>();
2022

2123
public PlayerMenuUtility(Player p) {
22-
this.owner = p;
24+
this.owner = p.getUniqueId();
2325
}
2426

2527
public Player getOwner() {
26-
return owner;
28+
return Bukkit.getPlayer(owner);
2729
}
2830

2931
/**

0 commit comments

Comments
 (0)