Refresh player head on login

+ Cleaned up imports
pull/18/head
Joey Hines 2021-08-06 22:36:33 -06:00
parent 1b5c8625de
commit e66969f039
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
1 changed files with 17 additions and 26 deletions

View File

@ -1,26 +1,18 @@
package xyz.etztech.qol.listeners; package xyz.etztech.qol.listeners;
import com.nisovin.shopkeepers.api.ShopkeepersAPI;
import com.nisovin.shopkeepers.api.ShopkeepersPlugin; 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.ShopkeeperRegistry;
import com.nisovin.shopkeepers.api.shopkeeper.admin.regular.RegularAdminShopkeeper; 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.shopkeeper.offers.TradeOffer;
import com.nisovin.shopkeepers.api.shopobjects.ShopObject;
import com.nisovin.shopkeepers.api.storage.ShopkeeperStorage;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.dynmap.markers.Marker;
import xyz.etztech.qol.QoL; import xyz.etztech.qol.QoL;
import xyz.etztech.qol.commands.CheckupCommand; import xyz.etztech.qol.commands.CheckupCommand;
@ -79,28 +71,27 @@ public class JoinListener implements Listener {
RegularAdminShopkeeper donorHeadShop = (RegularAdminShopkeeper) shopkeeperRegistry.getShopkeeperById(shopKeeperID); RegularAdminShopkeeper donorHeadShop = (RegularAdminShopkeeper) shopkeeperRegistry.getShopkeeperById(shopKeeperID);
if (donorHeadShop != null) { if (donorHeadShop != null) {
// Remove the head if it already exists. This is done to refresh the skin of the head.
boolean donorFound = false; List<? extends TradeOffer> tradeOffers = new ArrayList<>(donorHeadShop.getOffers());
for (TradeOffer tradeOffer: donorHeadShop.getOffers()) { tradeOffers.removeIf(tradeOffer -> {
SkullMeta itemOfferMeta = (SkullMeta)tradeOffer.getResultItem().getItemMeta(); SkullMeta itemOfferMeta = (SkullMeta)tradeOffer.getResultItem().getItemMeta();
if (itemOfferMeta.getOwningPlayer().getUniqueId() == player.getUniqueId()) { return itemOfferMeta.getOwningPlayer().getUniqueId() == player.getUniqueId();
donorFound = true; });
break;
}
}
if (!donorFound) { donorHeadShop.setOffers(tradeOffers);
int diamondPrice = plugin.getConfig().getInt("head_shop.price", 2);
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta();
skullMeta.setOwningPlayer(player); // Add the head to the shop
skullMeta.setDisplayName(player.getDisplayName()); int diamondPrice = plugin.getConfig().getInt("head_shop.price", 2);
playerHead.setItemMeta(skullMeta); ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta();
TradeOffer donorHeadTrade = TradeOffer.create(playerHead, new ItemStack(Material.DIAMOND, diamondPrice), null); skullMeta.setOwningPlayer(player);
donorHeadShop.addOffer(donorHeadTrade); skullMeta.setDisplayName(player.getDisplayName());
} playerHead.setItemMeta(skullMeta);
TradeOffer donorHeadTrade = TradeOffer.create(playerHead, new ItemStack(Material.DIAMOND, diamondPrice), null);
donorHeadShop.addOffer(donorHeadTrade);
} }
} }