finished lobby and manual join system

This commit is contained in:
Tyler Murphy 2021-10-11 17:06:21 -04:00
parent 9d3cf79879
commit 55e15245e6
13 changed files with 186 additions and 27 deletions

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -18,6 +19,9 @@ public class Store {
public static Map<String,Player>
playerList = new HashMap<String,Player>();
public static Map<String,Location>
playerLastLocationList = new HashMap<String,Location>();
public static List<String>
Hider,
Seeker,
@ -44,6 +48,7 @@ public class Store {
public static Vector
spawnPosition,
lobbyPosition,
worldborderPosition;
public static List<String>
@ -52,7 +57,8 @@ public class Store {
public static boolean
nametagsVisible,
permissionsRequired,
manualJoin,
lobbyManualJoin,
lobbyAnnounced,
lobbyStarted = false,
unbreakableArmorstands,
unbreakablePaintings,
@ -104,7 +110,12 @@ public class Store {
getConfig().addDefault("prefix.warning", "&cWarning > &f");
getConfig().addDefault("nametagsVisible", false);
getConfig().addDefault("permissionsRequired", true);
getConfig().addDefault("manualJoin", true);
getConfig().addDefault("lobby.manualJoin", false);
getConfig().addDefault("lobby.countdownTime", 60);
getConfig().addDefault("lobby.announceJoinAndLeave", false);
getConfig().addDefault("lobby.spawn.x", 0);
getConfig().addDefault("lobby.spawn.y", 0);
getConfig().addDefault("lobby.spawn.z", 0);
getConfig().addDefault("blockSettings.unbreakable.painting", false);
getConfig().addDefault("blockSettings.unbreakable.armorstand", false);
getConfig().addDefault("blockSettings.unbreakable.itemframe", false);
@ -123,6 +134,13 @@ public class Store {
);
spawnWorld = getConfig().getString("spawn.world");
///Lobby
lobbyPosition = new Vector(
getConfig().getDouble("lobby.spawn.x"),
Math.max(0,Math.min(255,getConfig().getDouble("lobby.spawn.y"))),
getConfig().getDouble("lobby.spawn.z")
);
//World border
worldborderPosition = new Vector(
getConfig().getInt("worldBorder.x"),
@ -150,7 +168,7 @@ public class Store {
//Other
nametagsVisible = getConfig().getBoolean("nametagsVisible");
permissionsRequired = getConfig().getBoolean("permissionsRequired");
manualJoin = getConfig().getBoolean("manualJoin");
lobbyManualJoin = getConfig().getBoolean("lobby.manualJoin");
unbreakablePaintings = getConfig().getBoolean("blockSettings.unbreakable.painting");
unbreakableArmorstands = getConfig().getBoolean("blockSettings.unbreakable.armorstand");
unbreakableItemframes = getConfig().getBoolean("blockSettings.unbreakable.itemframe");

View file

@ -29,9 +29,12 @@ public class CommandHandler {
registerCommand(new Start());
registerCommand(new Stop());
registerCommand(new SetSpawnLocation());
registerCommand(new SetLobbyLocation());
registerCommand(new SetBorder());
registerCommand(new Reload());
registerCommand(new SaveMap());
registerCommand(new Join());
registerCommand(new Leave());
}
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {

View file

@ -40,7 +40,12 @@ public class EventListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if(status.equals("Playing") || status.equals("Starting")) {
if(manualJoin && !Functions.playerInProtectedWorld(event.getPlayer())) return;
if(lobbyManualJoin) {
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)) {
return;
} else return;
}
Spectator.add(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.");
@ -51,16 +56,16 @@ public class EventListener implements Listener {
}
event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
} else if(status.equals("Setup") || status.equals("Standby")) {
if (manualJoin) {
if (lobbyManualJoin) {
if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld)){
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
return;
}
}
Hider.add(event.getPlayer().getName());
HiderTeam.addEntry(event.getPlayer().getName());
event.getPlayer().setGameMode(GameMode.ADVENTURE);
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
}
playerList.put(event.getPlayer().getName(), event.getPlayer());
}

View file

@ -12,8 +12,8 @@ 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");
if(!lobbyManualJoin) {
sender.sendMessage(errorPrefix + "Manual join/leave isnt set to manual in this server");
return;
}
if(!status.equals("Standby")) {
@ -29,23 +29,28 @@ public class Join implements ICommand {
sender.sendMessage(errorPrefix + "An internal error has occured");
return;
}
if(playerList.containsKey(player.getName())){
sender.sendMessage(errorPrefix + "You are already in the lobby");
return;
}
playerList.put(player.getName(), player);
Hider.add(player.getName());
HiderTeam.addEntry(player.getName());
playerLastLocationList.put(player.getName(), player.getLocation());
player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the game lobby");
if(lobbyAnnounced) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
}
public String getLabel() {
return null;
return "join";
}
public String getUsage() {
return null;
return "";
}
public String getDescription() {
return null;
return "Joins the lobby if game is set to manual join/leave";
}
}

View file

@ -0,0 +1,56 @@
package net.tylermurphy.hideAndSeek.command;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*;
public class Leave implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!lobbyManualJoin) {
sender.sendMessage(errorPrefix + "Manual join/leave isnt set to manual 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;
}
if(!playerList.containsKey(player.getName())) {
sender.sendMessage(errorPrefix + "You are currently not in the lobby");
return;
}
playerList.remove(player.getName());
Hider.remove(player.getName());
Seeker.remove(player.getName());
HiderTeam.removeEntry(player.getName());
SeekerTeam.removeEntry(player.getName());
player.teleport(playerLastLocationList.get(player.getName()));
if(lobbyAnnounced) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has left the HideAndSeek lobby");
}
public String getLabel() {
return "leave";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Leaves the lobby if game is set to manual join/leave";
}
}

View file

@ -25,7 +25,7 @@ public class Reload implements ICommand {
} catch(Exception e) {}
sender.sendMessage(messagePrefix + "Reloaded the config");
playerList = new HashMap<String,Player>();
if(!manualJoin) {
if(!lobbyManualJoin) {
for(Player p : Bukkit.getOnlinePlayers())
playerList.put(p.getName(), p);
}

View file

@ -0,0 +1,48 @@
package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.util.ICommand;
public class SetLobbyLocation implements ICommand {
public void execute(CommandSender sender, String[] args) {
Vector newLobbyPosition = new Vector();
Player player = (Player) sender;
newLobbyPosition.setX(player.getLocation().getBlockX());
newLobbyPosition.setY(player.getLocation().getBlockY());
newLobbyPosition.setZ(player.getLocation().getBlockZ());
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
lobbyPosition = newLobbyPosition;
sender.sendMessage(messagePrefix + "Set lobby position to current location");
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("x", lobbyPosition.getX());
temp.put("y", lobbyPosition.getY());
temp.put("z", lobbyPosition.getZ());
addToSection("lobby.spawn",temp);
saveConfig();
}
public String getLabel() {
return "setlobby";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Sets hide and seeks lobby location to current position";
}
}

View file

@ -32,6 +32,10 @@ public class Start implements ICommand {
sender.sendMessage(errorPrefix + "Please set spawn location first");
return;
}
if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) {
sender.sendMessage(errorPrefix + "Please set lobby location first");
return;
}
File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
if(!destenation.exists()) {
sender.sendMessage(errorPrefix + "Please set map save first");
@ -94,54 +98,54 @@ public class Start implements ICommand {
Functions.resetWorldborder("hideandseek_"+spawnWorld);
status = "Starting";
int temp = gameId;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!");
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!");
}
}, 20 * 10);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!");
}
}, 20 * 20);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!");
}
}, 20 * 25);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!");
}
}, 20 * 27);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!");
}
}, 20 * 28);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!");
Functions.broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!");
}
}, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!");
Functions.broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!");
status = "Playing";
for(Player player : playerList.values()) {
Functions.resetPlayer(player);

View file

@ -41,7 +41,7 @@ public class Stop implements ICommand {
Hider.add(player.getName());
HiderTeam.addEntry(player.getName());
player.getInventory().clear();
player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
player.teleport(new Location(Bukkit.getWorld(spawnWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}

View file

@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
public class Taunt {
@ -65,7 +66,7 @@ public class Taunt {
}
if(taunted != null) {
taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
Bukkit.getServer().broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s");
Functions.broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s");
tauntPlayer = taunted.getName();
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
public void run() {
@ -86,7 +87,7 @@ public class Taunt {
.withTrail()
.build());
fw.setFireworkMeta(fwm);
Bukkit.getServer().broadcastMessage(tauntPrefix + " Taunt has been activated");
Functions.broadcastMessage(tauntPrefix + " Taunt has been activated");
}
tauntPlayer = "";
waitTaunt();

View file

@ -5,6 +5,7 @@ import org.bukkit.World;
import org.bukkit.WorldBorder;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
import static net.tylermurphy.hideAndSeek.Store.*;
@ -27,7 +28,7 @@ public class Worldborder {
private void decreaceWorldborder() {
if(temp != gameId) return;
if(currentWorldborderSize-100 > 100) {
Bukkit.getServer().broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s");
Functions.broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
World world = Bukkit.getWorld("hideandseek_"+spawnWorld);
WorldBorder border = world.getWorldBorder();

View file

@ -161,4 +161,10 @@ public class Functions {
return p.getWorld().getName().equals("hideandseek_"+spawnWorld) || p.getWorld().getName().equals(spawnWorld);
}
public static void broadcastMessage(String message) {
for(Player player : playerList.values()) {
player.sendMessage(message);
}
}
}

View file

@ -19,10 +19,13 @@ permissions:
hideandseek.reload: true
hideandseek.setborder: true
hideandseek.setspawn: true
hideandseek.setlobby: true
hideandseek.start: true
hideandseek.stop: true
hideandseek.savemap: true
hideandseek.blockbypass: true
hideandseek.join: true
hideandseek.leave: true
hideandseek.about:
description: Allows you to run the about command
default: true
@ -38,6 +41,9 @@ permissions:
hideandseek.setspawn:
description: Allows you to set the game spawn point
default: op
hideandseek.setlobby:
description: Allows you to set the game lobby point
default: op
hideandseek.start:
description: Allows you to start the game
default: op
@ -50,3 +56,9 @@ permissions:
hideandseek.blockbypass:
description: Allows you to bypass the block break prevention
default: op
hideandseek.join:
description: Allows you to join the game manual lobby
default: true
hideandseek.leave:
description: Allows you to leave the game manual lobby
default: true