feat: add Spawns with /varo addspawns
This commit is contained in:
parent
6f5ee556c5
commit
5513aac4b5
6 changed files with 99 additions and 6 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
@ -12,6 +12,7 @@
|
||||||
"Gson",
|
"Gson",
|
||||||
"Minecraft",
|
"Minecraft",
|
||||||
"Mojang",
|
"Mojang",
|
||||||
|
"addspawns",
|
||||||
"cliffbreak",
|
"cliffbreak",
|
||||||
"koords",
|
"koords",
|
||||||
"mkdir",
|
"mkdir",
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package de.cliffbreak.varo.commands;
|
package de.cliffbreak.varo.commands;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.destroystokyo.paper.Title;
|
import com.destroystokyo.paper.Title;
|
||||||
|
|
||||||
|
@ -12,6 +14,8 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent.Reason;
|
import org.bukkit.event.inventory.InventoryCloseEvent.Reason;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
@ -22,6 +26,7 @@ import de.cliffbreak.varo.uitls.WebUtils;
|
||||||
public class VaroCommand implements CommandExecutor {
|
public class VaroCommand implements CommandExecutor {
|
||||||
|
|
||||||
private final Varo plugin;
|
private final Varo plugin;
|
||||||
|
private final HashMap<UUID, TeamPlayerId> addSpawnsCounter = new HashMap<UUID, TeamPlayerId>();
|
||||||
|
|
||||||
public VaroCommand(final Varo plugin) {
|
public VaroCommand(final Varo plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -93,15 +98,80 @@ public class VaroCommand implements CommandExecutor {
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§c§lFehler: §r§cBitte überprüfe deine Eingabe.");
|
sender.sendMessage("§c§lFehler: §r§cBitte überprüfe deine Eingabe.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (args.length == 1 && args[0].equals("addspawns")) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("§c§lFehler: §r§cDieses Kommando kann nur von einem Spieler ausgeführt werden.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final Player p = (Player) sender;
|
||||||
|
TeamPlayerId teamPlayerId;
|
||||||
|
boolean firstRun = false;
|
||||||
|
if (this.addSpawnsCounter.containsKey(p.getUniqueId())) {
|
||||||
|
teamPlayerId = this.addSpawnsCounter.get(p.getUniqueId());
|
||||||
|
} else {
|
||||||
|
p.sendMessage("§aDer Spawn-Erstellungs-Wizard wird gestartet...");
|
||||||
|
teamPlayerId = new TeamPlayerId(0, 0);
|
||||||
|
this.addSpawnsCounter.put(p.getUniqueId(), teamPlayerId);
|
||||||
|
firstRun = true;
|
||||||
|
}
|
||||||
|
final JSONArray teams = this.plugin.getTeamManager().getTeams();
|
||||||
|
final JSONObject team = (JSONObject) teams.get(teamPlayerId.team);
|
||||||
|
final JSONArray players = (JSONArray) team.get("players");
|
||||||
|
|
||||||
|
if (!firstRun) {
|
||||||
|
p.sendMessage("§a§lErfolg.");
|
||||||
|
this.plugin.getTeamManager().setPlayerSpawnByKeys(teamPlayerId.team, teamPlayerId.player,
|
||||||
|
p.getLocation());
|
||||||
|
if (teamPlayerId.player + 1 == players.size()) {
|
||||||
|
if (teamPlayerId.team + 1 == teams.size()) {
|
||||||
|
p.sendMessage("§a§lErfolg: §r§aAlle Spawns wurden erfolgreich gesetzt.");
|
||||||
|
this.addSpawnsCounter.remove(p.getUniqueId());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.addSpawnsCounter.replace(p.getUniqueId(), new TeamPlayerId(teamPlayerId.team + 1, 0));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.addSpawnsCounter.replace(p.getUniqueId(),
|
||||||
|
new TeamPlayerId(teamPlayerId.team, teamPlayerId.player + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String playerName = "";
|
||||||
|
String teamName = "";
|
||||||
|
if (teamPlayerId.player + 1 == players.size()) {
|
||||||
|
final JSONObject tmpTeam = (JSONObject) teams.get(teamPlayerId.team + 1);
|
||||||
|
teamName = (String) tmpTeam.get("name");
|
||||||
|
playerName = (String) ((JSONObject) ((JSONArray) tmpTeam.get("players")).get(0)).get("name");
|
||||||
|
} else {
|
||||||
|
teamName = (String) team.get("name");
|
||||||
|
playerName = (String) ((JSONObject) players.get(teamPlayerId.player + 1)).get("name");
|
||||||
|
}
|
||||||
|
if (firstRun) {
|
||||||
|
teamName = (String) team.get("name");
|
||||||
|
playerName = (String) ((JSONObject) players.get(0)).get("name");
|
||||||
|
}
|
||||||
|
p.sendMessage("Begebe dich in Position um den Spawn für Spieler: §6" + playerName + "§r vom Team: §6"
|
||||||
|
+ teamName + "§r zu setzen.\nFühre danach dieses Kommando erneut aus, um den Spawn zu setzten.");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n ");
|
sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n ");
|
||||||
sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!");
|
sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!");
|
||||||
sender.sendMessage("§a/varo ban [Spieler]: §rSpieler bannen");
|
sender.sendMessage("§a/varo ban [Spieler]: §rSpieler bannen");
|
||||||
sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen");
|
sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen");
|
||||||
sender.sendMessage("§a/varo portal [enable/disable]: §rAktiviere/Deaktiviere die Portal-Erstellung");
|
sender.sendMessage("§a/varo portal [enable/disable]: §rAktiviere/Deaktiviere die Portal-Erstellung");
|
||||||
|
sender.sendMessage("§a/varo addspawns: §rStarte den Spawn-Erstellungs-Wizard");
|
||||||
sender.sendMessage("\n§6==========================================");
|
sender.sendMessage("\n§6==========================================");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TeamPlayerId {
|
||||||
|
public final int team;
|
||||||
|
public final int player;
|
||||||
|
|
||||||
|
public TeamPlayerId(final int team, final int player) {
|
||||||
|
this.team = team;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -26,10 +26,8 @@ public class VaroTabCompleter implements TabCompleter {
|
||||||
list.add("unban");
|
list.add("unban");
|
||||||
list.add("ban");
|
list.add("ban");
|
||||||
list.add("start");
|
list.add("start");
|
||||||
list.add("teamcolors");
|
|
||||||
list.add("portal");
|
list.add("portal");
|
||||||
list.add("test");
|
list.add("addspawns");
|
||||||
list.add("testremove");
|
|
||||||
} else if (args.length == 2 && args[0].equals("unban")) {
|
} else if (args.length == 2 && args[0].equals("unban")) {
|
||||||
final ArrayList<String> bans = this.plugin.getBanUtils().getBans();
|
final ArrayList<String> bans = this.plugin.getBanUtils().getBans();
|
||||||
for (String uuid : bans) {
|
for (String uuid : bans) {
|
||||||
|
|
|
@ -22,10 +22,10 @@ public class GameTimeManager {
|
||||||
private static final LocalTime firstPlayStart = LocalTime.of(19, 10, 00);
|
private static final LocalTime firstPlayStart = LocalTime.of(19, 10, 00);
|
||||||
private static final int playTimeMinutes = 30;
|
private static final int playTimeMinutes = 30;
|
||||||
private static final int playTimeLoginMinutes = 5;
|
private static final int playTimeLoginMinutes = 5;
|
||||||
private static final LocalTime playStart = LocalTime.of(19, 30, 00);
|
// private static final LocalTime playStart = LocalTime.of(19, 30, 00);
|
||||||
// private static final LocalTime playStart = LocalTime.now().plusMinutes(30);
|
// private static final LocalTime playStart = LocalTime.now().plusMinutes(30);
|
||||||
// private static final LocalTime playStart = LocalTime.now().plusMinutes(1);
|
// private static final LocalTime playStart = LocalTime.now().plusMinutes(1);
|
||||||
// private static final LocalTime playStart = LocalTime.now();
|
private static final LocalTime playStart = LocalTime.now();
|
||||||
|
|
||||||
public GameTimeManager(final Varo plugin) {
|
public GameTimeManager(final Varo plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
@ -40,7 +41,7 @@ public class TeamManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
final JSONArray jsonTeams = config.getArray("teams");
|
final JSONArray jsonTeams = this.config.getArray("teams");
|
||||||
int teamKey = -1;
|
int teamKey = -1;
|
||||||
for (final Object jsonRawTeam : jsonTeams) {
|
for (final Object jsonRawTeam : jsonTeams) {
|
||||||
teamKey++;
|
teamKey++;
|
||||||
|
@ -95,6 +96,10 @@ public class TeamManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONArray getTeams() {
|
||||||
|
return this.config.getArray("teams");
|
||||||
|
}
|
||||||
|
|
||||||
public Team getTeamByPlayer(final String player) {
|
public Team getTeamByPlayer(final String player) {
|
||||||
for (final Team team : this.teams) {
|
for (final Team team : this.teams) {
|
||||||
if (team.hasEntry(player)) {
|
if (team.hasEntry(player)) {
|
||||||
|
@ -132,6 +137,10 @@ public class TeamManager {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPlayerSpawnByKeys(final int teamKey, final int playerKey, final Location location) {
|
||||||
|
this.config.updatePlayerSpawn(teamKey, playerKey, location);
|
||||||
|
}
|
||||||
|
|
||||||
public void setAFK(final String player) {
|
public void setAFK(final String player) {
|
||||||
final Team oldTeam = getTeamByPlayer(player);
|
final Team oldTeam = getTeamByPlayer(player);
|
||||||
for (final Team team : this.teams) {
|
for (final Team team : this.teams) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.TreeMap;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
@ -127,4 +128,18 @@ public class JSONConfig {
|
||||||
.get(playerKey)).put("name", name);
|
.get(playerKey)).put("name", name);
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void updatePlayerSpawn(final int teamKey, final int playerKey, final Location location) {
|
||||||
|
JSONObject loc = new JSONObject();
|
||||||
|
loc.put("world", location.getWorld().getName());
|
||||||
|
loc.put("x", location.getX());
|
||||||
|
loc.put("y", location.getY());
|
||||||
|
loc.put("z", location.getZ());
|
||||||
|
loc.put("yaw", (double) location.getYaw());
|
||||||
|
loc.put("pitch", (double) location.getPitch());
|
||||||
|
((JSONObject) ((JSONArray) ((JSONObject) ((JSONArray) this.json.get("teams")).get(teamKey)).get("players"))
|
||||||
|
.get(playerKey)).put("spawn", loc);
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue