From 693f3cdf54ef4337def17a09c891d84ba6666ab7 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 19 Jun 2021 22:00:19 -0600 Subject: [PATCH 01/12] Added reminder groups + Multiple reminder groups can be define + Reminders still occur as set by the frequency + Each group can be configured with its own chat color and period + The period config defines how many reminder cycles it takes before that group's next message is used --- pom.xml | 6 +- src/main/java/xyz/etztech/qol/QoL.java | 22 +++---- .../java/xyz/etztech/qol/other/Reminder.java | 63 +++++++++++++++++++ .../xyz/etztech/qol/other/ReminderList.java | 46 ++++++++++++++ src/main/resources/config.yml | 17 +++-- 5 files changed, 133 insertions(+), 21 deletions(-) create mode 100644 src/main/java/xyz/etztech/qol/other/Reminder.java create mode 100644 src/main/java/xyz/etztech/qol/other/ReminderList.java diff --git a/pom.xml b/pom.xml index 6f2a341..88326e3 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ xyz.etztech plugin-api - 1.0.8 + 1.0.7 net.ess3 @@ -72,8 +72,8 @@ https://nexus.scarsz.me/content/groups/public/ - etztech-repo - http://repo.etztech.xyz + birbmc-repo + https://mvn.birbmc.com dynmap-repo diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 8d26c61..469932a 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -2,7 +2,6 @@ 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.file.FileConfiguration; import org.bukkit.entity.Player; @@ -15,6 +14,7 @@ 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 java.util.ArrayList; @@ -45,6 +45,8 @@ public class QoL extends JavaPlugin { private static List audits = new ArrayList<>(); private static List links = new ArrayList<>(); + private Reminder reminder = null; + public void onEnable() { instance = this; saveDefaultConfig(); @@ -136,25 +138,15 @@ public class QoL extends JavaPlugin { }, 0, EtzTechUtil.minutesToTicks(schedule)); } - // Reminders - int frequency = config.getInt("reminders.frequency"); - if (frequency > 0) { + if (reminder != null && reminder.getFrequency() != 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)); + player.spigot().sendMessage(reminder.nextReminder()); } - idx++; } - }, 0, EtzTechUtil.minutesToTicks(frequency)); + }, 0, EtzTechUtil.minutesToTicks(reminder.getFrequency())); } // TPS Check @@ -186,6 +178,8 @@ public class QoL extends JavaPlugin { 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")); } diff --git a/src/main/java/xyz/etztech/qol/other/Reminder.java b/src/main/java/xyz/etztech/qol/other/Reminder.java new file mode 100644 index 0000000..3f39830 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/Reminder.java @@ -0,0 +1,63 @@ +package xyz.etztech.qol.other; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import org.bukkit.configuration.ConfigurationSection; +import net.md_5.bungee.api.ChatColor; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Reminder { + private final int frequency; + private final List reminderLists; + + public Reminder(int frequency, List reminderLists) { + this.frequency = frequency; + this.reminderLists = reminderLists; + Collections.sort(reminderLists); + } + + public static Reminder fromConfig(ConfigurationSection config) { + int frequency = config.getInt("frequency"); + List reminderLists = new ArrayList(); + ConfigurationSection reminderGroups = config.getConfigurationSection("reminder_groups"); + + for (String groupName: reminderGroups.getKeys(false)) { + ConfigurationSection group = reminderGroups.getConfigurationSection(groupName); + + int period = group.getInt("period", 0); + ChatColor color = ChatColor.of(group.getString("color", "#3273DC")); + List reminders = group.getStringList("reminders"); + + reminderLists.add(new ReminderList(reminders, period, color)); + } + + return new Reminder(frequency, reminderLists); + } + + public BaseComponent[] nextReminder() { + BaseComponent[] msg = null; + boolean reminderFound = false; + for (ReminderList reminderList: reminderLists) { + if (!reminderFound && reminderList.isReady()) { + msg = new ComponentBuilder(). + color(reminderList.getColor()) + .append(reminderList.nextReminder()) + .create(); + + reminderFound = true; + + } + + reminderList.incCount(); + } + + return msg; + } + + public int getFrequency() { + return frequency; + } +} diff --git a/src/main/java/xyz/etztech/qol/other/ReminderList.java b/src/main/java/xyz/etztech/qol/other/ReminderList.java new file mode 100644 index 0000000..c44c07d --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/ReminderList.java @@ -0,0 +1,46 @@ +package xyz.etztech.qol.other; + +import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class ReminderList implements Comparable{ + private final List reminders; + private final int period; + private final ChatColor color; + private int ndx; + private int count; + + public ReminderList(List reminders, int period, ChatColor color) { + this.reminders = reminders; + this.period = period; + this.color = color; + this.ndx = 0; + this.count = 0; + } + + public void incCount() { + count = (count + 1) % (period + 1); + } + + public boolean isReady() { + return count == period; + } + + public String nextReminder() { + String nextReminder = reminders.get(ndx); + ndx = (ndx + 1) % reminders.size(); + + return nextReminder; + } + + @Override + public int compareTo(@NotNull ReminderList o) { + return Integer.compare(o.period, this.period); + } + + public ChatColor getColor() { + return color; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17b14b4..102a360 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -60,10 +60,19 @@ schedule: # To disable, set minutes to 0 reminders: - frequency: 5 # In minutes - color: '&a' - messages: - - 'Check out the Discord!' + frequency: 1 # In minutes + reminder_groups: + standard: + color: '#3273DC' + reminders: + - '1st Standard Reminder' + - '2nd Standard Reminder' + event: + color: '#3273DC' + period: 2 + reminders: + - '1st Event Reminder' + - '2nd Event Reminder' # A list of links for link command aliases, separated by a comma between name and URL links: -- 2.41.0 From 684b269039317920be8781c37441e280fa373c39 Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Fri, 25 Jun 2021 16:08:50 +0000 Subject: [PATCH 02/12] Added reminder groups (#3) Added reminder groups + Multiple reminder groups can be define + Reminders still occur as set by the frequency + Each group can be configured with its own chat color and period + The period config defines how many reminder cycles it takes before that group's next message is used Co-authored-by: Joey Hines Reviewed-on: https://git.birbmc.com/Canopy/QoL/pulls/3 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 6 +- src/main/java/xyz/etztech/qol/QoL.java | 22 +++---- .../java/xyz/etztech/qol/other/Reminder.java | 63 +++++++++++++++++++ .../xyz/etztech/qol/other/ReminderList.java | 46 ++++++++++++++ src/main/resources/config.yml | 17 +++-- 5 files changed, 133 insertions(+), 21 deletions(-) create mode 100644 src/main/java/xyz/etztech/qol/other/Reminder.java create mode 100644 src/main/java/xyz/etztech/qol/other/ReminderList.java diff --git a/pom.xml b/pom.xml index 6f2a341..88326e3 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ xyz.etztech plugin-api - 1.0.8 + 1.0.7 net.ess3 @@ -72,8 +72,8 @@ https://nexus.scarsz.me/content/groups/public/ - etztech-repo - http://repo.etztech.xyz + birbmc-repo + https://mvn.birbmc.com dynmap-repo diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 8d26c61..469932a 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -2,7 +2,6 @@ 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.file.FileConfiguration; import org.bukkit.entity.Player; @@ -15,6 +14,7 @@ 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 java.util.ArrayList; @@ -45,6 +45,8 @@ public class QoL extends JavaPlugin { private static List audits = new ArrayList<>(); private static List links = new ArrayList<>(); + private Reminder reminder = null; + public void onEnable() { instance = this; saveDefaultConfig(); @@ -136,25 +138,15 @@ public class QoL extends JavaPlugin { }, 0, EtzTechUtil.minutesToTicks(schedule)); } - // Reminders - int frequency = config.getInt("reminders.frequency"); - if (frequency > 0) { + if (reminder != null && reminder.getFrequency() != 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)); + player.spigot().sendMessage(reminder.nextReminder()); } - idx++; } - }, 0, EtzTechUtil.minutesToTicks(frequency)); + }, 0, EtzTechUtil.minutesToTicks(reminder.getFrequency())); } // TPS Check @@ -186,6 +178,8 @@ public class QoL extends JavaPlugin { 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")); } diff --git a/src/main/java/xyz/etztech/qol/other/Reminder.java b/src/main/java/xyz/etztech/qol/other/Reminder.java new file mode 100644 index 0000000..3f39830 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/Reminder.java @@ -0,0 +1,63 @@ +package xyz.etztech.qol.other; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import org.bukkit.configuration.ConfigurationSection; +import net.md_5.bungee.api.ChatColor; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Reminder { + private final int frequency; + private final List reminderLists; + + public Reminder(int frequency, List reminderLists) { + this.frequency = frequency; + this.reminderLists = reminderLists; + Collections.sort(reminderLists); + } + + public static Reminder fromConfig(ConfigurationSection config) { + int frequency = config.getInt("frequency"); + List reminderLists = new ArrayList(); + ConfigurationSection reminderGroups = config.getConfigurationSection("reminder_groups"); + + for (String groupName: reminderGroups.getKeys(false)) { + ConfigurationSection group = reminderGroups.getConfigurationSection(groupName); + + int period = group.getInt("period", 0); + ChatColor color = ChatColor.of(group.getString("color", "#3273DC")); + List reminders = group.getStringList("reminders"); + + reminderLists.add(new ReminderList(reminders, period, color)); + } + + return new Reminder(frequency, reminderLists); + } + + public BaseComponent[] nextReminder() { + BaseComponent[] msg = null; + boolean reminderFound = false; + for (ReminderList reminderList: reminderLists) { + if (!reminderFound && reminderList.isReady()) { + msg = new ComponentBuilder(). + color(reminderList.getColor()) + .append(reminderList.nextReminder()) + .create(); + + reminderFound = true; + + } + + reminderList.incCount(); + } + + return msg; + } + + public int getFrequency() { + return frequency; + } +} diff --git a/src/main/java/xyz/etztech/qol/other/ReminderList.java b/src/main/java/xyz/etztech/qol/other/ReminderList.java new file mode 100644 index 0000000..c44c07d --- /dev/null +++ b/src/main/java/xyz/etztech/qol/other/ReminderList.java @@ -0,0 +1,46 @@ +package xyz.etztech.qol.other; + +import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class ReminderList implements Comparable{ + private final List reminders; + private final int period; + private final ChatColor color; + private int ndx; + private int count; + + public ReminderList(List reminders, int period, ChatColor color) { + this.reminders = reminders; + this.period = period; + this.color = color; + this.ndx = 0; + this.count = 0; + } + + public void incCount() { + count = (count + 1) % (period + 1); + } + + public boolean isReady() { + return count == period; + } + + public String nextReminder() { + String nextReminder = reminders.get(ndx); + ndx = (ndx + 1) % reminders.size(); + + return nextReminder; + } + + @Override + public int compareTo(@NotNull ReminderList o) { + return Integer.compare(o.period, this.period); + } + + public ChatColor getColor() { + return color; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17b14b4..102a360 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -60,10 +60,19 @@ schedule: # To disable, set minutes to 0 reminders: - frequency: 5 # In minutes - color: '&a' - messages: - - 'Check out the Discord!' + frequency: 1 # In minutes + reminder_groups: + standard: + color: '#3273DC' + reminders: + - '1st Standard Reminder' + - '2nd Standard Reminder' + event: + color: '#3273DC' + period: 2 + reminders: + - '1st Event Reminder' + - '2nd Event Reminder' # A list of links for link command aliases, separated by a comma between name and URL links: -- 2.41.0 From e91e5ae9e54beee4efa5aef83f2161fcb19750b9 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 27 Jun 2021 20:13:43 -0600 Subject: [PATCH 03/12] Added .drone.yml --- .drone.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..4448638 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,36 @@ +--- +kind: pipeline +type: docker +name: compliance + +steps: + - name: build + image: maven:3-openjdk-16 + commands: + - mvn install + +--- +kind: pipeline +type: docker +name: release + +trigger: + branch: + - main + event: + - push + +steps: + - name: build + image: maven:3-openjdk-16 + commands: + - mvn install + - name: gitea-release + pull: always + image: jolheiser/drone-gitea-main:latest + settings: + token: + from_secret: gitea_token + base: https://git.canopymc.net + files: + - "target/QoL-*.jar" \ No newline at end of file -- 2.41.0 From 9c316f9fffda497f90c61092ad5e3082987973eb Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 27 Jun 2021 20:18:41 -0600 Subject: [PATCH 04/12] why do we even *need* https --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 88326e3..2776d87 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ dynmap-repo - http://repo.mikeprimm.com/ + https://repo.mikeprimm.com/ ess-repo -- 2.41.0 From e3cf0d6d9fac5f30099fc72b6e7ea6b59c1e5b64 Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Mon, 5 Jul 2021 14:52:41 +0000 Subject: [PATCH 05/12] Switched to Spark for TPS alerts (#8) Switched to Spark for TPS alerts + Currently just looks at tps, but we could hook in mspt + Fixes #6 Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/8 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 21 ++++++++++--------- src/main/java/xyz/etztech/qol/QoL.java | 20 +++++++++++------- .../xyz/etztech/qol/other/TPSRunnable.java | 12 ++++++----- src/main/resources/plugin.yml | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 2776d87..b177e0d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.10 + 1.11 jar @@ -39,11 +39,6 @@ plugin-api 1.0.7 - - net.ess3 - EssentialsX - 2.18.1 - us.dynmap dynmap-api @@ -60,6 +55,12 @@ 1.19.1 provided + + me.lucko + spark-api + 0.1-SNAPSHOT + provided + @@ -78,10 +79,6 @@ dynmap-repo https://repo.mikeprimm.com/ - - - ess-repo - https://ci.ender.zone/plugin/repository/everything/ mvn-repo @@ -95,6 +92,10 @@ jitpack.io https://jitpack.io + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 469932a..66044e4 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -1,10 +1,10 @@ package xyz.etztech.qol; -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; @@ -16,6 +16,7 @@ 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; @@ -28,7 +29,7 @@ public class QoL extends JavaPlugin { private String qolMarkerIcon = null; private static QoL instance; - private IEssentials essentials = null; + private Spark spark = null; private DynmapAPI dynmap = null; private MarkerAPI markerAPI = null; private MarkerSet playerMarkerSet = null; @@ -53,10 +54,11 @@ public class QoL extends JavaPlugin { 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"); + //Spark hook + RegisteredServiceProvider sparkProvider = Bukkit.getServicesManager().getRegistration(Spark.class); + if (sparkProvider != null) { + log("Hooked into Spark for TPS alert."); + spark = sparkProvider.getProvider(); } //Dynmap hook @@ -276,8 +278,6 @@ public class QoL extends JavaPlugin { return links; } - public IEssentials getEssentials() { return essentials; } - public DynmapAPI getDynmap() { return dynmap; } public void runTask(final String command) { @@ -330,5 +330,9 @@ public class QoL extends JavaPlugin { return marker; } } + + public Spark getSpark() { + return spark; + } } diff --git a/src/main/java/xyz/etztech/qol/other/TPSRunnable.java b/src/main/java/xyz/etztech/qol/other/TPSRunnable.java index 57cf0a4..632d804 100644 --- a/src/main/java/xyz/etztech/qol/other/TPSRunnable.java +++ b/src/main/java/xyz/etztech/qol/other/TPSRunnable.java @@ -1,9 +1,11 @@ package xyz.etztech.qol.other; -import net.ess3.api.IEssentials; +import me.lucko.spark.api.statistic.StatisticWindow; +import me.lucko.spark.api.statistic.types.DoubleStatistic; 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; @@ -18,13 +20,13 @@ public class TPSRunnable implements Runnable { @Override public void run() { - IEssentials essentials = plugin.getEssentials(); - if (essentials != null) { - double tps = essentials.getTimer().getAverageTPS(); + Spark spark = plugin.getSpark(); + if (spark != null) { + DoubleStatistic tps = spark.tps(); 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 < threshold) { + if (tps.poll(StatisticWindow.TicksPerSecond.SECONDS_10) < threshold) { plugin.log(message); if (StringUtils.isNotEmpty(webhook)) { Map data = new HashMap<>(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 098c952..5762949 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ description: ${description} author: ${author} website: ${url} main: ${mainClass} -softdepend: [Essentials, dynmap, DiscordSRV] +softdepend: [spark, dynmap, DiscordSRV] commands: qol: description: Base command -- 2.41.0 From 3ae415d7d00234430bd1e8699d4c8db7d706f377 Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Sun, 11 Jul 2021 16:12:13 +0000 Subject: [PATCH 06/12] Marked dynmap-api dependency as `provided` (#10) Marked dynmap-api dependency as `provided` + Fixes #9 Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/10 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index b177e0d..00f9e42 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ us.dynmap dynmap-api 1.9.4 + provided commons-lang -- 2.41.0 From 3c54c249a1f04fd6826a932548ee9dc1e6dc70ba Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Mon, 12 Jul 2021 21:36:03 +0000 Subject: [PATCH 07/12] Each player now gets the same reminder (#12) Each player now gets the same reminder + Reminders are logged to console now + Fixes #11 Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/12 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- src/main/java/xyz/etztech/qol/QoL.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 66044e4..1dc5317 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -1,11 +1,13 @@ 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; @@ -144,9 +146,11 @@ 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(reminder.nextReminder()); + player.spigot().sendMessage(msg); } + Bukkit.getConsoleSender().spigot().sendMessage(msg); } }, 0, EtzTechUtil.minutesToTicks(reminder.getFrequency())); } -- 2.41.0 From 2e72736571bfa15a484780781b991a578f94e2da Mon Sep 17 00:00:00 2001 From: Mighty_Squid Date: Mon, 19 Jul 2021 17:30:59 +0000 Subject: [PATCH 08/12] Initial version of wiki command (#13) Version 1.12 Initial version of wiki command Co-authored-by: Mighty_Squid <103967@gmail.com> Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/13 Reviewed-by: Etzelia Co-Authored-By: Mighty_Squid Co-Committed-By: Mighty_Squid --- pom.xml | 2 +- src/main/java/xyz/etztech/qol/QoL.java | 1 + .../xyz/etztech/qol/commands/WikiCommand.java | 60 +++++++++++++++++++ src/main/resources/plugin.yml | 5 ++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/xyz/etztech/qol/commands/WikiCommand.java diff --git a/pom.xml b/pom.xml index 00f9e42..5e8b769 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.11 + 1.12 jar diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 1dc5317..e1ee728 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -120,6 +120,7 @@ public class QoL extends JavaPlugin { new DeathMuteCommand(this); new CheckupCommand(this); new DynmapLinkCommand(this); + new WikiCommand(this); if (dynmap != null) { new MarkerCommand(this); diff --git a/src/main/java/xyz/etztech/qol/commands/WikiCommand.java b/src/main/java/xyz/etztech/qol/commands/WikiCommand.java new file mode 100644 index 0000000..c8d4742 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/WikiCommand.java @@ -0,0 +1,60 @@ +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/resources/plugin.yml b/src/main/resources/plugin.yml index 5762949..7753706 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -46,6 +46,8 @@ commands: marker: description: Dynmap marker command aliases: [mark] + wiki: + description: Search the Minecraft wiki permissions: qol.admin: description: Ability to reload the plugin @@ -116,3 +118,6 @@ permissions: default: op children: qol.marker.limit: true + qol.wiki: + description: Ability to use the wiki command + default: op -- 2.41.0 From fa2f79239ed3b4db9f18ebd5070add7dc21a27bc Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Wed, 21 Jul 2021 00:20:25 +0000 Subject: [PATCH 09/12] Add Config To Disable Enderman Grief (#14) Added default config value Bumped version number Add config for disabling enderman grief Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/14 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 2 +- src/main/java/xyz/etztech/qol/QoL.java | 1 + .../listeners/EntityChangeBlockListener.java | 26 +++++++++++++++++++ src/main/resources/config.yml | 3 +++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java diff --git a/pom.xml b/pom.xml index 5e8b769..84a0e37 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.12 + 1.13 jar diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index e1ee728..e841f54 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -104,6 +104,7 @@ public class QoL extends JavaPlugin { new BlockIgniteListener(this); new CommandPreprocessListener(this); new DeathListener(this); + new EntityChangeBlockListener(this); // Add commands new MainCommand(this); diff --git a/src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java b/src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java new file mode 100644 index 0000000..cd99c11 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/listeners/EntityChangeBlockListener.java @@ -0,0 +1,26 @@ +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/resources/config.yml b/src/main/resources/config.yml index 102a360..4c297df 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -93,6 +93,9 @@ 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" -- 2.41.0 From df292f88c50e793de4e8d722939ffb6ff9f8cd01 Mon Sep 17 00:00:00 2001 From: Mighty_Squid Date: Tue, 3 Aug 2021 00:29:04 +0000 Subject: [PATCH 10/12] Add moon phase command (#15) Add moon phase command Co-authored-by: Mighty_Squid <103967@gmail.com> Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/15 Reviewed-by: ZeroHD Co-Authored-By: Mighty_Squid Co-Committed-By: Mighty_Squid --- pom.xml | 4 +- src/main/java/xyz/etztech/qol/QoL.java | 1 + .../xyz/etztech/qol/commands/MoonCommand.java | 51 +++++++++++++++++++ src/main/resources/plugin.yml | 5 ++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/main/java/xyz/etztech/qol/commands/MoonCommand.java diff --git a/pom.xml b/pom.xml index 84a0e37..d8ddb0f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.13 + 1.14 jar @@ -161,4 +161,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 e841f54..d4bbc59 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -122,6 +122,7 @@ public class QoL extends JavaPlugin { new CheckupCommand(this); new DynmapLinkCommand(this); new WikiCommand(this); + new MoonCommand(this); if (dynmap != null) { new MarkerCommand(this); diff --git a/src/main/java/xyz/etztech/qol/commands/MoonCommand.java b/src/main/java/xyz/etztech/qol/commands/MoonCommand.java new file mode 100644 index 0000000..3e0aa80 --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/MoonCommand.java @@ -0,0 +1,51 @@ +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/resources/plugin.yml b/src/main/resources/plugin.yml index 7753706..0f7467c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -48,6 +48,8 @@ commands: aliases: [mark] wiki: description: Search the Minecraft wiki + moon: + description: Get information about the current moon phase permissions: qol.admin: description: Ability to reload the plugin @@ -121,3 +123,6 @@ permissions: qol.wiki: description: Ability to use the wiki command default: op + qol.moon: + description: Ability to use the moon command + default: op -- 2.41.0 From f327f59d6caeec347302e65c5448267f29162014 Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Tue, 3 Aug 2021 02:34:17 +0000 Subject: [PATCH 11/12] Added `discordignore` command (#17) Small tweaks + Fixed permission node + Removed unused imports Added `discordignore` command + Toggles Discord messages on/off for the user + Resolves #16 Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/17 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 4 +- src/main/java/xyz/etztech/qol/QoL.java | 5 ++ .../qol/commands/DiscordIgnoreCommand.java | 55 +++++++++++++++++++ .../qol/listeners/DiscordSRVListener.java | 20 +++++++ src/main/resources/plugin.yml | 6 ++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java diff --git a/pom.xml b/pom.xml index d8ddb0f..dfdc86a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.14 + 1.15 jar @@ -53,7 +53,7 @@ com.discordsrv discordsrv - 1.19.1 + 1.23.0 provided diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index d4bbc59..1d53475 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -1,5 +1,6 @@ package xyz.etztech.qol; +import github.scarsz.discordsrv.DiscordSRV; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -124,6 +125,10 @@ public class QoL extends JavaPlugin { new WikiCommand(this); new MoonCommand(this); + if (DiscordSRV.api.isAnyHooked()) { + new DiscordIgnoreCommand(this); + } + if (dynmap != null) { new MarkerCommand(this); } diff --git a/src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java b/src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java new file mode 100644 index 0000000..63ec03f --- /dev/null +++ b/src/main/java/xyz/etztech/qol/commands/DiscordIgnoreCommand.java @@ -0,0 +1,55 @@ +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/listeners/DiscordSRVListener.java b/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java index b737bc5..72ca6fd 100644 --- a/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/DiscordSRVListener.java @@ -1,9 +1,15 @@ 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; @@ -20,4 +26,18 @@ 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/resources/plugin.yml b/src/main/resources/plugin.yml index 0f7467c..da07701 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -50,6 +50,9 @@ commands: 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 @@ -126,3 +129,6 @@ permissions: qol.moon: description: Ability to use the moon command default: op + qol.discordignore: + description: Ability to use the use the discordignore command + default: op -- 2.41.0 From 0c08c268543a99e6d67e6469903ca10509c01def Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Tue, 10 Aug 2021 01:32:17 +0000 Subject: [PATCH 12/12] Added Head Shop (#18) Moved ShopkeepersAPI reference to listener Moved head shop logic to its own listener Move checkup command join outside shopkeeper check Refresh player head on login + Cleaned up imports Use UUID instead of display name to determine if a player is in the shop Check if Shopkeepers is present before trying to enable it Added Head Shop + Integrates with ShopKeepers + On login, users with the `qol.head_shop` perm have their head added to the shop, if not already added + The shop id and the price to charge are both configurable Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/18 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 12 +++- src/main/java/xyz/etztech/qol/QoL.java | 9 ++- .../qol/listeners/HeadShopListener.java | 68 +++++++++++++++++++ .../etztech/qol/listeners/JoinListener.java | 3 - src/main/resources/config.yml | 8 +++ src/main/resources/plugin.yml | 6 +- 6 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java diff --git a/pom.xml b/pom.xml index dfdc86a..e9202bb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.15 + 1.16 jar @@ -62,6 +62,12 @@ 0.1-SNAPSHOT provided + + com.nisovin.shopkeepers + ShopkeepersAPI + 2.13.3 + provided + @@ -97,6 +103,10 @@ sonatype-snapshots https://oss.sonatype.org/content/repositories/snapshots + + shopkeepers-repo + https://nexus.lichtspiele.org/repository/releases/ + diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 1d53475..1b0b3f3 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -1,5 +1,6 @@ package xyz.etztech.qol; +import com.nisovin.shopkeepers.api.ShopkeepersPlugin; import github.scarsz.discordsrv.DiscordSRV; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Bukkit; @@ -8,7 +9,6 @@ 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; @@ -91,10 +91,17 @@ 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 diff --git a/src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java b/src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java new file mode 100644 index 0000000..88b6b1a --- /dev/null +++ b/src/main/java/xyz/etztech/qol/listeners/HeadShopListener.java @@ -0,0 +1,68 @@ +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 5b12cd5..5083eaa 100644 --- a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java @@ -2,13 +2,10 @@ 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/resources/config.yml b/src/main/resources/config.yml index 4c297df..6f949ef 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -116,3 +116,11 @@ 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 da07701..0f5958b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,8 @@ description: ${description} author: ${author} website: ${url} main: ${mainClass} -softdepend: [spark, dynmap, DiscordSRV] +softdepend: [spark, dynmap, DiscordSRV, Shopkeepers] +api-version: 1.13 commands: qol: description: Base command @@ -132,3 +133,6 @@ permissions: 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 -- 2.41.0