mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-20 22:31:48 +01:00
Mark shop items for enchantment prevention
This commit is contained in:
parent
1fdb18dfe1
commit
b8822c2a57
src/main/java/com/gamingmesh/jobs
@ -107,7 +107,7 @@ public final class ItemBoostManager {
|
||||
|
||||
String node = one.toLowerCase();
|
||||
|
||||
JobItems jitem = new JobItems(node);
|
||||
JobItems jitem = new JobItems(node).setType(JobsItemType.Boosted);
|
||||
|
||||
jitem.setJobs(jobs);
|
||||
jitem.setBoostMultiplier(b);
|
||||
@ -255,7 +255,19 @@ public final class ItemBoostManager {
|
||||
|
||||
private static final String jobsItemBoost = "JobsItemBoost";
|
||||
|
||||
/**
|
||||
* Checks if the given item is a boosted jobs item.
|
||||
*
|
||||
* @param item the item to check
|
||||
* @return true if the item is a boosted jobs item, false otherwise
|
||||
* @deprecated Use {@link #isBoostedJobsItem(ItemStack)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean containsItemBoostByNBT(ItemStack item) {
|
||||
return isBoostedJobsItem(item);
|
||||
}
|
||||
|
||||
public static boolean isBoostedJobsItem(ItemStack item) {
|
||||
return item != null && new CMINBT(item).hasNBT(jobsItemBoost);
|
||||
}
|
||||
|
||||
@ -263,17 +275,18 @@ public final class ItemBoostManager {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
Object itemName = new CMINBT(item).getString(jobsItemBoost);
|
||||
CMINBT nbt = new CMINBT(item);
|
||||
Object itemName = nbt.getString(jobsItemBoost);
|
||||
|
||||
if (itemName == null || itemName.toString().isEmpty()) {
|
||||
// Checking old boost items and converting to new format if needed
|
||||
if (new CMINBT(item).hasNBT(jobsItemBoost)) {
|
||||
if (nbt.hasNBT(jobsItemBoost)) {
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
itemName = new CMINBT(item).getString(jobsItemBoost + "." + one.getName());
|
||||
itemName = nbt.getString(jobsItemBoost + "." + one.getName());
|
||||
if (itemName != null) {
|
||||
JobItems b = getItemByKey(itemName.toString());
|
||||
if (b != null) {
|
||||
ItemStack ic = (ItemStack) new CMINBT(item).setString(jobsItemBoost, b.getNode());
|
||||
ItemStack ic = (ItemStack) nbt.setString(jobsItemBoost, b.getNode());
|
||||
item.setItemMeta(ic.getItemMeta());
|
||||
}
|
||||
break;
|
||||
|
5
src/main/java/com/gamingmesh/jobs/JobsItemType.java
Normal file
5
src/main/java/com/gamingmesh/jobs/JobsItemType.java
Normal file
@ -0,0 +1,5 @@
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
public enum JobsItemType {
|
||||
Shop, Boosted, Unknown;
|
||||
}
|
@ -111,7 +111,7 @@ public class GeneralConfigManager {
|
||||
BossBarEnabled = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse,
|
||||
DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled,
|
||||
LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false,
|
||||
payForEachVTradeItem, allowEnchantingBoostedItems, preventShopItemEnchanting;
|
||||
payForEachVTradeItem, allowEnchantingBoostedItems, preventShopItemEnchanting, preventBoostedItemEnchanting;
|
||||
|
||||
public int ActionBarsMessageKeepFor;
|
||||
|
||||
@ -483,6 +483,9 @@ public class GeneralConfigManager {
|
||||
c.addComment("prevent-shop-item-enchanting", "Prevent players to enchant items from the shop in the anvil with enchanted books");
|
||||
preventShopItemEnchanting = c.get("prevent-shop-item-enchanting", true);
|
||||
|
||||
c.addComment("prevent-boosted-item-enchanting", "Prevent players to enchant boosted jobs items in the anvil with enchanted books");
|
||||
preventBoostedItemEnchanting = c.get("prevent-boosted-item-enchanting", c.getC().getBoolean("prevent-shop-item-enchanting", true));
|
||||
|
||||
c.addComment("jobs-shop-enabled", "Enables or disables jobs shop");
|
||||
jobsshopenabled = c.get("jobs-shop-enabled", true);
|
||||
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.JobsItemType;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobItems;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
@ -36,17 +37,30 @@ import net.Zrips.CMILib.Items.CMIAsyncHead;
|
||||
import net.Zrips.CMILib.Items.CMIItemStack;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.NBT.CMINBT;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ShopManager {
|
||||
|
||||
private final List<ShopItem> list = new ArrayList<>();
|
||||
|
||||
private static final String jobsShopItem = "JobsShopItem";
|
||||
|
||||
public List<ShopItem> getShopItemList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean isShopItem(ItemStack item) {
|
||||
return item != null && new CMINBT(item).hasNBT(jobsShopItem);
|
||||
}
|
||||
|
||||
public static ItemStack applyNBT(ItemStack item, String node) {
|
||||
if (item == null)
|
||||
return null;
|
||||
return (ItemStack) new CMINBT(item).setString(jobsShopItem, node);
|
||||
}
|
||||
|
||||
private List<ShopItem> getItemsByPage(int page) {
|
||||
List<ShopItem> ls = new ArrayList<>();
|
||||
for (ShopItem one : list) {
|
||||
@ -249,6 +263,7 @@ public class ShopManager {
|
||||
GiveItem.giveItemForPlayer(player, item);
|
||||
}
|
||||
};
|
||||
|
||||
CMIItemStack citem = one.getItemStack(player, ahead);
|
||||
if (citem != null && !ahead.isAsyncHead())
|
||||
GiveItem.giveItemForPlayer(player, citem.getItemStack());
|
||||
@ -455,7 +470,7 @@ public class ShopManager {
|
||||
CMIMessages.consoleMessage("&cInvalid ItemStack for boosted item (" + itemString + ")");
|
||||
continue;
|
||||
}
|
||||
JobItems jitem = new JobItems("");
|
||||
JobItems jitem = new JobItems("").setType(JobsItemType.Shop);
|
||||
jitem.setItemString(itemString);
|
||||
items.add(jitem);
|
||||
}
|
||||
@ -542,7 +557,7 @@ public class ShopManager {
|
||||
if (!enchants.toString().isEmpty())
|
||||
itemSring += ";" + enchants.toString();
|
||||
|
||||
JobItems jitem = new JobItems(oneItemName.toLowerCase());
|
||||
JobItems jitem = new JobItems(oneItemName.toLowerCase()).setType(JobsItemType.Shop);
|
||||
|
||||
jitem.setItemString(itemSring);
|
||||
|
||||
|
@ -23,8 +23,13 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gamingmesh.jobs.ItemBoostManager;
|
||||
import com.gamingmesh.jobs.JobsItemType;
|
||||
import com.gamingmesh.jobs.config.ShopManager;
|
||||
|
||||
import net.Zrips.CMILib.Items.CMIAsyncHead;
|
||||
import net.Zrips.CMILib.Items.CMIItemStack;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
|
||||
public class JobItems {
|
||||
|
||||
@ -39,6 +44,8 @@ public class JobItems {
|
||||
private int fromLevel = 0;
|
||||
private int untilLevel = Integer.MAX_VALUE;
|
||||
|
||||
private JobsItemType type = JobsItemType.Unknown;
|
||||
|
||||
public JobItems(String node) {
|
||||
this.node = node;
|
||||
}
|
||||
@ -48,7 +55,24 @@ public class JobItems {
|
||||
}
|
||||
|
||||
public CMIItemStack getItemStack(Player player, CMIAsyncHead ahead) {
|
||||
return CMIItemStack.deserialize(itemString.replace("[player]", player == null ? "" : player.getName()), ahead);
|
||||
CMIItemStack item = CMIItemStack.deserialize(itemString.replace("[player]", player == null ? "" : player.getName()), ahead);
|
||||
|
||||
if (item != null) {
|
||||
switch (this.getType()) {
|
||||
case Boosted:
|
||||
item.setItemStack(ItemBoostManager.applyNBT(item.getItemStack(), getNode()));
|
||||
break;
|
||||
case Shop:
|
||||
item.setItemStack(ShopManager.applyNBT(item.getItemStack(), getNode()));
|
||||
break;
|
||||
case Unknown:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public BoostMultiplier getBoost() {
|
||||
@ -91,7 +115,7 @@ public class JobItems {
|
||||
}
|
||||
|
||||
public CMIItemStack getItem() {
|
||||
return CMIItemStack.deserialize(itemString);
|
||||
return this.getItemStack(null, null);
|
||||
}
|
||||
|
||||
public void setItemString(String itemString) {
|
||||
@ -102,4 +126,13 @@ public class JobItems {
|
||||
this.boostMultiplier = boostMultiplier;
|
||||
}
|
||||
|
||||
public JobsItemType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public JobItems setType(JobsItemType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,11 +14,25 @@ import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
public final class JobsPayment1_9Listener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void PrepareAnvilEvent(final PrepareAnvilEvent event) {
|
||||
public void onShowItemEnchantEvent(final PrepareAnvilEvent event) {
|
||||
if (!Jobs.getGCManager().preventShopItemEnchanting)
|
||||
return;
|
||||
|
||||
if (!ItemBoostManager.containsItemBoostByNBT(event.getInventory().getContents()[0]))
|
||||
if (!Jobs.getShopManager().isShopItem(event.getInventory().getContents()[0]))
|
||||
return;
|
||||
|
||||
if (!CMIMaterial.get(event.getInventory().getContents()[1]).equals(CMIMaterial.ENCHANTED_BOOK))
|
||||
return;
|
||||
|
||||
event.setResult(null);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBoostedItemEnchantEvent(final PrepareAnvilEvent event) {
|
||||
if (!Jobs.getGCManager().preventBoostedItemEnchanting)
|
||||
return;
|
||||
|
||||
if (!ItemBoostManager.isBoostedJobsItem(event.getInventory().getContents()[0]))
|
||||
return;
|
||||
|
||||
if (!CMIMaterial.get(event.getInventory().getContents()[1]).equals(CMIMaterial.ENCHANTED_BOOK))
|
||||
|
@ -12,10 +12,12 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Zrips.CMILib.Colors.CMIChatColor;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
|
||||
|
||||
public final class GiveItem {
|
||||
|
||||
@Deprecated
|
||||
public static void giveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore,
|
||||
java.util.Map<Enchantment, Integer> enchants) {
|
||||
ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack();
|
||||
@ -57,6 +59,7 @@ public final class GiveItem {
|
||||
public static void giveItemForPlayer(Player player, ItemStack item) {
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
CMIScheduler.runAtEntity(player, () -> {
|
||||
player.getInventory().addItem(item);
|
||||
player.updateInventory();
|
||||
|
Loading…
Reference in New Issue
Block a user