Updated to latest changes from private repo

master
Etzelia 2018-09-12 11:06:02 -05:00 committed by John Olheiser
parent 4befd87bc3
commit 941f0a40b6
8 changed files with 235 additions and 55 deletions

20
pom.xml
View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId> <artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml --> <!-- Version is used in plugin.yml -->
<version>1.0</version> <version>1.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Plugin Information --> <!-- Plugin Information -->
@ -58,6 +58,16 @@
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version> <version>1.13.1-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.ess3</groupId>
<artifactId>Essentials</artifactId>
<version>2.14-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
@ -76,6 +86,14 @@
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
<repository>
<id>etztech-repo</id>
<url>http://repo.etztech.xyz</url>
</repository>
<repository>
<id>ess-repo</id>
<url>http://repo.ess3.net/content/groups/essentials</url>
</repository>
<repository> <repository>
<id>mvn-repo</id> <id>mvn-repo</id>
<url>https://mvnrepository.com/artifact/</url> <url>https://mvnrepository.com/artifact/</url>

View File

@ -1,5 +1,7 @@
package xyz.etztech.qol; package xyz.etztech.qol;
import com.earth2me.essentials.Essentials;
import net.ess3.api.IEssentials;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -8,6 +10,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.qol.commands.*; import xyz.etztech.qol.commands.*;
import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.listeners.*;
import xyz.etztech.qol.other.LinkCommand; import xyz.etztech.qol.other.LinkCommand;
import xyz.etztech.qol.other.TPSRunnable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -16,9 +19,8 @@ import java.util.logging.Logger;
public class QoL extends JavaPlugin { public class QoL extends JavaPlugin {
private static QoL instance; private static QoL instance;
/** private static IEssentials essentials = null;
* Connection Pool
*/
public static FileConfiguration config; public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" ); private Logger log = Logger.getLogger( "Minecraft" );
@ -35,6 +37,12 @@ public class QoL extends JavaPlugin {
reloadConfig(); reloadConfig();
saveResource("qol.png", false); saveResource("qol.png", false);
//Essentials hook
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
log("Hooked into Essentials for TPS alert.");
essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
}
if( isEnabled() ) { if( isEnabled() ) {
@ -50,6 +58,8 @@ public class QoL extends JavaPlugin {
getServer().getPluginManager().registerEvents(blockIgniteListener, this); getServer().getPluginManager().registerEvents(blockIgniteListener, this);
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this); CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
getServer().getPluginManager().registerEvents(commandPreprocessListener, this); getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
DeathListener deathListener = new DeathListener(this);
getServer().getPluginManager().registerEvents(deathListener, this);
// Add commands // Add commands
MainCommand mainCommand = new MainCommand(this); MainCommand mainCommand = new MainCommand(this);
@ -72,6 +82,8 @@ public class QoL extends JavaPlugin {
this.getCommand("timeout").setExecutor(timeoutCommand); this.getCommand("timeout").setExecutor(timeoutCommand);
ColorsCommand colorsCommand = new ColorsCommand(this); ColorsCommand colorsCommand = new ColorsCommand(this);
this.getCommand("colors").setExecutor(colorsCommand); this.getCommand("colors").setExecutor(colorsCommand);
WorldInfoCommand worldInfoCommand = new WorldInfoCommand(this);
this.getCommand("worldinfo").setExecutor(worldInfoCommand);
@ -111,6 +123,9 @@ public class QoL extends JavaPlugin {
}, 0, EtzTechUtil.minutesToTicks(frequency)); }, 0, EtzTechUtil.minutesToTicks(frequency));
} }
// TPS Check
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new TPSRunnable(this), 0, EtzTechUtil.minutesToTicks(1));
} }
} }
@ -189,6 +204,8 @@ public class QoL extends JavaPlugin {
} }
} }
public static boolean hasSM(Player player) { public static boolean hasSM(Player player) {
return mutes.contains(player.getUniqueId().toString()); return mutes.contains(player.getUniqueId().toString());
} }
@ -221,6 +238,11 @@ public class QoL extends JavaPlugin {
return links; return links;
} }
public static IEssentials getEssentials() {
return essentials;
}
private void runTask(final String command) { private void runTask(final String command) {
Bukkit.getScheduler().runTask(QoL.instance, new Runnable() { Bukkit.getScheduler().runTask(QoL.instance, new Runnable() {
@Override @Override

View File

@ -0,0 +1,59 @@
package xyz.etztech.qol.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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.Lang;
import xyz.etztech.qol.QoL;
import java.util.*;
public class WorldInfoCommand implements CommandExecutor {
QoL plugin;
public WorldInfoCommand(QoL plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("qol.worldinfo")) {
sender.sendMessage(Lang.NO_PERMISSION.getDef());
}
Map<String, List<String>> worlds = new HashMap<>();
for (World world : Bukkit.getServer().getWorlds()) {
for (Player player : world.getPlayers()) {
if (worlds.containsKey(world.getName())) {
worlds.get(world.getName()).add(getName(world.getName(), player));
} else {
worlds.put(world.getName(), new ArrayList<>(Arrays.asList(getName(world.getName(), player))));
}
}
}
StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== World Info =====");
for (String world : worlds.keySet()) {
message.append("\n").append(ChatColor.YELLOW).append(world).append(": ").append(StringUtils.join(worlds.get(world).toArray(), ChatColor.YELLOW + ", "));
}
sender.sendMessage(message.toString());
return true;
}
private String getName(String world, Player player) {
int range = plugin.getConfig().getInt("worldinfo." + world, 0);
ChatColor color = ChatColor.GREEN;
if (range > 0 && (player.getLocation().getBlockX() > range || player.getLocation().getBlockZ() > range)) {
color = ChatColor.RED;
}
return color + player.getName();
}
}

View File

@ -3,24 +3,17 @@ package xyz.etztech.qol.listeners;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils; 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.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import xyz.etztech.core.CoreUtils;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.qol.QoL; import xyz.etztech.qol.QoL;
import xyz.etztech.qol.other.LinkCommand; import xyz.etztech.qol.other.LinkCommand;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class CommandPreprocessListener implements Listener { public class CommandPreprocessListener implements Listener {
@ -41,13 +34,22 @@ public class CommandPreprocessListener implements Listener {
Player sender = event.getPlayer(); Player sender = event.getPlayer();
// Command Auditing // Command Auditing
if (plugin.getConfig().getBoolean("audit.enabled") && QoL.getAudits().contains(base)) { if (sender.hasPermission("qol.audit") && plugin.getConfig().getBoolean("audit.enabled")) {
boolean auditable = false;
for (String audit : QoL.getAudits()) {
if (noSlash(command).startsWith(noSlash(audit))) {
auditable = true;
break;
}
}
if (auditable) {
Map<String, String> post = new HashMap<>(); Map<String, String> post = new HashMap<>();
post.put("username", "QoL Auditor"); post.put("username", "QoL Auditor");
post.put("content", sender.getName() + " executed command: " + command); post.put("content", "[" + StringUtils.capitalize(sender.getGameMode().name().toLowerCase()) + "] " + sender.getName() + " executed command: " + command);
String webhook = plugin.getConfig().getString("audit.webhook"); String webhook = plugin.getConfig().getString("audit.webhook");
if (StringUtils.isNotEmpty(webhook)) { if (StringUtils.isNotEmpty(webhook)) {
POST(webhook, post); CoreWeb.asyncPost(plugin, webhook, post);
}
} }
} }
@ -64,30 +66,8 @@ public class CommandPreprocessListener implements Listener {
} }
private static String POST(String url, Map<String, String> data) { public String noSlash(String command) {
StringBuffer result = new StringBuffer(); return command.startsWith("/") ? command.substring(1) : command;
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);
}
} }
@ -97,4 +77,6 @@ public class CommandPreprocessListener implements Listener {
} }

View File

@ -0,0 +1,41 @@
package xyz.etztech.qol.listeners;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import xyz.etztech.qol.QoL;
import java.util.Arrays;
public class DeathListener implements Listener {
QoL plugin;
public DeathListener(QoL plugin) {
this.plugin = plugin;
}
@EventHandler
public void onDeath(PlayerDeathEvent event) {
String message = event.getDeathMessage();
event.setDeathMessage("");
Location location = event.getEntity().getLocation();
String coords = StringUtils.join(Arrays.asList(location.getBlockX(), location.getBlockY(), location.getBlockZ()), ", ");
TextComponent newMessage = new TextComponent(message);
newMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Location: " + coords).create()));
for (Player player : Bukkit.getOnlinePlayers()) {
player.spigot().sendMessage(newMessage);
}
}
}

View File

@ -0,0 +1,38 @@
package xyz.etztech.qol.other;
import net.ess3.api.IEssentials;
import org.apache.commons.lang.StringUtils;
import xyz.etztech.core.web.CoreWeb;
import xyz.etztech.qol.QoL;
import java.util.HashMap;
import java.util.Map;
public class TPSRunnable implements Runnable {
private QoL plugin;
public TPSRunnable(QoL plugin) {
this.plugin = plugin;
}
@Override
public void run() {
IEssentials essentials = QoL.getEssentials();
if (essentials != null) {
double tps = essentials.getTimer().getAverageTPS();
int threshold = plugin.getConfig().getInt("tps.threshold", 0);
String webhook = plugin.getConfig().getString("tps.webhook", "");
String message = "@here TPS has fallen below " + threshold + "!";
if (tps < threshold) {
plugin.log(message);
if (StringUtils.isNotEmpty(webhook)) {
Map<String, String> data = new HashMap<>();
data.put("username", "TPS Alert");
data.put("content", message);
CoreWeb.asyncPost(plugin, webhook, data);
}
}
}
}
}

View File

@ -18,6 +18,17 @@ audit:
- mute - mute
- unban - unban
# TPS alert
# Set to 0 to cancel
tps:
threshold: 12
webhook: ''
# The range after which a player will be marked as "outside the border"
worldinfo:
world: 5000
world_nether: 500
world_the_end: 10000
# To disable, set minutes to 0 # To disable, set minutes to 0
schedule: schedule:

View File

@ -17,6 +17,9 @@ commands:
description: UUID utility command description: UUID utility command
portal: portal:
description: Nether Portal utility command description: Nether Portal utility command
worldinfo:
description: World Info utility command
aliases: [wi]
makeme: makeme:
description: MakeMe utility command description: MakeMe utility command
sudo: sudo:
@ -44,6 +47,9 @@ permissions:
qol.portal: qol.portal:
description: Ability to use the Portal command description: Ability to use the Portal command
default: op default: op
qol.worldinfo:
description: Ability to use the World Info command
deafult: op
qol.sudo: qol.sudo:
description: Ability to use the Sudo command description: Ability to use the Sudo command
default: op default: op
@ -53,6 +59,9 @@ permissions:
qol.shadowmute: qol.shadowmute:
description: Ability to use the Shadow Mute command description: Ability to use the Shadow Mute command
default: op default: op
qol.audit:
description: Audits command usage
default: op
qol.whitelist.bypass: qol.whitelist.bypass:
description: Allows someone into the server when Whitelist is enabled description: Allows someone into the server when Whitelist is enabled
default: op default: op