Skip to content

Commit

Permalink
[O] 向后兼容扩展
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Apr 20, 2020
1 parent 851bc05 commit 344cd6d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 84 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- Our default version will be UNOFFICIAL, this will prevent the auto updater -->
<!-- from overriding our local test file -->
<version>4.3-NIGHTLY-200419</version>
<version>4.3-NIGHTLY-200420</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class EnderTalisman extends Talisman {

private static final LockedCategory ENDER_TALISMANS_CATEGORY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7护身符 - &a等级 II"), 3, Talisman.TALISMANS_CATEGORY.getKey());
private static final LockedCategory ENDER_TALISMANS_CATEGORY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7护身符 - &a等级 II"), 3, Talisman.TALISMANS_CATEGORY);

public EnderTalisman(Talisman parent) {
super(ENDER_TALISMANS_CATEGORY, parent.upgrade(), new ItemStack[]{SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3, null, parent.getItem(), null, SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3}, parent.isConsumable(), parent.isEventCancelled(), parent.getSuffix(), parent.getChance(), parent.getEffects());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ final class DefaultCategories {
protected final Category resources = Categories.RESOURCES;

// Locked Categories
protected final LockedCategory electricity = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "electricity"), new CustomItem(SlimefunItems.NUCLEAR_REACTOR, "&bEnergy and Electricity"), 4, basicMachines.getKey());
protected final Category cargo = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "cargo"), new CustomItem(SlimefunItems.CARGO_MANAGER, "&cCargo Management"), 4, basicMachines.getKey());
protected final LockedCategory gps = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "gps"), new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS-based Machines"), 4, basicMachines.getKey());
protected final LockedCategory electricity = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "electricity"), new CustomItem(SlimefunItems.NUCLEAR_REACTOR, "&bEnergy and Electricity"), 4, basicMachines);
protected final Category cargo = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "cargo"), new CustomItem(SlimefunItems.CARGO_MANAGER, "&cCargo Management"), 4, basicMachines);
protected final LockedCategory gps = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "gps"), new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS-based Machines"), 4, basicMachines);

// Seasonal Categories
protected final SeasonalCategory christmas = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "christmas"), Month.DECEMBER, 1, new CustomItem(SkullItem.fromHash("215ba31cde2671b8f176de6a9ffd008035f0590d63ee240be6e8921cd2037a45"), ChatUtils.christmas("Christmas") + " &7(December only)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ public boolean onInteract(Player p, MultiBlock mb, Block b) {
new ItemStack[]{SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE, SlimefunItems.COPPER_WIRE})
.register(plugin);

