Browse Source

Initial commit for Gitea

discord_syntax
Etzelia 4 years ago committed by John Olheiser
commit
4befd87bc3
  1. 4
      .gitignore
  2. 8
      README.md
  3. 155
      pom.xml
  4. 123
      src/main/java/xyz/etztech/qol/EtzTechUtil.java
  5. 36
      src/main/java/xyz/etztech/qol/Lang.java
  6. 240
      src/main/java/xyz/etztech/qol/QoL.java
  7. 48
      src/main/java/xyz/etztech/qol/commands/ColorsCommand.java
  8. 66
      src/main/java/xyz/etztech/qol/commands/MainCommand.java
  9. 50
      src/main/java/xyz/etztech/qol/commands/MakeMeCommand.java
  10. 75
      src/main/java/xyz/etztech/qol/commands/NameHistoryCommand.java
  11. 63
      src/main/java/xyz/etztech/qol/commands/PortalCommand.java
  12. 85
      src/main/java/xyz/etztech/qol/commands/ShadowMuteCommand.java
  13. 41
      src/main/java/xyz/etztech/qol/commands/SudoCommand.java
  14. 80
      src/main/java/xyz/etztech/qol/commands/TimeoutCommand.java
  15. 77
      src/main/java/xyz/etztech/qol/commands/UUIDCommand.java
  16. 75
      src/main/java/xyz/etztech/qol/commands/WhitelistCommand.java
  17. 43
      src/main/java/xyz/etztech/qol/listeners/AsyncPlayerChatListener.java
  18. 23
      src/main/java/xyz/etztech/qol/listeners/BlockIgniteListener.java
  19. 100
      src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java
  20. 37
      src/main/java/xyz/etztech/qol/listeners/LoginListener.java
  21. 79
      src/main/java/xyz/etztech/qol/listeners/ServerListPingListener.java
  22. 46
      src/main/java/xyz/etztech/qol/other/LinkCommand.java
  23. 112
      src/main/java/xyz/etztech/qol/other/ShadowMuteTime.java
  24. 24
      src/main/java/xyz/etztech/qol/test/Test.java
  25. 52
      src/main/resources/config.yml
  26. 72
      src/main/resources/plugin.yml
  27. BIN
      src/main/resources/qol.png

4
.gitignore vendored

@ -0,0 +1,4 @@
.idea/
*.iml
target/
dependency-reduced-pom.xml

8
README.md

@ -0,0 +1,8 @@
## QoL
TODO
/sm
/whitelist
/timeout
Command Scheduler

155
pom.xml

@ -0,0 +1,155 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.0</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
<!-- Name, Description, and URL are used in plugin.yml -->
<name>QoL</name>
<description>A compilation plugin of various utilities.</description>
<url>http://www.etztech.xyz</url>
<licenses>
<license>
<name>Zlib License</name>
<url>http://opensource.org/licenses/Zlib</url>
<comments>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.</comments>
</license>
</licenses>
<developers>
<developer>
<name>EtzTech</name>
<url>http://www.etztech.xyz</url>
</developer>
</developers>
<properties>
<!-- Author and MainClass are used in plugin.yml -->
<author>EtzTech</author>
<mainClass>xyz.etztech.qol.QoL</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>mvn-repo</id>
<url>https://mvnrepository.com/artifact/</url>
</repository>
<repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>clean install</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- Keep filtering at false for other resources to prevent bad magic -->
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>plugin.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>xyz.etztech.qol.QoL</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

123
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;
}
}

36
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;
}
}

240
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<String> mutes = new ArrayList<>();
private static boolean whitelist = false;
private static boolean timeout = false;
private static List<String> audits = new ArrayList<>();
private static List<LinkCommand> 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<String> 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<String> 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<String> getAudits() {
return audits;
}
public static List<LinkCommand> 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);
}
});
}
}

48
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;
}
}

66
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.");
}
}

50
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;
}
}

75
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;
}
}

63
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;
}
}

