Merge pull request #25 from tylermurphy534/1.4.2

1.4.2
This commit is contained in:
Tyler Murphy 2022-04-28 16:02:01 -04:00 committed by GitHub
commit 52d6f450ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 265 additions and 95 deletions

View file

@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>net.tylermurphy</groupId> <groupId>net.tylermurphy</groupId>
<artifactId>HideAndSeek</artifactId> <artifactId>HideAndSeek</artifactId>
<version>1.4.1</version> <version>1.4.2</version>
<name>Hide and Seek Plugin</name> <name>Hide and Seek Plugin</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View file

@ -29,7 +29,9 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import net.tylermurphy.hideAndSeek.game.CommandHandler; import net.tylermurphy.hideAndSeek.game.CommandHandler;
@ -70,10 +72,13 @@ public class Main extends JavaPlugin implements Listener {
e.printStackTrace(); e.printStackTrace();
} }
},0,1).getTaskId(); },0,1).getTaskId();
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
} }
public void onDisable() { public void onDisable() {
Main.plugin.getServer().getScheduler().cancelTask(onTickTask); Main.plugin.getServer().getScheduler().cancelTask(onTickTask);
Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
UUIDFetcher.cleanup(); UUIDFetcher.cleanup();
Board.cleanup(); Board.cleanup();
} }

View file

