From 3f7a4c2d88064a84131757d4c6c836f8f9c4413d Mon Sep 17 00:00:00 2001 From: Mighty_Squid <103967@gmail.com> Date: Fri, 30 Jul 2021 22:19:34 +0200 Subject: [PATCH 1/4] Add moon phase command --- 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 df292f88c50e793de4e8d722939ffb6ff9f8cd01 Mon Sep 17 00:00:00 2001 From: Mighty_Squid Date: Tue, 3 Aug 2021 00:29:04 +0000 Subject: [PATCH 2/4] 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 3/4] 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 4/4] 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