Almost done.
Todo: - Write Logic for each minion - Implement ReFueling - Implement Chest/Block linking - Implement Upgradingmaster
parent
af06fd2f88
commit
2bb4d3b57f
@ -0,0 +1,116 @@
|
||||
package me.loganb1max.minions.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.loganb1max.minions.model.Minion;
|
||||
import me.loganb1max.minions.model.minions.FarmerMinion;
|
||||
import me.loganb1max.minions.model.minions.FisherMinion;
|
||||
import me.loganb1max.minions.model.minions.MinerMinion;
|
||||
import me.loganb1max.minions.util.ItemUtil;
|
||||
import me.loganb1max.minions.util.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MinionCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!sender.hasPermission("minions.command")) {
|
||||
sender.sendMessage(Text.color("&cYou don't have permission for this command."));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
|
||||
} else {
|
||||
sendHelp(sender);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 3) {
|
||||
if (!args[0].equalsIgnoreCase("give")) {
|
||||
sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player target = Bukkit.getPlayer(args[1]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(Text.color("&cPlayer Not Found."));
|
||||
return true;
|
||||
}
|
||||
|
||||
Minion minion = null;
|
||||
|
||||
final String type = args[2].toLowerCase();
|
||||
switch (type) {
|
||||
case "miner":
|
||||
minion = new MinerMinion(target);
|
||||
break;
|
||||
case "farmer":
|
||||
minion = new FarmerMinion(target);
|
||||
break;
|
||||
case "fisher":
|
||||
minion = new FisherMinion(target);
|
||||
break;
|
||||
}
|
||||
|
||||
if (minion == null) {
|
||||
sender.sendMessage(Text.color("&cInvalid Minion Type."));
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemUtil.giveAndDrop(target, minion.toItemStack());
|
||||
target.sendMessage(Text.color("&aYou have received a " + minion.getName()));
|
||||
sender.sendMessage(Text.color("&aYou gave " + target.getName() + " a " + minion.getName()));
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) {
|
||||
List<String> toReturn = new ArrayList<>();
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
toReturn = ImmutableList.of(
|
||||
"give",
|
||||
"reload"
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
toReturn = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
break;
|
||||
case 2:
|
||||
toReturn = ImmutableList.of(
|
||||
"miner",
|
||||
"farmer",
|
||||
"fisher"
|
||||
);
|
||||
break;
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private void sendHelp(final CommandSender sender) {
|
||||
sender.sendMessage(Text.color("&7============================================"));
|
||||
sender.sendMessage(Text.color("&6 Minions Help Menu"));
|
||||
sender.sendMessage(Text.color("&7============================================"));
|
||||
sender.sendMessage(Text.color("&6 /minions give <player> <type>"));
|
||||
sender.sendMessage(Text.color("&6 /minions reload"));
|
||||
}
|
||||
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package me.loganb1max.minions.model;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.Getter;
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractMinion implements Minion {
|
||||
|
||||
private final UUID owner;
|
||||
private final String ownerName;
|
||||
private Location location;
|
||||
private double energy;
|
||||
private int level;
|
||||
private Set<Block> linkedBlocks;
|
||||
private ArmorStand stand;
|
||||
|
||||
private double offset = 0.1;
|
||||
|
||||
public AbstractMinion(final Player owner) {
|
||||
this.owner = owner.getUniqueId();
|
||||
this.ownerName = owner.getName();
|
||||
}
|
||||
|
||||
public void spawn(final Location location) {
|
||||
this.location = location;
|
||||
if (this.stand == null) {
|
||||
this.stand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
this.stand.setSmall(true);
|
||||
this.stand.setBasePlate(false);
|
||||
this.stand.setGravity(false);
|
||||
this.stand.setCanPickupItems(false);
|
||||
this.stand.setRemoveWhenFarAway(false);
|
||||
this.stand.setMarker(false);
|
||||
this.equipEquipment(this.stand);
|
||||
MinionsPlugin.getInstance().getMinionManager().getMinions().add(this);
|
||||
} else {
|
||||
this.stand.teleport(location);
|
||||
}
|
||||
}
|
||||
|
||||
public void despawn(final Player player) {
|
||||
if (this.stand == null) return;
|
||||
this.location = null;
|
||||
this.stand.remove();
|
||||
this.stand = null;
|
||||
this.linkedBlocks.clear();
|
||||
player.getInventory().addItem(this.toItemStack()).forEach((integer, itemStack) -> player.getWorld().dropItemNaturally(player.getLocation(), itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pickup(Player player) {
|
||||
this.despawn(player);
|
||||
MinionsPlugin.getInstance().getMinionManager().getMinions().remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Block> getLinkedBlocks() {
|
||||
return ImmutableSet.copyOf(this.linkedBlocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double gainEnergy(final double amount) {
|
||||
return this.energy += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double consumeEnergy(final double amount) {
|
||||
return this.energy -= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
if (this.stand == null) return null;
|
||||
return this.stand.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.stand == null) return;
|
||||
if (this.stand.getRightArmPose().getX() > 300) offset = -0.1;
|
||||
if (this.stand.getRightArmPose().getX() < 230) offset = 0.1;
|
||||
this.stand.setRightArmPose(this.stand.getRightArmPose().add(offset, 0, 0));
|
||||
this.stand.setFireTicks(0);
|
||||
}
|
||||
|
||||
public abstract ItemStack toItemStack();
|
||||
|
||||
public abstract void equipEquipment(final ArmorStand stand);
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package me.loganb1max.minions.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.loganb1max.minions.util.ItemUtil;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Fuel {
|
||||
|
||||
private final String name;
|
||||
private final ItemStack itemStack;
|
||||
private final double energy;
|
||||
|
||||
public boolean isEqual(final ItemStack item) {
|
||||
return ItemUtil.compareType(this.itemStack, item);
|
||||
}
|
||||
|
||||
public static Fuel fromConfigSection(final ConfigurationSection section) {
|
||||
final String name = section.getName();
|
||||
final double energy = section.getDouble("Energy");
|
||||
final ItemStack item = ItemUtil.fromConfigSection(section.getConfigurationSection("Item"));
|
||||
return new Fuel(name, item, energy);
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +1,227 @@
|
||||
package me.loganb1max.minions.model;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
import me.loganb1max.minions.model.minions.FarmerMinion;
|
||||
import me.loganb1max.minions.model.minions.FisherMinion;
|
||||
import me.loganb1max.minions.model.minions.MinerMinion;
|
||||
import me.loganb1max.minions.util.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Minion {
|
||||
|
||||
String getName();
|
||||
|
||||
UUID getId();
|
||||
|
||||
UUID getOwner();
|
||||
|
||||
String getOwnerName();
|
||||
|
||||
Location getLocation();
|
||||
|
||||
double getEnergy();
|
||||
|
||||
int getLevel();
|
||||
|
||||
Set<Block> getLinkedBlocks();
|
||||
|
||||
double gainEnergy(final double amount);
|
||||
|
||||
double consumeEnergy(final double amount);
|
||||
|
||||
void spawn(final Location location);
|
||||
|
||||
void despawn(final Player player);
|
||||
|
||||
ItemStack getIcon();
|
||||
|
||||
void tick();
|
||||
|
||||
void pickup(final Player player);
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Getter
|
||||
public abstract class Minion {
|
||||
|
||||
private final ConfigurationSection section;
|
||||
private final Replacer replacer;
|
||||
private final UUID owner;
|
||||
private final String ownerName;
|
||||
@Setter(AccessLevel.PROTECTED) private Location location;
|
||||
@Setter(AccessLevel.PROTECTED) private double energy;
|
||||
@Setter(AccessLevel.PROTECTED) private int level;
|
||||
@Setter(AccessLevel.PROTECTED)private Set<Block> linkedBlocks;
|
||||
private ArmorStand stand;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private double offset = 0.1;
|
||||
|
||||
public Minion(final ConfigurationSection section, final UUID owner, final String ownerName) {
|
||||
this.section = section;
|
||||
this.owner = owner;
|
||||
this.ownerName = ownerName;
|
||||
this.replacer = Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", String.valueOf(getEnergy()))
|
||||
.add("%owner%", getOwnerName());
|
||||
}
|
||||
|
||||
protected void findStand() {
|
||||
if (this.stand != null) return;
|
||||
this.location.getWorld().getNearbyEntities(this.location, 0.5, 0.5, 0.5).stream().filter(entity -> entity instanceof ArmorStand && !entity.getCustomName().isEmpty()).findFirst().ifPresent(entity -> {
|
||||
this.stand = (ArmorStand) entity;
|
||||
});
|
||||
}
|
||||
|
||||
public void spawn(final Location location) {
|
||||
this.location = location;
|
||||
if (this.stand == null) {
|
||||
this.stand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
this.stand.setSmall(true);
|
||||
this.stand.setBasePlate(false);
|
||||
this.stand.setGravity(false);
|
||||
this.stand.setCanPickupItems(false);
|
||||
this.stand.setRemoveWhenFarAway(false);
|
||||
this.stand.setMarker(false);
|
||||
this.stand.setCustomName(Text.color(getName()));
|
||||
this.stand.setCustomNameVisible(true);
|
||||
this.equipEquipment(this.stand);
|
||||
MinionsPlugin.getInstance().getMinionManager().getMinions().add(this);
|
||||
} else {
|
||||
this.stand.teleport(location);
|
||||
}
|
||||
}
|
||||
|
||||
public void despawn(final Player player) {
|
||||
if (this.stand == null) return;
|
||||
this.location = null;
|
||||
this.stand.remove();
|
||||
this.stand = null;
|
||||
this.linkedBlocks.clear();
|
||||
player.getInventory().addItem(this.toItemStack()).forEach((integer, itemStack) -> player.getWorld().dropItemNaturally(player.getLocation(), itemStack));
|
||||
MinionsPlugin.getInstance().getMinionManager().getMinions().remove(this);
|
||||
}
|
||||
|
||||
public void animationTick() {
|
||||
if (this.stand == null) return;
|
||||
if (this.stand.getRightArmPose().getX() > 300) offset = -0.1;
|
||||
if (this.stand.getRightArmPose().getX() < 230) offset = 0.1;
|
||||
this.stand.setRightArmPose(this.stand.getRightArmPose().add(offset, 0, 0));
|
||||
this.stand.setFireTicks(0);
|
||||
}
|
||||
|
||||
public double gainEnergy(final double amount) {
|
||||
return this.energy += amount;
|
||||
}
|
||||
|
||||
public double consumeEnergy(final double amount) {
|
||||
return this.energy -= amount;
|
||||
}
|
||||
|
||||
public void equipEquipment(final ArmorStand stand) {
|
||||
final String skull = this.section.getString("Equipment.Skull", "");
|
||||
ItemStack skullItem = SkullCreator.itemFromBase64(skull);
|
||||
stand.setHelmet(skullItem);
|
||||
final ItemStack chestplate = ItemUtil.fromConfigSection(this.section.getConfigurationSection("Equipment.Chestplate"));
|
||||
stand.setChestplate(chestplate);
|
||||
final ItemStack leggings = ItemUtil.fromConfigSection(this.section.getConfigurationSection("Equipment.Leggings"));
|
||||
stand.setLeggings(leggings);
|
||||
final ItemStack boots = ItemUtil.fromConfigSection(this.section.getConfigurationSection("Equipment.Boots"));
|
||||
stand.setBoots(boots);
|
||||
final ItemStack rightHand = ItemUtil.fromConfigSection(this.section.getConfigurationSection("Equipment.RightHand"));
|
||||
stand.setItemInHand(rightHand);
|
||||
}
|
||||
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack item = getIcon();
|
||||
item = ItemUtil.setKeyString(item, "minion-owner", this.owner.toString());
|
||||
item = ItemUtil.setKeyString(item, "minion-owner-name", this.ownerName);
|
||||
item = ItemUtil.setKeyInt(item, "minion-level", this.level);
|
||||
item = ItemUtil.setKeyDouble(item, "minion-energy", this.energy);
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemStack getIcon() {
|
||||
final Material material = Material.getMaterial(this.section.getString("Item.Material"));
|
||||
final int durability = this.section.getInt("Item.Durability");
|
||||
final String skull = this.section.getString("Item.Skull", null);
|
||||
final String displayName = this.section.getString("Item.DisplayName");
|
||||
final List<String> lore = this.section.getStringList("Item.Lore");
|
||||
ItemStack item = ItemBuilder.of(material)
|
||||
.durability((short) durability)
|
||||
.name(displayName)
|
||||
.lore(this.replacer.replace(lore))
|
||||
.build();
|
||||
if (material == Material.SKULL_ITEM && skull != null) {
|
||||
item = SkullCreator.itemWithBase64(item, skull);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public Set<Block> getLinkedBlocks() {
|
||||
return ImmutableSet.copyOf(this.linkedBlocks);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
if (this.stand == null) return null;
|
||||
return this.stand.getUniqueId();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.section.getName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.section.getString("Name");
|
||||
}
|
||||
|
||||
public double getEnergyPerUse(final int level) {
|
||||
return this.section.getDouble("Levels." + level + ".EnergyPerAction", 0.0);
|
||||
}
|
||||
|
||||
public double getPrice(final int level) {
|
||||
return this.section.getDouble("Levels." + level + ".Price", 0.0);
|
||||
}
|
||||
|
||||
public JsonElement serialize() {
|
||||
final Gson gson = new Gson();
|
||||
final JsonObject object = new JsonObject();
|
||||
object.addProperty("type", getType());
|
||||
object.addProperty("owner", this.owner.toString());
|
||||
object.addProperty("ownerName", this.ownerName);
|
||||
final JsonObject loc = new JsonObject();
|
||||
loc.addProperty("world", this.location.getWorld().getName());
|
||||
loc.addProperty("x", this.location.getX());
|
||||
loc.addProperty("y", this.location.getY());
|
||||
loc.addProperty("z", this.location.getZ());
|
||||
object.add("location", loc);
|
||||
object.addProperty("energy", this.energy);
|
||||
object.addProperty("level", this.level);
|
||||
final List<JsonElement> linked = new ArrayList<>();
|
||||
this.linkedBlocks.forEach(block -> {
|
||||
JsonObject b = new JsonObject();
|
||||
b.addProperty("world", block.getWorld().getName());
|
||||
b.addProperty("x", block.getX());
|
||||
b.addProperty("y", block.getY());
|
||||
b.addProperty("z", block.getZ());
|
||||
linked.add(b);
|
||||
});
|
||||
object.add("linkedBlocks", gson.toJsonTree(linked));
|
||||
return object;
|
||||
}
|
||||
|
||||
public static Minion deserialize(final MinionsPlugin plugin, final JsonElement element) {
|
||||
final JsonObject data = element.getAsJsonObject();
|
||||
final String type = data.get("type").getAsString();
|
||||
final UUID owner = UUID.fromString(data.get("owner").getAsString());
|
||||
final String ownerName = data.get("ownerName").getAsString();
|
||||
final JsonObject locData = data.get("location").getAsJsonObject();
|
||||
final Location location = new Location(Bukkit.getWorld(locData.get("world").getAsString()), locData.get("x").getAsDouble(), locData.get("y").getAsDouble(), locData.get("z").getAsDouble());
|
||||
final double energy = data.get("energy").getAsDouble();
|
||||
final int level = data.get("level").getAsInt();
|
||||
final Set<Block> linkedBlocks = Stream.of(data.get("linkedBlocks").getAsJsonArray())
|
||||
.map(JsonElement::getAsJsonObject)
|
||||
.map(jsonObject -> Bukkit.getWorld(jsonObject.get("world").getAsString()).getBlockAt(jsonObject.get("x").getAsInt(), jsonObject.get("y").getAsInt(), jsonObject.get("z").getAsInt())).collect(Collectors.toSet());
|
||||
Minion toReturn = null;
|
||||
switch (type) {
|
||||
case "Miner":
|
||||
toReturn = new MinerMinion(owner, ownerName, location, energy, level, linkedBlocks);
|
||||
break;
|
||||
case "Farmer":
|
||||
toReturn = new FarmerMinion(owner, ownerName, location, energy, level, linkedBlocks);
|
||||
break;
|
||||
case "Fisher":
|
||||
toReturn = new FisherMinion(owner, ownerName, location, energy, level, linkedBlocks);
|
||||
break;
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public abstract void tick();
|
||||
|
||||
}
|
||||
|
@ -1,93 +1,39 @@
|
||||
package me.loganb1max.minions.model.minions;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
import me.loganb1max.minions.model.AbstractMinion;
|
||||
import me.loganb1max.minions.util.ItemUtil;
|
||||
import me.loganb1max.minions.util.Replacer;
|
||||
import me.loganb1max.minions.util.SkullCreator;
|
||||
import me.loganb1max.minions.util.Text;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import me.loganb1max.minions.model.Minion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FarmerMinion extends AbstractMinion {
|
||||
public class FarmerMinion extends Minion {
|
||||
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public FarmerMinion(final Player owner) {
|
||||
super(owner);
|
||||
this.section = MinionsPlugin.getInstance().getConfig().getConfigurationSection("Farmer");
|
||||
public FarmerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlugin.getInstance().getConfig().getConfigurationSection("Farmer"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
getReplacer().add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIcon() {
|
||||
final Material material = Material.getMaterial(section.getString("Item.Material"));
|
||||
final int durability = section.getInt("Item.Durability");
|
||||
final String skull = section.getString("Item.Skull", null);
|
||||
final String displayName = section.getString("Item.DisplayName");
|
||||
final List<String> lore = section.getStringList("Item.Lore");
|
||||
final Replacer replacer = Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", String.valueOf(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
item.setDurability((short) durability);
|
||||
if (material == Material.SKULL_ITEM && skull != null) {
|
||||
item = SkullCreator.itemWithBase64(item, skull);
|
||||
}
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Text.color(displayName));
|
||||
meta.setLore(lore.stream().map(Text::color).map(replacer::replace).collect(Collectors.toList()));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack item = getIcon();
|
||||
item = ItemUtil.setKeyString(item, "minion-owner", getOwner().toString());
|
||||
item = ItemUtil.setKeyString(item, "minion-owner-name", getOwnerName());
|
||||
item = ItemUtil.setKeyInt(item, "minion-level", getLevel());
|
||||
item = ItemUtil.setKeyDouble(item, "minion-energy", getEnergy());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipEquipment(ArmorStand stand) {
|
||||
final String skull = section.getString("Equipment.Skull", "");
|
||||
ItemStack skullItem = SkullCreator.itemFromBase64(skull);
|
||||
stand.setHelmet(skullItem);
|
||||
final ItemStack chestplate = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Chestplate"));
|
||||
stand.setChestplate(chestplate);
|
||||
final ItemStack leggings = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Leggings"));
|
||||
stand.setLeggings(leggings);
|
||||
final ItemStack boots = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Boots"));
|
||||
stand.setBoots(boots);
|
||||
final ItemStack rightHand = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.RightHand"));
|
||||
stand.setItemInHand(rightHand);
|
||||
public FarmerMinion(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 section.getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
public double getPrice(final int level) {
|
||||
return section.getDouble("Levels." + level + ".Price", 0.0);
|
||||
}
|
||||
|
||||
public double getEnergyPerUse(final int level) {
|
||||
return section.getDouble("Levels." + level + ".EnergyPerAction", 0.0);
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return section.getString("Name");
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,98 +1,43 @@
|
||||
package me.loganb1max.minions.model.minions;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
import me.loganb1max.minions.model.AbstractMinion;
|
||||
import me.loganb1max.minions.util.ItemUtil;
|
||||
import me.loganb1max.minions.util.Replacer;
|
||||
import me.loganb1max.minions.util.SkullCreator;
|
||||
import me.loganb1max.minions.util.Text;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import me.loganb1max.minions.model.Minion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FisherMinion extends AbstractMinion {
|
||||
public class FisherMinion extends Minion {
|
||||
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public FisherMinion(final Player owner) {
|
||||
super(owner);
|
||||
this.section = MinionsPlugin.getInstance().getConfig().getConfigurationSection("Fisher");
|
||||
public FisherMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlugin.getInstance().getConfig().getConfigurationSection("Fisher"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
getReplacer().add("%radius%", String.valueOf(getRadius(getLevel()))).add("%chanceperblockpersecond%", String.valueOf(getChancePerBlockPerSecond(getLevel())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIcon() {
|
||||
final Material material = Material.getMaterial(section.getString("Item.Material"));
|
||||
final int durability = section.getInt("Item.Durability");
|
||||
final String skull = section.getString("Item.Skull", null);
|
||||
final String displayName = section.getString("Item.DisplayName");
|
||||
final List<String> lore = section.getStringList("Item.Lore");
|
||||
final Replacer replacer = Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", String.valueOf(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())))
|
||||
.add("%chanceperblockpersecond%", String.valueOf(getChancePerBlockPerSecond(getLevel())));
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
item.setDurability((short) durability);
|
||||
if (material == Material.SKULL_ITEM && skull != null) {
|
||||
item = SkullCreator.itemWithBase64(item, skull);
|
||||
}
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Text.color(displayName));
|
||||
meta.setLore(lore.stream().map(Text::color).map(replacer::replace).collect(Collectors.toList()));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack item = getIcon();
|
||||
item = ItemUtil.setKeyString(item, "minion-owner", getOwner().toString());
|
||||
item = ItemUtil.setKeyString(item, "minion-owner-name", getOwnerName());
|
||||
item = ItemUtil.setKeyInt(item, "minion-level", getLevel());
|
||||
item = ItemUtil.setKeyDouble(item, "minion-energy", getEnergy());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipEquipment(ArmorStand stand) {
|
||||
final String skull = section.getString("Equipment.Skull", "");
|
||||
ItemStack skullItem = SkullCreator.itemFromBase64(skull);
|
||||
stand.setHelmet(skullItem);
|
||||
final ItemStack chestplate = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Chestplate"));
|
||||
stand.setChestplate(chestplate);
|
||||
final ItemStack leggings = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Leggings"));
|
||||
stand.setLeggings(leggings);
|
||||
final ItemStack boots = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Boots"));
|
||||
stand.setBoots(boots);
|
||||
final ItemStack rightHand = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.RightHand"));
|
||||
stand.setItemInHand(rightHand);
|
||||
public FisherMinion(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 double getChancePerBlockPerSecond(final int level) {
|
||||
return section.getDouble("Levels." + level + ".ChancePerBlockPerSecond", 0.0);
|
||||
return getSection().getDouble("Levels." + level + ".ChancePerBlockPerSecond", 0.0);
|
||||
}
|
||||
|
||||
public int getRadius(final int level) {
|
||||
return section.getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
public double getPrice(final int level) {
|
||||
return section.getDouble("Levels." + level + ".Price", 0.0);
|
||||
}
|
||||
|
||||
public double getEnergyPerUse(final int level) {
|
||||
return section.getDouble("Levels." + level + ".EnergyPerAction", 0.0);
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return section.getString("Name");
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,93 +1,39 @@
|
||||
package me.loganb1max.minions.model.minions;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
import me.loganb1max.minions.model.AbstractMinion;
|
||||
import me.loganb1max.minions.util.ItemUtil;
|
||||
import me.loganb1max.minions.util.Replacer;
|
||||
import me.loganb1max.minions.util.SkullCreator;
|
||||
import me.loganb1max.minions.util.Text;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import me.loganb1max.minions.model.Minion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MinerMinion extends AbstractMinion {
|
||||
public class MinerMinion extends Minion {
|
||||
|
||||
private final ConfigurationSection section;
|
||||
|
||||
public MinerMinion(final Player owner) {
|
||||
super(owner);
|
||||
this.section = MinionsPlugin.getInstance().getConfig().getConfigurationSection("Miner");
|
||||
public MinerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlugin.getInstance().getConfig().getConfigurationSection("Miner"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
getReplacer().add("%blocklimit%", String.valueOf(getBlockLimit(getLevel())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIcon() {
|
||||
final Material material = Material.getMaterial(section.getString("Item.Material"));
|
||||
final int durability = section.getInt("Item.Durability");
|
||||
final String skull = section.getString("Item.Skull", null);
|
||||
final String displayName = section.getString("Item.DisplayName");
|
||||
final List<String> lore = section.getStringList("Item.Lore");
|
||||
final Replacer replacer = Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", String.valueOf(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%blocklimit%", String.valueOf(getBlockLimit(getLevel())));
|
||||
ItemStack item = new ItemStack(material, 1);
|
||||
item.setDurability((short) durability);
|
||||
if (material == Material.SKULL_ITEM && skull != null) {
|
||||
item = SkullCreator.itemWithBase64(item, skull);
|
||||
}
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Text.color(displayName));
|
||||
meta.setLore(lore.stream().map(Text::color).map(replacer::replace).collect(Collectors.toList()));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack item = getIcon();
|
||||
item = ItemUtil.setKeyString(item, "minion-owner", getOwner().toString());
|
||||
item = ItemUtil.setKeyString(item, "minion-owner-name", getOwnerName());
|
||||
item = ItemUtil.setKeyInt(item, "minion-level", getLevel());
|
||||
item = ItemUtil.setKeyDouble(item, "minion-energy", getEnergy());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipEquipment(ArmorStand stand) {
|
||||
final String skull = section.getString("Equipment.Skull", "");
|
||||
ItemStack skullItem = SkullCreator.itemFromBase64(skull);
|
||||
stand.setHelmet(skullItem);
|
||||
final ItemStack chestplate = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Chestplate"));
|
||||
stand.setChestplate(chestplate);
|
||||
final ItemStack leggings = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Leggings"));
|
||||
stand.setLeggings(leggings);
|
||||
final ItemStack boots = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.Boots"));
|
||||
stand.setBoots(boots);
|
||||
final ItemStack rightHand = ItemUtil.fromConfigSection(section.getConfigurationSection("Equipment.RightHand"));
|
||||
stand.setItemInHand(rightHand);
|
||||
public MinerMinion(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 getBlockLimit(final int level) {
|
||||
return section.getInt("Levels." + level + ".BlockLimit", 1);
|
||||
}
|
||||
|
||||
public double getPrice(final int level) {
|
||||
return section.getDouble("Levels." + level + ".Price", 0.0);
|
||||
}
|
||||
|
||||
public double getEnergyPerUse(final int level) {
|
||||
return section.getDouble("Levels." + level + ".EnergyPerAction", 0.0);
|
||||
return getSection().getInt("Levels." + level + ".BlockLimit", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return section.getString("Name");
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue