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, 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

@ -15,224 +15,227 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*;
public class Map { public class Map {
private final String name; private final String name;
private Location private Location
spawnPosition = Location.getDefault(), spawnPosition = Location.getDefault(),
lobbyPosition = Location.getDefault(), lobbyPosition = Location.getDefault(),
seekerLobbyPosition = Location.getDefault(); seekerLobbyPosition = Location.getDefault();
private int private int
xBoundMin = 0, xBoundMin = 0,
zBoundMin = 0, zBoundMin = 0,
xBoundMax = 0, xBoundMax = 0,
zBoundMax = 0, zBoundMax = 0,
xWorldBorder = 0, xWorldBorder = 0,
zWorldBorder = 0, zWorldBorder = 0,
worldBorderSize = 0, worldBorderSize = 0,
worldBorderDelay = 0, worldBorderDelay = 0,
worldBorderChange = 0; worldBorderChange = 0;
private boolean private boolean
blockhunt = false; blockhunt = false;
private List<Material> private List<Material>
blockhuntBlocks = new ArrayList<>(); blockhuntBlocks = new ArrayList<>();
private final Border private final Border
worldBorder; worldBorder;
private final WorldLoader private final WorldLoader
worldLoader; worldLoader;
public Map(String name) { public Map(String name) {
this.name = name; this.name = name;
this.worldBorder = new Border(this); this.worldBorder = new Border(this);
this.worldLoader = new WorldLoader(this); this.worldLoader = new WorldLoader(this);
}
public void setSpawn(Location pos) {
this.spawnPosition = pos;
}
public void setLobby(Location pos) {
this.lobbyPosition = pos;
}
public void setSeekerLobby(Location pos) {
this.seekerLobbyPosition = pos;
}
public void setWorldBorderData(int x, int z, int size, int delay, int move) {
if(size < 1) {
this.worldBorderSize = 0;
this.worldBorderDelay = 0;
this.worldBorderChange = 0;
this.xWorldBorder = 0;
this.zWorldBorder = 0;
} else {
this.worldBorderSize = size;
this.worldBorderDelay = delay;
this.worldBorderChange = move;
this.xWorldBorder = x;
this.zWorldBorder = z;
} }
this.worldBorder.resetWorldBorder();
}
public void setBlockhunt(boolean enabled, List<Material> blocks) { public void setSpawn(Location pos) {
if (Main.getInstance().supports(9)) { this.spawnPosition = pos;
this.blockhunt = enabled;
} else {
this.blockhunt = false;
} }
this.blockhuntBlocks = blocks;
}
public void setBoundMin(int x, int z) { public void setLobby(Location pos) {
this.xBoundMin = x; this.lobbyPosition = pos;
this.zBoundMin = z;
}
public void setBoundMax(int x, int z) {
this.xBoundMax = x;
this.zBoundMax = z;
}
@NotNull
public Location getGameSpawn() {
if(mapSaveEnabled) {
return spawnPosition.changeWorld("hs_"+name);
} else {
return spawnPosition;
} }
}
@NotNull public void setSeekerLobby(Location pos) {
public String getGameSpawnName() { this.seekerLobbyPosition = pos;
if(mapSaveEnabled)
return getGameSpawn().getWorld();
else
return getSpawn().getWorld();
}
@NotNull
public Location getSpawn() {
return spawnPosition;
}
@NotNull
public String getSpawnName() {
return getSpawn().getWorld();
}
@NotNull
public Location getLobby() {
return lobbyPosition;
}
@NotNull
public String getLobbyName() {
return getLobby().getWorld();
}
@NotNull
public Location getSeekerLobby() {
return seekerLobbyPosition;
}
@NotNull
public String getSeekerLobbyName() {
return getSeekerLobby().getWorld();
}
@NotNull
public Location getGameSeekerLobby() {
if(mapSaveEnabled) {
return seekerLobbyPosition.changeWorld("hs_"+name);
} else {
return seekerLobbyPosition;
} }
}
public boolean isWorldBorderEnabled() { public void setWorldBorderData(int x, int z, int size, int delay, int move) {
return worldBorderSize > 0; if(size < 1) {
} this.worldBorderSize = 0;
this.worldBorderDelay = 0;
this.worldBorderChange = 0;
this.xWorldBorder = 0;
this.zWorldBorder = 0;
} else {
this.worldBorderSize = size;
this.worldBorderDelay = delay;
this.worldBorderChange = move;
this.xWorldBorder = x;
this.zWorldBorder = z;
}
this.worldBorder.resetWorldBorder();
}
@NotNull public void setBlockhunt(boolean enabled, List<Material> blocks) {
public Vector getWorldBorderPos() { if (Main.getInstance().supports(9)) {
return new Vector( this.blockhunt = enabled;
xWorldBorder, } else {
0, this.blockhunt = false;
zWorldBorder }
); this.blockhuntBlocks = blocks;
} }
@NotNull public void setBoundMin(int x, int z) {
public Vector getWorldBorderData() { this.xBoundMin = x;
return new Vector( this.zBoundMin = z;
worldBorderSize, }
worldBorderDelay,
worldBorderChange
);
}
@NotNull public void setBoundMax(int x, int z) {
public Border getWorldBorder() { this.xBoundMax = x;
return worldBorder; this.zBoundMax = z;
} }
public boolean isBlockHuntEnabled() { @NotNull
return blockhunt; public Location getGameSpawn() {
} if(mapSaveEnabled) {
return spawnPosition.changeWorld("hs_"+name);
} else {
return spawnPosition;
}
}
@NotNull @NotNull
public List<Material> getBlockHunt() { public String getGameSpawnName() {
return blockhuntBlocks; if(mapSaveEnabled)
} return getGameSpawn().getWorld();
else
return getSpawn().getWorld();
}
@NotNull @NotNull
public Vector getBoundsMin() { public Location getSpawn() {
return new Vector( return spawnPosition;
xBoundMin, }
0,
zBoundMin
);
}
@NotNull @NotNull
public Vector getBoundsMax() { public String getSpawnName() {
return new Vector( return getSpawn().getWorld();
xBoundMax, }
0,
zBoundMax
);
}
@NotNull @NotNull
public String getName() { public Location getLobby() {
return name; return lobbyPosition;
} }
@NotNull @NotNull
public WorldLoader getWorldLoader() { public String getLobbyName() {
return worldLoader; return getLobby().getWorld();
} }
public boolean isNotSetup() { @NotNull
if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !spawnPosition.exists()) return true; public Location getSeekerLobby() {
if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !lobbyPosition.exists()) return true; return seekerLobbyPosition;
if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) return true; }
if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !seekerLobbyPosition.exists()) return true;
if (mapSaveEnabled && !getGameSpawn().exists()) return true;
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;
}
public boolean isBoundsNotSetup() { @NotNull
return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0; public String getSeekerLobbyName() {
} return getSeekerLobby().getWorld();
}
@NotNull
public Location getGameSeekerLobby() {
if(mapSaveEnabled) {
return seekerLobbyPosition.changeWorld("hs_"+name);
} else {
return seekerLobbyPosition;
}
}
public boolean isWorldBorderEnabled() {
return worldBorderSize > 0;
}
@NotNull
public Vector getWorldBorderPos() {
return new Vector(
xWorldBorder,
0,
zWorldBorder
);
}
@NotNull
public Vector getWorldBorderData() {
return new Vector(
worldBorderSize,
worldBorderDelay,
worldBorderChange
);
}
@NotNull
public Border getWorldBorder() {
return worldBorder;
}
public boolean isBlockHuntEnabled() {
return blockhunt;
}
@NotNull
public List<Material> getBlockHunt() {
return blockhuntBlocks;
}
@NotNull
public Vector getBoundsMin() {
return new Vector(
xBoundMin,
0,
zBoundMin
);
}
@NotNull
public Vector getBoundsMax() {
return new Vector(
xBoundMax,
0,
zBoundMax
);
}
@NotNull
public String getName() {
return name;
}
@NotNull
public WorldLoader getWorldLoader() {
return worldLoader;
}
public boolean isNotSetup() {
if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !spawnPosition.exists()) return true;
if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !lobbyPosition.exists()) return true;
if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) return true;
if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !seekerLobbyPosition.exists()) return true;
if (mapSaveEnabled && !getGameSpawn().exists()) return true;
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 isBoundsNotSetup();
}
public boolean isBoundsNotSetup() {
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); 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());
player.getInventory().setContents(data); try {
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));

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);
} }
} }

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,7 +89,11 @@ 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;
player.teleport(toBukkit()); if (spawnPatch) {
Main.getInstance().scheduleTask(() -> player.teleport(toBukkit()));
} else {
player.teleport(toBukkit());
}
} }
public Location changeWorld(String world) { public Location changeWorld(String world) {
@ -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

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