Attempts to improve command code a bit

This commit is contained in:
Kristian Knarvik 2023-07-07 02:49:08 +02:00
parent 943a273423
commit 638094be33
31 changed files with 485 additions and 400 deletions

101
README.md
View File

@ -50,30 +50,37 @@ _**Note:** Instead of using /BlockHunt you could use:_
<> = Required [] = Optional
|Command|Description|Permission|| |:--|:--|:--|:--| |`/BlockHunt [info/i]`|Displays the plugin's info.|blockhunt.info|_
All players have this permission from default._| |`/BlockHunt <help/h>`|Shows a list of commands.|blockhunt.help|_All
players have this permission from default._| |`/BlockHunt <reload/r>`|Reloads all
configs.|blockhunt.reload|blockhunt.admin| |`/BlockHunt <join/j> <arenaName>`|Joins a BlockHunt
game.|blockhunt.join|blockhunt.player| |`/BlockHunt <leave/l>`|Leave a BlockHunt game.|blockhunt.leave|blockhunt.player|
|`/BlockHunt <list/li>`|Shows a list of available arenas.|blockhunt.list|blockhunt.player| |`/BlockHunt <shop/sh>`|Opens
the BlockHunt shop.|blockhunt.shop|blockhunt.player| |`/BlockHunt <start/go> <arenaName>`|Forces an arena to
start.|blockhunt.start|blockhunt.moderator| |`/BlockHunt <wand/w>`|Gives you the wand selection
tool.|blockhunt.create|blockhunt.admin| |`/BlockHunt <create/c> <arenaName>`|Creates an arena from your
selection.|blockhunt.create|blockhunt.admin| |`/BlockHunt <set/s> <arenaName>`|Opens a panel to set
settings.|blockhunt.set|blockhunt.moderator| |`/BlockHunt <setWarp/sw> <lobby/hiders/seekers/spawn> <arenaName>`|Sets
warps for your arena.|blockhunt.setWarp|blockhunt.moderator| |`/BlockHunt <remove/delete> <arenaName>`|Deletes an
Arena.|blockhunt.remove|blockhunt.admin| |`/BlockHunt <tokens/t> <set/add/take> <%playerName%> <amount>`|Change someones
tokens.|blockhunt.tokens|blockhunt.admin| ||Able to join full games.|blockhunt.joinfull|blockhunt.moderator| ||Able to
join/leave using join/leave signs.|blockhunt.joinsign|blockhunt.player| ||Able to create a join/leave
sign.|blockhunt.signcreate|blockhunt.moderator| ||Gives you the
BlockChooser.|blockhunt.shop.blockchooser|blockhunt.admin| ||Gives you the ability to do all commands
in-game.|blockhunt.allcommands|Operators|
| Command | Description | Permission | Default allowed |
|--------------------------------------------------------------------|---------------------------------------------------|-----------------------------|-------------------------------------------------|
| `/BlockHunt [info/i]` | Displays the plugin's info. | blockhunt.info | All players have this permission from default._ |
| `/BlockHunt <help/h>` | Shows a list of commands. | blockhunt.help | All players have this permission from default._ |
| `/BlockHunt <reload/r>` | Reloads all configs. | blockhunt.reload | blockhunt.admin |
| `/BlockHunt <join/j> <arenaName>` | Joins a BlockHunt game. | blockhunt.join | blockhunt.player |
| `/BlockHunt <leave/l>` | Leave a BlockHunt game. | blockhunt.leave | blockhunt.player |
| `/BlockHunt <list/li>` | Shows a list of available arenas. | blockhunt.list | blockhunt.player |
| `/BlockHunt <shop/sh>` | Opens the BlockHunt shop. | blockhunt.shop | blockhunt.player |
| `/BlockHunt <start/go> <arenaName>` | Forces an arena to start. | blockhunt.start | blockhunt.moderator |
| `/BlockHunt <wand/w>` | Gives you the wand selection tool. | blockhunt.create | blockhunt.admin |
| `/BlockHunt <create/c> <arenaName>` | Creates an arena from your selection. | blockhunt.create | blockhunt.admin |
| `/BlockHunt <set/s> <arenaName>` | Opens a panel to set settings. | blockhunt.set | blockhunt.moderator |
| `/BlockHunt <setWarp/sw> <lobby/hiders/seekers/spawn> <arenaName>` | Sets warps for your arena. | blockhunt.setWarp | blockhunt.moderator |
| `/BlockHunt <remove/delete> <arenaName>` | Deletes an Arena. | blockhunt.remove | blockhunt.admin |
| `/BlockHunt <tokens/t> <set/add/take> <%playerName%> <amount>` | Change someones tokens. | blockhunt.tokens | blockhunt.admin |
| | Able to join full games. | blockhunt.joinfull | blockhunt.moderator |
| | Able to join/leave using join/leave signs. | blockhunt.joinsign | blockhunt.player |
| | Able to create a join/leave sign. | blockhunt.signcreate | blockhunt.moderator |
| | Gives you the BlockChooser. | blockhunt.shop.blockchooser | blockhunt.admin |
| | Gives you the ability to do all commands in-game. | blockhunt.allcommands | Operators |
### Other special permissions
|Permission|Description| |:--|:--| |`blockhunt.*`|All BlockHunt permissions.| |`blockhunt.player`|All player related
permissions.| |`blockhunt.moderator`|All moderator related permissions.| |`blockhunt.admin`|All admin related
permissions.| |`*`|All permissions on your server, including BlockHunt's permissions.|
| Permission | Description |
|-----------------------|--------------------------------------------------------------------|
| `blockhunt.*` | All BlockHunt permissions. |
| `blockhunt.player` | All player related permissions. |
| `blockhunt.moderator` | All moderator related permissions. |
| `blockhunt.admin` | All admin related permissions. |
| `*` | All permissions on your server, including BlockHunt's permissions. |
## How to set up?
@ -83,4 +90,54 @@ Use this video to manage your way through the set-up phase!
" target="_blank"><img src="http://img.youtube.com/vi/msPQ1UMiHWg/0.jpg"
alt="" width="240" height="180" border="10" /></a>
**Thanks to [Koz4Christ](https://www.youtube.com/user/koz4christ/) for this video!**
**Thanks to [Koz4Christ](https://www.youtube.com/user/koz4christ/) for this video!**
### Textual guide
To start setting up your arena, start by using the `/bh wand` command to get the setup wand. Mark the corners of a
square containing your entire arena, like you'd create a WorldGuard region. Right-click with the wand on one corner,
and then left-click with the wand on the opposite corner. Make sure one corner is below the bottom of the arena, and
that the other is above the top of the arena.
Use `/bh create \<name>` to create your new arena with name \<name>. Use `/bh set \<name>` to get a GUI for setting the
properties of the arena. You can set the maximum number of players that can play at once, the minimum amount of players
for a game to start, the amount of seekers required to start, the amount of seconds to keep the players in the lobby (
allowing other players to join) before starting the arena, the number of seconds to wait until seekers can start
seeking, the amount of time a game will last, the amount of seconds between each time the number of remaining hiders is
announced, the number of seconds before the game ends the hiders will be given swords.
### Arena interface descriptions
#### maxPlayers
The maximum amount of players that can join this arena.
#### minPlayers
The minimum amount of players required for a round to start.
#### amountSeekersOnStart
The number of players made into seekers when the game starts.
#### timeInLobbyUntilStart
The amount of seconds to wait in the lobby until the game actually starts. During this time, players can use an item in
their inventory to choose their hide block. Other players can join during this time, until the game starts.
#### waitingTimeSeeker
The number of seconds seekers have to wait before they are allowed to start seeking. This is basically how long the
seekers count for until they start searching for the hiders.
#### gameTime
The amount of seconds a game will last. If the hiders are alive after this time, they win.
#### blockAnnouncerTime
The amount of seconds
#### sword
The amount of seconds to wait before allowing hiders to defend themselves with a wooden sword.

View File

@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.Steffion</groupId>
<groupId>net.knarcraft</groupId>
<artifactId>BlockHunt</artifactId>
<version>0.5.0-SNAPSHOT</version>
<name>BlockHunt</name>

View File

@ -6,24 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.command.CreateCommand;
import net.knarcraft.blockhunt.command.HelpCommand;
import net.knarcraft.blockhunt.command.InfoCommand;
import net.knarcraft.blockhunt.command.JoinCommand;
import net.knarcraft.blockhunt.command.LeaveCommand;
import net.knarcraft.blockhunt.command.ListCommand;
import net.knarcraft.blockhunt.command.NotFoundCommand;
import net.knarcraft.blockhunt.command.ReloadCommand;
import net.knarcraft.blockhunt.command.RemoveCommand;
import net.knarcraft.blockhunt.command.SetCommand;
import net.knarcraft.blockhunt.command.SetWarpCommand;
import net.knarcraft.blockhunt.command.ShopCommand;
import net.knarcraft.blockhunt.command.StartCommand;
import net.knarcraft.blockhunt.command.TokensCommand;
import net.knarcraft.blockhunt.command.WandCommand;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.config.Permission;
import net.knarcraft.blockhunt.listener.OnBlockBreakEvent;
import net.knarcraft.blockhunt.listener.OnBlockPlaceEvent;
import net.knarcraft.blockhunt.listener.OnEntityDamageByEntityEvent;
@ -41,7 +24,6 @@ import net.knarcraft.blockhunt.listener.OnSignChangeEvent;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.ConfigManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
@ -52,8 +34,6 @@ import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -61,10 +41,8 @@ import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class BlockHunt extends JavaPlugin implements Listener {
@ -72,41 +50,6 @@ public class BlockHunt extends JavaPlugin implements Listener {
public static BlockHunt plugin;
public String rootPermission;
public static final List<String> BlockHuntCMD = new ArrayList<>() {
{
add("info");
add("help");
add("reload");
add("join");
add("leave");
add("list");
add("shop");
add("start");
add("wand");
add("create");
add("set");
add("setWarp");
add("remove");
add("tokens");
}
};
public static CommandManager CMD;
public static CommandManager CMDInfo;
public static CommandManager CMDHelp;
public static CommandManager CMDReload;
public static CommandManager CMDJoin;
public static CommandManager CMDLeave;
public static CommandManager CMDList;
public static CommandManager CMDShop;
public static CommandManager CMDStart;
public static CommandManager CMDWand;
public static CommandManager CMDCreate;
public static CommandManager CMDSet;
public static CommandManager CMDSetWarp;
public static CommandManager CMDRemove;
public static CommandManager CMDTokens;
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
@ -134,37 +77,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
ConfigManager.newFiles();
CMD = new CommandManager("BlockHunt", "BlockHunt", null, null, Permission.INFO, MessageKey.HELP_INFO, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_INFO), BlockHuntCMD,
new InfoCommand(), null);
CMDInfo = new CommandManager("BlockHunt INFO", "BlockHunt", "info", "i", Permission.INFO, MessageKey.HELP_INFO, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_INFO),
BlockHuntCMD, new InfoCommand(), "/BlockHunt [info|i]");
CMDHelp = new CommandManager("BlockHunt HELP", "BlockHunt", "help", "h", Permission.HELP, MessageKey.HELP_HELP, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_HELP),
BlockHuntCMD, new HelpCommand(), "/BlockHunt <help|h> [page number]");
CMDReload = new CommandManager("BlockHunt RELOAD", "BlockHunt", "reload", "r", Permission.RELOAD, MessageKey.HELP_RELOAD,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_RELOAD), BlockHuntCMD, new ReloadCommand(), "/BlockHunt <reload|r>");
CMDJoin = new CommandManager("BlockHunt JOIN", "BlockHunt", "join", "j", Permission.JOIN, MessageKey.HELP_JOIN, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_JOIN),
BlockHuntCMD, new JoinCommand(), "/BlockHunt <join|j> <arena name>");
CMDLeave = new CommandManager("BlockHunt LEAVE", "BlockHunt", "leave", "l", Permission.LEAVE, MessageKey.HELP_LEAVE,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_LEAVE), BlockHuntCMD, new LeaveCommand(), "/BlockHunt <leave|l>");
CMDList = new CommandManager("BlockHunt LIST", "BlockHunt", "list", "li", Permission.LIST, MessageKey.HELP_LIST, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_LIST),
BlockHuntCMD, new ListCommand(), "/BlockHunt <list|li>");
CMDShop = new CommandManager("BlockHunt SHOP", "BlockHunt", "shop", "sh", Permission.SHOP, MessageKey.HELP_SHOP, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_SHOP),
BlockHuntCMD, new ShopCommand(), "/BlockHunt <shop|sh>");
CMDStart = new CommandManager("BlockHunt START", "BlockHunt", "start", "go", Permission.START, MessageKey.HELP_START,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_START), BlockHuntCMD, new StartCommand(), "/BlockHunt <start|go> <arena name>");
CMDWand = new CommandManager("BlockHunt WAND", "BlockHunt", "wand", "w", Permission.CREATE, MessageKey.HELP_WAND, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_WAND),
BlockHuntCMD, new WandCommand(), "/BlockHunt <wand|w>");
CMDCreate = new CommandManager("BlockHunt CREATE", "BlockHunt", "create", "c", Permission.CREATE, MessageKey.HELP_CREATE,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_CREATE), BlockHuntCMD, new CreateCommand(), "/BlockHunt <create|c> <arena name>");
CMDSet = new CommandManager("BlockHunt SET", "BlockHunt", "set", "s", Permission.SET, MessageKey.HELP_SET, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_SET),
BlockHuntCMD, new SetCommand(), "/BlockHunt <set|s> <arena name>");
CMDSetWarp = new CommandManager("BlockHunt SETWARP", "BlockHunt", "setWarp", "sw", Permission.SET_WARP, MessageKey.HELP_SET_WARP,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_SET_WARP), BlockHuntCMD, new SetWarpCommand(),
"/BlockHunt <setWarp|sw> <lobby|hiders|seekers|spawn> <arena name>");
CMDRemove = new CommandManager("BlockHunt REMOVE", "BlockHunt", "remove", "delete", Permission.REMOVE, MessageKey.HELP_REMOVE,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_REMOVE), BlockHuntCMD, new RemoveCommand(), "/BlockHunt <remove|delete> <arena name>");
CMDTokens = new CommandManager("BlockHunt TOKENS", "BlockHunt", "tokens", "t", Permission.TOKENS, MessageKey.HELP_TOKENS,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_TOKENS), BlockHuntCMD, new TokensCommand(), "/BlockHunt <tokens|t> <set|add|take> <player name> <amount>");
CommandManager.load();
if (!getServer().getPluginManager().isPluginEnabled("LibsDisguises")) {
MessageManager.broadcastFMessage(MessageKey.ERROR_LIBS_DISGUISES_NOT_INSTALLED);
@ -293,7 +206,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
if (MemoryStorage.seekertime.get(player) <= 0) {
PlayerHandler.teleport(player, arena.hidersWarp);
MemoryStorage.seekertime.remove(player);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED, "%playerName%-" + player.getName());
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED,
"%playerName%-" + player.getName());
}
}
}
@ -439,72 +353,6 @@ public class BlockHunt extends JavaPlugin implements Listener {
return pluginDescriptionFile;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
for (CommandManager command : MemoryStorage.commands) {
String[] argsSplit = null;
String[] argsSplitAlias = null;
if (command.args != null && command.argumentAliases != null) {
argsSplit = command.args.split("/");
argsSplitAlias = command.argumentAliases.split("/");
}
if (cmd.getName().equalsIgnoreCase(command.label)) {
boolean equals = true;
if (argsSplit == null) {
equals = args.length == 0;
} else {
if (args.length >= argsSplit.length) {
for (int i2 = argsSplit.length - 1; i2 >= 0; i2 = i2 - 1) {
int loc = argsSplit.length - i2 - 1;
if (!argsSplit[loc].equalsIgnoreCase(args[loc]) && !argsSplitAlias[loc].equalsIgnoreCase(args[loc])) {
equals = false;
break;
}
}
} else {
equals = false;
}
}
if (equals) {
if (PermissionsManager.hasPerm(player, command.permission, true)) {
if (command.enabled) {
return command.CMD.execute(player, cmd, label, args);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_COMMAND_NOT_ENABLED);
}
}
return true;
}
}
}
new NotFoundCommand().execute(player, cmd, label, args);
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
for (CommandManager command : MemoryStorage.commands) {
if (cmd.getName().equalsIgnoreCase(command.label)) {
if (args.length == 1) {
return command.mainTABlist;
}
}
}
return null;
}
/**
* Short a String for like the Scoreboard title.
*
@ -518,4 +366,5 @@ public class BlockHunt extends JavaPlugin implements Listener {
}
return string;
}
}

View File

@ -228,7 +228,7 @@ public class InventoryHandler {
shop.setItem(0, shopTokens);
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)
&& (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") == null && !PermissionsManager.hasPerm(player, Permission.SHOP_BLOCK_CHOOSER, false))) {
&& (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") == null && !PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false))) {
shop.setItem(1, shopBlockChooser);
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED)) {

View File

@ -1,7 +1,7 @@
package net.knarcraft.blockhunt;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.Command;
import net.knarcraft.blockhunt.manager.ConfigManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -18,7 +18,7 @@ public class MemoryStorage {
* Standard stuff.
*/
public static final ArrayList<String> newFiles = new ArrayList<>();
public static final ArrayList<CommandManager> commands = new ArrayList<>();
public static final ArrayList<Command> commands = new ArrayList<>();
/*
* If you want another file to be created. Copy and paste this line.

View File

@ -7,29 +7,8 @@ import org.bukkit.potion.PotionEffect;
import java.util.Collection;
public class PlayerArenaData {
public final GameMode pGameMode;
public final ItemStack[] pInventory;
public final ItemStack[] pArmor;
public final Float pEXP;
public final Integer pEXPL;
public final Double pMaxHealth;
public final Double pHealth;
public final Integer pFood;
public final Collection<PotionEffect> pPotionEffects;
public final boolean pFlying;
public PlayerArenaData(Location pLocation, GameMode pGameMode, ItemStack[] pInventory, ItemStack[] pArmor, Float pEXP, Integer pEXPL, Double pMaxHealth, Double pHealth, Integer pFood,
Collection<PotionEffect> pPotionEffects, boolean pFlying) {
this.pGameMode = pGameMode;
this.pInventory = pInventory;
this.pArmor = pArmor;
this.pEXP = pEXP;
this.pEXPL = pEXPL;
this.pMaxHealth = pMaxHealth;
this.pHealth = pHealth;
this.pFood = pFood;
this.pPotionEffects = pPotionEffects;
this.pFlying = pFlying;
}
public record PlayerArenaData(Location playerLocation, GameMode playerGameMode, ItemStack[] playerInventory,
ItemStack[] playerArmor, Float playerEXP, Integer playerEXPLevels, Double playerMaxHealth,
Double playerHealth, Integer playerFood, Collection<PotionEffect> playerPotionEffects,
boolean playerFlying) {
}

View File

@ -107,7 +107,7 @@ public class ArenaHandler {
if (!arena.lobbyWarp.equals(zero) && !arena.hidersWarp.equals(zero) && !arena.seekersWarp.equals(zero) && !arena.spawnWarp.equals(zero)) {
if (arena.gameState == ArenaState.WAITING || arena.gameState == ArenaState.STARTING) {
if (arena.playersInArena.size() >= arena.maxPlayers) {
if (!PermissionsManager.hasPerm(player, Permission.JOIN_FULL, false)) {
if (!PermissionsManager.hasPermission(player, Permission.JOIN_FULL, false)) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_FULL);
return;
}
@ -172,7 +172,7 @@ public class ArenaHandler {
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)) {
if (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") != null
|| PermissionsManager.hasPerm(player, Permission.SHOP_BLOCK_CHOOSER, false)) {
|| PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false)) {
ItemStack shopBlockChooser = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ID_NAME)), 1);
ItemMeta shopBlockChooser_IM = shopBlockChooser.getItemMeta();
shopBlockChooser_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
@ -317,18 +317,18 @@ public class ArenaHandler {
}
player.getInventory().clear();
player.getInventory().setContents(pad.pInventory);
player.getInventory().setArmorContents(pad.pArmor);
player.getInventory().setContents(pad.playerInventory());
player.getInventory().setArmorContents(pad.playerArmor());
player.updateInventory();
player.setExp(pad.pEXP);
player.setLevel(pad.pEXPL);
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(pad.pMaxHealth);
player.setHealth(pad.pHealth);
player.setFoodLevel(pad.pFood);
player.addPotionEffects(pad.pPotionEffects);
player.setExp(pad.playerEXP());
player.setLevel(pad.playerEXPLevels());
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(pad.playerMaxHealth());
player.setHealth(pad.playerHealth());
player.setFoodLevel(pad.playerFood());
player.addPotionEffects(pad.playerPotionEffects());
PlayerHandler.teleport(player, arena.spawnWarp);
player.setGameMode(pad.pGameMode);
player.setAllowFlight(pad.pFlying);
player.setGameMode(pad.playerGameMode());
player.setAllowFlight(pad.playerFlying());
if (player.getAllowFlight()) {
player.setFlying(true);
}

View File

@ -0,0 +1,69 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.Command;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class BlockHuntCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label,
String[] arguments) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
// TODO: This is horrible. Instead, use a map from command label to executor, and pipe the command
for (Command commandRecord : MemoryStorage.commands) {
String[] splitArguments = null;
String[] splitArgumentAliases = null;
if (commandRecord.args() != null && commandRecord.argumentAliases() != null) {
splitArguments = commandRecord.args().split("/");
splitArgumentAliases = commandRecord.argumentAliases().split("/");
}
if (!command.getName().equalsIgnoreCase(commandRecord.label())) {
continue;
}
boolean equals = true;
if (splitArguments == null) {
equals = arguments.length == 0;
} else if (arguments.length >= splitArguments.length) {
for (int i2 = splitArguments.length - 1; i2 >= 0; i2 = i2 - 1) {
int loc = splitArguments.length - i2 - 1;
if (!splitArguments[loc].equalsIgnoreCase(arguments[loc]) &&
!splitArgumentAliases[loc].equalsIgnoreCase(arguments[loc])) {
equals = false;
break;
}
}
} else {
equals = false;
}
if (equals) {
if (PermissionsManager.hasPermission(player, commandRecord.permission(), true)) {
if (commandRecord.enabled()) {
return commandRecord.command().execute(player, arguments);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_COMMAND_NOT_ENABLED);
}
}
return true;
}
}
new NotFoundCommand().execute(player, arguments);
return true;
}
}

View File

@ -0,0 +1,28 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.manager.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class BlockHuntTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull String label,
String[] args) {
for (Command command : MemoryStorage.commands) {
if (cmd.getName().equalsIgnoreCase(command.label())) {
if (args.length == 1) {
return command.mainTabList();
}
}
}
return null;
}
}

View File

@ -1,14 +1,13 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.ScoreboardHandler;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -16,30 +15,39 @@ import java.util.ArrayList;
public class CreateCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDCreate.usage);
} else {
if (MemoryStorage.pos1.get(player) != null && MemoryStorage.pos2.get(player) != null) {
if (MemoryStorage.pos1.get(player).getWorld().equals(MemoryStorage.pos2.get(player).getWorld())) {
Arena arena = new Arena(args[1], MemoryStorage.pos1.get(player), MemoryStorage.pos2.get(player), 12, 3, 1, 50, 20, 300, 30, 45, false, false, false, false, false, new ArrayList<>(), null, null, null,
null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), 10, 50, 8, new ArrayList<>(), ArenaState.WAITING,
0, new ArrayList<>(), Bukkit.getScoreboardManager().getNewScoreboard());
MemoryStorage.arenas.getFile().set(args[1], arena);
MemoryStorage.arenas.save();
MemoryStorage.signs.load();
public boolean execute(Player player, String[] args) {
if (player == null) {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
return true;
}
MemoryStorage.arenaList.add(arena);
ScoreboardHandler.createScoreboard(arena);
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getCreateCommand().usage());
} else {
if (MemoryStorage.pos1.get(player) != null && MemoryStorage.pos2.get(player) != null) {
if (MemoryStorage.pos1.get(player).getWorld().equals(MemoryStorage.pos2.get(player).getWorld())) {
Arena arena = new Arena(args[1], MemoryStorage.pos1.get(player), MemoryStorage.pos2.get(player),
12, 3, 1, 50, 20,
300, 30, 45, false,
false, false, false, false,
new ArrayList<>(), null, null, null, null,
new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), 10, 50,
8, new ArrayList<>(), ArenaState.WAITING, 0, new ArrayList<>(),
Bukkit.getScoreboardManager().getNewScoreboard());
MemoryStorage.arenas.getFile().set(args[1], arena);
MemoryStorage.arenas.save();
MemoryStorage.signs.load();
MessageManager.sendFMessage(player, MessageKey.NORMAL_CREATE_CREATED_ARENA, "name-" + args[1]);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_CREATE_NOT_SAME_WORLD);
}
MemoryStorage.arenaList.add(arena);
ScoreboardHandler.createScoreboard(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_CREATE_CREATED_ARENA, "name-" + args[1]);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_CREATE_SELECTION_FIRST);
MessageManager.sendFMessage(player, MessageKey.ERROR_CREATE_NOT_SAME_WORLD);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_CREATE_SELECTION_FIRST);
}
}
return true;

View File

@ -1,10 +1,9 @@
package net.knarcraft.blockhunt.command;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public abstract class DefaultCommand {
public abstract boolean execute(Player player, Command cmd, String label, String[] args);
public abstract boolean execute(Player player, String[] arguments);
}

View File

@ -3,20 +3,19 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.Command;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class HelpCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
int amountCommands = 0;
for (CommandManager command : MemoryStorage.commands) {
if (command.usage != null) {
for (Command command : MemoryStorage.commands) {
if (command.usage() != null) {
amountCommands = amountCommands + 1;
}
}
@ -30,13 +29,13 @@ public class HelpCommand extends DefaultCommand {
if (args.length == 1) {
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName() + " %Nhelp page %A" + page + "%N/%A" + maxPages);
int i = 1;
for (CommandManager command : MemoryStorage.commands) {
for (Command command : MemoryStorage.commands) {
if (i <= 4) {
if (command.usage != null) {
if (PermissionsManager.hasPerm(player, command.permission, false)) {
MessageManager.sendMessage(player, "%A" + command.usage + "%N - " + MemoryStorage.messages.getFile().get(command.help.getPath()));
if (command.usage() != null) {
if (PermissionsManager.hasPermission(player, command.permission(), false)) {
MessageManager.sendMessage(player, "%A" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
} else {
MessageManager.sendMessage(player, "%MemoryStorage" + command.usage + "%N - " + MemoryStorage.messages.getFile().get(command.help.getPath()));
MessageManager.sendMessage(player, "%MemoryStorage" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
}
i = i + 1;
}
@ -56,14 +55,14 @@ public class HelpCommand extends DefaultCommand {
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName() + " %Nhelp page %A" + page + "%N/%A" + maxPages);
int i = 1;
for (CommandManager command : MemoryStorage.commands) {
for (Command command : MemoryStorage.commands) {
if (i <= (page * 4) + 4) {
if (command.usage != null) {
if (command.usage() != null) {
if (i >= ((page - 1) * 4) + 1 && i <= ((page - 1) * 4) + 4) {
if (PermissionsManager.hasPerm(player, command.permission, false)) {
MessageManager.sendMessage(player, "%A" + command.usage + "%N - " + MemoryStorage.messages.getFile().get(command.help.getPath()));
if (PermissionsManager.hasPermission(player, command.permission(), false)) {
MessageManager.sendMessage(player, "%A" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
} else {
MessageManager.sendMessage(player, "%MemoryStorage" + command.usage + "%N - " + MemoryStorage.messages.getFile().get(command.help.getPath()));
MessageManager.sendMessage(player, "%MemoryStorage" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
}
}
i = i + 1;

View File

@ -2,20 +2,20 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class InfoCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName());
MessageManager.sendMessage(player, "%A%name%%N made by %A%authors%%N.", "name-" +
BlockHunt.getPluginDescriptionFile().getName(), "authors-" + BlockHunt.getPluginDescriptionFile().getAuthors().get(0));
MessageManager.sendMessage(player, "%NVersion: %A%version%%N.", "version-" + BlockHunt.getPluginDescriptionFile().getVersion());
MessageManager.sendMessage(player, "%NType %A%helpusage% %Nfor help.", "helpusage-" + BlockHunt.CMDHelp.usage);
MessageManager.sendMessage(player, "%NType %A%helpusage% %Nfor help.", "helpusage-" +
CommandManager.getHelpCommand().usage());
MessageManager.sendMessage(player, "%NDev-Page: %Ahttp://dev.bukkit.org/bukkit-plugins/blockhunt/");
MessageManager.sendMessage(player, "%NDonations are welcome!");
MessageManager.sendMessage(player, "%NMade by help from some friends &c<3%N!");

View File

@ -1,19 +1,19 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class JoinCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDJoin.usage);
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getJoinCommand().usage());
} else {
ArenaHandler.playerJoinArena(player, args[1]);
}

View File

@ -3,13 +3,12 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class LeaveCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
ArenaHandler.playerLeaveArena(player, true, true);
} else {

View File

@ -5,13 +5,12 @@ import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class ListCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName());
if (MemoryStorage.arenaList.size() >= 1) {
MessageManager.sendMessage(player, "&7Available arena(s):");

View File

@ -2,13 +2,12 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class NotFoundCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
MessageManager.sendFMessage(player, MessageKey.ERROR_COMMAND_NOT_FOUND);
return true;
}

View File

@ -6,14 +6,13 @@ import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.ConfigManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class ReloadCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
ConfigManager.newFiles();
MemoryStorage.config.load();

View File

@ -1,24 +1,24 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class RemoveCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDRemove.usage);
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getRemoveCommand().usage());
} else {
for (Arena arena : MemoryStorage.arenaList) {
if (args[1].equalsIgnoreCase(arena.arenaName)) {

View File

@ -1,19 +1,19 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.InventoryHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class SetCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDSet.usage);
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getSetCommand().usage());
} else {
String arenaName = args[1];
InventoryHandler.openPanel(player, arenaName);

View File

@ -1,22 +1,22 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class SetWarpCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 2) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDSetWarp.usage);
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.setWarpCommand().usage());
} else {
String arenaName = args[2];
String warpname = args[1];

View File

@ -1,13 +1,12 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.InventoryHandler;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class ShopCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
InventoryHandler.openShop(player);
return true;
}

View File

@ -1,21 +1,21 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class StartCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDStart.usage);
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getStartCommand().usage());
} else {
Arena arena = null;
for (Arena arena2 : MemoryStorage.arenaList) {

View File

@ -1,20 +1,20 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class TokensCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (args.length <= 3) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" + BlockHunt.CMDTokens.usage);
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getTokensCommand().usage());
} else {
String option = args[1];
String playerName = args[2];

View File

@ -6,7 +6,6 @@ import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -17,7 +16,7 @@ import java.util.List;
public class WandCommand extends DefaultCommand {
@Override
public boolean execute(Player player, Command cmd, String label, String[] args) {
public boolean execute(Player player, String[] args) {
if (player != null) {
ItemStack wand = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.WAND_ID_NAME)));
ItemMeta im = wand.getItemMeta();

View File

@ -34,7 +34,7 @@ public class OnPlayerInteractEvent implements Listener {
public void onPlayerInteractEvent(PlayerInteractEvent event) {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (PermissionsManager.hasPerm(player, Permission.CREATE, false)) {
if (PermissionsManager.hasPermission(player, Permission.CREATE, false)) {
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Material.AIR) {
if (item.getItemMeta().hasDisplayName()) {
@ -73,17 +73,17 @@ public class OnPlayerInteractEvent implements Listener {
Sign sign = (Sign) event.getClickedBlock().getState();
if (sign.getLine(1) != null) {
if (sign.getLine(1).equals(MessageManager.replaceAll(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_LEAVE.getPath()).get(1)))) {
if (PermissionsManager.hasPerm(player, Permission.JOIN_SIGN, true)) {
if (PermissionsManager.hasPermission(player, Permission.JOIN_SIGN, true)) {
ArenaHandler.playerLeaveArena(player, true, true);
}
} else if (sign.getLine(1).equals(MessageManager.replaceAll(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_SHOP.getPath()).get(1)))) {
if (PermissionsManager.hasPerm(player, Permission.SHOP, true)) {
if (PermissionsManager.hasPermission(player, Permission.SHOP, true)) {
InventoryHandler.openShop(player);
}
} else {
for (Arena arena : MemoryStorage.arenaList) {
if (sign.getLines()[1].contains(arena.arenaName)) {
if (PermissionsManager.hasPerm(player, Permission.JOIN_SIGN, true)) {
if (PermissionsManager.hasPermission(player, Permission.JOIN_SIGN, true)) {
ArenaHandler.playerJoinArena(player, arena.arenaName);
}
}

View File

@ -18,7 +18,7 @@ public class OnSignChangeEvent implements Listener {
String[] lines = event.getLines();
if (lines[0] != null) {
if (lines[0].equalsIgnoreCase("[" + BlockHunt.getPluginDescriptionFile().getName() + "]")) {
if (PermissionsManager.hasPerm(player, Permission.SIGN_CREATE, true)) {
if (PermissionsManager.hasPermission(player, Permission.SIGN_CREATE, true)) {
SignsHandler.createSign(event, lines, event.getBlock().getLocation());
}
}

View File

@ -0,0 +1,29 @@
package net.knarcraft.blockhunt.manager;
import net.knarcraft.blockhunt.command.DefaultCommand;
import net.knarcraft.blockhunt.config.Key;
import net.knarcraft.blockhunt.config.Permission;
import java.util.List;
/**
* A record keeping track of a command's properties
*
* @param name <p></p>
* @param args
* @param argumentAliases
* @param permission
* @param help
* @param enabled
* @param mainTabList
* @param command
* @param usage
*/
public record Command(String name, String args, String argumentAliases, Permission permission,
Key help, boolean enabled, List<String> mainTabList, DefaultCommand command, String usage) {
public String label() {
return "BlockHunt";
}
}

