mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-09-30 23:47:32 +02:00
Lootables
This commit is contained in:
parent
1aae07c08d
commit
b03c7c60f8
6
pom.xml
6
pom.xml
@ -33,6 +33,7 @@
|
|||||||
<artifactSet>
|
<artifactSet>
|
||||||
<includes>
|
<includes>
|
||||||
<include>com.songoda:songodaupdater</include>
|
<include>com.songoda:songodaupdater</include>
|
||||||
|
<include>com.songoda:Lootables</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<filters>
|
<filters>
|
||||||
@ -73,6 +74,11 @@
|
|||||||
<artifactId>songodaupdater</artifactId>
|
<artifactId>songodaupdater</artifactId>
|
||||||
<version>1</version>
|
<version>1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.songoda</groupId>
|
||||||
|
<artifactId>Lootables</artifactId>
|
||||||
|
<version>1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.milkbowl</groupId>
|
<groupId>net.milkbowl</groupId>
|
||||||
<artifactId>vault</artifactId>
|
<artifactId>vault</artifactId>
|
||||||
|
@ -8,7 +8,7 @@ import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays;
|
|||||||
import com.songoda.ultimatestacker.hook.StackerHook;
|
import com.songoda.ultimatestacker.hook.StackerHook;
|
||||||
import com.songoda.ultimatestacker.hook.hooks.JobsHook;
|
import com.songoda.ultimatestacker.hook.hooks.JobsHook;
|
||||||
import com.songoda.ultimatestacker.listeners.*;
|
import com.songoda.ultimatestacker.listeners.*;
|
||||||
import com.songoda.ultimatestacker.lootables.LootManager;
|
import com.songoda.ultimatestacker.lootables.LootablesManager;
|
||||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||||
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
||||||
import com.songoda.ultimatestacker.storage.Storage;
|
import com.songoda.ultimatestacker.storage.Storage;
|
||||||
@ -51,7 +51,7 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
private SettingsManager settingsManager;
|
private SettingsManager settingsManager;
|
||||||
private EntityStackManager entityStackManager;
|
private EntityStackManager entityStackManager;
|
||||||
private SpawnerStackManager spawnerStackManager;
|
private SpawnerStackManager spawnerStackManager;
|
||||||
private LootManager lootManager;
|
private LootablesManager lootablesManager;
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
private StackingTask stackingTask;
|
private StackingTask stackingTask;
|
||||||
private Hologram hologram;
|
private Hologram hologram;
|
||||||
@ -92,10 +92,10 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
|
|
||||||
this.commandManager = new CommandManager(this);
|
this.commandManager = new CommandManager(this);
|
||||||
|
|
||||||
this.lootManager = new LootManager();
|
this.lootablesManager = new LootablesManager();
|
||||||
|
this.lootablesManager.createDefaultLootables();
|
||||||
|
this.getLootablesManager().getLootManager().loadLootables();
|
||||||
|
|
||||||
lootManager.createDefaultLootables();
|
|
||||||
lootManager.loadLootables();
|
|
||||||
|
|
||||||
for (EntityType value : EntityType.values()) {
|
for (EntityType value : EntityType.values()) {
|
||||||
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
|
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
|
||||||
@ -224,7 +224,7 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
this.itemFile = new ConfigWrapper(this, "", "items.yml");
|
this.itemFile = new ConfigWrapper(this, "", "items.yml");
|
||||||
this.spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
|
this.spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
|
||||||
this.settingsManager.reloadConfig();
|
this.settingsManager.reloadConfig();
|
||||||
this.getLootManager().loadLootables();
|
this.getLootablesManager().getLootManager().loadLootables();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean spawnersEnabled() {
|
public boolean spawnersEnabled() {
|
||||||
@ -259,8 +259,8 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LootManager getLootManager() {
|
public LootablesManager getLootablesManager() {
|
||||||
return lootManager;
|
return lootablesManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityStackManager getEntityStackManager() {
|
public EntityStackManager getEntityStackManager() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.songoda.ultimatestacker.entity;
|
package com.songoda.ultimatestacker.entity;
|
||||||
|
|
||||||
|
import com.songoda.lootables.loot.Drop;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.lootables.Drop;
|
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||||
@ -119,7 +119,7 @@ public class EntityStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (custom)
|
if (custom)
|
||||||
drops = UltimateStacker.getInstance().getLootManager().getDrops(killed);
|
drops = UltimateStacker.getInstance().getLootablesManager().getDrops(killed);
|
||||||
for (Drop drop : drops) {
|
for (Drop drop : drops) {
|
||||||
Methods.processDrop(killed, drop);
|
Methods.processDrop(killed, drop);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.songoda.ultimatestacker.listeners;
|
package com.songoda.ultimatestacker.listeners;
|
||||||
|
|
||||||
|
import com.songoda.lootables.loot.Drop;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.lootables.Drop;
|
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -23,11 +23,10 @@ public class DeathListeners implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
List<Drop> drops = Setting.CUSTOM_DROPS.getBoolean()
|
List<Drop> drops = instance.getLootablesManager().getDrops(event.getEntity());
|
||||||
? instance.getLootManager().getDrops(event.getEntity()) : new ArrayList<>();
|
|
||||||
|
|
||||||
boolean custom = false;
|
boolean custom = false;
|
||||||
if (drops.size() != 0) {
|
if (Setting.CUSTOM_DROPS.getBoolean()) {
|
||||||
event.getDrops().clear();
|
event.getDrops().clear();
|
||||||
|
|
||||||
for (Drop drop : drops) {
|
for (Drop drop : drops) {
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.songoda.ultimatestacker.lootables;
|
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class Drop {
|
|
||||||
|
|
||||||
private ItemStack itemStack;
|
|
||||||
|
|
||||||
private String command;
|
|
||||||
|
|
||||||
public Drop(ItemStack itemStack) {
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Drop(String command) {
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommand() {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommand(String command) {
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItemStack(ItemStack itemStack) {
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,225 +0,0 @@
|
|||||||
package com.songoda.ultimatestacker.lootables;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Loot {
|
|
||||||
|
|
||||||
// Material used for this drop.
|
|
||||||
@SerializedName("Command")
|
|
||||||
private String command;
|
|
||||||
|
|
||||||
// Material used for this drop.
|
|
||||||
@SerializedName("Type")
|
|
||||||
private Material material;
|
|
||||||
|
|
||||||
// Data value for old crappy versions of Minecraft.
|
|
||||||
@SerializedName("Data")
|
|
||||||
private Short data;
|
|
||||||
|
|
||||||
// The override for the item name.
|
|
||||||
@SerializedName("Name")
|
|
||||||
private String name = null;
|
|
||||||
|
|
||||||
// The override for the item lore.
|
|
||||||
@SerializedName("Lore")
|
|
||||||
private List<String> lore = null;
|
|
||||||
|
|
||||||
// The override for the item enchantments.
|
|
||||||
@SerializedName("Enchantments")
|
|
||||||
private Map<String, Integer> enchants = null;
|
|
||||||
|
|
||||||
// Material used if entity died on fire.
|
|
||||||
@SerializedName("Burned Type")
|
|
||||||
private Material burnedMaterial = null;
|
|
||||||
|
|
||||||
// Chance that this drop will take place.
|
|
||||||
@SerializedName("Chance")
|
|
||||||
private double chance = 100;
|
|
||||||
|
|
||||||
// Minimum amount of this item.
|
|
||||||
@SerializedName("Min")
|
|
||||||
private int min = 1;
|
|
||||||
|
|
||||||
// Maximum amount of this item.
|
|
||||||
@SerializedName("Max")
|
|
||||||
private int max = 1;
|
|
||||||
|
|
||||||
// Will the looting enchantment be usable for this loot?
|
|
||||||
@SerializedName("Looting")
|
|
||||||
private boolean allowLootingEnchant = true;
|
|
||||||
|
|
||||||
// The looting chance increase.
|
|
||||||
@SerializedName("Looting Chance Increase")
|
|
||||||
private Double lootingIncrease;
|
|
||||||
|
|
||||||
// Should this drop only be applicable for specific entities?
|
|
||||||
@SerializedName("Only Drop For")
|
|
||||||
private List<EntityType> onlyDropFor;
|
|
||||||
|
|
||||||
// How many child loots should drop?
|
|
||||||
@SerializedName("Child Loot Drop Count Min")
|
|
||||||
private Integer childDropCountMin;
|
|
||||||
@SerializedName("Child Loot Drop Count Max")
|
|
||||||
private Integer childDropCountMax;
|
|
||||||
|
|
||||||
// Should this drop house child drops?
|
|
||||||
@SerializedName("Child Loot")
|
|
||||||
private List<Loot> childLoot;
|
|
||||||
|
|
||||||
public Material getMaterial() {
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaterial(Material material) {
|
|
||||||
this.material = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommand() {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommand(String command) {
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(Short data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return Methods.formatText(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getLore() {
|
|
||||||
if (lore == null) return null;
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
for (String line : this.lore)
|
|
||||||
lore.add(Methods.formatText(line));
|
|
||||||
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLore(List<String> lore) {
|
|
||||||
this.lore = new ArrayList<>(lore);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Enchantment, Integer> getEnchants() {
|
|
||||||
if (enchants == null) return null;
|
|
||||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
|
||||||
for (Map.Entry<String, Integer> entry : this.enchants.entrySet())
|
|
||||||
enchants.put(Enchantment.getByName(entry.getKey()), entry.getValue());
|
|
||||||
return enchants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnchants(Map<String, Integer> enchants) {
|
|
||||||
this.enchants = enchants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getBurnedMaterial() {
|
|
||||||
return burnedMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBurnedMaterial(Material burnedMaterial) {
|
|
||||||
this.burnedMaterial = burnedMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getChance() {
|
|
||||||
return chance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChance(double chance) {
|
|
||||||
this.chance = chance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean runChance(int looting) {
|
|
||||||
return (Math.random() * 100) - (chance + (lootingIncrease == null ? 1
|
|
||||||
: lootingIncrease * looting)) < 0 || chance == 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMin() {
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMin(int min) {
|
|
||||||
this.min = min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMax() {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMax(int max) {
|
|
||||||
this.max = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmountToDrop(int looting) {
|
|
||||||
return min == max ? (max + getLooting(looting)) : new Random().nextInt((max + getLooting(looting)) - min + 1) + min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLooting(int looting) {
|
|
||||||
return allowLootingEnchant ? looting : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAllowLootingEnchant() {
|
|
||||||
return allowLootingEnchant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowLootingEnchant(boolean allowLootingEnchant) {
|
|
||||||
this.allowLootingEnchant = allowLootingEnchant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLootingIncrease(double increase) {
|
|
||||||
this.lootingIncrease = increase;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Loot> getChild() {
|
|
||||||
return childLoot == null ? new ArrayList<>() : new ArrayList<>(childLoot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addChildLoots(Loot... loots) {
|
|
||||||
this.childDropCountMin = 1;
|
|
||||||
this.childDropCountMax = 1;
|
|
||||||
this.childLoot = new ArrayList<>();
|
|
||||||
this.childLoot.addAll(Arrays.asList(loots));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Loot> getChildLoot() {
|
|
||||||
return childLoot == null ? new ArrayList<>() : new ArrayList<>(childLoot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EntityType> getOnlyDropFor() {
|
|
||||||
return onlyDropFor == null ? new ArrayList<>() : new ArrayList<>(onlyDropFor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addOnlyDropFors(EntityType... types) {
|
|
||||||
this.onlyDropFor = new ArrayList<>();
|
|
||||||
this.onlyDropFor.addAll(Arrays.asList(types));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChildDropCountMin(int childDropCountMin) {
|
|
||||||
this.childDropCountMin = childDropCountMin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChildDropCountMax(int childDropCountMax) {
|
|
||||||
this.childDropCountMax = childDropCountMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getChildDropCount() {
|
|
||||||
if (childDropCountMin == null || childDropCountMax == null) return 0;
|
|
||||||
return new Random().nextInt(childDropCountMax - min + 1) + childDropCountMin;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
package com.songoda.ultimatestacker.lootables;
|
|
||||||
|
|
||||||
|
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class LootBuilder {
|
|
||||||
|
|
||||||
private final Loot loot;
|
|
||||||
|
|
||||||
public LootBuilder() {
|
|
||||||
this.loot = new Loot();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setMaterial(Material material) {
|
|
||||||
this.loot.setMaterial(material);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setData(int data) {
|
|
||||||
return setData((short)data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setData(short data) {
|
|
||||||
this.loot.setData(data);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setName(String name) {
|
|
||||||
this.loot.setName(name);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder addLore(String... lore) {
|
|
||||||
this.loot.setLore(Arrays.asList(lore));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder addEnchants(Methods.Tuple... tuples) {
|
|
||||||
Map<String, Integer> enchants = new HashMap<>();
|
|
||||||
for (Methods.Tuple tuple : tuples)
|
|
||||||
enchants.put((String)tuple.getKey(), (int)tuple.getValue());
|
|
||||||
this.loot.setEnchants(enchants);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setBurnedMaterial(Material material) {
|
|
||||||
this.loot.setBurnedMaterial(material);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setChance(double chance) {
|
|
||||||
this.loot.setChance(chance);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setMin(int min) {
|
|
||||||
this.loot.setMin(min);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setMax(int max) {
|
|
||||||
this.loot.setMax(max);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setAllowLootingEnchant(boolean allow) {
|
|
||||||
this.loot.setAllowLootingEnchant(allow);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setLootingIncrease(double increase) {
|
|
||||||
this.loot.setLootingIncrease(increase);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder addOnlyDropFors(EntityType... types) {
|
|
||||||
this.loot.addOnlyDropFors(types);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder addChildLoot(Loot... loots) {
|
|
||||||
this.loot.addChildLoots(loots);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setChildDropCount(int count) {
|
|
||||||
this.loot.setChildDropCountMin(count);
|
|
||||||
this.loot.setChildDropCountMax(count);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setChildDropCounMin(int count) {
|
|
||||||
this.loot.setChildDropCountMin(count);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LootBuilder setChildDropCountMax(int count) {
|
|
||||||
this.loot.setChildDropCountMax(count);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Loot build() {
|
|
||||||
return this.loot;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.songoda.ultimatestacker.lootables;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Lootable {
|
|
||||||
|
|
||||||
// The entity applicable to this lootable.
|
|
||||||
@SerializedName("Type")
|
|
||||||
private final EntityType type;
|
|
||||||
|
|
||||||
// Registered loot.
|
|
||||||
@SerializedName("Loot")
|
|
||||||
private final List<Loot> registeredLoot = new ArrayList<>();
|
|
||||||
|
|
||||||
public Lootable(EntityType type, Loot... loots) {
|
|
||||||
this.type = type;
|
|
||||||
registeredLoot.addAll(Arrays.asList(loots));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Loot> getRegisteredLoot() {
|
|
||||||
return new ArrayList<>(registeredLoot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,143 +2,28 @@ package com.songoda.ultimatestacker.lootables;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.songoda.lootables.Lootables;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
|
||||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.Ageable;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.loot.Lootable;
|
||||||
import org.bukkit.entity.Sheep;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
public class LootManager {
|
public class LootManager {
|
||||||
|
|
||||||
private final Map<EntityType, Lootable> registeredLootables = new HashMap<>();
|
private final Lootables instance;
|
||||||
|
|
||||||
|
public LootManager() {
|
||||||
|
this.instance = new Lootables();
|
||||||
|
}
|
||||||
|
|
||||||
private final String lootablesDir = UltimateStacker.getInstance().getDataFolder() + File.separator + "lootables";
|
private final String lootablesDir = UltimateStacker.getInstance().getDataFolder() + File.separator + "lootables";
|
||||||
|
|
||||||
public Lootable addLootable(Lootable lootable) {
|
|
||||||
return registeredLootables.put(lootable.getType(), lootable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Drop> getDrops(LivingEntity entity) {
|
|
||||||
List<Drop> toDrop = new ArrayList<>();
|
|
||||||
if (entity instanceof Ageable && !((Ageable) entity).isAdult()
|
|
||||||
|| !registeredLootables.containsKey(entity.getType())) return toDrop;
|
|
||||||
|
|
||||||
Lootable lootable = registeredLootables.get(entity.getType());
|
|
||||||
int looting = entity.getKiller() != null
|
|
||||||
&& entity.getKiller().getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_MOBS)
|
|
||||||
? entity.getKiller().getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS)
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
int rerollChance = looting / (looting + 1);
|
|
||||||
|
|
||||||
for (Loot loot : lootable.getRegisteredLoot())
|
|
||||||
toDrop.addAll(runLoot(entity, loot, rerollChance, looting));
|
|
||||||
|
|
||||||
return toDrop;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Drop> runLoot(LivingEntity entity, Loot loot, int rerollChance, int looting) {
|
|
||||||
List<Drop> toDrop = new ArrayList<>();
|
|
||||||
if (loot.runChance(looting) || ((Math.random() * 100) - rerollChance < 0 || rerollChance == 100)
|
|
||||||
&& loot.runChance(looting)) {
|
|
||||||
|
|
||||||
if (loot.getOnlyDropFor().size() != 0
|
|
||||||
&& loot.getOnlyDropFor().stream().noneMatch(type -> entity.getKiller() != null && type == entity.getKiller().getType()))
|
|
||||||
return toDrop;
|
|
||||||
|
|
||||||
if (loot.getChildLoot().size() > 0) {
|
|
||||||
List<Loot> childLoot = loot.getChildLoot();
|
|
||||||
Collections.shuffle(childLoot);
|
|
||||||
|
|
||||||
int amt = loot.getChildDropCount();
|
|
||||||
|
|
||||||
for (int i = 0; i < amt; i++) {
|
|
||||||
toDrop.addAll(runLoot(entity, childLoot.get(i), rerollChance, looting));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Material material = loot.getMaterial();
|
|
||||||
String command = loot.getCommand();
|
|
||||||
|
|
||||||
if (material == null && command == null) return toDrop;
|
|
||||||
|
|
||||||
short data = loot.getData() != null ? loot.getData() : 0;
|
|
||||||
|
|
||||||
if (entity.getType() == EntityType.SHEEP
|
|
||||||
&& material == (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|
|
||||||
? Material.WHITE_WOOL : Material.valueOf("WOOL"))
|
|
||||||
&& ((Sheep) entity).getColor() != null) {
|
|
||||||
if (((Sheep) entity).isSheared()) return null;
|
|
||||||
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13))
|
|
||||||
material = Material.valueOf(((Sheep) entity).getColor() + "_WOOL");
|
|
||||||
else
|
|
||||||
data = ((Sheep) entity).getColor().getWoolData();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int amount = loot.getAmountToDrop(looting);
|
|
||||||
if (amount == 0) return toDrop;
|
|
||||||
|
|
||||||
if (material != null) {
|
|
||||||
ItemStack item = new ItemStack(loot.getBurnedMaterial() != null && entity.getFireTicks() != -1
|
|
||||||
? loot.getBurnedMaterial() : material, amount);
|
|
||||||
item.setDurability(data);
|
|
||||||
ItemMeta meta = item.getItemMeta() == null ? Bukkit.getItemFactory().getItemMeta(loot.getMaterial())
|
|
||||||
: item.getItemMeta();
|
|
||||||
|
|
||||||
if (loot.getName() != null)
|
|
||||||
meta.setDisplayName(loot.getName());
|
|
||||||
|
|
||||||
if (loot.getLore() != null)
|
|
||||||
meta.setLore(loot.getLore());
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
if (loot.getEnchants() != null)
|
|
||||||
item.addEnchantments(loot.getEnchants());
|
|
||||||
|
|
||||||
toDrop.add(new Drop(item));
|
|
||||||
}
|
|
||||||
if (command != null) {
|
|
||||||
for (int i = 0; i < amount; i++)
|
|
||||||
toDrop.add(new Drop(command));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return toDrop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadLootables() {
|
|
||||||
registeredLootables.clear();
|
|
||||||
File dir = new File(lootablesDir);
|
|
||||||
File[] directoryListing = dir.listFiles();
|
|
||||||
if (directoryListing != null) {
|
|
||||||
for (File file : directoryListing) {
|
|
||||||
if (!file.getName().endsWith(".json")) continue;
|
|
||||||
try {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
JsonReader reader = new JsonReader(new FileReader(file.getPath()));
|
|
||||||
|
|
||||||
Lootable lootable = gson.fromJson(reader, Lootable.class);
|
|
||||||
|
|
||||||
if (lootable.getRegisteredLoot().size() != 0)
|
|
||||||
addLootable(lootable);
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createDefaultLootables() {
|
public void createDefaultLootables() {
|
||||||
UltimateStacker plugin = UltimateStacker.getInstance();
|
UltimateStacker plugin = UltimateStacker.getInstance();
|
||||||
|
|
@ -1,9 +1,9 @@
|
|||||||
package com.songoda.ultimatestacker.utils;
|
package com.songoda.ultimatestacker.utils;
|
||||||
|
|
||||||
|
import com.songoda.lootables.loot.Drop;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.entity.Check;
|
import com.songoda.ultimatestacker.entity.Check;
|
||||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||||
import com.songoda.ultimatestacker.lootables.Drop;
|
|
||||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
Loading…
Reference in New Issue
Block a user