mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Some refactoring and small fixes
This commit is contained in:
parent
be001baa6e
commit
1c5f2f650b
@ -52,6 +52,8 @@
|
||||
* Fixed #2527
|
||||
* Fixed #2519
|
||||
* Fixed #2517
|
||||
* Fixed Magician Talisman sometimes drawing invalid enchantments
|
||||
* Fixed id conflicts for external Enchantment sources (e.g. plugins) for the Magician Talisman settings
|
||||
|
||||
## Release Candidate 17 (17 Oct 2020)
|
||||
|
||||
|
@ -16,6 +16,7 @@ import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator;
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||
@ -48,10 +49,14 @@ public class RainbowTickHandler extends BlockTicker {
|
||||
material = iterator.next();
|
||||
}
|
||||
|
||||
public RainbowTickHandler(Material... materials) {
|
||||
public RainbowTickHandler(@Nonnull Material... materials) {
|
||||
this(Arrays.asList(materials));
|
||||
}
|
||||
|
||||
public RainbowTickHandler(@Nonnull ColoredMaterial material) {
|
||||
this(material.asList());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks whether a given {@link Material} array contains any {@link Material}
|
||||
* that would result in a {@link GlassPane} {@link BlockData}.
|
||||
|
@ -167,7 +167,7 @@ public class LocalizationService extends SlimefunLocalization {
|
||||
return getDefaultLanguage();
|
||||
}
|
||||
|
||||
private void setLanguage(String language, boolean reset) {
|
||||
private void setLanguage(@Nonnull String language, boolean reset) {
|
||||
// Clearing out the old Language (if necessary)
|
||||
if (reset) {
|
||||
getConfig().clear();
|
||||
|
@ -31,14 +31,14 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
* This is an abstract parent class of {@link LocalizationService}.
|
||||
* There is not really much more I can say besides that...
|
||||
*
|
||||
* @author TheBusyBiscui
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see LocalizationService
|
||||
*
|
||||
*/
|
||||
public abstract class SlimefunLocalization extends Localization implements Keyed {
|
||||
|
||||
public SlimefunLocalization(@Nonnull SlimefunPlugin plugin) {
|
||||
protected SlimefunLocalization(@Nonnull SlimefunPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@ -71,6 +71,15 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
*/
|
||||
public abstract Language getDefaultLanguage();
|
||||
|
||||
/**
|
||||
* This returns whether a {@link Language} with the given id exists within
|
||||
* the project resources.
|
||||
*
|
||||
* @param id
|
||||
* The {@link Language} id
|
||||
*
|
||||
* @return Whether the project contains a {@link Language} with that id
|
||||
*/
|
||||
protected abstract boolean hasLanguage(@Nonnull String id);
|
||||
|
||||
/**
|
||||
@ -82,10 +91,23 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
@Nonnull
|
||||
public abstract Collection<Language> getLanguages();
|
||||
|
||||
/**
|
||||
* This method adds a new {@link Language} with the given id and texture.
|
||||
*
|
||||
* @param id
|
||||
* The {@link Language} id
|
||||
* @param texture
|
||||
* The texture of how this {@link Language} should be displayed
|
||||
*/
|
||||
protected abstract void addLanguage(@Nonnull String id, @Nonnull String texture);
|
||||
|
||||
/**
|
||||
* This will load every {@link SupportedLanguage} into memory.
|
||||
* To be precise: It performs {@link #addLanguage(String, String)} for every
|
||||
* value of {@link SupportedLanguage}.
|
||||
*/
|
||||
protected void loadEmbeddedLanguages() {
|
||||
for (SupportedLanguage lang : SupportedLanguage.valuesCache) {
|
||||
for (SupportedLanguage lang : SupportedLanguage.values()) {
|
||||
if (lang.isReadyForRelease() || SlimefunPlugin.getUpdater().getBranch() != SlimefunBranch.STABLE) {
|
||||
addLanguage(lang.getLanguageId(), lang.getTexture());
|
||||
}
|
||||
|
@ -58,8 +58,6 @@ enum SupportedLanguage {
|
||||
MACEDONIAN("mk", false, "a0e0b0b5d87a855466980a101a757bcdb5f77d9f7287889f3efa998ee0472fc0"),
|
||||
TAGALOG("tl", true, "9306c0c1ce6a9c61bb42a572c49e6d0ed20e0e6b3d122cc64c339cbf78e9e937");
|
||||
|
||||
public static final SupportedLanguage[] valuesCache = values();
|
||||
|
||||
private final String id;
|
||||
private final boolean releaseReady;
|
||||
private final String textureHash;
|
||||
@ -71,11 +69,22 @@ enum SupportedLanguage {
|
||||
this.textureHash = textureHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the id of this {@link Language}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nonnull
|
||||
public String getLanguageId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns whether this {@link SupportedLanguage} is "release-ready".
|
||||
* A release-ready {@link Language} will be available in RC builds of Slimefun.
|
||||
*
|
||||
* @return Whether this {@link Language} is "release-ready"
|
||||
*/
|
||||
public boolean isReadyForRelease() {
|
||||
return releaseReady;
|
||||
}
|
||||
|
@ -31,6 +31,9 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
*/
|
||||
public class RadioactiveItem extends SlimefunItem implements Radioactive, NotPlaceable {
|
||||
|
||||
/**
|
||||
* This is the level of {@link Radioactivity} for this {@link SlimefunItem}
|
||||
*/
|
||||
private final Radioactivity radioactivity;
|
||||
|
||||
/**
|
||||
|
@ -807,12 +807,8 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
|
||||
}
|
||||
|
||||
private void constructMenu(@Nonnull BlockMenuPreset preset) {
|
||||
for (int i : BORDER) {
|
||||
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
for (int i : OUTPUT_BORDER) {
|
||||
preset.addItem(i, ChestMenuUtils.getOutputSlotTexture(), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
preset.drawBackground(BORDER);
|
||||
preset.drawBackground(ChestMenuUtils.getOutputSlotTexture(), OUTPUT_BORDER);
|
||||
|
||||
for (int i : getOutputSlots()) {
|
||||
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {
|
||||
@ -841,7 +837,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
|
||||
}
|
||||
|
||||
protected void move(Block b, BlockFace face, Block block) {
|
||||
if (block.getY() > 0 && block.getY() < block.getWorld().getMaxHeight() && (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR)) {
|
||||
if (block.getY() > 0 && block.getY() < block.getWorld().getMaxHeight() && block.isEmpty()) {
|
||||
BlockData blockData = Material.PLAYER_HEAD.createBlockData(data -> {
|
||||
if (data instanceof Rotatable) {
|
||||
Rotatable rotatable = ((Rotatable) data);
|
||||
|
@ -11,7 +11,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterials;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
@ -100,7 +100,7 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
||||
menu.replaceExistingItem(slotCurrent, new CustomItem(HeadTexture.CHEST_TERMINAL.getAsItemStack(), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(slotCurrent, ChestMenuUtils.getEmptyClickHandler());
|
||||
} else {
|
||||
menu.replaceExistingItem(slotCurrent, new CustomItem(ColoredMaterials.WOOL.get(channel), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.replaceExistingItem(slotCurrent, new CustomItem(ColoredMaterial.WOOL.get(channel), "&bChannel ID: &3" + (channel + 1)));
|
||||
menu.addMenuClickHandler(slotCurrent, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -107,22 +109,12 @@ public class ReactorAccessPort extends SlimefunItem {
|
||||
});
|
||||
}
|
||||
|
||||
private void constructMenu(BlockMenuPreset preset) {
|
||||
for (int i : background) {
|
||||
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
private void constructMenu(@Nonnull BlockMenuPreset preset) {
|
||||
preset.drawBackground(ChestMenuUtils.getBackground(), background);
|
||||
|
||||
for (int i : fuelBorder) {
|
||||
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
for (int i : inputBorder) {
|
||||
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
for (int i : outputBorder) {
|
||||
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
preset.drawBackground(new CustomItem(Material.LIME_STAINED_GLASS_PANE, " "), fuelBorder);
|
||||
preset.drawBackground(new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), inputBorder);
|
||||
preset.drawBackground(new CustomItem(Material.GREEN_STAINED_GLASS_PANE, " "), outputBorder);
|
||||
|
||||
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), ChestMenuUtils.getEmptyClickHandler());
|
||||
preset.addItem(22, new CustomItem(SlimefunItems.PLUTONIUM, "&7Byproduct Slot", "", "&rThis Slot contains the Reactor's Byproduct", "&rsuch as &aNeptunium &ror &7Plutonium"), ChestMenuUtils.getEmptyClickHandler());
|
||||
|
@ -66,17 +66,9 @@ public abstract class AbstractEntityAssembler<T extends Entity> extends SimpleSl
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
for (int i : border) {
|
||||
addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
for (int i : headBorder) {
|
||||
addItem(i, new CustomItem(getHeadBorder(), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
for (int i : bodyBorder) {
|
||||
addItem(i, new CustomItem(getBodyBorder(), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
drawBackground(border);
|
||||
drawBackground(new CustomItem(getHeadBorder(), " "), headBorder);
|
||||
drawBackground(new CustomItem(getBodyBorder(), " "), bodyBorder);
|
||||
|
||||
constructMenu(this);
|
||||
}
|
||||
|
@ -7,8 +7,13 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
@ -16,10 +21,18 @@ import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchan
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
* The {@link MagicianTalisman} is a special kind of {@link Talisman} which awards a {@link Player}
|
||||
* with an extra {@link Enchantment} when they enchant their {@link ItemStack}.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public class MagicianTalisman extends Talisman {
|
||||
|
||||
private final Set<TalismanEnchantment> enchantments = new HashSet<>();
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public MagicianTalisman(SlimefunItemStack item, ItemStack[] recipe) {
|
||||
super(item, recipe, false, false, "magician", 80);
|
||||
|
||||
@ -47,13 +60,31 @@ public class MagicianTalisman extends Talisman {
|
||||
*
|
||||
* @return An applicable {@link TalismanEnchantment} or null
|
||||
*/
|
||||
public TalismanEnchantment getRandomEnchantment(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
return null;
|
||||
}
|
||||
@Nullable
|
||||
public TalismanEnchantment getRandomEnchantment(@Nonnull ItemStack item, @Nonnull Set<Enchantment> existingEnchantments) {
|
||||
Validate.notNull(item, "The ItemStack cannot be null");
|
||||
Validate.notNull(existingEnchantments, "The Enchantments Set cannot be null");
|
||||
|
||||
// @formatter:off
|
||||
List<TalismanEnchantment> enabled = enchantments.stream()
|
||||
.filter(e -> e.getEnchantment().canEnchantItem(item))
|
||||
.filter(e -> hasConflicts(existingEnchantments, e))
|
||||
.filter(TalismanEnchantment::getValue)
|
||||
.collect(Collectors.toList());
|
||||
// @formatter:on
|
||||
|
||||
List<TalismanEnchantment> enabled = enchantments.stream().filter(e -> e.getEnchantment().canEnchantItem(item)).filter(TalismanEnchantment::getValue).collect(Collectors.toList());
|
||||
return enabled.isEmpty() ? null : enabled.get(ThreadLocalRandom.current().nextInt(enabled.size()));
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private boolean hasConflicts(Set<Enchantment> enchantments, TalismanEnchantment ench) {
|
||||
for (Enchantment existing : enchantments) {
|
||||
if (existing.conflictsWith(ench.getEnchantment())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -231,26 +231,28 @@ public class TalismanListener implements Listener {
|
||||
@EventHandler
|
||||
public void onEnchant(EnchantItemEvent e) {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
Map<Enchantment, Integer> enchantments = e.getEnchantsToAdd();
|
||||
|
||||
// Magician Talisman
|
||||
if (Talisman.checkFor(e, SlimefunItems.TALISMAN_MAGICIAN)) {
|
||||
MagicianTalisman talisman = (MagicianTalisman) SlimefunItems.TALISMAN_MAGICIAN.getItem();
|
||||
TalismanEnchantment enchantment = talisman.getRandomEnchantment(e.getItem());
|
||||
TalismanEnchantment enchantment = talisman.getRandomEnchantment(e.getItem(), enchantments.keySet());
|
||||
|
||||
if (enchantment != null) {
|
||||
e.getEnchantsToAdd().put(enchantment.getEnchantment(), enchantment.getLevel());
|
||||
enchantments.put(enchantment.getEnchantment(), enchantment.getLevel());
|
||||
}
|
||||
}
|
||||
|
||||
if (!e.getEnchantsToAdd().containsKey(Enchantment.SILK_TOUCH) && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_WIZARD)) {
|
||||
Set<Enchantment> enchantments = e.getEnchantsToAdd().keySet();
|
||||
// Wizard Talisman
|
||||
if (!enchantments.containsKey(Enchantment.SILK_TOUCH) && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_WIZARD)) {
|
||||
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
for (Enchantment enchantment : enchantments.keySet()) {
|
||||
if (random.nextInt(100) < 40) {
|
||||
e.getEnchantsToAdd().put(enchantment, random.nextInt(3) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
e.getEnchantsToAdd().put(Enchantment.LOOT_BONUS_BLOCKS, random.nextInt(3) + 3);
|
||||
enchantments.put(Enchantment.LOOT_BONUS_BLOCKS, random.nextInt(3) + 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.block.BrewingStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -21,7 +21,7 @@ public class TalismanEnchantment extends ItemSetting<Boolean> {
|
||||
private final int level;
|
||||
|
||||
public TalismanEnchantment(@Nonnull Enchantment enchantment, int level) {
|
||||
super("allow-enchantments." + enchantment.getKey().getKey() + ".level." + level, true);
|
||||
super("allow-enchantments." + enchantment.getKey().getNamespace() + '.' + enchantment.getKey().getKey() + ".level." + level, true);
|
||||
|
||||
this.enchantment = enchantment;
|
||||
this.level = level;
|
||||
|
@ -192,7 +192,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.IcyBow;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SwordOfBeheading;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterials;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
@ -2294,32 +2294,32 @@ public final class SlimefunItemSetup {
|
||||
|
||||
new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_WOOL, RecipeType.ANCIENT_ALTAR,
|
||||
new ItemStack[] {new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL)},
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_WOOL, 8), new RainbowTickHandler(ColoredMaterials.WOOL))
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_WOOL, 8), new RainbowTickHandler(ColoredMaterial.WOOL))
|
||||
.register(plugin);
|
||||
|
||||
new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLASS, RecipeType.ANCIENT_ALTAR,
|
||||
new ItemStack[] {new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS)},
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS, 8), new RainbowTickHandler(ColoredMaterials.STAINED_GLASS))
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS, 8), new RainbowTickHandler(ColoredMaterial.STAINED_GLASS))
|
||||
.register(plugin);
|
||||
|
||||
new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLASS_PANE, RecipeType.ANCIENT_ALTAR,
|
||||
new ItemStack[] {new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE)},
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS_PANE, 8), new RainbowTickHandler(ColoredMaterials.STAINED_GLASS_PANE))
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS_PANE, 8), new RainbowTickHandler(ColoredMaterial.STAINED_GLASS_PANE))
|
||||
.register(plugin);
|
||||
|
||||
new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_CLAY, RecipeType.ANCIENT_ALTAR,
|
||||
new ItemStack[] {new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA)},
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_CLAY, 8), new RainbowTickHandler(ColoredMaterials.TERRACOTTA))
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_CLAY, 8), new RainbowTickHandler(ColoredMaterial.TERRACOTTA))
|
||||
.register(plugin);
|
||||
|
||||
new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_CONCRETE, RecipeType.ANCIENT_ALTAR,
|
||||
new ItemStack[] {new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE)},
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_CONCRETE, 8), new RainbowTickHandler(ColoredMaterials.CONCRETE))
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_CONCRETE, 8), new RainbowTickHandler(ColoredMaterial.CONCRETE))
|
||||
.register(plugin);
|
||||
|
||||
new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, RecipeType.ANCIENT_ALTAR,
|
||||
new ItemStack[] {new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA)},
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, 8), new RainbowTickHandler(ColoredMaterials.GLAZED_TERRACOTTA))
|
||||
new SlimefunItemStack(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, 8), new RainbowTickHandler(ColoredMaterial.GLAZED_TERRACOTTA))
|
||||
.register(plugin);
|
||||
|
||||
// Christmas
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
@ -20,20 +21,14 @@ import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
|
||||
* @see SlimefunTag
|
||||
*
|
||||
*/
|
||||
public final class ColoredMaterials {
|
||||
|
||||
/**
|
||||
* We don't want any instances of this class, so we set the
|
||||
* constructor to be private.
|
||||
*/
|
||||
private ColoredMaterials() {}
|
||||
public enum ColoredMaterial {
|
||||
|
||||
// @formatter:off (We want this to stay formatted like this)
|
||||
|
||||
/**
|
||||
* This {@link List} contains all wool colors ordered by their appearance ingame.
|
||||
*/
|
||||
public static final List<Material> WOOL = asList(new Material[] {
|
||||
WOOL(new Material[] {
|
||||
Material.WHITE_WOOL,
|
||||
Material.ORANGE_WOOL,
|
||||
Material.MAGENTA_WOOL,
|
||||
@ -50,12 +45,12 @@ public final class ColoredMaterials {
|
||||
Material.GREEN_WOOL,
|
||||
Material.RED_WOOL,
|
||||
Material.BLACK_WOOL
|
||||
});
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link List} contains all stained glass colors ordered by their appearance ingame.
|
||||
*/
|
||||
public static final List<Material> STAINED_GLASS = asList(new Material[] {
|
||||
STAINED_GLASS(new Material[] {
|
||||
Material.WHITE_STAINED_GLASS,
|
||||
Material.ORANGE_STAINED_GLASS,
|
||||
Material.MAGENTA_STAINED_GLASS,
|
||||
@ -72,12 +67,12 @@ public final class ColoredMaterials {
|
||||
Material.GREEN_STAINED_GLASS,
|
||||
Material.RED_STAINED_GLASS,
|
||||
Material.BLACK_STAINED_GLASS
|
||||
});
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link List} contains all stained glass pane colors ordered by their appearance ingame.
|
||||
*/
|
||||
public static final List<Material> STAINED_GLASS_PANE = asList(new Material[] {
|
||||
STAINED_GLASS_PANE(new Material[] {
|
||||
Material.WHITE_STAINED_GLASS_PANE,
|
||||
Material.ORANGE_STAINED_GLASS_PANE,
|
||||
Material.MAGENTA_STAINED_GLASS_PANE,
|
||||
@ -94,12 +89,12 @@ public final class ColoredMaterials {
|
||||
Material.GREEN_STAINED_GLASS_PANE,
|
||||
Material.RED_STAINED_GLASS_PANE,
|
||||
Material.BLACK_STAINED_GLASS_PANE
|
||||
});
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link List} contains all terracotta colors ordered by their appearance ingame.
|
||||
*/
|
||||
public static final List<Material> TERRACOTTA = asList(new Material[] {
|
||||
TERRACOTTA(new Material[] {
|
||||
Material.WHITE_TERRACOTTA,
|
||||
Material.ORANGE_TERRACOTTA,
|
||||
Material.MAGENTA_TERRACOTTA,
|
||||
@ -116,12 +111,12 @@ public final class ColoredMaterials {
|
||||
Material.GREEN_TERRACOTTA,
|
||||
Material.RED_TERRACOTTA,
|
||||
Material.BLACK_TERRACOTTA
|
||||
});
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link List} contains all glazed terracotta colors ordered by their appearance ingame.
|
||||
*/
|
||||
public static final List<Material> GLAZED_TERRACOTTA = asList(new Material[] {
|
||||
GLAZED_TERRACOTTA(new Material[] {
|
||||
Material.WHITE_GLAZED_TERRACOTTA,
|
||||
Material.ORANGE_GLAZED_TERRACOTTA,
|
||||
Material.MAGENTA_GLAZED_TERRACOTTA,
|
||||
@ -138,12 +133,12 @@ public final class ColoredMaterials {
|
||||
Material.GREEN_GLAZED_TERRACOTTA,
|
||||
Material.RED_GLAZED_TERRACOTTA,
|
||||
Material.BLACK_GLAZED_TERRACOTTA
|
||||
});
|
||||
}),
|
||||
|
||||
/**
|
||||
* This {@link List} contains all concrete colors ordered by their appearance ingame.
|
||||
*/
|
||||
public static final List<Material> CONCRETE = asList(new Material[] {
|
||||
CONCRETE(new Material[] {
|
||||
Material.WHITE_CONCRETE,
|
||||
Material.ORANGE_CONCRETE,
|
||||
Material.MAGENTA_CONCRETE,
|
||||
@ -164,12 +159,38 @@ public final class ColoredMaterials {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
@Nonnull
|
||||
private static List<Material> asList(@Nonnull Material[] materials) {
|
||||
private final List<Material> list;
|
||||
|
||||
/**
|
||||
* This creates a new constant of {@link ColoredMaterial}.
|
||||
* The array must have a length of 16 and cannot contain null elements!
|
||||
*
|
||||
* @param materials
|
||||
* The {@link Material Materials} for this {@link ColoredMaterial}.
|
||||
*/
|
||||
ColoredMaterial(@Nonnull Material[] materials) {
|
||||
Validate.noNullElements(materials, "The List cannot contain any null elements");
|
||||
Validate.isTrue(materials.length == 16, "Expected 16, received: " + materials.length + ". Did you miss a color?");
|
||||
|
||||
return Collections.unmodifiableList(Arrays.asList(materials));
|
||||
list = Collections.unmodifiableList(Arrays.asList(materials));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<Material> asList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Material get(int index) {
|
||||
Validate.isTrue(index >= 0 && index < 16, "The index must be between 0 and 15 (inclusive).");
|
||||
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
public Material get(@Nonnull DyeColor color) {
|
||||
Validate.notNull(color, "Color cannot be null!");
|
||||
|
||||
return get(color.ordinal());
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,7 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
* @deprecated This interface is not designed to be used by addons.
|
||||
*
|
||||
*/
|
||||
// @Deprecated - commented out because we are not ready to send out warnings yet
|
||||
@Deprecated
|
||||
public interface InventoryBlock {
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
@ -122,6 +123,33 @@ public abstract class BlockMenuPreset extends ChestMenu {
|
||||
throw new UnsupportedOperationException("BlockMenuPreset does not support this method.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will draw unclickable background items into this {@link BlockMenuPreset}.
|
||||
*
|
||||
* @param item
|
||||
* The {@link ItemStack} that should be used as background
|
||||
* @param slots
|
||||
* The slots which should be treated as background
|
||||
*/
|
||||
public void drawBackground(@Nonnull ItemStack item, @Nonnull int[] slots) {
|
||||
Validate.notNull(item, "The background item cannot be null!");
|
||||
checkIfLocked();
|
||||
|
||||
for (int slot : slots) {
|
||||
addItem(slot, item, ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will draw unclickable background items into this {@link BlockMenuPreset}.
|
||||
*
|
||||
* @param slots
|
||||
* The slots which should be treated as background
|
||||
*/
|
||||
public void drawBackground(@Nonnull int[] slots) {
|
||||
drawBackground(ChestMenuUtils.getBackground(), slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChestMenu addItem(int slot, @Nullable ItemStack item) {
|
||||
checkIfLocked();
|
||||
|
Loading…
Reference in New Issue
Block a user