View File

@ -1,39 +1,183 @@
package net.knarcraft.blockhunt.manager;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.command.DefaultCommand;
import net.knarcraft.blockhunt.config.Key;
import net.knarcraft.blockhunt.command.BlockHuntCommand;
import net.knarcraft.blockhunt.command.BlockHuntTabCompleter;
import net.knarcraft.blockhunt.command.CreateCommand;
import net.knarcraft.blockhunt.command.HelpCommand;
import net.knarcraft.blockhunt.command.InfoCommand;
import net.knarcraft.blockhunt.command.JoinCommand;
import net.knarcraft.blockhunt.command.LeaveCommand;
import net.knarcraft.blockhunt.command.ListCommand;
import net.knarcraft.blockhunt.command.ReloadCommand;
import net.knarcraft.blockhunt.command.RemoveCommand;
import net.knarcraft.blockhunt.command.SetCommand;
import net.knarcraft.blockhunt.command.SetWarpCommand;
import net.knarcraft.blockhunt.command.ShopCommand;
import net.knarcraft.blockhunt.command.StartCommand;
import net.knarcraft.blockhunt.command.TokensCommand;
import net.knarcraft.blockhunt.command.WandCommand;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.config.Permission;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class CommandManager {
private static Command blockHuntCommand;
private static Command helpCommand;
private static Command joinCommand;
private static Command startCommand;
private static Command createCommand;
private static Command setCommand;
private static Command setWarpCommand;
private static Command removeCommand;
private static Command tokensCommand;
public final String name;
public final String label;
public final String args;
public final String argumentAliases;
public final Permission permission;
public final Key help;
public final boolean enabled;
public final List<String> mainTABlist;
public final DefaultCommand CMD;
public final String usage;
private CommandManager() {
public CommandManager(String name, String label, String args, String argumentAliases, Permission permission, Key help, Boolean enabled, List<String> mainTABlist,
DefaultCommand CMD, String usage) {
this.name = name;
this.label = label;
this.args = args;
this.argumentAliases = argumentAliases;
this.permission = permission;
this.help = help;
this.enabled = enabled;
this.mainTABlist = mainTABlist;
this.CMD = CMD;
this.usage = usage;
MemoryStorage.commands.add(this);
}
public static void load() {
if (blockHuntCommand != null) {
return;
}
List<String> BlockHuntCMD = new ArrayList<>() {{
add("info");
add("help");
add("reload");
add("join");
add("leave");
add("list");
add("shop");
add("start");
add("wand");
add("create");
add("set");
add("setWarp");
add("remove");
add("tokens");
}};
blockHuntCommand = new Command("BlockHunt", null, null, Permission.INFO,
MessageKey.HELP_INFO, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_INFO), BlockHuntCMD,
new InfoCommand(), null);
MemoryStorage.commands.add(blockHuntCommand);
MemoryStorage.commands.add(new Command("BlockHunt INFO", "info", "i",
Permission.INFO, MessageKey.HELP_INFO, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_INFO),
BlockHuntCMD, new InfoCommand(), "/BlockHunt [info|i]"));
helpCommand = new Command("BlockHunt HELP", "help", "h",
Permission.HELP, MessageKey.HELP_HELP, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_HELP),
BlockHuntCMD, new HelpCommand(), "/BlockHunt <help|h> [page number]");
MemoryStorage.commands.add(helpCommand);
MemoryStorage.commands.add(new Command("BlockHunt RELOAD", "reload", "r",
Permission.RELOAD, MessageKey.HELP_RELOAD,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_RELOAD), BlockHuntCMD,
new ReloadCommand(), "/BlockHunt <reload|r>"));
joinCommand = new Command("BlockHunt JOIN", "join", "j",
Permission.JOIN, MessageKey.HELP_JOIN, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_JOIN),
BlockHuntCMD, new JoinCommand(), "/BlockHunt <join|j> <arena name>");
MemoryStorage.commands.add(joinCommand);
MemoryStorage.commands.add(new Command("BlockHunt LEAVE", "leave", "l",
Permission.LEAVE, MessageKey.HELP_LEAVE, (Boolean) MemoryStorage.config.get(
ConfigKey.COMMAND_ENABLED_LEAVE), BlockHuntCMD, new LeaveCommand(), "/BlockHunt <leave|l>"));
MemoryStorage.commands.add(new Command("BlockHunt LIST", "list", "li",
Permission.LIST, MessageKey.HELP_LIST, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_LIST),
BlockHuntCMD, new ListCommand(), "/BlockHunt <list|li>"));
MemoryStorage.commands.add(new Command("BlockHunt SHOP", "shop", "sh",
Permission.SHOP, MessageKey.HELP_SHOP, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_SHOP),
BlockHuntCMD, new ShopCommand(), "/BlockHunt <shop|sh>"));
startCommand = new Command("BlockHunt START", "start", "go",
Permission.START, MessageKey.HELP_START,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_START), BlockHuntCMD, new StartCommand(),
"/BlockHunt <start|go> <arena name>");
MemoryStorage.commands.add(startCommand);
MemoryStorage.commands.add(new Command("BlockHunt WAND", "wand", "w",
Permission.CREATE, MessageKey.HELP_WAND, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_WAND),
BlockHuntCMD, new WandCommand(), "/BlockHunt <wand|w>"));
createCommand = new Command("BlockHunt CREATE", "create", "c",
Permission.CREATE, MessageKey.HELP_CREATE,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_CREATE), BlockHuntCMD, new CreateCommand(),
"/BlockHunt <create|c> <arena name>");
MemoryStorage.commands.add(createCommand);
setCommand = new Command("BlockHunt SET", "set", "s",
Permission.SET, MessageKey.HELP_SET, (Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_SET),
BlockHuntCMD, new SetCommand(), "/BlockHunt <set|s> <arena name>");
MemoryStorage.commands.add(setCommand);
setWarpCommand = new Command("BlockHunt SETWARP", "setWarp", "sw",
Permission.SET_WARP, MessageKey.HELP_SET_WARP,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_SET_WARP), BlockHuntCMD,
new SetWarpCommand(), "/BlockHunt <setWarp|sw> <lobby|hiders|seekers|spawn> <arena name>");
MemoryStorage.commands.add(setWarpCommand);
removeCommand = new Command("BlockHunt REMOVE", "remove", "delete",
Permission.REMOVE, MessageKey.HELP_REMOVE,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_REMOVE), BlockHuntCMD, new RemoveCommand(),
"/BlockHunt <remove|delete> <arena name>");
MemoryStorage.commands.add(removeCommand);
tokensCommand = new Command("BlockHunt TOKENS", "tokens", "t",
Permission.TOKENS, MessageKey.HELP_TOKENS,
(Boolean) MemoryStorage.config.get(ConfigKey.COMMAND_ENABLED_TOKENS), BlockHuntCMD, new TokensCommand(),
"/BlockHunt <tokens|t> <set|add|take> <player name> <amount>");
MemoryStorage.commands.add(tokensCommand);
registerCommand(new BlockHuntCommand(), new BlockHuntTabCompleter());
}
public static Command getRemoveCommand() {
return removeCommand;
}
public static Command getSetCommand() {
return setCommand;
}
public static Command getCreateCommand() {
return createCommand;
}
public static Command getStartCommand() {
return startCommand;
}
public static Command getHelpCommand() {
return helpCommand;
}
public static Command getTokensCommand() {
return tokensCommand;
}
public static Command getJoinCommand() {
return joinCommand;
}
public static Command setWarpCommand() {
return setWarpCommand;
}
/**
* Registers a command
*
* @param commandExecutor <p>The executor for the command</p>
* @param tabCompleter <p>The tab-completer to use, or null</p>
*/
private static void registerCommand(@NotNull CommandExecutor commandExecutor, @Nullable TabCompleter tabCompleter) {
PluginCommand command = BlockHunt.plugin.getCommand("BlockHunt");
if (command != null) {
command.setExecutor(commandExecutor);
if (tabCompleter != null) {
command.setTabCompleter(tabCompleter);
}
} else {
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Unable to register the command " + "BlockHunt");
}
}
}

