Merge pull request '1.7.1 - A few tweaks and bug squashes' (#5) from dev into main

Reviewed-on: https://g.tylerm.dev/tylermurphy534/KenshinsHideAndSeek/pulls/5
This commit is contained in:
tylermurphy534 2023-02-08 23:24:53 +00:00
commit b87174e770
21 changed files with 378 additions and 248 deletions

14
pom.xml
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>KenshinsHideAndSeek</artifactId> <artifactId>KenshinsHideAndSeek</artifactId>
<version>1.7.0</version> <version>1.7.1</version>
<name>Hide and Seek Plugin</name> <name>Hide and Seek Plugin</name>
<properties> <properties>
@ -47,8 +47,6 @@
<artifact>*:*</artifact> <artifact>*:*</artifact>
<excludes> <excludes>
<exclude>META-INF/**</exclude> <exclude>META-INF/**</exclude>
<exclude>sqlite-jdbc.properties</exclude>
<exclude>mariadb.properties</exclude>
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
@ -113,7 +111,7 @@
<dependency> <dependency>
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.39.3.0</version> <version>3.40.1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
@ -123,23 +121,23 @@
<dependency> <dependency>
<groupId>com.github.cryptomorin</groupId> <groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId> <artifactId>XSeries</artifactId>
<version>9.1.0</version> <version>9.2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
<version>2.11.1</version> <version>2.11.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>5.0.1</version> <version>4.0.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mariadb.jdbc</groupId> <groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId> <artifactId>mariadb-java-client</artifactId>
<version>3.0.6</version> <version>3.1.2</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -36,7 +36,7 @@ public class Border implements ICommand {
addToConfig("worldBorder.enabled",false); addToConfig("worldBorder.enabled",false);
saveConfig(); saveConfig();
sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder(); map.getWorldBorder().resetWorldBorder();
return; return;
} }
int num,delay,change; int num,delay,change;

View file

@ -51,7 +51,7 @@ public class CommandGroup {
if (data == null) { if (data == null) {
player.sendMessage( player.sendMessage(
String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.1%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

@ -61,7 +61,10 @@ public class Config {
mapSaveEnabled, mapSaveEnabled,
allowNaturalCauses, allowNaturalCauses,
saveInventory, saveInventory,
delayedRespawn; delayedRespawn,
spawnPatch,
dropItems,
regenHealth;
public static int public static int
minPlayers, minPlayers,
@ -115,7 +118,7 @@ public class Config {
announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers");
//Prefix //Prefix
char SYMBOL = '\u00A7'; char SYMBOL = '§';
String SYMBOL_STRING = String.valueOf(SYMBOL); String SYMBOL_STRING = String.valueOf(SYMBOL);
messagePrefix = config.getString("prefix.default").replace("&", SYMBOL_STRING); messagePrefix = config.getString("prefix.default").replace("&", SYMBOL_STRING);
@ -237,6 +240,10 @@ public class Config {
delayedRespawn = config.getBoolean("delayedRespawn.enabled"); delayedRespawn = config.getBoolean("delayedRespawn.enabled");
delayedRespawnDelay = Math.max(0,config.getInt("delayedRespawn.delay")); delayedRespawnDelay = Math.max(0,config.getInt("delayedRespawn.delay"));
spawnPatch = config.getBoolean("spawnPatch");
dropItems = config.getBoolean("dropItems");
regenHealth = config.getBoolean("regenHealth");
} }
public static void addToConfig(String path, Object value) { public static void addToConfig(String path, Object value) {

View file

@ -228,11 +228,14 @@ public class Map {
if (blockhunt && blockhuntBlocks.isEmpty()) return true; if (blockhunt && blockhuntBlocks.isEmpty()) return true;
if(isWorldBorderEnabled() && if(isWorldBorderEnabled() &&
new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true; new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true;
return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; return isBoundsNotSetup();
} }
public boolean isBoundsNotSetup() { public boolean isBoundsNotSetup() {
return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; if (xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0) return true;
int xDiff = xBoundMax - xBoundMin;
int zDiff = zBoundMax - zBoundMin;
return xDiff < 5 || zDiff < 5;
} }
} }

View file

@ -14,6 +14,7 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import static net.tylermurphy.hideAndSeek.configuration.Config.databasePort;
import static net.tylermurphy.hideAndSeek.configuration.Config.databaseType; import static net.tylermurphy.hideAndSeek.configuration.Config.databaseType;
public class Database { public class Database {
@ -25,12 +26,14 @@ public class Database {
public Database(){ public Database(){
if(databaseType.equals("SQLITE")) { if(databaseType.equalsIgnoreCase("SQLITE")) {
Main.getInstance().getLogger().info("SQLITE database chosen"); Main.getInstance().getLogger().info("SQLITE database chosen");
connection = new SQLiteConnection(); connection = new SQLiteConnection();
} else { } else if(databaseType.equalsIgnoreCase("MYSQL")) {
Main.getInstance().getLogger().info("MYSQL database chosen"); Main.getInstance().getLogger().info("MYSQL database chosen");
connection = new MySQLConnection(); connection = new MySQLConnection();
} else {
throw new IllegalArgumentException("Invalid database type: " + databaseType);
} }
playerInfo = new GameDataTable(this); playerInfo = new GameDataTable(this);

View file

@ -201,7 +201,7 @@ public class GameDataTable {
} }
protected void updateInfo(byte[] uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths){ protected void updateInfo(byte[] uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths){
String sql = "INSERT OR REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)"; String sql = "REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)";
try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) { try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setBytes(1, uuid); statement.setBytes(1, uuid);
statement.setInt(2, hider_wins); statement.setInt(2, hider_wins);

View file

@ -59,7 +59,7 @@ public class InventoryTable {
} }
public void saveInventory(@NotNull UUID uuid, @NotNull ItemStack[] itemArray) { public void saveInventory(@NotNull UUID uuid, @NotNull ItemStack[] itemArray) {
String sql = "INSERT OR REPLACE INTO hs_inventory (uuid, inventory) VALUES (?,?)"; String sql = "REPLACE INTO hs_inventory (uuid, inventory) VALUES (?,?)";
String data = itemStackArrayToBase64(itemArray); String data = itemStackArrayToBase64(itemArray);
try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) { try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setBytes(1, database.encodeUUID(uuid)); statement.setBytes(1, database.encodeUUID(uuid));

View file

@ -96,7 +96,7 @@ public class NameDataTable {
} }
public boolean update(@NotNull UUID uuid, @NotNull String name){ public boolean update(@NotNull UUID uuid, @NotNull String name){
String sql = "INSERT OR REPLACE INTO hs_names (uuid, name) VALUES (?,?)"; String sql = "REPLACE INTO hs_names (uuid, name) VALUES (?,?)";
try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) { try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setBytes(1, database.encodeUUID(uuid)); statement.setBytes(1, database.encodeUUID(uuid));
statement.setString(2, name); statement.setString(2, name);

View file

@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.Main;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
@ -43,7 +44,8 @@ public class MySQLConnection implements DatabaseConnection {
Main.getInstance().getLogger().info("Database name: " + databaseName); Main.getInstance().getLogger().info("Database name: " + databaseName);
config.setJdbcUrl("jdbc:mariadb://"+databaseHost+":"+databasePort+"/"+databaseName); config.setDriverClassName(org.mariadb.jdbc.Driver.class.getName());
config.setJdbcUrl("jdbc:mariadb://"+databaseHost+":"+databasePort+"/"+databaseName.trim());
config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

View file

@ -2,7 +2,6 @@ package net.tylermurphy.hideAndSeek.game;
import static com.comphenix.protocol.PacketType.Play.Server.*; import static com.comphenix.protocol.PacketType.Play.Server.*;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -31,7 +30,7 @@ public class EntityHider implements Listener {
private static final PacketType[] ENTITY_PACKETS = { private static final PacketType[] ENTITY_PACKETS = {
ENTITY_EQUIPMENT, ANIMATION, NAMED_ENTITY_SPAWN, ENTITY_EQUIPMENT, ANIMATION, NAMED_ENTITY_SPAWN,
COLLECT, SPAWN_ENTITY, SPAWN_ENTITY_LIVING, SPAWN_ENTITY_PAINTING, SPAWN_ENTITY_EXPERIENCE_ORB, COLLECT, SPAWN_ENTITY, SPAWN_ENTITY_EXPERIENCE_ORB,
ENTITY_VELOCITY, REL_ENTITY_MOVE, ENTITY_LOOK, ENTITY_VELOCITY, REL_ENTITY_MOVE, ENTITY_LOOK,
ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA, ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA,
ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION
@ -85,26 +84,38 @@ public class EntityHider implements Listener {
/** /**
* Add or remove the given entity and observer entry from the table. * Add or remove the given entity and observer entry from the table.
* @param observer - the player observer. * @param observer - the player observer.
* @param entityID - ID of the entity. * @param newEntityId - ID of the entity.
* @param member - TRUE if they should be present in the table, FALSE otherwise. * @param member - TRUE if they should be present in the table, FALSE otherwise.
* @return TRUE if they already were present, FALSE otherwise. * @return TRUE if they already were present, FALSE otherwise.
*/ */
protected boolean setMembership(Player observer, int entityID, boolean member) { protected boolean setMembership(Player observer, int newEntityId, boolean member) {
int entityID;
try {
entityID = observer.getEntityId();
} catch (Exception e) {
return member;
}
if (member) { if (member) {
return observerEntityMap.put(observer.getEntityId(), entityID, true) != null; return observerEntityMap.put(newEntityId, entityID, true) != null;
} else { } else {
return observerEntityMap.remove(observer.getEntityId(), entityID) != null; return observerEntityMap.remove(newEntityId, entityID) != null;
} }
} }
/** /**
* Determine if the given entity and observer is present in the table. * Determine if the given entity and observer is present in the table.
* @param observer - the player observer. * @param observer - the player observer.
* @param entityID - ID of the entity. * @param newEntityID - ID of the entity.
* @return TRUE if they are present, FALSE otherwise. * @return TRUE if they are present, FALSE otherwise.
*/ */
protected boolean getMembership(Player observer, int entityID) { protected boolean getMembership(Player observer, int newEntityID) {
return observerEntityMap.contains(observer.getEntityId(), entityID); int entityID;
try {
entityID = observer.getEntityId();
} catch (Exception e) {
return false;
}
return observerEntityMap.contains(entityID, newEntityID);
} }
/** /**
@ -125,7 +136,12 @@ public class EntityHider implements Listener {
* @param entity - the entity to remove. * @param entity - the entity to remove.
*/ */
protected void removeEntity(Entity entity) { protected void removeEntity(Entity entity) {
int entityID = entity.getEntityId(); int entityID;
try {
entityID = entity.getEntityId();
} catch (Exception e) {
return;
}
for (Map<Integer, Boolean> maps : observerEntityMap.rowMap().values()) { for (Map<Integer, Boolean> maps : observerEntityMap.rowMap().values()) {
maps.remove(entityID); maps.remove(entityID);
@ -137,8 +153,13 @@ public class EntityHider implements Listener {
* @param player - the player that jused logged out. * @param player - the player that jused logged out.
*/ */
protected void removePlayer(Player player) { protected void removePlayer(Player player) {
// Cleanup int entityID;
observerEntityMap.rowMap().remove(player.getEntityId()); try {
entityID = player.getEntityId();
} catch (Exception e) {
return;
}
observerEntityMap.rowMap().remove(entityID);
} }
/** /**
@ -195,7 +216,13 @@ public class EntityHider implements Listener {
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final boolean toggleEntity(Player observer, Entity entity) { public final boolean toggleEntity(Player observer, Entity entity) {
if (isVisible(observer, entity.getEntityId())) { int entityID;
try {
entityID = observer.getEntityId();
} catch (Exception e) {
return true;
}
if (isVisible(observer, entityID)) {
return hideEntity(observer, entity); return hideEntity(observer, entity);
} else { } else {
return !showEntity(observer, entity); return !showEntity(observer, entity);
@ -210,7 +237,13 @@ public class EntityHider implements Listener {
*/ */
public final boolean showEntity(Player observer, Entity entity) { public final boolean showEntity(Player observer, Entity entity) {
validate(observer, entity); validate(observer, entity);
boolean hiddenBefore = !setVisibility(observer, entity.getEntityId(), true); int entityID;
try {
entityID = entity.getEntityId();
} catch (Exception e) {
return false;
}
boolean hiddenBefore = !setVisibility(observer, entityID, true);
// Resend packets // Resend packets
if (manager != null && hiddenBefore) { if (manager != null && hiddenBefore) {
@ -227,12 +260,18 @@ public class EntityHider implements Listener {
*/ */
public final boolean hideEntity(Player observer, Entity entity) { public final boolean hideEntity(Player observer, Entity entity) {
validate(observer, entity); validate(observer, entity);
boolean visibleBefore = setVisibility(observer, entity.getEntityId(), false); int entityID;
try {
entityID = entity.getEntityId();
} catch (Exception e) {
return true;
}
boolean visibleBefore = setVisibility(observer, entityID, false);
if (visibleBefore) { if (visibleBefore) {
PacketContainer destroyEntity = new PacketContainer(ENTITY_DESTROY); PacketContainer destroyEntity = new PacketContainer(ENTITY_DESTROY);
try { try {
destroyEntity.getIntegerArrays().write(0, new int[]{entity.getEntityId()}); destroyEntity.getIntegerArrays().write(0, new int[]{entityID});
} catch (Exception e){ return false; } } catch (Exception e){ return false; }
// Make the entity disappear // Make the entity disappear
manager.sendServerPacket(observer, destroyEntity); manager.sendServerPacket(observer, destroyEntity);
@ -253,8 +292,13 @@ public class EntityHider implements Listener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final boolean canSee(Player observer, Entity entity) { public final boolean canSee(Player observer, Entity entity) {
validate(observer, entity); validate(observer, entity);
int entityID;
return isVisible(observer, entity.getEntityId()); try {
entityID = entity.getEntityId();
} catch (Exception e) {
return true;
}
return isVisible(observer, entityID);
} }
private void validate(Player observer, Entity entity) { private void validate(Player observer, Entity entity) {

View file

@ -186,7 +186,9 @@ public class Game {
PlayerLoader.unloadPlayer(player); PlayerLoader.unloadPlayer(player);
if(saveInventory) { if(saveInventory) {
ItemStack[] data = Main.getInstance().getDatabase().getInventoryData().getInventory(player.getUniqueId()); ItemStack[] data = Main.getInstance().getDatabase().getInventoryData().getInventory(player.getUniqueId());
try {
player.getInventory().setContents(data); player.getInventory().setContents(data);
} catch (NullPointerException ignored){}
} }
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
else broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); else broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
@ -240,6 +242,9 @@ public class Game {
} }
} else { } else {
lobbyTimer = -1; lobbyTimer = -1;
if (gameTick % 20 == 0) {
board.reloadLobbyBoards();
}
} }
} }

View file

@ -128,7 +128,6 @@ public class PlayerLoader {
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.ADVENTURE);
player.getInventory().clear(); player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()) { for(PotionEffect effect : player.getActivePotionEffects()) {
Main.getInstance().getLogger().severe(player.getName() + " " + effect.getType());
if(effect.getType().getName().equals("INVISIBILITY") && Main.getInstance().getDisguiser().disguised(player)) continue; if(effect.getType().getName().equals("INVISIBILITY") && Main.getInstance().getDisguiser().disguised(player)) continue;
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }

View file

@ -7,6 +7,10 @@ import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedEnumEntityUseAction;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.messages.ActionBar;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.game.util.Disguise; import net.tylermurphy.hideAndSeek.game.util.Disguise;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -33,18 +37,14 @@ public class DisguiseHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onMove(PlayerMoveEvent event) { public void onMove(PlayerMoveEvent event) {
final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(event.getPlayer()); final Player player = event.getPlayer();
if(disguise == null) return; final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(player);
final Location lastLocation = event.getPlayer().getLocation(); if(disguise == null) return;;
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { if(event.getFrom().distance(event.getTo()) > .1) {
final Location currentLocation = event.getPlayer().getLocation();
if(lastLocation.getWorld() != currentLocation.getWorld()) return;
double distance = lastLocation.distance(currentLocation);
disguise.setSolidify(distance < .1);
}, 20 * 3);
if(event.getFrom().distance(event.getTo()) > .1)
disguise.setSolidify(false); disguise.setSolidify(false);
} }
disguise.startSolidifying();
}
private PacketAdapter createProtocol(){ private PacketAdapter createProtocol(){
return new PacketAdapter(Main.getInstance(), USE_ENTITY) { return new PacketAdapter(Main.getInstance(), USE_ENTITY) {
@ -52,6 +52,12 @@ public class DisguiseHandler implements Listener {
@Override @Override
public void onPacketReceiving(PacketEvent event){ public void onPacketReceiving(PacketEvent event){
PacketContainer packet = event.getPacket(); PacketContainer packet = event.getPacket();
// only left click attacks
WrappedEnumEntityUseAction action = packet.getEnumEntityUseActions().getValues().stream().findFirst().orElse(null);
if (action == null) return;
if (action.getAction() != EnumWrappers.EntityUseAction.ATTACK) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
int id = packet.getIntegers().read(0); int id = packet.getIntegers().read(0);
Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id); Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id);

View file

@ -51,7 +51,7 @@ public class MovementHandler implements Listener {
if (!Main.getInstance().getBoard().contains(event.getPlayer())) return; if (!Main.getInstance().getBoard().contains(event.getPlayer())) return;
if (!event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) return; if (!event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) return;
if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) return; if (!event.getTo().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getGameSpawnName())) return;
if (event.getPlayer().hasPermission("hideandseek.leavebounds")) return; if (event.getPlayer().hasPermission("hs.leavebounds")) return;
Map map = Main.getInstance().getGame().getCurrentMap(); Map map = Main.getInstance().getGame().getCurrentMap();
if (event.getTo().getBlockX() < map.getBoundsMin().getBlockX() || event.getTo().getBlockX() > map.getBoundsMax().getBlockX() || event.getTo().getBlockZ() < map.getBoundsMin().getZ() || event.getTo().getBlockZ() > map.getBoundsMax().getZ()) { if (event.getTo().getBlockX() < map.getBoundsMin().getBlockX() || event.getTo().getBlockX() > map.getBoundsMax().getBlockX() || event.getTo().getBlockZ() < map.getBoundsMin().getZ() || event.getTo().getBlockZ() > map.getBoundsMax().getZ()) {
event.setCancelled(true); event.setCancelled(true);

View file

@ -13,6 +13,9 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import static net.tylermurphy.hideAndSeek.configuration.Config.dropItems;
import static net.tylermurphy.hideAndSeek.configuration.Config.regenHealth;
public class PlayerHandler implements Listener { public class PlayerHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -25,6 +28,7 @@ public class PlayerHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRegainHealth(EntityRegainHealthEvent event) { public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
if (regenHealth) return;
if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED || event.getRegainReason() == EntityRegainHealthEvent.RegainReason.REGEN) { if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED || event.getRegainReason() == EntityRegainHealthEvent.RegainReason.REGEN) {
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
if (!Main.getInstance().getBoard().contains((Player) event.getEntity())) return; if (!Main.getInstance().getBoard().contains((Player) event.getEntity())) return;
@ -35,7 +39,7 @@ public class PlayerHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onItemDrop(PlayerDropItemEvent event) { public void onItemDrop(PlayerDropItemEvent event) {
if (Main.getInstance().getBoard().contains(event.getPlayer())) { if (!dropItems && Main.getInstance().getBoard().contains(event.getPlayer())) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -45,6 +49,7 @@ public class PlayerHandler implements Listener {
if(Main.getInstance().getGame().getStatus() == Status.STANDBY) return; if(Main.getInstance().getGame().getStatus() == Status.STANDBY) return;
ItemStack item = event.getEntity().getItemStack(); ItemStack item = event.getEntity().getItemStack();
if (!Items.matchItem(item)) return; if (!Items.matchItem(item)) return;
if (dropItems) return;
event.setCancelled(true); event.setCancelled(true);
} }

View file

@ -1,5 +1,7 @@
package net.tylermurphy.hideAndSeek.game.util; package net.tylermurphy.hideAndSeek.game.util;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.messages.ActionBar;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.packet.BlockChangePacket; import net.tylermurphy.hideAndSeek.util.packet.BlockChangePacket;
import net.tylermurphy.hideAndSeek.util.packet.EntityTeleportPacket; import net.tylermurphy.hideAndSeek.util.packet.EntityTeleportPacket;
@ -20,7 +22,7 @@ public class Disguise {
FallingBlock block; FallingBlock block;
Horse hitBox; Horse hitBox;
Location blockLocation; Location blockLocation;
boolean solid, solidify; boolean solid, solidify, solidifying;
static Team hidden; static Team hidden;
static { static {
@ -172,4 +174,37 @@ public class Disguise {
} }
} }
public void startSolidifying() {
if (solidifying) return;
if (solid) return;
solidifying = true;
final Location lastLocation = hider.getLocation();
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> solidifyUpdate(lastLocation, 3), 10);
}
private void solidifyUpdate(Location lastLocation, int time) {
Location currentLocation = hider.getLocation();
if(lastLocation.getWorld() != currentLocation.getWorld()) {
solidifying = false;
return;
}
if(lastLocation.distance(currentLocation) > .1) {
solidifying = false;
return;
}
if(time == 0) {
ActionBar.clearActionBar(hider);
setSolidify(true);
solidifying = false;
} else {
StringBuilder s = new StringBuilder();
for (int i = 0; i < time; i++) {
s.append("");
}
ActionBar.sendActionBar(hider, s.toString());
XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, 1, 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> solidifyUpdate(lastLocation, time - 1), 20);
}
}
} }

View file

@ -11,6 +11,8 @@ import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import static net.tylermurphy.hideAndSeek.configuration.Config.spawnPatch;
public class Location { public class Location {
private final String world; private final String world;
@ -87,8 +89,12 @@ public class Location {
public void teleport(Player player) { public void teleport(Player player) {
if(!exists()) return; if(!exists()) return;
if(load() == null) return; if(load() == null) return;
if (spawnPatch) {
Main.getInstance().scheduleTask(() -> player.teleport(toBukkit()));
} else {
player.teleport(toBukkit()); player.teleport(toBukkit());
} }
}
public Location changeWorld(String world) { public Location changeWorld(String world) {
return new Location( return new Location(
@ -139,7 +145,7 @@ public class Location {
} }
public boolean isNotInBounds(int xmin, int xmax, int zmin, int zmax) { public boolean isNotInBounds(int xmin, int xmax, int zmin, int zmax) {
return getBlockX() < xmin || getBlockX() > xmax || getBlockZ() < zmin || getBlockZ() > zmax; return getBlockX() <= xmin || getBlockX() >= xmax || getBlockZ() <= zmin || getBlockZ() >= zmax;
} }
} }

View file

@ -6,6 +6,11 @@
# +--------------------------------------------------------+ # # +--------------------------------------------------------+ #
#============================================================# #============================================================#
# If you are having weird issues with your server where it's printing to the console
# "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH", try enabling the
# below spawn patch. WARNING: this will NOT work if you use Multiverse Inventory's.
spawnPatch: false
# How long in seconds will the game last, set it < 1 to disable # How long in seconds will the game last, set it < 1 to disable
# default: 1200 aka 20min # default: 1200 aka 20min
gameLength: 1200 gameLength: 1200
@ -14,6 +19,10 @@ gameLength: 1200
# default: true # default: true
announceMessagesToNonPlayers: true announceMessagesToNonPlayers: true
# Allow players to drop their items in game
# default: false
dropItems: false
# When the game is starting, the plugin will state there is x seconds left to hide. # When the game is starting, the plugin will state there is x seconds left to hide.
# You change where countdown messages are to be displayed: in the chat, action bar, or a title. # You change where countdown messages are to be displayed: in the chat, action bar, or a title.
# Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT. # Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT.
@ -46,6 +55,10 @@ minPlayers: 2
# default: true # default: true
pvp: true pvp: true
# Allow players to regen health
# default: false
regenHealth: false
# !! Only effects the game at all if pvp is set to false !! # !! Only effects the game at all if pvp is set to false !!
# By default, If you disable pvp, Hiders and Seekers can no longer take damage from natural causes such as # By default, If you disable pvp, Hiders and Seekers can no longer take damage from natural causes such as
# falling or projectiles. If you want, you can keep pvp disabled so that Seekers only have to tag Hiders, but # falling or projectiles. If you want, you can keep pvp disabled so that Seekers only have to tag Hiders, but

View file

@ -1 +1,3 @@
# PLEASE DO NOT EDIT THIS FILE
# ONLY EDIT IF YOU KNOW WHAT YOU ARE DOING
maps: maps:

View file

@ -1,6 +1,6 @@
name: KenshinsHideAndSeek name: KenshinsHideAndSeek
main: net.tylermurphy.hideAndSeek.Main main: net.tylermurphy.hideAndSeek.Main
version: 1.7.0 version: 1.7.1
author: KenshinEto author: KenshinEto
load: STARTUP load: STARTUP
api-version: 1.13 api-version: 1.13
@ -72,4 +72,6 @@ permissions:
default: op default: op
hs.confirm: hs.confirm:
default: op default: op
hs.leavebounds:
default: false