@ -26,7 +26,7 @@ public class About implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
sender.sendMessage( sender.sendMessage(
String.format("%s%sHide and Seek %s(%s1.4.1%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%s%sHide and Seek %s(%s1.4.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
); );

View file

@ -47,17 +47,7 @@ public class Leave implements ICommand {
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
return; return;
} }
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); Game.leave(player);
else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
Board.removeBoard(player);
Board.remove(player);
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
if(Game.status == Status.STANDBY) {
Board.reloadLobbyBoards();
} else {
Board.reloadGameBoards();
Board.reloadBoardTeams();
}
} }
public String getLabel() { public String getLabel() {

View file

@ -40,7 +40,7 @@ public class SetBorder implements ICommand {
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
return; return;
} }
if(args.length < 2) { if(args.length < 3) {
worldborderEnabled = false; worldborderEnabled = false;
addToConfig("worldBorder.enabled",false); addToConfig("worldBorder.enabled",false);
saveConfig(); saveConfig();
@ -48,7 +48,7 @@ public class SetBorder implements ICommand {
Game.resetWorldborder(spawnWorld); Game.resetWorldborder(spawnWorld);
return; return;
} }
int num,delay; int num,delay,change;
try { num = Integer.parseInt(args[0]); } catch (Exception e) { try { num = Integer.parseInt(args[0]); } catch (Exception e) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
return; return;
@ -57,10 +57,18 @@ public class SetBorder implements ICommand {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1]));
return; return;
} }
try { change = Integer.parseInt(args[2]); } catch (Exception e) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2]));
return;
}
if(num < 100) { if(num < 100) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE")); sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE"));
return; return;
} }
if(change < 1) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE"));
return;
}
Vector newWorldborderPosition = new Vector(); Vector newWorldborderPosition = new Vector();
Player player = (Player) sender; Player player = (Player) sender;
newWorldborderPosition.setX(player.getLocation().getBlockX()); newWorldborderPosition.setX(player.getLocation().getBlockX());
@ -73,12 +81,14 @@ public class SetBorder implements ICommand {
worldborderPosition = newWorldborderPosition; worldborderPosition = newWorldborderPosition;
worldborderSize = num; worldborderSize = num;
worldborderDelay = delay; worldborderDelay = delay;
worldborderChange = change;
worldborderEnabled = true; worldborderEnabled = true;
addToConfig("worldBorder.x", worldborderPosition.getBlockX()); addToConfig("worldBorder.x", worldborderPosition.getBlockX());
addToConfig("worldBorder.z", worldborderPosition.getBlockZ()); addToConfig("worldBorder.z", worldborderPosition.getBlockZ());
addToConfig("worldBorder.delay", worldborderDelay); addToConfig("worldBorder.delay", worldborderDelay);
addToConfig("worldBorder.size", worldborderSize); addToConfig("worldBorder.size", worldborderSize);
addToConfig("worldBorder.enabled", true); addToConfig("worldBorder.enabled", true);
addToConfig("worldBorder.move", worldborderChange);
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
saveConfig(); saveConfig();
Game.resetWorldborder(spawnWorld); Game.resetWorldborder(spawnWorld);
@ -89,7 +99,7 @@ public class SetBorder implements ICommand {
} }
public String getUsage() { public String getUsage() {
return "<size> <delay>"; return "<size> <delay> <move>";
} }
public String getDescription() { public String getDescription() {

View file

@ -19,9 +19,14 @@
package net.tylermurphy.hideAndSeek.configuration; package net.tylermurphy.hideAndSeek.configuration;
import com.cryptomorin.xseries.XItemStack;
import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XMaterial;
import net.tylermurphy.hideAndSeek.util.Version; import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,7 +49,8 @@ public class Config {
spawnWorld, spawnWorld,
exitWorld, exitWorld,
lobbyWorld, lobbyWorld,
locale; locale,
leaveServer;
public static Vector public static Vector
spawnPosition, spawnPosition,
@ -66,13 +72,16 @@ public class Config {
autoJoin, autoJoin,
teleportToExit, teleportToExit,
lobbyCountdownEnabled, lobbyCountdownEnabled,
seekerPing; seekerPing,
bungeeLeave,
lobbyItemStartAdmin;
public static int public static int
minPlayers, minPlayers,
worldborderSize, worldborderSize,
worldborderDelay, worldborderDelay,
currentWorldborderSize, currentWorldborderSize,
worldborderChange,
gameLength, gameLength,
saveMinX, saveMinX,
saveMinZ, saveMinZ,
@ -86,7 +95,9 @@ public class Config {
lobbyMax, lobbyMax,
seekerPingLevel1, seekerPingLevel1,
seekerPingLevel2, seekerPingLevel2,
seekerPingLevel3; seekerPingLevel3,
lobbyItemLeavePosition,
lobbyItemStartPosition;
public static List<String> public static List<String>
blockedCommands, blockedCommands,
@ -110,6 +121,10 @@ public class Config {
LOBBY_CONTENTS, LOBBY_CONTENTS,
GAME_CONTENTS; GAME_CONTENTS;
public static ItemStack
lobbyLeaveItem,
lobbyStartItem;
public static void loadConfig() { public static void loadConfig() {
config = new ConfigManager("config.yml"); config = new ConfigManager("config.yml");
@ -119,7 +134,7 @@ public class Config {
//Spawn //Spawn
spawnPosition = new Vector( spawnPosition = new Vector(
config.getDouble("spawns.game.x"), config.getDouble("spawns.game.x"),
Math.max(0, Math.min(255, config.getDouble("spawns.game.y"))), Math.max(Version.atLeast("1.18") ? -64 : 0, Math.min(255, config.getDouble("spawns.game.y"))),
config.getDouble("spawns.game.z") config.getDouble("spawns.game.z")
); );
spawnWorld = config.getString("spawns.game.world"); spawnWorld = config.getString("spawns.game.world");
@ -127,7 +142,7 @@ public class Config {
///Lobby ///Lobby
lobbyPosition = new Vector( lobbyPosition = new Vector(
config.getDouble("spawns.lobby.x"), config.getDouble("spawns.lobby.x"),
Math.max(0, Math.min(255, config.getDouble("spawns.lobby.y"))), Math.max(Version.atLeast("1.18") ? -64 : 0, Math.min(255, config.getDouble("spawns.lobby.y"))),
config.getDouble("spawns.lobby.z") config.getDouble("spawns.lobby.z")
); );
lobbyWorld = config.getString("spawns.lobby.world"); lobbyWorld = config.getString("spawns.lobby.world");
@ -136,7 +151,7 @@ public class Config {
exitPosition = new Vector( exitPosition = new Vector(
config.getDouble("spawns.exit.x"), config.getDouble("spawns.exit.x"),
Math.max(0, Math.min(255, config.getDouble("spawns.exit.y"))), Math.max(Version.atLeast("1.18") ? -64 : 0, Math.min(255, config.getDouble("spawns.exit.y"))),
config.getDouble("spawns.exit.z") config.getDouble("spawns.exit.z")
); );
exitWorld = config.getString("spawns.exit.world"); exitWorld = config.getString("spawns.exit.world");
@ -150,6 +165,7 @@ public class Config {
worldborderSize = Math.max(100, config.getInt("worldBorder.size")); worldborderSize = Math.max(100, config.getInt("worldBorder.size"));
worldborderDelay = Math.max(1, config.getInt("worldBorder.delay")); worldborderDelay = Math.max(1, config.getInt("worldBorder.delay"));
worldborderEnabled = config.getBoolean("worldBorder.enabled"); worldborderEnabled = config.getBoolean("worldBorder.enabled");
worldborderChange = config.getInt("worldBorder.moveAmount");
//Prefix //Prefix
char SYMBOLE = '\u00A7'; char SYMBOLE = '\u00A7';
@ -214,6 +230,8 @@ public class Config {
} }
} }
} }
bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy");
leaveServer = config.getString("leaveServer");
//Leaderboard //Leaderboard
LOBBY_TITLE = leaderboard.getString("lobby.title"); LOBBY_TITLE = leaderboard.getString("lobby.title");
@ -232,6 +250,31 @@ public class Config {
GLOW_INACTIVE = leaderboard.getString("glow.inactive"); GLOW_INACTIVE = leaderboard.getString("glow.inactive");
BORDER_COUNTING = leaderboard.getString("border.counting"); BORDER_COUNTING = leaderboard.getString("border.counting");
BORDER_DECREASING = leaderboard.getString("border.decreasing"); BORDER_DECREASING = leaderboard.getString("border.decreasing");
//Lobby Items
if(config.getBoolean("lobbyItems.leave.enabled")) {
ConfigurationSection item = new YamlConfiguration().createSection("temp");
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.leave.name")));
item.set("material", config.getString("lobbyItems.leave.material"));
List<String> lore = config.getStringList("lobbyItems.leave.lore");
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
ItemStack temp = null;
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
lobbyLeaveItem = temp;
lobbyItemLeavePosition = config.getInt("lobbyItems.leave.position");
}
if(config.getBoolean("lobbyItems.start.enabled")) {
ConfigurationSection item = new YamlConfiguration().createSection("temp");
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.start.name")));
item.set("material", config.getString("lobbyItems.start.material"));
List<String> lore = config.getStringList("lobbyItems.start.lore");
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
ItemStack temp = null;
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
lobbyStartItem = temp;
lobbyItemStartAdmin = config.getBoolean("lobbyItems.start.adminOnly");
lobbyItemStartPosition = config.getInt("lobbyItems.start.position");
}
} }
public static void addToConfig(String path, Object value) { public static void addToConfig(String path, Object value) {

View file

@ -232,6 +232,7 @@ public class ConfigManager {
if(end == -1) end = yamlString.length(); if(end == -1) end = yamlString.length();
String replace; String replace;
if(entry.getValue() instanceof List){ if(entry.getValue() instanceof List){
if(((List<?>) entry.getValue()).isEmpty()) continue;
replace = "["; replace = "[";
for(Object o : (List<Object>)entry.getValue()){ for(Object o : (List<Object>)entry.getValue()){
replace = replace + o.toString() + ", "; replace = replace + o.toString() + ", ";

View file

@ -34,28 +34,28 @@ import org.bukkit.scoreboard.*;
public class Board { public class Board {
private static final List<UUID> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
private static final Map<UUID, Player> playerList = new HashMap<>(); private static final Map<String, Player> playerList = new HashMap<>();
private static final Map<UUID, CustomBoard> customBoards = new HashMap<>(); private static final Map<String, CustomBoard> customBoards = new HashMap<>();
public static boolean isPlayer(Player player) { public static boolean isPlayer(Player player) {
return playerList.containsKey(player.getUniqueId()); return playerList.containsKey(player.getUniqueId().toString());
} }
public static boolean isPlayer(CommandSender sender) { public static boolean isPlayer(CommandSender sender) {
return playerList.containsKey(Bukkit.getPlayer(sender.getName()).getUniqueId()); return playerList.containsKey(Bukkit.getPlayer(sender.getName()).getUniqueId().toString());
} }
public static boolean isHider(Player player) { public static boolean isHider(Player player) {
return Hider.contains(player.getUniqueId()); return Hider.contains(player.getUniqueId().toString());
} }
public static boolean isSeeker(Player player) { public static boolean isSeeker(Player player) {
return Seeker.contains(player.getUniqueId()); return Seeker.contains(player.getUniqueId().toString());
} }
public static boolean isSpectator(Player player) { public static boolean isSpectator(Player player) {
return Spectator.contains(player.getUniqueId()); return Spectator.contains(player.getUniqueId().toString());
} }
public static int sizeHider() { public static int sizeHider() {
@ -70,13 +70,6 @@ public class Board {
return playerList.values().size(); return playerList.values().size();
} }
public static void check(){
for(UUID uuid : playerList.keySet()){
if(Bukkit.getPlayer(uuid) == null)
playerList.remove(uuid);
}
}
public static List<Player> getHiders(){ public static List<Player> getHiders(){
return Hider.stream().map(playerList::get).collect(Collectors.toList()); return Hider.stream().map(playerList::get).collect(Collectors.toList());
} }
@ -98,41 +91,41 @@ public class Board {
} }
public static Player getPlayer(UUID uuid) { public static Player getPlayer(UUID uuid) {
return playerList.get(uuid); return playerList.get(uuid.toString());
} }
public static void addHider(Player player) { public static void addHider(Player player) {
Hider.add(player.getUniqueId()); Hider.add(player.getUniqueId().toString());
Seeker.remove(player.getUniqueId()); Seeker.remove(player.getUniqueId().toString());
Spectator.remove(player.getUniqueId()); Spectator.remove(player.getUniqueId().toString());
playerList.put(player.getUniqueId(), player); playerList.put(player.getUniqueId().toString(), player);
} }
public static void addSeeker(Player player) { public static void addSeeker(Player player) {
Hider.remove(player.getUniqueId()); Hider.remove(player.getUniqueId().toString());
Seeker.add(player.getUniqueId()); Seeker.add(player.getUniqueId().toString());
Spectator.remove(player.getUniqueId()); Spectator.remove(player.getUniqueId().toString());
playerList.put(player.getUniqueId(), player); playerList.put(player.getUniqueId().toString(), player);
} }
public static void addSpectator(Player player) { public static void addSpectator(Player player) {
Hider.remove(player.getUniqueId()); Hider.remove(player.getUniqueId().toString());
Seeker.remove(player.getUniqueId()); Seeker.remove(player.getUniqueId().toString());
Spectator.add(player.getUniqueId()); Spectator.add(player.getUniqueId().toString());
playerList.put(player.getUniqueId(), player); playerList.put(player.getUniqueId().toString(), player);
} }
public static void remove(Player player) { public static void remove(Player player) {
Hider.remove(player.getUniqueId()); Hider.remove(player.getUniqueId().toString());
Seeker.remove(player.getUniqueId()); Seeker.remove(player.getUniqueId().toString());
Spectator.remove(player.getUniqueId()); Spectator.remove(player.getUniqueId().toString());
playerList.remove(player.getUniqueId()); playerList.remove(player.getUniqueId().toString());
} }
public static boolean onSameTeam(Player player1, Player player2) { public static boolean onSameTeam(Player player1, Player player2) {
if(Hider.contains(player1.getUniqueId()) && Hider.contains(player2.getUniqueId())) return true; if(Hider.contains(player1.getUniqueId().toString()) && Hider.contains(player2.getUniqueId().toString())) return true;
else if(Seeker.contains(player1.getUniqueId()) && Seeker.contains(player2.getUniqueId())) return true; else if(Seeker.contains(player1.getUniqueId().toString()) && Seeker.contains(player2.getUniqueId().toString())) return true;
else return Spectator.contains(player1.getUniqueId()) && Spectator.contains(player2.getUniqueId()); else return Spectator.contains(player1.getUniqueId().toString()) && Spectator.contains(player2.getUniqueId().toString());
} }
public static void reload() { public static void reload() {
@ -146,7 +139,7 @@ public class Board {
} }
private static void createLobbyBoard(Player player, boolean recreate) { private static void createLobbyBoard(Player player, boolean recreate) {
CustomBoard board = customBoards.get(player.getUniqueId()); CustomBoard board = customBoards.get(player.getUniqueId().toString());
if(recreate) { if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK"); board = new CustomBoard(player, "&l&eHIDE AND SEEK");
board.updateTeams(); board.updateTeams();
@ -175,7 +168,7 @@ public class Board {
i++; i++;
} }
board.display(); board.display();
customBoards.put(player.getUniqueId(), board); customBoards.put(player.getUniqueId().toString(), board);
} }
public static void createGameBoard(Player player){ public static void createGameBoard(Player player){
@ -183,7 +176,7 @@ public class Board {
} }
private static void createGameBoard(Player player, boolean recreate){ private static void createGameBoard(Player player, boolean recreate){
CustomBoard board = customBoards.get(player.getUniqueId()); CustomBoard board = customBoards.get(player.getUniqueId().toString());
if(recreate) { if(recreate) {
board = new CustomBoard(player, GAME_TITLE); board = new CustomBoard(player, GAME_TITLE);
board.updateTeams(); board.updateTeams();
@ -238,14 +231,14 @@ public class Board {
i++; i++;
} }
board.display(); board.display();
customBoards.put(player.getUniqueId(), board); customBoards.put(player.getUniqueId().toString(), board);
} }
public static void removeBoard(Player player) { public static void removeBoard(Player player) {
ScoreboardManager manager = Bukkit.getScoreboardManager(); ScoreboardManager manager = Bukkit.getScoreboardManager();
assert manager != null; assert manager != null;
player.setScoreboard(manager.getMainScoreboard()); player.setScoreboard(manager.getMainScoreboard());
customBoards.remove(player.getUniqueId()); customBoards.remove(player.getUniqueId().toString());
} }
public static void reloadLobbyBoards() { public static void reloadLobbyBoards() {

View file

@ -39,8 +39,11 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
@ -277,10 +280,58 @@ public class EventListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if(!Board.isPlayer(event.getPlayer())) return;
if(Board.isPlayer(event.getPlayer()) && blockedInteracts.contains(event.getClickedBlock().getType().name())){
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null && blockedInteracts.contains(event.getClickedBlock().getType().name())){
event.setCancelled(true);
return;
}
if(Game.status != Status.STANDBY) return;
ItemStack temp = event.getItem();
if(temp == null) return;
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyLeaveItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyLeaveItem.getType()) {
event.setCancelled(true);
Game.leave(event.getPlayer());
}
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyStartItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyStartItem.getType() && event.getPlayer().hasPermission("hideandseek.start")) {
event.setCancelled(true);
if (Game.isNotSetup()) {
event.getPlayer().sendMessage(errorPrefix + message("GAME_SETUP"));
return;
}
if (Game.status != Status.STANDBY) {
event.getPlayer().sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
if (Board.size() < minPlayers) {
event.getPlayer().sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers));
return;
}
Game.start();
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event) {
if(event.getWhoClicked() instanceof Player){
Player player = (Player) event.getWhoClicked();
if(Board.isPlayer(player) && Game.status == Status.STANDBY){
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemDrop(PlayerDropItemEvent event)
{
if(Board.isPlayer(event.getPlayer()) && Game.status == Status.STANDBY){
event.setCancelled(true);
}
}
} }

View file

@ -24,6 +24,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound; import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.messages.Titles; import com.cryptomorin.xseries.messages.Titles;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.database.Database;
@ -70,6 +72,26 @@ public class Game {
worldLoader = new WorldLoader(spawnWorld); worldLoader = new WorldLoader(spawnWorld);
} }
public static void start(){
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
if(!rand.isPresent()){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
String seekerName = rand.get().getName();
Player temp = Bukkit.getPlayer(seekerName);
if(temp == null){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
Player seeker = Board.getPlayer(temp.getUniqueId());
if(seeker == null){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
start(seeker);
}
public static void start(Player seeker){ public static void start(Player seeker){
if(status == Status.STARTING || status == Status.PLAYING) return; if(status == Status.STARTING || status == Status.PLAYING) return;
if(worldLoader.getWorld() != null) { if(worldLoader.getWorld() != null) {
@ -153,6 +175,10 @@ public class Game {
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.ADVENTURE);
Board.addHider(player); Board.addHider(player);
player.getInventory().clear(); player.getInventory().clear();
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.isOp()))
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
if(lobbyLeaveItem != null)
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){ for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
@ -187,6 +213,7 @@ public class Game {
} }
public static void resetWorldborder(String worldName){ public static void resetWorldborder(String worldName){
worldBorder = new Border();
worldBorder.resetWorldborder(worldName); worldBorder.resetWorldborder(worldName);
} }
@ -233,6 +260,10 @@ public class Game {
public static void join(Player player){ public static void join(Player player){
if(Game.status == Status.STANDBY) { if(Game.status == Status.STANDBY) {
player.getInventory().clear(); player.getInventory().clear();
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
if(lobbyLeaveItem != null)
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
Board.addHider(player); Board.addHider(player);
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
@ -258,6 +289,28 @@ public class Game {
} }
} }
public static void leave(Player player){
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
Board.removeBoard(player);
Board.remove(player);
player.getInventory().clear();
if(Game.status == Status.STANDBY) {
Board.reloadLobbyBoards();
} else {
Board.reloadGameBoards();
Board.reloadBoardTeams();
}
if(bungeeLeave) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(leaveServer);
player.sendPluginMessage(Main.plugin, "BungeeCord", out.toByteArray());
} else {
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
}
}
public static void removeItems(Player player){ public static void removeItems(Player player){
for(ItemStack si : Items.SEEKER_ITEMS) for(ItemStack si : Items.SEEKER_ITEMS)
for(ItemStack i : player.getInventory().getContents()) for(ItemStack i : player.getInventory().getContents())
@ -279,23 +332,7 @@ public class Game {
Board.reloadLobbyBoards(); Board.reloadLobbyBoards();
} }
if(countdownTime == 0){ if(countdownTime == 0){
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); start();
if(!rand.isPresent()){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
String seekerName = rand.get().getName();
Player temp = Bukkit.getPlayer(seekerName);
if(temp == null){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
Player seeker = Board.getPlayer(temp.getUniqueId());
if(seeker == null){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
start(seeker);
} }
} else { } else {
countdownTime = -1; countdownTime = -1;
@ -527,16 +564,19 @@ class Border {
} }
private void decreaceWorldborder() { private void decreaceWorldborder() {
if(currentWorldborderSize-100 > 100) { if(currentWorldborderSize == 100) return;
running = true; int change = worldborderChange;
broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); if(currentWorldborderSize-worldborderChange < 100){
currentWorldborderSize -= 100; change = currentWorldborderSize-100;
World world = Bukkit.getWorld("hideandseek_"+spawnWorld);
assert world != null;
org.bukkit.WorldBorder border = world.getWorldBorder();
border.setSize(border.getSize()-100,30);
delay = 30;
} }
running = true;
broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING").addAmount(change));
currentWorldborderSize -= worldborderChange;
World world = Bukkit.getWorld("hideandseek_"+spawnWorld);
assert world != null;
org.bukkit.WorldBorder border = world.getWorldBorder();
border.setSize(border.getSize()-change,30);
delay = 30;
} }
public void resetWorldborder(String worldName) { public void resetWorldborder(String worldName) {

View file

@ -44,6 +44,21 @@ autoJoin: false
# default: false # default: false
teleportToExit: false teleportToExit: false
# What do you want to happen when a player leaves the lobby. If you are running a single server, maybe you want to send
# them to the world hub. But if you are running a bungee-cord or velocity server, maybe you want to send them to the servers
# hub.
#
# EXIT - Sends the player to the specified exit position set by /hs setexit
#
# PROXY - Send the player to a specified server in a bungee-cord / velocity setup.
#
# default: EXIT
leaveType: EXIT
# Ignore this setting if you aren't using the PROXY leave type method above. If you are, set this to the server you want to send
# players too.
leaveServer: hub
# The worldborder closes every interval, which is evey [delay] in minutes. # The worldborder closes every interval, which is evey [delay] in minutes.
# Thw worldborder starts at [size], and decreases 100 blocks every interval. # Thw worldborder starts at [size], and decreases 100 blocks every interval.
# x & z are the center location. [enabled] is whenever the border is enabled. # x & z are the center location. [enabled] is whenever the border is enabled.
@ -53,6 +68,7 @@ worldBorder:
z: 0 z: 0
delay: 10 delay: 10
size: 500 size: 500
moveAmount: 100
warn: true warn: true
enabled: false enabled: false
@ -99,6 +115,26 @@ lobby:
max: 10 max: 10
enabled: true enabled: true
# Below are the two items given to you when you join a lobby. A item to click to leave the lobby, and another
# to start the game. Each of these items can be toggled separately, but only these items are currently supported.
# You can customize the material, name, lore, and position of the item. And finally, the start item is marked as
# adminOnly be default since the /hs start command is also admin by default. If you set adminOnly to false, only
# the item will become non admin only, not the command.
lobbyItems:
leave:
material: BED
name: "&cLeave Lobby"
lore: ["Go back to server hub"]
position: 8
enabled: true
start:
material: CLOCK
name: "&bStart Game"
lore: []
position: 0
enabled: true
adminOnly: true
# As a hider, the closer a seeker gets to you, the louder and faster a pining noise will play. # As a hider, the closer a seeker gets to you, the louder and faster a pining noise will play.
# There are 3 separate distances (in blocks) you can set to the 3 different levels for the noise. # There are 3 separate distances (in blocks) you can set to the 3 different levels for the noise.
# The higher the level, the closer the seeker. # The higher the level, the closer the seeker.
@ -128,7 +164,6 @@ blockedCommands: [msg, tp, gamemode, kill, give, effect]
# the block ID you enter, as the plugin will automatically switch to the # the block ID you enter, as the plugin will automatically switch to the
# block ID of your current Minecraft server version. # block ID of your current Minecraft server version.
blockedInteracts: [FURNACE, CRAFTING_TABLE, ANVIL, CHEST, BARREL] blockedInteracts: [FURNACE, CRAFTING_TABLE, ANVIL, CHEST, BARREL]
# ---------------------------------------------------------- # # ---------------------------------------------------------- #
# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # # ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING #
# ---------------------------------------------------------- # # ---------------------------------------------------------- #

View file

@ -40,6 +40,7 @@ items:
material: POTION material: POTION
amount: 2 amount: 2
type: INSTANT_HEAL type: INSTANT_HEAL
effects: effects:
seeker: seeker:
'1': '1':

View file

@ -34,9 +34,10 @@ Localization:
WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}."
WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks."
WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_POSITION: "Spawn position must be 100 from world border center."
WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, delay to {AMOUNT}, and move to {AMOUNT}."
WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." WORLDBORDER_DECREASING: "World border decreasing by {AMOUNT} blocks over the next 30s."
WORLDBORDER_WARN: "World border will shrink in the next 30s!" WORLDBORDER_WARN: "World border will shrink in the next 30s!"
WORLDBORDER_CHANGE_SIZE: "World border change cannot be 0 or less."
TAUNTED: "&c&oOh no! You have been chosen to be taunted." TAUNTED: "&c&oOh no! You have been chosen to be taunted."
TAUNT: "A random hider will be taunted in the next 30s." TAUNT: "A random hider will be taunted in the next 30s."
TAUNT_ACTIVATE: "Taunt has been activated." TAUNT_ACTIVATE: "Taunt has been activated."

View file

@ -71,7 +71,7 @@ game:
countdown: countdown:
waiting: "Waiting for players..." waiting: "Waiting for players..."
adminStart: "Waiting for gamemaster..." adminStart: "Waiting for gamemaster..."
counting: "Starting in: $a{AMOUNT}s" counting: "Starting in: &a{AMOUNT}s"
taunt: taunt:
counting: "{AMOUNT}m{AMOUNT}s" counting: "{AMOUNT}m{AMOUNT}s"

View file

@ -1,6 +1,6 @@
name: HideAndSeek name: HideAndSeek
main: net.tylermurphy.hideAndSeek.Main main: net.tylermurphy.hideAndSeek.Main
version: 1.4.1 version: 1.4.2
author: KenshinEto author: KenshinEto
load: STARTUP load: STARTUP
api-version: 1.13 api-version: 1.13