mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 11:06:14 +01:00
Ban certain items from the "My Items" class.
This commit removes certain items from the in-arena inventories of players who choose the "My Items" class: - Ender chests allow players to smuggle stuff out of arenas - Ender pearls can be used to warp to unintended spots, and to build ender chests - Shulker boxes can carry any items - including ender chests - Shulker shells can be used to build shulker boxes At the end of the day, ender chests are the bad seed. The rest are just to prevent ender chests from making appearances.
This commit is contained in:
parent
02f75d0e7f
commit
99f57b7128
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class ArenaClass
|
public class ArenaClass
|
||||||
{
|
{
|
||||||
@ -389,6 +390,7 @@ public class ArenaClass
|
|||||||
if (arena != null) {
|
if (arena != null) {
|
||||||
try {
|
try {
|
||||||
arena.getInventoryManager().restoreInv(p);
|
arena.getInventoryManager().restoreInv(p);
|
||||||
|
removeBannedItems(p.getInventory());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
am.getPlugin().getLogger().severe("Failed to give " + p.getName() + " their own items: " + e.getMessage());
|
am.getPlugin().getLogger().severe("Failed to give " + p.getName() + " their own items: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -399,5 +401,23 @@ public class ArenaClass
|
|||||||
public Location getClassChest() {
|
public Location getClassChest() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeBannedItems(PlayerInventory inv) {
|
||||||
|
ItemStack[] contents = inv.getContents();
|
||||||
|
IntStream.range(0, contents.length)
|
||||||
|
.filter(i -> contents[i] != null)
|
||||||
|
.filter(i -> isBanned(contents[i].getType()))
|
||||||
|
.forEach(inv::clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBanned(Material type) {
|
||||||
|
switch (type) {
|
||||||
|
case ENDER_PEARL:
|
||||||
|
case ENDER_CHEST:
|
||||||
|
case SHULKER_SHELL:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return type.name().endsWith("_SHULKER_BOX");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user