Cleans a lot of code and fixes several bugs

Fixes joining by sign click not working
Fixes negative numbers breaking variable parsing
Fixes many messages not displaying properly
This commit is contained in:
Kristian Knarvik 2023-07-23 20:15:40 +02:00
parent 79cd565cb5
commit b66c63f698
48 changed files with 1325 additions and 888 deletions

View File

@ -9,7 +9,7 @@
<plugin.version>${project.version}-${buildnumber}</plugin.version>
<buildnumber/>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spigot.api.version>1.18</spigot.api.version>
<spigot.api.version>1.20</spigot.api.version>
<spigot.version>${spigot.api.version}.1-R0.1-SNAPSHOT</spigot.version>
</properties>
<repositories>

View File

@ -23,9 +23,7 @@ import net.knarcraft.blockhunt.listener.OnPlayerTeleportEvent;
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 org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -43,14 +41,22 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static net.knarcraft.blockhunt.util.StringHelper.uppercaseAllFirst;
/**
* BlockHunt's main class
*/
public class BlockHunt extends JavaPlugin implements Listener {
private static PluginDescriptionFile pluginDescriptionFile;
public static BlockHunt plugin;
public String rootPermission;
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
@ -81,273 +87,37 @@ public class BlockHunt extends JavaPlugin implements Listener {
CommandManager.load();
if (!getServer().getPluginManager().isPluginEnabled("LibsDisguises")) {
MessageManager.broadcastFMessage(MessageKey.ERROR_LIBS_DISGUISES_NOT_INSTALLED);
MessageHelper.broadcastMessage(MessageKey.ERROR_LIBS_DISGUISES_NOT_INSTALLED);
Bukkit.getServer().getPluginManager().disablePlugin(this);
return;
}
if (!getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
MessageManager.broadcastFMessage(MessageKey.ERROR_PROTOCOL_LIB_NOT_INSTALLED);
MessageHelper.broadcastMessage(MessageKey.ERROR_PROTOCOL_LIB_NOT_INSTALLED);
Bukkit.getServer().getPluginManager().disablePlugin(this);
return;
}
ArenaHandler.loadArenas();
MessageManager.sendFMessage(null, MessageKey.LOG_ENABLED_PLUGIN, "name-" + BlockHunt.pluginDescriptionFile.getName(), "version-" + BlockHunt.pluginDescriptionFile.getVersion(), "authors-"
+ BlockHunt.pluginDescriptionFile.getAuthors().get(0));
MessageHelper.sendMessage(null, MessageKey.LOG_ENABLED_PLUGIN, "name-" +
BlockHunt.pluginDescriptionFile.getName(), "version-" + BlockHunt.pluginDescriptionFile.getVersion(),
"authors-" + BlockHunt.pluginDescriptionFile.getAuthors().get(0));
// Welcome to the massive game loop!!
getServer().getScheduler().runTaskTimer(this, () -> {
for (Arena arena : MemoryStorage.arenaMap.values()) {
if (arena.gameState == ArenaState.WAITING) {
if (arena.playersInArena.size() >= arena.minPlayers) {
arena.gameState = ArenaState.STARTING;
arena.timer = arena.timeInLobbyUntilStart;
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timeInLobbyUntilStart);
}
} else if (arena.gameState == ArenaState.STARTING) {
arena.timer = arena.timer - 1;
if (arena.timer > 0) {
if (arena.timer == 60 || arena.timer == 30 || arena.timer == 10) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
} else if (arena.timer <= 5) {
World world = arena.arenaLocations.getLobbyWarp().getWorld();
if (world != null) {
int pitch = (int) (2 - Math.floor(arena.timer / 2.0));
world.playSound(arena.arenaLocations.getLobbyWarp(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
}
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
}
} else {
arena.gameState = ArenaState.IN_GAME;
arena.timer = arena.gameTime;
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_STARTED, "secs-" + arena.waitingTimeSeeker);
for (int i = arena.amountSeekersOnStart; i > 0; i = i - 1) {
boolean loop = true;
Player seeker = arena.playersInArena.get(MemoryStorage.random.nextInt(arena.playersInArena.size()));
for (Player playerCheck : arena.playersInArena) {
if (MemoryStorage.chosenSeeker.get(playerCheck) != null) {
if (MemoryStorage.chosenSeeker.get(playerCheck)) {
seeker = playerCheck;
MemoryStorage.chosenSeeker.remove(playerCheck);
} else {
if (seeker.equals(playerCheck)) {
i = i + 1;
loop = false;
}
}
}
}
if (loop) {
if (!arena.seekers.contains(seeker)) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + seeker.getName());
arena.seekers.add(seeker);
PlayerHandler.teleport(seeker, arena.arenaLocations.getSeekersWarp());
seeker.getInventory().clear();
seeker.updateInventory();
seeker.setWalkSpeed(0.3F);
MemoryStorage.seekerTime.put(seeker, arena.waitingTimeSeeker);
} else {
i = i + 1;
}
}
}
for (Player arenaPlayer : arena.playersInArena) {
if (!arena.seekers.contains(arenaPlayer)) {
arenaPlayer.getInventory().clear();
arenaPlayer.updateInventory();
ItemStack block = arena.disguiseBlocks.get(MemoryStorage.random.nextInt(arena.disguiseBlocks.size()));
if (MemoryStorage.chosenBlock.get(arenaPlayer) != null) {
block = MemoryStorage.chosenBlock.get(arenaPlayer);
MemoryStorage.chosenBlock.remove(arenaPlayer);
}
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
DisguiseAPI.disguiseToAll(arenaPlayer, disguise);
PlayerHandler.teleport(arenaPlayer, arena.arenaLocations.getHidersWarp());
ItemStack blockCount = new ItemStack(block.getType(), 5);
arenaPlayer.getInventory().setItem(8, blockCount);
arenaPlayer.getInventory().setHelmet(new ItemStack(block));
MemoryStorage.pBlock.put(arenaPlayer, block);
String blockName = block.getType().name();
blockName = WordUtils.capitalizeFully(blockName.replace("_", " "));
MessageManager.sendFMessage(arenaPlayer, MessageKey.NORMAL_IN_GAME_BLOCK,
"block-" + blockName);
}
}
}
}
for (Player player : arena.seekers) {
ItemStack item = player.getInventory().getItem(0);
if (item == null || item.getType() != Material.DIAMOND_SWORD) {
player.getInventory().clear(); // semi prevent duping infinite swords. TODO: Fix this properly
ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);
i.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
player.getInventory().setItem(0, i);
player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET, 1));
player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS, 1));
ItemStack infBow = new ItemStack(Material.BOW, 1);
infBow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
player.getInventory().setItem(1, infBow);
player.getInventory().setItem(2, new ItemStack(Material.ARROW, 1));
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_USE, 1, 1);
}
if (MemoryStorage.seekerTime.get(player) != null) {
MemoryStorage.seekerTime.put(player, MemoryStorage.seekerTime.get(player) - 1);
if (MemoryStorage.seekerTime.get(player) <= 0) {
PlayerHandler.teleport(player, arena.arenaLocations.getHidersWarp());
MemoryStorage.seekerTime.remove(player);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED,
"%playerName%-" + player.getName());
}
}
}
if (arena.gameState == ArenaState.IN_GAME) {
arena.timer = arena.timer - 1;
if (arena.timer > 0) {
if (arena.timer == arena.gameTime - arena.timeUntilHidersSword) {
ItemStack sword = new ItemStack(Material.WOODEN_SWORD, 1);
sword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 2);
for (Player arenaPlayer : arena.playersInArena) {
if (!arena.seekers.contains(arenaPlayer)) {
arenaPlayer.getInventory().addItem(sword);
MessageManager.sendFMessage(arenaPlayer, MessageKey.NORMAL_IN_GAME_GIVEN_SWORD);
}
}
}
// blockAnnouncer code.
if ((arena.blockAnnouncerTime > 0) && (arena.timer == arena.blockAnnouncerTime)) {
List<String> remainingBlocks = new ArrayList<>();
for (Player arenaPlayer : arena.playersInArena) {
if (!arena.seekers.contains(arenaPlayer)) {
ItemStack item = arenaPlayer.getInventory().getItem(8);
String block = item == null ? Material.AIR.name() : item.getType().name();
block = WordUtils.capitalizeFully(block.replace("_", " "));
if (!remainingBlocks.contains(block)) { //Don't print double up block names.
remainingBlocks.add(block);
}
}
}
String blocklist = StringUtils.join(remainingBlocks, ", ");
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_BLOCKS_LEFT, "1-" + blocklist);
}
if (arena.timer == 190 || arena.timer == 60 || arena.timer == 30 || arena.timer == 10) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_ARENA_END, "1-" + arena.timer);
} else if (arena.timer <= 5) {
World world = arena.arenaLocations.getLobbyWarp().getWorld();
if (world != null) {
int pitch = (int) (2 - Math.floor(arena.timer / 2.0));
world.playSound(arena.arenaLocations.getLobbyWarp(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
}
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
}
} else {
ArenaHandler.hidersWin(arena);
return;
}
for (Player player : arena.playersInArena) {
if (!arena.seekers.contains(player)) {
Location pLoc = player.getLocation();
Location moveLoc = MemoryStorage.moveLoc.get(player);
ItemStack block = player.getInventory().getItem(8);
if (block == null) {
if (MemoryStorage.pBlock.get(player) != null) {
block = MemoryStorage.pBlock.get(player);
player.getInventory().setItem(8, block);
player.updateInventory();
}
}
if (moveLoc != null && block != null) {
if (moveLoc.getX() == pLoc.getX() && moveLoc.getY() == pLoc.getY() &&
moveLoc.getZ() == pLoc.getZ()) {
if (block.getAmount() > 1) {
block.setAmount(block.getAmount() - 1);
} else {
Block pBlock = player.getLocation().getBlock();
BlockData pBlockData = pBlock.getBlockData();
if (pBlockData.getMaterial().equals(Material.AIR) || pBlockData.getMaterial().equals(Material.WATER)
|| pBlockData.getMaterial().equals(Material.WATER)) {
if (pBlockData.getMaterial().equals(Material.WATER) || pBlockData.getMaterial().equals(Material.WATER)) {
MemoryStorage.hiddenLocWater.put(player, true);
} else {
MemoryStorage.hiddenLocWater.put(player, false);
}
if (DisguiseAPI.isDisguised(player)) {
DisguiseAPI.undisguiseToAll(player);
for (Player pl : Bukkit.getOnlinePlayers()) {
if (!pl.equals(player)) {
pl.hidePlayer(this, player);
pl.sendBlockChange(pBlock.getLocation(), block.getType().createBlockData());
}
}
block.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
player.playSound(pLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
MemoryStorage.hiddenLoc.put(player, moveLoc);
String blockName = block.getType().name();
blockName = WordUtils.capitalizeFully(blockName.replace("_", " "));
MessageManager.sendFMessage(player, MessageKey.NORMAL_IN_GAME_NOW_SOLID, "block-"
+ blockName);
}
for (Player pl : Bukkit.getOnlinePlayers()) {
if (!pl.equals(player)) {
pl.hidePlayer(this, player);
pl.sendBlockChange(pBlock.getLocation(), block.getType().createBlockData());
}
}
} else {
MessageManager.sendFMessage(player, MessageKey.WARNING_IN_GAME_NO_SOLID_PLACE);
}
}
} else {
block.setAmount(5);
if (!DisguiseAPI.isDisguised(player)) {
SolidBlockHandler.makePlayerUnsolid(player);
}
}
}
}
}
ScoreboardHandler.updateScoreboard(arena); // TODO Only do this when needed (player added/removed)
}
for (Player pl : arena.playersInArena) {
pl.setLevel(arena.timer);
if (arena.seekers.contains(pl)) {
pl.setGameMode(GameMode.SURVIVAL);
} else {
pl.setGameMode(GameMode.ADVENTURE);
}
}
}
SignsHandler.updateSigns(); //TODO Only do this when needed (game-state change or player count change)
}, 0, 20);
getServer().getScheduler().runTaskTimer(this, this::updateArenaStates, 0, 20);
}
@Override
public void onDisable() {
for (Arena arena : MemoryStorage.arenaMap.values()) {
String cause = "[BlockHunt] Arena " + arena.arenaName + " has been stopped";
ArenaHandler.stopArena(arena, cause, MessageKey.WARNING_ARENA_STOPPED);
}
MessageManager.sendFMessage(null, MessageKey.LOG_DISABLED_PLUGIN, "name-" + BlockHunt.pluginDescriptionFile.getName(), "version-" + BlockHunt.pluginDescriptionFile.getVersion(), "authors-"
+ BlockHunt.pluginDescriptionFile.getAuthors().get(0));
MessageHelper.sendMessage(null, MessageKey.LOG_DISABLED_PLUGIN, "name-" +
BlockHunt.pluginDescriptionFile.getName(), "version-" + BlockHunt.pluginDescriptionFile.getVersion(),
"authors-" + BlockHunt.pluginDescriptionFile.getAuthors().get(0));
}
public static PluginDescriptionFile getPluginDescriptionFile() {
@ -355,17 +125,396 @@ public class BlockHunt extends JavaPlugin implements Listener {
}
/**
* Short a String for like the Scoreboard title.
* Shorten a String for things like the Scoreboard title.
*
* @param string String to be shortened.
* @param maxLength Max length of the characters.
* @return Shorten string, else normal string.
* @param string <p>The string to be shortened</p>
* @param maxLength <p>The maximum amount of characters allowed</p>
* @return <p>The shortened string, or the original string if already short enough</p>
*/
public static String cutString(String string, int maxLength) {
if (string.length() > maxLength) {
string = string.substring(0, maxLength);
if (string.length() <= maxLength) {
return string;
} else {
return string.substring(0, maxLength);
}
}
private void updateArenaStates() {
for (Arena arena : MemoryStorage.arenaMap.values()) {
if (arena.gameState == ArenaState.WAITING) {
if (arena.playersInArena.size() >= arena.minPlayers) {
arena.gameState = ArenaState.STARTING;
arena.timer = arena.timeInLobbyUntilStart;
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" +
arena.timeInLobbyUntilStart);
}
} else if (arena.gameState == ArenaState.STARTING) {
updateStartingArena(arena);
}
// TODO: Figure out a better way to do this. Currently, individual seeker timers are used to allow another
// player to take over if a seeker leaves the game. But assuming the game is already running, wouldn't it
// make more sense to allow the seeker to seek immediately?
for (Player player : arena.seekers) {
// Reduce the seeker wait timer if necessary
Integer seekerTime = MemoryStorage.seekerTime.get(player);
if (seekerTime != null) {
MemoryStorage.seekerTime.put(player, --seekerTime);
if (seekerTime <= 0) {
// Teleport the seeker to the hiders warp, and allow them to seek
PlayerHandler.teleport(player, arena.arenaLocations.getHidersWarp());
MemoryStorage.seekerTime.remove(player);
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED,
"%playerName%-" + player.getName());
}
}
}
if (arena.gameState == ArenaState.IN_GAME) {
updateInGameArena(arena);
}
for (Player pl : arena.playersInArena) {
pl.setLevel(arena.timer);
if (arena.seekers.contains(pl)) {
pl.setGameMode(GameMode.SURVIVAL);
} else {
pl.setGameMode(GameMode.ADVENTURE);
}
}
}
SignsHandler.updateSigns(); //TODO Only do this when needed (game-state change or player count change)
}
/**
* Updates the state of an arena that's in the process of starting
*
* @param arena <p>An arena in the STARTING state</p>
*/
private void updateStartingArena(Arena arena) {
// Reduce the arena's timer
arena.timer -= 1;
if (arena.timer > 0) {
if (arena.timer == 60 || arena.timer == 30 || arena.timer == 10) {
// Announce when the arena starts
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
} else if (arena.timer <= 5) {
// Count down from 5 seconds
World world = null;
Location warp = arena.arenaLocations.getLobbyWarp();
if (warp != null) {
world = warp.getWorld();
}
if (world != null) {
int pitch = (int) (2 - Math.floor(arena.timer / 2.0));
world.playSound(arena.arenaLocations.getLobbyWarp(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,
pitch);
}
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
}
} else {
startArena(arena);
}
}
/**
* Starts an arena
*
* @param arena <p>The arena to start</p>
*/
private void startArena(Arena arena) {
// Update the game state, and set the timer to count down from the specified game-time
arena.gameState = ArenaState.IN_GAME;
arena.timer = arena.gameTime;
// Assign the necessary seekers
assignSeekers(arena);
// Assign the necessary hiders
assignHiders(arena);
MessageHelper.broadcastMessage(arena.hiders, MessageKey.NORMAL_LOBBY_ARENA_STARTED_HIDERS,
"seconds-" + arena.waitingTimeSeeker);
MessageHelper.broadcastMessage(arena.seekers, MessageKey.NORMAL_LOBBY_ARENA_STARTED_SEEKERS,
"seconds-" + arena.waitingTimeSeeker);
}
/**
* Assigns all non-seekers in an arena as hiders
*
* @param arena <p>The arena to assign hiders for</p>
*/
private void assignHiders(Arena arena) {
List<Player> possibleHiders = new ArrayList<>(arena.playersInArena);
possibleHiders.removeAll(arena.seekers);
// Assign all non-seekers to hiders
for (Player arenaPlayer : possibleHiders) {
arena.hiders.add(arenaPlayer);
// Clear the player's inventory
arenaPlayer.getInventory().clear();
// Assign a random disguise block
ItemStack block = arena.disguiseBlocks.get(MemoryStorage.random.nextInt(arena.disguiseBlocks.size()));
// If the player has chosen their block type, use that instead
if (MemoryStorage.chosenBlock.get(arenaPlayer) != null) {
block = MemoryStorage.chosenBlock.get(arenaPlayer);
MemoryStorage.chosenBlock.remove(arenaPlayer);
}
// Disguise the hider from all players
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
DisguiseAPI.disguiseToAll(arenaPlayer, disguise);
// Teleport to the hiders warp
PlayerHandler.teleport(arenaPlayer, arena.arenaLocations.getHidersWarp());
// Put the block in the player's inventory and on the player's head, so they know which block they are
ItemStack blockTimer = new ItemStack(block.getType(), 5);
arenaPlayer.getInventory().setItem(8, blockTimer);
arenaPlayer.getInventory().setHelmet(new ItemStack(block));
MemoryStorage.playerBlock.put(arenaPlayer, block);
// Tell the player which block they are disguised as
String blockName = block.getType().name();
blockName = uppercaseAllFirst(blockName.replace("_", " "));
MessageHelper.sendMessage(arenaPlayer, MessageKey.NORMAL_IN_GAME_BLOCK,
"block-" + blockName);
}
}
/**
* Assigns necessary seekers for the given arena
*
* @param arena <p>The arena to assign seekers to</p>
*/
private void assignSeekers(Arena arena) {
List<Player> possibleSeekers = new ArrayList<>(arena.playersInArena);
// Prioritize players that have asked to be seekers
int seekers = 0;
for (Player player : arena.playersInArena) {
/* Add the player as a seeker if they prefer to be a seeker, or remove them from possible seekers if they
have set themselves as a hider */
Boolean chosenSeeker = MemoryStorage.chosenSeeker.get(player);
if (chosenSeeker != null) {
if (chosenSeeker) {
addSeeker(arena, player);
}
possibleSeekers.remove(player);
}
// Prevent more than the max amount of seekers from being assigned
if (seekers >= arena.amountSeekersOnStart) {
break;
}
}
// Randomly assign the required amount of seekers
for (int i = seekers; i < arena.amountSeekersOnStart; i++) {
// Prevent an infinite loop if it's impossible to assign the required amount of seekers
if (possibleSeekers.size() == 0) {
break;
}
// Add a random seeker
Player seeker = possibleSeekers.remove(MemoryStorage.random.nextInt(possibleSeekers.size()));
addSeeker(arena, seeker);
}
}
/**
* Adds a single seeker to an arena, and teleports them to the seekers warp
*
* @param arena <p>The arena to assign a seeker for</p>
* @param player <p>The player to assign as a seeker</p>
*/
private void addSeeker(Arena arena, Player player) {
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + player.getName());
arena.seekers.add(player);
PlayerHandler.teleport(player, arena.arenaLocations.getSeekersWarp());
player.getInventory().clear();
player.setWalkSpeed(0.3F);
MemoryStorage.seekerTime.put(player, arena.waitingTimeSeeker);
// Give the seeker their armor and sword
giveSeekerItems(player);
}
/**
* Gives a seeker their armor, sword and bow items
*
* @param player <p>The player to give seeker items to</p>
*/
private void giveSeekerItems(Player player) {
ItemStack swordItem = new ItemStack(Material.DIAMOND_SWORD, 1);
swordItem.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
player.getInventory().setItem(0, swordItem);
player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET, 1));
player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS, 1));
ItemStack infinityBowItem = new ItemStack(Material.BOW, 1);
infinityBowItem.addEnchantment(Enchantment.ARROW_INFINITE, 1);
player.getInventory().setItem(1, infinityBowItem);
player.getInventory().setItem(2, new ItemStack(Material.ARROW, 1));
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_USE, 1, 1);
}
/**
* Updates an arena that's currently in-game
*
* @param arena <P>The arena to update</P>
*/
private void updateInGameArena(Arena arena) {
arena.timer--;
// If the game ends, trigger the hiders' win
if (arena.timer <= 0) {
ArenaHandler.hidersWin(arena);
return;
}
// If "timeUntilHidersSword" has passed, give the hiders their sword
if (arena.timer == arena.gameTime - arena.timeUntilHidersSword) {
ItemStack sword = new ItemStack(Material.WOODEN_SWORD, 1);
sword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 2);
for (Player arenaPlayer : arena.hiders) {
arenaPlayer.getInventory().addItem(sword);
MessageHelper.sendMessage(arenaPlayer, MessageKey.NORMAL_IN_GAME_GIVEN_SWORD);
}
}
// Announce the type of blocks the remaining hiders are disguised as
if (arena.blockAnnouncerTime > 0 && arena.timer == arena.blockAnnouncerTime) {
Set<String> remainingBlocks = new HashSet<>();
for (Player arenaPlayer : arena.hiders) {
ItemStack item = arenaPlayer.getInventory().getItem(8);
String block = (item == null ? Material.AIR : item.getType()).name();
remainingBlocks.add(uppercaseAllFirst(block.replace("_", " ")));
}
String blocklist = String.join(", ", remainingBlocks);
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_BLOCKS_LEFT, "1-" + blocklist);
}
// Count down towards the end of the arena
if (arena.timer == 190 || arena.timer == 60 || arena.timer == 30 || arena.timer == 10 || arena.timer <= 5) {
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_ARENA_END, "1-" + arena.timer);
}
// Play a sound for the last 5 seconds of the arena game's duration
if (arena.timer <= 5) {
Location location = arena.arenaLocations.getLobbyWarp();
if (location != null && location.getWorld() != null) {
int pitch = (int) (2 - Math.floor(arena.timer / 2.0));
location.getWorld().playSound(arena.arenaLocations.getLobbyWarp(),
Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, pitch);
}
}
for (Player player : arena.hiders) {
updateHiddenState(player);
}
ScoreboardHandler.updateScoreboard(arena); // TODO Only do this when needed (player added/removed)
}
/**
* Updates the hidden state of the given hider
*
* @param player <p>A player that's currently a hider</p>
*/
private void updateHiddenState(Player player) {
Location playerLocation = player.getLocation();
Location moveLocation = MemoryStorage.moveLocation.get(player);
// If the hider has somehow lost their disguise block from their inventory,
ItemStack inventoryBlock = player.getInventory().getItem(8);
if (inventoryBlock == null && MemoryStorage.playerBlock.get(player) != null) {
inventoryBlock = MemoryStorage.playerBlock.get(player);
player.getInventory().setItem(8, inventoryBlock);
}
if (moveLocation == null || inventoryBlock == null) {
return;
}
// If the player is standing still, try to turn the player into a solid block
if (moveLocation.getX() == playerLocation.getX() && moveLocation.getY() == playerLocation.getY() &&
moveLocation.getZ() == playerLocation.getZ()) {
if (inventoryBlock.getAmount() > 1) {
// Just decrease the timer
inventoryBlock.setAmount(inventoryBlock.getAmount() - 1);
} else {
// Try to make the player solid
Block playerBlock = player.getLocation().getBlock();
BlockData playerBlockData = playerBlock.getBlockData();
if (playerBlockData.getMaterial().isAir() || playerBlockData.getMaterial().equals(Material.WATER)) {
makePlayerSolid(player, playerBlock, playerBlockData, inventoryBlock, playerLocation);
} else {
MessageHelper.sendMessage(player, MessageKey.WARNING_IN_GAME_NO_SOLID_PLACE);
}
}
} else {
// The player moved. Un-hide and reset the hide timer
inventoryBlock.setAmount(5);
if (!DisguiseAPI.isDisguised(player)) {
SolidBlockHandler.makePlayerUnsolid(player);
}
}
}
/**
* Makes a player into a perceived solid block
*
* @param player <p>The player to make solid</p>
* @param playerBlock <p>The block the player is currently standing at</p>
* @param playerBlockData <p>The data of the block the player is currently standing at</p>
* @param inventoryBlock <p>The inventory block which corresponds to the player's hide material</p>
* @param playerLocation <p>The current location of the player</p>
*/
private void makePlayerSolid(Player player, Block playerBlock, BlockData playerBlockData, ItemStack inventoryBlock,
Location playerLocation) {
// Store whether the player is replacing water so the water can be restored afterwards
if (playerBlockData.getMaterial().equals(Material.WATER)) {
MemoryStorage.hiddenLocationWater.put(player, true);
} else {
MemoryStorage.hiddenLocationWater.put(player, false);
}
if (DisguiseAPI.isDisguised(player)) {
// Hide the player, and make all other players see a full block in the player's location
DisguiseAPI.undisguiseToAll(player);
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (!onlinePlayer.equals(player)) {
onlinePlayer.hidePlayer(this, player);
onlinePlayer.sendBlockChange(playerBlock.getLocation(),
inventoryBlock.getType().createBlockData());
}
}
inventoryBlock.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
player.playSound(playerLocation, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
// Store the location the player is hidden at
MemoryStorage.hiddenLocation.put(player, playerLocation);
// Announce to the player that they are now hidden
String blockName = inventoryBlock.getType().name();
blockName = uppercaseAllFirst(blockName.replace("_", " "));
MessageHelper.sendMessage(player, MessageKey.NORMAL_IN_GAME_NOW_SOLID, "block-"
+ blockName);
}
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
if (otherPlayer.equals(player)) {
continue;
}
// Hide the player and update the perceived
otherPlayer.hidePlayer(this, player);
otherPlayer.sendBlockChange(playerBlock.getLocation(), inventoryBlock.getType().createBlockData());
}
return string;
}
}