85
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 <player> <time>");
EtzTechUtil.sms(commandSender, ChatColor.RED + "Time Format: 1h2m3s (1 hour, 2 minutes, and 3 seconds)");
return true;
}
Player argPlayer = null;
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.getName().equalsIgnoreCase(args[0])) {
argPlayer = onlinePlayer;
}
}
if (argPlayer == null) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "No player found.");
return true;
}
final Player player = argPlayer;
ShadowMuteTime smt;
try {
smt = ShadowMuteTime.parse(args[1]);
} catch (Exception ex) {
smt = new ShadowMuteTime();
commandSender.sendMessage(ChatColor.RED + ex.getMessage());
}
EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Shadow Muting " + ChatColor.YELLOW +
player.getName() + ChatColor.GREEN + " for " + ChatColor.YELLOW + smt.toString());
QoL.addSM(player);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Removing Shadow Mute for " + ChatColor.YELLOW + player.getName());
QoL.removeSM(player);
}
}, smt.toTicks());
return true;
}
}

41
src/main/java/xyz/etztech/qol/commands/SudoCommand.java

@ -0,0 +1,41 @@
package xyz.etztech.qol.commands;
import org.apache.commons.lang.StringUtils;
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 SudoCommand implements CommandExecutor {
QoL plugin;
public SudoCommand(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.sudo")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), StringUtils.join(args, " "));
StringBuilder message = new StringBuilder(ChatColor.GOLD + "Command Executed.");
EtzTechUtil.sms(commandSender, message.toString());
return true;
}
}

80
src/main/java/xyz/etztech/qol/commands/TimeoutCommand.java

@ -0,0 +1,80 @@
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.EtzTechUtil;
import xyz.etztech.qol.Lang;
import xyz.etztech.qol.QoL;
import java.util.Arrays;
import java.util.List;
public class TimeoutCommand implements CommandExecutor {
private final List<String> TRUE = Arrays.asList("on", "yes", "true");
private final List<String> FALSE = Arrays.asList("off", "no", "false");
QoL plugin;
public TimeoutCommand(QoL paramQoL)
{
this.plugin = paramQoL;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("qol.timeout.command")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
String name;
if (commandSender instanceof Player) {
name = commandSender.getName();
} else {
name = "Console";
}
if (args.length < 1) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "/timeout on|off|yes|no|true|false");
return true;
}
Boolean enabled = parse(args[0]);
if (enabled == null) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "/timeout on|off|yes|no|true|false");
return true;
}
QoL.setTimeout(enabled);
String activated = enabled ? "activated" : "deactivated";
for (Player player : Bukkit.getOnlinePlayers()) {
EtzTechUtil.sms(player, ChatColor.YELLOW + "A chat timeout has been " + activated + " by " +
ChatColor.GREEN + name + ChatColor.YELLOW + ".");
}
return true;
}
private Boolean parse(String bool) {
if (TRUE.contains(bool)) {
return true;
}
if (FALSE.contains(bool)) {
return false;
}
return null;
}
}

77
src/main/java/xyz/etztech/qol/commands/UUIDCommand.java

@ -0,0 +1,77 @@
package xyz.etztech.qol.commands;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
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;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
public class UUIDCommand implements CommandExecutor {
QoL plugin;
public UUIDCommand(QoL paramQoL)
{
this.plugin = paramQoL;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("qol.uuid")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
if (args.length < 1) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "Please specify a username.");
return true;
}
StringBuilder message = buildMessage(args[0]);
EtzTechUtil.sms(commandSender, message.toString());
return true;
}
private StringBuilder buildMessage(String username) {
StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== UUID Utility =====");
boolean local = false;
String uuid = null;
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getName().toLowerCase().equals(username.toLowerCase())) {
uuid = player.getUniqueId().toString();
message.append("\n" + ChatColor.GREEN + "Name: " + ChatColor.YELLOW + player.getName());
message.append("\n" + ChatColor.GREEN + "UUID: " + ChatColor.YELLOW + uuid);
local = true;
break;
}
}
if (!local) {
try {
InputStream response = new URL(EtzTechUtil.MOJANG_API + EtzTechUtil.path(EtzTechUtil.UUID_API, "name", username)).openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(response));
JsonObject jsonObject = new JsonParser().parse(reader.readLine()).getAsJsonObject();
uuid = jsonObject.get("id").getAsString();
message.append("\n" + ChatColor.GREEN + "Name: " + ChatColor.YELLOW + jsonObject.get("name").getAsString());
message.append("\n" + ChatColor.GREEN + "UUID: " + ChatColor.YELLOW + uuid);
} catch (Exception e) {
message = new StringBuilder(ChatColor.RED + "Mojang API returned nothing. Make sure the name is spelled correctly.");
}
}
return message;
}
}

75
src/main/java/xyz/etztech/qol/commands/WhitelistCommand.java

