directional minions

master
Hamza Ali 2020-06-26 09:39:04 +07:00
parent ff5a40ba4d
commit 76d14c66f8
7 changed files with 102 additions and 46 deletions

@ -1,6 +1,7 @@
plugins {
id 'java'
id 'maven'
id 'com.github.johnrengelman.shadow' version '4.0.4'
}
group 'me.loganb1max'
@ -25,8 +26,8 @@ repositories {
dependencies {
compileOnly(files('libs/paper-server-1.8.8-R0.1.jar'))
compile('org.projectlombok:lombok:1.16.20')
annotationProcessor('org.projectlombok:lombok:1.16.20')
compile('org.projectlombok:lombok:1.18.12')
annotationProcessor('org.projectlombok:lombok:1.18.12')
compileOnly('com.github.MilkBowl:VaultAPI:1.7') {
exclude group: 'org.bukkit'
exclude group: 'org.spigot'

@ -1,5 +1,6 @@
#Fri Apr 17 13:30:53 ICT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

@ -24,6 +24,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@ -37,11 +38,13 @@ public class MinionManager implements Listener {
private final MinionsPlus plugin;
private final BukkitTask animationTask;
private final BukkitTask tickTask;
@Getter private final Map<LivingEntity, ButcherMinion> butcherKillMap = new HashMap<>();
@Getter
private final Map<LivingEntity, ButcherMinion> butcherKillMap = new HashMap<>();
@Getter private Set<Minion> minions = new HashSet<>();
@Getter
private Set<Minion> minions = new HashSet<>();
public MinionManager(final MinionsPlus plugin) {
public MinionManager(MinionsPlus plugin) {
this.plugin = plugin;
this.animationTask = Bukkit.getScheduler().runTaskTimer(this.plugin, () -> this.minions.forEach(Minion::animationTick), 1, 1);
final int actionSpeed = this.plugin.getConfig().getInt("Action-Speed", 20);
@ -104,14 +107,20 @@ public class MinionManager implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(final EntityDamageEvent e) {
if (!(e.getEntity() instanceof ArmorStand)) return;
if (this.minions.stream().map(Minion::getId).filter(Objects::nonNull).anyMatch(uuid -> uuid.equals(e.getEntity().getUniqueId()))) {
if (this.minions.stream()
.map(Minion::getId)
.filter(Objects::nonNull)
.anyMatch(uuid -> uuid.equals(e.getEntity().getUniqueId()))) {
e.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onRightClick(final PlayerArmorStandManipulateEvent e) {
this.minions.stream().filter(minion -> minion.getId() != null).filter(minion -> minion.getId().equals(e.getRightClicked().getUniqueId())).findFirst().ifPresent(minion -> {
this.minions.stream()
.filter(minion -> minion.getId() != null)
.filter(minion -> minion.getId().equals(e.getRightClicked().getUniqueId()))
.findFirst().ifPresent(minion -> {
e.setCancelled(true);
if (!minion.getOwner().equals(e.getPlayer().getUniqueId())) {
e.getPlayer().sendMessage(Text.color("&cOnly the owner of the minion can interact with it."));
@ -125,7 +134,7 @@ public class MinionManager implements Listener {
});
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOWEST)
public void onPlace(PlayerInteractEvent e) {
if (!e.hasItem() || !Minion.isMinion(e.getItem())) return;
e.setCancelled(true);
@ -143,7 +152,7 @@ public class MinionManager implements Listener {
final List<ItemStack> drops = e.getDrops();
minion.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();
final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[]{})).values();
drops.clear();
drops.addAll(remaining);
});

@ -89,7 +89,9 @@ public class MinionMenu implements Listener {
this.player.getInventory().setItem(i, new ItemStack(Material.AIR));
}
}
this.player.sendMessage(Text.color("&aYou successfully refueled this minion. Added " + totalGained + " energy."));
if (totalGained != 0)
this.player.sendMessage(Text.color("&aYou successfully refueled this minion. Added " + totalGained + " energy."));
else this.player.sendMessage(Text.color("&cYou do not have any fuel!"));
rebind();
}
);
@ -123,7 +125,7 @@ public class MinionMenu implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onClick(final InventoryClickEvent e) {
if (e.getSlotType() == InventoryType.SlotType.OUTSIDE) return;
if (!e.getClickedInventory().equals(this.inventory)) return;
if (!e.getInventory().equals(this.inventory)) return;
e.setCancelled(true);
this.clickHandlerMap.get(e.getSlot()).accept(e.getClick());
}

@ -50,7 +50,7 @@ public class FisherMinion extends Minion {
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;
if (ThreadLocalRandom.current().nextDouble(0, 100) > getChancePerBlockPerSecond(getLevel())) continue;
drops.add(ItemBuilder.of(Material.RAW_FISH).build());
}
}

@ -1,14 +1,17 @@
package me.loganb1max.minionsplus.model.minions;
import lombok.val;
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.BlockFace;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.*;
@ -49,39 +52,80 @@ public class MinerMinion extends Minion {
@Override
public void tick() {
if (getEnergy() < getEnergyPerUse(getLevel())) return;
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()));
// 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();
// float pitch = 0;
// switch (direction) {
// case NORTH:
// pitch = 180;
// break;
// case SOUTH:
// pitch = 360;
// break;
// case EAST:
// pitch = 270;
// break;
// case WEST:
// pitch = 90;
// break;
// }
// val l = getStand().getLocation();
// l.setYaw(pitch);
// getStand().teleport(l);
// 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(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));
int radius = 1;
int y = getLocation().getBlockY();
for (int x = getLocation().getBlockX() - radius; x <= getLocation().getBlockX() + radius; x++) {
for (int z = getLocation().getBlockZ() - radius; z <= getLocation().getBlockZ() + radius; z++) {
Block blk = getLocation().getWorld().getBlockAt(x, y, z);
if (!VALID_BLOCKS.contains(blk.getType())) continue;
Location l = getStand().getLocation();
l.setYaw(getNewDirection(x - getLocation().getBlockX(), z - getLocation().getBlockZ()));
getStand().teleport(l);
final Collection<ItemStack> drops = blk.getDrops();
blk.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));
}
return;
}
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();
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));
}
});*/
}
private float getNewDirection(int x, int y) {
if (x == 1 && y == -1) return 225;
if (x == 1 && y == 0) return 270;
if (x == 1 && y == 1) return 315;
if (x == 0 && y == -1) return 180;
if (x == 0 && y == 1) return 0;
if (x == -1 && y == -1) return 135;
if (x == -1 && y == 0) return 90;
if (x == -1 && y == 1) return 45;
return 0;
}
@Override

@ -69,7 +69,6 @@ Miner:
'2':
Price: 1000.0
EnergyPerAction: 0.3
BlockLimit: 3
Farmer:
Name: "Farmer Minion"