mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2499
This commit is contained in:
parent
95f827727d
commit
210c8d20f4
@ -47,6 +47,7 @@
|
|||||||
* Fixed contributors not showing correctly
|
* Fixed contributors not showing correctly
|
||||||
* Fixed #2469
|
* Fixed #2469
|
||||||
* Fixed #2509
|
* Fixed #2509
|
||||||
|
* Fixed #2499
|
||||||
|
|
||||||
## Release Candidate 17 (17 Oct 2020)
|
## Release Candidate 17 (17 Oct 2020)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Optional;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Keyed;
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@ -58,6 +59,9 @@ public class BlockDataService implements PersistentDataService, Keyed {
|
|||||||
* The value to store
|
* The value to store
|
||||||
*/
|
*/
|
||||||
public void setBlockData(@Nonnull Block b, @Nonnull String value) {
|
public void setBlockData(@Nonnull Block b, @Nonnull String value) {
|
||||||
|
Validate.notNull(b, "The block cannot be null!");
|
||||||
|
Validate.notNull(value, "The value cannot be null!");
|
||||||
|
|
||||||
BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
|
BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
|
||||||
BlockState state = result.getState();
|
BlockState state = result.getState();
|
||||||
|
|
||||||
@ -78,6 +82,8 @@ public class BlockDataService implements PersistentDataService, Keyed {
|
|||||||
* @return The stored value
|
* @return The stored value
|
||||||
*/
|
*/
|
||||||
public Optional<String> getBlockData(@Nonnull Block b) {
|
public Optional<String> getBlockData(@Nonnull Block b) {
|
||||||
|
Validate.notNull(b, "The block cannot be null!");
|
||||||
|
|
||||||
BlockState state = PaperLib.getBlockState(b, false).getState();
|
BlockState state = PaperLib.getBlockState(b, false).getState();
|
||||||
|
|
||||||
if (state instanceof TileState) {
|
if (state instanceof TileState) {
|
||||||
@ -133,4 +139,4 @@ public class BlockDataService implements PersistentDataService, Keyed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.block.EnderChest;
|
import org.bukkit.block.EnderChest;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -21,12 +23,13 @@ class EnderTalisman extends Talisman {
|
|||||||
|
|
||||||
private static final LockedCategory ENDER_TALISMANS_CATEGORY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance(), "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier 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, "&7Talismans - &aTier II"), 3, Talisman.TALISMANS_CATEGORY.getKey());
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public EnderTalisman(Talisman parent, SlimefunItemStack item) {
|
public EnderTalisman(Talisman parent, SlimefunItemStack item) {
|
||||||
super(ENDER_TALISMANS_CATEGORY, item, 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.getMessageSuffix(), parent.getChance(), parent.getEffects());
|
super(ENDER_TALISMANS_CATEGORY, item, 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.getMessageSuffix(), parent.getChance(), parent.getEffects());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createEnderTalisman() {
|
void loadEnderTalisman() {
|
||||||
// Let's override that, otherwise we would be creating Ender Talismans
|
// Let's override that, otherwise we would be creating Ender Talismans
|
||||||
// for every Ender Talisman
|
// for every Ender Talisman
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -44,19 +48,23 @@ public class Talisman extends SlimefunItem {
|
|||||||
protected final PotionEffect[] effects;
|
protected final PotionEffect[] effects;
|
||||||
protected final int chance;
|
protected final int chance;
|
||||||
|
|
||||||
public Talisman(SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, PotionEffect... effects) {
|
@ParametersAreNonnullByDefault
|
||||||
|
public Talisman(SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, @Nullable String messageSuffix, PotionEffect... effects) {
|
||||||
this(item, recipe, consumable, cancelEvent, messageSuffix, 100, effects);
|
this(item, recipe, consumable, cancelEvent, messageSuffix, 100, effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Talisman(SlimefunItemStack item, ItemStack[] recipe, String messageSuffix, int chance, PotionEffect... effects) {
|
@ParametersAreNonnullByDefault
|
||||||
|
public Talisman(SlimefunItemStack item, ItemStack[] recipe, @Nullable String messageSuffix, int chance, PotionEffect... effects) {
|
||||||
this(item, recipe, true, true, messageSuffix, chance, effects);
|
this(item, recipe, true, true, messageSuffix, chance, effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Talisman(SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, int chance, PotionEffect... effects) {
|
@ParametersAreNonnullByDefault
|
||||||
|
public Talisman(SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, @Nullable String messageSuffix, int chance, PotionEffect... effects) {
|
||||||
this(TALISMANS_CATEGORY, item, recipe, consumable, cancelEvent, messageSuffix, chance, effects);
|
this(TALISMANS_CATEGORY, item, recipe, consumable, cancelEvent, messageSuffix, chance, effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Talisman(Category category, SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, int chance, PotionEffect... effects) {
|
@ParametersAreNonnullByDefault
|
||||||
|
protected Talisman(Category category, SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, @Nullable String messageSuffix, int chance, PotionEffect... effects) {
|
||||||
super(category, item, RecipeType.MAGIC_WORKBENCH, recipe, new CustomItem(item, consumable ? 4 : 1));
|
super(category, item, RecipeType.MAGIC_WORKBENCH, recipe, new CustomItem(item, consumable ? 4 : 1));
|
||||||
|
|
||||||
this.consumable = consumable;
|
this.consumable = consumable;
|
||||||
@ -81,14 +89,26 @@ public class Talisman extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns whether the {@link Talisman} will be consumed upon use.
|
||||||
|
*
|
||||||
|
* @return Whether this {@link Talisman} is consumed on use.
|
||||||
|
*/
|
||||||
public boolean isConsumable() {
|
public boolean isConsumable() {
|
||||||
return consumable;
|
return consumable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns the chance of this {@link Talisman} activating.
|
||||||
|
* The chance will be between 1 and 100.
|
||||||
|
*
|
||||||
|
* @return The chance of this {@link Talisman} activating.
|
||||||
|
*/
|
||||||
public int getChance() {
|
public int getChance() {
|
||||||
return chance;
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
public PotionEffect[] getEffects() {
|
public PotionEffect[] getEffects() {
|
||||||
return effects;
|
return effects;
|
||||||
}
|
}
|
||||||
@ -101,6 +121,7 @@ public class Talisman extends SlimefunItem {
|
|||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private SlimefunItemStack getEnderVariant() {
|
private SlimefunItemStack getEnderVariant() {
|
||||||
return enderTalisman;
|
return enderTalisman;
|
||||||
}
|
}
|
||||||
@ -114,10 +135,10 @@ public class Talisman extends SlimefunItem {
|
|||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
super.load();
|
super.load();
|
||||||
createEnderTalisman();
|
loadEnderTalisman();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createEnderTalisman() {
|
void loadEnderTalisman() {
|
||||||
EnderTalisman talisman = (EnderTalisman) SlimefunItem.getByItem(getEnderVariant());
|
EnderTalisman talisman = (EnderTalisman) SlimefunItem.getByItem(getEnderVariant());
|
||||||
Optional<Research> research = Research.getResearch(new NamespacedKey(SlimefunPlugin.instance(), "ender_talismans"));
|
Optional<Research> research = Research.getResearch(new NamespacedKey(SlimefunPlugin.instance(), "ender_talismans"));
|
||||||
|
|
||||||
@ -126,14 +147,16 @@ public class Talisman extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasMessage(Talisman talisman) {
|
private static boolean hasMessage(@Nonnull Talisman talisman) {
|
||||||
return talisman.getMessageSuffix() != null;
|
return talisman.getMessageSuffix() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public static boolean checkFor(Event e, SlimefunItemStack stack) {
|
public static boolean checkFor(Event e, SlimefunItemStack stack) {
|
||||||
return checkFor(e, stack.getItem());
|
return checkFor(e, stack.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public static boolean checkFor(Event e, SlimefunItem item) {
|
public static boolean checkFor(Event e, SlimefunItem item) {
|
||||||
if (!(item instanceof Talisman)) {
|
if (!(item instanceof Talisman)) {
|
||||||
return false;
|
return false;
|
||||||
@ -153,7 +176,7 @@ public class Talisman extends SlimefunItem {
|
|||||||
|
|
||||||
if (SlimefunUtils.containsSimilarItem(p.getInventory(), talismanItem, true)) {
|
if (SlimefunUtils.containsSimilarItem(p.getInventory(), talismanItem, true)) {
|
||||||
if (Slimefun.hasUnlocked(p, talisman, true)) {
|
if (Slimefun.hasUnlocked(p, talisman, true)) {
|
||||||
activateTalisman(e, p, p.getInventory(), talisman);
|
activateTalisman(e, p, p.getInventory(), talisman, talismanItem);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -163,7 +186,7 @@ public class Talisman extends SlimefunItem {
|
|||||||
|
|
||||||
if (SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalisman, true)) {
|
if (SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalisman, true)) {
|
||||||
if (Slimefun.hasUnlocked(p, talisman, true)) {
|
if (Slimefun.hasUnlocked(p, talisman, true)) {
|
||||||
activateTalisman(e, p, p.getEnderChest(), talisman);
|
activateTalisman(e, p, p.getEnderChest(), talisman, enderTalisman);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -174,38 +197,43 @@ public class Talisman extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void activateTalisman(Event e, Player p, Inventory inv, Talisman talisman) {
|
@ParametersAreNonnullByDefault
|
||||||
consumeItem(inv, talisman);
|
private static void activateTalisman(Event e, Player p, Inventory inv, Talisman talisman, ItemStack talismanItem) {
|
||||||
|
consumeItem(inv, talisman, talismanItem);
|
||||||
applyTalismanEffects(p, talisman);
|
applyTalismanEffects(p, talisman);
|
||||||
cancelEvent(e, talisman);
|
cancelEvent(e, talisman);
|
||||||
sendMessage(p, talisman);
|
sendMessage(p, talisman);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
private static void applyTalismanEffects(Player p, Talisman talisman) {
|
private static void applyTalismanEffects(Player p, Talisman talisman) {
|
||||||
for (PotionEffect effect : talisman.getEffects()) {
|
for (PotionEffect effect : talisman.getEffects()) {
|
||||||
p.addPotionEffect(effect);
|
p.addPotionEffect(effect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
private static void cancelEvent(Event e, Talisman talisman) {
|
private static void cancelEvent(Event e, Talisman talisman) {
|
||||||
if (e instanceof Cancellable && talisman.isEventCancelled()) {
|
if (e instanceof Cancellable && talisman.isEventCancelled()) {
|
||||||
((Cancellable) e).setCancelled(true);
|
((Cancellable) e).setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
private static void sendMessage(Player p, Talisman talisman) {
|
private static void sendMessage(Player p, Talisman talisman) {
|
||||||
if (hasMessage(talisman)) {
|
if (hasMessage(talisman)) {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.talisman." + talisman.getMessageSuffix(), true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.talisman." + talisman.getMessageSuffix(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void consumeItem(Inventory inv, Talisman talisman) {
|
@ParametersAreNonnullByDefault
|
||||||
|
private static void consumeItem(Inventory inv, Talisman talisman, ItemStack talismanItem) {
|
||||||
if (talisman.isConsumable()) {
|
if (talisman.isConsumable()) {
|
||||||
ItemStack[] contents = inv.getContents();
|
ItemStack[] contents = inv.getContents();
|
||||||
for (int i = 0; i < contents.length; i++) {
|
for (int i = 0; i < contents.length; i++) {
|
||||||
ItemStack item = contents[i];
|
ItemStack item = contents[i];
|
||||||
|
|
||||||
if (SlimefunUtils.isItemSimilar(item, talisman.getItem(), true, false)) {
|
if (SlimefunUtils.isItemSimilar(item, talismanItem, true, false)) {
|
||||||
ItemUtils.consumeItem(item, false);
|
ItemUtils.consumeItem(item, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user