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 <joey@ahines.net>
Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/18
Reviewed-by: Etzelia <etzelia@hotmail.com>
Co-Authored-By: ZeroHD <joey@ahines.net>
Co-Committed-By: ZeroHD <joey@ahines.net>
benamaurer-chatchatDiscod latest
Joey Hines 2021-08-10 01:32:17 +00:00 committed by Etzelia
parent f327f59d6c
commit 0c08c26854
6 changed files with 100 additions and 6 deletions

12
pom.xml
View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.15</version>
<version>1.16</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
@ -62,6 +62,12 @@
<version>0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.nisovin.shopkeepers</groupId>
<artifactId>ShopkeepersAPI</artifactId>
<version>2.13.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
@ -97,6 +103,10 @@
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>shopkeepers-repo</id>
<url>https://nexus.lichtspiele.org/repository/releases/</url>
</repository>
</repositories>
<build>

View File

@ -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

View File

@ -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<? extends TradeOffer> 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);
}
}
}
}
}

View File

@ -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;

View File

@ -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

View File

@ -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