Finished
parent
2bb4d3b57f
commit
c051cf2714
@ -1,2 +1,2 @@
|
||||
rootProject.name = 'minions'
|
||||
rootProject.name = 'minionsplus'
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
package me.loganb1max.minions;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.loganb1max.minions.command.MinionCommand;
|
||||
import me.loganb1max.minions.manager.MinionManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class MinionsPlugin extends JavaPlugin {
|
||||
|
||||
@Getter private static MinionsPlugin instance;
|
||||
@Getter private MinionManager minionManager;
|
||||
private MinionCommand minionCommand;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
this.minionManager = new MinionManager(this);
|
||||
this.minionCommand = new MinionCommand();
|
||||
getCommand("minions").setExecutor(minionCommand);
|
||||
getCommand("minions").setTabCompleter(minionCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.minionManager.close();
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package me.loganb1max.minions.menu;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
import me.loganb1max.minions.model.Minion;
|
||||
import me.loganb1max.minions.util.ItemBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MinionMenu implements Listener {
|
||||
|
||||
private final Minion minion;
|
||||
private final Player player;
|
||||
private final Inventory inventory;
|
||||
private final Map<Integer, Consumer<ClickType>> clickHandlerMap = new HashMap<>();
|
||||
|
||||
public MinionMenu(final Minion minion, final Player player) {
|
||||
this.minion = minion;
|
||||
this.player = player;
|
||||
Bukkit.getPluginManager().registerEvents(this, MinionsPlugin.getInstance());
|
||||
this.inventory = Bukkit.createInventory(this.player, 9, "Minion Menu");
|
||||
|
||||
bindItem(
|
||||
minion.getIcon(),
|
||||
1,
|
||||
clickType -> { }
|
||||
);
|
||||
|
||||
bindItem(
|
||||
ItemBuilder.of(Material.GOLD_INGOT)
|
||||
.name("&6Upgrade")
|
||||
.lore("&7click to upgrade this minion.")
|
||||
.build(),
|
||||
3,
|
||||
clickType -> {
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
bindItem(
|
||||
ItemBuilder.of(Material.COAL)
|
||||
.name("&6Deposit Energy")
|
||||
.lore("")
|
||||
.build(),
|
||||
5,
|
||||
clickType -> {
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
bindItem(
|
||||
ItemBuilder.of(Material.CHEST)
|
||||
.name("&6Link Chest")
|
||||
.lore("&7click to link a deposit chest.")
|
||||
.build(),
|
||||
7,
|
||||
clickType -> {
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
this.player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
private void bindItem(final ItemStack item, final int slot, final Consumer<ClickType> consumer) {
|
||||
this.inventory.setItem(slot, item);
|
||||
this.clickHandlerMap.remove(slot);
|
||||
this.clickHandlerMap.put(slot, consumer);
|
||||
this.player.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onClose(final InventoryCloseEvent e) {
|
||||
if (!e.getInventory().equals(this.inventory)) return;
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onClick(final InventoryClickEvent e) {
|
||||
if (!e.getClickedInventory().equals(this.inventory)) return;
|
||||
e.setCancelled(true);
|
||||
this.clickHandlerMap.get(e.getSlot()).accept(e.getClick());
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package me.loganb1max.minions.model.minions;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
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 Minion {
|
||||
|
||||
public FarmerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlugin.getInstance().getConfig().getConfigurationSection("Farmer"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
getReplacer().add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
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 getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package me.loganb1max.minions.model.minions;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
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 Minion {
|
||||
|
||||
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())));
|
||||
}
|
||||
|
||||
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 getSection().getDouble("Levels." + level + ".ChancePerBlockPerSecond", 0.0);
|
||||
}
|
||||
|
||||
public int getRadius(final int level) {
|
||||
return getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package me.loganb1max.minions.model.minions;
|
||||
|
||||
import me.loganb1max.minions.MinionsPlugin;
|
||||
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 Minion {
|
||||
|
||||
public MinerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlugin.getInstance().getConfig().getConfigurationSection("Miner"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
getReplacer().add("%blocklimit%", String.valueOf(getBlockLimit(getLevel())));
|
||||
}
|
||||
|
||||
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 getSection().getInt("Levels." + level + ".BlockLimit", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package me.loganb1max.minionsplus;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.loganb1max.minionsplus.command.MinionCommand;
|
||||
import me.loganb1max.minionsplus.manager.LinkingManager;
|
||||
import me.loganb1max.minionsplus.manager.MinionManager;
|
||||
import me.loganb1max.minionsplus.model.Fuel;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MinionsPlus extends JavaPlugin {
|
||||
|
||||
@Getter private static MinionsPlus instance;
|
||||
@Getter private static Economy econ;
|
||||
@Getter private MinionManager minionManager;
|
||||
@Getter private LinkingManager linkingManager;
|
||||
private MinionCommand minionCommand;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
saveDefaultConfig();
|
||||
setupEconomy();
|
||||
this.minionManager = new MinionManager(this);
|
||||
this.linkingManager = new LinkingManager(this);
|
||||
this.minionCommand = new MinionCommand();
|
||||
getCommand("minions").setExecutor(minionCommand);
|
||||
getCommand("minions").setTabCompleter(minionCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.minionManager.close();
|
||||
this.linkingManager.close();
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
return econ != null;
|
||||
}
|
||||
|
||||
public Set<Fuel> getFuels() {
|
||||
return getConfig()
|
||||
.getConfigurationSection("Fuel")
|
||||
.getKeys(false)
|
||||
.stream()
|
||||
.map(s -> Fuel.fromConfigSection(getConfig().getConfigurationSection("Fuel." + s)))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package me.loganb1max.minionsplus.manager;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LinkingManager implements Listener {
|
||||
|
||||
private final MinionsPlus plugin;
|
||||
private final BukkitTask timerTask;
|
||||
private Map<Player, Minion> linkingMap = new HashMap<>();
|
||||
private Map<Player, Integer> timeMap = new HashMap<>();
|
||||
|
||||
public LinkingManager(final MinionsPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, this.plugin);
|
||||
this.timerTask = Bukkit.getScheduler().runTaskTimer(this.plugin, () -> {
|
||||
for (Map.Entry<Player, Integer> entry : timeMap.entrySet()) {
|
||||
if (entry.getValue() > 0) entry.setValue(entry.getValue() - 1);
|
||||
else endLinking(entry.getKey());
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
HandlerList.unregisterAll(this);
|
||||
this.timerTask.cancel();
|
||||
}
|
||||
|
||||
public void beginLinking(final Player player, final Minion minion) {
|
||||
this.linkingMap.put(player, minion);
|
||||
this.timeMap.put(player, 15);
|
||||
player.sendMessage(Text.color("&aYou have begun linking new blocks for " + minion.getName() + ". (15 Seconds)"));
|
||||
}
|
||||
|
||||
private void endLinking(final Player player) {
|
||||
this.linkingMap.remove(player);
|
||||
this.timeMap.remove(player);
|
||||
player.sendMessage(Text.color("&cYou are no longer linking blocks."));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onLink(final PlayerInteractEvent e) {
|
||||
if (!this.linkingMap.containsKey(e.getPlayer())) return;
|
||||
if (!e.hasBlock()) {
|
||||
e.getPlayer().sendMessage(Text.color("&cYou must click on a block."));
|
||||
return;
|
||||
}
|
||||
final Minion minion = this.linkingMap.get(e.getPlayer());
|
||||
final Block block = e.getClickedBlock();
|
||||
if (minion.getLinkedBlocks().contains(block)) {
|
||||
minion.getLinkedBlocks().remove(block);
|
||||
e.getPlayer().sendMessage(Text.color("&aSuccessfully unlinked block."));
|
||||
} else {
|
||||
minion.getLinkedBlocks().add(block);
|
||||
e.getPlayer().sendMessage(Text.color("&aSuccessfully linked block."));
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
package me.loganb1max.minionsplus.menu;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Fuel;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.ItemBuilder;
|
||||
import me.loganb1max.minionsplus.util.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MinionMenu implements Listener {
|
||||
|
||||
private final Minion minion;
|
||||
private final Player player;
|
||||
private final Inventory inventory;
|
||||
private final Map<Integer, Consumer<ClickType>> clickHandlerMap = new HashMap<>();
|
||||
|
||||
public MinionMenu(final Minion minion, final Player player) {
|
||||
this.minion = minion;
|
||||
this.player = player;
|
||||
Bukkit.getPluginManager().registerEvents(this, MinionsPlus.getInstance());
|
||||
this.inventory = Bukkit.createInventory(this.player, 9, "Minion Menu");
|
||||
rebind();
|
||||
this.player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
public void rebind() {
|
||||
bindItem(
|
||||
minion.getIcon(),
|
||||
1,
|
||||
clickType -> { }
|
||||
);
|
||||
|
||||
bindItem(
|
||||
ItemBuilder.of(Material.GOLD_INGOT)
|
||||
.name("&6Upgrade")
|
||||
.lore("&7Click to upgrade this minion.")
|
||||
.lore("")
|
||||
.lore(this.minion.isMaxLevel() ? "&aMax Level" : "&7Price: &f$" + this.minion.getPrice(minion.getLevel() + 1))
|
||||
.build(),
|
||||
3,
|
||||
clickType -> {
|
||||
if (this.minion.isMaxLevel()) {
|
||||
this.player.sendMessage(Text.color("&cThis minion is already max level."));
|
||||
return;
|
||||
}
|
||||
if (!MinionsPlus.getEcon().withdrawPlayer(this.player, this.minion.getPrice(this.minion.getLevel() + 1)).transactionSuccess()) {
|
||||
this.player.sendMessage(Text.color("&cYou can not afford this upgrade!"));
|
||||
return;
|
||||
}
|
||||
this.minion.levelUp();
|
||||
this.player.sendMessage(Text.color("&aYou have successfully upgraded this minion."));
|
||||
rebind();
|
||||
}
|
||||
);
|
||||
|
||||
bindItem(
|
||||
ItemBuilder.of(Material.COAL)
|
||||
.name("&6Deposit Energy")
|
||||
.lore(MinionsPlus.getInstance().getFuels().stream().map(Fuel::getDisplayString).collect(Collectors.toList()))
|
||||
.build(),
|
||||
5,
|
||||
clickType -> {
|
||||
double totalGained = 0.0;
|
||||
Set<Fuel> fuels = MinionsPlus.getInstance().getFuels();
|
||||
for (int i = 0; i < this.player.getInventory().getSize(); i++) {
|
||||
final ItemStack item = this.player.getInventory().getItem(i);
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
for (Fuel fuel : fuels) {
|
||||
if (!fuel.isEqual(item)) continue;
|
||||
this.minion.gainEnergy(item.getAmount() * fuel.getEnergy());
|
||||
totalGained += item.getAmount() * fuel.getEnergy();
|
||||
this.player.getInventory().setItem(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
this.player.sendMessage(Text.color("&aYou successfully refueled this minion. Added " + totalGained + " energy."));
|
||||
rebind();
|
||||
}
|
||||
);
|
||||
|
||||
bindItem(
|
||||
ItemBuilder.of(Material.CHEST)
|
||||
.name("&6Link Chest")
|
||||
.lore("&7Click to link a deposit chest.")
|
||||
.build(),
|
||||
7,
|
||||
clickType -> {
|
||||
MinionsPlus.getInstance().getLinkingManager().beginLinking(this.player, this.minion);
|
||||
this.player.closeInventory();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void bindItem(final ItemStack item, final int slot, final Consumer<ClickType> consumer) {
|
||||
this.inventory.setItem(slot, item);
|
||||
this.clickHandlerMap.remove(slot);
|
||||
this.clickHandlerMap.put(slot, consumer);
|
||||
this.player.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onClose(final InventoryCloseEvent e) {
|
||||
if (!e.getInventory().equals(this.inventory)) return;
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onClick(final InventoryClickEvent e) {
|
||||
if (e.getSlotType() == InventoryType.SlotType.OUTSIDE) return;
|
||||
if (!e.getClickedInventory().equals(this.inventory)) return;
|
||||
e.setCancelled(true);
|
||||
this.clickHandlerMap.get(e.getSlot()).accept(e.getClick());
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,26 @@
|
||||
package me.loganb1max.minions.model;
|
||||
package me.loganb1max.minionsplus.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.loganb1max.minions.util.ItemUtil;
|
||||
import lombok.Getter;
|
||||
import me.loganb1max.minionsplus.util.ItemUtil;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Fuel {
|
||||
|
||||
private final String name;
|
||||
@Getter private final String name;
|
||||
private final ItemStack itemStack;
|
||||
private final double energy;
|
||||
@Getter private final double energy;
|
||||
|
||||
public boolean isEqual(final ItemStack item) {
|
||||
return ItemUtil.compareType(this.itemStack, item);
|
||||
}
|
||||
|
||||
public String getDisplayString() {
|
||||
return "&7" + this.name + ": &f" + this.energy;
|
||||
}
|
||||
|
||||
public static Fuel fromConfigSection(final ConfigurationSection section) {
|
||||
final String name = section.getName();
|
||||
final double energy = section.getDouble("Energy");
|
@ -0,0 +1,104 @@
|
||||
package me.loganb1max.minionsplus.model.minions;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.ItemBuilder;
|
||||
import me.loganb1max.minionsplus.util.Replacer;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Crops;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FarmerMinion extends Minion {
|
||||
|
||||
public FarmerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Farmer"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
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 getSection().getInt("Levels." + level + ".Radius", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
||||
final int radius = getRadius(getLevel());
|
||||
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 block = getLocation().getWorld().getBlockAt(x, y, z);
|
||||
final List<ItemStack> drops = new ArrayList<>();
|
||||
if (block.getType() == Material.POTATO || block.getType() == Material.CARROT || block.getType() == Material.CROPS) {
|
||||
if (block.getData() != 7) continue;
|
||||
drops.add(ItemBuilder.of(
|
||||
block.getType() == Material.CARROT ? Material.CARROT_ITEM
|
||||
: block.getType() == Material.POTATO ? Material.POTATO_ITEM : Material.WHEAT
|
||||
).build());
|
||||
block.setData((byte)0);
|
||||
}
|
||||
if (block.getType() == Material.CACTUS || block.getType() == Material.SUGAR_CANE_BLOCK) {
|
||||
int height = 1;
|
||||
final Material type = block.getType();
|
||||
Block rel = block;
|
||||
while (rel.getRelative(BlockFace.DOWN).getType() == block.getType()) {
|
||||
height++;
|
||||
rel.setType(Material.AIR);
|
||||
rel = rel.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
if (height > 1) {
|
||||
drops.add(ItemBuilder.of(type).amount(height - 1).build());
|
||||
}
|
||||
}
|
||||
if (block.getType() == Material.MELON_BLOCK) {
|
||||
drops.addAll(block.getDrops());
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
if (block.getType() == Material.PUMPKIN) {
|
||||
drops.addAll(block.getDrops());
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
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(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
return Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", String.valueOf(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%radius%", String.valueOf(getRadius(getLevel())));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package me.loganb1max.minionsplus.model.minions;
|
||||
|
||||
import me.loganb1max.minionsplus.MinionsPlus;
|
||||
import me.loganb1max.minionsplus.model.Minion;
|
||||
import me.loganb1max.minionsplus.util.ItemBuilder;
|
||||
import me.loganb1max.minionsplus.util.Replacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class FisherMinion extends Minion {
|
||||
|
||||
public FisherMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Fisher"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
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 getSection().getDouble("Levels." + level + ".ChancePerBlockPerSecond", 0.0);
|
||||
}
|
||||
|
||||
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());
|
||||
final List<ItemStack> drops = new ArrayList<>();
|
||||
for (int x = getLocation().getBlockX() - radius; x < getLocation().getBlockX() + radius; x++) {
|
||||
for (int y = getLocation().getBlockY() - radius; y < getLocation().getBlockY() + radius; y++) {
|
||||
for (int z = getLocation().getBlockZ() - radius; z < getLocation().getBlockZ() + radius; z++) {
|
||||
final Block block = getLocation().getWorld().getBlockAt(x, y, z);
|
||||
if (block.getType() != Material.WATER && block.getType() != Material.STATIONARY_WATER) continue;
|
||||
if (ThreadLocalRandom.current().nextDouble(0.000000, 100.000000) > getChancePerBlockPerSecond(getLevel())) continue;
|
||||
drops.add(ItemBuilder.of(Material.RAW_FISH).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
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(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
||||
}
|
||||
consumeEnergy(getEnergyPerUse(getLevel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
return 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())));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
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.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MinerMinion extends Minion {
|
||||
|
||||
private static Set<Material> VALID_BLOCKS = new HashSet<>();
|
||||
|
||||
static {
|
||||
VALID_BLOCKS.add(Material.STONE);
|
||||
VALID_BLOCKS.add(Material.COBBLESTONE);
|
||||
for (Material mat : Material.values()) {
|
||||
if (!mat.name().toLowerCase().contains("ore")) continue;
|
||||
VALID_BLOCKS.add(mat);
|
||||
}
|
||||
}
|
||||
|
||||
public MinerMinion(final UUID owner, final String ownerName) {
|
||||
super(
|
||||
MinionsPlus.getInstance().getConfig().getConfigurationSection("Miner"),
|
||||
owner,
|
||||
ownerName
|
||||
);
|
||||
}
|
||||
|
||||
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 getSection().getInt("Levels." + level + ".BlockLimit", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
||||
getLinkedBlocks().stream().filter(block -> !(block.getState() instanceof InventoryHolder)).filter(block -> VALID_BLOCKS.contains(block.getType())).limit(getBlockLimit(getLevel())).forEachOrdered(block -> {
|
||||
final Collection<ItemStack> drops = block.getDrops();
|
||||
block.setType(Material.AIR);
|
||||
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(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
||||
}
|
||||
});
|
||||
consumeEnergy(getEnergyPerUse(getLevel()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Replacer getReplacer() {
|
||||
return Replacer.create()
|
||||
.add("%level%", String.valueOf(getLevel()))
|
||||
.add("%energy%", String.valueOf(getEnergy()))
|
||||
.add("%owner%", getOwnerName())
|
||||
.add("%blocklimit%", String.valueOf(getBlockLimit(getLevel())));
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.loganb1max.minions.util;
|
||||
package me.loganb1max.minionsplus.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
@ -1,4 +1,4 @@
|
||||
package me.loganb1max.minions.util;
|
||||
package me.loganb1max.minionsplus.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
@ -1,4 +1,4 @@
|
||||
package me.loganb1max.minions.util;
|
||||
package me.loganb1max.minionsplus.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
@ -1,4 +1,4 @@
|
||||
package me.loganb1max.minions.util;
|
||||
package me.loganb1max.minionsplus.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
Loading…
Reference in New Issue