forked from Minecraft/QoL
Initial commit for Gitea
commit
4befd87bc3
|
@ -0,0 +1,4 @@
|
|||
.idea/
|
||||
*.iml
|
||||
target/
|
||||
dependency-reduced-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>
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.");
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package xyz.etztech.qol.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import xyz.etztech.qol.QoL;
|
||||
|
||||
public class LoginListener implements Listener {
|
||||
|
||||
private QoL plugin;
|
||||
|
||||
public LoginListener(QoL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(PlayerLoginEvent event) {
|
||||
// Whitelist mode
|
||||
if (QoL.getWhitelist() && !event.getPlayer().hasPermission("qol.whitelist.bypass")) {
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "QoL Whitelist is enabled. Please check back soon.");
|
||||
}
|
||||
|
||||
// Player cap
|
||||
int max = plugin.getConfig().getInt("server-list.max");
|
||||
Player player = event.getPlayer();
|
||||
if (max > 0 && Bukkit.getServer().getOnlinePlayers().size() >= max) {
|
||||
if (player.hasPermission("qol.priority")) {
|
||||
Bukkit.getConsoleSender().sendMessage(player.getName() + " has permission to bypass the player cap.");
|
||||
} else {
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "The server is full!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package xyz.etztech.qol.listeners;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
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;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ServerListPingListener implements Listener {
|
||||
|
||||
private QoL plugin;
|
||||
|
||||
public ServerListPingListener(QoL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPing(ServerListPingEvent event) {
|
||||
// MAX PLAYERS
|
||||
int max = plugin.getConfig().getInt("server-list.max");
|
||||
if (event.getMaxPlayers() < max) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Your server max players is lower than QoL! This can cause unintended behaviour.");
|
||||
}
|
||||
if (max > 0) {
|
||||
event.setMaxPlayers(max);
|
||||
}
|
||||
|
||||
// MOTD
|
||||
String motd = plugin.getConfig().getString("server-list.motd");
|
||||
if (StringUtils.isNotBlank(motd)) {
|
||||
event.setMotd(motd);
|
||||
}
|
||||
|
||||
// FAVICON
|
||||
String path = plugin.getConfig().getString("server-list.favicon");
|
||||
if (StringUtils.isNotBlank(path)) {
|
||||
File file = new File(plugin.getDataFolder(), path);
|
||||
try {
|
||||
Image image = ImageIO.read(file);
|
||||
ImageIO.setCacheDirectory(plugin.getDataFolder());
|
||||
image = image.getScaledInstance(64, 64, Image.SCALE_DEFAULT);
|
||||
CachedServerIcon favicon = Bukkit.loadServerIcon(toBufferedImage(image));
|
||||
event.setServerIcon(favicon);
|
||||
} catch (Exception ex) {
|
||||
plugin.log("Could not load favicon from " + file.getAbsolutePath());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage toBufferedImage(Image img)
|
||||
{
|
||||
if (img instanceof BufferedImage)
|
||||
{
|
||||
return (BufferedImage) img;
|
||||
}
|
||||
|
||||
// Create a buffered image with transparency
|
||||
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
// Draw the image on to the buffered image
|
||||
Graphics2D bGr = bimage.createGraphics();
|
||||
bGr.drawImage(img, 0, 0, null);
|
||||
bGr.dispose();
|
||||
|
||||
// Return the buffered image
|
||||
return bimage;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package xyz.etztech.qol.other;
|
||||
|
||||
public class LinkCommand {
|
||||
|
||||
private String command;
|
||||
private String url;
|
||||
private String message; // Placeholder
|
||||
|
||||
public LinkCommand(String command, String url) {
|
||||
this.command = command.toLowerCase();
|
||||
this.url = url;
|
||||
this.message = "Click here to open the " + command + " link.";
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static LinkCommand fromString(String raw) {
|
||||
String[] parts = raw.split(",");
|
||||
if (parts.length != 2) {
|
||||
return null;
|
||||
}
|
||||
return new LinkCommand(parts[0], parts[1]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package xyz.etztech.qol.other;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ShadowMuteTime {
|
||||
|
||||
private int hours;
|
||||
private int minutes;
|
||||
private int seconds;
|
||||
|
||||
public ShadowMuteTime() {
|
||||
hours = 1;
|
||||
minutes = 0;
|
||||
seconds = 0;
|
||||
}
|
||||
|
||||
public int getHours() {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours) {
|
||||
this.hours = hours;
|
||||
}
|
||||
|
||||
public void addHours(int hours) {
|
||||
this.hours += hours;
|
||||
}
|
||||
|
||||
public int getMinutes() {
|
||||
return minutes;
|
||||
}
|
||||
|
||||
public void setMinutes(int minutes) {
|
||||
this.minutes = minutes;
|
||||
}
|
||||
|
||||
public void addMinutes(int minutes) {
|
||||
this.minutes += minutes;
|
||||
}
|
||||
|
||||
public int getSeconds() {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public void setSeconds(int seconds) {
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public void addSeconds(int seconds) {
|
||||
this.seconds += seconds;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getHours() + " hours, " + getMinutes() + " minutes, and " + getSeconds() + " seconds";
|
||||
}
|
||||
|
||||
public long toTicks() {
|
||||
int seconds = getSeconds();
|
||||
seconds += getMinutes()*60;
|
||||
seconds += getHours()*60*60;
|
||||
return seconds*20;
|
||||
}
|
||||
|
||||
public static ShadowMuteTime parse(String time) throws Exception {
|
||||
ShadowMuteTime smt = new ShadowMuteTime();
|
||||
smt.setHours(0); // Defaults to 1 hour
|
||||
String timePattern = "(?:(?<hours>\\d+)h)?(?:(?<minutes>\\d+)m)?(?:(?<seconds>\\d+)s)?";
|
||||
Pattern pattern = Pattern.compile(timePattern);
|
||||
Matcher match = pattern.matcher(time);
|
||||
|
||||
if (!match.matches()) {
|
||||
throw new Exception("Time format does not match, defaulting to 1 hour.");
|
||||
}
|
||||
|
||||
String hourString = match.group("hours");
|
||||
if (hourString != null) {
|
||||
int hours = Integer.parseInt(hourString);
|
||||
smt.addHours(hours);
|
||||
}
|
||||
|
||||
String minuteString = match.group("minutes");
|
||||
if (minuteString != null) {
|
||||
int minutes = Integer.parseInt(minuteString);
|
||||
if (minutes >= 60) {
|
||||
int toHours = minutes / 60;
|
||||
minutes %= 60;
|
||||
smt.addHours(toHours);
|
||||
}
|
||||
smt.addMinutes(minutes);
|
||||
}
|
||||
|
||||
String secondString = match.group("seconds");
|
||||
if (secondString != null) {
|
||||
int seconds = Integer.parseInt(secondString);
|
||||
if (seconds >= 60) {
|
||||
int toMinutes = seconds / 60;
|
||||
seconds %= 60;
|
||||
int minutes = smt.getMinutes() + toMinutes;
|
||||
if (minutes >= 60) {
|
||||
int toHours = minutes / 60;
|
||||
minutes %= 60;
|
||||
smt.addHours(toHours);
|
||||
}
|
||||
smt.addMinutes(minutes);
|
||||
}
|
||||
smt.addSeconds(seconds);
|
||||
}
|
||||
|
||||
return smt;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package xyz.etztech.qol.test;
|
||||
|
||||
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 xyz.etztech.qol.EtzTechUtil;
|
||||
import xyz.etztech.qol.other.ShadowMuteTime;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
# MakeMe needs the UUID of each player who can run it, since it can't rely on a permission node
|
||||
# Make sure all UUID are in dash format
|
||||
makeme:
|
||||
uuids:
|
||||
- 'uuid1'
|
||||
- 'uuid2'
|
||||
- 'etc'
|
||||
# Can either be PermissionsEX or LuckPerms
|
||||
engine: 'LuckPerms'
|
||||
|
||||
# A list of commands to send to Discord if anyone uses them
|
||||
audit:
|
||||
enabled: true
|
||||
webhook: ''
|
||||
commands:
|
||||
- tp
|
||||
- teleport
|
||||
- mute
|
||||
- unban
|
||||
|
||||
|
||||
# To disable, set minutes to 0
|
||||
schedule:
|
||||
frequency: 60 # In minutes
|
||||
commands:
|
||||
- 'save-all'
|
||||
|
||||
# To disable, set minutes to 0
|
||||
reminders:
|
||||
frequency: 5 # In minutes
|
||||
color: '&a'
|
||||
messages:
|
||||
- 'Check out the Discord!'
|
||||
|
||||
# A list of links for link command aliases, separated by a comma between name and URL
|
||||
links:
|
||||
- 'Discord,https://discord.gg/invite'
|
||||
|
||||
server-list:
|
||||
# Set max to 0 to disable
|
||||
max: 0
|
||||
motd: ''
|
||||
favicon: 'qol.png'
|
||||
|
||||
disable-fire:
|
||||
lava: false
|
||||
flint_and_steel: false
|
||||
spread: false
|
||||
lightning: false
|
||||
fireball: false
|
||||
ender_crystal: false
|
||||
explosion: false
|
|
@ -0,0 +1,72 @@
|
|||
name: ${name}
|
||||
version: ${version}
|
||||
description: ${description}
|
||||
author: ${author}
|
||||
website: ${url}
|
||||
main: ${mainClass}
|
||||
commands:
|
||||
qol:
|
||||
description: Base command
|
||||
colors:
|
||||
description: See all color/formatting codes
|
||||
aliases: [color, c]
|
||||
history:
|
||||
description: Name History utility command
|
||||
aliases: [names, name]
|
||||
uuid:
|
||||
description: UUID utility command
|
||||
portal:
|
||||
description: Nether Portal utility command
|
||||
makeme:
|
||||
description: MakeMe utility command
|
||||
sudo:
|
||||
description: Sudo utility command
|
||||
shadowmute:
|
||||
description: Shadow Mute command
|
||||
aliases: [sm]
|
||||
whitelist:
|
||||
description: Whitelist command
|
||||
timeout:
|
||||
description: Timeout command
|
||||
permissions:
|
||||
qol.admin:
|
||||
description: Ability to reload the plugin
|
||||
default: op
|
||||
qol.priority:
|
||||
description: Allows a player on past the player cap
|
||||
default: op
|
||||
qol.uuid:
|
||||
description: Ability to use the UUID command
|
||||
default: op
|
||||
qol.history:
|
||||
description: Ability to use the Name History command
|
||||
default: op
|
||||
qol.portal:
|
||||
description: Ability to use the Portal command
|
||||
default: op
|
||||
qol.sudo:
|
||||
description: Ability to use the Sudo command
|
||||
default: op
|
||||
qol.makeme:
|
||||
description: Ability to use the MakeMe command
|
||||
default: true
|
||||
qol.shadowmute:
|
||||
description: Ability to use the Shadow Mute command
|
||||
default: op
|
||||
qol.whitelist.bypass:
|
||||
description: Allows someone into the server when Whitelist is enabled
|
||||
default: op
|
||||
qol.whitelist.command:
|
||||
description: Ability to use the Whitelist command
|
||||
default: op
|
||||
children:
|
||||
qol.whitelist.bypass: true
|
||||
qol.timeout.bypass:
|
||||
description: Allows someone to chat while a Timeout is active
|
||||
default: op
|
||||
qol.timeout.command:
|
||||
description: Ability to use the Timeout command
|
||||
default: op
|
||||
children:
|
||||
qol.timeout.bypass: true
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 7.4 KiB |
Loading…
Reference in New Issue