QoL/src/main/java/xyz/etztech/qol/QoL.java

404 lines
15 KiB
Java
Raw Normal View History

2018-09-12 15:53:47 +00:00
package xyz.etztech.qol;
import net.ess3.api.IEssentials;
2018-09-12 15:53:47 +00:00
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
2019-10-09 16:30:54 +00:00
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
2018-09-12 15:53:47 +00:00
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;
2019-10-09 16:30:54 +00:00
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet;
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;
import xyz.etztech.qol.other.TPSRunnable;
2018-09-12 15:53:47 +00:00
import java.util.*;
2018-09-12 15:53:47 +00:00
import java.util.logging.Logger;
public class QoL extends JavaPlugin {
2018-09-12 15:53:47 +00:00
2019-10-09 16:30:54 +00:00
static private final String qolMarkerSetName = "qolMarkerSet";
private String qolMarkerIcon = null;
2019-10-09 16:30:54 +00:00
2018-09-12 15:53:47 +00:00
private static QoL instance;
private IEssentials essentials = null;
private DynmapAPI dynmap = null;
2019-10-09 16:30:54 +00:00
private MarkerAPI markerAPI = null;
private MarkerSet playerMarkerSet = null;
private boolean qolMarkerLayerShow = false;
private String qolMarkerSetLabel = null;
2018-09-12 15:53:47 +00:00
public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" );
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<>();
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
public void onEnable() {
2018-09-12 15:53:47 +00:00
instance = this;
saveDefaultConfig();
reloadConfig();
saveResource("qol.png", true);
2018-09-12 15:53:47 +00:00
//Essentials hook
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
log("Hooked into Essentials for TPS alert.");
essentials = (IEssentials) Bukkit.getPluginManager().getPlugin("Essentials");
}
//Dynmap hook
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
2018-09-23 22:23:53 +00:00
log("Hooked into Dynmap.");
dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap");
2019-10-09 16:30:54 +00:00
// Marker setup
if (dynmap != null) {
markerAPI = dynmap.getMarkerAPI();
playerMarkerSet = markerAPI.getMarkerSet(qolMarkerSetName);
if (playerMarkerSet == null) {
playerMarkerSet = markerAPI.createMarkerSet(qolMarkerSetName, qolMarkerSetLabel, null, true);
}
if (playerMarkerSet == null) {
log("Unable to create marker set");
}
else {
playerMarkerSet.setHideByDefault(!qolMarkerLayerShow);
playerMarkerSet.setMarkerSetLabel(qolMarkerSetLabel);
2019-10-09 16:30:54 +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);
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);
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);
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);
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);
2019-09-30 17:15:29 +00:00
CheckupCommand checkupCommand = new CheckupCommand(this);
this.getCommand("checkup").setExecutor(checkupCommand);
2019-10-05 02:14:28 +00:00
DynmapLinkCommand dynmapLinkCommand = new DynmapLinkCommand(this);
this.getCommand("dynmaplink").setExecutor(dynmapLinkCommand);
2018-09-12 15:53:47 +00:00
2019-10-09 16:30:54 +00:00
if (dynmap != null) {
MarkerCommand markerCommand = new MarkerCommand(this);
this.getCommand("marker").setExecutor(markerCommand);
this.getCommand("marker").setTabCompleter(markerCommand);
2019-10-09 16:30:54 +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));
}
// 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-12 15:53:47 +00:00
links = new ArrayList<>();
for (String raw : config.getStringList("links")) {
links.add(LinkCommand.fromString(raw));
}
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);
}
qolMarkerIcon = config.getString("dynmap.marker_icon", "blueflag");
qolMarkerLayerShow = config.getBoolean("dynmap.marker_set_show", false);
qolMarkerSetLabel = config.getString("dynmap.marker_set_label", "QoL Markers");
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( "--------------------- ## ========= ## ---------------------" );
}
}
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) {
if (!mutes.contains(player.getUniqueId())) {
mutes.add(player.getUniqueId());
2018-09-12 15:53:47 +00:00
}
}
public static boolean toggleDeathMute(Player player) {
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 21:50:22 +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) {
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;
}
public static List<String> getAudits() { return audits; }
2018-09-12 15:53:47 +00:00
public static List<LinkCommand> getLinks() {
return links;
}
public IEssentials getEssentials() { return essentials; }
public DynmapAPI getDynmap() { return dynmap; }
2018-12-04 20:02:05 +00:00
public GriefAlert getGriefAlert() {
return griefAlert;
}
public static Map<String, Integer> getViewDistances() {
return viewDistances;
}
2018-12-08 22:34:57 +00:00
public void runTask(final String command) {
Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
2018-09-12 15:53:47 +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-10-09 16:30:54 +00:00
public MarkerSet getPlayerMarkerSet() {
return playerMarkerSet;
}
public List<Marker> getPlayerMarkers(Player player) {
ArrayList<Marker> markers = new ArrayList<>();
String player_uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), true);
for (Marker marker: playerMarkerSet.getMarkers()) {
if (marker.getMarkerID().contains(player_uuid)) {
markers.add(marker);
}
}
return markers;
}
public String getMarkerName(Player player, String name) {
String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), true);
return uuid + " " + name;
}
public void createMarkerAtPlayer(Player player, String name) {
2019-10-09 16:30:54 +00:00
Location location = player.getLocation();
MarkerIcon icon = markerAPI.getMarkerIcon(qolMarkerIcon);
Marker playerMarker = getPlayerMarker(player, name);
2019-10-09 16:30:54 +00:00
if (playerMarker != null) {
playerMarker.deleteMarker();
}
playerMarkerSet.createMarker(getMarkerName(player, name), name, player.getWorld().getName(), location.getX(), location.getY(), location.getZ(), icon, true);
2019-10-09 16:30:54 +00:00
}
public Marker getPlayerMarker(Player player, String name) {
Marker marker = playerMarkerSet.findMarker(getMarkerName(player, name));
2019-10-09 16:30:54 +00:00
// Find marker using old naming system
if (marker == null) {
String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false);
return playerMarkerSet.findMarker(uuid);
}
else {
return marker;
}
2019-10-09 16:30:54 +00:00
}
2018-09-12 15:53:47 +00:00
}