spawn patch, bounds checks, drop items, regen

This commit is contained in:
Tyler Murphy 2023-02-06 12:15:09 -05:00
parent 8fdd3461c1
commit 2139a8d5d3
9 changed files with 239 additions and 200 deletions

View file

@ -61,7 +61,10 @@ public class Config {
mapSaveEnabled,
allowNaturalCauses,
saveInventory,
delayedRespawn;
delayedRespawn,
spawnPatch,
dropItems,
regenHealth;
public static int
minPlayers,
@ -115,7 +118,7 @@ public class Config {
announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers");
//Prefix
char SYMBOL = '\u00A7';
char SYMBOL = '§';
String SYMBOL_STRING = String.valueOf(SYMBOL);
messagePrefix = config.getString("prefix.default").replace("&", SYMBOL_STRING);
@ -237,6 +240,10 @@ public class Config {
delayedRespawn = config.getBoolean("delayedRespawn.enabled");
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) {

View file

@ -228,11 +228,14 @@ public class Map {
if (blockhunt && blockhuntBlocks.isEmpty()) return true;
if(isWorldBorderEnabled() &&
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() {
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

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

View file

@ -51,7 +51,7 @@ public class MovementHandler implements Listener {
if (!Main.getInstance().getBoard().contains(event.getPlayer())) 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.getPlayer().hasPermission("hideandseek.leavebounds")) return;
if (event.getPlayer().hasPermission("hs.leavebounds")) return;
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()) {
event.setCancelled(true);

View file

@ -13,6 +13,9 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
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 {
@EventHandler(priority = EventPriority.HIGHEST)
@ -25,6 +28,7 @@ public class PlayerHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
if (regenHealth) return;
if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED || event.getRegainReason() == EntityRegainHealthEvent.RegainReason.REGEN) {
if (event.getEntity() instanceof Player) {
if (!Main.getInstance().getBoard().contains((Player) event.getEntity())) return;
@ -35,7 +39,7 @@ public class PlayerHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemDrop(PlayerDropItemEvent event) {
if (Main.getInstance().getBoard().contains(event.getPlayer())) {
if (!dropItems && Main.getInstance().getBoard().contains(event.getPlayer())) {
event.setCancelled(true);
}
}

View file

@ -11,6 +11,8 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
import static net.tylermurphy.hideAndSeek.configuration.Config.spawnPatch;
public class Location {
private final String world;
@ -87,8 +89,12 @@ public class Location {
public void teleport(Player player) {
if(!exists()) return;
if(load() == null) return;
if (spawnPatch) {
Main.getInstance().scheduleTask(() -> player.teleport(toBukkit()));
} else {
player.teleport(toBukkit());
}
}
public Location changeWorld(String world) {
return new Location(
@ -139,7 +145,7 @@ public class Location {
}
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
# default: 1200 aka 20min
gameLength: 1200
@ -14,6 +19,10 @@ gameLength: 1200
# default: 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.
# 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.
@ -46,6 +55,10 @@ minPlayers: 2
# default: true
pvp: true
# Allow players to regen health
# default: false
regenHealth: 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
# 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:

View file

@ -72,4 +72,6 @@ permissions:
default: op
hs.confirm:
default: op
hs.leavebounds:
default: false