commit 4befd87bc343373566098fc9b206d145d2cb9ba7 Author: Etzelia Date: Wed Sep 12 10:53:47 2018 -0500 Initial commit for Gitea diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d13e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +*.iml +target/ +dependency-reduced-pom.xml \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c307948 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +## QoL + +TODO +/sm +/whitelist +/timeout + +Command Scheduler diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..04504f1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,155 @@ + + 4.0.0 + xyz.etztech + QoL + + 1.0 + jar + + + + QoL + A compilation plugin of various utilities. + http://www.etztech.xyz + + + + Zlib License + http://opensource.org/licenses/Zlib + Copyright (c) 2017 EtzTech + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. + + + + + + EtzTech + http://www.etztech.xyz + + + + + + EtzTech + xyz.etztech.qol.QoL + UTF-8 + + + + + org.spigotmc + spigot-api + 1.13.1-R0.1-SNAPSHOT + + + commons-lang + commons-lang + 2.6 + + + org.apache.httpcomponents + httpclient + 4.5.5 + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + mvn-repo + https://mvnrepository.com/artifact/ + + + jcenter + http://jcenter.bintray.com + + + jitpack.io + https://jitpack.io + + + + + src/main/java + clean install + + + src/main/resources + + true + + plugin.yml + config.yml + + + + src/main/resources + + false + + **/*.java + plugin.yml + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + + + true + lib/ + xyz.etztech.qol.QoL + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.1 + + + package + + shade + + + + + + + \ No newline at end of file diff --git a/src/main/java/xyz/etztech/qol/EtzTechUtil.java b/src/main/java/xyz/etztech/qol/EtzTechUtil.java new file mode 100644 index 0000000..0dcead6 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/EtzTechUtil.java @@ -0,0 +1,123 @@ +package xyz.etztech.qol; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +public class EtzTechUtil +{ + public static final String MOJANG_API = "https://api.mojang.com/"; + public static final String UUID_API = "users/profiles/minecraft/{name}"; + public static final String NAME_HISTORY_API = "user/profiles/{uuid}/names"; + + public static String path(String path, String key, String value) { + return path.replace("{" + key + "}", value); + } + + public static void sms(CommandSender paramCommandSender, String paramString) + { + paramCommandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', paramString)); + } + + public static void sms(Player paramPlayer, String paramString) + { + paramPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', paramString)); + } + + + + public static UUID asUUID(String uuid) { + try { + if (uuid.contains("-") && uuid.length() == 36) { + return UUID.fromString(uuid); + } else if (uuid.length() == 32) { + return UUID.fromString(uuid.substring(0, 8) + "-" + uuid.substring(8, 12) + "-" + uuid.substring(12, 16) + + "-" + uuid.substring(16, 20) + "-" + uuid.substring(20, 32)); + } else { + return null; + } + } catch (Exception ex) { + return null; + } + } + + public static String getUUID(String username) { + // First, look for an online player + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.getName().toLowerCase().equals(username.toLowerCase())) { + return formatUUID(player.getUniqueId().toString(), false); + } + } + // Nothing? Well shit, guess we better ask Mojang + try { + InputStream response = new URL(MOJANG_API + EtzTechUtil.path(UUID_API, "name", username)).openStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(response)); + JsonObject jsonObject = new JsonParser().parse(reader.readLine()).getAsJsonObject(); + return jsonObject.get("id").getAsString(); + } catch (Exception ex) { + //QoL.getInstance().log("Could not connect to Mojang API."); + return null; + } + } + + public static String formatUUID(String uuid, boolean dash) { + if (uuid.contains("-") && uuid.length() == 36) { + if (dash) { + return uuid; + } else { + return uuid.replace("-", ""); + } + } else if (!uuid.contains("-") && uuid.length() == 32) { + if (dash) { + return uuid.substring(0, 8) + "-" + uuid.substring(8, 12) + "-" + uuid.substring(12, 16) + + "-" + uuid.substring(16, 20) + "-" + uuid.substring(20, 32); + } else { + return uuid; + } + } else { + return uuid; + } + } + + public static String componentText(BaseComponent... components) { + StringBuilder text = new StringBuilder(); + for (BaseComponent component : components) { + text.append(ChatColor.stripColor(component.toPlainText())); + } + return text.toString(); + } + + public static String formatDate(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); + return sdf.format(date); + } + + public static String yesNo(boolean yesNo) { + if (yesNo) { + return ChatColor.GREEN + "Yes"; + } else { + return ChatColor.RED + "No"; + } + } + + public static int minutesToTicks(int minutes) { + return minutes*60*20; + } + + + + + +} diff --git a/src/main/java/xyz/etztech/qol/Lang.java b/src/main/java/xyz/etztech/qol/Lang.java new file mode 100644 index 0000000..7e96459 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/Lang.java @@ -0,0 +1,36 @@ +package xyz.etztech.qol; + +import org.bukkit.ChatColor; + +public enum Lang +{ + NO_PERMISSION("&cYou don't have permission to do that!"), + NO_CONSOLE("&cThis command isn't supported by Console!"); + + private String def; + + private Lang(String paramString) + { + this.def = paramString; + } + + public String getDef() + { + return this.def; + } + + public String getDef(String[] paramArrayOfString) + { + String str = ChatColor.translateAlternateColorCodes('&', this.def); + if (paramArrayOfString == null) { + return str; + } + if (paramArrayOfString.length == 0) { + return str; + } + for (int i = 0; i < paramArrayOfString.length; i++) { + str = str.replace("{" + i + "}", paramArrayOfString[i]); + } + return str; + } +} diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java new file mode 100644 index 0000000..3aa3cc6 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -0,0 +1,240 @@ +package xyz.etztech.qol; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import xyz.etztech.qol.commands.*; +import xyz.etztech.qol.listeners.*; +import xyz.etztech.qol.other.LinkCommand; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +public class QoL extends JavaPlugin { + + private static QoL instance; + /** + * Connection Pool + */ + public static FileConfiguration config; + private Logger log = Logger.getLogger( "Minecraft" ); + + private static List mutes = new ArrayList<>(); + private static boolean whitelist = false; + private static boolean timeout = false; + private static List audits = new ArrayList<>(); + private static List links = new ArrayList<>(); + + @Override + public void onEnable() { + instance = this; + saveDefaultConfig(); + reloadConfig(); + saveResource("qol.png", false); + + + + if( isEnabled() ) { + + // Add listeners + ServerListPingListener serverListPingListener = new ServerListPingListener(this); + getServer().getPluginManager().registerEvents(serverListPingListener, this); + AsyncPlayerChatListener asyncPlayerChatListener = new AsyncPlayerChatListener(this); + getServer().getPluginManager().registerEvents(asyncPlayerChatListener, this); + LoginListener loginListener = new LoginListener(this); + getServer().getPluginManager().registerEvents(loginListener, this); + BlockIgniteListener blockIgniteListener = new BlockIgniteListener(this); + getServer().getPluginManager().registerEvents(blockIgniteListener, this); + CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this); + getServer().getPluginManager().registerEvents(commandPreprocessListener, this); + + // Add commands + MainCommand mainCommand = new MainCommand(this); + this.getCommand("qol").setExecutor(mainCommand); + UUIDCommand uuidCommand = new UUIDCommand(this); + this.getCommand("uuid").setExecutor(uuidCommand); + NameHistoryCommand nameHistoryCommand = new NameHistoryCommand(this); + this.getCommand("history").setExecutor(nameHistoryCommand); + PortalCommand portalCommand = new PortalCommand(this); + this.getCommand("portal").setExecutor(portalCommand); + SudoCommand sudoCommand = new SudoCommand(this); + this.getCommand("sudo").setExecutor(sudoCommand); + MakeMeCommand makeMeCommand = new MakeMeCommand(this); + this.getCommand("makeme").setExecutor(makeMeCommand); + ShadowMuteCommand shadowMuteCommand = new ShadowMuteCommand(this); + this.getCommand("shadowmute").setExecutor(shadowMuteCommand); + WhitelistCommand whitelistCommand = new WhitelistCommand(this); + this.getCommand("whitelist").setExecutor(whitelistCommand); + TimeoutCommand timeoutCommand = new TimeoutCommand(this); + this.getCommand("timeout").setExecutor(timeoutCommand); + ColorsCommand colorsCommand = new ColorsCommand(this); + this.getCommand("colors").setExecutor(colorsCommand); + + + + // Scheduler + int schedule = config.getInt("schedule.frequency"); + if (schedule > 0) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new Runnable() { + + @Override + public void run() { + List scheduled = config.getStringList("schedule.commands"); + for (String command : scheduled) { + runTask(command); + } + } + }, 0, EtzTechUtil.minutesToTicks(schedule)); + } + + // Reminders + int frequency = config.getInt("reminders.frequency"); + if (frequency > 0) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new Runnable() { + int idx = 0; + + @Override + public void run() { + List reminders = config.getStringList("reminders.messages"); + ChatColor color = ChatColor.getByChar(config.getString("reminders.color").replace("&", "")); + if (idx >= reminders.size()) { + idx = 0; + } + for (Player player : Bukkit.getOnlinePlayers()) { + EtzTechUtil.sms(player, color + reminders.get(idx)); + } + idx++; + } + }, 0, EtzTechUtil.minutesToTicks(frequency)); + } + + } + } + + public void loadConfig() { + config = Bukkit.getPluginManager().getPlugin("QoL").getConfig(); + } + + + + + @Override + public void reloadConfig() { + super.reloadConfig(); + loadConfig(); + audits = new ArrayList<>(); + for (String command : config.getStringList("audit.commands")) { + audits.add(command.toLowerCase()); + } + links = new ArrayList<>(); + for (String raw : config.getStringList("links")) { + links.add(LinkCommand.fromString(raw)); + } + } + + + /** + * + * @param message + */ + public void log(String message) { + log.info( "[QoL]: " + message ); + } + + /** + * + * @param messages + */ + public void logSection(String[] messages) { + if( messages.length > 0 ) { + log( "--------------------- ## Important ## ---------------------" ); + for ( final String msg : messages ) { + log( msg ); + } + log( "--------------------- ## ========= ## ---------------------" ); + } + } + + + @Override + public void onDisable() { + } + + public void disablePlugin() { + this.setEnabled( false ); + } + + public static QoL getInstance() { + return instance; + } + + + + public Logger getLog() + { + return this.log; + } + + public void setLog(Logger paramLogger) + { + this.log = paramLogger; + } + + public static void addSM(Player player) { + if (!mutes.contains(player.getUniqueId().toString())) { + mutes.add(player.getUniqueId().toString()); + } + } + + public static boolean hasSM(Player player) { + return mutes.contains(player.getUniqueId().toString()); + } + + public static void removeSM(Player player) { + mutes.remove(player.getUniqueId().toString()); + } + + public static boolean getWhitelist() { + return whitelist; + } + + public static void setWhitelist(boolean enabled) { + whitelist = enabled; + } + + public static boolean getTimeout() { + return timeout; + } + + public static void setTimeout(boolean enabled) { + timeout = enabled; + } + + public static List getAudits() { + return audits; + } + + public static List getLinks() { + return links; + } + + private void runTask(final String command) { + Bukkit.getScheduler().runTask(QoL.instance, new Runnable() { + @Override + public void run() { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + }); + } + + + + + + + +} + diff --git a/src/main/java/xyz/etztech/qol/commands/ColorsCommand.java b/src/main/java/xyz/etztech/qol/commands/ColorsCommand.java new file mode 100644 index 0000000..7b5c79a --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/ColorsCommand.java @@ -0,0 +1,48 @@ +package xyz.etztech.qol.commands; + +import net.md_5.bungee.api.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import xyz.etztech.qol.QoL; + +public class ColorsCommand implements CommandExecutor { + + QoL plugin; + + public ColorsCommand(QoL plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + + String colors = ChatColor.GOLD + "===== Minecraft Colors/Formatting =====" + + ChatColor.BLACK + "\n&0 - Black" + + ChatColor.DARK_BLUE + "\n&1 - Dark Blue" + + ChatColor.DARK_GREEN + "\n&2 - Dark Green" + + ChatColor.DARK_AQUA + "\n&3 - Dark Aqua" + + ChatColor.DARK_RED + "\n&4 - Dark Red" + + ChatColor.DARK_PURPLE + "\n&5 - Dark Purple" + + ChatColor.GOLD + "\n&6 - Gold" + + ChatColor.GRAY + "\n&7 - Gray" + + ChatColor.DARK_GRAY + "\n&8 - Dark Gray" + + ChatColor.BLUE + "\n&9 - Blue" + + ChatColor.GREEN + "\n&a - Green" + + ChatColor.AQUA + "\n&b - Aqu" + + ChatColor.RED + "\n&c - Red" + + ChatColor.LIGHT_PURPLE + "\n&d - Light Purple" + + ChatColor.YELLOW + "\n&e - Yellow" + + ChatColor.WHITE + "\n&f - White" + + ChatColor.RESET + ChatColor.MAGIC + "\n&k - Obfuscated" + + ChatColor.RESET + " (&k - Obfuscated)" + + ChatColor.RESET + ChatColor.BOLD + "\n&l - Bold" + + ChatColor.RESET + ChatColor.STRIKETHROUGH + "\n&m - Strikethrough" + + ChatColor.RESET + ChatColor.UNDERLINE + "\n&n - Underline" + + ChatColor.RESET + ChatColor.ITALIC + "\n&o - Italic" + + ChatColor.RESET + "\n&r - Reset"; + commandSender.sendMessage(colors); + return true; + } +} + diff --git a/src/main/java/xyz/etztech/qol/commands/MainCommand.java b/src/main/java/xyz/etztech/qol/commands/MainCommand.java new file mode 100644 index 0000000..06150f4 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/MainCommand.java @@ -0,0 +1,66 @@ +package xyz.etztech.qol.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import xyz.etztech.qol.QoL; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; + +public class MainCommand implements CommandExecutor { + + + QoL plugin; + + public MainCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!commandSender.hasPermission("qol.admin")) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + if (args.length == 0) { + help(commandSender); + } else { + switch (args[0]) { + case "help": + help(commandSender); + break; + case "reload": + reload(commandSender); + break; + default: + EtzTechUtil.sms(commandSender, ChatColor.RED + "Command not recognized."); + break; + } + } + + + + return true; + } + + private void help(CommandSender commandSender) { + FileConfiguration config = this.plugin.getConfig(); + String version = Bukkit.getPluginManager().getPlugin("QoL").getDescription().getVersion(); + StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== QoL v" + version + "====="); + message.append("\n" + ChatColor.YELLOW + "/makeme"); + message.append("\n" + ChatColor.YELLOW + "/names"); + message.append("\n" + ChatColor.YELLOW + "/portal"); + message.append("\n" + ChatColor.YELLOW + "/sudo"); + message.append("\n" + ChatColor.YELLOW + "/uuid"); + EtzTechUtil.sms(commandSender, message.toString()); + } + + private void reload(CommandSender commandSender) { + this.plugin.reloadConfig(); + EtzTechUtil.sms(commandSender, ChatColor.GREEN + "QoL reloaded."); + } +} diff --git a/src/main/java/xyz/etztech/qol/commands/MakeMeCommand.java b/src/main/java/xyz/etztech/qol/commands/MakeMeCommand.java new file mode 100644 index 0000000..381e776 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/MakeMeCommand.java @@ -0,0 +1,50 @@ +package xyz.etztech.qol.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import xyz.etztech.qol.QoL; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; + +public class MakeMeCommand implements CommandExecutor { + + + QoL plugin; + + public MakeMeCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!( commandSender instanceof Player)) { + EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef()); + return true; + } + Player player = (Player) commandSender; + if (!this.plugin.getConfig().getStringList("makeme.uuids").contains(player.getUniqueId().toString())) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + if (args.length < 1) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "You must enter a group."); + return true; + } + String engine = plugin.getConfig().getString("makeme.engine"); + if ("luckperms".equalsIgnoreCase(engine)) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + player.getUniqueId().toString() + " group set " + args[0]); + } else if ("permissionsex".equalsIgnoreCase(engine)) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user " + player.getUniqueId().toString() + " group set " + args[0]); + } + + StringBuilder message = new StringBuilder(ChatColor.GOLD + "You are now in group " + ChatColor.GREEN + args[0] + ChatColor.GOLD + "."); + EtzTechUtil.sms(commandSender, message.toString()); + + return true; + } +} diff --git a/src/main/java/xyz/etztech/qol/commands/NameHistoryCommand.java b/src/main/java/xyz/etztech/qol/commands/NameHistoryCommand.java new file mode 100644 index 0000000..d0473ea --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/NameHistoryCommand.java @@ -0,0 +1,75 @@ +package xyz.etztech.qol.commands; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import xyz.etztech.qol.QoL; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Date; + +public class NameHistoryCommand implements CommandExecutor { + + + QoL plugin; + + public NameHistoryCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!commandSender.hasPermission("qol.history")) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + if (args.length < 1) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "Please specify a username."); + return true; + } + + String uuid = EtzTechUtil.getUUID(args[0]); + + if (uuid == null) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "Could not get results from Mojang API. Make sure the name is spelled correctly."); + return true; + } + + try { + Date changedToAt; + JsonObject obj; + InputStream response = new URL(EtzTechUtil.MOJANG_API + EtzTechUtil.path(EtzTechUtil.NAME_HISTORY_API, "uuid", uuid)).openStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(response)); + JsonArray jsonArray = new JsonParser().parse(reader.readLine()).getAsJsonArray(); + StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Name History Utility ====="); + for (JsonElement element : jsonArray) { + obj = element.getAsJsonObject(); + message.append("\n" + ChatColor.GREEN + obj.get("name").getAsString()); + if (obj.get("changedToAt") != null) { + changedToAt = new Date(obj.get("changedToAt").getAsLong()); + message.append(" (" + EtzTechUtil.formatDate(changedToAt) + ")"); + } else { + message.append(" (original)"); + } + } + EtzTechUtil.sms(commandSender, message.toString()); + } catch (IOException e) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "Mojang API returned nothing."); + } + + + return true; + } +} diff --git a/src/main/java/xyz/etztech/qol/commands/PortalCommand.java b/src/main/java/xyz/etztech/qol/commands/PortalCommand.java new file mode 100644 index 0000000..85322f8 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/PortalCommand.java @@ -0,0 +1,63 @@ +package xyz.etztech.qol.commands; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import xyz.etztech.qol.QoL; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; + +public class PortalCommand implements CommandExecutor { + + + QoL plugin; + + public PortalCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!( commandSender instanceof Player)) { + EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef()); + return true; + } + if (!commandSender.hasPermission("qol.portal")) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + Player player = (Player) commandSender; + Location location = player.getLocation(); + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + World.Environment world = player.getWorld().getEnvironment(); + if (world.equals(World.Environment.THE_END)) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "This command doesn't work in The End!"); + } + int newX = 0, newZ = 0; + String worldStr = ""; + if (world.equals(World.Environment.NORMAL)) { + // Calculate Nether coordinates + newX = x/8; + newZ = z/8; + worldStr = "Nether"; + } else if (world.equals(World.Environment.NETHER)) { + // Calculate Overworld coordinates + newX = x*8; + newZ = z*8; + worldStr = "Overworld"; + } + StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Nether Portal Utility ====="); + message.append("\n" + ChatColor.GREEN + "Current Location: " + x + ", " + y + ", " + z); + message.append("\n" + ChatColor.GREEN + "Location in the " + worldStr + ": " + newX + ", " + y + ", " + newZ); + EtzTechUtil.sms(commandSender, message.toString()); + + return true; + } +} diff --git a/src/main/java/xyz/etztech/qol/commands/ShadowMuteCommand.java b/src/main/java/xyz/etztech/qol/commands/ShadowMuteCommand.java new file mode 100644 index 0000000..1e52dab --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/ShadowMuteCommand.java @@ -0,0 +1,85 @@ +package xyz.etztech.qol.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import xyz.etztech.qol.EtzTechUtil; +import xyz.etztech.qol.Lang; +import xyz.etztech.qol.QoL; +import xyz.etztech.qol.other.ShadowMuteTime; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ShadowMuteCommand implements CommandExecutor { + + + QoL plugin; + + public ShadowMuteCommand(QoL paramQoL) + { + this.plugin = paramQoL; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if (!commandSender.hasPermission("qol.shadowmute")) { + EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); + return true; + } + + if (args.length < 2) { + EtzTechUtil.sms(commandSender, ChatColor.RED + "/sm