From ca4918747fbf8eb578781dacc1caee78fe9f537a Mon Sep 17 00:00:00 2001 From: theoparker24 <87245945+cytocracy@users.noreply.github.com> Date: Thu, 22 Jul 2021 13:17:21 -0500 Subject: [PATCH] additional warp functionality --- .../ParadisuPlugin/commands/warps.java | 77 +++++++++++++++++-- .../ParadisuPlugin/paradisumain.java | 7 ++ src/main/resources/plugin.yml | 14 +++- 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/jakedadream/ParadisuPlugin/commands/warps.java b/src/main/java/me/jakedadream/ParadisuPlugin/commands/warps.java index 3b5f035..e2992cf 100644 --- a/src/main/java/me/jakedadream/ParadisuPlugin/commands/warps.java +++ b/src/main/java/me/jakedadream/ParadisuPlugin/commands/warps.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -15,6 +16,9 @@ import org.bukkit.potion.PotionEffectType; import java.io.File; +import java.io.ObjectInputFilter; +import java.util.Locale; +import java.util.Set; public class warps implements CommandExecutor { @@ -62,6 +66,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String paradisumain.fileWarpConfig.createSection(args[0].toLowerCase()); ConfigurationSection cs = paradisumain.fileWarpConfig.getConfigurationSection(args[0].toLowerCase()); + cs.set("X", loc.getX()); cs.set("Y", loc.getY()); cs.set("Z", loc.getZ()); @@ -99,13 +104,15 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String player.sendMessage("§3[§dParadisu §bツ§3] §fUsage: /warp "); return true; } - ConfigurationSection d = paradisumain.fileWarpConfig.getConfigurationSection(args[0]); + ConfigurationSection d = paradisumain.fileWarpConfig.getConfigurationSection(args[0].toLowerCase()); if (d == null){ - player.sendMessage("§3[§dParadisu §bツ§3] §fThat warp doesn't exist."); - return true; - } else { -// player.sendMessage(String.valueOf(d.getDouble("X"))); - + if (paradisumain.fileWarpConfig.getString("aliases." + args[0].toLowerCase()) != null) { + String w = paradisumain.fileWarpConfig.getString("aliases." + args[0].toLowerCase()); + d = paradisumain.fileWarpConfig.getConfigurationSection(w); + } else { + player.sendMessage("§3[§dParadisu §bツ§3] §fThat warp doesn't exist."); + return true; + } } if (!(player.hasPermission(d.getString("Permission")))){ player.sendMessage("§3[§dParadisu §bツ§3] §7You cannot warp here."); @@ -130,7 +137,65 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1)); player.teleport(l); + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 10, 29); player.sendMessage("§3[§dParadisu §bツ§3] §fWelcome to " + ChatColor.DARK_AQUA + wstring + ChatColor.WHITE + "!"); + break; + + case "reloadwarp": + case "reloadwarps": + if(!(player.hasPermission("snw.warp.reload"))){ + player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have permission to use that command."); + return true; + } + paradisumain.reloadWarpConfig(); + player.sendMessage("§3[§dParadisu §bツ§3] §fReloaded warps."); + break; + + case "setalias": + if(!(player.hasPermission("snw.warp.setalias"))){ + player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have permission to use that command."); + return true; + } + if(args.length < 2 || paradisumain.fileWarpConfig.getConfigurationSection(args[0].toLowerCase()) == null){ + player.sendMessage("§3[§dParadisu §bツ§3] §fPlease use /setalias "); + return true; + } + ConfigurationSection al = paradisumain.fileWarpConfig.getConfigurationSection("aliases"); + al.set(args[1].toLowerCase(), args[0].toLowerCase()); + paradisumain.saveWarpConfig(); + player.sendMessage("§3[§dParadisu §bツ§3] §f" + ChatColor.DARK_AQUA + args[1] + ChatColor.WHITE + " is now a warp alias for " + ChatColor.DARK_AQUA + args[0] + ChatColor.WHITE + "!"); + break; + + case "delalias": + if(!(player.hasPermission("snw.warp.delalias"))){ + player.sendMessage("§3[§dParadisu §bツ§3] §7You do not have permission to use that command."); + return true; + } + if(args.length < 2 || paradisumain.fileWarpConfig.getConfigurationSection(args[0].toLowerCase()) == null || paradisumain.fileWarpConfig.getString("aliases." + args[1].toLowerCase()) == null){ + player.sendMessage("§3[§dParadisu §bツ§3] §fPlease use /delalias "); + return true; + } + paradisumain.fileWarpConfig.getConfigurationSection("aliases").set(args[1].toLowerCase(), null); + paradisumain.saveWarpConfig(); + player.sendMessage("§3[§dParadisu §bツ§3] §fDeleted warp alias " + ChatColor.DARK_AQUA + args[1]); + break; + + case "warps": + Set s = paradisumain.fileWarpConfig.getKeys(false); + s.remove("aliases"); + String mes = "§3[§dParadisu §bツ§3] §fCurrent Warps:" + ChatColor.DARK_AQUA; + for (String i : s){ +// player.sendMessage(i); + i = i.substring(0,1).toUpperCase() + i.substring(1); +// player.sendMessage(i); + mes = mes.concat("\n" + i); +// player.sendMessage(mes); + } + player.sendMessage(mes); + break; + +// String wstring = d.getName(); +// wstring = wstring.substring(0,1).toUpperCase() + wstring.substring(1); } return false; diff --git a/src/main/java/me/jakedadream/ParadisuPlugin/paradisumain.java b/src/main/java/me/jakedadream/ParadisuPlugin/paradisumain.java index 359cc08..e946d55 100644 --- a/src/main/java/me/jakedadream/ParadisuPlugin/paradisumain.java +++ b/src/main/java/me/jakedadream/ParadisuPlugin/paradisumain.java @@ -89,6 +89,10 @@ public void onEnable() { getCommand("setwarp").setExecutor(new warps()); getCommand("delwarp").setExecutor(new warps()); getCommand("warp").setExecutor(new warps()); + getCommand("setalias").setExecutor(new warps()); + getCommand("delalias").setExecutor(new warps()); + getCommand("reloadwarp").setExecutor(new warps()); + getCommand("warps").setExecutor(new warps()); // // getConfig().options().copyDefaults(); @@ -162,6 +166,9 @@ public void createWarpFiles() { } catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); } + if (fileWarpConfig.getConfigurationSection("aliases") == null){ + fileWarpConfig.createSection("aliases"); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b783f62..d010998 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,21 @@ name: ParadisuPlugin -version: 2.4.1 +version: 2.4.2 authors: [JakeDaDream, RealInstantRamen, andyinnie, _Kastle] main: me.jakedadream.ParadisuPlugin.paradisumain api-version: 1.16 commands: + warps: + description: gives a list of all warps + reloadwarp: + description: reloads warp config file if edited manually + aliases: [reloadwarps] + permission: snw.warp.reload + setalias: + description: creates an alias for a warp + permission: snw.warp.setalias + delalias: + description: deleates an alias for a warp + permission: snw.warp.delalias setwarp: description: sets a warp delwarp: