diff --git a/pom.xml b/pom.xml index a561bef..465656e 100644 --- a/pom.xml +++ b/pom.xml @@ -50,11 +50,36 @@ 0.0.1-SNAPSHOT provided + + commons-io + commons-io + 2.6 + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + ${project.groupId}.Challenges + + + + + + + + org.apache.maven.plugins maven-jar-plugin 3.2.0 diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java index 54f9896..94bce0b 100644 --- a/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java +++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java @@ -5,13 +5,15 @@ import de.fanta.challenges.Challenges; import de.fanta.challengesjoinentities.ChallengesGlobalDataHelper.ChallengeMessageType; import de.iani.cubesideutils.bukkit.plugin.api.GlobalDataHelperBukkit; +import de.speedy64.globalport.GlobalApi; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; import java.io.DataInputStream; import java.io.IOException; +import java.util.UUID; public class ChallengesGlobalDataHelper extends GlobalDataHelperBukkit implements Listener { @@ -101,8 +103,37 @@ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { plugin.updateServerStatus(event.getServer().getName(), true); this.requestInitialData(event.getServer().getName()); - },200L); + }, 200L); } + + for (Server server : plugin.getPluginConfig().getChallengeServers()) { + if (server.getName().equals(event.getServer().getName())) { + UUID uuid = Server.serverPlayers.get(server); + if (uuid != null) { + Player p = Bukkit.getPlayer(uuid); + if (p != null) { + server.spawnPiglin(p); + GlobalApi.portOnlinePlayerToLocation(p.getName(), server.getGPLocation()); + } + } + break; + } + } + + for (Server server : plugin.getPluginConfig().getAdventureServers()) { + if (server.getName().equals(event.getServer().getName())) { + UUID uuid = Server.serverPlayers.get(server); + if (uuid != null) { + Player p = Bukkit.getPlayer(uuid); + if (p != null) { + server.spawnPiglin(p); + GlobalApi.portOnlinePlayerToLocation(p.getName(), server.getGPLocation()); + } + } + break; + } + } + } @EventHandler @@ -110,5 +141,25 @@ if (plugin.getEntityData(event.getServer().getName()) != null) { plugin.updateServerStatus(event.getServer().getName(), false); } + + for (Server server : plugin.getPluginConfig().getChallengeServers()) { + if (server.getName().equals(event.getServer().getName())) { + server.setOnline(false); + Server.serverPlayers.remove(server); + server.despawnPiglin(); + break; + } + } + + for (Server server : plugin.getPluginConfig().getAdventureServers()) { + if (server.getName().equals(event.getServer().getName())) { + server.setOnline(false); + Server.serverPlayers.remove(server); + server.despawnPiglin(); + break; + } + } + + plugin.getAvailableServers().remove(event.getServer().getName()); } } diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java index e2cf44b..6dc9ab2 100644 --- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java +++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java @@ -1,9 +1,11 @@ package de.fanta.challengesjoinentities; import de.fanta.challengesjoinentities.JoinEntityData.ServerStatus; -import de.fanta.challengesjoinentities.commands.AddEntityCommand; -import de.fanta.challengesjoinentities.commands.RemoveEntityCommand; -import de.fanta.challengesjoinentities.commands.ToggleArenaCommand; +import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureLoadCommand; +import de.fanta.challengesjoinentities.commands.PiglinCommand.AddEntityCommand; +import de.fanta.challengesjoinentities.commands.PiglinCommand.RemoveEntityCommand; +import de.fanta.challengesjoinentities.commands.PiglinCommand.ToggleArenaCommand; +import de.fanta.challengesjoinentities.commands.ChallengesCommand.ChallengesloadCommand; import de.fanta.challengesjoinentities.listeners.ChallengesEventListener; import de.fanta.challengesjoinentities.listeners.EntityListener; import de.fanta.challengesjoinentities.listeners.PlayerListener; @@ -17,23 +19,30 @@ import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.UUID; public class ChallengesJoinEntities extends JavaPlugin { - public static final String PREFIX = ChatColor.of("#455aad") + "[" + ChatColor.of("#1FFF00") + "Challenge" + ChatColor.of("#455aad") + "]"; + public static final String PREFIX = ChatColor.of("#455aad") + "[" + ChatColor.of("#1FFF00") + "Lobby" + ChatColor.of("#455aad") + "]"; private Config config; private ChallengesGlobalDataHelper globalDataHelper; private Map entityData; private Map entityServerMapping; + private Set availableServers; public ChallengesJoinEntities() { this.entityData = new HashMap<>(); this.entityServerMapping = new HashMap<>(); + this.availableServers = new HashSet(); } @Override @@ -49,13 +58,29 @@ router.addCommandMapping(new RemoveEntityCommand(this), "remove"); router.addCommandMapping(new ToggleArenaCommand(this, true), "enable"); router.addCommandMapping(new ToggleArenaCommand(this, false), "disable"); + + CommandRouter challengesrouter = new CommandRouter(getCommand("challenges")); + challengesrouter.addCommandMapping(new ChallengesloadCommand(this), "load"); + + CommandRouter adventurerouter = new CommandRouter(getCommand("adventure")); + adventurerouter.addCommandMapping(new AdventureLoadCommand(this), "load"); } Bukkit.getPluginManager().registerEvents(new EntityListener(this), this); Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this); Bukkit.getPluginManager().registerEvents(globalDataHelper, this); } + @Override + public void onDisable() { + getPluginConfig().getChallengeServers().forEach(Server::despawnPiglin); + getPluginConfig().getAdventureServers().forEach(Server::despawnPiglin); + } + public void spawnPiglin(Location location, String serverName, String gpLocationName, String serverDisplayName) { + spawnPiglin(location, serverName, gpLocationName, serverDisplayName, true); + } + + public void spawnPiglin(Location location, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) { if (entityData.containsKey(serverName)) { despawnPiglin(entityData.get(serverName).getEntityUUID(), serverName); } @@ -66,8 +91,7 @@ piglin.getEquipment().clear(); piglin.setRemoveWhenFarAway(false); piglin.setCustomNameVisible(true); - - addPiglin(piglin.getUniqueId(), serverName, gpLocationName, serverDisplayName); + addPiglin(piglin.getUniqueId(), serverName, gpLocationName, serverDisplayName, saveToConfig); globalDataHelper.requestInitialData(serverName); } @@ -80,8 +104,10 @@ } } - public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName) { - addPiglin(piglinUUID, serverName, gpLocationName, serverDisplayName, true); + public void despawnPiglin(String serverName) { + if(entityData.get(serverName) != null){ + despawnPiglin(entityData.get(serverName).getEntityUUID(), serverName); + } } public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) { @@ -210,4 +236,8 @@ public Map getEntityData() { return entityData; } + + public Set getAvailableServers() { + return availableServers; + } } diff --git a/src/main/java/de/fanta/challengesjoinentities/Config.java b/src/main/java/de/fanta/challengesjoinentities/Config.java index 3d893f2..768b71f 100644 --- a/src/main/java/de/fanta/challengesjoinentities/Config.java +++ b/src/main/java/de/fanta/challengesjoinentities/Config.java @@ -1,17 +1,28 @@ package de.fanta.challengesjoinentities; +import com.destroystokyo.paper.HeightmapType; import org.bukkit.Bukkit; +import org.bukkit.HeightMap; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class Config { private ChallengesJoinEntities plugin; + private Set challengeServers; + private Set adventureServers; public Config(ChallengesJoinEntities plugin) { this.plugin = plugin; + this.challengeServers = new HashSet<>(); + this.adventureServers = new HashSet<>(); + if (Bukkit.getPluginManager().getPlugin("Challenges") == null) { plugin.saveDefaultConfig(); reloadConfig(); @@ -23,7 +34,6 @@ FileConfiguration config = plugin.getConfig(); ConfigurationSection piglinsSection = config.getConfigurationSection("piglins"); - if (piglinsSection != null) { for (String serverName : piglinsSection.getKeys(false)) { ConfigurationSection piglin = piglinsSection.getConfigurationSection(serverName); @@ -31,6 +41,40 @@ plugin.getGlobalDataHelper().requestInitialData(serverName); } } + + ConfigurationSection challengeServerSection = config.getConfigurationSection("challenge"); + if (challengeServerSection != null) { + for (String serverName : challengeServerSection.getKeys(false)) { + ConfigurationSection server = challengeServerSection.getConfigurationSection(serverName); + + ConfigurationSection locSection = server.getConfigurationSection("location"); + World world = Bukkit.getWorld(locSection.getString("world")); + double x = locSection.getDouble("x"); + double y = locSection.getDouble("y"); + double z = locSection.getDouble("z"); + float yaw = (float) locSection.getDouble("yaw"); + Location location = new Location(world, x, y, z, yaw, 0f); + + challengeServers.add(new Server(serverName, server.getString("gpLocation"), server.getString("dir"), ServerType.CHALLENGES, plugin, location)); + } + } + + ConfigurationSection adventureServerSection = config.getConfigurationSection("adventure"); + if (adventureServerSection != null) { + for (String serverName : adventureServerSection.getKeys(false)) { + ConfigurationSection server = adventureServerSection.getConfigurationSection(serverName); + + ConfigurationSection locSection = server.getConfigurationSection("location"); + World world = Bukkit.getWorld(locSection.getString("world")); + double x = locSection.getDouble("x"); + double z = locSection.getDouble("z"); + float pitch = (float) locSection.getDouble("pitch"); + Location location = new Location(world, x, 200, z, 0.0f, pitch); + + adventureServers.add(new Server(serverName, server.getString("gpLocation"), server.getString("dir"), ServerType.ADVENTURE, plugin, location)); + } + } + } public void savePiglin(JoinEntityData data) { @@ -58,5 +102,13 @@ plugin.saveConfig(); } + + public Set getChallengeServers() { + return challengeServers; + } + + public Set getAdventureServers() { + return adventureServers; + } } diff --git a/src/main/java/de/fanta/challengesjoinentities/Server.java b/src/main/java/de/fanta/challengesjoinentities/Server.java new file mode 100644 index 0000000..6fd0cac --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/Server.java @@ -0,0 +1,125 @@ +package de.fanta.challengesjoinentities; + +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.UUID; + +public class Server { + + public static HashMap serverPlayers = new HashMap<>(); + + private ChallengesJoinEntities plugin; + private String name; + private String gPLocation; + private String dir; + private ServerType serverType; + private Location piglinLocation; + private boolean online; + + public Server(String name, String gPLocation, String dir, ServerType serverType, ChallengesJoinEntities plugin, Location piglinLocation) { + this.name = name; + this.gPLocation = gPLocation; + this.dir = dir; + this.serverType = serverType; + this.plugin = plugin; + this.online = plugin.getGlobalDataHelper().getServer(name) != null; + this.piglinLocation = piglinLocation; + } + + public boolean isOnline() { + return online; + } + + public void setOnline(boolean online) { + this.online = online; + } + + public String getName() { + return name; + } + + public String getGPLocation() { + return gPLocation; + } + + public void load(Player p) { + online = true; + Server.serverPlayers.put(this, p.getUniqueId()); + UUID uuid = p.getUniqueId(); + File dir = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString()); + if (!dir.isDirectory()) { + ChatUtil.sendErrorMessage(p, "Du hast noch keine Map gespeichert!"); + online = false; + Server.serverPlayers.remove(this); + return; + } + + File configs = new File("/home/minecraft/" + this.dir + "/plugins/Challenges"); + File end = new File("/home/minecraft/" + this.dir + "/world_the_end"); + File nether = new File("/home/minecraft/" + this.dir + "/world_nether"); + File world = new File("/home/minecraft/" + this.dir + "/world"); + File saveend = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/world_the_end"); + File savenether = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/world_nether"); + File saveworld = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/world"); + File saveconfigs = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/Challenges"); + + ChatUtil.sendNormalMessage(p, "Versuche Map zu laden!"); + try { + if (world.isDirectory()) { + FileUtils.deleteDirectory(world); + FileUtils.deleteDirectory(end); + FileUtils.deleteDirectory(nether); + } + FileUtils.copyDirectory(saveconfigs, configs); + FileUtils.copyDirectory(saveworld, world); + FileUtils.copyDirectory(savenether, nether); + FileUtils.copyDirectory(saveend, end); + + } catch (IOException e) { + e.printStackTrace(); + ChatUtil.sendErrorMessage(p, "Map konnte nicht geladen werden!"); + online = false; + Server.serverPlayers.remove(this); + return; + } + ChatUtil.sendNormalMessage(p, "Map wurde geladen! Server wird nun gestartet!"); + start(uuid, p); + } + + public void start(UUID uuid, Player player) { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("screen", "-AmdS", uuid.toString(), "./start.sh").directory(new File("/home/minecraft/" + dir)); + try { + Process process = processBuilder.start(); + Bukkit.getLogger().info(serverType.toString().toLowerCase() + " Server: " + uuid + " wurde von " + player.getName() + " gestartet!"); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + int exitCode = process.waitFor(); + System.out.println("Exited with error code : " + exitCode); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + + public void spawnPiglin(Player player){ + plugin.spawnPiglin(piglinLocation, name, gPLocation, player.getName(), false); + + + + } + + public void despawnPiglin(){ + plugin.despawnPiglin(name); + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/ServerType.java b/src/main/java/de/fanta/challengesjoinentities/ServerType.java new file mode 100644 index 0000000..1ddaadf --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/ServerType.java @@ -0,0 +1,17 @@ +package de.fanta.challengesjoinentities; + +public enum ServerType { + + ADVENTURE("Adventure-saves"), + CHALLENGES("saves"); + + private String dir; + + ServerType(String dir){ + this.dir = dir; + } + + public String getDir() { + return dir; + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AddEntityCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AddEntityCommand.java deleted file mode 100644 index 77c7f39..0000000 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AddEntityCommand.java +++ /dev/null @@ -1,77 +0,0 @@ -package de.fanta.challengesjoinentities.commands; - -import de.cubeside.connection.GlobalServer; -import de.fanta.challengesjoinentities.ChallengesJoinEntities; -import de.fanta.challengesjoinentities.ChatUtil; -import de.iani.cubesideutils.StringUtil; -import de.iani.cubesideutils.bukkit.commands.SubCommand; -import de.iani.cubesideutils.commands.ArgsParser; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; - -public class AddEntityCommand extends SubCommand { - - private final ChallengesJoinEntities plugin; - - public AddEntityCommand(ChallengesJoinEntities plugin) { - this.plugin = plugin; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { - if (!(sender instanceof Player)) { - ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!"); - return true; - } - - if (!sender.hasPermission("challenges.spawn.teleporter")) { - ChatUtil.sendErrorMessage(sender, "Keine Berechtigung!"); - return true; - } - - if (!args.hasNext()) { - return false; - } - String serverName = args.getNext(); - - if (!args.hasNext()) { - return false; - } - String locationName = args.getNext(); - - if (plugin.getGlobalDataHelper().getServer(serverName) != null) { - String serverDisplayName = StringUtil.convertColors(args.getAll(serverName)); - - plugin.spawnPiglin(((Player) sender).getLocation(), serverName, locationName, serverDisplayName); - ChatUtil.sendNormalMessage(sender, "Piglin hinzugefügt! *grunz*"); - } else { - ChatUtil.sendErrorMessage(sender, "Server nicht gefunden!"); - } - return true; - } - - @Override - public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { - args.next(); - if (!args.hasNext()) { - return plugin.getGlobalDataHelper().getServers().stream().map(GlobalServer::getName).collect(Collectors.toList()); - } - - return Collections.emptyList(); - } - - @Override - public String getUsage() { - return " [Anzeigename]"; - } - - @Override - public String getRequiredPermission() { - return "challenges.spawn.teleporter"; - } -} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java new file mode 100644 index 0000000..d32d118 --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java @@ -0,0 +1,45 @@ +package de.fanta.challengesjoinentities.commands.AdventureCommand; + +import de.fanta.challengesjoinentities.ChallengesJoinEntities; +import de.fanta.challengesjoinentities.ChatUtil; +import de.fanta.challengesjoinentities.Server; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class AdventureLoadCommand extends SubCommand { + + private final ChallengesJoinEntities plugin; + + public AdventureLoadCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!"); + return true; + } + Player p = (Player) sender; + if (!Server.serverPlayers.containsValue(p.getUniqueId())) { + boolean serverAvailable = false; + for (Server server : plugin.getPluginConfig().getAdventureServers()) { + if (server.isOnline()) + continue; + server.load(p); + serverAvailable = true; + break; + } + if (!serverAvailable) { + ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"); + } + } else { + ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!"); + } + return true; + } +} + diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java new file mode 100644 index 0000000..4544a65 --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengesloadCommand.java @@ -0,0 +1,44 @@ +package de.fanta.challengesjoinentities.commands.ChallengesCommand; + +import de.fanta.challengesjoinentities.ChallengesJoinEntities; +import de.fanta.challengesjoinentities.ChatUtil; +import de.fanta.challengesjoinentities.Server; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ChallengesloadCommand extends SubCommand { + + private final ChallengesJoinEntities plugin; + + public ChallengesloadCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!"); + return true; + } + Player p = (Player) sender; + if (!Server.serverPlayers.containsValue(p.getUniqueId())) { + boolean serverAvailable = false; + for (Server server : plugin.getPluginConfig().getChallengeServers()) { + if (server.isOnline()) + continue; + server.load(p); + serverAvailable = true; + break; + } + if (!serverAvailable) { + ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"); + } + } else { + ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!"); + } + return true; + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/AddEntityCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/AddEntityCommand.java new file mode 100644 index 0000000..9cf45b2 --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/AddEntityCommand.java @@ -0,0 +1,77 @@ +package de.fanta.challengesjoinentities.commands.PiglinCommand; + +import de.cubeside.connection.GlobalServer; +import de.fanta.challengesjoinentities.ChallengesJoinEntities; +import de.fanta.challengesjoinentities.ChatUtil; +import de.iani.cubesideutils.StringUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; + +public class AddEntityCommand extends SubCommand { + + private final ChallengesJoinEntities plugin; + + public AddEntityCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!"); + return true; + } + + if (!sender.hasPermission("challenges.spawn.teleporter")) { + ChatUtil.sendErrorMessage(sender, "Keine Berechtigung!"); + return true; + } + + if (!args.hasNext()) { + return false; + } + String serverName = args.getNext(); + + if (!args.hasNext()) { + return false; + } + String locationName = args.getNext(); + + if (plugin.getGlobalDataHelper().getServer(serverName) != null) { + String serverDisplayName = StringUtil.convertColors(args.getAll(serverName)); + + plugin.spawnPiglin(((Player) sender).getLocation(), serverName, locationName, serverDisplayName); + ChatUtil.sendNormalMessage(sender, "Piglin hinzugefügt! *grunz*"); + } else { + ChatUtil.sendErrorMessage(sender, "Server nicht gefunden!"); + } + return true; + } + + @Override + public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { + args.next(); + if (!args.hasNext()) { + return plugin.getGlobalDataHelper().getServers().stream().map(GlobalServer::getName).collect(Collectors.toList()); + } + + return Collections.emptyList(); + } + + @Override + public String getUsage() { + return " [Anzeigename]"; + } + + @Override + public String getRequiredPermission() { + return "challenges.spawn.teleporter"; + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/RemoveEntityCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/RemoveEntityCommand.java new file mode 100644 index 0000000..ac69490 --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/RemoveEntityCommand.java @@ -0,0 +1,63 @@ +package de.fanta.challengesjoinentities.commands.PiglinCommand; + +import de.fanta.challengesjoinentities.ChallengesJoinEntities; +import de.fanta.challengesjoinentities.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPiglin; + +import java.util.Collection; +import java.util.Collections; + +public class RemoveEntityCommand extends SubCommand { + + private final ChallengesJoinEntities plugin; + + public RemoveEntityCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!sender.hasPermission("challenges.spawn.teleporter")) { + ChatUtil.sendErrorMessage(sender, "Keine Berechtigung!"); + return true; + } + + if (args.hasNext()) { + String serverName = args.getNext(); + + CraftPiglin piglin = plugin.getPiglinForServerName(serverName); + if (piglin != null) { + plugin.despawnPiglin(piglin.getUniqueId(), serverName); + ChatUtil.sendNormalMessage(sender, "Piglin entfernt."); + } else { + ChatUtil.sendErrorMessage(sender, "Kein Piglin für diesen Server gefunden!"); + } + return true; + } + return false; + } + + @Override + public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { + args.next(); + if (!args.hasNext()) { + return plugin.getEntityData().keySet(); + } + + return Collections.emptyList(); + } + + @Override + public String getUsage() { + return ""; + } + + @Override + public String getRequiredPermission() { + return "challenges.spawn.teleporter"; + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/ToggleArenaCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/ToggleArenaCommand.java new file mode 100644 index 0000000..4b95cbe --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/PiglinCommand/ToggleArenaCommand.java @@ -0,0 +1,58 @@ +package de.fanta.challengesjoinentities.commands.PiglinCommand; + +import de.fanta.challengesjoinentities.ChallengesJoinEntities; +import de.fanta.challengesjoinentities.ChatUtil; +import de.fanta.challengesjoinentities.JoinEntityData; +import de.fanta.challengesjoinentities.JoinEntityData.ServerStatus; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.Collections; + +public class ToggleArenaCommand extends SubCommand { + + private final ChallengesJoinEntities plugin; + private final boolean enable; + + public ToggleArenaCommand(ChallengesJoinEntities plugin, boolean enable) { + this.plugin = plugin; + this.enable = enable; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!sender.hasPermission("challenges.event")) { + ChatUtil.sendErrorMessage(sender, "Keine Berechtigung"); + return true; + } + + if (!args.hasNext()) { + return false; + } + String serverName = args.getNext(); + JoinEntityData data = plugin.getEntityData(serverName); + if (data == null) { + ChatUtil.sendErrorMessage(sender, "Server nicht gefunden."); + return true; + } + if (data.getServerStatus() == ServerStatus.RUNNING) { + ChatUtil.sendErrorMessage(sender, "Arena disablen nicht möglich, da gerade eine Runde läuft."); + return true; + } + + plugin.updateServerStatus(serverName, enable); + return true; + } + + @Override + public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { + args.next(); + if (!args.hasNext()) { + return plugin.getEntityData().keySet(); + } + return Collections.emptyList(); + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/RemoveEntityCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/RemoveEntityCommand.java deleted file mode 100644 index 09880df..0000000 --- a/src/main/java/de/fanta/challengesjoinentities/commands/RemoveEntityCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package de.fanta.challengesjoinentities.commands; - -import de.fanta.challengesjoinentities.ChallengesJoinEntities; -import de.fanta.challengesjoinentities.ChatUtil; -import de.iani.cubesideutils.bukkit.commands.SubCommand; -import de.iani.cubesideutils.commands.ArgsParser; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPiglin; - -import java.util.Collection; -import java.util.Collections; - -public class RemoveEntityCommand extends SubCommand { - - private final ChallengesJoinEntities plugin; - - public RemoveEntityCommand(ChallengesJoinEntities plugin) { - this.plugin = plugin; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { - if (!sender.hasPermission("challenges.spawn.teleporter")) { - ChatUtil.sendErrorMessage(sender, "Keine Berechtigung!"); - return true; - } - - if (args.hasNext()) { - String serverName = args.getNext(); - - CraftPiglin piglin = plugin.getPiglinForServerName(serverName); - if (piglin != null) { - plugin.despawnPiglin(piglin.getUniqueId(), serverName); - ChatUtil.sendNormalMessage(sender, "Piglin entfernt."); - } else { - ChatUtil.sendErrorMessage(sender, "Kein Piglin für diesen Server gefunden!"); - } - return true; - } - return false; - } - - @Override - public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { - args.next(); - if (!args.hasNext()) { - return plugin.getEntityData().keySet(); - } - - return Collections.emptyList(); - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getRequiredPermission() { - return "challenges.spawn.teleporter"; - } -} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/ToggleArenaCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/ToggleArenaCommand.java deleted file mode 100644 index a5265ab..0000000 --- a/src/main/java/de/fanta/challengesjoinentities/commands/ToggleArenaCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.fanta.challengesjoinentities.commands; - -import de.fanta.challengesjoinentities.ChallengesJoinEntities; -import de.fanta.challengesjoinentities.ChatUtil; -import de.fanta.challengesjoinentities.JoinEntityData; -import de.fanta.challengesjoinentities.JoinEntityData.ServerStatus; -import de.iani.cubesideutils.bukkit.commands.SubCommand; -import de.iani.cubesideutils.commands.ArgsParser; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.Collections; - -public class ToggleArenaCommand extends SubCommand { - - private final ChallengesJoinEntities plugin; - private final boolean enable; - - public ToggleArenaCommand(ChallengesJoinEntities plugin, boolean enable) { - this.plugin = plugin; - this.enable = enable; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { - if (!sender.hasPermission("challenges.event")) { - ChatUtil.sendErrorMessage(sender, "Keine Berechtigung"); - return true; - } - - if (!args.hasNext()) { - return false; - } - String serverName = args.getNext(); - JoinEntityData data = plugin.getEntityData(serverName); - if (data == null) { - ChatUtil.sendErrorMessage(sender, "Server nicht gefunden."); - return true; - } - if (data.getServerStatus() == ServerStatus.RUNNING) { - ChatUtil.sendErrorMessage(sender, "Arena disablen nicht möglich, da gerade eine Runde läuft."); - return true; - } - - plugin.updateServerStatus(serverName, enable); - return true; - } - - @Override - public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { - args.next(); - if (!args.hasNext()) { - return plugin.getEntityData().keySet(); - } - return Collections.emptyList(); - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e185b3c..18d28d5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,5 +8,11 @@ commands: piglins: - aliases: [piglin] - description: asdf \ No newline at end of file + aliases: + - piglin + challenges: + aliases: + - c + adventure: + aliases: + - a \ No newline at end of file