Skip to content

Commit 84aca9b

Browse files
committed
Improve Personal EnderChests
1 parent 3075689 commit 84aca9b

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
<dependency>
6060
<groupId>de.marcely.bedwars</groupId>
6161
<artifactId>API</artifactId>
62-
<version>5.0.15</version>
62+
<version>5.2</version>
6363
<scope>system</scope>
6464
<systemPath>${basedir}/libs/private/MBedwars.jar</systemPath>
6565
</dependency>
6666
<dependency>
6767
<groupId>de.marcely.bedwars</groupId>
6868
<artifactId>API</artifactId>
69-
<version>5.1</version>
69+
<version>5.2</version>
7070
</dependency>
7171
-->
7272
<dependency>

src/main/java/me/metallicgoat/tweaksaddon/tweaks/misc/PersonalChests.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,44 @@
2121
import org.bukkit.event.player.PlayerInteractEvent;
2222
import org.bukkit.inventory.Inventory;
2323

24-
import java.util.Collections;
25-
import java.util.HashMap;
26-
import java.util.Map;
24+
import java.util.*;
2725

2826
public class PersonalChests implements Listener {
2927

30-
private static final HashMap<Inventory, Arena> inventoryArenaHashMap = new HashMap<>();
28+
private static final HashMap<Arena, List<Inventory>> inventoryArenaHashMap = new HashMap<>();
3129
private static final HashMap<Player, Block> openChests = new HashMap<>();
3230

3331
@EventHandler
34-
public void onRoundStart(RoundStartEvent event){
35-
if(!ConfigValue.personal_ender_chests_enabled)
32+
public void onRoundStart(RoundStartEvent event) {
33+
if (!ConfigValue.personal_ender_chests_enabled)
3634
return;
3735

3836
final Arena arena = event.getArena();
39-
for(Player player : arena.getPlayers()){
37+
final List<Inventory> inventories = new ArrayList<>();
38+
39+
for (Player player : arena.getPlayers()) {
4040
final Team team = arena.getPlayerTeam(player);
4141
final String teamName = team != null ? ChatColor.stripColor(team.getDisplayName()) : "";
42-
final String teamColor = team != null ? "&" + team.getChatColor().getChar() : "";
42+
final String teamColor = team != null ? "" + team.getBungeeChatColor() : "";
4343
final String chestName = Message.build(ConfigValue.personal_ender_chests_name)
4444
.placeholder("team-name", teamName)
4545
.placeholder("team-color", teamColor)
4646
.done();
4747

48-
final Inventory inventory = Bukkit.createInventory(player, 27, chestName);
49-
inventoryArenaHashMap.put(inventory, arena);
48+
inventories.add(Bukkit.createInventory(player, 27, chestName));
5049
}
50+
51+
inventoryArenaHashMap.put(arena, inventories);
5152
}
5253

5354
@EventHandler
54-
public void onRoundEnd(RoundEndEvent e){
55-
inventoryArenaHashMap.values().removeAll(Collections.singleton(e.getArena()));
55+
public void onRoundEnd(RoundEndEvent event) {
56+
inventoryArenaHashMap.remove(event.getArena());
5657
}
5758

58-
// TODO Do we need to cancel this event?
59-
6059
@EventHandler(priority = EventPriority.HIGH)
61-
public void onChestOpen(PlayerInteractEvent event){
62-
63-
if(!ConfigValue.personal_ender_chests_enabled)
60+
public void onChestOpen(PlayerInteractEvent event) {
61+
if (!ConfigValue.personal_ender_chests_enabled)
6462
return;
6563

6664
final Player player = event.getPlayer();
@@ -69,29 +67,31 @@ public void onChestOpen(PlayerInteractEvent event){
6967

7068
// Check if player is opening chest in an arena
7169
if (arena == null || block == null ||
70+
block.getType() != Material.ENDER_CHEST ||
7271
arena.getStatus() != ArenaStatus.RUNNING ||
7372
event.getAction() != Action.RIGHT_CLICK_BLOCK)
7473
return;
7574

76-
if (block.getType() == Material.ENDER_CHEST) {
77-
for(Map.Entry<Inventory, Arena> entry : inventoryArenaHashMap.entrySet()){
75+
final List<Inventory> inventories = inventoryArenaHashMap.get(arena);
7876

79-
final Inventory inventory = entry.getKey();
77+
if (inventories == null)
78+
return;
8079

81-
if(inventory.getHolder() == player){
82-
BedwarsAPI.getNMSHelper().simulateChestOpening(block);
83-
player.openInventory(inventory);
84-
openChests.put(player, block);
85-
break;
86-
}
80+
for (Inventory inventory : inventories) {
81+
if (inventory.getHolder() == player) {
82+
BedwarsAPI.getNMSHelper().simulateChestOpening(block);
83+
player.openInventory(inventory);
84+
openChests.put(player, block);
85+
break;
8786
}
8887
}
8988
}
9089

9190
@EventHandler
92-
public void onInventoryClose(InventoryCloseEvent e){
91+
public void onInventoryClose(InventoryCloseEvent e) {
9392
final Player player = (Player) e.getPlayer();
94-
if(openChests.containsKey(player)){
93+
94+
if (openChests.containsKey(player)) {
9595
BedwarsAPI.getNMSHelper().simulateChestClosing(openChests.get(player));
9696
openChests.remove(player);
9797
}

0 commit comments

Comments
 (0)