mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-23 03:21:22 +00:00
RS multikill support
still experimental
This commit is contained in:
@@ -132,7 +132,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
playerDrop = new PlayerDrop(this);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("RoseStacker")) {
|
||||
logger.info("RoseStacker has been detected, adding support!");
|
||||
roseStacker = new RoseStacker();
|
||||
roseStacker = new RoseStacker(this);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockBreak, this);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ChunkPopulate implements Listener {
|
||||
// this is delayed because entities are not loaded instantly
|
||||
// we just check 1 second later
|
||||
Chunk chunk = event.getChunk();
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), scheduledTask -> {
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), _ -> {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (!(entity instanceof ItemFrame itemFrame)) {
|
||||
|
||||
@@ -259,12 +259,22 @@ public class EntityDamage implements Listener {
|
||||
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
// player is shooting a mob
|
||||
ItemMeta newBow;
|
||||
int count = 1;
|
||||
if (toolStats.roseStacker != null) {
|
||||
count = toolStats.roseStacker.countMobs(entity);
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemMeta newBow = toolStats.itemLore.updateMobKills(heldBow, count);
|
||||
if (newBow != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||
} else if (isMain) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||
} else if (isOffHand) {
|
||||
playerInventory.getItemInOffHand().setItemMeta(newBow);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
newBow = toolStats.itemLore.updateMobKills(heldBow, count);
|
||||
ItemMeta newBow = toolStats.itemLore.updateMobKills(heldBow, 1);
|
||||
if (newBow != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||
@@ -292,19 +302,30 @@ public class EntityDamage implements Listener {
|
||||
|
||||
private void updateTridentKills(Trident trident, String type, LivingEntity entity) {
|
||||
ItemStack newTrident = trident.getItemStack();
|
||||
ItemMeta newTridentMeta;
|
||||
if (type.equalsIgnoreCase("player")) {
|
||||
newTridentMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||
} else {
|
||||
int count = 1;
|
||||
if (toolStats.roseStacker != null) {
|
||||
count = toolStats.roseStacker.countMobs(entity);
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
newTridentMeta = toolStats.itemLore.updateMobKills(newTrident, count);
|
||||
return;
|
||||
}
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
if (toolStats.roseStacker != null) {
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updateMobKills(newTrident, count);
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,19 +348,28 @@ public class EntityDamage implements Listener {
|
||||
|
||||
private void updateWeaponKills(PlayerInventory playerInventory, String type, LivingEntity entity) {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = null;
|
||||
if (type.equalsIgnoreCase("player")) {
|
||||
newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
int count = 1;
|
||||
if (toolStats.roseStacker != null) {
|
||||
count = toolStats.roseStacker.countMobs(entity);
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemStack currentHeldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateMobKills(currentHeldWeapon, count);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
currentHeldWeapon.setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, 1);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, count);
|
||||
}
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,7 +377,7 @@ public class EntityDamage implements Listener {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
int count = 1;
|
||||
if (toolStats.roseStacker != null) {
|
||||
count = toolStats.roseStacker.countMobs(entity);
|
||||
//count = toolStats.roseStacker.countMobs(entity);
|
||||
}
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldWeapon, count, boss);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
@@ -364,12 +394,23 @@ public class EntityDamage implements Listener {
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||
|
||||
int count = 1;
|
||||
if (toolStats.roseStacker != null) {
|
||||
count = toolStats.roseStacker.countMobs(entity);
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldBow, count, boss);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
} else if (isMain) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
} else if (isOffHand) {
|
||||
playerInventory.getItemInOffHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldBow, count, boss);
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldBow, 1, boss);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
|
||||
@@ -36,32 +36,61 @@ package lol.hyper.toolstats.support.rosestacker;
|
||||
|
||||
import dev.rosewood.rosestacker.api.RoseStackerAPI;
|
||||
import dev.rosewood.rosestacker.stack.StackedEntity;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RoseStacker {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final RoseStackerAPI rsAPI;
|
||||
|
||||
public RoseStacker() {
|
||||
public RoseStacker(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
this.rsAPI = RoseStackerAPI.getInstance();
|
||||
}
|
||||
|
||||
public int countMobs(LivingEntity entity) {
|
||||
public void countMobs(LivingEntity entity, Consumer<Integer> callback) {
|
||||
if (!rsAPI.isEntityStacked(entity)) {
|
||||
// if the entity is not stacked, ignore
|
||||
return 1;
|
||||
callback.accept(1);
|
||||
return;
|
||||
}
|
||||
StackedEntity stackedEntity = rsAPI.getStackedEntity(entity);
|
||||
if (stackedEntity == null) {
|
||||
return 1;
|
||||
callback.accept(1);
|
||||
return;
|
||||
}
|
||||
|
||||
int before = stackedEntity.getStackSize();
|
||||
boolean killAll = stackedEntity.getStackSettings().shouldKillEntireStackOnDeath();
|
||||
// if we kill the entire stack, add the entire stack to the count
|
||||
if (killAll) {
|
||||
return stackedEntity.getStackSize();
|
||||
callback.accept(before);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
Location stackedLocation = stackedEntity.getLocation();
|
||||
Chunk stackedChunk = stackedEntity.getLocation().getChunk();
|
||||
// check the stack size after a tick to see the difference
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, stackedLocation.getWorld(), stackedChunk.getX(), stackedChunk.getZ(), _ -> {
|
||||
int after = stackedEntity.getStackSize();
|
||||
int difference = before - after;
|
||||
// if the diff goes negative, we killed more than the stack
|
||||
// we killed the entire stack, so return the size
|
||||
if (difference <= 0) {
|
||||
difference = before;
|
||||
}
|
||||
|
||||
toolStats.logger.info("before: {}", before);
|
||||
toolStats.logger.info("after: {}", after);
|
||||
toolStats.logger.info("difference: {}", difference);
|
||||
|
||||
callback.accept(difference);
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user