Added Set command.
Used to set settings!
This commit is contained in:
parent
fed9a3b4f1
commit
6993fc1068
@ -1,6 +1,7 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import nl.Steffion.BlockHunt.Listeners.PlayerListener;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnInventoryClickEvent;
|
||||
import nl.Steffion.BlockHunt.Listeners.OnPlayerInteractEvent;
|
||||
import nl.Steffion.BlockHunt.Managers.CommandC;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
@ -20,7 +21,10 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(),
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerInteractEvent(),
|
||||
this);
|
||||
getServer().getPluginManager().registerEvents(
|
||||
new OnInventoryClickEvent(),
|
||||
this);
|
||||
|
||||
ConfigurationSerialization.registerClass(LocationSerializable.class,
|
||||
|
@ -31,6 +31,16 @@ public class CMDcreate extends DefaultCMD {
|
||||
W.pos1.get(player));
|
||||
W.arenas.getFile().set(args[1] + ".pos2",
|
||||
W.pos2.get(player));
|
||||
W.arenas.getFile().set(args[1] + ".maxPlayers", 12);
|
||||
W.arenas.getFile().set(args[1] + ".minPlayers", 3);
|
||||
W.arenas.getFile().set(
|
||||
args[1] + ".amountSeekersOnStart", 1);
|
||||
W.arenas.getFile().set(
|
||||
args[1] + ".timeInLobbyUntilStart", 90);
|
||||
W.arenas.getFile().set(
|
||||
args[1] + ".waitingTimeSeeker", 20);
|
||||
W.arenas.getFile().set(args[1] + ".gameTime", 200);
|
||||
|
||||
W.arenas.save();
|
||||
MessageM.sendFMessage(player,
|
||||
ConfigC.normal_createCreatedArena, true,
|
||||
@ -44,9 +54,9 @@ public class CMDcreate extends DefaultCMD {
|
||||
ConfigC.error_createSelectionFirst, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true);
|
||||
}
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
34
src/nl/Steffion/BlockHunt/Commands/CMDset.java
Normal file
34
src/nl/Steffion/BlockHunt/Commands/CMDset.java
Normal file
@ -0,0 +1,34 @@
|
||||
package nl.Steffion.BlockHunt.Commands;
|
||||
|
||||
import nl.Steffion.BlockHunt.InventoryHandler;
|
||||
import nl.Steffion.BlockHunt.Managers.CommandC;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
import nl.Steffion.BlockHunt.Managers.PlayerM;
|
||||
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CMDset extends DefaultCMD {
|
||||
|
||||
@Override
|
||||
public boolean exectue(Player player, Command cmd, String label,
|
||||
String[] args) {
|
||||
if (PlayerM.hasPerm(player, PermsC.set, true)) {
|
||||
if (player != null) {
|
||||
if (args.length <= 1) {
|
||||
MessageM.sendFMessage(player,
|
||||
ConfigC.error_notEnoughArguments, true, "syntax-"
|
||||
+ CommandC.SET.usage);
|
||||
} else {
|
||||
String arenaname = args[1];
|
||||
InventoryHandler.openPanel(player, arenaname);
|
||||
}
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
121
src/nl/Steffion/BlockHunt/InventoryHandler.java
Normal file
121
src/nl/Steffion/BlockHunt/InventoryHandler.java
Normal file
@ -0,0 +1,121 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class InventoryHandler {
|
||||
|
||||
public static void openPanel(Player player, String arenaname) {
|
||||
String shorten = arenaname;
|
||||
if (W.arenas.getFile().getString(arenaname) != null) {
|
||||
if (shorten.length() > 6)
|
||||
shorten = shorten.substring(0, 6);
|
||||
Inventory panel = Bukkit
|
||||
.createInventory(
|
||||
null,
|
||||
27,
|
||||
MessageM.replaceAll("\u00A7r%N&lSettings of: %A"
|
||||
+ shorten));
|
||||
ItemStack maxPlayers_UP = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
ItemStack maxPlayers = new ItemStack(Material.PISTON_MOVING_PIECE,
|
||||
W.arenas.getFile().getInt(arenaname + ".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"));
|
||||
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"));
|
||||
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"));
|
||||
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"));
|
||||
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"));
|
||||
ItemStack gameTime_DOWN = new ItemStack(Material.GOLD_NUGGET, 1);
|
||||
|
||||
//
|
||||
|
||||
updownButton(panel, arenaname, "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, arenaname, "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, arenaname, "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);
|
||||
|
||||
player.openInventory(panel);
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_noArena, true, "name-"
|
||||
+ arenaname);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updownButton(Inventory panel, String arenaname,
|
||||
String option, String addremove, ItemStack UP, ItemStack BUTTON,
|
||||
ItemStack DOWN, int up, int button, int down) {
|
||||
ItemMeta UP_IM = UP.getItemMeta();
|
||||
UP_IM.setDisplayName(MessageM.replaceAll(
|
||||
(String) W.messages.get(ConfigC.button_add), "1-" + addremove,
|
||||
"2-" + option));
|
||||
UP.setItemMeta(UP_IM);
|
||||
|
||||
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)));
|
||||
BUTTON.setItemMeta(BUTTON_IM);
|
||||
|
||||
ItemMeta DOWN_IM = DOWN.getItemMeta();
|
||||
DOWN_IM.setDisplayName(MessageM.replaceAll(
|
||||
(String) W.messages.get(ConfigC.button_remove), "1-"
|
||||
+ addremove, "2-" + option));
|
||||
DOWN.setItemMeta(DOWN_IM);
|
||||
|
||||
panel.setItem(up, UP);
|
||||
panel.setItem(button, BUTTON);
|
||||
panel.setItem(down, DOWN);
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package nl.Steffion.BlockHunt.Listeners;
|
||||
|
||||
import nl.Steffion.BlockHunt.InventoryHandler;
|
||||
import nl.Steffion.BlockHunt.W;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class OnInventoryClickEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onInventoryClickEvent(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Inventory inv = event.getInventory();
|
||||
if (inv.getType().equals(InventoryType.CHEST)) {
|
||||
if (inv.getName().startsWith("\u00A7r")) {
|
||||
event.setCancelled(true);
|
||||
ItemStack item = event.getCurrentItem();
|
||||
String arenaname = inv.getName().replaceAll(
|
||||
MessageM.replaceAll("\u00A7r%N&lSettings of: %A"), "");
|
||||
if (item == null)
|
||||
return;
|
||||
if (item.getType().equals(Material.AIR))
|
||||
return;
|
||||
if (!item.getItemMeta().hasDisplayName())
|
||||
return;
|
||||
if (item.getType().equals(Material.GOLD_NUGGET)) {
|
||||
if (item.getItemMeta().getDisplayName()
|
||||
.contains("maxPlayers")) {
|
||||
updownButton(item, arenaname, player, "maxPlayers",
|
||||
Bukkit.getMaxPlayers(), 2, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("minPlayers")) {
|
||||
updownButton(item, arenaname, player, "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);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("timeInLobbyUntilStart")) {
|
||||
updownButton(item, arenaname, player,
|
||||
"timeInLobbyUntilStart", 1000, 5, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("waitingTimeSeeker")) {
|
||||
updownButton(item, arenaname, player,
|
||||
"waitingTimeSeeker", 1000, 5, 1, 1);
|
||||
} else if (item.getItemMeta().getDisplayName()
|
||||
.contains("gameTime")) {
|
||||
updownButton(item, arenaname, player, "gameTime", 1000,
|
||||
5, 1, 1);
|
||||
}
|
||||
|
||||
W.arenas.save();
|
||||
InventoryHandler.openPanel(player, arenaname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updownButton(ItemStack item, String arenaname,
|
||||
Player player, String 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);
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_tooHighNumber,
|
||||
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);
|
||||
} else {
|
||||
MessageM.sendFMessage(player, ConfigC.error_tooLowNumber, true,
|
||||
"min-" + min);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,13 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
// private BlockHunt plugin;
|
||||
//
|
||||
// public PlayerListener (BlockHunt plugin) {
|
||||
// this.plugin = plugin;
|
||||
// }
|
||||
public class OnPlayerInteractEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerInteractEvent(PlayerInteractEvent event) {
|
@ -58,6 +58,14 @@ public enum CommandC {
|
||||
ConfigC.help_create,
|
||||
1,
|
||||
W.pluginName + " <create|c> <arenaname>"),
|
||||
SET ("BlockHunt%set_",
|
||||
"BlockHunt%s_",
|
||||
new CMDset(),
|
||||
ConfigC.commandEnabled_set,
|
||||
PermsC.set,
|
||||
ConfigC.help_set,
|
||||
1,
|
||||
W.pluginName + " <set|s> <arenaname>"),
|
||||
NOT_FOUND ("%_",
|
||||
"%_",
|
||||
new CMDnotfound(),
|
||||
|
@ -20,6 +20,7 @@ public enum ConfigC {
|
||||
commandEnabled_reload (true, W.config),
|
||||
commandEnabled_wand (true, W.config),
|
||||
commandEnabled_create (true, W.config),
|
||||
commandEnabled_set (true, W.config),
|
||||
|
||||
wandID (280, W.config),
|
||||
wandName ("%A&l" + W.pluginName + "%N's selection wand", W.config),
|
||||
@ -40,13 +41,20 @@ public enum ConfigC {
|
||||
help_reload ("%NReloads all configs.", W.messages),
|
||||
help_wand ("%NGives you the wand selection tool.", W.messages),
|
||||
help_create ("%NCreates an arena from your selection.", W.messages),
|
||||
help_set ("%NOpens a panel to set settings.", W.messages),
|
||||
|
||||
button_add ("%NAdd %A%1%%N to %A%2%%N", W.messages),
|
||||
button_add2 ("Add", W.messages),
|
||||
button_setting ("%NSetting %A%1%%N is now: %A%2%%N.", W.messages),
|
||||
button_remove ("%NRemove %A%1%%N from %A%2%%N", W.messages),
|
||||
button_remove2 ("Remove", W.messages),
|
||||
|
||||
normal_reloadedConfigs ("&aReloaded all configs!", W.messages),
|
||||
normal_wandGaveWand ("%NHere you go ;)! &o(Use the %A&o%type%%N&o!)",
|
||||
W.messages),
|
||||
normal_wandSetPosition ("%NSet position %A#%number%%N to location: %pos%.",
|
||||
W.messages),
|
||||
normal_createCreatedArena ("%NCreated an arena with the name %A%name%%N.",
|
||||
normal_createCreatedArena ("%NCreated an arena with the name '%A%name%%N'.",
|
||||
W.messages),
|
||||
|
||||
error_noPermission ("%EYou don't have the permissions to do that!",
|
||||
@ -62,6 +70,10 @@ public enum ConfigC {
|
||||
+ W.pluginName + " <wand|w>%E.",
|
||||
W.messages),
|
||||
error_createNotSameWorld ("%EMake your selection points in the same world!",
|
||||
W.messages),
|
||||
error_tooHighNumber ("%EThat amount is too high! Max amount is: %A%max%%E.",
|
||||
W.messages),
|
||||
error_tooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.",
|
||||
W.messages);
|
||||
|
||||
Object value;
|
||||
|
@ -19,7 +19,8 @@ public class PlayerM {
|
||||
info (main + "info", PType.ALL),
|
||||
help (main + "help", PType.ALL),
|
||||
reload (main + "reload", PType.MODERATOR),
|
||||
create (main + "create", PType.ADMIN);
|
||||
create (main + "create", PType.ADMIN),
|
||||
set (main + "set", PType.MODERATOR);
|
||||
|
||||
public String perm;
|
||||
public PType type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user