This commit is contained in:
Tyler Murphy 2021-10-11 11:52:56 -04:00
parent f1379a9475
commit 9d3cf79879
7 changed files with 105 additions and 4 deletions

View file

@ -52,6 +52,8 @@ public class Store {
public static boolean public static boolean
nametagsVisible, nametagsVisible,
permissionsRequired, permissionsRequired,
manualJoin,
lobbyStarted = false,
unbreakableArmorstands, unbreakableArmorstands,
unbreakablePaintings, unbreakablePaintings,
unbreakableItemframes, unbreakableItemframes,
@ -102,6 +104,7 @@ public class Store {
getConfig().addDefault("prefix.warning", "&cWarning > &f"); getConfig().addDefault("prefix.warning", "&cWarning > &f");
getConfig().addDefault("nametagsVisible", false); getConfig().addDefault("nametagsVisible", false);
getConfig().addDefault("permissionsRequired", true); getConfig().addDefault("permissionsRequired", true);
getConfig().addDefault("manualJoin", true);
getConfig().addDefault("blockSettings.unbreakable.painting", false); getConfig().addDefault("blockSettings.unbreakable.painting", false);
getConfig().addDefault("blockSettings.unbreakable.armorstand", false); getConfig().addDefault("blockSettings.unbreakable.armorstand", false);
getConfig().addDefault("blockSettings.unbreakable.itemframe", false); getConfig().addDefault("blockSettings.unbreakable.itemframe", false);
@ -147,6 +150,7 @@ public class Store {
//Other //Other
nametagsVisible = getConfig().getBoolean("nametagsVisible"); nametagsVisible = getConfig().getBoolean("nametagsVisible");
permissionsRequired = getConfig().getBoolean("permissionsRequired"); permissionsRequired = getConfig().getBoolean("permissionsRequired");
manualJoin = getConfig().getBoolean("manualJoin");
unbreakablePaintings = getConfig().getBoolean("blockSettings.unbreakable.painting"); unbreakablePaintings = getConfig().getBoolean("blockSettings.unbreakable.painting");
unbreakableArmorstands = getConfig().getBoolean("blockSettings.unbreakable.armorstand"); unbreakableArmorstands = getConfig().getBoolean("blockSettings.unbreakable.armorstand");
unbreakableItemframes = getConfig().getBoolean("blockSettings.unbreakable.itemframe"); unbreakableItemframes = getConfig().getBoolean("blockSettings.unbreakable.itemframe");

View file

@ -40,6 +40,7 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if(status.equals("Playing") || status.equals("Starting")) { if(status.equals("Playing") || status.equals("Starting")) {
if(manualJoin && !Functions.playerInProtectedWorld(event.getPlayer())) return;
Spectator.add(event.getPlayer().getName()); Spectator.add(event.getPlayer().getName());
SpectatorTeam.addEntry(event.getPlayer().getName()); SpectatorTeam.addEntry(event.getPlayer().getName());
event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team."); event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team.");
@ -50,6 +51,12 @@ public class EventListener implements Listener {
} }
event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
} else if(status.equals("Setup") || status.equals("Standby")) { } else if(status.equals("Setup") || status.equals("Standby")) {
if (manualJoin) {
if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)){
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
return;
}
}
Hider.add(event.getPlayer().getName()); Hider.add(event.getPlayer().getName());
HiderTeam.addEntry(event.getPlayer().getName()); HiderTeam.addEntry(event.getPlayer().getName());
event.getPlayer().setGameMode(GameMode.ADVENTURE); event.getPlayer().setGameMode(GameMode.ADVENTURE);
@ -85,6 +92,7 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity() instanceof Player) { if(event.getEntity() instanceof Player) {
if(!Functions.playerInProtectedWorld((Player) event.getEntity())) return;
if(!status.equals("Playing")) { if(!status.equals("Playing")) {
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -119,6 +127,7 @@ public class EventListener implements Listener {
if(event.getEntity() instanceof ArmorStand) { if(event.getEntity() instanceof ArmorStand) {
if(unbreakableArmorstands) { if(unbreakableArmorstands) {
if(event.getDamager() instanceof Player) { if(event.getDamager() instanceof Player) {
if(!Functions.playerInProtectedWorld((Player) event.getDamager())) return;
Player player = (Player) event.getDamager(); Player player = (Player) event.getDamager();
if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) {
System.out.println('t'); System.out.println('t');
@ -133,6 +142,7 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return;
if(!interactableArmorstands) { if(!interactableArmorstands) {
if(event.getRightClicked() instanceof ArmorStand) { if(event.getRightClicked() instanceof ArmorStand) {
if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) {
@ -141,6 +151,7 @@ public class EventListener implements Listener {
} }
} }
if(!interactableItemframes) { if(!interactableItemframes) {
if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return;
if(event.getRightClicked() instanceof ItemFrame) { if(event.getRightClicked() instanceof ItemFrame) {
if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) { if(status.equals("Playing") || status.equals("Starting") || !event.getPlayer().hasPermission("hideandseek.blockbypass")) {
event.setCancelled(true); event.setCancelled(true);
@ -151,6 +162,7 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteractBlock(PlayerInteractEvent event) { public void onPlayerInteractBlock(PlayerInteractEvent event) {
if(!Functions.playerInProtectedWorld((Player) event.getPlayer())) return;
if(!interactableDoors) { if(!interactableDoors) {
if( if(
event.getClickedBlock().getType() == Material.ACACIA_DOOR || event.getClickedBlock().getType() == Material.ACACIA_DOOR ||
@ -208,6 +220,7 @@ public class EventListener implements Listener {
if(event.getEntity() instanceof ItemFrame) { if(event.getEntity() instanceof ItemFrame) {
if(unbreakableItemframes) { if(unbreakableItemframes) {
if(event.getRemover() instanceof Player) { if(event.getRemover() instanceof Player) {
if(!Functions.playerInProtectedWorld((Player) event.getRemover())) return;
Player player = (Player) event.getRemover(); Player player = (Player) event.getRemover();
if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) {
event.setCancelled(true); event.setCancelled(true);
@ -221,6 +234,7 @@ public class EventListener implements Listener {
if(event.getEntity() instanceof Painting) { if(event.getEntity() instanceof Painting) {
if(unbreakableArmorstands) { if(unbreakableArmorstands) {
if(event.getRemover() instanceof Player) { if(event.getRemover() instanceof Player) {
if(!Functions.playerInProtectedWorld((Player) event.getRemover())) return;
Player player = (Player) event.getRemover(); Player player = (Player) event.getRemover();
if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) { if(status.equals("Playing") || status.equals("Starting") || !player.hasPermission("hideandseek.blockbypass")) {
event.setCancelled(true); event.setCancelled(true);
@ -238,6 +252,7 @@ public class EventListener implements Listener {
if(event.getEntity() instanceof Snowball) { if(event.getEntity() instanceof Snowball) {
Snowball snowball = (Snowball) event.getEntity(); Snowball snowball = (Snowball) event.getEntity();
if(snowball.getShooter() instanceof Player) { if(snowball.getShooter() instanceof Player) {
if(!Functions.playerInProtectedWorld((Player) snowball.getShooter())) return;
Player player = (Player) snowball.getShooter(); Player player = (Player) snowball.getShooter();
if(Hider.contains(player.getName())) { if(Hider.contains(player.getName())) {
Main.glow.onProjectilve(); Main.glow.onProjectilve();
@ -250,18 +265,28 @@ public class EventListener implements Listener {
@EventHandler @EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) { public void onFoodLevelChange(FoodLevelChangeEvent event) {
if(event.getEntity() instanceof Player) {
if(playerList.containsKey(event.getEntity().getName())) {
event.setCancelled(true); event.setCancelled(true);
} }
}
}
@EventHandler @EventHandler
public void onPlayerRegainHealth(EntityRegainHealthEvent event) { public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) {
if(event.getEntity() instanceof Player) {
if(playerList.containsKey(event.getEntity().getName())) {
event.setCancelled(true); event.setCancelled(true);
} }
}
}
}
@EventHandler @EventHandler
public void onPlayerCommandPreProccess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreProccess(PlayerCommandPreprocessEvent event) {
if(status.equals("Setup") || status.equals("Standby")) return; if(status.equals("Setup") || status.equals("Standby")) return;
if(!playerList.containsKey(event.getPlayer().getName())) return;
String handle = event.getMessage().split(" ")[0].substring(1); String handle = event.getMessage().split(" ")[0].substring(1);
for(String blocked : blockedCommands) { for(String blocked : blockedCommands) {
if(handle.equalsIgnoreCase(blocked) || handle.equalsIgnoreCase("minecraft:"+blocked)) { if(handle.equalsIgnoreCase(blocked) || handle.equalsIgnoreCase("minecraft:"+blocked)) {

View file

@ -0,0 +1,51 @@
package net.tylermurphy.hideAndSeek.command;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*;
public class Join implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!manualJoin) {
sender.sendMessage(errorPrefix + "Manual join isnt enabled in this server");
return;
}
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
if(!lobbyStarted) {
sender.sendMessage(errorPrefix + "There is currently no lobby in session");
return;
}
Player player = Bukkit.getServer().getPlayer(sender.getName());
if(player == null) {
sender.sendMessage(errorPrefix + "An internal error has occured");
return;
}
playerList.put(player.getName(), player);
Hider.add(player.getName());
HiderTeam.addEntry(player.getName());
player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the game lobby");
}
public String getLabel() {
return null;
}
public String getUsage() {
return null;
}
public String getDescription() {
return null;
}
}

View file

@ -1,6 +1,8 @@
package net.tylermurphy.hideAndSeek.command; package net.tylermurphy.hideAndSeek.command;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Store; import net.tylermurphy.hideAndSeek.Store;
import net.tylermurphy.hideAndSeek.util.Functions; import net.tylermurphy.hideAndSeek.util.Functions;
@ -8,14 +10,25 @@ import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*; import static net.tylermurphy.hideAndSeek.Store.*;
import java.util.HashMap;
public class Reload implements ICommand { public class Reload implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
Store.loadConfig(); Store.loadConfig();
try { try {
Functions.loadScoreboard(); Functions.loadScoreboard();
} catch(Exception e) {} } catch(Exception e) {}
sender.sendMessage(messagePrefix + "Reloaded the config"); sender.sendMessage(messagePrefix + "Reloaded the config");
playerList = new HashMap<String,Player>();
if(!manualJoin) {
for(Player p : Bukkit.getOnlinePlayers())
playerList.put(p.getName(), p);
}
} }
public String getLabel() { public String getLabel() {

View file

@ -21,6 +21,10 @@ import net.tylermurphy.hideAndSeek.util.ICommand;
public class SaveMap implements ICommand { public class SaveMap implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) { if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
sender.sendMessage(errorPrefix + "Please set spawn location first"); sender.sendMessage(errorPrefix + "Please set spawn location first");
return; return;

View file

@ -69,7 +69,7 @@ public class Start implements ICommand {
} }
Seeker.add(seeker.getName()); Seeker.add(seeker.getName());
SeekerTeam.addEntry(seeker.getName()); SeekerTeam.addEntry(seeker.getName());
currentWorldborderSize = worldborderSize;
for(Player player : playerList.values()) { for(Player player : playerList.values()) {
player.getInventory().clear(); player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.ADVENTURE);

View file

@ -157,4 +157,8 @@ public class Functions {
board = mainBoard; board = mainBoard;
} }
public static boolean playerInProtectedWorld(Player p) {
return p.getWorld().getName().equals("hideandseek_"+spawnWorld) || p.getWorld().getName().equals(spawnWorld);
}
} }