Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean execute(CommandSender commandSender, String[] args) {
return true;
}

RandomItem randomItem = new RandomItem(player.getInventory().getItemInMainHand(), chance, false);
RandomItem randomItem = new RandomItem(() -> player.getInventory().getItemInMainHand().clone(), chance, false);
RandomLootChestMain.getInstance().getItemsManager().getItems().put(id, randomItem);
RandomLootChestMain.getInstance().getItemsManager().save();
player.sendMessage(Language.ITEMS_ADDED_ITEM.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import java.util.concurrent.Callable;

public class MMOItemsHook {

Expand All @@ -18,9 +19,10 @@ public MMOItemsHook() {
Util.sendPluginMessage("&aHooked into MMOItems!");
}

public ItemStack getItemStack(@NotNull String type, @NotNull String itemId) {
public Callable<ItemStack> getItemStack(@NotNull String type, @NotNull String itemId) {
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(type), itemId);
return Optional.ofNullable(mmoItem).map(mmoItem1 -> mmoItem1.newBuilder().build()).orElse(null);
if (mmoItem == null)
return () -> null;
return () -> mmoItem.newBuilder().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import me.dreamdevs.randomlootchest.api.util.Util;
import org.bukkit.inventory.ItemStack;

import java.util.concurrent.Callable;

public class MythicMobsHook {

public static MythicMobsHook INSTANCE;
Expand All @@ -16,8 +18,8 @@ public MythicMobsHook() {
Util.sendPluginMessage("&aHooked into MythicMobs!");
}

public ItemStack getItemStack(String id) {
return mythicBukkit.getItemManager().getItemStack(id);
public Callable<ItemStack> getItemStack(String id) {
return () -> mythicBukkit.getItemManager().getItemStack(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.io.File;
import java.util.*;
import java.util.concurrent.Callable;

@Getter
public class ChestsManager {
Expand Down Expand Up @@ -135,7 +136,12 @@ public void load(RandomLootChestMain plugin) {
itemStack.setItemMeta(copiedMeta);
}

RandomItem randomItem = new RandomItem(itemStack, config.getDouble(CONTENTS + "." + content + ".Chance"), config.getBoolean(CONTENTS + "." + content + ".RandomAmount", false));
ItemStack finalItemStack = itemStack;
Callable<ItemStack> callable = () -> null;
if (finalItemStack != null) {
callable = finalItemStack::clone;
}
RandomItem randomItem = new RandomItem(callable, config.getDouble(CONTENTS + "." + content + ".Chance"), config.getBoolean(CONTENTS + "." + content + ".RandomAmount", false));

chestGame.getItemStacks().add(randomItem);
} catch (NullPointerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void load(RandomLootChestMain plugin) {
itemsSection.getInt(string+".Amount",1), itemsSection.getString(string+".DisplayName"),
itemsSection.getStringList(string+".DisplayLore"), enchantments,
itemsSection.getBoolean(string+".Unbreakable", false), itemsSection.getBoolean(string+".Glowing",false));
items.put(string, new RandomItem(itemStack, section.get().getDouble(string+".Chance"), section.get().getBoolean(string+".RandomAmount", false)));
items.put(string, new RandomItem(() -> itemStack.clone(), section.get().getDouble(string+".Chance"), section.get().getBoolean(string+".RandomAmount", false)));
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

@AllArgsConstructor
public class RandomItem implements IRandomItem {

private ItemStack itemStack;
private Callable<ItemStack> itemStack;
private double chance;
private boolean randomDropAmount;

public RandomItem(ItemStack itemStack, double chance) {
public RandomItem(Callable<ItemStack> itemStack, double chance) {
this.itemStack = itemStack;
this.chance = chance;
this.randomDropAmount = false;
}

@Override
public ItemStack getItemStack() {
return this.itemStack;
try {
return this.itemStack.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
Expand All @@ -40,11 +45,13 @@ public void setRandomDropAmount(boolean randomDropAmount) {
}

public String getDisplayName() {
var itemStack = getItemStack();
return (itemStack.hasItemMeta() && itemStack.getItemMeta() != null && itemStack.getItemMeta().hasDisplayName())
? itemStack.getItemMeta().getDisplayName() : itemStack.getType().name();
}

public List<String> getLore() {
var itemStack = getItemStack();
return (itemStack.hasItemMeta() && itemStack.getItemMeta() != null && itemStack.getItemMeta().hasLore())
? itemStack.getItemMeta().getLore() : new ArrayList<>();
}
Expand Down