Added way to set DisguiseBlocks and let it choose randomly.
This commit is contained in:
parent
ea8eed6010
commit
f4986f28b2
@ -1,5 +1,7 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaType;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
@ -30,7 +32,7 @@ public class InventoryHandler {
|
||||
Inventory panel = Bukkit
|
||||
.createInventory(
|
||||
null,
|
||||
27,
|
||||
54,
|
||||
MessageM.replaceAll("\u00A7r%N&lSettings of: %A"
|
||||
+ shorten));
|
||||
|
||||
@ -79,6 +81,13 @@ public class InventoryHandler {
|
||||
arena.gameTime);
|
||||
ItemStack gameTime_DOWN = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
|
||||
ItemStack disguiseBlocks_NOTE = new ItemStack(Material.BOOK, 1);
|
||||
ItemMeta disguiseBlocks_NOTE_IM = disguiseBlocks_NOTE.getItemMeta();
|
||||
disguiseBlocks_NOTE_IM.setDisplayName(MessageM
|
||||
.replaceAll("%NSet the %AdisguiseBlocks%N."));
|
||||
disguiseBlocks_NOTE.setItemMeta(disguiseBlocks_NOTE_IM);
|
||||
panel.setItem(37, disguiseBlocks_NOTE);
|
||||
|
||||
//
|
||||
|
||||
updownButton(panel, arena, ArenaType.maxPlayers, "maxPlayers", "1",
|
||||
@ -158,4 +167,25 @@ public class InventoryHandler {
|
||||
panel.setItem(button, BUTTON);
|
||||
panel.setItem(down, DOWN);
|
||||
}
|
||||
|
||||
public static void openDisguiseBlocks(Arena arena, Player player) {
|
||||
String arenaname = arena.arenaName;
|
||||
Inventory panel = Bukkit.createInventory(null, 36,
|
||||
MessageM.replaceAll("\u00A7r%N&lDisguiseBlocks"));
|
||||
|
||||
ItemStack arenaNameNote = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta arenaNameNote_IM = arenaNameNote.getItemMeta();
|
||||
arenaNameNote_IM.setDisplayName(MessageM
|
||||
.replaceAll("%NDisguiseBlocks of arena: %A" + arenaname));
|
||||
ArrayList<String> lores = new ArrayList<String>();
|
||||
lores.add(MessageM
|
||||
.replaceAll("%NPlace the DisguiseBlocks inside this inventory."));
|
||||
arenaNameNote_IM.setLore(lores);
|
||||
arenaNameNote.setItemMeta(arenaNameNote_IM);
|
||||
panel.setItem(0, arenaNameNote);
|
||||
for (int i = arena.disguiseBlocks.size(); i > 0; i = i - 1) {
|
||||
panel.setItem(i, arena.disguiseBlocks.get(i - 1));
|
||||
}
|
||||
player.openInventory(panel);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,15 @@ public class OnInventoryClickEvent implements Listener {
|
||||
Inventory inv = event.getInventory();
|
||||
if (inv.getType().equals(InventoryType.CHEST)) {
|
||||
if (inv.getName().startsWith("\u00A7r")) {
|
||||
if (inv.getName().contains("DisguiseBlocks")) {
|
||||
if (!event.getCurrentItem().getType().isBlock()) {
|
||||
event.setCancelled(true);
|
||||
MessageM.sendFMessage(player,
|
||||
ConfigC.error_setNotABlock, true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
ItemStack item = event.getCurrentItem();
|
||||
String arenaname = inv
|
||||
@ -85,6 +94,12 @@ public class OnInventoryClickEvent implements Listener {
|
||||
|
||||
save(arena);
|
||||
InventoryHandler.openPanel(player, arena.arenaName);
|
||||
|
||||
} else if (item.getType().equals(Material.BOOK)) {
|
||||
if (item.getItemMeta().getDisplayName()
|
||||
.contains("disguiseBlocks")) {
|
||||
InventoryHandler.openDisguiseBlocks(arena, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
package nl.Steffion.BlockHunt.Listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nl.Steffion.BlockHunt.Arena;
|
||||
import nl.Steffion.BlockHunt.ArenaHandler;
|
||||
import nl.Steffion.BlockHunt.W;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class OnInventoryCloseEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onInventoryCloseEvent(InventoryCloseEvent event) {
|
||||
Inventory inv = event.getInventory();
|
||||
if (inv.getType().equals(InventoryType.CHEST)) {
|
||||
if (inv.getName().startsWith("\u00A7r")) {
|
||||
if (inv.getName().contains("DisguiseBlocks")) {
|
||||
String arenaname = inv
|
||||
.getItem(0)
|
||||
.getItemMeta()
|
||||
.getDisplayName()
|
||||
.replaceAll(
|
||||
MessageM.replaceAll("%NDisguiseBlocks of arena: %A"),
|
||||
"");
|
||||
|
||||
Arena arena = null;
|
||||
for (Arena arena2 : W.arenaList) {
|
||||
if (arena2.arenaName.equalsIgnoreCase(arenaname)) {
|
||||
arena = arena2;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ItemStack> blocks = new ArrayList<ItemStack>();
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
if (item != null) {
|
||||
if (!item.getType().equals(Material.PAPER)) {
|
||||
blocks.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arena.disguiseBlocks = blocks;
|
||||
save(arena);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Arena arena) {
|
||||
W.arenas.getFile().set(arena.arenaName, arena);
|
||||
W.arenas.save();
|
||||
ArenaHandler.loadArenas();
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@SerializableAs("Arena")
|
||||
public class ArenaSerializable extends Arena implements
|
||||
@ -18,10 +19,13 @@ public class ArenaSerializable extends Arena implements
|
||||
public ArenaSerializable (String arenaName, LocationSerializable pos1,
|
||||
LocationSerializable pos2, int maxPlayers, int minPlayers,
|
||||
int amountSeekersOnStart, int timeInLobbyUntilStart,
|
||||
int waitingTimeSeeker, int gameTime, List<Player> playersInArena) {
|
||||
int waitingTimeSeeker, int gameTime,
|
||||
ArrayList<ItemStack> disguiseBlocks, List<Player> playersInArena,
|
||||
ArenaState gameState, int timer, List<Player> seekers) {
|
||||
super(arenaName, pos1, pos2, maxPlayers, minPlayers,
|
||||
amountSeekersOnStart, timeInLobbyUntilStart, waitingTimeSeeker,
|
||||
gameTime, playersInArena);
|
||||
gameTime, disguiseBlocks, playersInArena, gameState, timer,
|
||||
seekers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,9 +40,11 @@ public class ArenaSerializable extends Arena implements
|
||||
map.put("timeInLobbyUntilStart", timeInLobbyUntilStart);
|
||||
map.put("waitingTimeSeeker", waitingTimeSeeker);
|
||||
map.put("gameTime", gameTime);
|
||||
map.put("disguiseBlocks", disguiseBlocks);
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ArenaSerializable deserialize(Map<String, Object> map) {
|
||||
LocationSerializable loc = new LocationSerializable(
|
||||
Bukkit.getWorld("world"), 0, 0, 0, 0, 0);
|
||||
@ -50,6 +56,9 @@ public class ArenaSerializable extends Arena implements
|
||||
"amountSeekersOnStart", 1), (Integer) M.g(map,
|
||||
"timeInLobbyUntilStart", 90), (Integer) M.g(map,
|
||||
"waitingTimeSeeker", 20), (Integer) M.g(map,
|
||||
"gameTime", 200), new ArrayList<Player>());
|
||||
"gameTime", 200), (ArrayList<ItemStack>) M.g(map,
|
||||
"disguiseBlocks", new ArrayList<ItemStack>()),
|
||||
new ArrayList<Player>(), ArenaState.WAITING, 0,
|
||||
new ArrayList<Player>());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user