241 lines
7.4 KiB
Java
241 lines
7.4 KiB
Java
|
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);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|