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
pull/18/head
Joey Hines 2021-08-06 21:21:12 -06:00
parent f327f59d6c
commit b6ffbf7168
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
5 changed files with 87 additions and 3 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,7 @@
package xyz.etztech.qol;
import com.nisovin.shopkeepers.api.ShopkeepersAPI;
import com.nisovin.shopkeepers.api.ShopkeepersPlugin;
import github.scarsz.discordsrv.DiscordSRV;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
@ -38,6 +40,7 @@ public class QoL extends JavaPlugin {
private MarkerSet playerMarkerSet = null;
private boolean qolMarkerLayerShow = false;
private String qolMarkerSetLabel = null;
private ShopkeepersPlugin shopkeepersAPI = null;
public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" );
@ -95,6 +98,13 @@ public class QoL extends JavaPlugin {
new DiscordSRVListener(this);
}
try {
shopkeepersAPI = ShopkeepersPlugin.getInstance();
log("Hooked in Shopkeepers for the Donor Shop");
}
catch (Exception ignored) {}
if( isEnabled() ) {
// Add listeners
@ -346,5 +356,9 @@ public class QoL extends JavaPlugin {
public Spark getSpark() {
return spark;
}
public ShopkeepersPlugin getShopkeepersAPI() {
return shopkeepersAPI;
}
}

View File

@ -1,13 +1,25 @@
package xyz.etztech.qol.listeners;
import com.nisovin.shopkeepers.api.ShopkeepersAPI;
import com.nisovin.shopkeepers.api.ShopkeepersPlugin;
import com.nisovin.shopkeepers.api.shopkeeper.Shopkeeper;
import com.nisovin.shopkeepers.api.shopkeeper.ShopkeeperRegistry;
import com.nisovin.shopkeepers.api.shopkeeper.admin.regular.RegularAdminShopkeeper;
import com.nisovin.shopkeepers.api.shopkeeper.offers.PriceOffer;
import com.nisovin.shopkeepers.api.shopkeeper.offers.TradeOffer;
import com.nisovin.shopkeepers.api.shopobjects.ShopObject;
import com.nisovin.shopkeepers.api.storage.ShopkeeperStorage;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
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.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.dynmap.markers.Marker;
import xyz.etztech.qol.QoL;
import xyz.etztech.qol.commands.CheckupCommand;
@ -58,7 +70,43 @@ public class JoinListener implements Listener {
}
}
CheckupCommand.join(player);
ShopkeepersPlugin shopkeepersAPI = plugin.getShopkeepersAPI();
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) {
boolean donorFound = false;
for (TradeOffer tradeOffer: donorHeadShop.getOffers()) {
if (tradeOffer.getResultItem().getItemMeta().getDisplayName().equals(player.getDisplayName())) {
donorFound = true;
break;
}
}
if (!donorFound) {
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);
}
}
}
CheckupCommand.join(player);
}
}
}

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