Cleans and moves a lot of code
This commit is contained in:
parent
b66c63f698
commit
4480e0994f
@ -4,7 +4,6 @@ import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import net.knarcraft.blockhunt.arena.ArenaState;
|
||||
import net.knarcraft.blockhunt.config.MessageKey;
|
||||
import net.knarcraft.blockhunt.listener.OnBlockBreakEvent;
|
||||
@ -23,15 +22,18 @@ 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.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import net.knarcraft.blockhunt.util.PlayerHelper;
|
||||
import net.knarcraft.blockhunt.util.ScoreboardHelper;
|
||||
import net.knarcraft.blockhunt.util.SignsHelper;
|
||||
import net.knarcraft.blockhunt.util.VisibilityHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -98,7 +100,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
ArenaHandler.loadArenas();
|
||||
ArenaHelper.loadArenas();
|
||||
|
||||
MessageHelper.sendMessage(null, MessageKey.LOG_ENABLED_PLUGIN, "name-" +
|
||||
BlockHunt.pluginDescriptionFile.getName(), "version-" + BlockHunt.pluginDescriptionFile.getVersion(),
|
||||
@ -112,7 +114,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
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);
|
||||
ArenaHelper.stopArena(arena, cause, MessageKey.WARNING_ARENA_STOPPED);
|
||||
}
|
||||
|
||||
MessageHelper.sendMessage(null, MessageKey.LOG_DISABLED_PLUGIN, "name-" +
|
||||
@ -145,7 +147,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
if (arena.playersInArena.size() >= arena.minPlayers) {
|
||||
arena.gameState = ArenaState.STARTING;
|
||||
arena.timer = arena.timeInLobbyUntilStart;
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" +
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" +
|
||||
arena.timeInLobbyUntilStart);
|
||||
}
|
||||
} else if (arena.gameState == ArenaState.STARTING) {
|
||||
@ -162,9 +164,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
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());
|
||||
PlayerHelper.teleport(player, arena.arenaLocations.getHidersWarp());
|
||||
MemoryStorage.seekerTime.remove(player);
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED,
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_SPAWNED,
|
||||
"%playerName%-" + player.getName());
|
||||
}
|
||||
}
|
||||
@ -174,16 +176,17 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
updateInGameArena(arena);
|
||||
}
|
||||
|
||||
for (Player pl : arena.playersInArena) {
|
||||
pl.setLevel(arena.timer);
|
||||
if (arena.seekers.contains(pl)) {
|
||||
pl.setGameMode(GameMode.SURVIVAL);
|
||||
// Display countdown as the player's XP level
|
||||
for (Player player : arena.playersInArena) {
|
||||
player.setLevel(arena.timer);
|
||||
if (arena.seekers.contains(player)) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
} else {
|
||||
pl.setGameMode(GameMode.ADVENTURE);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
SignsHandler.updateSigns(); //TODO Only do this when needed (game-state change or player count change)
|
||||
SignsHelper.updateSigns(); //TODO Only do this when needed (game-state change or player count change)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,7 +200,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
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);
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
|
||||
} else if (arena.timer <= 5) {
|
||||
// Count down from 5 seconds
|
||||
World world = null;
|
||||
@ -210,7 +213,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
world.playSound(arena.arenaLocations.getLobbyWarp(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,
|
||||
pitch);
|
||||
}
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_LOBBY_ARENA_IS_STARTING, "1-" + arena.timer);
|
||||
}
|
||||
} else {
|
||||
startArena(arena);
|
||||
@ -267,7 +270,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
DisguiseAPI.disguiseToAll(arenaPlayer, disguise);
|
||||
|
||||
// Teleport to the hiders warp
|
||||
PlayerHandler.teleport(arenaPlayer, arena.arenaLocations.getHidersWarp());
|
||||
PlayerHelper.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);
|
||||
@ -330,9 +333,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
* @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());
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + player.getName());
|
||||
arena.seekers.add(player);
|
||||
PlayerHandler.teleport(player, arena.arenaLocations.getSeekersWarp());
|
||||
PlayerHelper.teleport(player, arena.arenaLocations.getSeekersWarp());
|
||||
player.getInventory().clear();
|
||||
player.setWalkSpeed(0.3F);
|
||||
MemoryStorage.seekerTime.put(player, arena.waitingTimeSeeker);
|
||||
@ -373,7 +376,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
// If the game ends, trigger the hiders' win
|
||||
if (arena.timer <= 0) {
|
||||
ArenaHandler.hidersWin(arena);
|
||||
ArenaHelper.hidersWin(arena);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -397,12 +400,12 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
remainingBlocks.add(uppercaseAllFirst(block.replace("_", " ")));
|
||||
}
|
||||
String blocklist = String.join(", ", remainingBlocks);
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_BLOCKS_LEFT, "1-" + blocklist);
|
||||
ArenaHelper.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);
|
||||
ArenaHelper.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) {
|
||||
@ -417,7 +420,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
for (Player player : arena.hiders) {
|
||||
updateHiddenState(player);
|
||||
}
|
||||
ScoreboardHandler.updateScoreboard(arena); // TODO Only do this when needed (player added/removed)
|
||||
ScoreboardHelper.updateScoreboard(arena); // TODO Only do this when needed (player added/removed)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -447,74 +450,15 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
// 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);
|
||||
}
|
||||
VisibilityHelper.makePlayerSolid(player, inventoryBlock);
|
||||
}
|
||||
} else {
|
||||
// The player moved. Un-hide and reset the hide timer
|
||||
inventoryBlock.setAmount(5);
|
||||
if (!DisguiseAPI.isDisguised(player)) {
|
||||
SolidBlockHandler.makePlayerUnsolid(player);
|
||||
VisibilityHelper.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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.manager.Command;
|
||||
import net.knarcraft.blockhunt.manager.ConfigManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -51,8 +52,9 @@ public class MemoryStorage {
|
||||
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, Material> hiddenLocationMaterial = new HashMap<>();
|
||||
|
||||
public static final Map<Player, Location> teleportLocation = new HashMap<>();
|
||||
public static final Map<Player, Arena> playerArena = new HashMap<>();
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,21 @@ import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A record storing a player's data before they entered an arena
|
||||
*
|
||||
* @param playerLocation <p>The location the player was at before joining the arena</p>
|
||||
* @param playerGameMode <p>The game mode the player was in</p>
|
||||
* @param playerInventory <p>The player's earlier inventory</p>
|
||||
* @param playerArmor <p>The player's earlier equipped armor</p>
|
||||
* @param playerEXP <p>The player's earlier exp amount</p>
|
||||
* @param playerEXPLevels <p>The player's earlier exp level</p>
|
||||
* @param playerMaxHealth <p>The player's previous max health</p>
|
||||
* @param playerHealth <p>The player's previous health</p>
|
||||
* @param playerFood <p>The player's previous food amount</p>
|
||||
* @param playerPotionEffects <p>The player's previous potion effects</p>
|
||||
* @param playerFlying <p>The player's previous flying state</p>
|
||||
*/
|
||||
public record PlayerArenaData(Location playerLocation, GameMode playerGameMode, ItemStack[] playerInventory,
|
||||
ItemStack[] playerArmor, Float playerEXP, Integer playerEXPLevels, Double playerMaxHealth,
|
||||
Double playerHealth, Integer playerFood, Collection<PotionEffect> playerPotionEffects,
|
||||
|
@ -1,67 +0,0 @@
|
||||
package net.knarcraft.blockhunt;
|
||||
|
||||
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.util.MessageHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SolidBlockHandler {
|
||||
|
||||
public static void makePlayerUnsolid(Player player) {
|
||||
ItemStack block = player.getInventory().getItem(8);
|
||||
if (block == null) {
|
||||
player.sendMessage(ChatColor.RED + "Unable to hide you because your inventory block is missing!");
|
||||
BlockHunt.plugin.getLogger().log(Level.SEVERE, player.getName() + " could not be hidden because " +
|
||||
"their inventory block was missing!");
|
||||
return;
|
||||
}
|
||||
|
||||
Block pBlock = player.getLocation().getBlock();
|
||||
|
||||
if (MemoryStorage.hiddenLocation.get(player) != null) {
|
||||
pBlock = MemoryStorage.hiddenLocation.get(player).getBlock();
|
||||
}
|
||||
|
||||
block.setAmount(5);
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if (pl.equals(player)) {
|
||||
continue;
|
||||
}
|
||||
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));
|
||||
}
|
||||
} else {
|
||||
pl.sendBlockChange(pBlock.getLocation(), Bukkit.createBlockData(Material.AIR));
|
||||
}
|
||||
|
||||
MemoryStorage.hiddenLocationWater.remove(player);
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_BAT_HURT, 1, 1);
|
||||
block.removeEnchantment(Enchantment.DURABILITY);
|
||||
|
||||
for (Player playerShow : Bukkit.getOnlinePlayers()) {
|
||||
playerShow.showPlayer(BlockHunt.plugin, player);
|
||||
}
|
||||
|
||||
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
|
||||
DisguiseAPI.disguiseToAll(player, disguise);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_IN_GAME_NO_MORE_SOLID);
|
||||
}
|
||||
|
||||
}
|
@ -1,469 +0,0 @@
|
||||
package net.knarcraft.blockhunt.arena;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.PlayerArenaData;
|
||||
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.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.PermissionsManager;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ArenaHandler {
|
||||
|
||||
public static void loadArenas() {
|
||||
MemoryStorage.arenaMap.clear();
|
||||
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()) {
|
||||
ScoreboardHandler.createScoreboard(arena);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
MessageHelper.broadcastMessage(arena.playersInArena, message, 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 alreadyJoined = false;
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena != null && arena.playersInArena.contains(player)) {
|
||||
alreadyJoined = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (alreadyJoined) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_ALREADY_JOINED);
|
||||
return;
|
||||
}
|
||||
|
||||
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
|
||||
if (arena != null) {
|
||||
if (arena.disguiseBlocks.isEmpty()) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_NO_BLOCKS_SET);
|
||||
} else {
|
||||
boolean inventoryEmpty = true;
|
||||
for (ItemStack inventoryItem : player.getInventory()) {
|
||||
if (inventoryItem != null && inventoryItem.getType() != Material.AIR) {
|
||||
inventoryEmpty = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack inventoryItem : player.getInventory().getArmorContents()) {
|
||||
if (inventoryItem != null && inventoryItem.getType() != Material.AIR) {
|
||||
inventoryEmpty = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((Boolean) MemoryStorage.config.get(ConfigKey.REQUIRE_INVENTORY_CLEAR_ON_JOIN) && !inventoryEmpty) {
|
||||
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.getExitWarp() != null) {
|
||||
if (!locations.getLobbyWarp().equals(zero) && !locations.getHidersWarp().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)) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_FULL);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean canWarp = PlayerHandler.teleport(player, locations.getLobbyWarp());
|
||||
if (!canWarp) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockHunt.plugin.getLogger().log(Level.INFO, player.getName() + " has joined " + arenaName);
|
||||
arena.playersInArena.add(player);
|
||||
JoinArenaEvent event = new JoinArenaEvent(player, arena);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
PlayerArenaData pad = new PlayerArenaData(player.getLocation(), player.getGameMode(), player.getInventory().getContents(), player
|
||||
.getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), player.getHealth(), player.getFoodLevel(),
|
||||
player.getActivePotionEffects(), player.getAllowFlight());
|
||||
|
||||
MemoryStorage.playerData.put(player, pad);
|
||||
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
for (PotionEffect pe : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(pe.getType());
|
||||
}
|
||||
player.setFoodLevel(20);
|
||||
player.setHealth(20);
|
||||
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
|
||||
player.setLevel(arena.timer);
|
||||
player.setExp(0);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setHelmet(new ItemStack(Material.AIR));
|
||||
player.getInventory().setChestplate(new ItemStack(Material.AIR));
|
||||
player.getInventory().setLeggings(new ItemStack(Material.AIR));
|
||||
player.getInventory().setBoots(new ItemStack(Material.AIR));
|
||||
player.setFlying(false);
|
||||
player.setAllowFlight(false);
|
||||
player.setWalkSpeed(0.2F);
|
||||
|
||||
// Fix for client not showing players after
|
||||
// they join
|
||||
for (Player otherPlayer : arena.playersInArena) {
|
||||
if (otherPlayer.canSee(player)) {
|
||||
otherPlayer.showPlayer(BlockHunt.plugin, player); // Make
|
||||
}
|
||||
// new
|
||||
// player
|
||||
// visible
|
||||
// to
|
||||
// others
|
||||
if (player.canSee(otherPlayer)) {
|
||||
player.showPlayer(BlockHunt.plugin, otherPlayer); // Make
|
||||
}
|
||||
// other
|
||||
// players
|
||||
// visible
|
||||
// to
|
||||
// new
|
||||
// player
|
||||
}
|
||||
|
||||
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)) {
|
||||
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(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(MessageHelper.replaceAll(lore));
|
||||
}
|
||||
shopBlockChooser_IM.setLore(loreStrings2);
|
||||
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
|
||||
|
||||
player.getInventory().addItem(shopBlockChooser);
|
||||
}
|
||||
}
|
||||
|
||||
if ((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED)) {
|
||||
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(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(MessageHelper.replaceAll(lore));
|
||||
}
|
||||
|
||||
shopBlockHuntPass_IM.setLore(loreStrings2);
|
||||
shopBlockHuntPass.setItemMeta(shopBlockHuntPass_IM);
|
||||
shopBlockHuntPass.setAmount(MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass"));
|
||||
|
||||
player.getInventory().addItem(shopBlockHuntPass);
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_JOIN_JOINED_ARENA, "%playerName%-" + player.getName(),
|
||||
"1-" + arena.playersInArena.size(), "2-" + arena.maxPlayers);
|
||||
if (arena.playersInArena.size() < arena.minPlayers) {
|
||||
sendMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_ARENA_IN_GAME);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
|
||||
}
|
||||
|
||||
SignsHandler.updateSigns();
|
||||
}
|
||||
|
||||
public static void playerLeaveArena(Player player, boolean message, boolean cleanup) {
|
||||
|
||||
Arena arena = null;
|
||||
for (Arena arena2 : MemoryStorage.arenaMap.values()) {
|
||||
if (arena2.playersInArena != null) {
|
||||
if (arena2.playersInArena.contains(player)) {
|
||||
arena = arena2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (arena != null) {
|
||||
BlockHunt.plugin.getLogger().log(Level.INFO, player.getName() + " has left " + arena.arenaName);
|
||||
LeaveArenaEvent event = new LeaveArenaEvent(player, arena);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
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;
|
||||
|
||||
sendMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
|
||||
}
|
||||
|
||||
if (arena.playersInArena.size() <= 1 && arena.gameState == ArenaState.IN_GAME) {
|
||||
if (arena.seekers.size() >= arena.playersInArena.size()) {
|
||||
ArenaHandler.seekersWin(arena);
|
||||
} else {
|
||||
ArenaHandler.hidersWin(arena);
|
||||
}
|
||||
}
|
||||
|
||||
if (arena.seekers.size() >= arena.playersInArena.size()) {
|
||||
ArenaHandler.seekersWin(arena);
|
||||
}
|
||||
|
||||
if (arena.seekers.size() == 0 && arena.gameState == ArenaState.IN_GAME) {
|
||||
Player seeker = arena.playersInArena.get(MemoryStorage.random.nextInt(arena.playersInArena.size()));
|
||||
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);
|
||||
}
|
||||
seeker.getInventory().clear();
|
||||
arena.seekers.add(seeker);
|
||||
PlayerHandler.teleport(seeker, arena.arenaLocations.getSeekersWarp());
|
||||
MemoryStorage.seekerTime.put(seeker, arena.waitingTimeSeeker);
|
||||
seeker.setWalkSpeed(0.3F);
|
||||
|
||||
// Fix for client not showing players after they join
|
||||
for (Player otherPlayer : arena.playersInArena) {
|
||||
if (otherPlayer.canSee(player)) {
|
||||
otherPlayer.showPlayer(BlockHunt.plugin, player); // Make new player
|
||||
}
|
||||
// visible to others
|
||||
if (player.canSee(otherPlayer)) {
|
||||
player.showPlayer(BlockHunt.plugin, otherPlayer); // Make other
|
||||
}
|
||||
// players visible
|
||||
// to new player
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayerArenaData pad = new PlayerArenaData(null, null, null, null, null, null, null, null, null, null, false);
|
||||
|
||||
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.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.getExitWarp());
|
||||
player.setGameMode(pad.playerGameMode());
|
||||
player.setAllowFlight(pad.playerFlying());
|
||||
if (player.getAllowFlight()) {
|
||||
player.setFlying(true);
|
||||
}
|
||||
player.setWalkSpeed(0.2F);
|
||||
|
||||
MemoryStorage.playerData.remove(player);
|
||||
MemoryStorage.chosenBlock.remove(player);
|
||||
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
pl.showPlayer(BlockHunt.plugin, 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
}
|
||||
|
||||
ScoreboardHandler.removeScoreboard(player);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_LEAVE_YOU_LEFT);
|
||||
if (message) {
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_LEAVE_LEFT_ARENA, "%playerName%-" + player.getName(), "1-" + arena.playersInArena.size(), "2-"
|
||||
+ arena.maxPlayers);
|
||||
}
|
||||
} else {
|
||||
if (message) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_LEAVE_NOT_IN_ARENA);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SignsHandler.updateSigns();
|
||||
}
|
||||
|
||||
public static void seekersWin(Arena arena) {
|
||||
String cause = "[BlockHunt] Seekers have won " + arena.arenaName;
|
||||
|
||||
List<Player> winners = new ArrayList<>();
|
||||
List<Player> losers = new ArrayList<>();
|
||||
|
||||
for (Player player : arena.playersInArena) {
|
||||
|
||||
if (arena.seekers.contains(player)) {
|
||||
|
||||
winners.add(player);
|
||||
|
||||
if (arena.seekersWinCommands != null) {
|
||||
for (String command : arena.seekersWinCommands) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getDisplayName()));
|
||||
}
|
||||
|
||||
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
|
||||
MemoryStorage.shop.save();
|
||||
}
|
||||
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens + arena.seekersTokenWin);
|
||||
MemoryStorage.shop.save();
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.seekersTokenWin);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
losers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
EndArenaEvent event = new EndArenaEvent(winners, losers, arena);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
stopArena(arena, cause, MessageKey.normal_winSeekers);
|
||||
}
|
||||
|
||||
public static void hidersWin(Arena arena) {
|
||||
String cause = "[BlockHunt] Hiders have won " + arena.arenaName;
|
||||
|
||||
List<Player> winners = new ArrayList<>();
|
||||
List<Player> losers = new ArrayList<>();
|
||||
|
||||
for (Player player : arena.playersInArena) {
|
||||
|
||||
if (arena.seekers.contains(player)) {
|
||||
losers.add(player);
|
||||
} else {
|
||||
|
||||
winners.add(player);
|
||||
|
||||
if (arena.hidersWinCommands != null) {
|
||||
for (String command : arena.hidersWinCommands) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getDisplayName()));
|
||||
}
|
||||
|
||||
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
|
||||
MemoryStorage.shop.save();
|
||||
}
|
||||
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", playerTokens + arena.hidersTokenWin);
|
||||
MemoryStorage.shop.save();
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.hidersTokenWin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EndArenaEvent event = new EndArenaEvent(winners, losers, arena);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
stopArena(arena, cause, MessageKey.NORMAL_WIN_HIDERS);
|
||||
}
|
||||
|
||||
public static void stopArena(Arena arena, String cause, MessageKey message) {
|
||||
BlockHunt.plugin.getLogger().log(Level.INFO, cause);
|
||||
ArenaHandler.sendMessage(arena, message);
|
||||
arena.seekers.clear();
|
||||
arena.hiders.clear();
|
||||
|
||||
for (Player player : arena.playersInArena) {
|
||||
playerLeaveArena(player, false, false);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
|
||||
}
|
||||
|
||||
arena.gameState = ArenaState.WAITING;
|
||||
arena.timer = 0;
|
||||
arena.playersInArena.clear();
|
||||
}
|
||||
|
||||
public static boolean noPlayersInArenas() {
|
||||
// Check if there are any players in any arena (quick way to early exit for event handlers)
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.size() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package net.knarcraft.blockhunt.command;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.ScoreboardHandler;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaState;
|
||||
import net.knarcraft.blockhunt.config.MessageKey;
|
||||
import net.knarcraft.blockhunt.manager.CommandManager;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import net.knarcraft.blockhunt.util.ScoreboardHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -40,7 +40,7 @@ public class CreateCommand extends DefaultCommand {
|
||||
MemoryStorage.signs.load();
|
||||
|
||||
MemoryStorage.arenaMap.put(args[1].toLowerCase(), arena);
|
||||
ScoreboardHandler.createScoreboard(arena);
|
||||
ScoreboardHelper.createScoreboard(arena);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_CREATE_CREATED_ARENA, "name-" + args[1]);
|
||||
} else {
|
||||
|
@ -1,8 +1,8 @@
|
||||
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.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -15,7 +15,7 @@ public class JoinCommand extends DefaultCommand {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_NOT_ENOUGH_ARGUMENTS, "syntax-" +
|
||||
CommandManager.getJoinCommand().usage());
|
||||
} else {
|
||||
ArenaHandler.playerJoinArena(player, args[1]);
|
||||
ArenaHelper.playerJoinArena(player, args[1]);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.blockhunt.command;
|
||||
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import net.knarcraft.blockhunt.config.MessageKey;
|
||||
import net.knarcraft.blockhunt.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -10,7 +10,7 @@ public class LeaveCommand extends DefaultCommand {
|
||||
@Override
|
||||
public boolean execute(Player player, String[] args) {
|
||||
if (player != null) {
|
||||
ArenaHandler.playerLeaveArena(player, true, true);
|
||||
ArenaHelper.playerLeaveArena(player, true, true);
|
||||
} else {
|
||||
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package net.knarcraft.blockhunt.command;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import net.knarcraft.blockhunt.config.MessageKey;
|
||||
import net.knarcraft.blockhunt.manager.ConfigManager;
|
||||
import net.knarcraft.blockhunt.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -22,10 +22,10 @@ public class ReloadCommand extends DefaultCommand {
|
||||
MemoryStorage.shop.load();
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
String cause = "[BlockHunt] Arena " + arena.arenaName + " has been stopped";
|
||||
ArenaHandler.stopArena(arena, cause, MessageKey.WARNING_ARENA_STOPPED);
|
||||
ArenaHelper.stopArena(arena, cause, MessageKey.WARNING_ARENA_STOPPED);
|
||||
}
|
||||
|
||||
ArenaHandler.loadArenas();
|
||||
ArenaHelper.loadArenas();
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_RELOADED_CONFIGS);
|
||||
return true;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class RemoveCommand extends DefaultCommand {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + args[1]);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_ONLY_IN_GAME);
|
||||
MessageHelper.sendMessage(null, MessageKey.ERROR_ONLY_IN_GAME);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
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.util.InventoryHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -16,7 +16,7 @@ public class SetCommand extends DefaultCommand {
|
||||
CommandManager.getSetCommand().usage());
|
||||
} else {
|
||||
String arenaName = args[1];
|
||||
InventoryHandler.openPanel(player, arenaName);
|
||||
InventoryHelper.openPanel(player, arenaName);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_ONLY_IN_GAME);
|
||||
|
@ -2,10 +2,10 @@ package net.knarcraft.blockhunt.command;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
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.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -58,7 +58,7 @@ public class SetWarpCommand extends DefaultCommand {
|
||||
public void save(Arena arena) {
|
||||
MemoryStorage.arenas.getFileConfiguration().set(arena.arenaName, arena);
|
||||
MemoryStorage.arenas.save();
|
||||
ArenaHandler.loadArenas();
|
||||
ArenaHelper.loadArenas();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package net.knarcraft.blockhunt.command;
|
||||
|
||||
import net.knarcraft.blockhunt.InventoryHandler;
|
||||
import net.knarcraft.blockhunt.util.InventoryHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ShopCommand extends DefaultCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String[] args) {
|
||||
InventoryHandler.openShop(player);
|
||||
InventoryHelper.openShop(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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.util.MessageHelper;
|
||||
import net.knarcraft.blockhunt.util.TokensHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -37,32 +37,37 @@ public class TokensCommand extends DefaultCommand {
|
||||
}
|
||||
|
||||
if (option.equalsIgnoreCase("set")) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(tokenPlayer.getName() + ".tokens", amount);
|
||||
MemoryStorage.shop.save();
|
||||
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);
|
||||
updateTokens(player, tokenPlayer, name, amount, "Set", "to");
|
||||
} else if (option.equalsIgnoreCase("add")) {
|
||||
int tokens = 0;
|
||||
if (MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens") != 0) {
|
||||
tokens = MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens");
|
||||
}
|
||||
MemoryStorage.shop.getFileConfiguration().set(tokenPlayer.getName() + ".tokens", tokens + amount);
|
||||
MemoryStorage.shop.save();
|
||||
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);
|
||||
updateTokens(player, tokenPlayer, name, TokensHelper.getTokens(tokenPlayer) + amount,
|
||||
"Added", "to");
|
||||
} else if (option.equalsIgnoreCase("take")) {
|
||||
int tokens = 0;
|
||||
if (MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens") != 0) {
|
||||
tokens = MemoryStorage.shop.getFileConfiguration().getInt(tokenPlayer.getName() + ".tokens");
|
||||
}
|
||||
MemoryStorage.shop.getFileConfiguration().set(tokenPlayer.getName() + ".tokens", tokens - amount);
|
||||
MemoryStorage.shop.save();
|
||||
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);
|
||||
updateTokens(player, tokenPlayer, name, TokensHelper.getTokens(tokenPlayer) - amount,
|
||||
"Took", "from");
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_TOKENS_UNKNOWN_SETTING, "option-" + option);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates tokens for a player
|
||||
*
|
||||
* @param player <p>The player that's changing tokens</p>
|
||||
* @param tokenPlayer <p>The player whose tokens are changed</p>
|
||||
* @param name <p>The name of the player that's changing tokens</p>
|
||||
* @param newTokens <p>The amount of tokens to set for the player</p>
|
||||
* @param action <p>A description of the action performed</p>
|
||||
* @param pronoun <p>The pronoun to use for the action. Ex: if the action is "Added", the correct pronoun is "to"</p>
|
||||
*/
|
||||
private void updateTokens(Player player, Player tokenPlayer, String name, int newTokens, String action,
|
||||
String pronoun) {
|
||||
TokensHelper.setTokens(player, newTokens);
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_TOKENS_CHANGED, "option-" + action,
|
||||
"%playerName%-" + tokenPlayer.getName(), "option2-" + pronoun, "amount-" + newTokens);
|
||||
MessageHelper.sendMessage(tokenPlayer, MessageKey.NORMAL_TOKENS_CHANGED_PERSON, "option-" +
|
||||
action.toLowerCase(), "%playerName%-" + name, "option2-" + pronoun, "amount-" + newTokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public enum MessageKey implements Key {
|
||||
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%seconds%%N" +
|
||||
"seconds!", "normal.inGameSeekerDied"),
|
||||
normal_winSeekers("%TAG%NThe %ASEEKERS%N have won!", "normal.winSeekers"),
|
||||
NORMAL_WIN_SEEKERS("%TAG%NThe %ASEEKERS%N have won!", "normal.winSeekers"),
|
||||
NORMAL_WIN_HIDERS("%TAG%NThe %AHIDERS%N have won!", "normal.winHiders"),
|
||||
NORMAL_SET_WARP_WARP_SET("%TAG%NSet warp '%A%warp%%N' to your location!", "normal.setWarpWarpSet"),
|
||||
NORMAL_ADDED_TOKEN("%TAG%A%amount%%N tokens were added to your account!", "normal.addedToken"),
|
||||
|
@ -1,9 +1,6 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -13,16 +10,8 @@ public class OnBlockBreakEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlockBreakEvent(BlockBreakEvent event) {
|
||||
// Early exit if no one is in any arena
|
||||
if (ArenaHandler.noPlayersInArenas()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
if (MemoryStorage.playerArena.get(event.getPlayer()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -13,16 +10,8 @@ public class OnBlockPlaceEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlockPlaceEvent(BlockPlaceEvent event) {
|
||||
// Early exit if no one is in any arena
|
||||
if (ArenaHandler.noPlayersInArenas()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
if (MemoryStorage.playerArena.get(event.getPlayer()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,15 @@ package net.knarcraft.blockhunt.listener;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.PlayerHandler;
|
||||
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.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import net.knarcraft.blockhunt.util.PlayerHelper;
|
||||
import net.knarcraft.blockhunt.util.StringHelper;
|
||||
import net.knarcraft.blockhunt.util.TokensHelper;
|
||||
import net.knarcraft.blockhunt.util.VisibilityHelper;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Arrow;
|
||||
@ -35,7 +37,7 @@ public class OnEntityDamageByEntityEvent implements Listener {
|
||||
}
|
||||
|
||||
// Early exit if no one is in any arena
|
||||
if (ArenaHandler.noPlayersInArenas()) {
|
||||
if (ArenaHelper.noPlayersInArenas()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -58,13 +60,17 @@ public class OnEntityDamageByEntityEvent implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
Arena arena = MemoryStorage.playerArena.get(player);
|
||||
if (arena == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arena.gameState == ArenaState.WAITING || arena.gameState == ArenaState.STARTING) {
|
||||
// Always cancel damage when players are waiting
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
|
||||
// Seeker receiving damage
|
||||
if (arena.seekers.contains(player)) {
|
||||
if (arena.seekers.contains(damageDealer)) {
|
||||
@ -91,44 +97,77 @@ public class OnEntityDamageByEntityEvent implements Listener {
|
||||
// The damage is allowed, so lets handle it!
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT, 1, 1);
|
||||
|
||||
if (event.getDamage() >= player.getHealth()) {
|
||||
if (event.getDamage() < player.getHealth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.setHealth(20);
|
||||
event.setCancelled(true);
|
||||
|
||||
// try moving everything to the next tick to prevent "Removing entity while ticking" errors
|
||||
Player finalDamager = damageDealer;
|
||||
Player finalDamageDealer = damageDealer;
|
||||
player.getServer().getScheduler().runTask(BlockHunt.plugin, () -> {
|
||||
killPlayer(arena, player, finalDamageDealer);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* "Kills" a player in an arena
|
||||
*
|
||||
* @param arena <p>The arena the player is in</p>
|
||||
* @param player <p>The player to "kill"</p>
|
||||
* @param finalDamageDealer <p>The player that caused the last bit of damage</p>
|
||||
*/
|
||||
private void killPlayer(Arena arena, Player player, Player finalDamageDealer) {
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
MemoryStorage.playerBlock.remove(player);
|
||||
|
||||
if (!arena.seekers.contains(player)) {
|
||||
if (MemoryStorage.shop.getFileConfiguration().get(finalDamager.getName() + ".tokens") == null) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(finalDamager.getName() + ".tokens", 0);
|
||||
MemoryStorage.shop.save();
|
||||
if (arena.hiders.contains(player)) {
|
||||
killHider(arena, player, finalDamageDealer);
|
||||
}
|
||||
int damagerTokens = MemoryStorage.shop.getFileConfiguration().getInt(finalDamager.getName() + ".tokens");
|
||||
MemoryStorage.shop.getFileConfiguration().set(finalDamager.getName() + ".tokens", damagerTokens + arena.killTokens);
|
||||
MemoryStorage.shop.save();
|
||||
|
||||
MessageHelper.sendMessage(finalDamager, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.killTokens);
|
||||
player.getInventory().clear();
|
||||
|
||||
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
|
||||
MemoryStorage.shop.save();
|
||||
if (arena.seekers.size() >= arena.playersInArena.size()) {
|
||||
ArenaHelper.seekersWin(arena);
|
||||
} else {
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
MemoryStorage.seekerTime.put(player, arena.waitingTimeSeeker);
|
||||
PlayerHelper.teleport(player, arena.arenaLocations.getSeekersWarp());
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setWalkSpeed(0.3F);
|
||||
|
||||
// Fix for client not showing players after they join
|
||||
VisibilityHelper.makePlayerVisible(arena, player);
|
||||
}
|
||||
}
|
||||
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.getFileConfiguration().set(player.getName() + ".tokens", playerTokens + (int) addingTokens);
|
||||
MemoryStorage.shop.save();
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + (int) addingTokens);
|
||||
/**
|
||||
* "Kills" a hider in an arena
|
||||
*
|
||||
* @param arena <p>The arena the player is in</p>
|
||||
* @param player <p>The hider to "kill"</p>
|
||||
* @param finalDamageDealer <p>The player that caused the last bit of damage</p>
|
||||
*/
|
||||
private void killHider(Arena arena, Player player, Player finalDamageDealer) {
|
||||
int damageDealerTokens = TokensHelper.getTokens(finalDamageDealer);
|
||||
TokensHelper.setTokens(finalDamageDealer, damageDealerTokens + arena.killTokens);
|
||||
|
||||
MessageHelper.sendMessage(finalDamageDealer, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + arena.killTokens);
|
||||
|
||||
int playerTokens = TokensHelper.getTokens(player);
|
||||
float addedTokens = ((float) arena.hidersTokenWin - (((float) arena.timer / (float) arena.gameTime) *
|
||||
(float) arena.hidersTokenWin));
|
||||
TokensHelper.setTokens(player, playerTokens + (int) addedTokens);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + (int) addedTokens);
|
||||
|
||||
arena.seekers.add(player);
|
||||
player.setWalkSpeed(0.3F);
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDER_DIED,
|
||||
"%playerName%-" + player.getDisplayName(), "killer-" + finalDamager.getDisplayName());
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDER_DIED,
|
||||
"%playerName%-" + player.getDisplayName(), "killer-" + finalDamageDealer.getDisplayName());
|
||||
|
||||
int hiderCount = (arena.playersInArena.size() - arena.seekers.size());
|
||||
int hiderCount = arena.hiders.size();
|
||||
if ((hiderCount <= 3) && (hiderCount > 0)) {
|
||||
List<String> hiders = new ArrayList<>();
|
||||
for (Player p : arena.playersInArena) {
|
||||
@ -138,40 +177,13 @@ public class OnEntityDamageByEntityEvent implements Listener {
|
||||
}
|
||||
Collections.sort(hiders);
|
||||
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT,
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT,
|
||||
"left-" + String.join(", ",
|
||||
StringHelper.toString(hiders.toArray())));
|
||||
} else {
|
||||
ArenaHandler.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT,
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_IN_GAME_HIDERS_LEFT,
|
||||
"left-" + hiderCount);
|
||||
}
|
||||
}
|
||||
|
||||
player.getInventory().clear();
|
||||
|
||||
if (arena.seekers.size() >= arena.playersInArena.size()) {
|
||||
ArenaHandler.seekersWin(arena);
|
||||
} else {
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
MemoryStorage.seekerTime.put(player, arena.waitingTimeSeeker);
|
||||
PlayerHandler.teleport(player, arena.arenaLocations.getSeekersWarp());
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setWalkSpeed(0.3F);
|
||||
|
||||
// Fix for client not showing players after they join
|
||||
for (Player otherplayer : arena.playersInArena) {
|
||||
if (otherplayer.canSee(player)) {
|
||||
otherplayer.showPlayer(BlockHunt.plugin, player); // Make new player visible to others
|
||||
}
|
||||
if (player.canSee(otherplayer)) {
|
||||
player.showPlayer(BlockHunt.plugin, otherplayer); // Make other players visible to new player
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,50 +2,36 @@ package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
public class OnEntityDamageEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onEntityDamageEvent(EntityDamageEvent event) {
|
||||
// Early exit if no one is in any arena
|
||||
if (ArenaHandler.noPlayersInArenas()) {
|
||||
if (!(event.getEntity() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity ent = event.getEntity();
|
||||
if (ent instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
DamageCause cause = event.getCause();
|
||||
switch (cause) {
|
||||
Arena arena = MemoryStorage.playerArena.get(player);
|
||||
if (arena == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.getCause()) {
|
||||
case ENTITY_ATTACK:
|
||||
case PROJECTILE:
|
||||
// Do nothing about damage from an entity
|
||||
// Any entity damage that makes it to here was already allowed by the EntityDamageByEntity event
|
||||
break;
|
||||
case FALL:
|
||||
// Should we prevent the fall damage?
|
||||
if (arena.seekers.contains(player)) {
|
||||
if (!arena.seekersTakeFallDamage) {
|
||||
// Prevent seeker fall damage (if configured)
|
||||
// Prevent seeker/hider fall damage (if configured)
|
||||
if ((arena.seekers.contains(player) && !arena.seekersTakeFallDamage) ||
|
||||
(arena.hiders.contains(player) && !arena.hidersTakeFallDamage)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!arena.hidersTakeFallDamage) {
|
||||
// Prevent hider fall damage (if configured)
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -53,9 +39,6 @@ public class OnEntityDamageEvent implements Listener {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -12,12 +11,12 @@ public class OnFoodLevelChangeEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onFoodLevelChangeEvent(FoodLevelChangeEvent event) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!(event.getEntity() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
if (MemoryStorage.playerArena.get(player) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.InventoryHandler;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
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.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.InventoryHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import net.knarcraft.blockhunt.util.StringHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -27,11 +27,9 @@ public class OnInventoryClickEvent implements Listener {
|
||||
public void onInventoryClickEvent(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
if (MemoryStorage.playerArena.get(player) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
InventoryView inventoryView = event.getView();
|
||||
@ -93,7 +91,7 @@ public class OnInventoryClickEvent implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
InventoryHandler.openShop(player);
|
||||
InventoryHelper.openShop(player);
|
||||
} 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) {
|
||||
@ -115,13 +113,12 @@ public class OnInventoryClickEvent implements Listener {
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
for (Player playerCheck : arena.playersInArena) {
|
||||
if (MemoryStorage.chosenSeeker.get(playerCheck) != null) {
|
||||
if (MemoryStorage.chosenSeeker.get(playerCheck)) {
|
||||
if (MemoryStorage.chosenSeeker.get(playerCheck) != null &&
|
||||
MemoryStorage.chosenSeeker.get(playerCheck)) {
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= arena.amountSeekersOnStart) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_SHOP_MAX_SEEKERS_REACHED);
|
||||
@ -208,11 +205,11 @@ public class OnInventoryClickEvent implements Listener {
|
||||
}
|
||||
|
||||
save(arena);
|
||||
InventoryHandler.openPanel(player, arena.arenaName);
|
||||
InventoryHelper.openPanel(player, arena.arenaName);
|
||||
|
||||
} else if (item.getType().equals(Material.BOOK)) {
|
||||
if (item.getItemMeta().getDisplayName().contains("disguiseBlocks")) {
|
||||
InventoryHandler.openDisguiseBlocks(arena, player);
|
||||
InventoryHelper.openDisguiseBlocks(arena, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,7 +218,7 @@ public class OnInventoryClickEvent implements Listener {
|
||||
public void save(Arena arena) {
|
||||
MemoryStorage.arenas.getFileConfiguration().set(arena.arenaName, arena);
|
||||
MemoryStorage.arenas.save();
|
||||
ArenaHandler.loadArenas();
|
||||
ArenaHelper.loadArenas();
|
||||
}
|
||||
|
||||
public static void upDownButton(Player player, ItemStack item, Arena arena, ArenaProperty at, int option, int max,
|
||||
|
@ -2,7 +2,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.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -52,6 +52,6 @@ public class OnInventoryCloseEvent implements Listener {
|
||||
public void save(Arena arena) {
|
||||
MemoryStorage.arenas.getFileConfiguration().set(arena.arenaName, arena);
|
||||
MemoryStorage.arenas.save();
|
||||
ArenaHandler.loadArenas();
|
||||
ArenaHelper.loadArenas();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -14,10 +13,8 @@ public class OnPlayerDropItemEvent implements Listener {
|
||||
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
if (MemoryStorage.playerArena.get(player) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.InventoryHandler;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.SignsHandler;
|
||||
import net.knarcraft.blockhunt.SolidBlockHandler;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
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.PermissionsManager;
|
||||
import net.knarcraft.blockhunt.util.ArenaHelper;
|
||||
import net.knarcraft.blockhunt.util.InventoryHelper;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import net.knarcraft.blockhunt.util.SignsHelper;
|
||||
import net.knarcraft.blockhunt.util.VisibilityHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -39,57 +39,79 @@ public class OnPlayerInteractEvent implements Listener {
|
||||
public void onPlayerInteractEvent(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
// Handle wand-usage
|
||||
if (PermissionsManager.hasPermission(player, Permission.CREATE, false)) {
|
||||
handleWandClick(event, player, block);
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null &&
|
||||
event.getClickedBlock().getState() instanceof Sign sign &&
|
||||
SignsHandler.isSign(event.getClickedBlock().getLocation())) {
|
||||
// Handle sign-clicking
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block != null &&
|
||||
block.getState() instanceof Sign sign &&
|
||||
SignsHelper.isSign(block.getLocation())) {
|
||||
handleSignClick(player, sign);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
if (event.getClickedBlock().getType() != Material.AIR) {
|
||||
if (event.getClickedBlock().getType().equals(Material.ENCHANTING_TABLE) || event.getClickedBlock().getType().equals(Material.CRAFTING_TABLE)
|
||||
|| event.getClickedBlock().getType().equals(Material.FURNACE) || event.getClickedBlock().getType().equals(Material.CHEST)
|
||||
|| event.getClickedBlock().getType().equals(Material.ANVIL) || event.getClickedBlock().getType().equals(Material.ENDER_CHEST)
|
||||
|| event.getClickedBlock().getType().equals(Material.JUKEBOX) || block.getRelative(event.getBlockFace()).getType().equals(Material.FIRE)) {
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
// Block container or fire clicking
|
||||
if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) &&
|
||||
block != null && !block.getType().isAir() &&
|
||||
(block.getType().isInteractable() ||
|
||||
block.getRelative(event.getBlockFace()).getType().equals(Material.FIRE))) {
|
||||
if (MemoryStorage.playerArena.get(player) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle seekers hitting solid hiders
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.seekers.contains(player)) {
|
||||
for (Player pl : arena.playersInArena) {
|
||||
if (MemoryStorage.hiddenLocation.get(pl) != null) {
|
||||
Block pLoc = event.getClickedBlock();
|
||||
Block moveLocBlock = MemoryStorage.hiddenLocation.get(pl).getBlock();
|
||||
if (moveLocBlock.getX() == pLoc.getX() && moveLocBlock.getY() == pLoc.getY() && moveLocBlock.getZ() == pLoc.getZ()) {
|
||||
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);
|
||||
}
|
||||
// TODO: Do this more efficiently and directly, for example by mapping location vector to player instead of
|
||||
// the other way around.
|
||||
Arena arena = MemoryStorage.playerArena.get(event.getPlayer());
|
||||
if (arena != null && arena.seekers.contains(player)) {
|
||||
for (Player arenaPlayer : arena.playersInArena) {
|
||||
// Check all hidden players
|
||||
if (MemoryStorage.hiddenLocation.get(arenaPlayer) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the player is hidden at the location hit
|
||||
Block moveLocBlock = MemoryStorage.hiddenLocation.get(arenaPlayer).getBlock();
|
||||
if (block == null || moveLocBlock.getX() != block.getX() || moveLocBlock.getY() != block.getY() ||
|
||||
moveLocBlock.getZ() != block.getZ()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make the hidden player no longer solid
|
||||
MemoryStorage.moveLocation.put(arenaPlayer, new Location(arenaPlayer.getWorld(), 0, 0, 0));
|
||||
arenaPlayer.getWorld().playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT, 1, 1);
|
||||
VisibilityHelper.makePlayerUnSolid(arenaPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player) && (arena.gameState.equals(ArenaState.WAITING) || arena.gameState.equals(ArenaState.STARTING))) {
|
||||
Arena arena = MemoryStorage.playerArena.get(player);
|
||||
if (arena == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!arena.gameState.equals(ArenaState.WAITING) && !arena.gameState.equals(ArenaState.STARTING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (item.getType() != Material.AIR) {
|
||||
if (item.getItemMeta().getDisplayName() != null) {
|
||||
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 (item.getType() == Material.AIR || item.getItemMeta() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
item.getItemMeta().getDisplayName();
|
||||
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));
|
||||
@ -99,27 +121,25 @@ public class OnPlayerInteractEvent implements Listener {
|
||||
player.openInventory(blockChooser);
|
||||
}
|
||||
|
||||
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(MessageHelper.replaceAll("&eSEEKER"));
|
||||
BlockHuntPassSEEKER.setItemMeta(BlockHuntPassIM);
|
||||
BlockHuntPass.setItem(1, BlockHuntPassSEEKER);
|
||||
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 blockHuntPassItemMeta = blockHuntPassSEEKER.getItemMeta();
|
||||
blockHuntPassItemMeta.setDisplayName(MessageHelper.replaceAll("&eSEEKER"));
|
||||
blockHuntPassSEEKER.setItemMeta(blockHuntPassItemMeta);
|
||||
blockHuntPass.setItem(1, blockHuntPassSEEKER);
|
||||
|
||||
ItemStack BlockHuntPassHIDER = new ItemStack(Material.RED_WOOL, 1);
|
||||
BlockHuntPassIM.setDisplayName(MessageHelper.replaceAll("&eHIDER"));
|
||||
BlockHuntPassHIDER.setItemMeta(BlockHuntPassIM);
|
||||
BlockHuntPass.setItem(7, BlockHuntPassHIDER);
|
||||
ItemStack blockHuntPassHider = new ItemStack(Material.RED_WOOL, 1);
|
||||
blockHuntPassItemMeta.setDisplayName(MessageHelper.replaceAll("&eHIDER"));
|
||||
blockHuntPassHider.setItemMeta(blockHuntPassItemMeta);
|
||||
blockHuntPass.setItem(7, blockHuntPassHider);
|
||||
|
||||
player.openInventory(BlockHuntPass);
|
||||
player.openInventory(blockHuntPass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleSignClick(Player player, Sign sign) {
|
||||
FileConfiguration fileConfiguration = MemoryStorage.config.getFileConfiguration();
|
||||
@ -127,19 +147,19 @@ public class OnPlayerInteractEvent implements Listener {
|
||||
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);
|
||||
ArenaHelper.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);
|
||||
InventoryHelper.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);
|
||||
ArenaHelper.playerJoinArena(player, arena.arenaName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.PlayerHandler;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import net.knarcraft.blockhunt.arena.ArenaLocations;
|
||||
import net.knarcraft.blockhunt.arena.ArenaState;
|
||||
import net.knarcraft.blockhunt.util.PlayerHelper;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
@ -22,47 +20,25 @@ public class OnPlayerMoveEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerMoveEvent(PlayerMoveEvent event) {
|
||||
// Early exit if no one is in any arena
|
||||
if (ArenaHandler.noPlayersInArenas()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
//TODO: Optimize this to runtime O(1)
|
||||
if (!arena.playersInArena.contains(player)) {
|
||||
continue;
|
||||
}
|
||||
Arena arena = MemoryStorage.playerArena.get(player);
|
||||
|
||||
if (arena.gameState != ArenaState.IN_GAME) {
|
||||
if (arena == null || arena.gameState != ArenaState.IN_GAME) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArenaLocations locations = arena.arenaLocations;
|
||||
// Store the location the player moved to for solid block mechanics
|
||||
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:" +
|
||||
((locations.getCorner1() != null) ? locations.getCorner1().toString() : " NULL") + " Pos2:" +
|
||||
((locations.getCorner2() != null) ? locations.getCorner2().toString() : " NULL"));
|
||||
BlockHunt.plugin.getLogger().info("Player has been returned to hiderswarp due to bad arena state");
|
||||
//event.setCancelled(true);
|
||||
Location loc = player.getLocation();
|
||||
player.playEffect(loc, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(loc, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
PlayerHandler.teleport(player, locations.getHidersWarp());
|
||||
return;
|
||||
}
|
||||
|
||||
// Force the player back in bounds if they are about to leave the arena
|
||||
ArenaLocations locations = arena.arenaLocations;
|
||||
Location maxLocation = getRelativeLocation(locations.getCorner1(), locations.getCorner2(), Math::max);
|
||||
Location minLocation = getRelativeLocation(locations.getCorner1(), locations.getCorner2(), Math::min);
|
||||
Location playerLocation = player.getLocation();
|
||||
if (!areIntersecting(playerLocation, minLocation, maxLocation)) {
|
||||
player.playEffect(playerLocation, Effect.ENDER_SIGNAL, null);
|
||||
player.playSound(playerLocation, Sound.ENTITY_GHAST_SHOOT, 1, 1);
|
||||
PlayerHandler.teleport(player, locations.getHidersWarp());
|
||||
}
|
||||
return;
|
||||
PlayerHelper.teleport(player, locations.getHidersWarp());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,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.util.ArenaHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -14,11 +13,8 @@ public class OnPlayerQuitEvent implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerQuitEvent(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
ArenaHandler.playerLeaveArena(player, true, true);
|
||||
}
|
||||
if (MemoryStorage.playerArena.get(player) != null) {
|
||||
ArenaHelper.playerLeaveArena(player, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,18 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
|
||||
public class OnPlayerSwapHandItemsEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) {
|
||||
// Early exit if no one is in any arena
|
||||
if (ArenaHandler.noPlayersInArenas()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.contains(player)) {
|
||||
if (MemoryStorage.playerArena.get(event.getPlayer()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package net.knarcraft.blockhunt.listener;
|
||||
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.SignsHandler;
|
||||
import net.knarcraft.blockhunt.config.Permission;
|
||||
import net.knarcraft.blockhunt.manager.PermissionsManager;
|
||||
import net.knarcraft.blockhunt.util.SignsHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -19,7 +19,7 @@ public class OnSignChangeEvent implements Listener {
|
||||
if (lines[0] != null) {
|
||||
if (lines[0].equalsIgnoreCase("[" + BlockHunt.getPluginDescriptionFile().getName() + "]")) {
|
||||
if (PermissionsManager.hasPermission(player, Permission.SIGN_CREATE, true)) {
|
||||
SignsHandler.createSign(event, lines, event.getBlock().getLocation());
|
||||
SignsHelper.createSign(event, lines, event.getBlock().getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
570
src/main/java/net/knarcraft/blockhunt/util/ArenaHelper.java
Normal file
570
src/main/java/net/knarcraft/blockhunt/util/ArenaHelper.java
Normal file
@ -0,0 +1,570 @@
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.PlayerArenaData;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaLocations;
|
||||
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.event.EndArenaEvent;
|
||||
import net.knarcraft.blockhunt.event.JoinArenaEvent;
|
||||
import net.knarcraft.blockhunt.event.LeaveArenaEvent;
|
||||
import net.knarcraft.blockhunt.manager.PermissionsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A helper class for dealing with arenas
|
||||
*/
|
||||
public final class ArenaHelper {
|
||||
|
||||
private ArenaHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all arenas and creates scoreboards
|
||||
*/
|
||||
public static void loadArenas() {
|
||||
MemoryStorage.arenaMap.clear();
|
||||
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()) {
|
||||
ScoreboardHelper.createScoreboard(arena);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
MessageHelper.broadcastMessage(arena.playersInArena, message, 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) {
|
||||
if (MemoryStorage.playerArena.get(player) != null) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_ALREADY_JOINED);
|
||||
return;
|
||||
}
|
||||
|
||||
Arena arena = MemoryStorage.arenaMap.get(arenaName.toLowerCase());
|
||||
if (arena != null) {
|
||||
// TODO: Use a disabled arena state instead of checking this condition every time
|
||||
if (arena.disguiseBlocks.isEmpty()) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_NO_BLOCKS_SET);
|
||||
} else {
|
||||
joinLobby(arena, player);
|
||||
}
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_NO_ARENA, "name-" + arenaName);
|
||||
}
|
||||
|
||||
SignsHelper.updateSigns();
|
||||
}
|
||||
|
||||
public static void playerLeaveArena(Player player, boolean message, boolean cleanup) {
|
||||
Arena arena = MemoryStorage.playerArena.get(player);
|
||||
if (arena == null) {
|
||||
if (message) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_LEAVE_NOT_IN_ARENA);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BlockHunt.plugin.getLogger().log(Level.INFO, player.getName() + " has left " + arena.arenaName);
|
||||
LeaveArenaEvent event = new LeaveArenaEvent(player, arena);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (cleanup) {
|
||||
cleanup(arena, player);
|
||||
}
|
||||
|
||||
PlayerArenaData playerArenaData = new PlayerArenaData(null, null, null,
|
||||
null, null, null, null, null, null,
|
||||
null, false);
|
||||
|
||||
if (MemoryStorage.playerData.get(player) != null) {
|
||||
playerArenaData = MemoryStorage.playerData.get(player);
|
||||
} else {
|
||||
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Unable to find player data for " + player.getName() +
|
||||
". The player's state will be broken!");
|
||||
}
|
||||
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setContents(playerArenaData.playerInventory());
|
||||
player.getInventory().setArmorContents(playerArenaData.playerArmor());
|
||||
player.setExp(playerArenaData.playerEXP());
|
||||
player.setLevel(playerArenaData.playerEXPLevels());
|
||||
AttributeInstance healthAttribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
if (healthAttribute != null) {
|
||||
healthAttribute.setBaseValue(playerArenaData.playerMaxHealth());
|
||||
}
|
||||
player.setHealth(playerArenaData.playerHealth());
|
||||
player.setFoodLevel(playerArenaData.playerFood());
|
||||
player.addPotionEffects(playerArenaData.playerPotionEffects());
|
||||
PlayerHelper.teleport(player, arena.arenaLocations.getExitWarp());
|
||||
player.setGameMode(playerArenaData.playerGameMode());
|
||||
player.setAllowFlight(playerArenaData.playerFlying());
|
||||
player.setFlying(playerArenaData.playerFlying());
|
||||
player.setWalkSpeed(0.2F);
|
||||
|
||||
MemoryStorage.playerData.remove(player);
|
||||
MemoryStorage.chosenBlock.remove(player);
|
||||
|
||||
VisibilityHelper.makePlayerUnhidden(player);
|
||||
|
||||
ScoreboardHelper.removeScoreboard(player);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_LEAVE_YOU_LEFT);
|
||||
if (message) {
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_LEAVE_LEFT_ARENA, "%playerName%-" +
|
||||
player.getName(), "1-" + arena.playersInArena.size(), "2-" + arena.maxPlayers);
|
||||
}
|
||||
|
||||
SignsHelper.updateSigns();
|
||||
}
|
||||
|
||||
private static void cleanup(Arena arena, Player player) {
|
||||
arena.playersInArena.remove(player);
|
||||
MemoryStorage.playerArena.remove(player);
|
||||
arena.seekers.remove(player);
|
||||
arena.hiders.remove(player);
|
||||
MemoryStorage.playerArena.remove(player);
|
||||
|
||||
if (arena.playersInArena.size() < arena.minPlayers && arena.gameState.equals(ArenaState.STARTING)) {
|
||||
arena.gameState = ArenaState.WAITING;
|
||||
arena.timer = 0;
|
||||
|
||||
sendMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
|
||||
}
|
||||
|
||||
if (arena.playersInArena.size() <= 1 && arena.gameState == ArenaState.IN_GAME) {
|
||||
if (arena.seekers.size() >= arena.playersInArena.size()) {
|
||||
ArenaHelper.seekersWin(arena);
|
||||
} else {
|
||||
ArenaHelper.hidersWin(arena);
|
||||
}
|
||||
}
|
||||
|
||||
if (arena.seekers.size() >= arena.playersInArena.size()) {
|
||||
ArenaHelper.seekersWin(arena);
|
||||
}
|
||||
|
||||
if (arena.seekers.size() == 0 && arena.gameState == ArenaState.IN_GAME) {
|
||||
Player seeker = arena.playersInArena.get(MemoryStorage.random.nextInt(arena.playersInArena.size()));
|
||||
ArenaHelper.sendMessage(arena, MessageKey.WARNING_IN_GAME_NEW_SEEKER_CHOSEN, "seeker-" + seeker.getName());
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_IN_GAME_SEEKER_CHOSEN, "seeker-" + seeker.getName());
|
||||
DisguiseAPI.undisguiseToAll(seeker);
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
pl.showPlayer(BlockHunt.plugin, seeker);
|
||||
}
|
||||
seeker.getInventory().clear();
|
||||
arena.seekers.add(seeker);
|
||||
PlayerHelper.teleport(seeker, arena.arenaLocations.getSeekersWarp());
|
||||
MemoryStorage.seekerTime.put(seeker, arena.waitingTimeSeeker);
|
||||
seeker.setWalkSpeed(0.3F);
|
||||
|
||||
// Fix for client not showing players after they join
|
||||
VisibilityHelper.makePlayerVisible(arena, player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants rewards to the seekers, and stops the arena
|
||||
*
|
||||
* @param arena <p>The arena in which the seekers won</p>
|
||||
*/
|
||||
public static void seekersWin(Arena arena) {
|
||||
String cause = "[BlockHunt] Seekers have won " + arena.arenaName;
|
||||
rewardWinnersAndStop(arena, cause, arena.seekers, arena.seekersWinCommands, arena.seekersTokenWin,
|
||||
MessageKey.NORMAL_WIN_SEEKERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant rewards to the hiders, and stops the arena
|
||||
*
|
||||
* @param arena <p>The arena in which the hiders won</p>
|
||||
*/
|
||||
public static void hidersWin(Arena arena) {
|
||||
String cause = "[BlockHunt] Hiders have won " + arena.arenaName;
|
||||
rewardWinnersAndStop(arena, cause, arena.hiders, arena.hidersWinCommands, arena.hidersTokenWin,
|
||||
MessageKey.NORMAL_WIN_HIDERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewards winners of an arena and stops the arena
|
||||
*
|
||||
* @param arena <p>The arena to grant rewards for</p>
|
||||
* @param cause <p>The cause of the arena stopping</p>
|
||||
* @param winnerTeam <p>The players on the team that won</p>
|
||||
* @param winCommands <p>The commands to be executed for the winning team</p>
|
||||
* @param winTokens <p>The amount of tokens to grant to the winners</p>
|
||||
* @param winMessage <p>The message to display to the players in the arena regarding which team won</p>
|
||||
*/
|
||||
private static void rewardWinnersAndStop(Arena arena, String cause, List<Player> winnerTeam,
|
||||
List<String> winCommands, int winTokens, MessageKey winMessage) {
|
||||
|
||||
List<Player> winners = new ArrayList<>();
|
||||
List<Player> losers = new ArrayList<>();
|
||||
|
||||
for (Player player : arena.playersInArena) {
|
||||
if (winnerTeam.contains(player)) {
|
||||
winners.add(player);
|
||||
grantRewards(player, winCommands, winTokens);
|
||||
} else {
|
||||
losers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the arena
|
||||
stopArena(arena, winners, losers, cause, winMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops an arena
|
||||
*
|
||||
* @param arena <p>The arena to stop</p>
|
||||
* @param winners <p>The winners of the arena</p>
|
||||
* @param losers <p>The losers of the arena</p>
|
||||
* @param cause <p>The cause of why the arena was stopped</p>
|
||||
* @param message <p>The message to display to players</p>
|
||||
*/
|
||||
private static void stopArena(Arena arena, List<Player> winners, List<Player> losers, String cause,
|
||||
MessageKey message) {
|
||||
EndArenaEvent event = new EndArenaEvent(winners, losers, arena);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
stopArena(arena, cause, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant arena win rewards to a player
|
||||
*
|
||||
* @param player <p>The player to reward</p>
|
||||
* @param winCommands <p>The commands to execute upon winning</p>
|
||||
* @param tokens <p>The amount of tokens to grant</p>
|
||||
*/
|
||||
private static void grantRewards(Player player, List<String> winCommands, int tokens) {
|
||||
|
||||
// Execute any hiders win commands
|
||||
if (winCommands != null) {
|
||||
for (String command : winCommands) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%",
|
||||
player.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
// Give the player their tokens
|
||||
int playerTokens = TokensHelper.getTokens(player);
|
||||
TokensHelper.setTokens(player, playerTokens + tokens);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_ADDED_TOKEN, "amount-" + tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops an arena
|
||||
*
|
||||
* @param arena <p>The arena to stop</p>
|
||||
* @param cause <p>A description of why the arena was stopped</p>
|
||||
* @param message <p>The message to display to affected players</p>
|
||||
*/
|
||||
public static void stopArena(Arena arena, String cause, MessageKey message) {
|
||||
BlockHunt.plugin.getLogger().log(Level.INFO, cause);
|
||||
ArenaHelper.sendMessage(arena, message);
|
||||
arena.seekers.clear();
|
||||
arena.hiders.clear();
|
||||
|
||||
for (Player player : arena.playersInArena) {
|
||||
playerLeaveArena(player, false, false);
|
||||
MemoryStorage.playerArena.remove(player);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
|
||||
}
|
||||
|
||||
arena.gameState = ArenaState.WAITING;
|
||||
arena.timer = 0;
|
||||
arena.playersInArena.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether any arena has any player
|
||||
*
|
||||
* @return <p>True if all arenas are empty</p>
|
||||
*/
|
||||
public static boolean noPlayersInArenas() {
|
||||
// Check if there are any players in any arena (quick way to early exit for event handlers)
|
||||
for (Arena arena : MemoryStorage.arenaMap.values()) {
|
||||
if (arena.playersInArena.size() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given player join the given arena's lobby
|
||||
*
|
||||
* @param arena <p>The arena the player wants to join</p>
|
||||
* @param player <p>The player that's joining the arena</p>
|
||||
*/
|
||||
private static void joinLobby(Arena arena, Player player) {
|
||||
// Deny the player if their inventory needs to be empty, and it's not
|
||||
if ((Boolean) MemoryStorage.config.get(ConfigKey.REQUIRE_INVENTORY_CLEAR_ON_JOIN) && !isInventoryEmpty(player)) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_INVENTORY_NOT_EMPTY);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that the arena has been properly set up before allowing the player to play
|
||||
// TODO: It would be better to have a DISABLED state for arenas until they are properly set up.
|
||||
ArenaLocations locations = arena.arenaLocations;
|
||||
if (!areWarpsSet(locations, player.getWorld())) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_WARPS_NOT_SET);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the game isn't already running
|
||||
if (arena.gameState == ArenaState.IN_GAME) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_ARENA_IN_GAME);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the arena is already full
|
||||
if (arena.playersInArena.size() >= arena.maxPlayers &&
|
||||
!PermissionsManager.hasPermission(player, Permission.JOIN_FULL, false)) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_JOIN_FULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// Teleport the player to the arena
|
||||
boolean canWarp = PlayerHelper.teleport(player, locations.getLobbyWarp());
|
||||
if (!canWarp) {
|
||||
MessageHelper.sendMessage(player, MessageKey.ERROR_TELEPORT_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockHunt.plugin.getLogger().log(Level.INFO, player.getName() + " has joined " + arena.arenaName);
|
||||
arena.playersInArena.add(player);
|
||||
MemoryStorage.playerArena.put(player, arena);
|
||||
// Call the join event for any add-ons
|
||||
Bukkit.getPluginManager().callEvent(new JoinArenaEvent(player, arena));
|
||||
|
||||
AttributeInstance healthAttribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
|
||||
// Store the player's data for restoration later
|
||||
PlayerArenaData playerArenaData = new PlayerArenaData(player.getLocation(), player.getGameMode(),
|
||||
player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getExp(),
|
||||
player.getLevel(), healthAttribute != null ? healthAttribute.getValue() : 20, player.getHealth(),
|
||||
player.getFoodLevel(), player.getActivePotionEffects(), player.getAllowFlight());
|
||||
MemoryStorage.playerData.put(player, playerArenaData);
|
||||
|
||||
// Set the player's state to the desired state
|
||||
setArenaState(arena, player, healthAttribute);
|
||||
|
||||
// Fix for client not showing players after they join
|
||||
VisibilityHelper.makePlayerVisible(arena, player);
|
||||
|
||||
// Give the player access to the block chooser
|
||||
giveBlockChooser(player);
|
||||
|
||||
// Give the player access to the hider/seeker chooser
|
||||
giveHiderSeekerChooser(player);
|
||||
|
||||
// Remove any existing disguise
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
|
||||
// Announce that the player joined
|
||||
ArenaHelper.sendMessage(arena, MessageKey.NORMAL_JOIN_JOINED_ARENA, "%playerName%-" + player.getName(),
|
||||
"1-" + arena.playersInArena.size(), "2-" + arena.maxPlayers);
|
||||
if (arena.playersInArena.size() < arena.minPlayers) {
|
||||
// Announce that additional players are required for the arena to start
|
||||
sendMessage(arena, MessageKey.WARNING_LOBBY_NEED_AT_LEAST, "1-" + arena.minPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a hider/seeker chooser to the given player if necessary
|
||||
*
|
||||
* @param player <p>The player to give the hider/seeker chooser to</p>
|
||||
*/
|
||||
private static void giveHiderSeekerChooser(Player player) {
|
||||
// If not enabled, return
|
||||
if (!((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ENABLED))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the player is out of passes, don't give them the choice between hider and seeker
|
||||
if (MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".blockhuntpass") <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material chooserMaterial = Material.matchMaterial((String) MemoryStorage.config.get(
|
||||
ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ID_NAME));
|
||||
if (chooserMaterial == null) {
|
||||
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Cannot give the block chooser because an invalid" +
|
||||
" material has been set.");
|
||||
return;
|
||||
}
|
||||
ItemStack shopBlockHuntPass = new ItemStack(chooserMaterial, 1);
|
||||
ItemMeta shopBlockHuntPassItemMeta = shopBlockHuntPass.getItemMeta();
|
||||
if (shopBlockHuntPassItemMeta == null) {
|
||||
return;
|
||||
}
|
||||
shopBlockHuntPassItemMeta.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(MessageHelper.replaceAll(lore));
|
||||
}
|
||||
|
||||
shopBlockHuntPassItemMeta.setLore(loreStrings2);
|
||||
shopBlockHuntPass.setItemMeta(shopBlockHuntPassItemMeta);
|
||||
shopBlockHuntPass.setAmount(MemoryStorage.shop.getFileConfiguration().getInt(
|
||||
player.getName() + ".blockhuntpass"));
|
||||
|
||||
player.getInventory().addItem(shopBlockHuntPass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a block chooser to the given player if necessary
|
||||
*
|
||||
* @param player <p>The player to give the block chooser to</p>
|
||||
*/
|
||||
private static void giveBlockChooser(Player player) {
|
||||
// If missing the necessary permission or if it's disabled, abort
|
||||
if (!((Boolean) MemoryStorage.config.get(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ENABLED)) ||
|
||||
(MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".blockchooser") == null &&
|
||||
!PermissionsManager.hasPermission(player, Permission.SHOP_BLOCK_CHOOSER, false))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material chooserMaterial = Material.matchMaterial((String) MemoryStorage.config.get(
|
||||
ConfigKey.SHOP_BLOCK_CHOOSER_V_1_ID_NAME));
|
||||
if (chooserMaterial == null) {
|
||||
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Cannot give the block chooser because an invalid" +
|
||||
" material has been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack shopBlockChooser = new ItemStack(chooserMaterial, 1);
|
||||
ItemMeta shopBlockChooserItemMeta = shopBlockChooser.getItemMeta();
|
||||
if (shopBlockChooserItemMeta == null) {
|
||||
return;
|
||||
}
|
||||
shopBlockChooserItemMeta.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 loreLine : loreStrings) {
|
||||
loreStrings2.add(MessageHelper.replaceAll(loreLine));
|
||||
}
|
||||
shopBlockChooserItemMeta.setLore(loreStrings2);
|
||||
shopBlockChooser.setItemMeta(shopBlockChooserItemMeta);
|
||||
|
||||
player.getInventory().addItem(shopBlockChooser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player's state to the arena's required state
|
||||
*
|
||||
* <p>Sets food and health to defaults, and clears the inventory among other things.</p>
|
||||
*
|
||||
* @param arena <p>The arena the player joined</p>
|
||||
* @param player <p>The player to update the state for</p>
|
||||
* @param healthAttribute <p>The player's health attribute</p>
|
||||
*/
|
||||
private static void setArenaState(Arena arena, Player player, AttributeInstance healthAttribute) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(potionEffect.getType());
|
||||
}
|
||||
player.setFoodLevel(20);
|
||||
player.setHealth(20);
|
||||
|
||||
if (healthAttribute != null) {
|
||||
healthAttribute.setBaseValue(20);
|
||||
}
|
||||
player.setLevel(arena.timer);
|
||||
player.setExp(0);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setHelmet(new ItemStack(Material.AIR));
|
||||
player.getInventory().setChestplate(new ItemStack(Material.AIR));
|
||||
player.getInventory().setLeggings(new ItemStack(Material.AIR));
|
||||
player.getInventory().setBoots(new ItemStack(Material.AIR));
|
||||
player.setFlying(false);
|
||||
player.setAllowFlight(false);
|
||||
player.setWalkSpeed(0.2F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player's inventory is completely empty
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if the player's inventory is completely empty</p>
|
||||
*/
|
||||
private static boolean isInventoryEmpty(Player player) {
|
||||
for (ItemStack inventoryItem : player.getInventory()) {
|
||||
if (inventoryItem != null && inventoryItem.getType() != Material.AIR) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (ItemStack inventoryItem : player.getInventory().getArmorContents()) {
|
||||
if (inventoryItem != null && inventoryItem.getType() != Material.AIR) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether all warps are set in the given ArenaLocations object
|
||||
*
|
||||
* @param locations <p>The arena locations to check</p>
|
||||
* @param world <p>The world the arena belongs to</p>
|
||||
* @return <p>True if all warps have been properly set</p>
|
||||
*/
|
||||
private static boolean areWarpsSet(ArenaLocations locations, World world) {
|
||||
Location zero = new Location(world, 0, 0, 0, 0, 0);
|
||||
return locations.getLobbyWarp() != null && locations.getHidersWarp() != null &&
|
||||
locations.getSeekersWarp() != null && locations.getExitWarp() != null &&
|
||||
!locations.getLobbyWarp().equals(zero) && !locations.getHidersWarp().equals(zero) &&
|
||||
!locations.getSeekersWarp().equals(zero) && !locations.getExitWarp().equals(zero);
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package net.knarcraft.blockhunt;
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
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.PermissionsManager;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,7 +17,11 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryHandler {
|
||||
public final class InventoryHelper {
|
||||
|
||||
private InventoryHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static void openPanel(Player player, String arenaName) {
|
||||
|
||||
@ -183,23 +187,19 @@ public class InventoryHandler {
|
||||
public static void openShop(Player player) {
|
||||
Inventory shop = Bukkit.createInventory(null, 9, MessageHelper.replaceAll("\u00A7r" +
|
||||
MemoryStorage.config.get(ConfigKey.SHOP_TITLE)));
|
||||
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
|
||||
MemoryStorage.shop.save();
|
||||
}
|
||||
int playerTokens = MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
|
||||
int playerTokens = TokensHelper.getTokens(player);
|
||||
List<String> loreLines;
|
||||
List<String> loreLines2;
|
||||
|
||||
ItemStack shopTokens = new ItemStack(Material.EMERALD, 1);
|
||||
ItemMeta shopTokens_IM = shopTokens.getItemMeta();
|
||||
shopTokens_IM.setDisplayName(MessageHelper.replaceAll("%N&lTokens: %A" + playerTokens));
|
||||
shopTokens.setItemMeta(shopTokens_IM);
|
||||
ItemMeta shopTokensItemMeta = shopTokens.getItemMeta();
|
||||
shopTokensItemMeta.setDisplayName(MessageHelper.replaceAll("%N&lTokens: %A" + playerTokens));
|
||||
shopTokens.setItemMeta(shopTokensItemMeta);
|
||||
|
||||
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(MessageHelper.replaceAll((String) MemoryStorage.config.get(
|
||||
ItemMeta shopBlockChooserItemMeta = shopBlockChooser.getItemMeta();
|
||||
shopBlockChooserItemMeta.setDisplayName(MessageHelper.replaceAll((String) MemoryStorage.config.get(
|
||||
ConfigKey.SHOP_BLOCK_CHOOSER_V_1_NAME)));
|
||||
loreLines = MemoryStorage.config.getFileConfiguration().getStringList(ConfigKey.SHOP_BLOCK_CHOOSER_V_1_DESCRIPTION.getPath());
|
||||
loreLines2 = new ArrayList<>();
|
||||
@ -210,8 +210,8 @@ public class InventoryHandler {
|
||||
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);
|
||||
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
|
||||
shopBlockChooserItemMeta.setLore(loreLines2);
|
||||
shopBlockChooser.setItemMeta(shopBlockChooserItemMeta);
|
||||
|
||||
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) MemoryStorage.config.get(
|
||||
ConfigKey.SHOP_BLOCK_HUNT_PASS_V_2_ID_NAME)), 1);
|
@ -1,11 +1,18 @@
|
||||
package net.knarcraft.blockhunt;
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerHandler {
|
||||
public final class PlayerHelper {
|
||||
|
||||
private PlayerHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean teleport(Player player, Location location) {
|
||||
MemoryStorage.teleportLocation.put(player, location);
|
||||
return player.teleport(location);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package net.knarcraft.blockhunt;
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.arena.ArenaState;
|
||||
import net.knarcraft.blockhunt.config.ConfigKey;
|
||||
import net.knarcraft.blockhunt.util.MessageHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Criteria;
|
||||
@ -12,7 +13,12 @@ import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
public class ScoreboardHandler {
|
||||
public final class ScoreboardHelper {
|
||||
|
||||
private ScoreboardHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static void createScoreboard(Arena arena) {
|
||||
if ((Boolean) MemoryStorage.config.get(ConfigKey.SCOREBOARD_ENABLED)) {
|
||||
Scoreboard board = arena.scoreboard;
|
||||
@ -85,4 +91,5 @@ public class ScoreboardHandler {
|
||||
public static void removeScoreboard(Player player) {
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package net.knarcraft.blockhunt;
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
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.util.MessageHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.Side;
|
||||
@ -12,7 +12,11 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SignsHandler {
|
||||
public final class SignsHelper {
|
||||
|
||||
private SignsHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static void createSign(SignChangeEvent event, String[] lines, Location location) {
|
||||
if (lines[1] != null) {
|
@ -1,5 +1,8 @@
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
/**
|
||||
* A helper class for common string modification actions
|
||||
*/
|
||||
public final class StringHelper {
|
||||
|
||||
private StringHelper() {
|
||||
|
49
src/main/java/net/knarcraft/blockhunt/util/TokensHelper.java
Normal file
49
src/main/java/net/knarcraft/blockhunt/util/TokensHelper.java
Normal file
@ -0,0 +1,49 @@
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A helper class for dealing with a player's tokens
|
||||
*/
|
||||
public final class TokensHelper {
|
||||
|
||||
private TokensHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount of tokens for the given player
|
||||
*
|
||||
* @param player <p>The player to set tokens for</p>
|
||||
* @param tokens <p>The amount of tokens to set</p>
|
||||
*/
|
||||
public static void setTokens(Player player, int tokens) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", tokens);
|
||||
MemoryStorage.shop.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player's current tokens
|
||||
*
|
||||
* @param player <p>The player to get tokens for</p>
|
||||
* @return <p>The player's current tokens</p>
|
||||
*/
|
||||
public static int getTokens(Player player) {
|
||||
initializeTokens(player);
|
||||
return MemoryStorage.shop.getFileConfiguration().getInt(player.getName() + ".tokens");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the given player's tokens is initialized and not null
|
||||
*
|
||||
* @param player <p>The player whose tokens should be initialized</p>
|
||||
*/
|
||||
private static void initializeTokens(Player player) {
|
||||
if (MemoryStorage.shop.getFileConfiguration().get(player.getName() + ".tokens") == null) {
|
||||
MemoryStorage.shop.getFileConfiguration().set(player.getName() + ".tokens", 0);
|
||||
MemoryStorage.shop.save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
194
src/main/java/net/knarcraft/blockhunt/util/VisibilityHelper.java
Normal file
194
src/main/java/net/knarcraft/blockhunt/util/VisibilityHelper.java
Normal file
@ -0,0 +1,194 @@
|
||||
package net.knarcraft.blockhunt.util;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.arena.Arena;
|
||||
import net.knarcraft.blockhunt.config.MessageKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static net.knarcraft.blockhunt.util.StringHelper.uppercaseAllFirst;
|
||||
|
||||
/**
|
||||
* A helper class for editing player visibility
|
||||
*/
|
||||
public final class VisibilityHelper {
|
||||
|
||||
private VisibilityHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a player visible to players in an arena and the other way around
|
||||
*
|
||||
* @param arena <p>The arena the player was in</p>
|
||||
* @param player <p>The player to make visible</p>
|
||||
*/
|
||||
public static void makePlayerVisible(Arena arena, Player player) {
|
||||
for (Player otherPlayer : arena.playersInArena) {
|
||||
if (otherPlayer.canSee(player)) {
|
||||
// Make player visible to others
|
||||
otherPlayer.showPlayer(BlockHunt.plugin, player);
|
||||
}
|
||||
if (player.canSee(otherPlayer)) {
|
||||
// Make other players visible to player
|
||||
player.showPlayer(BlockHunt.plugin, otherPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a hidden player in an arena no longer appear as hidden
|
||||
*
|
||||
* <p>This should be used when a player leaves an arena or the server to make sure no remnants of the hidden block
|
||||
* remains</p>
|
||||
*
|
||||
* @param player <p>The player to un-hide</p>
|
||||
*/
|
||||
public static void makePlayerUnhidden(Player player) {
|
||||
// Un-disguise the player
|
||||
DisguiseAPI.undisguiseToAll(player);
|
||||
|
||||
// Get the block data for the player
|
||||
BlockData hiddenBlockData = null;
|
||||
if (MemoryStorage.hiddenLocationMaterial.get(player) != null) {
|
||||
hiddenBlockData = Bukkit.createBlockData(MemoryStorage.hiddenLocationMaterial.get(player));
|
||||
}
|
||||
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
// Make the player visible to other players
|
||||
onlinePlayer.showPlayer(BlockHunt.plugin, player);
|
||||
|
||||
// No longer display the player's solid block
|
||||
if (hiddenBlockData != null) {
|
||||
Block playerBlock = MemoryStorage.hiddenLocation.get(player).getBlock();
|
||||
onlinePlayer.sendBlockChange(playerBlock.getLocation(), hiddenBlockData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the player into a no longer solid block
|
||||
*
|
||||
* @param player <p>The player to make unsolid</p>
|
||||
*/
|
||||
public static void makePlayerUnSolid(Player player) {
|
||||
ItemStack block = player.getInventory().getItem(8);
|
||||
if (block == null) {
|
||||
// This shouldn't be possible, but just in case
|
||||
player.sendMessage(ChatColor.RED + "Unable to hide you because your inventory block is missing!");
|
||||
BlockHunt.plugin.getLogger().log(Level.SEVERE, player.getName() + " could not be hidden because " +
|
||||
"their inventory block was missing!");
|
||||
return;
|
||||
}
|
||||
|
||||
Block playerBlock = player.getLocation().getBlock();
|
||||
if (MemoryStorage.hiddenLocation.get(player) != null) {
|
||||
playerBlock = MemoryStorage.hiddenLocation.get(player).getBlock();
|
||||
}
|
||||
|
||||
block.setAmount(5);
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (otherPlayer.equals(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Restore the block the player replaced
|
||||
Material material = MemoryStorage.hiddenLocationMaterial.get(player);
|
||||
otherPlayer.sendBlockChange(playerBlock.getLocation(),
|
||||
Bukkit.createBlockData(Objects.requireNonNullElse(material, Material.AIR)));
|
||||
MemoryStorage.hiddenLocationMaterial.remove(player);
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_BAT_HURT, 1, 1);
|
||||
block.removeEnchantment(Enchantment.DURABILITY);
|
||||
|
||||
for (Player playerShow : Bukkit.getOnlinePlayers()) {
|
||||
playerShow.showPlayer(BlockHunt.plugin, player);
|
||||
}
|
||||
|
||||
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, block.getType());
|
||||
DisguiseAPI.disguiseToAll(player, disguise);
|
||||
|
||||
MessageHelper.sendMessage(player, MessageKey.NORMAL_IN_GAME_NO_MORE_SOLID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to make the given player solid
|
||||
*
|
||||
* @param player <p>The player to make solid</p>
|
||||
* @param solidBlock <p>The block to solidify the player as</p>
|
||||
*/
|
||||
public static void makePlayerSolid(Player player, ItemStack solidBlock) {
|
||||
Block playerBlock = player.getLocation().getBlock();
|
||||
BlockData playerBlockData = playerBlock.getBlockData();
|
||||
if (playerBlockData.getMaterial().isAir() || !playerBlockData.getMaterial().isSolid()) {
|
||||
makePlayerSolid(player, playerBlock, playerBlockData, solidBlock, player.getLocation());
|
||||
} else {
|
||||
MessageHelper.sendMessage(player, MessageKey.WARNING_IN_GAME_NO_SOLID_PLACE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 static void makePlayerSolid(Player player, Block playerBlock, BlockData playerBlockData, ItemStack inventoryBlock,
|
||||
Location playerLocation) {
|
||||
// Store the material the player replaced
|
||||
MemoryStorage.hiddenLocationMaterial.put(player, playerBlockData.getMaterial());
|
||||
|
||||
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(BlockHunt.plugin, 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(BlockHunt.plugin, player);
|
||||
otherPlayer.sendBlockChange(playerBlock.getLocation(), inventoryBlock.getType().createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user