2018-09-12 15:53:47 +00:00
|
|
|
package xyz.etztech.qol;
|
|
|
|
|
2018-10-24 19:19:03 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2018-09-12 15:53:47 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
2019-02-27 17:00:56 +00:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
2018-09-12 15:53:47 +00:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
2018-10-24 19:19:03 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import org.dynmap.DynmapAPI;
|
2018-09-12 15:53:47 +00:00
|
|
|
import xyz.etztech.qol.commands.*;
|
|
|
|
import xyz.etztech.qol.listeners.*;
|
2018-12-04 20:02:05 +00:00
|
|
|
import xyz.etztech.qol.other.GriefAlert;
|
2018-09-12 15:53:47 +00:00
|
|
|
import xyz.etztech.qol.other.LinkCommand;
|
2018-09-12 16:06:02 +00:00
|
|
|
import xyz.etztech.qol.other.TPSRunnable;
|
2018-09-12 15:53:47 +00:00
|
|
|
|
2019-02-27 17:00:56 +00:00
|
|
|
import java.util.*;
|
2018-09-12 15:53:47 +00:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2018-10-24 19:19:03 +00:00
|
|
|
public class QoL extends JavaPlugin {
|
2018-09-12 15:53:47 +00:00
|
|
|
|
|
|
|
private static QoL instance;
|
2018-10-24 19:19:03 +00:00
|
|
|
private IEssentials essentials = null;
|
|
|
|
private DynmapAPI dynmap = null;
|
2018-09-12 16:06:02 +00:00
|
|
|
|
2018-09-12 15:53:47 +00:00
|
|
|
public static FileConfiguration config;
|
|
|
|
private Logger log = Logger.getLogger( "Minecraft" );
|
|
|
|
|
2018-10-09 22:21:38 +00:00
|
|
|
private static List<UUID> mutes = new ArrayList<>();
|
2018-10-09 21:50:22 +00:00
|
|
|
private static List<UUID> deathMutes = new ArrayList<>();
|
2018-09-12 15:53:47 +00:00
|
|
|
private static boolean whitelist = false;
|
|
|
|
private static boolean timeout = false;
|
|
|
|
private static List<String> audits = new ArrayList<>();
|
|
|
|
private static List<LinkCommand> links = new ArrayList<>();
|
2019-02-27 17:00:56 +00:00
|
|
|
|
|
|
|
private static Map<String, Integer> viewDistances = new HashMap<>();
|
2018-12-04 20:02:05 +00:00
|
|
|
private GriefAlert griefAlert;
|
2018-09-12 15:53:47 +00:00
|
|
|
|
2018-10-24 19:19:03 +00:00
|
|
|
public void onEnable() {
|
2018-09-12 15:53:47 +00:00
|
|
|
instance = this;
|
|
|
|
saveDefaultConfig();
|
|
|
|
reloadConfig();
|
2018-10-24 19:19:03 +00:00
|
|
|
saveResource("qol.png", true);
|
2018-09-12 15:53:47 +00:00
|
|
|
|
2018-09-12 16:06:02 +00:00
|
|
|
//Essentials hook
|
|
|
|
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
|
|
|
log("Hooked into Essentials for TPS alert.");
|
2018-10-24 19:19:03 +00:00
|
|
|
essentials = (IEssentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
2018-09-12 16:06:02 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 19:49:17 +00:00
|
|
|
//Dynmap hook
|
|
|
|
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
|
2018-09-23 22:23:53 +00:00
|
|
|
log("Hooked into Dynmap.");
|
2018-10-24 19:19:03 +00:00
|
|
|
dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap");
|
2018-09-23 19:49:17 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 15:53:47 +00:00
|
|
|
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);
|
2018-09-23 22:46:09 +00:00
|
|
|
JoinListener joinListener = new JoinListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(joinListener, this);
|
2018-09-12 15:53:47 +00:00
|
|
|
BlockIgniteListener blockIgniteListener = new BlockIgniteListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(blockIgniteListener, this);
|
|
|
|
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
|
2018-09-12 16:06:02 +00:00
|
|
|
DeathListener deathListener = new DeathListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(deathListener, this);
|
2018-12-04 20:02:05 +00:00
|
|
|
PlayerBucketEmptyListener playerBucketEmptyListener = new PlayerBucketEmptyListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(playerBucketEmptyListener, this);
|
|
|
|
BlockPlaceListener blockPlaceListener = new BlockPlaceListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(blockPlaceListener, this);
|
2019-02-27 17:00:56 +00:00
|
|
|
PlayerChangedWorldListener playerChangedWorldListener = new PlayerChangedWorldListener(this);
|
|
|
|
getServer().getPluginManager().registerEvents(playerChangedWorldListener, this);
|
2018-09-12 15:53:47 +00:00
|
|
|
|
|
|
|
// 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);
|
2018-09-12 16:06:02 +00:00
|
|
|
WorldInfoCommand worldInfoCommand = new WorldInfoCommand(this);
|
|
|
|
this.getCommand("worldinfo").setExecutor(worldInfoCommand);
|
2018-10-09 21:50:22 +00:00
|
|
|
DeathMuteCommand deathMuteCommand = new DeathMuteCommand(this);
|
|
|
|
this.getCommand("deathmute").setExecutor(deathMuteCommand);
|
2018-10-12 15:51:26 +00:00
|
|
|
KaratTrophyCommand karatTrophyCommand = new KaratTrophyCommand(this);
|
|
|
|
this.getCommand("karattrophy").setExecutor(karatTrophyCommand);
|
2018-09-12 15:53:47 +00:00
|
|
|
|
2018-09-14 05:08:13 +00:00
|
|
|
if (getConfig().getStringList("list").size() > 0) {
|
|
|
|
ListCommand listCommand = new ListCommand(this);
|
|
|
|
this.getCommand("list").setExecutor(listCommand);
|
|
|
|
}
|
|
|
|
if (getConfig().getStringList("plugins").size() > 0) {
|
|
|
|
PluginsCommand pluginsCommand = new PluginsCommand(this);
|
|
|
|
this.getCommand("plugins").setExecutor(pluginsCommand);
|
|
|
|
}
|
|
|
|
|
2018-09-12 15:53:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Scheduler
|
|
|
|
int schedule = config.getInt("schedule.frequency");
|
|
|
|
if (schedule > 0) {
|
2018-09-14 05:08:13 +00:00
|
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), () -> {
|
|
|
|
List<String> scheduled = config.getStringList("schedule.commands");
|
|
|
|
for (String command : scheduled) {
|
|
|
|
runTask(command);
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
}, 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));
|
|
|
|
}
|
|
|
|
|
2018-09-12 16:06:02 +00:00
|
|
|
// TPS Check
|
|
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new TPSRunnable(this), 0, EtzTechUtil.minutesToTicks(1));
|
|
|
|
|
2018-12-04 20:02:05 +00:00
|
|
|
// Grief Alert
|
|
|
|
griefAlert = new GriefAlert(this);
|
|
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), griefAlert, 0, EtzTechUtil.minutesToTicks(10));
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2018-09-22 19:50:07 +00:00
|
|
|
|
2018-09-12 15:53:47 +00:00
|
|
|
links = new ArrayList<>();
|
|
|
|
for (String raw : config.getStringList("links")) {
|
|
|
|
links.add(LinkCommand.fromString(raw));
|
|
|
|
}
|
2019-02-27 17:00:56 +00:00
|
|
|
|
|
|
|
viewDistances = new HashMap<>();
|
|
|
|
|
|
|
|
ConfigurationSection view_distances = config.getConfigurationSection("view-distances");
|
|
|
|
|
|
|
|
for (String worldName : view_distances.getKeys(false)) {
|
|
|
|
|
|
|
|
int viewDistance = view_distances.getInt(worldName);
|
|
|
|
|
|
|
|
viewDistances.put(worldName, viewDistance);
|
|
|
|
}
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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( "--------------------- ## ========= ## ---------------------" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 19:19:03 +00:00
|
|
|
public void onDisable() {
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-10-09 22:21:38 +00:00
|
|
|
if (!mutes.contains(player.getUniqueId())) {
|
|
|
|
mutes.add(player.getUniqueId());
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 18:39:53 +00:00
|
|
|
public static boolean toggleDeathMute(Player player) {
|
2018-10-09 22:21:38 +00:00
|
|
|
if (!deathMutes.contains(player.getUniqueId())) {
|
|
|
|
deathMutes.add(player.getUniqueId());
|
2018-10-29 23:11:37 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
deathMutes.remove(player.getUniqueId());
|
|
|
|
return false;
|
2018-10-09 22:21:38 +00:00
|
|
|
}
|
2018-10-09 21:50:22 +00:00
|
|
|
}
|
2018-09-12 16:06:02 +00:00
|
|
|
|
2018-10-09 22:21:38 +00:00
|
|
|
public static boolean hasSM(Player player) {
|
|
|
|
return mutes.contains(player.getUniqueId());
|
|
|
|
}
|
2018-10-09 21:50:22 +00:00
|
|
|
|
|
|
|
public static boolean hasDeathMute(Player player) { return deathMutes.contains(player.getUniqueId()); }
|
2018-09-12 15:53:47 +00:00
|
|
|
|
|
|
|
public static void removeSM(Player player) {
|
2018-10-09 22:21:38 +00:00
|
|
|
mutes.remove(player.getUniqueId());
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:50:07 +00:00
|
|
|
public static List<String> getAudits() { return audits; }
|
|
|
|
|
2018-09-12 15:53:47 +00:00
|
|
|
public static List<LinkCommand> getLinks() {
|
|
|
|
return links;
|
|
|
|
}
|
|
|
|
|
2018-10-24 19:19:03 +00:00
|
|
|
public IEssentials getEssentials() { return essentials; }
|
2018-09-23 19:49:17 +00:00
|
|
|
|
2018-10-24 19:19:03 +00:00
|
|
|
public DynmapAPI getDynmap() { return dynmap; }
|
2018-09-12 16:06:02 +00:00
|
|
|
|
2018-12-04 20:02:05 +00:00
|
|
|
public GriefAlert getGriefAlert() {
|
|
|
|
return griefAlert;
|
|
|
|
}
|
|
|
|
|
2019-02-27 17:00:56 +00:00
|
|
|
public static Map<String, Integer> getViewDistances() {
|
|
|
|
return viewDistances;
|
|
|
|
}
|
2018-09-12 16:06:02 +00:00
|
|
|
|
2018-12-08 22:34:57 +00:00
|
|
|
public void runTask(final String command) {
|
2018-09-27 05:02:49 +00:00
|
|
|
Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 17:00:56 +00:00
|
|
|
public void updatePlayerViewDistance(Player player) {
|
2019-07-22 18:07:11 +00:00
|
|
|
//player.setViewDistance(viewDistances.getOrDefault(player.getWorld().getName().toLowerCase(), getServer().getViewDistance()));
|
2019-02-27 17:00:56 +00:00
|
|
|
}
|
2018-09-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
|