View File

@ -5,8 +5,8 @@ import net.knarcraft.blockhunt.arena.ArenaProperty;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.config.Permission;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -28,11 +28,11 @@ public class InventoryHandler {
if (shorten.length() > 6) {
shorten = shorten.substring(0, 6);
}
Inventory panel = Bukkit.createInventory(null, 54, MessageManager.replaceAll("\u00A7r%N&lBlockHunt Arena: %A" + shorten));
Inventory panel = Bukkit.createInventory(null, 54, MessageHelper.replaceAll("\u00A7r%N&lBlockHunt Arena: %A" + shorten));
ItemStack arenaNameNote = new ItemStack(Material.PAPER, 1);
ItemMeta arenaNameNote_IM = arenaNameNote.getItemMeta();
arenaNameNote_IM.setDisplayName(MessageManager.replaceAll("%NBlockHunt arena: %A" + arena.arenaName));
arenaNameNote_IM.setDisplayName(MessageHelper.replaceAll("%NBlockHunt arena: %A" + arena.arenaName));
arenaNameNote.setItemMeta(arenaNameNote_IM);
panel.setItem(0, arenaNameNote);
@ -64,7 +64,7 @@ public class InventoryHandler {
ItemStack disguiseBlocks_NOTE = new ItemStack(Material.BOOK, 1);
ItemMeta disguiseBlocks_NOTE_IM = disguiseBlocks_NOTE.getItemMeta();
disguiseBlocks_NOTE_IM.setDisplayName(MessageManager.replaceAll("%NSet the %AdisguiseBlocks%N."));
disguiseBlocks_NOTE_IM.setDisplayName(MessageHelper.replaceAll("%NSet the %AdisguiseBlocks%N."));
disguiseBlocks_NOTE.setItemMeta(disguiseBlocks_NOTE_IM);
panel.setItem(36, disguiseBlocks_NOTE);
@ -119,7 +119,7 @@ public class InventoryHandler {
player.openInventory(panel);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
}
}
@ -127,7 +127,7 @@ public class InventoryHandler {
String addRemove, ItemStack upItem, ItemStack buttonItem, ItemStack downItem,
int up, int button, int down) {
ItemMeta upItemItemMeta = upItem.getItemMeta();
upItemItemMeta.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.messages.get(MessageKey.BUTTON_ADD),
upItemItemMeta.setDisplayName(MessageHelper.replaceAll((String) MemoryStorage.messages.get(MessageKey.BUTTON_ADD),
"1-" + addRemove, "2-" + option));
upItem.setItemMeta(upItemItemMeta);
@ -146,12 +146,12 @@ public class InventoryHandler {
};
ItemMeta buttonItemMeta = buttonItem.getItemMeta();
buttonItemMeta.setDisplayName(MessageManager.replaceAll(
buttonItemMeta.setDisplayName(MessageHelper.replaceAll(
(String) MemoryStorage.messages.get(MessageKey.BUTTON_SETTING), "1-" + option, "2-" + setting));
buttonItem.setItemMeta(buttonItemMeta);
ItemMeta DOWN_IM = downItem.getItemMeta();
DOWN_IM.setDisplayName(MessageManager.replaceAll(
DOWN_IM.setDisplayName(MessageHelper.replaceAll(
(String) MemoryStorage.messages.get(MessageKey.BUTTON_REMOVE), "1-" + addRemove, "2-" + option));
downItem.setItemMeta(DOWN_IM);
@ -162,13 +162,13 @@ public class InventoryHandler {
public static void openDisguiseBlocks(Arena arena, Player player) {
String arenaName = arena.arenaName;
Inventory panel = Bukkit.createInventory(null, 36, MessageManager.replaceAll("%N&lDisguiseBlocks"));
Inventory panel = Bukkit.createInventory(null, 36, MessageHelper.replaceAll("%N&lDisguiseBlocks"));
ItemStack arenaNameNote = new ItemStack(Material.PAPER, 1);
ItemMeta arenaNameNoteItemMeta = arenaNameNote.getItemMeta();
arenaNameNoteItemMeta.setDisplayName(MessageManager.replaceAll("%NDisguiseBlocks of arena: %A" + arenaName));
arenaNameNoteItemMeta.setDisplayName(MessageHelper.replaceAll("%NDisguiseBlocks of arena: %A" + arenaName));
List<String> loreLines = new ArrayList<>();
loreLines.add(MessageManager.replaceAll("%NPlace the DisguiseBlocks inside this inventory."));
loreLines.add(MessageHelper.replaceAll("%NPlace the DisguiseBlocks inside this inventory."));
arenaNameNoteItemMeta.setLore(loreLines);
arenaNameNote.setItemMeta(arenaNameNoteItemMeta);
panel.setItem(0, arenaNameNote);
@ -181,33 +181,33 @@ public class InventoryHandler {
}
public static void openShop(Player player) {
Inventory shop = Bukkit.createInventory(null, 9, MessageManager.replaceAll("\u00A7r" +
Inventory shop = Bukkit.createInventory(null, 9, MessageHelper.replaceAll("\u00A7r" +
MemoryStorage.config.get(ConfigKey.SHOP_TITLE)));
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
List<String> loreLines;
List<String> loreLines2;
ItemStack shopTokens = new ItemStack(Material.EMERALD, 1);
ItemMeta shopTokens_IM = shopTokens.getItemMeta();
shopTokens_IM.setDisplayName(MessageManager.replaceAll("%N&lTokens: %A" + playerTokens));
shopTokens_IM.setDisplayName(MessageHelper.replaceAll("%N&lTokens: %A" + playerTokens));
shopTokens.setItemMeta(shopTokens_IM);
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(
shopBlockChooser_IM.setDisplayName(MessageHelper.replaceAll((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
loreLines = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
loreLines = MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
loreLines2 = new ArrayList<>();
for (String lore : loreLines) {
loreLines2.add(MessageManager.replaceAll(lore));
loreLines2.add(MessageHelper.replaceAll(lore));
}
loreLines2.add(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE),
loreLines2.add(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE),
"amount-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_PRICE)));
shopBlockChooser_IM.setLore(loreLines2);
@ -216,15 +216,15 @@ public class InventoryHandler {
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ID_NAME)), 1);
ItemMeta shopBlockHuntPass_IM = shopBlockHuntPass.getItemMeta();
shopBlockHuntPass_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(
shopBlockHuntPass_IM.setDisplayName(MessageHelper.replaceAll((String) MemoryStorage.config.get(
ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
loreLines = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
loreLines = MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
loreLines2 = new ArrayList<>();
for (String lore : loreLines) {
loreLines2.add(MessageManager.replaceAll(lore));
loreLines2.add(MessageHelper.replaceAll(lore));
}
loreLines2.add(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE),
loreLines2.add(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_PRICE),
"amount-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_PRICE)));
shopBlockHuntPass_IM.setLore(loreLines2);
@ -232,7 +232,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 &&
&& (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".blockchooser") == null &&
!PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false))) {
shop.setItem(1, shopBlockChooser);
}

View File

@ -34,22 +34,25 @@ public class MemoryStorage {
* Add any variable you need in different classes here:
*/
// The first position selected with the arena selection tool
public static final Map<Player, Location> pos1 = new HashMap<>();
// The second position selected with the arena selection tool
public static final Map<Player, Location> pos2 = new HashMap<>();
public static final Map<String, Arena> arenaMap = new HashMap<>();
public static final Random random = new Random();
public static final Map<Player, Integer> seekerTime = new HashMap<>();
public static final Map<Player, PlayerArenaData> pData = new HashMap<>();
public static final Map<Player, PlayerArenaData> playerData = new HashMap<>();
public static final Map<Player, ItemStack> chosenBlock = new HashMap<>();
public static final Map<Player, Boolean> chosenSeeker = new HashMap<>();
public static final Map<Player, ItemStack> pBlock = new HashMap<>();
public static final Map<Player, Location> moveLoc = new HashMap<>();
public static final Map<Player, Location> hiddenLoc = new HashMap<>();
public static final Map<Player, Boolean> hiddenLocWater = new HashMap<>();
public static final Map<Player, ItemStack> playerBlock = new HashMap<>();
public static final Map<Player, Location> moveLocation = new HashMap<>();
public static final Map<Player, Location> hiddenLocation = new HashMap<>();
// Whether the player's hidden location contained water
public static final Map<Player, Boolean> hiddenLocationWater = new HashMap<>();
public static final Map<Player, Location> teleportLoc = new HashMap<>();
public static final Map<Player, Location> teleportLocation = new HashMap<>();
}

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
public class PlayerHandler {
public static boolean teleport(Player player, Location location) {
MemoryStorage.teleportLoc.put(player, location);
MemoryStorage.teleportLocation.put(player, location);
return player.teleport(location);
}
}

View File

@ -3,9 +3,10 @@ package net.knarcraft.blockhunt;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
@ -20,20 +21,22 @@ public class ScoreboardHandler {
return;
}
String displayName = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TITLE)), 32);
Objective object = board.registerNewObjective(BlockHunt.cutString(arena.arenaName, 32), "dummy", displayName);
String displayName = BlockHunt.cutString(MessageHelper.replaceAll(
(String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TITLE)), 32);
Objective object = board.registerNewObjective(BlockHunt.cutString(arena.arenaName, 32),
Criteria.DUMMY, displayName);
object.setDisplaySlot(DisplaySlot.SIDEBAR);
String temp = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TIME_LEFT)), 32);
String temp = BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TIME_LEFT)), 32);
Score timeleft = object.getScore(temp);
timeleft.setScore(arena.timer);
temp = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_SEEKERS)), 32);
temp = BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_SEEKERS)), 32);
Score seekers = object.getScore(temp);
seekers.setScore(arena.seekers.size());
temp = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_HIDERS)), 32);
temp = BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_HIDERS)), 32);
Score hiders = object.getScore(temp);
hiders.setScore(arena.playersInArena.size() - arena.seekers.size());
@ -53,17 +56,17 @@ public class ScoreboardHandler {
if ((Boolean) MemoryStorage.config.get(ConfigKey.SCOREBOARD_ENABLED)) {
Scoreboard board = arena.scoreboard;
Objective object = board.getObjective(DisplaySlot.SIDEBAR);
object.setDisplayName(BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TITLE)), 32));
object.setDisplayName(BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TITLE)), 32));
String temp = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TIME_LEFT)), 32);
String temp = BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_TIME_LEFT)), 32);
Score timeleft = object.getScore(temp);
timeleft.setScore(arena.timer);
temp = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_SEEKERS)), 32);
temp = BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_SEEKERS)), 32);
Score seekers = object.getScore(temp);
seekers.setScore(arena.seekers.size());
temp = BlockHunt.cutString(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_HIDERS)), 32);
temp = BlockHunt.cutString(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SCOREBOARD_HIDERS)), 32);
Score hiders = object.getScore(temp);
hiders.setScore(arena.playersInArena.size() - arena.seekers.size());

