summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/game/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/game/util')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/util/CountdownDisplay.java26
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/util/Packet.java56
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/util/PlayerUtil.java120
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java26
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/util/Version.java45
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java26
6 files changed, 299 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/CountdownDisplay.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/CountdownDisplay.java
new file mode 100644
index 0000000..e735af9
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/CountdownDisplay.java
@@ -0,0 +1,26 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2022 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.game.util;
+
+public enum CountdownDisplay {
+ CHAT,
+ ACTIONBAR,
+ TITLE
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Packet.java
new file mode 100644
index 0000000..0fad539
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Packet.java
@@ -0,0 +1,56 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2021 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.game.util;
+
+import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.ProtocolLibrary;
+import com.comphenix.protocol.ProtocolManager;
+import com.comphenix.protocol.events.PacketContainer;
+import com.comphenix.protocol.wrappers.WrappedDataWatcher;
+import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
+import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
+import org.bukkit.entity.Player;
+
+import java.lang.reflect.InvocationTargetException;
+
+public class Packet {
+
+ private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
+
+ public static void setGlow(Player player, Player target, boolean glowing) {
+ PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
+ packet.getIntegers().write(0, target.getEntityId());
+ WrappedDataWatcher watcher = new WrappedDataWatcher();
+ Serializer serializer = Registry.get(Byte.class);
+ watcher.setEntity(target);
+ if (glowing) {
+ watcher.setObject(0, serializer, (byte) (0x40));
+ } else {
+ watcher.setObject(0, serializer, (byte) (0x0));
+ }
+ packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
+ try {
+ protocolManager.sendServerPacket(player, packet);
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/PlayerUtil.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/PlayerUtil.java
new file mode 100644
index 0000000..61d2b0e
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/PlayerUtil.java
@@ -0,0 +1,120 @@
+package net.tylermurphy.hideAndSeek.game.util;
+
+import com.cryptomorin.xseries.messages.Titles;
+import net.md_5.bungee.api.ChatColor;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.configuration.Items;
+import net.tylermurphy.hideAndSeek.game.Board;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.attribute.Attribute;
+import org.bukkit.attribute.AttributeInstance;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.lobbyPosition;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+public class PlayerUtil {
+
+ public static void loadHider(Player player, String gameWorld){
+ player.teleport(new Location(Bukkit.getWorld(gameWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
+ loadPlayer(player);
+ player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
+ }
+
+ public static void loadSeeker(Player player, String gameWorld){
+ player.teleport(new Location(Bukkit.getWorld(gameWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
+ loadPlayer(player);
+ player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
+ player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
+ player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,1000000,128,false,false));
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("SEEKER_TEAM_NAME"), ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString());
+ }
+
+ public static void loadSpectator(Player player, String gameWorld){
+ player.teleport(new Location(Bukkit.getWorld(gameWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
+ loadPlayer(player);
+ player.setAllowFlight(true);
+ player.setFlying(true);
+ player.setFallDistance(0.0F);
+ Main.getInstance().getBoard().getPlayers().forEach(otherPlayer -> {
+ otherPlayer.hidePlayer(player);
+ });
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString());
+ }
+
+ public static void resetPlayer(Player player, Board board){
+ loadPlayer(player);
+ if (board.isSeeker(player)) {
+ if (pvpEnabled)
+ for(ItemStack item : Items.SEEKER_ITEMS)
+ player.getInventory().addItem(item);
+ for(PotionEffect effect : Items.SEEKER_EFFECTS)
+ player.addPotionEffect(effect);
+ } else if (board.isHider(player)) {
+ if (pvpEnabled)
+ for(ItemStack item : Items.HIDER_ITEMS)
+ player.getInventory().addItem(item);
+ for(PotionEffect effect : Items.HIDER_EFFECTS)
+ player.addPotionEffect(effect);
+ if (glowEnabled) {
+ player.getInventory().addItem(glowPowerupItem);
+ }
+ }
+ }
+
+ public static void unloadPlayer(Player player){
+ player.setGameMode(GameMode.ADVENTURE);
+ player.getInventory().clear();
+ for(PotionEffect effect : player.getActivePotionEffects()) {
+ player.removePotionEffect(effect.getType());
+ }
+ if (Version.atLeast("1.9")) {
+ AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
+ if (attribute != null) player.setHealth(attribute.getValue());
+ for(Player temp : Main.getInstance().getBoard().getPlayers()) {
+ Packet.setGlow(player, temp, false);
+ }
+ } else {
+ player.setHealth(player.getMaxHealth());
+ }
+ Main.getInstance().getBoard().getPlayers().forEach(temp -> {
+ player.showPlayer(temp);
+ temp.showPlayer(player);
+ });
+ player.setAllowFlight(false);
+ player.setFlying(false);
+ player.setFallDistance(0.0F);
+ }
+
+ public static void joinPlayer(Player player){
+ player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
+ loadPlayer(player);
+ if (lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
+ player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
+ if (lobbyLeaveItem != null)
+ player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
+ }
+
+ private static void loadPlayer(Player player){
+ player.setGameMode(GameMode.ADVENTURE);
+ player.getInventory().clear();
+ for(PotionEffect effect : player.getActivePotionEffects()) {
+ player.removePotionEffect(effect.getType());
+ }
+ player.setFoodLevel(20);
+ if (Version.atLeast("1.9")) {
+ AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
+ if (attribute != null) player.setHealth(attribute.getValue());
+ } else {
+ player.setHealth(player.getMaxHealth());
+ }
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java
new file mode 100644
index 0000000..e630070
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Status.java
@@ -0,0 +1,26 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2021 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.game.util;
+
+public enum Status {
+
+ STANDBY, STARTING, PLAYING, ENDING, ENDED
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/Version.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Version.java
new file mode 100644
index 0000000..e2dcfdd
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/Version.java
@@ -0,0 +1,45 @@
+package net.tylermurphy.hideAndSeek.game.util;
+
+import org.bukkit.Bukkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Version {
+
+ private static final Map<String,Boolean> CACHE = new HashMap<>();
+
+ public static boolean atLeast(String testVersion) {
+
+
+ if (CACHE.containsKey(testVersion)) return CACHE.get(testVersion);
+
+ String[] serverCheckTemp = Bukkit.getBukkitVersion().substring(2,Bukkit.getBukkitVersion().indexOf('-')).split("\\.");
+ int[] serverCheck = new int[serverCheckTemp.length];
+ for(int i=0; i<serverCheck.length; i++) {
+ serverCheck[i] = Integer.parseInt(serverCheckTemp[i]);
+ }
+
+ String[] customCheckTemp = testVersion.substring(2).split("\\.");
+ int[] customCheck = new int[customCheckTemp.length];
+ for(int i=0; i<customCheck.length; i++) {
+ customCheck[i] = Integer.parseInt(customCheckTemp[i]);
+ }
+
+ boolean result = getResult(customCheck, serverCheck);
+ CACHE.put(testVersion, result);
+ return result;
+ }
+
+ private static boolean getResult(int[] customCheck, int[] serverCheck) {
+ if (customCheck[0] > serverCheck[0]) return false;
+ else if (customCheck[0] < serverCheck[0]) return true;
+ else {
+ if (customCheck.length == 1 && serverCheck.length == 1) return true;
+ else if (customCheck.length == 2 && serverCheck.length == 2) {
+ return customCheck[1] <= serverCheck[1];
+ }
+ else return serverCheck.length == 2;
+ }
+ }
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java b/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java
new file mode 100644
index 0000000..f584d80
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/util/WinType.java
@@ -0,0 +1,26 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2021 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.game.util;
+
+public enum WinType {
+
+ HIDER_WIN, SEEKER_WIN, NONE
+
+}