mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 10:35:15 +01:00
1.13 preparations: Get rid of numeric item ids
This commit is contained in:
parent
0176ea1dc5
commit
6d4db1c8f6
@ -259,6 +259,7 @@ public class MaterialUtil {
|
||||
return Metadata.getFromCode(group);
|
||||
}
|
||||
|
||||
//1.13 TODO: Get rid of numeric data values with the API that replaces MaterialData
|
||||
public static class DataValue {
|
||||
/**
|
||||
* Gets the data value from a string
|
||||
|
@ -50,7 +50,7 @@ public class ItemInfo implements CommandExecutor {
|
||||
private static String getNameAndID(ItemStack item) {
|
||||
String itemName = MaterialUtil.getName(item);
|
||||
|
||||
return ChatColor.GRAY + itemName + ChatColor.WHITE + " " + item.getTypeId();
|
||||
return ChatColor.GRAY + itemName;
|
||||
}
|
||||
|
||||
private static String getDurability(ItemStack item) {
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.Acrobot.ChestShop.Listeners.Modules;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.Breeze.Utils.NumberUtil;
|
||||
import com.Acrobot.Breeze.Utils.PriceUtil;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -11,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_PRICE;
|
||||
import static com.Acrobot.ChestShop.Signs.ChestShopSign.ITEM_LINE;
|
||||
@ -31,12 +34,14 @@ public class PriceRestrictionModule implements Listener {
|
||||
configuration.options().header("In this file you can configure maximum and minimum prices for items (when creating a shop).");
|
||||
|
||||
if (!file.exists()) {
|
||||
configuration.addDefault("max.buy_price.itemID", 5.53);
|
||||
configuration.addDefault("max.buy_price.988", 3.51);
|
||||
configuration.addDefault("max.sell_price.978", 3.52);
|
||||
configuration.addDefault("uses_materials", true);
|
||||
|
||||
configuration.addDefault("max.buy_price.item_type", 5.53);
|
||||
configuration.addDefault("max.buy_price.piston_head", 3.51);
|
||||
configuration.addDefault("max.sell_price.placed_banner", 3.52);
|
||||
|
||||
configuration.addDefault("min.buy_price.979", 1.03);
|
||||
configuration.addDefault("min.sell_price.989", 0.51);
|
||||
configuration.addDefault("min.buy_price.piston_head", 1.03);
|
||||
configuration.addDefault("min.sell_price.placed_banner", 0.51);
|
||||
|
||||
try {
|
||||
configuration.options().copyDefaults(true);
|
||||
@ -44,9 +49,41 @@ public class PriceRestrictionModule implements Listener {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (!configuration.getBoolean("uses_materials")) {
|
||||
try {
|
||||
Material.getMaterial(1);
|
||||
ChestShop.getBukkitLogger().log(Level.INFO, "Converting numeric IDs in priceLimits.yml to Material names...");
|
||||
convertToMaterial("max.buy_price");
|
||||
convertToMaterial("max.sell_price");
|
||||
convertToMaterial("min.buy_price");
|
||||
convertToMaterial("min.sell_price");
|
||||
configuration.set("uses_materials", true);
|
||||
try {
|
||||
configuration.save(file);
|
||||
ChestShop.getBukkitLogger().log(Level.INFO, "Conversion finished!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (NoSuchMethodError e) {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Could not convert numeric IDs in priceLimits.yml to Material names!");
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "If you want to automatically convert them you have to run this version on a pre 1.13 server.");
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "If you want to manually convert it and hide this message set the uses_materials key to true.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void convertToMaterial(String sectionPath) {
|
||||
for (String typeId : configuration.getConfigurationSection(sectionPath).getKeys(false)) {
|
||||
if (NumberUtil.isInteger(typeId)) {
|
||||
Material material = Material.matchMaterial(typeId);
|
||||
if (material != null) {
|
||||
configuration.set(sectionPath + "." + material.toString().toLowerCase(), configuration.get(sectionPath + "." + typeId));
|
||||
configuration.set(sectionPath + "." + typeId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPreShopCreation(PreShopCreationEvent event) {
|
||||
ItemStack material = MaterialUtil.getItem(event.getSignLine(ITEM_LINE));
|
||||
@ -55,17 +92,17 @@ public class PriceRestrictionModule implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
int itemID = material.getTypeId();
|
||||
String itemType = material.getType().toString().toLowerCase();
|
||||
int amount = material.getAmount();
|
||||
|
||||
if (PriceUtil.hasBuyPrice(event.getSignLine(PRICE_LINE))) {
|
||||
double buyPrice = PriceUtil.getBuyPrice(event.getSignLine(PRICE_LINE));
|
||||
|
||||
if (isValid("min.buy_price." + itemID) && buyPrice < (configuration.getDouble("min.buy_price." + itemID) / amount)) {
|
||||
if (isValid("min.buy_price." + itemType) && buyPrice < (configuration.getDouble("min.buy_price." + itemType) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
|
||||
if (isValid("max.buy_price." + itemID) && buyPrice > (configuration.getDouble("max.buy_price." + itemID) / amount)) {
|
||||
if (isValid("max.buy_price." + itemType) && buyPrice > (configuration.getDouble("max.buy_price." + itemType) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
}
|
||||
@ -73,11 +110,11 @@ public class PriceRestrictionModule implements Listener {
|
||||
if (PriceUtil.hasSellPrice(event.getSignLine(PRICE_LINE))) {
|
||||
double sellPrice = PriceUtil.getSellPrice(event.getSignLine(PRICE_LINE));
|
||||
|
||||
if (isValid("min.sell_price." + itemID) && sellPrice < (configuration.getDouble("min.sell_price." + itemID) / amount)) {
|
||||
if (isValid("min.sell_price." + itemType) && sellPrice < (configuration.getDouble("min.sell_price." + itemType) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
|
||||
if (isValid("max.sell_price." + itemID) && sellPrice > (configuration.getDouble("max.sell_price." + itemID) / amount)) {
|
||||
if (isValid("max.sell_price." + itemType) && sellPrice > (configuration.getDouble("max.sell_price." + itemType) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,8 @@ public class ItemChecker implements Listener {
|
||||
}
|
||||
|
||||
if (!isSameItem(code + data, item)) {
|
||||
code = String.valueOf(item.getTypeId());
|
||||
event.setOutcome(INVALID_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
code = StringUtil.capitalizeFirstLetter(code);
|
||||
|
@ -33,7 +33,7 @@ public class PermissionChecker implements Listener {
|
||||
|
||||
ItemStack item = MaterialUtil.getItem(itemLine);
|
||||
|
||||
if (item == null || Permission.has(player, SHOP_CREATION_ID + Integer.toString(item.getTypeId()))) {
|
||||
if (item == null || Permission.has(player, SHOP_CREATION_ID + item.getType().toString().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class PermissionChecker implements Listener {
|
||||
TransactionEvent.TransactionType transactionType = event.getTransactionType();
|
||||
|
||||
for (ItemStack stock : event.getStock()) {
|
||||
String matID = Integer.toString(stock.getTypeId());
|
||||
String matID = stock.getType().toString().toLowerCase();
|
||||
|
||||
boolean hasPerm;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user