View File

@ -4,9 +4,10 @@ import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Location;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.event.block.SignChangeEvent;
import java.util.List;
@ -28,7 +29,7 @@ public class SignsHandler {
}
if (!saved) {
MessageManager.sendFMessage(event.getPlayer(), MessageKey.ERROR_NO_ARENA, "name-" + lines[1]);
MessageHelper.sendMessage(event.getPlayer(), MessageKey.ERROR_NO_ARENA, "name-" + lines[1]);
}
}
}
@ -38,9 +39,9 @@ public class SignsHandler {
boolean saved = false;
int number = 1;
while (!saved) {
if (MemoryStorage.signs.getFile().get(key + "_" + number) == null) {
MemoryStorage.signs.getFile().set(key + "_" + number + ".arenaName", key);
MemoryStorage.signs.getFile().set(key + "_" + number + ".location", location);
if (MemoryStorage.signs.getFileConfiguration().get(key + "_" + number) == null) {
MemoryStorage.signs.getFileConfiguration().set(key + "_" + number + ".arenaName", key);
MemoryStorage.signs.getFileConfiguration().set(key + "_" + number + ".location", location);
MemoryStorage.signs.save();
saved = true;
@ -52,10 +53,10 @@ public class SignsHandler {
public static void removeSign(Location location) {
//TODO: This seems really inefficient
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
Location signLocation = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
for (String sign : MemoryStorage.signs.getFileConfiguration().getKeys(false)) {
Location signLocation = (Location) MemoryStorage.signs.getFileConfiguration().get(sign + ".location");
if (signLocation != null && signLocation.equals(location)) {
MemoryStorage.signs.getFile().set(sign, null);
MemoryStorage.signs.getFileConfiguration().set(sign, null);
MemoryStorage.signs.save();
}
}
@ -63,8 +64,8 @@ public class SignsHandler {
public static boolean isSign(Location location) {
//TODO: This seems really inefficient
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
Location loc = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
for (String sign : MemoryStorage.signs.getFileConfiguration().getKeys(false)) {
Location loc = (Location) MemoryStorage.signs.getFileConfiguration().get(sign + ".location");
if (loc == null) {
throw new IllegalArgumentException("Sign location could not be loaded.");
}
@ -80,8 +81,8 @@ public class SignsHandler {
//TODO: Instead of this awful method of signs updating every second for no reason, it would be preferable for
// sign changes to be directly triggered when its contents changes
MemoryStorage.signs.load(); //TODO: This loads from disk once every second which seems unnecessary
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
Location location = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
for (String sign : MemoryStorage.signs.getFileConfiguration().getKeys(false)) {
Location location = (Location) MemoryStorage.signs.getFileConfiguration().get(sign + ".location");
if (location == null) {
throw new IllegalArgumentException("Sign location could not be loaded.");
}
@ -94,11 +95,11 @@ public class SignsHandler {
continue;
}
if (location.getBlock().getState() instanceof Sign signBlock) {
String[] lines = signBlock.getLines();
String[] lines = signBlock.getSide(Side.FRONT).getLines();
if (sign.contains("leave")) {
drawSign(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_LEAVE.getPath()), signBlock);
drawSign(MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SIGN_LEAVE.getPath()), signBlock);
} else if (sign.contains("shop")) {
drawSign(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_SHOP.getPath()), signBlock);
drawSign(MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SIGN_SHOP.getPath()), signBlock);
} else {
drawArenaSign(lines[1], signBlock);
}
@ -116,11 +117,11 @@ public class SignsHandler {
continue;
}
if (arena.gameState.equals(ArenaState.WAITING)) {
drawSign(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_WAITING.getPath()), signBlock, arena);
drawSign(MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SIGN_WAITING.getPath()), signBlock, arena);
} else if (arena.gameState.equals(ArenaState.STARTING)) {
drawSign(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_STARTING.getPath()), signBlock, arena);
drawSign(MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SIGN_STARTING.getPath()), signBlock, arena);
} else if (arena.gameState.equals(ArenaState.IN_GAME)) {
drawSign(MemoryStorage.config.getFile().getStringList(ConfigKey.SIGN_IN_GAME.getPath()), signBlock, arena);
drawSign(MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SIGN_IN_GAME.getPath()), signBlock, arena);
}
}
}
@ -134,7 +135,7 @@ public class SignsHandler {
int lineCount = 0;
for (String line : signLines) {
if (lineCount <= 3) {
signBlock.setLine(lineCount, MessageManager.replaceAll(line, variables));
signBlock.getSide(Side.FRONT).setLine(lineCount, MessageHelper.replaceAll(line, variables));
}
lineCount = lineCount + 1;

View File

@ -4,7 +4,7 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -29,8 +29,8 @@ public class SolidBlockHandler {
Block pBlock = player.getLocation().getBlock();
if (MemoryStorage.hiddenLoc.get(player) != null) {
pBlock = MemoryStorage.hiddenLoc.get(player).getBlock();
if (MemoryStorage.hiddenLocation.get(player) != null) {
pBlock = MemoryStorage.hiddenLocation.get(player).getBlock();
}
block.setAmount(5);
@ -38,8 +38,8 @@ public class SolidBlockHandler {
if (pl.equals(player)) {
continue;
}
if (MemoryStorage.hiddenLocWater.get(player) != null) {
if (MemoryStorage.hiddenLocWater.get(player)) {
if (MemoryStorage.hiddenLocationWater.get(player) != null) {
if (MemoryStorage.hiddenLocationWater.get(player)) {
pl.sendBlockChange(pBlock.getLocation(), Bukkit.createBlockData(Material.WATER));
} else {
pl.sendBlockChange(pBlock.getLocation(), Bukkit.createBlockData(Material.AIR));
@ -48,7 +48,7 @@ public class SolidBlockHandler {
pl.sendBlockChange(pBlock.getLocation(), Bukkit.createBlockData(Material.AIR));
}
MemoryStorage.hiddenLocWater.remove(player);
MemoryStorage.hiddenLocationWater.remove(player);
}
player.playSound(player.getLocation(), Sound.ENTITY_BAT_HURT, 1, 1);
@ -61,7 +61,7 @@ public class SolidBlockHandler {
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
DisguiseAPI.disguiseToAll(player, disguise);
MessageManager.sendFMessage(player, MessageKey.NORMAL_IN_GAME_NO_MORE_SOLID);
MessageHelper.sendMessage(player, MessageKey.NORMAL_IN_GAME_NO_MORE_SOLID);
}
}

View File

@ -134,23 +134,24 @@ public class Arena implements ConfigurationSerializable {
*/
public ArenaState gameState;
public ArenaLocations arenaLocations;
public final ArenaLocations arenaLocations;
/**
* A timer that counts from the game duration towards 0
*/
public int timer;
public final List<Player> seekers;
public final List<Player> hiders;
public final Scoreboard scoreboard;
public Arena(String arenaName, Location corner1, Location corner2, int maxPlayers, int minPlayers, int amountSeekersOnStart,
int timeInLobbyUntilStart, int waitingTimeSeeker, int gameTime, int timeUntilHidersSword,
int blockAnnouncerTime, boolean seekersCanHurtSeekers, boolean hidersCanHurtSeekers,
boolean hidersCanHurtHiders, boolean seekersTakeFallDamage, boolean hidersTakeFallDamage,
List<ItemStack> disguiseBlocks, Location lobbyWarp, Location hidersWarp, Location seekersWarp,
Location spawnWarp, List<String> seekersWinCommands, List<String> hidersWinCommands,
List<String> allowedCommands, int seekersTokenWin, int hidersTokenWin, int killTokens,
List<Player> playersInArena, ArenaState gameState, int timer, List<Player> seekers,
public Arena(String arenaName, Location corner1, Location corner2, int maxPlayers, int minPlayers,
int amountSeekersOnStart, int timeInLobbyUntilStart, int waitingTimeSeeker, int gameTime,
int timeUntilHidersSword, int blockAnnouncerTime, boolean seekersCanHurtSeekers,
boolean hidersCanHurtSeekers, boolean hidersCanHurtHiders, boolean seekersTakeFallDamage,
boolean hidersTakeFallDamage, List<ItemStack> disguiseBlocks, Location lobbyWarp, Location hidersWarp,
Location seekersWarp, Location spawnWarp, List<String> seekersWinCommands,
List<String> hidersWinCommands, List<String> allowedCommands, int seekersTokenWin, int hidersTokenWin,
int killTokens, List<Player> playersInArena, ArenaState gameState, int timer, List<Player> seekers,
Scoreboard scoreboard) {
this.arenaName = arenaName;
this.maxPlayers = maxPlayers;
@ -177,6 +178,8 @@ public class Arena implements ConfigurationSerializable {
this.gameState = gameState;
this.timer = timer;
this.seekers = seekers;
this.hiders = new ArrayList<>(playersInArena);
this.hiders.removeAll(seekers);
this.scoreboard = scoreboard;
this.arenaLocations = new ArenaLocations(corner1, corner2, lobbyWarp, hidersWarp, seekersWarp, spawnWarp);
}
@ -204,7 +207,7 @@ public class Arena implements ConfigurationSerializable {
map.put("lobbyWarp", arenaLocations.getLobbyWarp());
map.put("hidersWarp", arenaLocations.getHidersWarp());
map.put("seekersWarp", arenaLocations.getSeekersWarp());
map.put("spawnWarp", arenaLocations.getSpawnWarp());
map.put("spawnWarp", arenaLocations.getExitWarp());
map.put("seekersWinCommands", seekersWinCommands);
map.put("hidersWinCommands", hidersWinCommands);
map.put("allowedCommands", allowedCommands);

View File

@ -8,14 +8,13 @@ import net.knarcraft.blockhunt.PlayerHandler;
import net.knarcraft.blockhunt.ScoreboardHandler;
import net.knarcraft.blockhunt.SignsHandler;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.Key;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.config.Permission;
import net.knarcraft.blockhunt.event.EndArenaEvent;
import net.knarcraft.blockhunt.event.JoinArenaEvent;
import net.knarcraft.blockhunt.event.LeaveArenaEvent;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -36,8 +35,8 @@ public class ArenaHandler {
public static void loadArenas() {
MemoryStorage.arenaMap.clear();
for (String arenaName : MemoryStorage.arenas.getFile().getKeys(false)) {
MemoryStorage.arenaMap.put(arenaName.toLowerCase(), (Arena) MemoryStorage.arenas.getFile().get(arenaName));
for (String arenaName : MemoryStorage.arenas.getFileConfiguration().getKeys(false)) {
MemoryStorage.arenaMap.put(arenaName.toLowerCase(), (Arena) MemoryStorage.arenas.getFileConfiguration().get(arenaName));
}
for (Arena arena : MemoryStorage.arenaMap.values()) {
@ -45,26 +44,29 @@ public class ArenaHandler {
}
}
/**
* Sends a message to all players in an arena
*
* @param arena <p>The arena to announce to</p>
* @param message <p>The message to display</p>
* @param variables <p>The variables to replace in the message</p>
*/
public static void sendMessage(Arena arena, String message, String... variables) {
for (Player player : arena.playersInArena) {
String playerMessage = message.replaceAll("%player%", player.getDisplayName());
player.sendMessage(MessageManager.replaceAll(playerMessage, variables));
}
MessageHelper.broadcastMessage(arena.playersInArena, message, variables);
}
public static void sendFMessage(Arena arena, Key location, String... variables) {
for (Player player : arena.playersInArena) {
Location realLocation = location.getConfigManager().getFile().getLocation(location.getPath());
if (realLocation == null) {
continue;
}
String playerMessage = realLocation.toString().replaceAll("%player%", player.getDisplayName());
player.sendMessage(MessageManager.replaceAll(playerMessage, variables));
}
/**
* Sends a message to all players in an arena
*
* @param arena <p>The arena to announce to</p>
* @param messageKey <p>The message key defining the string to display</p>
* @param variables <p>The variables to replace in the message</p>
*/
public static void sendMessage(Arena arena, MessageKey messageKey, String... variables) {
MessageHelper.broadcastMessage(arena.playersInArena, messageKey, variables);
}
public static void playerJoinArena(Player player, String arenaName) {
boolean found;
boolean alreadyJoined = false;
for (Arena arena : MemoryStorage.arenaMap.values()) {
if (arena.playersInArena != null && arena.playersInArena.contains(player)) {
@ -74,53 +76,49 @@ public class ArenaHandler {
}
if (alreadyJoined) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_ALREADY_JOINED);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_ALREADY_JOINED);
return;
}
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
if (arena != null) {
if (arena.disguiseBlocks.isEmpty()) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_NO_BLOCKS_SET);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_NO_BLOCKS_SET);
} else {
boolean inventoryEmpty = true;
for (ItemStack inventoryItem : player.getInventory()) {
if (inventoryItem != null) {
if (inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
if (inventoryItem != null && inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
}
for (ItemStack inventoryItem : player.getInventory().getArmorContents()) {
if (inventoryItem != null) {
if (inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
if (inventoryItem != null && inventoryItem.getType() != Material.AIR) {
inventoryEmpty = false;
}
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.REQUIRE_INVENTORY_CLEAR_ON_JOIN) && !inventoryEmpty) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_INVENTORY_NOT_EMPTY);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_INVENTORY_NOT_EMPTY);
return;
}
Location zero = new Location(Bukkit.getWorld(player.getWorld().getName()), 0, 0, 0, 0, 0);
ArenaLocations locations = arena.arenaLocations;
if (locations.getLobbyWarp() != null && locations.getHidersWarp() != null &&
locations.getSeekersWarp() != null && locations.getSpawnWarp() != null) {
locations.getSeekersWarp() != null && locations.getExitWarp() != null) {
if (!locations.getLobbyWarp().equals(zero) && !locations.getHidersWarp().equals(zero) &&
!locations.getSeekersWarp().equals(zero) && !locations.getSpawnWarp().equals(zero)) {
!locations.getSeekersWarp().equals(zero) && !locations.getExitWarp().equals(zero)) {
if (arena.gameState == ArenaState.WAITING || arena.gameState == ArenaState.STARTING) {
if (arena.playersInArena.size() >= arena.maxPlayers &&
!PermissionsManager.hasPermission(player, Permission.JOIN_FULL, false)) {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_FULL);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_FULL);
return;
}
boolean canWarp = PlayerHandler.teleport(player, locations.getLobbyWarp());
if (!canWarp) {
MessageManager.sendFMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
MessageHelper.sendMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
return;
}
@ -133,7 +131,7 @@ public class ArenaHandler {
.getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), player.getHealth(), player.getFoodLevel(),
player.getActivePotionEffects(), player.getAllowFlight());
MemoryStorage.pData.put(player, pad);
MemoryStorage.playerData.put(player, pad);
player.setGameMode(GameMode.SURVIVAL);
for (PotionEffect pe : player.getActivePotionEffects()) {
@ -176,15 +174,15 @@ public class ArenaHandler {
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)) {
if (MemoryStorage.shop.getFile().get(player.getName() + ".blockchooser") != null
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".blockchooser") != null
|| 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)));
List<String> loreStrings = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
shopBlockChooser_IM.setDisplayName(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
List<String> loreStrings = MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
List<String> loreStrings2 = new ArrayList<>();
for (String lore : loreStrings) {
loreStrings2.add(MessageManager.replaceAll(lore));
loreStrings2.add(MessageHelper.replaceAll(lore));
}
shopBlockChooser_IM.setLore(loreStrings2);
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
@ -194,45 +192,44 @@ public class ArenaHandler {
}
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED)) {
if (MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") != 0) {
if (MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass") != 0) {
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ID_NAME)),
1);
ItemMeta shopBlockHuntPass_IM = shopBlockHuntPass.getItemMeta();
shopBlockHuntPass_IM.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
List<String> loreStrings = MemoryStorage.config.getFile().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
shopBlockHuntPass_IM.setDisplayName(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
List<String> loreStrings = MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_DESCRIPTION.getPath());
List<String> loreStrings2 = new ArrayList<>();
for (String lore : loreStrings) {
loreStrings2.add(MessageManager.replaceAll(lore));
loreStrings2.add(MessageHelper.replaceAll(lore));
}
shopBlockHuntPass_IM.setLore(loreStrings2);
shopBlockHuntPass.setItemMeta(shopBlockHuntPass_IM);
shopBlockHuntPass.setAmount(MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass"));
shopBlockHuntPass.setAmount(MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass"));
player.getInventory().addItem(shopBlockHuntPass);
}
}
player.updateInventory();
DisguiseAPI.undisguiseToAll(player);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_JOIN_JOINED_ARENA, "%playerName%-" + player.getName(),
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_JOIN_JOINED_ARENA, "%playerName%-" + player.getName(),
"1-" + arena.playersInArena.size(), "2-" + arena.maxPlayers);
if (arena.playersInArena.size() < arena.minPlayers) {
sendFMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
sendMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_ARENA_IN_GAME);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_ARENA_IN_GAME);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
}
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
}
SignsHandler.updateSigns();
@ -257,12 +254,13 @@ public class ArenaHandler {
if (cleanup) {
arena.playersInArena.remove(player);
arena.seekers.remove(player);
arena.hiders.remove(player);
if (arena.playersInArena.size() < arena.minPlayers && arena.gameState.equals(ArenaState.STARTING)) {
arena.gameState = ArenaState.WAITING;
arena.timer = 0;
sendFMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
sendMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
}
if (arena.playersInArena.size() <= 1 && arena.gameState == ArenaState.IN_GAME) {
@ -277,10 +275,10 @@ public class ArenaHandler {
ArenaHandler.seekersWin(arena);
}
if (arena.seekers.size() <= 0 && arena.gameState == ArenaState.IN_GAME) {
if (arena.seekers.size() == 0 && arena.gameState == ArenaState.IN_GAME) {
Player seeker = arena.playersInArena.get(MemoryStorage.random.nextInt(arena.playersInArena.size()));
ArenaHandler.sendFMessage(arena, MessageKey.WARNING_IN_GAME_NEW_SEEKER_CHOSEN, "seeker-" + seeker.getName());
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + seeker.getName());
ArenaHandler.sendMessage(arena, MessageKey.WARNING_IN_GAME_NEW_SEEKER_CHOSEN, "seeker-" + seeker.getName());
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + seeker.getName());
DisguiseAPI.undisguiseToAll(seeker);
for (Player pl : Bukkit.getOnlinePlayers()) {
pl.showPlayer(BlockHunt.plugin, seeker);
@ -308,21 +306,20 @@ public class ArenaHandler {
PlayerArenaData pad = new PlayerArenaData(null, null, null, null, null, null, null, null, null, null, false);
if (MemoryStorage.pData.get(player) != null) {
pad = MemoryStorage.pData.get(player);
if (MemoryStorage.playerData.get(player) != null) {
pad = MemoryStorage.playerData.get(player);
}
player.getInventory().clear();
player.getInventory().setContents(pad.playerInventory());
player.getInventory().setArmorContents(pad.playerArmor());
player.updateInventory();
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.arenaLocations.getSpawnWarp());
PlayerHandler.teleport(player, arena.arenaLocations.getExitWarp());
player.setGameMode(pad.playerGameMode());
player.setAllowFlight(pad.playerFlying());
if (player.getAllowFlight()) {
@ -330,15 +327,15 @@ public class ArenaHandler {
}
player.setWalkSpeed(0.2F);
MemoryStorage.pData.remove(player);
MemoryStorage.playerData.remove(player);
MemoryStorage.chosenBlock.remove(player);
for (Player pl : Bukkit.getOnlinePlayers()) {
pl.showPlayer(BlockHunt.plugin, player);
if (MemoryStorage.hiddenLoc.get(player) != null) {
if (MemoryStorage.hiddenLocWater.get(player) != null) {
Block pBlock = MemoryStorage.hiddenLoc.get(player).getBlock();
if (MemoryStorage.hiddenLocWater.get(player)) {
if (MemoryStorage.hiddenLocation.get(player) != null) {
if (MemoryStorage.hiddenLocationWater.get(player) != null) {
Block pBlock = MemoryStorage.hiddenLocation.get(player).getBlock();
if (MemoryStorage.hiddenLocationWater.get(player)) {
pl.sendBlockChange(pBlock.getLocation(), Bukkit.createBlockData(Material.WATER));
} else {
pl.sendBlockChange(pBlock.getLocation(), Bukkit.createBlockData(Material.AIR));
@ -351,14 +348,14 @@ public class ArenaHandler {
ScoreboardHandler.removeScoreboard(player);
MessageManager.sendFMessage(player, MessageKey.NORMAL_LEAVE_YOU_LEFT);
MessageHelper.sendMessage(player, MessageKey.NORMAL_LEAVE_YOU_LEFT);
if (message) {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_LEAVE_LEFT_ARENA, "%playerName%-" + player.getName(), "1-" + arena.playersInArena.size(), "2-"
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LEAVE_LEFT_ARENA, "%playerName%-" + player.getName(), "1-" + arena.playersInArena.size(), "2-"
+ arena.maxPlayers);
}
} else {
if (message) {
MessageManager.sendFMessage(player, MessageKey.ERROR_LEAVE_NOT_IN_ARENA);
MessageHelper.sendMessage(player, MessageKey.ERROR_LEAVE_NOT_IN_ARENA);
}
return;
}
@ -383,15 +380,15 @@ public class ArenaHandler {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getDisplayName()));
}
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens + arena.seekersTokenWin);
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens + arena.seekersTokenWin);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.seekersTokenWin);
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.seekersTokenWin);
}
@ -424,15 +421,15 @@ public class ArenaHandler {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getDisplayName()));
}
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens + arena.hidersTokenWin);
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens + arena.hidersTokenWin);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.hidersTokenWin);
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.hidersTokenWin);
}
}
@ -443,10 +440,11 @@ public class ArenaHandler {
stopArena(arena, cause, MessageKey.NORMAL_WIN_HIDERS);
}
public static void stopArena(Arena arena, String cause, Key message) {
public static void stopArena(Arena arena, String cause, MessageKey message) {
BlockHunt.plugin.getLogger().log(Level.INFO, cause);
ArenaHandler.sendFMessage(arena, message);
ArenaHandler.sendMessage(arena, message);
arena.seekers.clear();
arena.hiders.clear();
for (Player player : arena.playersInArena) {
playerLeaveArena(player, false, false);

View File

@ -14,7 +14,7 @@ public class ArenaLocations {
private Location lobbyWarp;
private Location hidersWarp;
private Location seekersWarp;
private Location spawnWarp;
private Location exitWarp;
/**
* Instantiates a new arena locations container
@ -24,16 +24,16 @@ public class ArenaLocations {
* @param lobbyWarp <p>The location of the lobby's warp</p>
* @param hidersWarp <p>The location of the hiders' warp</p>
* @param seekersWarp <p>The location of the temporary seekers warp (should not be able to see hiders from this location)</p>
* @param spawnWarp <p>The location of the spawn warp where players are sent once this arena's game ends</p>
* @param exitWarp <p>The location of the exit warp where players are sent once this arena's game ends</p>
*/
public ArenaLocations(@NotNull Location corner1, @NotNull Location corner2, @Nullable Location lobbyWarp,
@Nullable Location hidersWarp, @Nullable Location seekersWarp, @Nullable Location spawnWarp) {
@Nullable Location hidersWarp, @Nullable Location seekersWarp, @Nullable Location exitWarp) {
this.corner1 = corner1;
this.corner2 = corner2;
this.lobbyWarp = lobbyWarp;
this.hidersWarp = hidersWarp;
this.seekersWarp = seekersWarp;
this.spawnWarp = spawnWarp;
this.exitWarp = exitWarp;
}
/**
@ -111,23 +111,23 @@ public class ArenaLocations {
}
/**
* Gets the location of the "spawn" warp
* Gets the location of the exit warp
*
* <p>This location is where players are teleported to when leaving the arena</p>
*
* @return <p>The location of the "spawn" warp</p>
* @return <p>The location of the exit warp</p>
*/
public @Nullable Location getSpawnWarp() {
return spawnWarp;
public @Nullable Location getExitWarp() {
return exitWarp;
}
/**
* Sets the location of the "spawn" warp
* Sets the location of the exit warp
*
* @param spawnWarp <p>The location of the "spawn" warp</p>
* @param exitWarp <p>The location of the exit warp</p>
*/
public void setSpawnWarp(@NotNull Location spawnWarp) {
this.spawnWarp = spawnWarp;
public void setExitWarp(@NotNull Location exitWarp) {
this.exitWarp = exitWarp;
}
}

View File

@ -3,8 +3,8 @@ 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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -55,7 +55,7 @@ public class BlockHuntCommand implements CommandExecutor {
if (commandRecord.enabled()) {
return commandRecord.command().execute(player, arguments);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_COMMAND_NOT_ENABLED);
MessageHelper.sendMessage(player, MessageKey.ERROR_COMMAND_NOT_ENABLED);
}
}

View File

@ -18,6 +18,7 @@ public class BlockHuntTabCompleter implements TabCompleter {
return command.mainTabList();
}
}
//TODO: Make proper tab-completions
return null;
}

View File

@ -6,7 +6,7 @@ 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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -17,12 +17,12 @@ public class CreateCommand extends DefaultCommand {
@Override
public boolean execute(Player player, String[] args) {
if (player == null) {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
return true;
}
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getCreateCommand().usage());
} else {
if (MemoryStorage.pos1.get(player) != null && MemoryStorage.pos2.get(player) != null) {
@ -35,19 +35,19 @@ public class CreateCommand extends DefaultCommand {
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.getFileConfiguration().set(args[1], arena);
MemoryStorage.arenas.save();
MemoryStorage.signs.load();
MemoryStorage.arenaMap.put(args[1].toLowerCase(), arena);
ScoreboardHandler.createScoreboard(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_CREATE_CREATED_ARENA, "name-" + args[1]);
MessageHelper.sendMessage(player, MessageKey.NORMAL_CREATE_CREATED_ARENA, "name-" + args[1]);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_CREATE_NOT_SAME_WORLD);
MessageHelper.sendMessage(player, MessageKey.ERROR_CREATE_NOT_SAME_WORLD);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_CREATE_SELECTION_FIRST);
MessageHelper.sendMessage(player, MessageKey.ERROR_CREATE_SELECTION_FIRST);
}
}
return true;

View File

@ -4,8 +4,8 @@ import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.manager.Command;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class HelpCommand extends DefaultCommand {
@ -26,15 +26,15 @@ public class HelpCommand extends DefaultCommand {
int page = 1;
if (args.length == 1) {
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName() + " %Nhelp page %A" + page + "%N/%A" + maxPages);
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName() + " %Nhelp page %A" + page + "%N/%A" + maxPages);
int i = 1;
for (Command command : MemoryStorage.commands) {
if (i <= 4) {
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()));
MessageHelper.sendMessage(player, "%A" + command.usage() + "%N - " + MemoryStorage.messages.getFileConfiguration().get(command.help().getPath()));
} else {
MessageManager.sendMessage(player, "%MemoryStorage" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
MessageHelper.sendMessage(player, "%MemoryStorage" + command.usage() + "%N - " + MemoryStorage.messages.getFileConfiguration().get(command.help().getPath()));
}
i = i + 1;
}
@ -51,7 +51,7 @@ public class HelpCommand extends DefaultCommand {
maxPages = page;
}
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName() + " %Nhelp page %A" + page + "%N/%A" + maxPages);
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName() + " %Nhelp page %A" + page + "%N/%A" + maxPages);
int i = 1;
for (Command command : MemoryStorage.commands) {
@ -59,9 +59,9 @@ public class HelpCommand extends DefaultCommand {
if (command.usage() != null) {
if (i >= ((page - 1) * 4) + 1 && i <= ((page - 1) * 4) + 4) {
if (PermissionsManager.hasPermission(player, command.permission(), false)) {
MessageManager.sendMessage(player, "%A" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
MessageHelper.sendMessage(player, "%A" + command.usage() + "%N - " + MemoryStorage.messages.getFileConfiguration().get(command.help().getPath()));
} else {
MessageManager.sendMessage(player, "%MemoryStorage" + command.usage() + "%N - " + MemoryStorage.messages.getFile().get(command.help().getPath()));
MessageHelper.sendMessage(player, "%MemoryStorage" + command.usage() + "%N - " + MemoryStorage.messages.getFileConfiguration().get(command.help().getPath()));
}
}
i = i + 1;
@ -69,7 +69,7 @@ public class HelpCommand extends DefaultCommand {
}
}
}
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-&oHelp Page");
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-&oHelp Page");
return true;
}
}

View File

@ -3,23 +3,23 @@ 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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class InfoCommand extends DefaultCommand {
@Override
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-" +
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName());
MessageHelper.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-" +
MessageHelper.sendMessage(player, "%NVersion: %A%version%%N.", "version-" + BlockHunt.getPluginDescriptionFile().getVersion());
MessageHelper.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!");
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-&oInfo Page");
MessageHelper.sendMessage(player, "%NDev-Page: %Ahttp://dev.bukkit.org/bukkit-plugins/blockhunt/");
MessageHelper.sendMessage(player, "%NDonations are welcome!");
MessageHelper.sendMessage(player, "%NMade by help from some friends &c<3%N!");
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-&oInfo Page");
return true;
}
}

View File

@ -3,7 +3,7 @@ package net.knarcraft.blockhunt.command;
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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class JoinCommand extends DefaultCommand {
@ -12,13 +12,13 @@ public class JoinCommand extends DefaultCommand {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getJoinCommand().usage());
} else {
ArenaHandler.playerJoinArena(player, args[1]);
}
} else {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}

View File

@ -2,7 +2,7 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class LeaveCommand extends DefaultCommand {
@ -12,7 +12,7 @@ public class LeaveCommand extends DefaultCommand {
if (player != null) {
ArenaHandler.playerLeaveArena(player, true, true);
} else {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}

View File

@ -4,24 +4,24 @@ import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class ListCommand extends DefaultCommand {
@Override
public boolean execute(Player player, String[] args) {
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName());
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-" + BlockHunt.getPluginDescriptionFile().getName());
if (MemoryStorage.arenaMap.size() >= 1) {
MessageManager.sendMessage(player, "&7Available arena(s):");
MessageHelper.sendMessage(player, "&7Available arena(s):");
for (Arena arena : MemoryStorage.arenaMap.values()) {
MessageManager.sendMessage(player, "%A" + arena.arenaName);
MessageHelper.sendMessage(player, "%A" + arena.arenaName);
}
} else {
MessageManager.sendMessage(player, "&7&oNo arenas available...");
MessageManager.sendMessage(player, "&7&oCreate an arena first please.");
MessageHelper.sendMessage(player, "&7&oNo arenas available...");
MessageHelper.sendMessage(player, "&7&oCreate an arena first please.");
}
MessageManager.sendFMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-&oArenas list");
MessageHelper.sendMessage(player, ConfigKey.CHAT_HEADER_HIGH, "header-&oArenas list");
return true;
}
}

View File

@ -1,14 +1,14 @@
package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class NotFoundCommand extends DefaultCommand {
@Override
public boolean execute(Player player, String[] args) {
MessageManager.sendFMessage(player, MessageKey.ERROR_COMMAND_NOT_FOUND);
MessageHelper.sendMessage(player, MessageKey.ERROR_COMMAND_NOT_FOUND);
return true;
}
}

View File

@ -5,7 +5,7 @@ import net.knarcraft.blockhunt.arena.Arena;
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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class ReloadCommand extends DefaultCommand {
@ -26,7 +26,7 @@ public class ReloadCommand extends DefaultCommand {
}
ArenaHandler.loadArenas();
MessageManager.sendFMessage(player, MessageKey.NORMAL_RELOADED_CONFIGS);
MessageHelper.sendMessage(player, MessageKey.NORMAL_RELOADED_CONFIGS);
return true;
}
}

View File

@ -4,7 +4,7 @@ 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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
@ -17,20 +17,20 @@ public class RemoveCommand extends DefaultCommand {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getRemoveCommand().usage());
} else {
Arena arena = MemoryStorage.arenaMap.get(args[1].toLowerCase());
if (arena != null) {
MessageManager.sendFMessage(player, MessageKey.NORMAL_REMOVE_REMOVED_ARENA, "name-" + args[1]);
MemoryStorage.arenas.getFile().set(args[1], null);
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
if (MemoryStorage.signs.getFile().get(sign + ".arenaName").toString().equalsIgnoreCase(args[1])) {
Location signLoc = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
MessageHelper.sendMessage(player, MessageKey.NORMAL_REMOVE_REMOVED_ARENA, "name-" + args[1]);
MemoryStorage.arenas.getFileConfiguration().set(args[1], null);
for (String sign : MemoryStorage.signs.getFileConfiguration().getKeys(false)) {
if (MemoryStorage.signs.getFileConfiguration().get(sign + ".arenaName").toString().equalsIgnoreCase(args[1])) {
Location signLoc = (Location) MemoryStorage.signs.getFileConfiguration().get(sign + ".location");
signLoc.getBlock().setType(Material.AIR);
signLoc.getWorld().playEffect(signLoc, Effect.MOBSPAWNER_FLAMES, 0);
signLoc.getWorld().playSound(signLoc, Sound.ENTITY_ENDER_DRAGON_FLAP, 1, 1);
MemoryStorage.signs.getFile().set(sign, null);
MemoryStorage.signs.getFileConfiguration().set(sign, null);
}
}
@ -41,10 +41,10 @@ public class RemoveCommand extends DefaultCommand {
return true;
}
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + args[1]);
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + args[1]);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(player, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}

View File

@ -3,7 +3,7 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.InventoryHandler;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class SetCommand extends DefaultCommand {
@ -12,14 +12,14 @@ public class SetCommand extends DefaultCommand {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getSetCommand().usage());
} else {
String arenaName = args[1];
InventoryHandler.openPanel(player, arenaName);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(player, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}

View File

@ -6,7 +6,7 @@ import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.arena.ArenaLocations;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -16,7 +16,7 @@ public class SetWarpCommand extends DefaultCommand {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 2) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.setWarpCommand().usage());
} else {
String arenaName = args[2];
@ -29,34 +29,34 @@ public class SetWarpCommand extends DefaultCommand {
if (warpName.equalsIgnoreCase("lobby")) {
locations.setLobbyWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
MessageHelper.sendMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else if (warpName.equalsIgnoreCase("hiders")) {
locations.setHidersWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
MessageHelper.sendMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else if (warpName.equalsIgnoreCase("seekers")) {
locations.setSeekersWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
MessageHelper.sendMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else if (warpName.equalsIgnoreCase("spawn")) {
locations.setSpawnWarp(playerLocation);
locations.setExitWarp(playerLocation);
save(arena);
MessageManager.sendFMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
MessageHelper.sendMessage(player, MessageKey.NORMAL_SET_WARP_WARP_SET, "warp-" + warpName);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_WARP_WARP_NOT_FOUND, "warp-" + warpName);
MessageHelper.sendMessage(player, MessageKey.ERROR_SET_WARP_WARP_NOT_FOUND, "warp-" + warpName);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
}
}
} else {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}
public void save(Arena arena) {
MemoryStorage.arenas.getFile().set(arena.arenaName, arena);
MemoryStorage.arenas.getFileConfiguration().set(arena.arenaName, arena);
MemoryStorage.arenas.save();
ArenaHandler.loadArenas();
}

View File

@ -5,7 +5,7 @@ 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 net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class StartCommand extends DefaultCommand {
@ -14,7 +14,7 @@ public class StartCommand extends DefaultCommand {
public boolean execute(Player player, String[] args) {
if (player != null) {
if (args.length <= 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getStartCommand().usage());
} else {
Arena arena = MemoryStorage.arenaMap.get(args[1].toLowerCase());
@ -24,9 +24,9 @@ public class StartCommand extends DefaultCommand {
if (arena.playersInArena.size() >= 2) {
arena.timer = 11;
arena.gameState = ArenaState.STARTING;
MessageManager.sendFMessage(player, MessageKey.NORMAL_START_FORCED, "arenaName-" + arena.arenaName);
MessageHelper.sendMessage(player, MessageKey.NORMAL_START_FORCED, "arenaName-" + arena.arenaName);
} else {
MessageManager.sendFMessage(player, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-2");
MessageHelper.sendMessage(player, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-2");
}
} else if (arena.gameState.equals(ArenaState.STARTING)) {
if (arena.playersInArena.size() < arena.maxPlayers) {
@ -37,14 +37,14 @@ public class StartCommand extends DefaultCommand {
arena.timer = 1;
}
MessageManager.sendFMessage(player, MessageKey.NORMAL_START_FORCED, "arenaName-" + arena.arenaName);
MessageHelper.sendMessage(player, MessageKey.NORMAL_START_FORCED, "arenaName-" + arena.arenaName);
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + args[1]);
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + args[1]);
}
}
} else {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}

View File

@ -3,7 +3,7 @@ package net.knarcraft.blockhunt.command;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.CommandManager;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -13,7 +13,7 @@ public class TokensCommand extends DefaultCommand {
@Override
public boolean execute(Player player, String[] args) {
if (args.length <= 3) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
CommandManager.getTokensCommand().usage());
} else {
String option = args[1];
@ -22,13 +22,13 @@ public class TokensCommand extends DefaultCommand {
try {
amount = Integer.parseInt(args[3]);
} catch (NumberFormatException e) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NOT_A_NUMBER, "1-" + args[3]);
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_A_NUMBER, "1-" + args[3]);
return true;
}
Player tokenPlayer = Bukkit.getPlayer(playerName);
if (tokenPlayer == null) {
MessageManager.sendFMessage(player, MessageKey.ERROR_TOKENS_PLAYER_NOT_ONLINE, "%playerName%-" + playerName);
MessageHelper.sendMessage(player, MessageKey.ERROR_TOKENS_PLAYER_NOT_ONLINE, "%playerName%-" + playerName);
return true;
}
String name = "\u00A78Console";
@ -37,30 +37,30 @@ public class TokensCommand extends DefaultCommand {
}
if (option.equalsIgnoreCase("set")) {
MemoryStorage.shop.getFile().set(tokenPlayer.getName() + ".tokens", amount);
MemoryStorage.shop.getFileConfiguration().set(tokenPlayer.getName() + ".tokens", amount);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-Set", "%playerName%-" + tokenPlayer.getName(), "option2-to", "amount-" + amount);
MessageManager.sendFMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-set", "%playerName%-" + name, "option2-to", "amount-" + amount);
MessageHelper.sendMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-Set", "%playerName%-" + tokenPlayer.getName(), "option2-to", "amount-" + amount);
MessageHelper.sendMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-set", "%playerName%-" + name, "option2-to", "amount-" + amount);
} else if (option.equalsIgnoreCase("add")) {
int tokens = 0;
if (MemoryStorage.shop.getFile().getInt(tokenPlayer.getName() + ".tokens") != 0) {
tokens = MemoryStorage.shop.getFile().getInt(tokenPlayer.getName() + ".tokens");
if (MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens") != 0) {
tokens = MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens");
}
MemoryStorage.shop.getFile().set(tokenPlayer.getName() + ".tokens", tokens + amount);
MemoryStorage.shop.getFileConfiguration().set(tokenPlayer.getName() + ".tokens", tokens + amount);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-Added", "%playerName%-" + tokenPlayer.getName(), "option2-to", "amount-" + amount);
MessageManager.sendFMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-added", "%playerName%-" + name, "option2-to", "amount-" + amount);
MessageHelper.sendMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-Added", "%playerName%-" + tokenPlayer.getName(), "option2-to", "amount-" + amount);
MessageHelper.sendMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-added", "%playerName%-" + name, "option2-to", "amount-" + amount);
} else if (option.equalsIgnoreCase("take")) {
int tokens = 0;
if (MemoryStorage.shop.getFile().getInt(tokenPlayer.getName() + ".tokens") != 0) {
tokens = MemoryStorage.shop.getFile().getInt(tokenPlayer.getName() + ".tokens");
if (MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens") != 0) {
tokens = MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens");
}
MemoryStorage.shop.getFile().set(tokenPlayer.getName() + ".tokens", tokens - amount);
MemoryStorage.shop.getFileConfiguration().set(tokenPlayer.getName() + ".tokens", tokens - amount);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-Took", "%playerName%-" + tokenPlayer.getName(), "option2-from", "amount-" + amount);
MessageManager.sendFMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-took", "%playerName%-" + name, "option2-from", "amount-" + amount);
MessageHelper.sendMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-Took", "%playerName%-" + tokenPlayer.getName(), "option2-from", "amount-" + amount);
MessageHelper.sendMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-took", "%playerName%-" + name, "option2-from", "amount-" + amount);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_TOKENS_UNKNOWN_SETTING, "option-" + option);
MessageHelper.sendMessage(player, MessageKey.ERROR_TOKENS_UNKNOWN_SETTING, "option-" + option);
}
}
return true;

View File

@ -1,9 +1,10 @@
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.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -12,29 +13,39 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
public class WandCommand extends DefaultCommand {
@Override
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();
im.setDisplayName(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.WAND_NAME)));
Material material = Material.getMaterial((String) MemoryStorage.config.get(ConfigKey.WAND_ID_NAME));
if (material == null) {
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Invalid wand material specified in the config file!");
return true;
}
ItemStack wand = new ItemStack(material);
ItemMeta itemMeta = wand.getItemMeta();
Objects.requireNonNull(itemMeta).setDisplayName(MessageHelper.replaceAll(
(String) MemoryStorage.config.get(ConfigKey.WAND_NAME)));
MemoryStorage.config.load();
List<String> loreLines = MemoryStorage.config.getFile().getStringList(ConfigKey.WAND_DESCRIPTION.getPath());
List<String> loreLines = MemoryStorage.config.getFileConfiguration().getStringList(
ConfigKey.WAND_DESCRIPTION.getPath());
List<String> loreLines2 = new ArrayList<>();
for (String lore : loreLines) {
loreLines2.add(MessageManager.replaceAll(lore));
loreLines2.add(MessageHelper.replaceAll(lore));
}
im.setLore(loreLines2);
wand.setItemMeta(im);
itemMeta.setLore(loreLines2);
wand.setItemMeta(itemMeta);
player.getInventory().addItem(wand);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 0);
MessageManager.sendFMessage(player, MessageKey.NORMAL_WAND_GAVE_WAND, "type-" + wand.getType().toString().replaceAll("_", " ").toLowerCase());
MessageHelper.sendMessage(player, MessageKey.NORMAL_WAND_GAVE_WAND, "type-" +
wand.getType().toString().replaceAll("_", " ").toLowerCase());
} else {
MessageManager.sendFMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
}
return true;
}

View File

@ -0,0 +1,82 @@
package net.knarcraft.blockhunt.config;
import net.knarcraft.blockhunt.MemoryStorage;
/**
* An identifier for a specific type of chat message
*/
public enum ChatMessageTypeIdentifier {
/**
* A normal chat message
*/
NORMAL("%N", ConfigKey.CHAT_NORMAL),
/**
* A warning message
*/
WARNING("%W", ConfigKey.CHAT_WARNING),
/**
* An error message
*/
ERROR("%E", ConfigKey.CHAT_ERROR),
/**
* An argument which should be highlighted
*/
ARGUMENT("%A", ConfigKey.CHAT_ARGUMENT),
/**
* A BlockHunt header
*/
HEADER("%H", ConfigKey.CHAT_HEADER),
/**
* A tag specifying which plugin this message came from
*/
TAG("%TAG", ConfigKey.CHAT_HEADER, ConfigKey.CHAT_TAG, ConfigKey.CHAT_NORMAL),
;
private final String placeholder;
private final ConfigKey[] configKeys;
/**
* Instantiates a new chat message type identifier
*
* @param placeholder <p>The placeholder used to specify this message type</p>
* @param configKeys <p>The configuration keys used to select this chat message type</p>
*/
ChatMessageTypeIdentifier(String placeholder, ConfigKey... configKeys) {
this.placeholder = placeholder;
this.configKeys = configKeys;
}
/**
* Replaces every instance of this chat message type identifier
*
* @param input <p>The input string to replace for</p>
* @return <p>The input with this chat message type identifier replaced</p>
*/
public String replace(String input) {
StringBuilder replacement = new StringBuilder();
for (ConfigKey key : configKeys) {
replacement.append((String) MemoryStorage.config.get(key));
}
return input.replaceAll(this.placeholder, replacement.toString());
}
/**
* Replaces every instance for every chat message type identifier
*
* @param input <p>The input string to replace for</p>
* @return <p>The input with all chat message type identifiers replaced</p>
*/
public static String replaceAll(String input) {
for (ChatMessageTypeIdentifier identifier : ChatMessageTypeIdentifier.values()) {
input = identifier.replace(input);
}
return input;
}
}

View File

@ -49,8 +49,10 @@ public enum MessageKey implements Key {
"normal.createCreatedArena"),
NORMAL_LOBBY_ARENA_IS_STARTING("%TAG%NThe arena will start in %A%1%%N second(s)!",
"normal.lobbyArenaIsStarting"),
NORMAL_LOBBY_ARENA_STARTED("%TAG%NThe arena has been started! The seeker is coming to find you in " +
"%A%secs%%N seconds!", "normal.lobbyArenaStarted"),
NORMAL_LOBBY_ARENA_STARTED_HIDERS("%TAG%NThe arena has been started! The seeker is coming to find you" +
" in %A%seconds%%N seconds!", "normal.lobbyArenaStartedHiders"),
NORMAL_LOBBY_ARENA_STARTED_SEEKERS("%TAG%NThe arena has been started! You can start seeking in " +
"%A%seconds%%N seconds!", "normal.lobbyArenaStartedSeekers"),
NORMAL_IN_GAME_SEEKER_CHOSEN("%TAG%NPlayer %A%seeker%%N has been chosen as seeker!",
"normal.inGameSeekerChosen"),
NORMAL_IN_GAME_BLOCK("%TAG%NYou're disguised as a(n) '%A%block%%N' block.", "normal.inGameBlock"),
@ -61,7 +63,7 @@ public enum MessageKey implements Key {
NORMAL_IN_GAME_HIDER_DIED("%TAG%NHider %A%%playerName%%%N was killed by %A%killer%%N!",
"normal.inGameHiderDied"),
NORMAL_IN_GAME_HIDERS_LEFT("%NHider(s) left: %A%left%%N", "normal.inGameHidersLeft"),
NORMAL_IN_GAME_SEEKER_DIED("%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%secs%%N" +
NORMAL_IN_GAME_SEEKER_DIED("%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%seconds%%N" +
"seconds!", "normal.inGameSeekerDied"),
normal_winSeekers("%TAG%NThe %ASEEKERS%N have won!", "normal.winSeekers"),
NORMAL_WIN_HIDERS("%TAG%NThe %AHIDERS%N have won!", "normal.winHiders"),

View File

@ -19,7 +19,7 @@ public enum Permission {
SIGN_CREATE("signcreate", PermissionDefault.MODERATOR),
REMOVE("remove", PermissionDefault.ADMIN),
TOKENS("tokens", PermissionDefault.ADMIN),
ALL_COMMANDS("allcommands", PermissionDefault.OP);
;
public final String perm;
public final PermissionDefault type;

View File

@ -8,12 +8,13 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
@SuppressWarnings("unused")
public class EndArenaEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private List<Player> winners = null;
private List<Player> losers = null;
private Arena arena = null;
private final List<Player> winners;
private final List<Player> losers;
private final Arena arena;
public EndArenaEvent(List<Player> winners, List<Player> losers, Arena arena) {
this.winners = winners;
@ -33,6 +34,7 @@ public class EndArenaEvent extends Event {
return arena;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -6,11 +6,12 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class JoinArenaEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Player player = null;
private Arena arena = null;
private final Player player;
private final Arena arena;
public JoinArenaEvent(Player player, Arena arena) {
this.player = player;
@ -25,6 +26,7 @@ public class JoinArenaEvent extends Event {
return arena;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -6,11 +6,12 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class LeaveArenaEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Player player = null;
private Arena arena = null;
private final Player player;
private final Arena arena;
public LeaveArenaEvent(Player player, Arena arena) {
this.player = player;
@ -25,6 +26,7 @@ public class LeaveArenaEvent extends Event {
return arena;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -8,8 +8,8 @@ import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.apache.commons.lang.StringUtils;
import net.knarcraft.blockhunt.util.MessageHelper;
import net.knarcraft.blockhunt.util.StringHelper;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Arrow;
@ -29,7 +29,7 @@ public class OnEntityDamageByEntityEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player player) || event.getEntity() == null) {
if (!(event.getEntity() instanceof Player player)) {
// We only care about player damage
return;
}
@ -39,21 +39,21 @@ public class OnEntityDamageByEntityEvent implements Listener {
return;
}
Player damager = null;
Player damageDealer = null;
if (event.getDamager() instanceof Player) {
damager = (Player) event.getDamager();
damageDealer = (Player) event.getDamager();
} else {
if ((event.getCause() == DamageCause.PROJECTILE) && (event.getDamager() instanceof Arrow arrow)) {
// If damage was caused by an arrow, find out who shot the arrow
ProjectileSource shooter = arrow.getShooter();
if (shooter instanceof Player) {
damager = (Player) shooter;
damageDealer = (Player) shooter;
}
}
}
// Always block all damage not dealt by a player
if (damager == null || !(damager instanceof Player)) {
if (damageDealer == null) {
event.setCancelled(true);
return;
}
@ -67,7 +67,7 @@ public class OnEntityDamageByEntityEvent implements Listener {
} else {
// Seeker receiving damage
if (arena.seekers.contains(player)) {
if (arena.seekers.contains(damager)) {
if (arena.seekers.contains(damageDealer)) {
// Seeker damaged by seeker
if (!arena.seekersCanHurtSeekers) {
event.setCancelled(true);
@ -82,7 +82,7 @@ public class OnEntityDamageByEntityEvent implements Listener {
}
} else {
// Hider damaged by hider
if (!arena.hidersCanHurtHiders && !arena.seekers.contains(damager)) {
if (!arena.hidersCanHurtHiders && !arena.seekers.contains(damageDealer)) {
event.setCancelled(true);
return;
}
@ -96,39 +96,40 @@ public class OnEntityDamageByEntityEvent implements Listener {
event.setCancelled(true);
// try moving everything to the next tick to prevent "Removing entity while ticking" errors
Player finalDamager = damager;
Player finalDamager = damageDealer;
player.getServer().getScheduler().runTask(BlockHunt.plugin, () -> {
DisguiseAPI.undisguiseToAll(player);
MemoryStorage.pBlock.remove(player);
MemoryStorage.playerBlock.remove(player);
if (!arena.seekers.contains(player)) {
if (MemoryStorage.shop.getFile().get(finalDamager.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(finalDamager.getName() + ".tokens", 0);
if (MemoryStorage.shop.getFileConfiguration().get(finalDamager.getName() + ".tokens") == null) {
MemoryStorage.shop.getFileConfiguration().set(finalDamager.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int damagerTokens = MemoryStorage.shop.getFile().getInt(finalDamager.getName() + ".tokens");
MemoryStorage.shop.getFile().set(finalDamager.getName() + ".tokens", damagerTokens + arena.killTokens);
int damagerTokens = MemoryStorage.shop.getFileConfiguration().getInt(finalDamager.getName() + ".tokens");
MemoryStorage.shop.getFileConfiguration().set(finalDamager.getName() + ".tokens", damagerTokens + arena.killTokens);
MemoryStorage.shop.save();
MessageManager.sendFMessage(finalDamager, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.killTokens);
MessageHelper.sendMessage(finalDamager, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.killTokens);
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
float addingTokens = ((float) arena.hidersTokenWin - (((float) arena.timer / (float) arena.gameTime) * (float) arena.hidersTokenWin));
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens + (int) addingTokens);
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens + (int) addingTokens);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + (int) addingTokens);
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + (int) addingTokens);
arena.seekers.add(player);
player.setWalkSpeed(0.3F);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_HIDER_DIED, "%playerName%-" + player.getDisplayName(), "killer-" + finalDamager.getDisplayName());
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDER_DIED,
"%playerName%-" + player.getDisplayName(), "killer-" + finalDamager.getDisplayName());
int hidercount = (arena.playersInArena.size() - arena.seekers.size());
if ((hidercount <= 3) && (hidercount > 0)) {
int hiderCount = (arena.playersInArena.size() - arena.seekers.size());
if ((hiderCount <= 3) && (hiderCount > 0)) {
List<String> hiders = new ArrayList<>();
for (Player p : arena.playersInArena) {
if (!arena.seekers.contains(p)) {
@ -137,14 +138,16 @@ public class OnEntityDamageByEntityEvent implements Listener {
}
Collections.sort(hiders);
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT, "left-" + StringUtils.join(hiders.toArray(), ", "));
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT,
"left-" + String.join(", ",
StringHelper.toString(hiders.toArray())));
} else {
ArenaHandler.sendFMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT, "left-" + hidercount);
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT,
"left-" + hiderCount);
}
}
player.getInventory().clear();
player.updateInventory();
if (arena.seekers.size() >= arena.playersInArena.size()) {
ArenaHandler.seekersWin(arena);

View File

@ -7,8 +7,8 @@ import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.arena.ArenaProperty;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import org.apache.commons.lang.WordUtils;
import net.knarcraft.blockhunt.util.MessageHelper;
import net.knarcraft.blockhunt.util.StringHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -33,87 +33,81 @@ public class OnInventoryClickEvent implements Listener {
}
}
Inventory inv = event.getInventory();
InventoryView invView = event.getView();
Inventory inventory = event.getInventory();
InventoryView inventoryView = event.getView();
if (!inv.getType().equals(InventoryType.CHEST)) {
if (!inventory.getType().equals(InventoryType.CHEST)) {
return;
}
if (invView.getTitle().contains("DisguiseBlocks")) {
if (inventoryView.getTitle().contains("DisguiseBlocks")) {
if (event.getCurrentItem() != null && !event.getCurrentItem().getType().isBlock() &&
!event.getCurrentItem().getType().equals(Material.FLOWER_POT)) {
event.setCancelled(true);
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_NOT_A_BLOCK);
MessageHelper.sendMessage(player, MessageKey.ERROR_SET_NOT_A_BLOCK);
}
return;
}
// Early exit if this isn't a block-hunt inventory
if (!invView.getTitle().contains("BlockHunt")) {
if (!inventoryView.getTitle().contains("BlockHunt")) {
return;
}
if (!invView.getTitle().startsWith("\u00A7r")) {
if (!inventoryView.getTitle().startsWith("\u00A7r")) {
return;
}
if (invView.getTitle().equals(MessageManager.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_TITLE)))) {
if (inventoryView.getTitle().equals(MessageHelper.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_TITLE)))) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
if (item == null) {
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
if (item == null || item.getType().equals(Material.AIR) || item.getItemMeta() == null) {
return;
}
if (item.getType().equals(Material.AIR)) {
return;
}
if (item.getItemMeta().getDisplayName() == null) {
return;
}
if (item.getItemMeta().getDisplayName().equals(MessageManager.replaceAll(MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME).toString()))) {
if (item.getItemMeta().getDisplayName().equals(MessageHelper.replaceAll(MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME).toString()))) {
if (playerTokens >= (Integer) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_PRICE)) {
MemoryStorage.shop.getFile().set(player.getName() + ".blockchooser", true);
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens - (Integer) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_PRICE));
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockchooser", true);
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens - (Integer) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_PRICE));
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_SHOP_BOUGHT_ITEM, "itemName-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME));
MessageHelper.sendMessage(player, MessageKey.NORMAL_SHOP_BOUGHT_ITEM, "itemName-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME));
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SHOP_NEED_MORE_TOKENS);
MessageHelper.sendMessage(player, MessageKey.ERROR_SHOP_NEED_MORE_TOKENS);
}
} else if (item.getItemMeta().getDisplayName().equals(MessageManager.replaceAll(MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME).toString()))) {
} else if (item.getItemMeta().getDisplayName().equals(MessageHelper.replaceAll(MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME).toString()))) {
if (playerTokens >= (Integer) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_PRICE)) {
if (MemoryStorage.shop.getFile().get(player.getName() + ".blockhuntpass") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".blockhuntpass", 0);
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".blockhuntpass") == null) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockhuntpass", 0);
MemoryStorage.shop.save();
}
MemoryStorage.shop.getFile().set(player.getName() + ".blockhuntpass", (Integer) MemoryStorage.shop.getFile().get(player.getName() + ".blockhuntpass") + 1);
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens - (Integer) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_PRICE));
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockhuntpass", (Integer) MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".blockhuntpass") + 1);
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens - (Integer) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_PRICE));
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, MessageKey.NORMAL_SHOP_BOUGHT_ITEM, "itemName-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME));
MessageHelper.sendMessage(player, MessageKey.NORMAL_SHOP_BOUGHT_ITEM, "itemName-" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME));
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SHOP_NEED_MORE_TOKENS);
MessageHelper.sendMessage(player, MessageKey.ERROR_SHOP_NEED_MORE_TOKENS);
}
}
InventoryHandler.openShop(player);
} else if (invView.getTitle().contains(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)))) {
} else if (inventoryView.getTitle().contains(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)))) {
event.setCancelled(true);
if (event.getCurrentItem() != null) {
if (event.getCurrentItem().getType().isBlock()) {
MemoryStorage.chosenBlock.put(player, event.getCurrentItem());
String blockName = event.getCurrentItem().getType().name();
blockName = WordUtils.capitalizeFully(blockName.replace("_", " "));
MessageManager.sendFMessage(player, MessageKey.NORMAL_SHOP_CHOSEN_BLOCK, "block-"
blockName = StringHelper.uppercaseAllFirst(blockName.replace("_", " "));
MessageHelper.sendMessage(player, MessageKey.NORMAL_SHOP_CHOSEN_BLOCK, "block-"
+ blockName);
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_NOT_A_BLOCK);
MessageHelper.sendMessage(player, MessageKey.ERROR_SET_NOT_A_BLOCK);
}
}
} else if (invView.getTitle().contains(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)))) {
} else if (inventoryView.getTitle().contains(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)))) {
event.setCancelled(true);
if (event.getCurrentItem() != null) {
if (event.getCurrentItem().getType().equals(Material.BLUE_WOOL)) {
@ -130,18 +124,17 @@ public class OnInventoryClickEvent implements Listener {
}
if (i >= arena.amountSeekersOnStart) {
MessageManager.sendFMessage(player, MessageKey.ERROR_SHOP_MAX_SEEKERS_REACHED);
MessageHelper.sendMessage(player, MessageKey.ERROR_SHOP_MAX_SEEKERS_REACHED);
} else {
MemoryStorage.chosenSeeker.put(player, true);
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
player.updateInventory();
MessageManager.sendFMessage(player, MessageKey.NORMAL_SHOP_CHOSEN_SEEKER);
inv.clear();
if (MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") == 1) {
MemoryStorage.shop.getFile().set(player.getName() + ".blockhuntpass", null);
MessageHelper.sendMessage(player, MessageKey.NORMAL_SHOP_CHOSEN_SEEKER);
inventory.clear();
if (MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass") == 1) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockhuntpass", null);
MemoryStorage.shop.save();
} else {
MemoryStorage.shop.getFile().set(player.getName() + ".blockhuntpass", MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") - 1);
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockhuntpass", MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass") - 1);
MemoryStorage.shop.save();
}
}
@ -161,18 +154,17 @@ public class OnInventoryClickEvent implements Listener {
}
if (i >= (arena.playersInArena.size() - 1)) {
MessageManager.sendFMessage(player, MessageKey.ERROR_SHOP_MAX_HIDERS_REACHED);
MessageHelper.sendMessage(player, MessageKey.ERROR_SHOP_MAX_HIDERS_REACHED);
} else {
MemoryStorage.chosenSeeker.put(player, false);
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
player.updateInventory();
MessageManager.sendFMessage(player, MessageKey.NORMAL_SHOP_CHOSEN_HIDERS);
inv.clear();
if (MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") == 1) {
MemoryStorage.shop.getFile().set(player.getName() + ".blockhuntpass", null);
MessageHelper.sendMessage(player, MessageKey.NORMAL_SHOP_CHOSEN_HIDERS);
inventory.clear();
if (MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass") == 1) {
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockhuntpass", null);
MemoryStorage.shop.save();
} else {
MemoryStorage.shop.getFile().set(player.getName() + ".blockhuntpass", MemoryStorage.shop.getFile().getInt(player.getName() + ".blockhuntpass") - 1);
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".blockhuntpass", MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass") - 1);
MemoryStorage.shop.save();
}
}
@ -182,7 +174,7 @@ public class OnInventoryClickEvent implements Listener {
} else {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
String arenaName = inv.getItem(0).getItemMeta().getDisplayName().replaceAll(MessageManager.replaceAll("%NBlockHunt arena: %A"), "");
String arenaName = inventory.getItem(0).getItemMeta().getDisplayName().replaceAll(MessageHelper.replaceAll("%NBlockHunt arena: %A"), "");
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
@ -227,7 +219,7 @@ public class OnInventoryClickEvent implements Listener {
}
public void save(Arena arena) {
MemoryStorage.arenas.getFile().set(arena.arenaName, arena);
MemoryStorage.arenas.getFileConfiguration().set(arena.arenaName, arena);
MemoryStorage.arenas.save();
ArenaHandler.loadArenas();
}
@ -250,7 +242,7 @@ public class OnInventoryClickEvent implements Listener {
case KILL_TOKENS -> arena.killTokens = option + add;
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_TOO_HIGH_NUMBER, "max-" + max);
MessageHelper.sendMessage(player, MessageKey.ERROR_SET_TOO_HIGH_NUMBER, "max-" + max);
}
} else if (item.getItemMeta().getDisplayName().contains((String) MemoryStorage.messages.get(MessageKey.BUTTON_REMOVE_2))) {
if (option > min) {
@ -268,7 +260,7 @@ public class OnInventoryClickEvent implements Listener {
case KILL_TOKENS -> arena.killTokens = option - remove;
}
} else {
MessageManager.sendFMessage(player, MessageKey.ERROR_SET_TOO_LOW_NUMBER, "min-" + min);
MessageHelper.sendMessage(player, MessageKey.ERROR_SET_TOO_LOW_NUMBER, "min-" + min);
}
}
}

View File

@ -3,7 +3,7 @@ package net.knarcraft.blockhunt.listener;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.arena.Arena;
import net.knarcraft.blockhunt.arena.ArenaHandler;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -25,7 +25,8 @@ public class OnInventoryCloseEvent implements Listener {
InventoryView invView = event.getView();
if (inv.getType().equals(InventoryType.CHEST)) {
if (invView.getTitle().contains("DisguiseBlocks")) {
String arenaName = inv.getItem(0).getItemMeta().getDisplayName().replaceAll(MessageManager.replaceAll("%NDisguiseBlocks of arena: %A"), "");
String arenaName = inv.getItem(0).getItemMeta().getDisplayName().replaceAll(
MessageHelper.replaceAll("%NDisguiseBlocks of arena: %A"), "");
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
@ -49,7 +50,7 @@ public class OnInventoryCloseEvent implements Listener {
}
public void save(Arena arena) {
MemoryStorage.arenas.getFile().set(arena.arenaName, arena);
MemoryStorage.arenas.getFileConfiguration().set(arena.arenaName, arena);
MemoryStorage.arenas.save();
ArenaHandler.loadArenas();
}

View File

@ -10,14 +10,17 @@ import net.knarcraft.blockhunt.arena.ArenaState;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.config.Permission;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.manager.PermissionsManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -28,6 +31,8 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Map;
public class OnPlayerInteractEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@ -35,63 +40,13 @@ public class OnPlayerInteractEvent implements Listener {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (PermissionsManager.hasPermission(player, Permission.CREATE, false)) {
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Material.AIR) {
if (item.getItemMeta().hasDisplayName()) {
ItemMeta im = item.getItemMeta();
if (im.getDisplayName().equals(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.WAND_NAME)))) {
Action action = event.getAction();
if (event.hasBlock()) {
Location location = event.getClickedBlock().getLocation();
if (action.equals(Action.LEFT_CLICK_BLOCK)) {
event.setCancelled(true);
if (MemoryStorage.pos1.get(player) == null || !MemoryStorage.pos1.get(player).equals(location)) {
MessageManager.sendFMessage(player, MessageKey.NORMAL_WAND_SET_POSITION, "number-1",
"pos-%N(%A" + location.getBlockX() + "%N, %A" + location.getBlockY() + "%N, %A" + location.getBlockZ() + "%N)", "x-"
+ location.getBlockX(), "y-" + location.getBlockY(), "z-" + location.getBlockZ());
MemoryStorage.pos1.put(player, location);
}
} else if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true);
if (MemoryStorage.pos2.get(player) == null || !MemoryStorage.pos2.get(player).equals(location)) {
MessageManager.sendFMessage(player, MessageKey.NORMAL_WAND_SET_POSITION, "number-2",
"pos-%N(%A" + location.getBlockX() + "%N, %A" + location.getBlockY() + "%N, %A" + location.getBlockZ() + "%N)", "x-"
+ location.getBlockX(), "y-" + location.getBlockY(), "z-" + location.getBlockZ());
MemoryStorage.pos2.put(player, location);
}
}
}
}
}
}
handleWandClick(event, player, block);
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getClickedBlock() != null) {
if (event.getClickedBlock().getState() instanceof Sign) {
if (SignsHandler.isSign(event.getClickedBlock().getLocation())) {
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.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.hasPermission(player, Permission.SHOP, true)) {
InventoryHandler.openShop(player);
}
} else {
Arena arena = MemoryStorage.arenaMap.get(sign.getLines()[1].toLowerCase());
if (arena != null) {
if (PermissionsManager.hasPermission(player, Permission.JOIN_SIGN, true)) {
ArenaHandler.playerJoinArena(player, arena.arenaName);
}
}
}
}
}
}
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null &&
event.getClickedBlock().getState() instanceof Sign sign &&
SignsHandler.isSign(event.getClickedBlock().getLocation())) {
handleSignClick(player, sign);
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
@ -113,11 +68,11 @@ public class OnPlayerInteractEvent implements Listener {
for (Arena arena : MemoryStorage.arenaMap.values()) {
if (arena.seekers.contains(player)) {
for (Player pl : arena.playersInArena) {
if (MemoryStorage.hiddenLoc.get(pl) != null) {
if (MemoryStorage.hiddenLocation.get(pl) != null) {
Block pLoc = event.getClickedBlock();
Block moveLocBlock = MemoryStorage.hiddenLoc.get(pl).getBlock();
Block moveLocBlock = MemoryStorage.hiddenLocation.get(pl).getBlock();
if (moveLocBlock.getX() == pLoc.getX() && moveLocBlock.getY() == pLoc.getY() && moveLocBlock.getZ() == pLoc.getZ()) {
MemoryStorage.moveLoc.put(pl, new Location(pl.getWorld(), 0, 0, 0));
MemoryStorage.moveLocation.put(pl, new Location(pl.getWorld(), 0, 0, 0));
pl.getWorld().playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT, 1, 1);
SolidBlockHandler.makePlayerUnsolid(pl);
}
@ -133,8 +88,8 @@ public class OnPlayerInteractEvent implements Listener {
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Material.AIR) {
if (item.getItemMeta().getDisplayName() != null) {
if (item.getItemMeta().getDisplayName().equals(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)))) {
Inventory blockChooser = Bukkit.createInventory(null, 36, MessageManager.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
if (item.getItemMeta().getDisplayName().equals(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)))) {
Inventory blockChooser = Bukkit.createInventory(null, 36, MessageHelper.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
if (arena.disguiseBlocks != null) {
for (int i = arena.disguiseBlocks.size(); i > 0; i = i - 1) {
blockChooser.setItem(i - 1, arena.disguiseBlocks.get(i - 1));
@ -144,16 +99,16 @@ public class OnPlayerInteractEvent implements Listener {
player.openInventory(blockChooser);
}
if (item.getItemMeta().getDisplayName().equals(MessageManager.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)))) {
Inventory BlockHuntPass = Bukkit.createInventory(null, 9, MessageManager.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
if (item.getItemMeta().getDisplayName().equals(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)))) {
Inventory BlockHuntPass = Bukkit.createInventory(null, 9, MessageHelper.replaceAll("\u00A7r" + MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_NAME)));
ItemStack BlockHuntPassSEEKER = new ItemStack(Material.BLUE_WOOL, 1);
ItemMeta BlockHuntPassIM = BlockHuntPassSEEKER.getItemMeta();
BlockHuntPassIM.setDisplayName(MessageManager.replaceAll("&eSEEKER"));
BlockHuntPassIM.setDisplayName(MessageHelper.replaceAll("&eSEEKER"));
BlockHuntPassSEEKER.setItemMeta(BlockHuntPassIM);
BlockHuntPass.setItem(1, BlockHuntPassSEEKER);
ItemStack BlockHuntPassHIDER = new ItemStack(Material.RED_WOOL, 1);
BlockHuntPassIM.setDisplayName(MessageManager.replaceAll("&eHIDER"));
BlockHuntPassIM.setDisplayName(MessageHelper.replaceAll("&eHIDER"));
BlockHuntPassHIDER.setItemMeta(BlockHuntPassIM);
BlockHuntPass.setItem(7, BlockHuntPassHIDER);
@ -165,4 +120,75 @@ public class OnPlayerInteractEvent implements Listener {
}
}
private void handleSignClick(Player player, Sign sign) {
FileConfiguration fileConfiguration = MemoryStorage.config.getFileConfiguration();
String signIdentifier = sign.getSide(Side.FRONT).getLine(1);
if (signIdentifier.equals(MessageHelper.replaceAll(
fileConfiguration.getStringList(ConfigKey.SIGN_LEAVE.getPath()).get(1)))) {
if (PermissionsManager.hasPermission(player, Permission.JOIN_SIGN, true)) {
ArenaHandler.playerLeaveArena(player, true, true);
}
} else if (signIdentifier.equals(MessageHelper.replaceAll(
fileConfiguration.getStringList(ConfigKey.SIGN_SHOP.getPath()).get(1)))) {
if (PermissionsManager.hasPermission(player, Permission.SHOP, true)) {
InventoryHandler.openShop(player);
}
} else {
String cleanName = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&',
signIdentifier.toLowerCase()));
Arena arena = MemoryStorage.arenaMap.get(cleanName);
if (arena != null && PermissionsManager.hasPermission(player, Permission.JOIN_SIGN, true)) {
ArenaHandler.playerJoinArena(player, arena.arenaName);
}
}
}
/**
* Handles a player clicking a block with the selection wand
*
* @param event <p>The triggered interaction event</p>
* @param player <p>The player that interacted with a block</p>
* @param block <p>The block the player clicked</p>
*/
private void handleWandClick(PlayerInteractEvent event, Player player, Block block) {
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() == Material.AIR || item.getItemMeta() == null || !item.getItemMeta().hasDisplayName()) {
return;
}
ItemMeta itemMeta = item.getItemMeta();
if (!itemMeta.getDisplayName().equals(MessageHelper.replaceAll((String) MemoryStorage.config.get(ConfigKey.WAND_NAME)))) {
return;
}
Action action = event.getAction();
if (!event.hasBlock() || block == null) {
return;
}
Location location = block.getLocation();
if (!action.equals(Action.LEFT_CLICK_BLOCK) && !action.equals(Action.RIGHT_CLICK_BLOCK)) {
return;
}
event.setCancelled(true);
int number;
Map<Player, Location> locationMap;
if (action.equals(Action.LEFT_CLICK_BLOCK)) {
locationMap = MemoryStorage.pos1;
number = 1;
} else {
locationMap = MemoryStorage.pos2;
number = 2;
}
if (locationMap.get(player) == null || !locationMap.get(player).equals(location)) {
MessageHelper.sendMessage(player, MessageKey.NORMAL_WAND_SET_POSITION, "number-" + number,
"x-" + block.getX(), "y-" + block.getY(), "z-" + block.getZ());
locationMap.put(player, location);
}
}
}

View File

@ -38,7 +38,7 @@ public class OnPlayerMoveEvent implements Listener {
}
ArenaLocations locations = arena.arenaLocations;
MemoryStorage.moveLoc.put(player, player.getLocation());
MemoryStorage.moveLocation.put(player, player.getLocation());
if (locations.getCorner1() == null || locations.getCorner2() == null) {
BlockHunt.plugin.getLogger().info("Arena:" +
arena.arenaName + " appears to have bad coords : pos1:" +

View File

@ -2,7 +2,7 @@ package net.knarcraft.blockhunt.listener;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.manager.MessageManager;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -15,7 +15,7 @@ public class OnPlayerTeleportEvent implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerTeleportEvent(PlayerTeleportEvent event) {
Player player = event.getPlayer();
if (MemoryStorage.pData.get(player) != null) {
if (MemoryStorage.playerData.get(player) != null) {
handlePlayer(event, player);
}
}
@ -27,10 +27,10 @@ public class OnPlayerTeleportEvent implements Listener {
* @param player Player
*/
private void handlePlayer(PlayerTeleportEvent event, Player player) {
Location storedLoc = MemoryStorage.teleportLoc.remove(player);
Location storedLoc = MemoryStorage.teleportLocation.remove(player);
Location to = event.getTo();
if (storedLoc == null || storedLoc.getWorld() != to.getWorld() || to.distanceSquared(storedLoc) > 1) {
MessageManager.sendFMessage(player, MessageKey.ERROR_TELEPORT_BLOCKED);
MessageHelper.sendMessage(player, MessageKey.ERROR_TELEPORT_BLOCKED);
event.setCancelled(true);
}
}

View File

@ -5,6 +5,7 @@ import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.Key;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -14,7 +15,7 @@ public class ConfigManager {
private final String fileName;
private final File file;
private final FileConfiguration fileC;
private final FileConfiguration fileConfiguration;
/**
* Use this class to create an automated config file.
@ -24,9 +25,9 @@ public class ConfigManager {
public ConfigManager(String fileName) {
this.fileName = fileName;
this.file = new File(BlockHunt.plugin.getDataFolder(), fileName + ".yml");
this.fileC = new YamlConfiguration();
this.fileConfiguration = new YamlConfiguration();
this.checkFile();
fileC.getConfigurationSection("");
fileConfiguration.getConfigurationSection("");
this.load();
}
@ -37,7 +38,7 @@ public class ConfigManager {
public static void newFiles() {
ConfigManager.setDefaults();
for (String fileName : MemoryStorage.newFiles) {
MessageManager.sendMessage(null, "%TAG%WCouldn't find '%A%fileName%.yml%W'%A creating new one.",
MessageHelper.sendMessage(null, "%TAG%WCouldn't find '%A%fileName%.yml%W'%A creating new one.",
"fileName-" + fileName);
}
@ -55,8 +56,8 @@ public class ConfigManager {
private static void setDefaults(Key[] configKeys) {
for (Key key : configKeys) {
key.getConfigManager().load();
if (key.getConfigManager().getFile().get(key.getPath()) == null) {
key.getConfigManager().getFile().set(key.getPath(), key.getDefaultValue());
if (key.getConfigManager().getFileConfiguration().get(key.getPath()) == null) {
key.getConfigManager().getFileConfiguration().set(key.getPath(), key.getDefaultValue());
key.getConfigManager().save();
}
}
@ -82,7 +83,7 @@ public class ConfigManager {
*/
public void save() {
try {
this.fileC.save(this.file);
this.fileConfiguration.save(this.file);
} catch (Exception e) {
e.printStackTrace();
}
@ -95,7 +96,7 @@ public class ConfigManager {
this.checkFile();
if (this.file.exists()) {
try {
this.fileC.load(this.file);
this.fileConfiguration.load(this.file);
} catch (Exception e) {
e.printStackTrace();
}
@ -105,8 +106,8 @@ public class ConfigManager {
/**
* Get the File. Very useful for just loading/saving.
*/
public FileConfiguration getFile() {
return this.fileC;
public FileConfiguration getFileConfiguration() {
return this.fileConfiguration;
}
/**
@ -116,7 +117,7 @@ public class ConfigManager {
* @return Object
*/
public Object get(Key location) {
return this.getFile().get(location.getPath());
return this.getFileConfiguration().get(location.getPath());
}
}

View File

@ -1,167 +0,0 @@
package net.knarcraft.blockhunt.manager;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.MemoryStorage;
import net.knarcraft.blockhunt.config.ConfigKey;
import net.knarcraft.blockhunt.config.Key;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Objects;
import java.util.logging.Level;
public class MessageManager {
/**
* Send a message to a player. Also replaces the "%player%" variable to the
* player's name.
*
* @param player The player receiving the message.
* @param message Message which needs to be sent to the player.
* @param vars Variables. Separated with a - . Ex: "playerName-" +
* player.getName();
*/
public static void sendMessage(Player player, String message, String... vars) {
if (player == null) {
Bukkit.getConsoleSender().sendMessage(MessageManager.replaceAll(message.replaceAll("%player%", "Console"), vars));
} else {
player.sendMessage(MessageManager.replaceAll(message.replaceAll("%player%", player.getDisplayName()), vars));
}
}
/**
* Send a message to a player from a Config. Also replaces the "%player%"
* variable to the player's name.
*
* @param player The player receiving the message.
* @param location Location in the config of the message being sent.
* @param vars Variables. Separated with a - . Ex: "playerName-" +
* player.getName();
*/
public static void sendFMessage(Player player, Key location, String... vars) {
Object value = location.getConfigManager().getFile().get(location.getPath());
if (value == null) {
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Unable to read value for " + location.getPath());
Objects.requireNonNullElseGet(player, Bukkit::getConsoleSender).sendMessage("An error occurred while " +
"generating a BlockHunt message. Please notify an administrator.");
return;
}
String playerString = player == null ? "Console" : player.getDisplayName();
String message = MessageManager.replaceAll(value.toString().replaceAll("%player%", playerString), vars);
Objects.requireNonNullElseGet(player, Bukkit::getConsoleSender).sendMessage(message);
}
/**
* Send a message to all players online. Also replaces the "%player%"
* variable to the player's name.
*
* @param message Message which needs to be sent to the player.
* @param vars Variables. Seperated with a - . Ex: "playerName-" +
* player.getName();
*/
public static void broadcastMessage(String message, String... vars) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(MessageManager.replaceAll(message.replaceAll("%player%", player.getDisplayName()), vars));
}
Bukkit.getConsoleSender().sendMessage(MessageManager.replaceAll(message.replaceAll("%player%", "Console"), vars));
}
/**
* Send a message to all players online from a Config. Also replaces the
* "%player%" variable to the player's name.
*
* @param location Location in the config of the message being sent.
* @param vars Variables . Separated with a - . Ex: "playerName-" +
* player.getName();
*/
public static void broadcastFMessage(Key location, String... vars) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(MessageManager.replaceAll(location.getConfigManager().getFile().get(
location.getPath()).toString().replaceAll("%player%", player.getDisplayName()), vars));
}
Bukkit.getConsoleSender().sendMessage(MessageManager.replaceAll(location.getConfigManager().getFile().get(
location.getPath()).toString().replaceAll("%player%", "Console"), vars));
}
/**
* Replace all variables.
*
* @param message Message which needs to be replaced.
* @param vars Variables. Seperated with a - . Ex: "playerName-" +
* player.getName();
* @return String with the message with values replaced
*/
public static String replaceAll(String message, String... vars) {
return MessageManager.replaceColours(MessageManager.replaceColourVars(MessageManager.replaceVars(message, vars)));
}
/**
* Replace default Minecraft colour codes.
*
* @param message Message which needs to be replaced.
* @return Colour replaced message.
*/
public static String replaceColours(String message) {
return message.replaceAll("(&([a-fk-or0-9]))", "\u00A7$2");
}
/**
* Replace colour codes of this plugin.
*
* @param message Message which needs to be replaced.
* @return Colour replaced message.
*/
public static String replaceColourVars(String message) {
message = message.replaceAll("%N", CType.NORMAL());
message = message.replaceAll("%W", CType.WARNING());
message = message.replaceAll("%E", CType.ERROR());
message = message.replaceAll("%A", CType.ARG());
message = message.replaceAll("%H", CType.HEADER());
message = message.replaceAll("%TAG", CType.TAG());
return message;
}
/**
* Replace custom variables.
*
* @param message Message which needs to be replaced.
* @param vars Variables. Seperated with a - . Ex: "playerName-" +
* player.getName();
* @return Replaced String.
*/
public static String replaceVars(String message, String... vars) {
for (String var : vars) {
String[] split = var.split("-");
message = message.replaceAll("%" + split[0] + "%", split[1]);
}
return message;
}
public static class CType {
public static String NORMAL() {
return (String) MemoryStorage.config.get(ConfigKey.CHAT_NORMAL);
}
public static String WARNING() {
return (String) MemoryStorage.config.get(ConfigKey.CHAT_WARNING);
}
public static String ERROR() {
return (String) MemoryStorage.config.get(ConfigKey.CHAT_ERROR);
}
public static String ARG() {
return (String) MemoryStorage.config.get(ConfigKey.CHAT_ARGUMENT);
}
public static String HEADER() {
return (String) MemoryStorage.config.get(ConfigKey.CHAT_HEADER);
}
public static String TAG() {
return (String) MemoryStorage.config.get(ConfigKey.CHAT_HEADER) + MemoryStorage.config.get(ConfigKey.CHAT_TAG) + MemoryStorage.config.get(ConfigKey.CHAT_NORMAL);
}
}
}

View File

@ -4,6 +4,7 @@ import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.config.MessageKey;
import net.knarcraft.blockhunt.config.Permission;
import net.knarcraft.blockhunt.config.PermissionDefault;
import net.knarcraft.blockhunt.util.MessageHelper;
import org.bukkit.entity.Player;
public class PermissionsManager {
@ -12,14 +13,14 @@ public class PermissionsManager {
* Check if a player has the permission. Also checks * related permissions.
* This permission DOES HAVE TO be registered.
*
* @param player The player who needs the permission.
* @param perm The permission.
* @param message Send a message to the player saying you don't have the
* permission.
* @param player The player who needs the permission.
* @param permission 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 hasPermission(Player player, Permission perm, Boolean message) {
PermissionDefault type = perm.type;
public static boolean hasPermission(Player player, Permission permission, Boolean message) {
PermissionDefault type = permission.type;
if (player == null) {
return true;
}
@ -48,16 +49,16 @@ public class PermissionsManager {
return true;
} else if (player.hasPermission(BlockHunt.plugin.rootPermission + "*")) {
return true;
} else if (player.hasPermission(BlockHunt.plugin.rootPermission + perm.perm)) {
} else if (player.hasPermission(BlockHunt.plugin.rootPermission + permission.perm)) {
return true;
} else if (player.hasPermission(BlockHunt.plugin.rootPermission + perm.perm + ".*")) {
} else if (player.hasPermission(BlockHunt.plugin.rootPermission + permission.perm + ".*")) {
return true;
} else {
if (message) {
MessageManager.sendFMessage(player, MessageKey.ERROR_NO_PERMISSION);
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_PERMISSION);
}
return false;
}
return false;
}
}

View File

@ -0,0 +1,176 @@
package net.knarcraft.blockhunt.util;
import net.knarcraft.blockhunt.BlockHunt;
import net.knarcraft.blockhunt.config.ChatMessageTypeIdentifier;
import net.knarcraft.blockhunt.config.Key;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.Objects;
import java.util.logging.Level;
/**
* A helper class for sending messages
*/
public final class MessageHelper {
private MessageHelper() {
}
/**
* Sends a message to a player
*
* <p>Also replaces the "%player%" variable to the player's name</p>
*
* @param player <p>The player to receive the message</p>
* @param message <p>The message to send to a player</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
*/
public static void sendMessage(Player player, String message, String... variables) {
if (message == null) {
return;
}
String playerString = player == null ? "Console" : player.getDisplayName();
message = MessageHelper.replaceAll(message.replaceAll("%player%", playerString), variables);
Objects.requireNonNullElseGet(player, Bukkit::getConsoleSender).sendMessage(message);
}
/**
* Sends a message to a player defined
*
* <p>Also replaces the "%player%" variable to the player's name</p>
*
* @param player <p>The player to receive the message</p>
* @param messageKey <p>A key pointing to a message</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
*/
public static void sendMessage(Player player, Key messageKey, String... variables) {
sendMessage(player, getMessageFromConfig(player, messageKey), variables);
}
/**
* Sends a message to the specified players
*
* <p>Also replaces the "%player%" variable to the player's name.</p>
*
* @param players <p>The players to broadcast the message to</p>
* @param message <p>The message to send to a player</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
*/
public static void broadcastMessage(Collection<? extends Player> players, String message, String... variables) {
if (message == null) {
return;
}
for (Player player : players) {
sendMessage(player, message, variables);
}
}
/**
* Sends a message to all players online
*
* <p>Also replaces the "%player%" variable to the player's name.</p>
*
* @param message <p>The message to send to a player</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
*/
public static void broadcastMessage(String message, String... variables) {
broadcastMessage(Bukkit.getOnlinePlayers(), message, variables);
}
/**
* Sends a message to the specified players
*
* <p>Also replaces the "%player%" variable to the player's name.</p>
*
* @param players <p>The players to broadcast the message to</p>
* @param messageKey <p>A key pointing to a message</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
*/
public static void broadcastMessage(Collection<? extends Player> players, Key messageKey, String... variables) {
broadcastMessage(players, getMessageFromConfig(null, messageKey), variables);
}
/**
* Sends a message to all players online
*
* <p>Also replaces the "%player%" variable to the player's name.</p>
*
* @param messageKey <p>A key pointing to a message</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
*/
public static void broadcastMessage(Key messageKey, String... variables) {
broadcastMessage(getMessageFromConfig(null, messageKey), variables);
}
/**
* Replaces all variables and color variables in a string
*
* @param message <p>The message to replace variables for</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
* @return <p>The input string with any variables and color variables replaced</p>
*/
public static String replaceAll(String message, String... variables) {
return MessageHelper.replaceColors(MessageHelper.replaceFormattingVariables(
MessageHelper.replaceVariables(message, variables)));
}
/**
* Replaces default Minecraft colour codes
*
* @param message <p>The message to replace color codes for</p>
* @return <p>The input string with any default colors replaced</p>
*/
public static String replaceColors(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
/**
* Replaces special formatting variables defined by this plugin
*
* @param message <p>The message to replace formatting placeholders for</p>
* @return <p>The input string with any formatting placeholders replaced</p>
*/
public static String replaceFormattingVariables(String message) {
return ChatMessageTypeIdentifier.replaceAll(message);
}
/**
* Replaces custom variables
*
* @param message <p>The message to replace variables for</p>
* @param variables <p>Variables specified with the format "name-value" corresponding to %name%</p>
* @return <p>The input string with any variables replaced</p>
*/
public static String replaceVariables(String message, String... variables) {
for (String variable : variables) {
// Note: The splitting needs to be limited, or negative numbers will become empty strings
String[] split = variable.split("-", 2);
message = message.replaceAll("%" + split[0] + "%", split[1]);
}
return message;
}
/**
* Gets a message from the messages configuration file
*
* @param player <p>The player to get the message for, or null</p>
* @param messageKey <p>The key specifying the message</p>
* @return <p>The stored message, or null if not found</p>
*/
private static String getMessageFromConfig(Player player, Key messageKey) {
String message = messageKey.getConfigManager().getFileConfiguration().getString(messageKey.getPath(), null);
if (message == null) {
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Unable to read value for " + messageKey.getPath());
if (player != null) {
player.sendMessage("An error occurred while generating a BlockHunt message. " +
"Please notify an administrator.");
}
}
return message;
}
}

View File

@ -0,0 +1,37 @@
package net.knarcraft.blockhunt.util;
public final class StringHelper {
private StringHelper() {
}
/**
* Turns the first character of each of a string's words into uppercase
*
* @param input <p>The input to uppercase</p>
* @return <p>The input string with more uppercase</p>
*/
public static String uppercaseAllFirst(String input) {
String[] parts = input.split(" ");
for (int i = 0; i < parts.length; i++) {
parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1);
}
return String.join(" ", parts);
}
/**
* Gets an object array as a string array by running toString
*
* @param array <p>The input array</p>
* @return <p>The resulting string array</p>
*/
public static String[] toString(Object[] array) {
String[] output = new String[array.length];
for (int i = 0; i < array.length; i++) {
output[i] = array[i].toString();
}
return output;
}
}

View File

@ -30,7 +30,8 @@ wandGaveWand='%TAG%NHere you go! &o(Use the %A&o%type%%N&o!)'
wandSetPosition='%TAG%NSet position %A#%number%%N to location: (%A%x%%N, %A%y%%N,%A%z%%N).'
createCreatedArena='%TAG%NCreated an arena with the name ''%A%name%%N''.'
lobbyArenaIsStarting='%TAG%NThe arena will start in %A%1%%N second(s)!'
lobbyArenaStarted='%TAG%NThe arena has been started! The seeker is coming to find you in %A%secs%%N seconds!'
lobbyArenaStartedHiders='%TAG%NThe arena has been started! The seeker is coming to find you in %A%seconds%%N seconds!'
lobbyArenaStartedSeekers='%TAG%NThe arena has been started! You can start seeking in %A%seconds%%N seconds!'
inGameSeekerChosen='%TAG%NPlayer %A%seeker%%N has been chosen as seeker!'
inGameBlock='%TAG%NYou''re disguised as a(n) ''%A%block%%N'' block.'
inGameArenaEnd='%TAG%NThe arena will end in %A%1%%N second(s)!'
@ -38,7 +39,7 @@ inGameSeekerSpawned='%TAG%A%%playerName%%%N has spawned as a seeker!'
inGameGivenSword='%TAG%NYou were given a sword!'
inGameHiderDied='%TAG%NHider %A%%playerName%%%N was killed by %A%killer%%N!'
inGameHidersLeft='%NHider(s) left: %A%left%%N'
inGameSeekerDied='%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%secs%%N seconds!'
inGameSeekerDied='%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%seconds%%N seconds!'
winSeekers='%TAG%NThe %ASEEKERS%N have won!'
winHiders='%TAG%NThe %AHIDERS%N have won!'
setWarpWarpSet='%TAG%NSet warp ''%A%warp%%N'' to your location!'

View File

@ -30,7 +30,8 @@ wandGaveWand='%TAG%NHere you go! &o(Use the %A&o%type%%N&o!)'
wandSetPosition='%TAG%NSet position %A#%number%%N to location: (%A%x%%N, %A%y%%N,%A%z%%N).'
createCreatedArena='%TAG%NCreated an arena with the name ''%A%name%%N''.'
lobbyArenaIsStarting='%TAG%NThe arena will start in %A%1%%N second(s)!'
lobbyArenaStarted='%TAG%NThe arena has been started! The seeker is coming to find you in %A%secs%%N seconds!'
lobbyArenaStartedHiders='%TAG%NThe arena has been started! The seeker is coming to find you in %A%seconds%%N seconds!'
lobbyArenaStartedSeekers='%TAG%NThe arena has been started! You can start seeking in %A%seconds%%N seconds!'
inGameSeekerChosen='%TAG%NPlayer %A%seeker%%N has been chosen as seeker!'
inGameBlock='%TAG%NYou''re disguised as a(n) ''%A%block%%N'' block.'
inGameArenaEnd='%TAG%NThe arena will end in %A%1%%N second(s)!'
@ -38,7 +39,7 @@ inGameSeekerSpawned='%TAG%A%%playerName%%%N has spawned as a seeker!'
inGameGivenSword='%TAG%NYou were given a sword!'
inGameHiderDied='%TAG%NHider %A%%playerName%%%N was killed by %A%killer%%N!'
inGameHidersLeft='%NHider(s) left: %A%left%%N'
inGameSeekerDied='%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%secs%%N seconds!'
inGameSeekerDied='%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%seconds%%N seconds!'
winSeekers='%TAG%NThe %ASEEKERS%N have won!'
winHiders='%TAG%NThe %AHIDERS%N have won!'
setWarpWarpSet='%TAG%NSet warp ''%A%warp%%N'' to your location!'

View File

@ -22,3 +22,108 @@ commands:
- seekandfind
- saf
- sf
permissions:
blockhunt.*:
description: Gives all BlockHunt permissions
default: false
children:
- blockhunt.admin
- blockhunt.moderator
- blockhunt.player
- blockhunt.allcommands
blockhunt.admin:
description: Gives all admin-related BlockHunt permissions
default: false
children:
- blockhunt.reload
- blockhunt.create
- blockhunt.remove
- blockhunt.tokens
- blockhunt.shop.blockchooser
blockhunt.moderator:
description: Gives all moderator-related BlocHunt permissions
default: false
children:
- blockhunt.start
- blockhunt.set
- blockhunt.setWarp
- blockhunt.joinfull
- blockhunt.signcreate
blockhunt.player:
description: Gives all player-related BlockHunt permissions
default: false
children:
- blockhunt.join
- blockhunt.leave
- blockhunt.list
- blockhunt.shop
- blockhunt.joinsign
blockhunt.allcommands:
description: Gives access to all BlockHunt commands
default: op
children:
- blockhunt.info
- blockhunt.help
- blockhunt.reload
- blockhunt.join
- blockhunt.leave
- blockhunt.list
- blockhunt.shop
- blockhunt.start
- blockhunt.create
- blockhunt.set
- blockhunt.setWarp
- blockhunt.remove
- blockhunt.tokens
blockhunt.info:
description: Gives access to the "/bh info" command
default: true
blockhunt.help:
description: Gives access to the "/bh help" command
default: true
blockhunt.reload:
description: Gives access to the "/bh reload" command
default: false
blockhunt.join:
description: Gives access to the "/bh join" command
default: false
blockhunt.leave:
description: Gives access to the "/bh leave" command
default: false
blockhunt.list:
description: Gives access to the "/bh list" command
default: false
blockhunt.shop:
description: Gives access to the "/bh shop" command
default: false
blockhunt.start:
description: Gives access to the "/bh start" command
default: false
blockhunt.create:
description: Gives access to the "/bh create" and "/bh wand" commands
default: false
blockhunt.set:
description: Gives access to the "/bh set" command
default: false
blockhunt.setWarp:
description: Gives access to the "/bh setWarp" command
default: false
blockhunt.remove:
description: Gives access to the "/bh remove" command
default: false
blockhunt.tokens:
description: Gives access to the "/bh tokens" command
default: false
blockhunt.joinfull:
description: Gives access to joining a full BlockHunt arena
default: false
blockhunt.joinsign:
description: Gives access to join/leave sign usage
default: false
blockhunt.signcreate:
description: Gives access to create a join/leave sign
default: false
blockhunt.shop.blockchooser:
description: Gives access to the block chooser
default: false

View File

@ -33,8 +33,9 @@ normal:
%A%z%%N).'
createCreatedArena: '%TAG%NCreated an arena with the name ''%A%name%%N''.'
lobbyArenaIsStarting: '%TAG%NThe arena will start in %A%1%%N second(s)!'
lobbyArenaStarted: '%TAG%NThe arena has been started! The seeker is coming to find
you in %A%secs%%N seconds!'
lobbyArenaStartedHiders: '%TAG%NThe arena has been started! The seeker is coming to find
you in %A%seconds%%N seconds!'
lobbyArenaStartedSeekers: "%TAG%NThe arena has been started! You can start seeking in %A%seconds%%N seconds!"
inGameSeekerChosen: '%TAG%NPlayer %A%seeker%%N has been chosen as seeker!'
inGameBlock: '%TAG%NYou''re disguised as a(n) ''%A%block%%N'' block.'
inGameArenaEnd: '%TAG%NThe arena will end in %A%1%%N second(s)!'
@ -42,7 +43,7 @@ normal:
inGameGivenSword: '%TAG%NYou were given a sword!'
inGameHiderDied: '%TAG%NHider %A%%playerName%%%N was killed by %A%killer%%N!'
inGameHidersLeft: '%NHider(s) left: %A%left%%N'
inGameSeekerDied: '%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%secs%%N
inGameSeekerDied: '%TAG%NSeeker %A%%playerName%%%N died and will respawn in %A%seconds%%N
seconds!'
winSeekers: '%TAG%NThe %ASEEKERS%N have won!'
winHiders: '%TAG%NThe %AHIDERS%N have won!'