344 lines
10 KiB
Java
344 lines
10 KiB
Java
package xyz.etztech.qol;
|
|
|
|
import net.md_5.bungee.api.chat.BaseComponent;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
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.LinkCommand;
|
|
import xyz.etztech.qol.other.Reminder;
|
|
import xyz.etztech.qol.other.TPSRunnable;
|
|
import me.lucko.spark.api.Spark;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
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 Spark spark = 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<UUID> mutes = new ArrayList<>();
|
|
private static List<UUID> deathMutes = 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<>();
|
|
|
|
private Reminder reminder = null;
|
|
|
|
public void onEnable() {
|
|
instance = this;
|
|
saveDefaultConfig();
|
|
reloadConfig();
|
|
saveResource("qol.png", true);
|
|
|
|
//Spark hook
|
|
RegisteredServiceProvider<Spark> sparkProvider = Bukkit.getServicesManager().getRegistration(Spark.class);
|
|
if (sparkProvider != null) {
|
|
log("Hooked into Spark for TPS alert.");
|
|
spark = sparkProvider.getProvider();
|
|
}
|
|
|
|
//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 (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
|
|
new DiscordSRVListener(this);
|
|
}
|
|
|
|
if( isEnabled() ) {
|
|
|
|
// Add listeners
|
|
new ServerListPingListener(this);
|
|
new AsyncPlayerChatListener(this);
|
|
new LoginListener(this);
|
|
new JoinListener(this);
|
|
new BlockIgniteListener(this);
|
|
new CommandPreprocessListener(this);
|
|
new DeathListener(this);
|
|
|
|
// Add commands
|
|
new MainCommand(this);
|
|
new UUIDCommand(this);
|
|
new NameHistoryCommand(this);
|
|
new PortalCommand(this);
|
|
new SudoCommand(this);
|
|
new MakeMeCommand(this);
|
|
new ShadowMuteCommand(this);
|
|
new WhitelistCommand(this);
|
|
new TimeoutCommand(this);
|
|
new ColorsCommand(this);
|
|
new WorldInfoCommand(this);
|
|
new DeathMuteCommand(this);
|
|
new CheckupCommand(this);
|
|
new DynmapLinkCommand(this);
|
|
new WikiCommand(this);
|
|
|
|
if (dynmap != null) {
|
|
new MarkerCommand(this);
|
|
}
|
|
|
|
if (getConfig().getStringList("list").size() > 0) {
|
|
new ListCommand(this);
|
|
}
|
|
|
|
|
|
|
|
// Scheduler
|
|
int schedule = config.getInt("schedule.frequency");
|
|
if (schedule > 0) {
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), () -> {
|
|
List<String> scheduled = config.getStringList("schedule.commands");
|
|
for (String command : scheduled) {
|
|
runTask(command);
|
|
}
|
|
}, 0, EtzTechUtil.minutesToTicks(schedule));
|
|
}
|
|
|
|
if (reminder != null && reminder.getFrequency() != 0) {
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
BaseComponent [] msg = reminder.nextReminder();
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
player.spigot().sendMessage(msg);
|
|
}
|
|
Bukkit.getConsoleSender().spigot().sendMessage(msg);
|
|
}
|
|
}, 0, EtzTechUtil.minutesToTicks(reminder.getFrequency()));
|
|
}
|
|
|
|
// TPS Check
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new TPSRunnable(this), 0, EtzTechUtil.minutesToTicks(1));
|
|
}
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
qolMarkerIcon = config.getString("dynmap.marker_icon", "blueflag");
|
|
qolMarkerLayerShow = config.getBoolean("dynmap.marker_set_show", false);
|
|
qolMarkerSetLabel = config.getString("dynmap.marker_set_label", "QoL Markers");
|
|
|
|
reminder = Reminder.fromConfig(config.getConfigurationSection("reminders"));
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @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<String> getAudits() { return audits; }
|
|
|
|
public static List<LinkCommand> getLinks() {
|
|
return links;
|
|
}
|
|
|
|
public DynmapAPI getDynmap() { return dynmap; }
|
|
|
|
public void runTask(final String command) {
|
|
Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
|
}
|
|
|
|
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) {
|
|
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, true, 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;
|
|
}
|
|
}
|
|
|
|
public Spark getSpark() {
|
|
return spark;
|
|
}
|
|
}
|
|
|