View File

@ -30,22 +30,6 @@ public class ConfigManager {
this.load();
}
/**
* Use this class to create an automated config file.
*
* @param fileName Name of the file.
* @param subdirectory Sub-Location of the file.
*/
public ConfigManager(String fileName, String subdirectory) {
this.fileName = fileName;
File directory = new File(BlockHunt.plugin.getDataFolder(), subdirectory);
this.file = new File(directory, fileName + ".yml");
this.fileC = new YamlConfiguration();
this.checkFile();
fileC.getConfigurationSection("");
this.load();
}
/**
* Check if there are new files created if so, display a message to the
* console.
@ -84,12 +68,9 @@ public class ConfigManager {
public void checkFile() {
if (!this.file.exists()) {
try {
this.file.getParentFile().mkdirs();
this.file.createNewFile();
if (file.exists()) {
if (this.file.getParentFile().mkdirs() && this.file.createNewFile() && file.exists()) {
MemoryStorage.newFiles.add(this.fileName);
}
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -18,7 +18,7 @@ public class PermissionsManager {
* permission.
* @return True/False when either the player has the permission.
*/
public static boolean hasPerm(Player player, Permission perm, Boolean message) {
public static boolean hasPermission(Player player, Permission perm, Boolean message) {
PermissionDefault type = perm.type;
if (player == null) {
return true;
@ -60,55 +60,4 @@ public class PermissionsManager {
return false;
}
/**
* Check if a player has the permission. Also checks * related permissions.
* This permission does NOT have to be registered.
*
* @param player The player who needs the permission.
* @param type Type permission.
* @param perm The permission.
* @param message Send a message to the player saying you don't have the
* permission.
* @return True/False when either the player has the permission.
*/
public static boolean hasRawPerm(Player player, PermissionDefault type, String perm, Boolean message) {
if (player == null) {
return true;
}
if (type == PermissionDefault.ALL) {
return true;
} else if (type == PermissionDefault.OP) {
if (player.isOp()) {
return true;
}
} else if (type == PermissionDefault.ADMIN) {
if (player.hasPermission(BlockHunt.plugin.rootPermission + "admin")) {
return true;
}
} else if (type == PermissionDefault.MODERATOR) {
if (player.hasPermission(BlockHunt.plugin.rootPermission + "moderator")) {
return true;
}
} else if (type == PermissionDefault.PLAYER) {
if (player.hasPermission(BlockHunt.plugin.rootPermission + "player")) {
return true;
}
}
if (player.hasPermission("*")) {
return true;
} else if (player.hasPermission(BlockHunt.plugin.rootPermission + "*")) {
return true;
} else if (player.hasPermission(perm)) {
return true;
} else if (player.hasPermission(perm)) {
return true;
} else {
if (message) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_PERMISSION);
}
}
return false;
}
}