package xyz.etztech.qol; import net.ess3.api.IEssentials; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.DynmapAPI; import org.dynmap.markers.Marker; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerSet; import xyz.etztech.qol.commands.*; import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.other.GriefAlert; import xyz.etztech.qol.other.LinkCommand; import xyz.etztech.qol.other.TPSRunnable; import java.util.*; import java.util.logging.Logger; public class QoL extends JavaPlugin { static private final String qolMarkerSetName = "qolMarkerSet"; private String qolMarkerIcon = null; private static QoL instance; private IEssentials essentials = null; private DynmapAPI dynmap = null; private MarkerAPI markerAPI = null; private MarkerSet playerMarkerSet = null; private boolean qolMarkerLayerShow = false; private String qolMarkerSetLabel = null; public static FileConfiguration config; private Logger log = Logger.getLogger( "Minecraft" ); private static List mutes = new ArrayList<>(); private static List deathMutes = new ArrayList<>(); private static boolean whitelist = false; private static boolean timeout = false; private static List audits = new ArrayList<>(); private static List links = new ArrayList<>(); private static Map viewDistances = new HashMap<>(); private GriefAlert griefAlert; public void onEnable() { instance = this; saveDefaultConfig(); reloadConfig(); saveResource("qol.png", true); //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")) { log("Hooked into Dynmap."); dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); // 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); } } } 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); 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); 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); // 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); DeathMuteCommand deathMuteCommand = new DeathMuteCommand(this); this.getCommand("deathmute").setExecutor(deathMuteCommand); KaratTrophyCommand karatTrophyCommand = new KaratTrophyCommand(this); this.getCommand("karattrophy").setExecutor(karatTrophyCommand); CheckupCommand checkupCommand = new CheckupCommand(this); this.getCommand("checkup").setExecutor(checkupCommand); DynmapLinkCommand dynmapLinkCommand = new DynmapLinkCommand(this); this.getCommand("dynmaplink").setExecutor(dynmapLinkCommand); if (dynmap != null) { MarkerCommand markerCommand = new MarkerCommand(this); this.getCommand("marker").setExecutor(markerCommand); this.getCommand("marker").setTabCompleter(markerCommand); } 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); } // Scheduler int schedule = config.getInt("schedule.frequency"); if (schedule > 0) { Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), () -> { List 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 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)); // Grief Alert griefAlert = new GriefAlert(this); Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), griefAlert, 0, EtzTechUtil.minutesToTicks(10)); } } 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)); } 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"); } /** * * @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() { } 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()); } } public static boolean toggleDeathMute(Player player) { if (!deathMutes.contains(player.getUniqueId())) { deathMutes.add(player.getUniqueId()); return true; } else { deathMutes.remove(player.getUniqueId()); return false; } } public static boolean hasSM(Player player) { return mutes.contains(player.getUniqueId()); } public static boolean hasDeathMute(Player player) { return deathMutes.contains(player.getUniqueId()); } public static void removeSM(Player player) { mutes.remove(player.getUniqueId()); } 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 getAudits() { return audits; } public static List getLinks() { return links; } public IEssentials getEssentials() { return essentials; } public DynmapAPI getDynmap() { return dynmap; } public GriefAlert getGriefAlert() { return griefAlert; } public static Map getViewDistances() { return viewDistances; } public void runTask(final String command) { Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)); } public void updatePlayerViewDistance(Player player) { //player.setViewDistance(viewDistances.getOrDefault(player.getWorld().getName().toLowerCase(), getServer().getViewDistance())); } public MarkerSet getPlayerMarkerSet() { return playerMarkerSet; } public List getPlayerMarkers(Player player) { ArrayList 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) { Location location = player.getLocation(); MarkerIcon icon = markerAPI.getMarkerIcon(qolMarkerIcon); Marker playerMarker = getPlayerMarker(player, name); if (playerMarker != null) { playerMarker.deleteMarker(); } playerMarkerSet.createMarker(getMarkerName(player, name), name, player.getWorld().getName(), location.getX(), location.getY(), location.getZ(), icon, true); } public Marker getPlayerMarker(Player player, String name) { Marker marker = playerMarkerSet.findMarker(getMarkerName(player, name)); // Find marker using old naming system if (marker == null) { String uuid = EtzTechUtil.formatUUID(player.getUniqueId().toString(), false); return playerMarkerSet.findMarker(uuid); } else { return marker; } } }