Changes and Fixes

master
loganb1max 2019-06-25 11:16:30 +07:00
parent c051cf2714
commit e6961b3c0e
7 changed files with 46 additions and 12 deletions

@ -66,6 +66,7 @@ public class LinkingManager implements Listener {
minion.getLinkedBlocks().add(block); minion.getLinkedBlocks().add(block);
e.getPlayer().sendMessage(Text.color("&aSuccessfully linked block.")); e.getPlayer().sendMessage(Text.color("&aSuccessfully linked block."));
} }
endLinking(e.getPlayer());
e.setCancelled(true); e.setCancelled(true);
} }

@ -40,7 +40,8 @@ public class MinionManager implements Listener {
public MinionManager(final MinionsPlus plugin) { public MinionManager(final MinionsPlus plugin) {
this.plugin = plugin; this.plugin = plugin;
this.animationTask = Bukkit.getScheduler().runTaskTimer(this.plugin, () -> this.minions.forEach(Minion::animationTick), 1, 1); 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); Bukkit.getPluginManager().registerEvents(this, this.plugin);
loadMinions(); 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 Location loc = e.getClickedBlock().getRelative(e.getBlockFace()).getLocation().add(0.5, 0, 0.5);
final Minion minion = Minion.of(e.getItem(), loc); final Minion minion = Minion.of(e.getItem(), loc);
minion.spawn(loc); minion.spawn(loc);
if (minion instanceof MinerMinion) {
this.plugin.getLinkingManager().beginLinking(e.getPlayer(), minion);
}
ItemUtil.consumeItem(e.getPlayer().getInventory(), 1, e.getItem()); ItemUtil.consumeItem(e.getPlayer().getInventory(), 1, e.getItem());
} }

@ -20,6 +20,8 @@ import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.*; import java.util.*;
@Getter @Getter
@ -84,7 +86,9 @@ public abstract class Minion {
if (this.stand == null) return; if (this.stand == null) return;
if (this.stand.getRightArmPose().getX() < 5) offset = 0.1; if (this.stand.getRightArmPose().getX() < 5) offset = 0.1;
if (this.stand.getRightArmPose().getX() > 6) 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); this.stand.setFireTicks(0);
} }

@ -13,6 +13,7 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Crops; import org.bukkit.material.Crops;
import java.text.DecimalFormat;
import java.util.*; import java.util.*;
public class FarmerMinion extends Minion { public class FarmerMinion extends Minion {
@ -77,6 +78,8 @@ public class FarmerMinion extends Minion {
block.setType(Material.AIR); block.setType(Material.AIR);
} }
if (!drops.isEmpty()) consumeEnergy(getEnergyPerUse(getLevel()));
getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> { getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> {
InventoryHolder inv = (InventoryHolder) b.getState(); InventoryHolder inv = (InventoryHolder) b.getState();
final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values(); final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values();
@ -94,9 +97,10 @@ public class FarmerMinion extends Minion {
@Override @Override
public Replacer getReplacer() { public Replacer getReplacer() {
final DecimalFormat format = new DecimalFormat("#.#");
return Replacer.create() return Replacer.create()
.add("%level%", String.valueOf(getLevel())) .add("%level%", String.valueOf(getLevel()))
.add("%energy%", String.valueOf(getEnergy())) .add("%energy%", format.format(getEnergy()))
.add("%owner%", getOwnerName()) .add("%owner%", getOwnerName())
.add("%radius%", String.valueOf(getRadius(getLevel()))); .add("%radius%", String.valueOf(getRadius(getLevel())));
} }

@ -10,6 +10,7 @@ import org.bukkit.block.Block;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadLocalRandom; 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 -> { getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> {
InventoryHolder inv = (InventoryHolder) b.getState(); InventoryHolder inv = (InventoryHolder) b.getState();
final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values(); final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values();
@ -64,14 +66,14 @@ public class FisherMinion extends Minion {
if (!drops.isEmpty()) { if (!drops.isEmpty()) {
drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item)); drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
} }
consumeEnergy(getEnergyPerUse(getLevel()));
} }
@Override @Override
public Replacer getReplacer() { public Replacer getReplacer() {
final DecimalFormat format = new DecimalFormat("#.#");
return Replacer.create() return Replacer.create()
.add("%level%", String.valueOf(getLevel())) .add("%level%", String.valueOf(getLevel()))
.add("%energy%", String.valueOf(getEnergy())) .add("%energy%", format.format(getEnergy()))
.add("%owner%", getOwnerName()) .add("%owner%", getOwnerName())
.add("%radius%", String.valueOf(getRadius(getLevel()))) .add("%radius%", String.valueOf(getRadius(getLevel())))
.add("%chanceperblockpersecond%", String.valueOf(getChancePerBlockPerSecond(getLevel()))); .add("%chanceperblockpersecond%", String.valueOf(getChancePerBlockPerSecond(getLevel())));

@ -6,9 +6,11 @@ import me.loganb1max.minionsplus.util.Replacer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.*; import java.util.*;
public class MinerMinion extends Minion { public class MinerMinion extends Minion {
@ -48,7 +50,27 @@ public class MinerMinion extends Minion {
@Override @Override
public void tick() { public void tick() {
if (getEnergy() < getEnergyPerUse(getLevel())) return; 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<ItemStack> 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<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));
}
break;
}
/*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(); final Collection<ItemStack> drops = block.getDrops();
block.setType(Material.AIR); block.setType(Material.AIR);
getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> { getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> {
@ -60,15 +82,15 @@ public class MinerMinion extends Minion {
if (!drops.isEmpty()) { if (!drops.isEmpty()) {
drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item)); drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
} }
}); });*/
consumeEnergy(getEnergyPerUse(getLevel()));
} }
@Override @Override
public Replacer getReplacer() { public Replacer getReplacer() {
final DecimalFormat format = new DecimalFormat("#.#");
return Replacer.create() return Replacer.create()
.add("%level%", String.valueOf(getLevel())) .add("%level%", String.valueOf(getLevel()))
.add("%energy%", String.valueOf(getEnergy())) .add("%energy%", format.format(getEnergy()))
.add("%owner%", getOwnerName()) .add("%owner%", getOwnerName())
.add("%blocklimit%", String.valueOf(getBlockLimit(getLevel()))); .add("%blocklimit%", String.valueOf(getBlockLimit(getLevel())));
} }

@ -2,6 +2,9 @@
###################### Minions ############################# ###################### Minions #############################
############################################################################ ############################################################################
#This is in ticks (20 ticks / second)
Action-Speed: 20
Fuel: Fuel:
Coal: Coal: