Updated set command.
This commit is contained in:
parent
39e1f134a6
commit
675c1cba19
@ -1,5 +1,6 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaType;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
|
||||
@ -14,7 +15,14 @@ public class InventoryHandler {
|
||||
|
||||
public static void openPanel(Player player, String arenaname) {
|
||||
String shorten = arenaname;
|
||||
if (W.arenas.getFile().getString(arenaname) != null) {
|
||||
Arena arena = null;
|
||||
for (Arena arena2 : W.arenaList) {
|
||||
if (arena2.arenaName.equalsIgnoreCase(arenaname)) {
|
||||
arena = arena2;
|
||||
}
|
||||
}
|
||||
|
||||
if (arena != null) {
|
||||
if (shorten.length() > 6)
|
||||
shorten = shorten.substring(0, 6);
|
||||
Inventory panel = Bukkit
|
||||
@ -25,66 +33,64 @@ public class InventoryHandler {
|
||||
+ shorten));
|
||||
ItemStack maxPlayers_UP = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
ItemStack maxPlayers = new ItemStack(Material.PISTON_MOVING_PIECE,
|
||||
W.arenas.getFile().getInt(arenaname + ".maxPlayers"));
|
||||
arena.maxPlayers);
|
||||
ItemStack maxPlayers_DOWN = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
|
||||
ItemStack minPlayers_UP = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
ItemStack minPlayers = new ItemStack(Material.PISTON_MOVING_PIECE,
|
||||
W.arenas.getFile().getInt(arenaname + ".minPlayers"));
|
||||
arena.minPlayers);
|
||||
ItemStack minPlayers_DOWN = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
|
||||
ItemStack amountSeekersOnStart_UP = new ItemStack(
|
||||
Material.GOLD_NUGGET, 1);
|
||||
ItemStack amountSeekersOnStart = new ItemStack(
|
||||
Material.PISTON_MOVING_PIECE, W.arenas.getFile().getInt(
|
||||
arenaname + ".amountSeekersOnStart"));
|
||||
Material.PISTON_MOVING_PIECE, arena.amountSeekersOnStart);
|
||||
ItemStack amountSeekersOnStart_DOWN = new ItemStack(
|
||||
Material.GOLD_NUGGET, 1);
|
||||
|
||||
ItemStack timeInLobbyUntilStart_UP = new ItemStack(
|
||||
Material.GOLD_NUGGET, 1);
|
||||
ItemStack timeInLobbyUntilStart = new ItemStack(
|
||||
Material.PISTON_MOVING_PIECE, W.arenas.getFile().getInt(
|
||||
arenaname + ".timeInLobbyUntilStart"));
|
||||
Material.PISTON_MOVING_PIECE, arena.timeInLobbyUntilStart);
|
||||
ItemStack timeInLobbyUntilStart_DOWN = new ItemStack(
|
||||
Material.GOLD_NUGGET, 1);
|
||||
|
||||
ItemStack waitingTimeSeeker_UP = new ItemStack(
|
||||
Material.GOLD_NUGGET, 1);
|
||||
ItemStack waitingTimeSeeker = new ItemStack(
|
||||
Material.PISTON_MOVING_PIECE, W.arenas.getFile().getInt(
|
||||
arenaname + ".waitingTimeSeeker"));
|
||||
Material.PISTON_MOVING_PIECE, arena.waitingTimeSeeker);
|
||||
ItemStack waitingTimeSeeker_DOWN = new ItemStack(
|
||||
Material.GOLD_NUGGET, 1);
|
||||
|
||||
ItemStack gameTime_UP = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
ItemStack gameTime = new ItemStack(Material.PISTON_MOVING_PIECE,
|
||||
W.arenas.getFile().getInt(arenaname + ".gameTime"));
|
||||
arena.gameTime);
|
||||
ItemStack gameTime_DOWN = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
|
||||
//
|
||||
|
||||
updownButton(panel, arenaname, "maxPlayers", "1", maxPlayers_UP,
|
||||
maxPlayers, maxPlayers_DOWN, 0, 9, 18);
|
||||
updownButton(panel, arena, ArenaType.maxPlayers, "maxPlayers", "1",
|
||||
maxPlayers_UP, maxPlayers, maxPlayers_DOWN, 0, 9, 18);
|
||||
|
||||
updownButton(panel, arenaname, "minPlayers", "1", minPlayers_UP,
|
||||
minPlayers, minPlayers_DOWN, 1, 10, 19);
|
||||
updownButton(panel, arena, ArenaType.minPlayers, "minPlayers", "1",
|
||||
minPlayers_UP, minPlayers, minPlayers_DOWN, 1, 10, 19);
|
||||
|
||||
updownButton(panel, arenaname, "amountSeekersOnStart", "1",
|
||||
amountSeekersOnStart_UP, amountSeekersOnStart,
|
||||
amountSeekersOnStart_DOWN, 3, 12, 21);
|
||||
updownButton(panel, arena, ArenaType.amountSeekersOnStart,
|
||||
"amountSeekersOnStart", "1", amountSeekersOnStart_UP,
|
||||
amountSeekersOnStart, amountSeekersOnStart_DOWN, 3, 12, 21);
|
||||
|
||||
updownButton(panel, arenaname, "timeInLobbyUntilStart",
|
||||
"1 %Nsecond", timeInLobbyUntilStart_UP,
|
||||
timeInLobbyUntilStart, timeInLobbyUntilStart_DOWN, 5, 14,
|
||||
23);
|
||||
updownButton(panel, arena, ArenaType.timeInLobbyUntilStart,
|
||||
"timeInLobbyUntilStart", "1 %Nsecond",
|
||||
timeInLobbyUntilStart_UP, timeInLobbyUntilStart,
|
||||
timeInLobbyUntilStart_DOWN, 5, 14, 23);
|
||||
|
||||
updownButton(panel, arenaname, "waitingTimeSeeker", "1 %Nsecond",
|
||||
waitingTimeSeeker_UP, waitingTimeSeeker,
|
||||
waitingTimeSeeker_DOWN, 6, 15, 24);
|
||||
updownButton(panel, arena, ArenaType.waitingTimeSeeker,
|
||||
"waitingTimeSeeker", "1 %Nsecond", waitingTimeSeeker_UP,
|
||||
waitingTimeSeeker, waitingTimeSeeker_DOWN, 6, 15, 24);
|
||||
|
||||
updownButton(panel, arenaname, "gameTime", "1 %Nsecond",
|
||||
gameTime_UP, gameTime, gameTime_DOWN, 7, 16, 25);
|
||||
updownButton(panel, arena, ArenaType.gameTime, "gameTime",
|
||||
"1 %Nsecond", gameTime_UP, gameTime, gameTime_DOWN, 7, 16,
|
||||
25);
|
||||
|
||||
player.openInventory(panel);
|
||||
} else {
|
||||
@ -93,7 +99,7 @@ public class InventoryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updownButton(Inventory panel, String arenaname,
|
||||
public static void updownButton(Inventory panel, Arena arena, ArenaType at,
|
||||
String option, String addremove, ItemStack UP, ItemStack BUTTON,
|
||||
ItemStack DOWN, int up, int button, int down) {
|
||||
ItemMeta UP_IM = UP.getItemMeta();
|
||||
@ -102,10 +108,32 @@ public class InventoryHandler {
|
||||
"2-" + option));
|
||||
UP.setItemMeta(UP_IM);
|
||||
|
||||
int setting = 0;
|
||||
switch (at) {
|
||||
case maxPlayers:
|
||||
setting = arena.maxPlayers;
|
||||
break;
|
||||
case minPlayers:
|
||||
setting = arena.minPlayers;
|
||||
break;
|
||||
case amountSeekersOnStart:
|
||||
setting = arena.amountSeekersOnStart;
|
||||
break;
|
||||
case timeInLobbyUntilStart:
|
||||
setting = arena.timeInLobbyUntilStart;
|
||||
break;
|
||||
case waitingTimeSeeker:
|
||||
setting = arena.waitingTimeSeeker;
|
||||
break;
|
||||
case gameTime:
|
||||
setting = arena.gameTime;
|
||||
break;
|
||||
}
|
||||
|
||||
ItemMeta BUTTON_IM = BUTTON.getItemMeta();
|
||||
BUTTON_IM.setDisplayName(MessageM.replaceAll(
|
||||
(String) W.messages.get(ConfigC.button_setting), "1-" + option,
|
||||
"2-" + W.arenas.getFile().getString(arenaname + "." + option)));
|
||||
"2-" + setting));
|
||||
BUTTON.setItemMeta(BUTTON_IM);
|
||||
|
||||
ItemMeta DOWN_IM = DOWN.getItemMeta();
|
||||
|
@ -1,5 +1,8 @@
|
||||
package nl.Steffion.BlockHunt.Listeners;
|
||||
|
||||
import nl.Steffion.BlockHunt.Arena;
|
||||
import nl.Steffion.BlockHunt.Arena.ArenaType;
|
||||
import nl.Steffion.BlockHunt.ArenaHandler;
|
||||
import nl.Steffion.BlockHunt.InventoryHandler;
|
||||
import nl.Steffion.BlockHunt.W;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
@ -28,6 +31,14 @@ public class OnInventoryClickEvent implements Listener {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
String arenaname = inv.getName().replaceAll(
|
||||
MessageM.replaceAll("\u00A7r%N&lSettings of: %A"), "");
|
||||
|
||||
Arena arena = null;
|
||||
for (Arena arena2 : W.arenaList) {
|
||||
if (arena2.arenaName.equalsIgnoreCase(arenaname)) {
|
||||
arena = arena2;
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null)
|
||||
return;
|
||||
if (item.getType().equals(Material.AIR))
|
||||
@ -37,62 +48,109 @@ public class OnInventoryClickEvent implements Listener {
|
||||
if (item.getType().equals(Material.GOLD_NUGGET)) {
|
||||
if (item.getItemMeta().getDisplayName()
|
||||
.contains("maxPlayers")) {
|
||||
updownButton(item, arenaname, player, "maxPlayers",
|
||||
Bukkit.getMaxPlayers(), 2, 1, 1);
|
||||
updownButton(player, item, arena, ArenaType.maxPlayers,
|
||||
arena.maxPlayers, Bukkit.getMaxPlayers(), 2, 1,
|
||||
1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("minPlayers")) {
|
||||
updownButton(item, arenaname, player, "minPlayers",
|
||||
Bukkit.getMaxPlayers() - 1, 2, 1, 1);
|
||||
updownButton(player, item, arena, ArenaType.minPlayers,
|
||||
arena.minPlayers, Bukkit.getMaxPlayers() - 1,
|
||||
2, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("amountSeekersOnStart")) {
|
||||
updownButton(item, arenaname, player,
|
||||
"amountSeekersOnStart", W.arenas.getFile()
|
||||
.getInt(arenaname + ".maxPlayers") - 1,
|
||||
1, 1, 1);
|
||||
updownButton(player, item, arena,
|
||||
ArenaType.amountSeekersOnStart,
|
||||
arena.amountSeekersOnStart,
|
||||
arena.maxPlayers - 1, 1, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("timeInLobbyUntilStart")) {
|
||||
updownButton(item, arenaname, player,
|
||||
"timeInLobbyUntilStart", 1000, 5, 1, 1);
|
||||
updownButton(player, item, arena,
|
||||
ArenaType.timeInLobbyUntilStart,
|
||||
arena.timeInLobbyUntilStart, 1000, 5, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("waitingTimeSeeker")) {
|
||||
updownButton(item, arenaname, player,
|
||||
"waitingTimeSeeker", 1000, 5, 1, 1);
|
||||
updownButton(player, item, arena,
|
||||
ArenaType.waitingTimeSeeker,
|
||||
arena.waitingTimeSeeker, 1000, 5, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("gameTime")) {
|
||||
updownButton(item, arenaname, player, "gameTime", 1000,
|
||||
5, 1, 1);
|
||||
updownButton(player, item, arena, ArenaType.gameTime,
|
||||
arena.gameTime, 1000, 5, 1, 1);
|
||||
}
|
||||
|
||||
W.arenas.save();
|
||||
InventoryHandler.openPanel(player, arenaname);
|
||||
save(arena);
|
||||
InventoryHandler.openPanel(player, arena.arenaName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updownButton(ItemStack item, String arenaname,
|
||||
Player player, String option, int max, int min, int add, int remove) {
|
||||
public void save(Arena arena) {
|
||||
W.arenas.getFile().set(arena.arenaName, arena);
|
||||
W.arenas.save();
|
||||
ArenaHandler.loadArenas();
|
||||
}
|
||||
|
||||
public static void updownButton(Player player, ItemStack item, Arena arena,
|
||||
ArenaType at, int option, int max, int min, int add, int remove) {
|
||||
if (item.getItemMeta().getDisplayName()
|
||||
.contains((String) W.messages.get(ConfigC.button_add2))) {
|
||||
if (W.arenas.getFile().getInt(arenaname + "." + option) < max) {
|
||||
W.arenas.getFile().set(
|
||||
arenaname + "." + option,
|
||||
W.arenas.getFile().getInt(arenaname + "." + option)
|
||||
+ add);
|
||||
if (option < max) {
|
||||
|
||||
// W.arenas.getFile().set(arenaname + "." + option, option +
|
||||
// add);
|
||||
switch (at) {
|
||||
case maxPlayers:
|
||||
arena.maxPlayers = option + add;
|
||||
break;
|
||||
case minPlayers:
|
||||
arena.minPlayers = option + add;
|
||||
break;
|
||||
case amountSeekersOnStart:
|
||||
arena.amountSeekersOnStart = option + add;
|
||||
break;
|
||||
case timeInLobbyUntilStart:
|
||||
arena.timeInLobbyUntilStart = option + add;
|
||||
break;
|
||||
case waitingTimeSeeker:
|
||||
arena.waitingTimeSeeker = option + add;
|
||||
break;
|
||||
case gameTime:
|
||||
arena.gameTime = option + add;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_tooHighNumber,
|
||||
MessageM.sendFMessage(player, ConfigC.error_setTooHighNumber,
|
||||
true, "max-" + max);
|
||||
}
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains((String) W.messages.get(ConfigC.button_remove2))) {
|
||||
if (W.arenas.getFile().getInt(arenaname + "." + option) > min) {
|
||||
W.arenas.getFile().set(
|
||||
arenaname + "." + option,
|
||||
W.arenas.getFile().getInt(arenaname + "." + option)
|
||||
- remove);
|
||||
if (option > min) {
|
||||
// W.arenas.getFile().set(arenaname + "." + option,
|
||||
// option - remove);
|
||||
switch (at) {
|
||||
case maxPlayers:
|
||||
arena.maxPlayers = option - remove;
|
||||
break;
|
||||
case minPlayers:
|
||||
arena.minPlayers = option - remove;
|
||||
break;
|
||||
case amountSeekersOnStart:
|
||||
arena.amountSeekersOnStart = option - remove;
|
||||
break;
|
||||
case timeInLobbyUntilStart:
|
||||
arena.timeInLobbyUntilStart = option - remove;
|
||||
break;
|
||||
case waitingTimeSeeker:
|
||||
arena.waitingTimeSeeker = option - remove;
|
||||
break;
|
||||
case gameTime:
|
||||
arena.gameTime = option - remove;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_tooLowNumber, true,
|
||||
"min-" + min);
|
||||
MessageM.sendFMessage(player, ConfigC.error_setTooLowNumber,
|
||||
true, "min-" + min);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user