diff --git a/pom.xml b/pom.xml index e9202bb..2776d87 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.16 + 1.10 jar @@ -39,11 +39,15 @@ plugin-api 1.0.7 + + net.ess3 + EssentialsX + 2.18.1 + us.dynmap dynmap-api 1.9.4 - provided commons-lang @@ -53,19 +57,7 @@ com.discordsrv discordsrv - 1.23.0 - provided - - - me.lucko - spark-api - 0.1-SNAPSHOT - provided - - - com.nisovin.shopkeepers - ShopkeepersAPI - 2.13.3 + 1.19.1 provided @@ -86,6 +78,10 @@ dynmap-repo https://repo.mikeprimm.com/ + + + ess-repo + https://ci.ender.zone/plugin/repository/everything/ mvn-repo @@ -99,14 +95,6 @@ jitpack.io https://jitpack.io - - sonatype-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - shopkeepers-repo - https://nexus.lichtspiele.org/repository/releases/ - @@ -171,4 +159,4 @@ - + \ No newline at end of file diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 1b0b3f3..469932a 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -1,13 +1,10 @@ package xyz.etztech.qol; -import com.nisovin.shopkeepers.api.ShopkeepersPlugin; -import github.scarsz.discordsrv.DiscordSRV; -import net.md_5.bungee.api.chat.BaseComponent; +import net.ess3.api.IEssentials; 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.dynmap.DynmapAPI; import org.dynmap.markers.Marker; @@ -19,7 +16,6 @@ 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; @@ -32,7 +28,7 @@ public class QoL extends JavaPlugin { private String qolMarkerIcon = null; private static QoL instance; - private Spark spark = null; + private IEssentials essentials = null; private DynmapAPI dynmap = null; private MarkerAPI markerAPI = null; private MarkerSet playerMarkerSet = null; @@ -57,11 +53,10 @@ public class QoL extends JavaPlugin { reloadConfig(); saveResource("qol.png", true); - //Spark hook - RegisteredServiceProvider sparkProvider = Bukkit.getServicesManager().getRegistration(Spark.class); - if (sparkProvider != null) { - log("Hooked into Spark for TPS alert."); - spark = sparkProvider.getProvider(); + //Essentials hook + if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { + log("Hooked into Essentials for TPS alert."); + essentials = (IEssentials) Bukkit.getPluginManager().getPlugin("Essentials"); } //Dynmap hook @@ -91,17 +86,10 @@ public class QoL extends JavaPlugin { } } - // DiscordSRV Hook if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) { new DiscordSRVListener(this); } - // Shopkeepers Hook - if (Bukkit.getPluginManager().isPluginEnabled("Shopkeepers")) { - new HeadShopListener(this); - log("Hooked in Shopkeepers for the head shop"); - } - if( isEnabled() ) { // Add listeners @@ -112,7 +100,6 @@ public class QoL extends JavaPlugin { new BlockIgniteListener(this); new CommandPreprocessListener(this); new DeathListener(this); - new EntityChangeBlockListener(this); // Add commands new MainCommand(this); @@ -129,12 +116,6 @@ public class QoL extends JavaPlugin { new DeathMuteCommand(this); new CheckupCommand(this); new DynmapLinkCommand(this); - new WikiCommand(this); - new MoonCommand(this); - - if (DiscordSRV.api.isAnyHooked()) { - new DiscordIgnoreCommand(this); - } if (dynmap != null) { new MarkerCommand(this); @@ -161,11 +142,9 @@ public class QoL extends JavaPlugin { Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new Runnable() { @Override public void run() { - BaseComponent [] msg = reminder.nextReminder(); for (Player player : Bukkit.getOnlinePlayers()) { - player.spigot().sendMessage(msg); + player.spigot().sendMessage(reminder.nextReminder()); } - Bukkit.getConsoleSender().spigot().sendMessage(msg); } }, 0, EtzTechUtil.minutesToTicks(reminder.getFrequency())); } @@ -297,6 +276,8 @@ public class QoL extends JavaPlugin { return links; } + public IEssentials getEssentials() { return essentials; } + public DynmapAPI getDynmap() { return dynmap; } public void runTask(final String command) { @@ -349,9 +330,5 @@ public class QoL extends JavaPlugin { return marker; } } - - public Spark getSpark() { - return spark; - } } diff --git a/src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java b/src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java deleted file mode 100644 index 63ec03f..0000000 --- a/src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -package xyz.etztech.qol.commands; - -import github.scarsz.discordsrv.DiscordSRV; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.metadata.FixedMetadataValue; -import xyz.etztech.qol.EtzTechUtil; -import xyz.etztech.qol.Lang; -import xyz.etztech.qol.QoL; - -public class DiscordIgnoreCommand implements CommandExecutor { - public static final String DISCORD_IGNORE_METADATA = "qol.discord_ignore"; - QoL plugin; - - public DiscordIgnoreCommand(QoL plugin) { - this.plugin = plugin; - plugin.getCommand("discordignore").setExecutor(this); - } - - @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { - if (!( commandSender instanceof Player)) { - EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef()); - return true; - } - - if (!commandSender.hasPermission("qol.discordignore")) { - EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); - return true; - } - - if (!DiscordSRV.api.isAnyHooked()) { - EtzTechUtil.sms(commandSender, "Command not enabled!"); - return true; - } - - Player player = (Player) commandSender; - - boolean ignoreState = player.hasMetadata(DISCORD_IGNORE_METADATA); - String msg; - if (ignoreState) { - player.removeMetadata(DISCORD_IGNORE_METADATA, plugin); - msg = "Discord messages will now appear."; - } - else { - player.setMetadata(DISCORD_IGNORE_METADATA, new FixedMetadataValue(plugin, DISCORD_IGNORE_METADATA)); - msg = "Ignoring Discord messages."; - } - - EtzTechUtil.sms(commandSender, org.bukkit.ChatColor.GREEN + msg); - return true; - } -} diff --git a/src/main/java/xyz/etztech/qol/commands/MoonCommand.java b/src/main/java/xyz/etztech/qol/commands/MoonCommand.java deleted file mode 100644 index 3e0aa80..0000000 --- a/src/main/java/xyz/etztech/qol/commands/MoonCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package xyz.etztech.qol.commands; - -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import xyz.etztech.qol.QoL; -import xyz.etztech.qol.EtzTechUtil; -import xyz.etztech.qol.Lang; - -import java.util.Map; -import java.lang.*; - -public class MoonCommand implements CommandExecutor { - QoL plugin; - - private final Map moonPhases = Map.of( - 0, "Full moon", - 1, "Waning gibbous", - 2, "Third quarter", - 3, "Waning crescent", - 4, "New moon", - 5, "Waxing crescent", - 6, "First quarter", - 7, "Waxing gibbous" - ); - - public MoonCommand(QoL paramQoL) { - this.plugin = paramQoL; - plugin.getCommand("moon").setExecutor(this); - } - - @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { - if (!commandSender.hasPermission("qol.moon")) { - EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); - return true; - } - - String playername = commandSender.getName(); - long time = commandSender.getServer().getPlayer(playername).getWorld().getFullTime(); - double day = Math.floor(time / 24000); - int moonPhase = (int)(day % 8); - - StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Moon Phase Utility ====="); - message.append("\n" + ChatColor.GREEN + "Current moon phase: " + moonPhases.get(moonPhase) + "."); - message.append("\n" + ChatColor.GREEN + "Full moon is " + (moonPhase == 0 ? "tonight." : "in " + (8 - moonPhase) + ((moonPhase == 7) ? " day." : " days."))); - EtzTechUtil.sms(commandSender, message.toString()); - return true; - } -} diff --git a/src/main/java/xyz/etztech/qol/commands/WikiCommand.java b/src/main/java/xyz/etztech/qol/commands/WikiCommand.java deleted file mode 100644 index c8d4742..0000000 --- a/src/main/java/xyz/etztech/qol/commands/WikiCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package xyz.etztech.qol.commands; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import xyz.etztech.qol.QoL; -import xyz.etztech.qol.EtzTechUtil; -import xyz.etztech.qol.Lang; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.Date; - -public class WikiCommand implements CommandExecutor { - QoL plugin; - - public WikiCommand(QoL paramQoL) { - this.plugin = paramQoL; - plugin.getCommand("wiki").setExecutor(this); - } - - @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { - if (!commandSender.hasPermission("qol.wiki")) { - EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef()); - return true; - } - if (args.length < 1) { - EtzTechUtil.sms(commandSender, ChatColor.RED + "Please give a search argument."); - return true; - } - - try { - Date changedToAt; - JsonObject obj; - InputStream response = new URL(String.format("https://minecraft.gamepedia.com/api.php?action=opensearch&format=json&formatversion=2&search=%s&namespace=0&limit=1", args[0])).openStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(response)); - JsonArray jsonArray = new JsonParser().parse(reader.readLine()).getAsJsonArray(); - StringBuilder message = new StringBuilder(ChatColor.GREEN + jsonArray.get(1).getAsJsonArray().get(0).getAsString()); - message.append(": "); - message.append(ChatColor.WHITE + jsonArray.get(3).getAsJsonArray().get(0).getAsString()); - - EtzTechUtil.sms(commandSender, message.toString()); - } catch (IOException e) { - EtzTechUtil.sms(commandSender, ChatColor.RED + "Minecraft wiki API returned nothing."); - } catch (IndexOutOfBoundsException e) { - EtzTechUtil.sms(commandSender, ChatColor.RED + String.format("Nothing was found on the wiki using: %s", args[0])); - } - - return true; - } -} diff --git a/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java b/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java index 72ca6fd..b737bc5 100644 --- a/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java @@ -1,15 +1,9 @@ package xyz.etztech.qol.listeners; import github.scarsz.discordsrv.DiscordSRV; -import github.scarsz.discordsrv.api.events.DiscordGuildMessagePreBroadcastEvent; import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import xyz.etztech.qol.EtzTechUtil; -import xyz.etztech.qol.Lang; import xyz.etztech.qol.QoL; import github.scarsz.discordsrv.api.Subscribe; -import xyz.etztech.qol.commands.DiscordIgnoreCommand; public class DiscordSRVListener { private final QoL plugin; @@ -26,18 +20,4 @@ public class DiscordSRVListener { } } - @Subscribe - public void discordGuildMessagePreBroadcastEvent(DiscordGuildMessagePreBroadcastEvent event) { - event.getRecipients().removeIf(recipient -> { - if (recipient instanceof Player) { - Player player = (Player) recipient; - - return player.hasMetadata(DiscordIgnoreCommand.DISCORD_IGNORE_METADATA); - } - else { - return false; - } - }); - } - } diff --git a/src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java b/src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java deleted file mode 100644 index cd99c11..0000000 --- a/src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package xyz.etztech.qol.listeners; - -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import xyz.etztech.qol.QoL; - -public class EntityChangeBlockListener implements Listener { - QoL plugin; - - public EntityChangeBlockListener(QoL plugin) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @EventHandler - public void onEntityChangeBlock(EntityChangeBlockEvent e) { - if (e.getEntity().getType() == EntityType.ENDERMAN) { - if(plugin.getConfig().getBoolean("disable-mob-grief.enderman", false)){ - e.setCancelled(true); - } - } - - } -} diff --git a/src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java b/src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java deleted file mode 100644 index 88b6b1a..0000000 --- a/src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java +++ /dev/null @@ -1,68 +0,0 @@ -package xyz.etztech.qol.listeners; - -import com.nisovin.shopkeepers.api.ShopkeepersPlugin; -import com.nisovin.shopkeepers.api.shopkeeper.ShopkeeperRegistry; -import com.nisovin.shopkeepers.api.shopkeeper.admin.regular.RegularAdminShopkeeper; -import com.nisovin.shopkeepers.api.shopkeeper.offers.TradeOffer; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; -import xyz.etztech.qol.QoL; - -import java.util.ArrayList; -import java.util.List; - -public class HeadShopListener implements Listener{ - - private final QoL plugin; - private final ShopkeepersPlugin shopkeepersAPI; - - public HeadShopListener(QoL plugin) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - - this.shopkeepersAPI = ShopkeepersPlugin.getInstance(); - } - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - final Player player = event.getPlayer(); - - if (shopkeepersAPI != null && player.hasPermission("qol.head_shop")) { - int shopKeeperID = plugin.getConfig().getInt("head_shop.id", -1); - - if (shopKeeperID != -1) { - ShopkeeperRegistry shopkeeperRegistry = shopkeepersAPI.getShopkeeperRegistry(); - RegularAdminShopkeeper donorHeadShop = (RegularAdminShopkeeper) shopkeeperRegistry.getShopkeeperById(shopKeeperID); - - if (donorHeadShop != null) { - // Remove the head if it already exists. This is done to refresh the skin of the head. - List tradeOffers = new ArrayList<>(donorHeadShop.getOffers()); - tradeOffers.removeIf(tradeOffer -> { - SkullMeta itemOfferMeta = (SkullMeta)tradeOffer.getResultItem().getItemMeta(); - return itemOfferMeta.getOwningPlayer().getUniqueId() == player.getUniqueId(); - }); - - donorHeadShop.setOffers(tradeOffers); - - // Add the head to the shop - int diamondPrice = plugin.getConfig().getInt("head_shop.price", 2); - ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD); - SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta(); - - skullMeta.setOwningPlayer(player); - skullMeta.setDisplayName(player.getDisplayName()); - playerHead.setItemMeta(skullMeta); - - TradeOffer donorHeadTrade = TradeOffer.create(playerHead, new ItemStack(Material.DIAMOND, diamondPrice), null); - - donorHeadShop.addOffer(donorHeadTrade); - } - } - } - } -} diff --git a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java index 5083eaa..5b12cd5 100644 --- a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java @@ -2,10 +2,13 @@ package xyz.etztech.qol.listeners; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.dynmap.markers.Marker; import xyz.etztech.qol.QoL; import xyz.etztech.qol.commands.CheckupCommand; diff --git a/src/main/java/xyz/etztech/qol/other/TPSRunnable.java b/src/main/java/xyz/etztech/qol/other/TPSRunnable.java index 632d804..57cf0a4 100644 --- a/src/main/java/xyz/etztech/qol/other/TPSRunnable.java +++ b/src/main/java/xyz/etztech/qol/other/TPSRunnable.java @@ -1,11 +1,9 @@ package xyz.etztech.qol.other; -import me.lucko.spark.api.statistic.StatisticWindow; -import me.lucko.spark.api.statistic.types.DoubleStatistic; +import net.ess3.api.IEssentials; import org.apache.commons.lang.StringUtils; import xyz.etztech.core.web.Http; import xyz.etztech.qol.QoL; -import me.lucko.spark.api.Spark; import java.util.HashMap; import java.util.Map; @@ -20,13 +18,13 @@ public class TPSRunnable implements Runnable { @Override public void run() { - Spark spark = plugin.getSpark(); - if (spark != null) { - DoubleStatistic tps = spark.tps(); + IEssentials essentials = plugin.getEssentials(); + if (essentials != null) { + double tps = essentials.getTimer().getAverageTPS(); int threshold = plugin.getConfig().getInt("tps.threshold", 0); String webhook = plugin.getConfig().getString("tps.webhook", ""); String message = "@here TPS has fallen below " + threshold + "!"; - if (tps.poll(StatisticWindow.TicksPerSecond.SECONDS_10) < threshold) { + if (tps < threshold) { plugin.log(message); if (StringUtils.isNotEmpty(webhook)) { Map data = new HashMap<>(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6f949ef..102a360 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -93,9 +93,6 @@ disable-fire: ender_crystal: false explosion: false -disable-mob-grief: - enderman: false - # A list of commands to confirm before using if the user isn't in spectator mode spec-confirm: - "tp" @@ -116,11 +113,3 @@ dynmap: defaults: map: "surface" zoom: 5 - -# Shopkeepers Player Head Shop -head_shop: - # Shopkeeper Shop ID, set to -1 to disable - id: -1 - # Diamond price of a head in the shop, default is 2 diamonds - price: 2 - diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0f5958b..098c952 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,8 +4,7 @@ description: ${description} author: ${author} website: ${url} main: ${mainClass} -softdepend: [spark, dynmap, DiscordSRV, Shopkeepers] -api-version: 1.13 +softdepend: [Essentials, dynmap, DiscordSRV] commands: qol: description: Base command @@ -47,13 +46,6 @@ commands: marker: description: Dynmap marker command aliases: [mark] - wiki: - description: Search the Minecraft wiki - moon: - description: Get information about the current moon phase - discordignore: - description: Mute chat messages coming from Discord - aliases: [dignore] permissions: qol.admin: description: Ability to reload the plugin @@ -124,15 +116,3 @@ permissions: default: op children: qol.marker.limit: true - qol.wiki: - description: Ability to use the wiki command - default: op - qol.moon: - description: Ability to use the moon command - default: op - qol.discordignore: - description: Ability to use the use the discordignore command - default: op - qol.head_shop: - description: Controls if a player's head should be added to the head shop - default: op