@ -0,0 +1,75 @@
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.EtzTechUtil;
import xyz.etztech.qol.Lang;
import xyz.etztech.qol.QoL;
import java.util.Arrays;
import java.util.List;
public class WhitelistCommand implements CommandExecutor {
private final List<String> TRUE = Arrays.asList("on", "yes", "true");
private final List<String> FALSE = Arrays.asList("off", "no", "false");
QoL plugin;
public WhitelistCommand(QoL paramQoL)
{
this.plugin = paramQoL;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("qol.whitelist.command")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
if (args.length < 1) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "/whitelist on|off|yes|no|true|false");
return true;
}
Boolean enabled = parse(args[0]);
if (enabled == null) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "/whitelist on|off|yes|no|true|false");
return true;
}
QoL.setWhitelist(enabled);
EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Whitelist mode: " + ChatColor.YELLOW + enabled);
if (enabled) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!player.hasPermission("qol.whitelist.bypass")) {
player.kickPlayer("Whitelist mode has been enabled. Please check back later.");
}
}
}
return true;
}
private Boolean parse(String bool) {
if (TRUE.contains(bool)) {
return true;
}
if (FALSE.contains(bool)) {
return false;
}
return null;
}
}

43
src/main/java/xyz/etztech/qol/listeners/AsyncPlayerChatListener.java

@ -0,0 +1,43 @@
package xyz.etztech.qol.listeners;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.util.CachedServerIcon;
import xyz.etztech.qol.QoL;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class AsyncPlayerChatListener implements Listener {
private QoL plugin;
public AsyncPlayerChatListener(QoL plugin) {
this.plugin = plugin;
}
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (QoL.hasSM(player)) {
event.getRecipients().clear();
event.getRecipients().add(player);
}
if (QoL.getTimeout() && !player.hasPermission("qol.timeout.bypass")) {
event.getRecipients().clear();
}
}
}

23
src/main/java/xyz/etztech/qol/listeners/BlockIgniteListener.java

@ -0,0 +1,23 @@
package xyz.etztech.qol.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockIgniteEvent;
import xyz.etztech.qol.QoL;
public class BlockIgniteListener implements Listener {
QoL plugin;
public BlockIgniteListener(QoL plugin) {
this.plugin = plugin;
}
@EventHandler
public void onBlockIgnite(BlockIgniteEvent event) {
BlockIgniteEvent.IgniteCause cause = event.getCause();
if (plugin.getConfig().getBoolean("disable-fire." + cause.name().toLowerCase())) {
event.setCancelled(true);
}
}
}

100
src/main/java/xyz/etztech/qol/listeners/CommandPreprocessListener.java

@ -0,0 +1,100 @@
package xyz.etztech.qol.listeners;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import xyz.etztech.qol.QoL;
import xyz.etztech.qol.other.LinkCommand;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CommandPreprocessListener implements Listener {
QoL plugin;
public CommandPreprocessListener(QoL plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String command = event.getMessage();
String base = command.split(" ")[0].substring(1).toLowerCase(); // Strip the slash
Player sender = event.getPlayer();
// Command Auditing
if (plugin.getConfig().getBoolean("audit.enabled") && QoL.getAudits().contains(base)) {
Map<String, String> post = new HashMap<>();
post.put("username", "QoL Auditor");
post.put("content", sender.getName() + " executed command: " + command);
String webhook = plugin.getConfig().getString("audit.webhook");
if (StringUtils.isNotEmpty(webhook)) {
POST(webhook, post);
}
}
// Links
for (LinkCommand linkCommand : QoL.getLinks()) {
if (base.equalsIgnoreCase(linkCommand.getCommand())) {
event.setCancelled(true);
TextComponent link = new TextComponent(ChatColor.GREEN + linkCommand.getMessage());
link.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, linkCommand.getUrl()));
sender.spigot().sendMessage(link);
return;
}
}
}
private static String POST(String url, Map<String, String> data) {
StringBuffer result = new StringBuffer();
try {
HttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
List<NameValuePair> params = new ArrayList<>();
for (String key : data.keySet()) {
params.add(new BasicNameValuePair(key, data.get(key)));
}
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
client.execute(post);
} catch (Exception ex) {
log("POST request failed. (" + url + ")");
}
return result.toString();
}
private static void log(String message) {
try {
Bukkit.getConsoleSender().sendMessage(message);
} catch (Exception ex) {
System.out.println(message);
}
}