new SlimefunItem(categories.technicalComponents, SlimefunItems.COPPER_WIRE, RecipeType.ENHANCED_CRAFTING_TABLE,
new SlimefunItem(categories.technicalComponents, (SlimefunItemStack) SlimefunItems.COPPER_WIRE, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[]{null, null, null, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, SlimefunItems.COPPER_INGOT, null, null, null},
new CustomItem(SlimefunItems.COPPER_WIRE, 8))
.register(plugin);
Expand Down Expand Up @@ -2658,7 +2658,7 @@ public int getEnergyConsumption() {
new ItemStack[]{null, null, null, null, SlimefunItems.BUCKET_OF_OIL, null, null, null, null})
.register(plugin);

new RadioactiveItem(categories.resources, Radioactivity.MODERATE, SlimefunItems.NETHER_ICE, RecipeType.GEO_MINER,
new RadioactiveItem(categories.resources, Radioactivity.MODERATE, (SlimefunItemStack) SlimefunItems.NETHER_ICE, RecipeType.GEO_MINER,
new ItemStack[]{null, null, null, null, null, null, null, null, null})
.register(plugin);

Expand Down Expand Up @@ -3013,7 +3013,7 @@ public int getSpeed() {
new ItemStack[]{new ItemStack(Material.BLUE_ICE), null, null, null, null, null, null, null, null})
.register(plugin);

new SlimefunItem(categories.technicalComponents, SlimefunItems.NETHER_ICE_COOLANT_CELL, RecipeType.HEATED_PRESSURE_CHAMBER,
new SlimefunItem(categories.technicalComponents, (SlimefunItemStack) SlimefunItems.NETHER_ICE_COOLANT_CELL, RecipeType.HEATED_PRESSURE_CHAMBER,
new ItemStack[]{SlimefunItems.ENRICHED_NETHER_ICE, null, null, null, null, null, null, null, null})
.register(plugin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ private SlimefunItems() {}
public static final ItemStack REINFORCED_PLATE = new SlimefunItemStack("REINFORCED_PLATE", Material.PAPER, "&7钢筋板");
public static final SlimefunItemStack ANCIENT_PEDESTAL = new SlimefunItemStack("ANCIENT_PEDESTAL", Material.DISPENSER, "&d古代基座", "", "&5古代祭坛的一部分");
public static final SlimefunItemStack ANCIENT_ALTAR = new SlimefunItemStack("ANCIENT_ALTAR", Material.ENCHANTING_TABLE, "&d古代祭坛", "", "&5在世界里建造祭坛", "&5并用古老的仪式合成物品");
public static final SlimefunItemStack COPPER_WIRE = new SlimefunItemStack("COPPER_WIRE", Material.STRING, "&6铜线", "", "&6电子配件中的重要组成部分");
// 向下兼容
public static final ItemStack COPPER_WIRE = new SlimefunItemStack("COPPER_WIRE", Material.STRING, "&6铜线", "", "&6电子配件中的重要组成部分");

public static final SlimefunItemStack RAINBOW_WOOL = new SlimefunItemStack("RAINBOW_WOOL", Material.WHITE_WOOL, "&5彩虹羊毛", "", "&d轮番展现彩虹的颜色!");
public static final SlimefunItemStack RAINBOW_GLASS = new SlimefunItemStack("RAINBOW_GLASS", Material.WHITE_STAINED_GLASS, "&5彩虹玻璃", "", "&d轮番展现彩虹的颜色!");
Expand Down Expand Up @@ -688,9 +689,10 @@ private SlimefunItems() {}
public static final ItemStack ENERGY_REGULATOR = new SlimefunItemStack("ENERGY_REGULATOR", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19", "&6能源调节器", "", "&r能源网络的核心部分");
public static final SlimefunItemStack DEBUG_FISH = new SlimefunItemStack("DEBUG_FISH", Material.SALMON, "&3这鱼多少钱?", "", "&e右键 &r任意方块以查看它的方块数据", "&e左键 &r破坏方块", "&eShift + 左键 &r任意方块以清除它的方块数据", "&eShift + 右键 &r放置一个占位符方块");

public static final SlimefunItemStack NETHER_ICE = new SlimefunItemStack("NETHER_ICE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2NlMmRhZDliYWY3ZWFiYTdlODBkNGQwZjlmYWMwYWFiMDFhNzZiMTJmYjcxYzNkMmFmMmExNmZkZDRjNzM4MyJ9fX0=", "&e下界冰", "", "&e辐射等级: 中等", "&4&o需要防化套装");
public static final ItemStack NETHER_ICE = new SlimefunItemStack("NETHER_ICE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2NlMmRhZDliYWY3ZWFiYTdlODBkNGQwZjlmYWMwYWFiMDFhNzZiMTJmYjcxYzNkMmFmMmExNmZkZDRjNzM4MyJ9fX0=", "&e下界冰", "", "&e辐射等级: 中等", "&4&o需要防化套装");
public static final SlimefunItemStack ENRICHED_NETHER_ICE = new SlimefunItemStack("ENRICHED_NETHER_ICE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2M4MThhYTEzYWFiYzcyOTQ4MzhkMjFjYWFjMDU3ZTk3YmQ4Yzg5NjQxYTBjMGY4YTU1NDQyZmY0ZTI3In19fQ==", "&e浓缩下界冰", "", "&2辐射等级: 极高", "&4&o需要防化套装");
public static final SlimefunItemStack NETHER_ICE_COOLANT_CELL = new SlimefunItemStack("NETHER_ICE_COOLANT_CELL", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGQzY2Q0MTI1NTVmODk3MDE2MjEzZTVkNmM3NDMxYjQ0OGI5ZTU2NDRlMWIxOWVjNTFiNTMxNmYzNTg0MGUwIn19fQ==", "&6下界冰冷却剂");
// 向下兼容
public static final ItemStack NETHER_ICE_COOLANT_CELL = new SlimefunItemStack("NETHER_ICE_COOLANT_CELL", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGQzY2Q0MTI1NTVmODk3MDE2MjEzZTVkNmM3NDMxYjQ0OGI5ZTU2NDRlMWIxOWVjNTFiNTMxNmYzNTg0MGUwIn19fQ==", "&6下界冰冷却剂");

// Cargo
public static final ItemStack CARGO_MANAGER = new SlimefunItemStack("CARGO_MANAGER", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTUxMGJjODUzNjJhMTMwYTZmZjlkOTFmZjExZDZmYTQ2ZDdkMTkxMmEzNDMxZjc1MTU1OGVmM2M0ZDljMiJ9fX0=", "&6货运管理器", "", "&r物品传输网络的核心组件");
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
*/
public class Category implements Keyed {

protected final List<SlimefunItem> items = new ArrayList<>();
protected final NamespacedKey key;
protected final ItemStack item;
protected final List<SlimefunItem> items;
protected final int tier;

/**
Expand Down Expand Up @@ -71,6 +71,8 @@ public Category(NamespacedKey key, ItemStack item, int tier) {
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
this.item.setItemMeta(meta);

this.items = new ArrayList<>();
this.tier = tier;
}

Expand Down Expand Up @@ -98,20 +100,12 @@ public void add(SlimefunItem item) {
items.add(item);
}

/**
* Removes the given {@link SlimefunItem} from this {@link Category}.
*
* @param item the {@link SlimefunItem} that should be removed from this {@link Category}
*/
public void remove(SlimefunItem item) {
items.remove(item);
}

/**
* This method returns a localized display item of this {@link Category}
* for the specified {@link Player}.
*
* @param p The Player to create this {@link ItemStack} for
* @param p
* The Player to create this {@link ItemStack} for
* @return A localized display item for this {@link Category}
*/
public ItemStack getItem(Player p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import org.apache.commons.lang.Validate;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;

/**
* Represents a {@link Category} that cannot be opened until the parent category/categories
Expand All @@ -30,8 +25,7 @@
*/
public class LockedCategory extends Category {

private final NamespacedKey[] keys;
private final Set<Category> parents = new HashSet<>();
private final List<Category> parents;

/**
* The basic constructor for a LockedCategory.
Expand All @@ -41,7 +35,7 @@ public class LockedCategory extends Category {
* @param item The display item for this category
* @param parents The parent categories for this category
*/
public LockedCategory(NamespacedKey key, ItemStack item, NamespacedKey... parents) {
public LockedCategory(NamespacedKey key, ItemStack item, Category... parents) {
this(key, item, 3, parents);
}

Expand All @@ -58,43 +52,20 @@ public LockedCategory(NamespacedKey key, ItemStack item, NamespacedKey... parent
* The parent categories for this category
*
*/
public LockedCategory(NamespacedKey key, ItemStack item, int tier, NamespacedKey... parents) {
public LockedCategory(NamespacedKey key, ItemStack item, int tier, Category... parents) {
super(key, item, tier);
Validate.noNullElements(parents, "A LockedCategory must not have any 'null' parents!");
this.keys = parents;
}

@Override
public void register() {
super.register();

List<NamespacedKey> namespacedKeys = new ArrayList<>();

for (NamespacedKey key : keys) {
if (key != null) {
namespacedKeys.add(key);
}
}

for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
if (namespacedKeys.remove(category.getKey())) {
addParent(category);
}
}

for (NamespacedKey key : namespacedKeys) {
Slimefun.getLogger().log(Level.INFO, "Parent \"{0}\" for Category \"{1}\" was not found, probably just disabled.", new Object[]{key, getKey()});
}
this.parents = Arrays.asList(parents);
}

/**
* Gets the list of parent categories for this {@link LockedCategory}.
*
* @return the list of parent categories
*
* @see #addParent(Category)
* @see #removeParent(Category)
*/
public Set<Category> getParents() {
public List<Category> getParents() {
return parents;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoEnchanter;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
Expand All @@ -30,7 +29,6 @@
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -245,22 +243,14 @@ public final boolean isHidden() {
return hidden;
}

/**
* This method will forcefully hide this {@link SlimefunItem} from the {@link SlimefunGuide}.
*
* @param hidden
* Whether to hide this {@link SlimefunItem} or not
*/
public void setHidden(boolean hidden) {
if (this.hidden != hidden) {
this.hidden = hidden;

if (state == ItemState.ENABLED) {
if (hidden) {
category.remove(this);
} else {
category.add(this);
}
this.hidden = hidden;

if (state == ItemState.ENABLED) {
if (hidden) {
category.getItems().remove(this);
} else {
category.add(this);
}
}
}
Expand Down Expand Up @@ -345,7 +335,6 @@ public void register(SlimefunAddon addon) {
}

SlimefunPlugin.getRegistry().getAllSlimefunItems().add(this);
SlimefunPlugin.getRegistry().getSlimefunItemIds().put(id, this);

SlimefunPlugin.getItemCfg().setDefaultValue(id + ".enabled", true);
SlimefunPlugin.getItemCfg().setDefaultValue(id + ".can-be-used-in-workbenches", useableInWorkbench);
Expand Down Expand Up @@ -389,6 +378,7 @@ public void register(SlimefunAddon addon) {
disenchantable = SlimefunPlugin.getItemCfg().getBoolean(id + ".allow-disenchanting");

SlimefunPlugin.getRegistry().getEnabledSlimefunItems().add(this);
SlimefunPlugin.getRegistry().getSlimefunItemIds().put(id, this);
loadItemHandlers();
} else if (this instanceof VanillaItem) {
state = ItemState.VANILLA_FALLBACK;
Expand Down Expand Up @@ -458,7 +448,7 @@ public void setRecipeType(RecipeType type) {
public void setCategory(Category category) {
Validate.notNull(category, "'category' is not allowed to be null!");

this.category.remove(this);
this.category.getItems().remove(this);
category.add(this);

this.category = category;
Expand Down Expand Up @@ -500,7 +490,6 @@ public boolean isUseableInWorkbench() {
*/
public SlimefunItem setUseableInWorkbench(boolean useable) {
this.useableInWorkbench = useable;

return this;
}

Expand Down Expand Up @@ -758,7 +747,7 @@ public static ItemStack getItem(String id) {
}

public static SlimefunItem getByItem(ItemStack item) {
if (item == null || item.getType() == Material.AIR) return null;
if (item == null) return null;

if (item instanceof SlimefunItemStack) {
return getByID(((SlimefunItemStack) item).getItemID());
Expand All @@ -774,22 +763,21 @@ public static SlimefunItem getByItem(ItemStack item) {

// Quite expensive performance-wise
// But necessary for supporting legacy items
ItemStackWrapper wrapper = new ItemStackWrapper(item);

for (SlimefunItem sfi : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
if (sfi.isItem(wrapper)) {
if (sfi.isItem(item)) {
// If we have to loop all items for the given item, then at least
// set the id via PersistenDataAPI for future performance boosts
SlimefunPlugin.getItemDataService().setItemData(item, sfi.getID());

return sfi;
}
}

if (SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.BROKEN_SPAWNER, false)) {
if (SlimefunUtils.isItemSimilar(item, SlimefunItems.BROKEN_SPAWNER, false)) {
return getByID("BROKEN_SPAWNER");
}

if (SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.REPAIRED_SPAWNER, false)) {
if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REPAIRED_SPAWNER, false)) {
return getByID("REINFORCED_SPAWNER");
}

Expand Down

0 comments on commit 344cd6d

Please sign in to comment.