From e6961b3c0ec2828161e737dc11fe42f53ee8a23a Mon Sep 17 00:00:00 2001 From: loganb1max Date: Tue, 25 Jun 2019 11:16:30 -0500 Subject: [PATCH] Changes and Fixes --- .../minionsplus/manager/LinkingManager.java | 1 + .../minionsplus/manager/MinionManager.java | 6 ++-- .../loganb1max/minionsplus/model/Minion.java | 6 +++- .../model/minions/FarmerMinion.java | 6 +++- .../model/minions/FisherMinion.java | 6 ++-- .../model/minions/MinerMinion.java | 30 ++++++++++++++++--- src/main/resources/config.yml | 3 ++ 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/loganb1max/minionsplus/manager/LinkingManager.java b/src/main/java/me/loganb1max/minionsplus/manager/LinkingManager.java index 247dc33..5caaa28 100644 --- a/src/main/java/me/loganb1max/minionsplus/manager/LinkingManager.java +++ b/src/main/java/me/loganb1max/minionsplus/manager/LinkingManager.java @@ -66,6 +66,7 @@ public class LinkingManager implements Listener { minion.getLinkedBlocks().add(block); e.getPlayer().sendMessage(Text.color("&aSuccessfully linked block.")); } + endLinking(e.getPlayer()); e.setCancelled(true); } diff --git a/src/main/java/me/loganb1max/minionsplus/manager/MinionManager.java b/src/main/java/me/loganb1max/minionsplus/manager/MinionManager.java index c6fa2e6..e96b211 100644 --- a/src/main/java/me/loganb1max/minionsplus/manager/MinionManager.java +++ b/src/main/java/me/loganb1max/minionsplus/manager/MinionManager.java @@ -40,7 +40,8 @@ public class MinionManager implements Listener { public MinionManager(final MinionsPlus plugin) { this.plugin = plugin; this.animationTask = Bukkit.getScheduler().runTaskTimer(this.plugin, () -> this.minions.forEach(Minion::animationTick), 1, 1); - this.tickTask = Bukkit.getScheduler().runTaskTimer(this.plugin, () -> this.minions.forEach(Minion::tick), 20, 20); + final int actionSpeed = this.plugin.getConfig().getInt("Action-Speed", 20); + this.tickTask = Bukkit.getScheduler().runTaskTimer(this.plugin, () -> this.minions.forEach(Minion::tick), actionSpeed, actionSpeed); Bukkit.getPluginManager().registerEvents(this, this.plugin); loadMinions(); } @@ -128,9 +129,6 @@ public class MinionManager implements Listener { final Location loc = e.getClickedBlock().getRelative(e.getBlockFace()).getLocation().add(0.5, 0, 0.5); final Minion minion = Minion.of(e.getItem(), loc); minion.spawn(loc); - if (minion instanceof MinerMinion) { - this.plugin.getLinkingManager().beginLinking(e.getPlayer(), minion); - } ItemUtil.consumeItem(e.getPlayer().getInventory(), 1, e.getItem()); } diff --git a/src/main/java/me/loganb1max/minionsplus/model/Minion.java b/src/main/java/me/loganb1max/minionsplus/model/Minion.java index 9c8c316..33ad370 100644 --- a/src/main/java/me/loganb1max/minionsplus/model/Minion.java +++ b/src/main/java/me/loganb1max/minionsplus/model/Minion.java @@ -20,6 +20,8 @@ import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; + +import java.text.DecimalFormat; import java.util.*; @Getter @@ -84,7 +86,9 @@ public abstract class Minion { if (this.stand == null) return; if (this.stand.getRightArmPose().getX() < 5) offset = 0.1; if (this.stand.getRightArmPose().getX() > 6) offset = -0.1; - this.stand.setRightArmPose(this.stand.getRightArmPose().add(offset, 0, 0)); + if (this.energy > 0) this.stand.setRightArmPose(this.stand.getRightArmPose().add(offset, 0, 0)); + final DecimalFormat format = new DecimalFormat("#.#"); + this.stand.setCustomName(Text.color(getName() + " &8[&f" + format.format(getEnergy()) + "&8]")); this.stand.setFireTicks(0); } diff --git a/src/main/java/me/loganb1max/minionsplus/model/minions/FarmerMinion.java b/src/main/java/me/loganb1max/minionsplus/model/minions/FarmerMinion.java index 194667d..804d7a3 100644 --- a/src/main/java/me/loganb1max/minionsplus/model/minions/FarmerMinion.java +++ b/src/main/java/me/loganb1max/minionsplus/model/minions/FarmerMinion.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Crops; +import java.text.DecimalFormat; import java.util.*; public class FarmerMinion extends Minion { @@ -77,6 +78,8 @@ public class FarmerMinion extends Minion { block.setType(Material.AIR); } + if (!drops.isEmpty()) consumeEnergy(getEnergyPerUse(getLevel())); + getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> { InventoryHolder inv = (InventoryHolder) b.getState(); final Collection remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values(); @@ -94,9 +97,10 @@ public class FarmerMinion extends Minion { @Override public Replacer getReplacer() { + final DecimalFormat format = new DecimalFormat("#.#"); return Replacer.create() .add("%level%", String.valueOf(getLevel())) - .add("%energy%", String.valueOf(getEnergy())) + .add("%energy%", format.format(getEnergy())) .add("%owner%", getOwnerName()) .add("%radius%", String.valueOf(getRadius(getLevel()))); } diff --git a/src/main/java/me/loganb1max/minionsplus/model/minions/FisherMinion.java b/src/main/java/me/loganb1max/minionsplus/model/minions/FisherMinion.java index 4de14be..927d13a 100644 --- a/src/main/java/me/loganb1max/minionsplus/model/minions/FisherMinion.java +++ b/src/main/java/me/loganb1max/minionsplus/model/minions/FisherMinion.java @@ -10,6 +10,7 @@ import org.bukkit.block.Block; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.ThreadLocalRandom; @@ -55,6 +56,7 @@ public class FisherMinion extends Minion { } } } + if (!drops.isEmpty()) consumeEnergy(getEnergyPerUse(getLevel())); getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> { InventoryHolder inv = (InventoryHolder) b.getState(); final Collection remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values(); @@ -64,14 +66,14 @@ public class FisherMinion extends Minion { if (!drops.isEmpty()) { drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item)); } - consumeEnergy(getEnergyPerUse(getLevel())); } @Override public Replacer getReplacer() { + final DecimalFormat format = new DecimalFormat("#.#"); return Replacer.create() .add("%level%", String.valueOf(getLevel())) - .add("%energy%", String.valueOf(getEnergy())) + .add("%energy%", format.format(getEnergy())) .add("%owner%", getOwnerName()) .add("%radius%", String.valueOf(getRadius(getLevel()))) .add("%chanceperblockpersecond%", String.valueOf(getChancePerBlockPerSecond(getLevel()))); diff --git a/src/main/java/me/loganb1max/minionsplus/model/minions/MinerMinion.java b/src/main/java/me/loganb1max/minionsplus/model/minions/MinerMinion.java index ac600fc..ad399cb 100644 --- a/src/main/java/me/loganb1max/minionsplus/model/minions/MinerMinion.java +++ b/src/main/java/me/loganb1max/minionsplus/model/minions/MinerMinion.java @@ -6,9 +6,11 @@ import me.loganb1max.minionsplus.util.Replacer; 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 java.text.DecimalFormat; import java.util.*; public class MinerMinion extends Minion { @@ -48,7 +50,27 @@ public class MinerMinion extends Minion { @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 -> { + Block block = getLocation().getBlock(); + for (BlockFace direction: new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) { + if (!VALID_BLOCKS.contains(block.getRelative(direction).getType())) continue; + block = block.getRelative(direction); + final Collection drops = block.getDrops(); + block.setType(Material.AIR); + + if (!drops.isEmpty()) consumeEnergy(getEnergyPerUse(getLevel())); + + getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> { + InventoryHolder inv = (InventoryHolder) b.getState(); + final Collection 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)); + } + break; + } + /*getLinkedBlocks().stream().filter(block -> !(block.getState() instanceof InventoryHolder)).filter(block -> VALID_BLOCKS.contains(block.getType())).limit(getBlockLimit(getLevel())).forEachOrdered(block -> { final Collection drops = block.getDrops(); block.setType(Material.AIR); getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> { @@ -60,15 +82,15 @@ public class MinerMinion extends Minion { if (!drops.isEmpty()) { drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item)); } - }); - consumeEnergy(getEnergyPerUse(getLevel())); + });*/ } @Override public Replacer getReplacer() { + final DecimalFormat format = new DecimalFormat("#.#"); return Replacer.create() .add("%level%", String.valueOf(getLevel())) - .add("%energy%", String.valueOf(getEnergy())) + .add("%energy%", format.format(getEnergy())) .add("%owner%", getOwnerName()) .add("%blocklimit%", String.valueOf(getBlockLimit(getLevel()))); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 91c21fa..34915ab 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,6 +2,9 @@ ###################### Minions ############################# ############################################################################ +#This is in ticks (20 ticks / second) +Action-Speed: 20 + Fuel: Coal: