Done.
parent
e6961b3c0e
commit
356a75634b
@ -0,0 +1,64 @@
|
||||
package me.loganb1max.minionsplus.model.minions;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.Replacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.*;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BreederMinion extends Minion {
|
||||
|
||||
public BreederMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Breeder"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
public BreederMinion(final UUID owner, final String ownerName, final Location location, final double energy, final int level, final Set<Block> linkedBlocks) {
|
||||
this(owner, ownerName);
|
||||
setLocation(location);
|
||||
setEnergy(energy);
|
||||
setLevel(level);
|
||||
setLinkedBlocks(linkedBlocks);
|
||||
findStand();
|
||||
}
|
||||
|
||||
public int getRadius(final int level) {
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
||||
final int radius = getRadius(getLevel());
|
||||
boolean useEnergy = false;
|
||||
for (Entity e : getStand().getNearbyEntities(radius, radius, radius)) {
|
||||
if (!(e instanceof Animals)) continue;
|
||||
final Animals a = (Animals) e;
|
||||
if (!a.canBreed()) return;
|
||||
if (!a.isAdult()) return;
|
||||
a.setBreed(false);
|
||||
final Animals a2 = (Animals) getLocation().getWorld().spawnEntity(a.getLocation(), a.getType());
|
||||
a2.setBaby();
|
||||
useEnergy = true;
|
||||
}
|
||||
if (useEnergy) consumeEnergy(getEnergyPerUse(getLevel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
final DecimalFormat format = new DecimalFormat("#.#");
|
||||
return Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", format.format(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package me.loganb1max.minionsplus.model.minions;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.Replacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class ButcherMinion extends Minion {
|
||||
|
||||
public ButcherMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Butcher"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
public ButcherMinion(final UUID owner, final String ownerName, final Location location, final double energy, final int level, final Set<Block> linkedBlocks) {
|
||||
this(owner, ownerName);
|
||||
setLocation(location);
|
||||
setEnergy(energy);
|
||||
setLevel(level);
|
||||
setLinkedBlocks(linkedBlocks);
|
||||
findStand();
|
||||
}
|
||||
|
||||
public int getRadius(final int level) {
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
||||
final int radius = getRadius(getLevel());
|
||||
boolean useEnergy = false;
|
||||
for (Entity e : getStand().getNearbyEntities(radius, radius, radius)) {
|
||||
if (!(e instanceof LivingEntity)) continue;
|
||||
if (e instanceof Player) continue;
|
||||
LivingEntity le = (LivingEntity) e;
|
||||
MinionsPlus.getInstance().getMinionManager().getButcherKillMap().put(le, this);
|
||||
le.damage(Integer.MAX_VALUE);
|
||||
useEnergy = true;
|
||||
}
|
||||
if (useEnergy) consumeEnergy(getEnergyPerUse(getLevel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
final DecimalFormat format = new DecimalFormat("#.#");
|
||||
return Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", format.format(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package me.loganb1max.minionsplus.model.minions;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.Replacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class CollectorMinion extends Minion {
|
||||
|
||||
public CollectorMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Collector"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
public CollectorMinion(final UUID owner, final String ownerName, final Location location, final double energy, final int level, final Set<Block> linkedBlocks) {
|
||||
this(owner, ownerName);
|
||||
setLocation(location);
|
||||
setEnergy(energy);
|
||||
setLevel(level);
|
||||
setLinkedBlocks(linkedBlocks);
|
||||
findStand();
|
||||
}
|
||||
|
||||
public int getRadius(final int level) {
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
||||
final int radius = getRadius(getLevel());
|
||||
boolean useEnergy = false;
|
||||
for (Entity e : getStand().getNearbyEntities(radius, radius, radius)) {
|
||||
if (!(e instanceof Item)) continue;
|
||||
if (e.hasMetadata("minionignore")) continue;
|
||||
final Item item = (Item) e;
|
||||
final List<ItemStack> drops = new ArrayList<>();
|
||||
drops.add(item.getItemStack());
|
||||
item.remove();
|
||||
getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> {
|
||||
InventoryHolder inv = (InventoryHolder) b.getState();
|
||||
final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values();
|
||||
drops.clear();
|
||||
drops.addAll(remaining);
|
||||
});
|
||||
if (!drops.isEmpty()) {
|
||||
drops.forEach(i -> {
|
||||
Item it = getLocation().getWorld().dropItemNaturally(getLocation(), i);
|
||||
it.setMetadata("minionignore", new FixedMetadataValue(MinionsPlus.getInstance(), true));
|
||||
});
|
||||
}
|
||||
useEnergy = true;
|
||||
}
|
||||
if (useEnergy) consumeEnergy(getEnergyPerUse(getLevel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
final DecimalFormat format = new DecimalFormat("#.#");
|
||||
return Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", format.format(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package me.loganb1max.minionsplus.model.minions;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.Replacer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SellerMinion extends Minion {
|
||||
|
||||
public SellerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Seller"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
public SellerMinion(final UUID owner, final String ownerName, final Location location, final double energy, final int level, final Set<Block> linkedBlocks) {
|
||||
this(owner, ownerName);
|
||||
setLocation(location);
|
||||
setEnergy(energy);
|
||||
setLevel(level);
|
||||
setLinkedBlocks(linkedBlocks);
|
||||
findStand();
|
||||
}
|
||||
|
||||
public int getRadius(final int level) {
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
||||
final int radius = getRadius(getLevel());
|
||||
boolean sold = false;
|
||||
for (int y = getLocation().getBlockY() - radius; y < getLocation().getBlockY() + radius; y++) {
|
||||
for (int x = getLocation().getBlockX() - radius; x < getLocation().getBlockX() + radius; x++) {
|
||||
for (int z = getLocation().getBlockZ() - radius; z < getLocation().getBlockZ() + radius; z++) {
|
||||
final Block b = getLocation().getWorld().getBlockAt(x, y, z);
|
||||
if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) continue;
|
||||
final Chest chest = (Chest) b.getState();
|
||||
for (int i = 0; i < chest.getInventory().getSize(); i++) {
|
||||
final ItemStack item = chest.getInventory().getItem(i);
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
double sellPrice = MinionsPlus.getEssentials().getWorth().getPrice(MinionsPlus.getEssentials(), item).doubleValue();
|
||||
if (sellPrice <= 0) continue;
|
||||
MinionsPlus.getEcon().depositPlayer(Bukkit.getOfflinePlayer(getOwner()), sellPrice * item.getAmount());
|
||||
chest.getInventory().setItem(i, new ItemStack(Material.AIR));
|
||||
sold = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sold) consumeEnergy(getEnergyPerUse(getLevel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
final DecimalFormat format = new DecimalFormat("#.#");
|
||||
return Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", format.format(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue