summaryrefslogtreewikicommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-04-11 12:36:11 -0400
committerTyler Murphy <tylermurphy534@gmail.com>2022-04-11 12:36:11 -0400
commite9daa954737864b124e7b4d0d29f8fa24da70e22 (patch)
tree08966c75f7bc84083bd573daee0fc23115f2b6d7 /src
parentMerge pull request #20 from tylermurphy534/1.3.3 (diff)
downloadkenshinshideandseek-e9daa954737864b124e7b4d0d29f8fa24da70e22.tar.gz
kenshinshideandseek-e9daa954737864b124e7b4d0d29f8fa24da70e22.tar.bz2
kenshinshideandseek-e9daa954737864b124e7b4d0d29f8fa24da70e22.zip
1.4.0 initial
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/About.java2
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java21
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java14
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java38
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java6
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/database/Database.java7
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/Board.java39
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java25
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/game/Game.java58
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java24
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/Version.java45
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java115
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java158
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java18
-rw-r--r--src/main/resources/config.yml12
-rw-r--r--src/main/resources/plugin.yml12
16 files changed, 523 insertions, 71 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java
index de1062b..bfc6c85 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java
@@ -26,7 +26,7 @@ public class About implements ICommand {
public void execute(CommandSender sender, String[] args) {
sender.sendMessage(
- String.format("%s%sHide and Seek %s(%s1.3.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
+ String.format("%s%sHide and Seek %s(%s1.4.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index 524eeac..98b27b2 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -19,6 +19,7 @@
package net.tylermurphy.hideAndSeek.configuration;
+import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.util.Vector;
public class Config {
@@ -36,7 +37,7 @@ public class Config {
spawnWorld,
exitWorld,
lobbyWorld,
- local;
+ locale;
public static Vector
spawnPosition,
@@ -57,7 +58,8 @@ public class Config {
pvpEnabled,
autoJoin,
teleportToExit,
- lobbyCountdownEnabled;
+ lobbyCountdownEnabled,
+ seekerPing;
public static int
minPlayers,
@@ -74,7 +76,10 @@ public class Config {
countdown,
changeCountdown,
lobbyMin,
- lobbyMax;
+ lobbyMax,
+ seekerPingLevel1,
+ seekerPingLevel2,
+ seekerPingLevel3;
public static void loadConfig() {
@@ -143,7 +148,7 @@ public class Config {
//Glow
glowLength = Math.max(1,manager.getInt("glow.time"));
glowStackable = manager.getBoolean("glow.stackable");
- glowEnabled = manager.getBoolean("glow.enabled");
+ glowEnabled = manager.getBoolean("glow.enabled") && Version.atLeast("1.9");
//Lobby
minPlayers = Math.max(2, manager.getInt("minPlayers"));
@@ -153,6 +158,12 @@ public class Config {
lobbyMax = manager.getInt("lobby.max");
lobbyCountdownEnabled = manager.getBoolean("lobby.enabled");
+ //SeekerPing
+ seekerPing = manager.getBoolean("seekerPing.enabled");
+ seekerPingLevel1 = manager.getInt("seekerPing.distances.level1");
+ seekerPingLevel2 = manager.getInt("seekerPing.distances.level2");
+ seekerPingLevel3 = manager.getInt("seekerPing.distances.level3");
+
//Other
nametagsVisible = manager.getBoolean("nametagsVisible");
permissionsRequired = manager.getBoolean("permissionsRequired");
@@ -160,7 +171,7 @@ public class Config {
pvpEnabled = manager.getBoolean("pvp");
autoJoin = manager.getBoolean("autoJoin");
teleportToExit = manager.getBoolean("teleportToExit");
- local = manager.getString("local");
+ locale = manager.getString("locale", "local");
}
public static void addToConfig(String path, Object value) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index 84ad5b4..2217273 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -130,6 +130,20 @@ public class ConfigManager {
}
}
+ public String getString(String path, String oldPath){
+ String value = config.getString(path);
+ if(value == null){
+ String oldValue = config.getString(oldPath);
+ if(oldValue == null){
+ return defaultConfig.getString(path);
+ } else {
+ return oldValue;
+ }
+ } else {
+ return value;
+ }
+ }
+
public void reset(String path){
config.set(path, defaultConfig.get(path));
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
index 569cae6..99bc74c 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
@@ -19,9 +19,13 @@
package net.tylermurphy.hideAndSeek.configuration;
+import com.cryptomorin.xseries.XEnchantment;
+import com.cryptomorin.xseries.XMaterial;
+import com.cryptomorin.xseries.XPotion;
+import net.tylermurphy.hideAndSeek.util.Version;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
-import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
@@ -63,7 +67,6 @@ public class Items {
if(item != null) HIDER_ITEMS.add(item);
i++;
}
-
SEEKER_EFFECTS = new ArrayList<>();
ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker");
i = 1;
@@ -91,18 +94,22 @@ public class Items {
private static ItemStack createItem(ConfigurationSection item) {
String material_string = item.getString("material");
if(material_string == null) return null;
- Material material = Material.valueOf(material_string.toUpperCase());
+ if(!XMaterial.matchXMaterial(material_string.toUpperCase()).isPresent()) return null;
+ Material material = XMaterial.matchXMaterial(material_string.toUpperCase()).get().parseMaterial();
int amount = item.getInt("amount");
+ if(material == null) return null;
ItemStack stack = new ItemStack(material, amount);
- if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){
+ if(material == XMaterial.POTION.parseMaterial() || material == XMaterial.SPLASH_POTION.parseMaterial() || material == XMaterial.LINGERING_POTION.parseMaterial()){
PotionMeta meta = getPotionMeta(stack, item);
+ if(meta == null) return null;
stack.setItemMeta(meta);
} else {
ConfigurationSection enchantments = item.getConfigurationSection("enchantments");
if (enchantments != null)
for (String enchantment_string : enchantments.getKeys(false)) {
- Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantment_string));
+ if(!XEnchantment.matchXEnchantment(enchantment_string).isPresent()) continue;
+ Enchantment enchantment = XEnchantment.matchXEnchantment(enchantment_string).get().getEnchant();
if (enchantment == null) continue;
stack.addUnsafeEnchantment(
enchantment,
@@ -121,23 +128,38 @@ public class Items {
String name = item.getString("name");
if(name != null)
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
- meta.setUnbreakable(item.getBoolean("unbreakable"));
+ if(Version.atLeast("1.11")){
+ meta.setUnbreakable(item.getBoolean("unbreakable"));
+ } else {
+ meta.spigot().setUnbreakable(true);
+ }
meta.setLore(item.getStringList("lore"));
return meta;
}
- private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item){
+ private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item) {
String type = item.getString("type");
PotionMeta meta = (PotionMeta) stack.getItemMeta();
if(type==null) return meta;
assert meta != null;
- meta.setBasePotionData(new PotionData((PotionType.valueOf(type.toUpperCase()))));
+ XPotion.Effect potionEffect = XPotion.parseEffect(type.toUpperCase());
+ if(potionEffect == null) return null;
+ XPotion xpotion = potionEffect.getXPotion();
+ if(xpotion == null) return null;
+ PotionEffectType potionType = xpotion.getPotionEffectType();
+ if(potionType == null) return null;
+ if(Version.atLeast("1.9")) {
+ meta.setBasePotionData(new PotionData(xpotion.getPotionType()));
+ } else {
+ meta.setMainEffect(potionType);
+ }
return meta;
}
private static PotionEffect getPotionEffect(ConfigurationSection item){
String type = item.getString("type");
if(type == null) return null;
+ if(PotionEffectType.getByName(type.toUpperCase()) == null) return null;
return new PotionEffect(
Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())),
item.getInt("duration"),
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
index d5ae01d..5ea9e53 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
@@ -33,7 +33,7 @@ public class Localization {
public static void loadLocalization() {
- ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.local+".yml");
+ ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.locale +".yml");
int PLUGIN_VERSION = 2;
int VERSION = manager.getInt("version");
@@ -50,8 +50,8 @@ public class Localization {
String SELECTED_LOCAL = manager.getString("type");
if(SELECTED_LOCAL == null){
manager.reset("type");
- } else if(!SELECTED_LOCAL.equals(Config.local)){
- manager.resetFile("lang"+File.separator+"localization_"+Config.local+".yml");
+ } else if(!SELECTED_LOCAL.equals(Config.locale)){
+ manager.resetFile("lang"+File.separator+"localization_"+Config.locale +".yml");
}
manager.saveConfig();
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java
index 602c948..9a0837b 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java
@@ -68,6 +68,13 @@ public class Database {
}
public static void init(){
+ try {
+ Class.forName("org.sqlite.JDBC");
+ } catch (ClassNotFoundException e) {
+ Main.plugin.getLogger().severe("Unable to load SQLite driver!");
+ System.exit(-1);
+ return;
+ }
playerInfo = new PlayerInfoTable();
}
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java
index 936f7ac..71060b9 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -275,8 +276,13 @@ class CustomBoard {
this.board = manager.getNewScoreboard();
this.LINES = new HashMap<>();
this.player = player;
- this.obj = board.registerNewObjective(
- "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
+ if(Version.atLeast("1.13")){
+ this.obj = board.registerNewObjective(
+ "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
+ } else {
+ this.obj = board.registerNewObjective("Scoreboard", "dummy");
+ this.obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', title));
+ }
this.blanks = 0;
this.displayed = false;
this.updateTeams();
@@ -297,15 +303,30 @@ class CustomBoard {
seekerTeam.removeEntry(entry);
for(Player player : Board.getSeekers())
seekerTeam.addEntry(player.getName());
- if(nametagsVisible) {
- hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
- seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
+ if(Version.atLeast("1.9")){
+ if(nametagsVisible) {
+ hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
+ seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
+ } else {
+ hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ }
+ } else {
+ if(nametagsVisible) {
+ hiderTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
+ seekerTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OWN_TEAM);
+ } else {
+ hiderTeam.setNameTagVisibility(NameTagVisibility.NEVER);
+ seekerTeam.setNameTagVisibility(NameTagVisibility.NEVER);
+ }
+ }
+ if(Version.atLeast("1.12")){
+ hiderTeam.setColor(ChatColor.GOLD);
+ seekerTeam.setColor(ChatColor.RED);
} else {
- hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
- seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
+ hiderTeam.setPrefix(ChatColor.translateAlternateColorCodes('&', "&6"));
+ seekerTeam.setPrefix(ChatColor.translateAlternateColorCodes('&', "&c"));
}
- hiderTeam.setColor(ChatColor.GOLD);
- seekerTeam.setColor(ChatColor.RED);
}
public void setLine(String key, String message){
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java
index 42589bc..10fc8db 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java
@@ -21,8 +21,11 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import com.cryptomorin.xseries.XMaterial;
+import com.cryptomorin.xseries.XSound;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@@ -178,16 +181,23 @@ public class EventListener implements Listener {
}
}
}
- if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) {
+ if (player.getHealth() - event.getFinalDamage() < 0 || !pvpEnabled) {
if (spawnPosition == null) return;
event.setCancelled(true);
- AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
- if(attribute != null)
- player.setHealth(attribute.getValue());
+ 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());
+ }
player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
- Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
+ if(Version.atLeast("1.9")){
+ XSound.ENTITY_PLAYER_DEATH.play(player, 1, 1);
+ } else {
+ XSound.ENTITY_PLAYER_HURT.play(player, 1, 1);
+ }
if (Board.isSeeker(player)) {
- Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
+ Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
}
if (Board.isHider(player)) {
if (attacker == null) {
@@ -217,7 +227,8 @@ public class EventListener implements Listener {
if(Board.isHider(player)) {
Game.glow.onProjectile();
snowball.remove();
- player.getInventory().remove(Material.SNOWBALL);
+ assert XMaterial.SNOWBALL.parseMaterial() != null;
+ player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial());
}
}
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
index 225eab0..3b1a0dd 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java
@@ -21,14 +21,19 @@ package net.tylermurphy.hideAndSeek.game;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import com.cryptomorin.xseries.XMaterial;
+import com.cryptomorin.xseries.XSound;
+import com.cryptomorin.xseries.messages.Titles;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.util.Version;
import net.tylermurphy.hideAndSeek.util.WinType;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
+import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
@@ -42,7 +47,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
-import java.beans.EventHandler;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
@@ -92,11 +96,11 @@ public class Game {
for(Player player : Board.getSeekers()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
- player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20);
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString());
}
for(Player player : Board.getHiders()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
- player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20);
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
}
if(tauntEnabled)
taunt = new Taunt();
@@ -153,8 +157,10 @@ public class Game {
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
- for(Player temp : Board.getPlayers()) {
- Packet.setGlow(player, temp, false);
+ if(Version.atLeast("1.9")){
+ for(Player temp : Board.getPlayers()) {
+ Packet.setGlow(player, temp, false);
+ }
}
}
EventListener.temp_loc.clear();
@@ -207,7 +213,8 @@ public class Game {
for(PotionEffect effect : Items.HIDER_EFFECTS)
player.addPotionEffect(effect);
if(glowEnabled) {
- ItemStack snowball = new ItemStack(Material.SNOWBALL, 1);
+ assert XMaterial.SNOWBALL.parseMaterial() != null;
+ ItemStack snowball = new ItemStack(XMaterial.SNOWBALL.parseMaterial(), 1);
ItemMeta snowballMeta = snowball.getItemMeta();
assert snowballMeta != null;
snowballMeta.setDisplayName("Glow Powerup");
@@ -238,11 +245,16 @@ public class Game {
player.setGameMode(GameMode.SPECTATOR);
Board.createGameBoard(player);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
- player.sendTitle(ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString(), 10, 70, 20);
+ Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString());
}
player.setFoodLevel(20);
- player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue());
+ 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());
+ }
}
public static void removeItems(Player player){
@@ -296,20 +308,36 @@ public class Game {
distance = temp;
}
}
- switch(tick%10) {
+// if(seekerPing) switch(tick%10) {
+// case 0:
+// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .5f, 1f);
+// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f);
+// break;
+// case 3:
+// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .3f, 1f);
+// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f);
+// break;
+// case 6:
+// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f);
+// break;
+// case 9:
+// if(distance < seekerPingLevel2) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f);
+// break;
+// }
+ if(seekerPing) switch(tick%10) {
case 0:
- if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
- if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .5f, 1f);
+ if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
case 3:
- if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
- if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .3f, 1f);
+ if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
case 6:
- if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
case 9:
- if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
+ if(distance < seekerPingLevel2) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f);
break;
}
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java
index 18913da..d793f46 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java
@@ -21,6 +21,8 @@ package net.tylermurphy.hideAndSeek.util;
import java.lang.reflect.InvocationTargetException;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.util.protocollib.WrapperPlayServerNamedSoundEffect;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@@ -38,19 +40,15 @@ public class Packet {
private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
public static void playSound(Player player, Sound sound, float volume, float pitch) {
- PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT);
- packet.getSoundCategories().write(0, SoundCategory.MASTER);
- packet.getSoundEffects().write(0, sound);
- packet.getIntegers().write(0, (int)(player.getLocation().getX() * 8.0));
- packet.getIntegers().write(1, (int)(player.getLocation().getY() * 8.0));
- packet.getIntegers().write(2, (int)(player.getLocation().getZ() * 8.0));
- packet.getFloat().write(0, volume);
- packet.getFloat().write(1, pitch);
- try {
- protocolManager.sendServerPacket(player, packet);
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
+ WrapperPlayServerNamedSoundEffect packet = new WrapperPlayServerNamedSoundEffect();
+ packet.setSoundCategory(SoundCategory.MASTER);
+ packet.setSoundEffect(sound);
+ packet.setEffectPositionX((int)(player.getLocation().getX() * 8.0));
+ packet.setEffectPositionY((int)(player.getLocation().getY() * 8.0));
+ packet.setEffectPositionZ((int)(player.getLocation().getZ() * 8.0));
+ packet.setPitch(pitch);
+ packet.setVolume(volume);
+ packet.sendPacket(player);
}
public static void setGlow(Player player, Player target, boolean glowing) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Version.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Version.java
new file mode 100644
index 0000000..96854db
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Version.java
@@ -0,0 +1,45 @@
+package net.tylermurphy.hideAndSeek.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/util/protocollib/AbstractPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java
new file mode 100644
index 0000000..f6bd15a
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java
@@ -0,0 +1,115 @@
+/**
+ * PacketWrapper - ProtocolLib wrappers for Minecraft packets
+ * Copyright (C) dmulloy2 <http://dmulloy2.net>
+ * Copyright (C) Kristian S. Strangeland
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.util.protocollib;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.bukkit.entity.Player;
+
+import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.ProtocolLibrary;
+import com.comphenix.protocol.events.PacketContainer;
+import com.google.common.base.Objects;
+
+public abstract class AbstractPacket {
+ // The packet we will be modifying
+ protected PacketContainer handle;
+
+ /**
+ * Constructs a new strongly typed wrapper for the given packet.
+ *
+ * @param handle - handle to the raw packet data.
+ * @param type - the packet type.
+ */
+ protected AbstractPacket(PacketContainer handle, PacketType type) {
+ // Make sure we're given a valid packet
+ if (handle == null)
+ throw new IllegalArgumentException("Packet handle cannot be NULL.");
+ if (!Objects.equal(handle.getType(), type))
+ throw new IllegalArgumentException(handle.getHandle()
+ + " is not a packet of type " + type);
+
+ this.handle = handle;
+ }
+
+ /**
+ * Retrieve a handle to the raw packet data.
+ *
+ * @return Raw packet data.
+ */
+ public PacketContainer getHandle() {
+ return handle;
+ }
+
+ /**
+ * Send the current packet to the given receiver.
+ *
+ * @param receiver - the receiver.
+ * @throws RuntimeException If the packet cannot be sent.
+ */
+ public void sendPacket(Player receiver) {
+ try {
+ ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
+ getHandle());
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Cannot send packet.", e);
+ }
+ }
+
+ /**
+ * Send the current packet to all online players.
+ */
+ public void broadcastPacket() {
+ ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
+ }
+
+ /**
+ * Simulate receiving the current packet from the given sender.
+ *
+ * @param sender - the sender.
+ * @throws RuntimeException If the packet cannot be received.
+ * @deprecated Misspelled. recieve to receive
+ * @see #receivePacket(Player)
+ */
+ @Deprecated
+ public void recievePacket(Player sender) {
+ try {
+ ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
+ getHandle());
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot recieve packet.", e);
+ }
+ }
+
+ /**
+ * Simulate receiving the current packet from the given sender.
+ *
+ * @param sender - the sender.
+ * @throws RuntimeException if the packet cannot be received.
+ */
+ public void receivePacket(Player sender) {
+ try {
+ ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
+ getHandle());
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot receive packet.", e);
+ }
+ }
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java
new file mode 100644
index 0000000..5851a75
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java
@@ -0,0 +1,158 @@
+/**
+ * PacketWrapper - ProtocolLib wrappers for Minecraft packets
+ * Copyright (C) dmulloy2 <http://dmulloy2.net>
+ * Copyright (C) Kristian S. Strangeland
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.util.protocollib;
+
+import org.bukkit.Sound;
+
+import com.comphenix.protocol.PacketType;
+import com.comphenix.protocol.events.PacketContainer;
+import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory;
+
+public class WrapperPlayServerNamedSoundEffect extends AbstractPacket {
+ public static final PacketType TYPE =
+ PacketType.Play.Server.NAMED_SOUND_EFFECT;
+
+ public WrapperPlayServerNamedSoundEffect() {
+ super(new PacketContainer(TYPE), TYPE);
+ handle.getModifier().writeDefaults();
+ }
+
+ public WrapperPlayServerNamedSoundEffect(PacketContainer packet) {
+ super(packet, TYPE);
+ }
+
+ public Sound getSoundEffect() {
+ return handle.getSoundEffects().read(0);
+ }
+
+ public void setSoundEffect(Sound value) {
+ handle.getSoundEffects().write(0, value);
+ }
+
+ public SoundCategory getSoundCategory() {
+ return handle.getSoundCategories().read(0);
+ }
+
+ public void setSoundCategory(SoundCategory value) {
+ handle.getSoundCategories().write(0, value);
+ }
+
+ /**
+ * Retrieve Effect position X.
+ * <p>
+ * Notes: effect X multiplied by 8
+ *
+ * @return The current Effect position X
+ */
+ public int getEffectPositionX() {
+ return handle.getIntegers().read(0);
+ }
+
+ /**
+ * Set Effect position X.
+ *
+ * @param value - new value.
+ */
+ public void setEffectPositionX(int value) {
+ handle.getIntegers().write(0, value);
+ }
+
+ /**
+ * Retrieve Effect position Y.
+ * <p>
+ * Notes: effect Y multiplied by 8
+ *
+ * @return The current Effect position Y
+ */
+ public int getEffectPositionY() {
+ return handle.getIntegers().read(1);
+ }
+
+ /**
+ * Set Effect position Y.
+ *
+ * @param value - new value.
+ */
+ public void setEffectPositionY(int value) {
+ handle.getIntegers().write(1, value);
+ }
+
+ /**
+ * Retrieve Effect position Z.
+ * <p>
+ * Notes: effect Z multiplied by 8
+ *
+ * @return The current Effect position Z
+ */
+ public int getEffectPositionZ() {
+ return handle.getIntegers().read(2);
+ }
+
+ /**
+ * Set Effect position Z.
+ *
+ * @param value - new value.
+ */
+ public void setEffectPositionZ(int value) {
+ handle.getIntegers().write(2, value);
+ }
+
+ /**
+ * Retrieve Volume.
+ * <p>
+ * Notes: 1 is 100%, can be more
+ *
+ * @return The current Volume
+ */
+ public float getVolume() {
+ return handle.getFloat().read(0);
+ }
+
+ /**
+ * Set Volume.
+ *
+ * @param value - new value.
+ */
+ public void setVolume(float value) {
+ handle.getFloat().write(0, value);
+ }
+
+ /**
+ * Retrieve Pitch.
+ * <p>
+ * Notes: 63 is 100%, can be more
+ *
+ * @return The current Pitch
+ */
+ public float getPitch() {
+ return handle.getFloat().read(1);
+ }
+
+ /**
+ * Set Pitch.
+ *
+ * @param value - new value.
+ */
+ public void setPitch(float value) {
+ handle.getFloat().write(1, value);
+ }
+
+}
+
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java
index 5d6e377..011d334 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java
@@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
@@ -63,7 +64,7 @@ public class WorldLoader {
}
public void loadMap(){
- Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator()));
+ Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator()));
World world = Bukkit.getServer().getWorld(savename);
if(world == null){
Main.plugin.getLogger().severe("COULD NOT LOAD " + savename);
@@ -111,7 +112,10 @@ public class WorldLoader {
private void copyFileFolder(String name, Boolean isMca) throws IOException {
File region = new File(Main.root+File.separator+mapname+File.separator+name);
File temp = new File(Main.root+File.separator+"temp_"+savename+File.separator+name);
+ System.out.println(region.getAbsolutePath());
+ System.out.println(temp.getAbsolutePath());
if(region.exists() && region.isDirectory()) {
+ System.out.println("passed");
if(!temp.exists())
if(!temp.mkdirs())
throw new IOException("Couldn't create region directory!");
@@ -121,17 +125,17 @@ public class WorldLoader {
return;
}
for (String file : files) {
-
+ System.out.println("Testing file "+ file);
if(isMca) {
- int minX = (int)Math.floor(saveMinX / 32.0);
- int minZ = (int)Math.floor(saveMinZ / 32.0);
- int maxX = (int)Math.floor(saveMaxX / 32.0);
- int maxZ = (int)Math.floor(saveMaxZ / 32.0);
+ int minX = (int)Math.floor(saveMinX / 512.0);
+ int minZ = (int)Math.floor(saveMinZ / 512.0);
+ int maxX = (int)Math.floor(saveMaxX / 512.0);
+ int maxZ = (int)Math.floor(saveMaxZ / 512.0);
String[] parts = file.split("\\.");
if(parts.length > 1) {
Main.plugin.getLogger().info(file);
- if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX ||Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ )
+ if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX || Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ )
continue;
}
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 778e3b4..1e3cbda 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -90,10 +90,20 @@ lobby:
max: 10
enabled: true
+# 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.
+# The higher the level, the closer the seeker.
+seekerPing:
+ distances:
+ level1: 30
+ level2: 20
+ level3: 10
+ enabled: true
+
# Changes the default plugin language. Currently, Supported localizations are:
# en-US (English - United States)
# de-DE (German - Germany)
-local: "en-US"
+locale: "en-US"
# ---------------------------------------------------------- #
# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING #
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index bd391c9..c03205c 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,9 +1,9 @@
name: HideAndSeek
main: net.tylermurphy.hideAndSeek.Main
-version: 1.3.3
+version: 1.4.0
author: KenshinEto
load: STARTUP
-api-version: 1.14
+api-version: 1.13
depend: [ProtocolLib]
commands:
hideandseek:
@@ -29,6 +29,8 @@ permissions:
hideandseek.join: true
hideandseek.leave: true
hideandseek.leavebounds: true
+ hideandseek.wins: true
+ hideand.top: true
hideandseek.about:
description: Allows you to run the about command
default: true
@@ -74,3 +76,9 @@ permissions:
hideandseek.leavebounds:
description: Allows players to leave specified game bounderies
default: op
+ hideandseek.wins:
+ description: Allows players to see a players amount of wins
+ default: true
+ hideandseek.top:
+ description: Allows players to see the global wins leaderboard
+ default: true