mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-22 19:11:23 +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);
|
playerDrop = new PlayerDrop(this);
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("RoseStacker")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("RoseStacker")) {
|
||||||
logger.info("RoseStacker has been detected, adding support!");
|
logger.info("RoseStacker has been detected, adding support!");
|
||||||
roseStacker = new RoseStacker();
|
roseStacker = new RoseStacker(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(blockBreak, 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
|
// this is delayed because entities are not loaded instantly
|
||||||
// we just check 1 second later
|
// we just check 1 second later
|
||||||
Chunk chunk = event.getChunk();
|
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()) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
// if there is a new item frame
|
// if there is a new item frame
|
||||||
if (!(entity instanceof ItemFrame itemFrame)) {
|
if (!(entity instanceof ItemFrame itemFrame)) {
|
||||||
|
|||||||
@@ -259,12 +259,22 @@ public class EntityDamage implements Listener {
|
|||||||
|
|
||||||
if (type.equalsIgnoreCase("mob")) {
|
if (type.equalsIgnoreCase("mob")) {
|
||||||
// player is shooting a mob
|
// player is shooting a mob
|
||||||
ItemMeta newBow;
|
|
||||||
int count = 1;
|
|
||||||
if (toolStats.roseStacker != null) {
|
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);
|
||||||
}
|
}
|
||||||
newBow = toolStats.itemLore.updateMobKills(heldBow, count);
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemMeta newBow = toolStats.itemLore.updateMobKills(heldBow, 1);
|
||||||
if (newBow != null) {
|
if (newBow != null) {
|
||||||
if (isMain && isOffHand) {
|
if (isMain && isOffHand) {
|
||||||
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
@@ -292,20 +302,31 @@ public class EntityDamage implements Listener {
|
|||||||
|
|
||||||
private void updateTridentKills(Trident trident, String type, LivingEntity entity) {
|
private void updateTridentKills(Trident trident, String type, LivingEntity entity) {
|
||||||
ItemStack newTrident = trident.getItemStack();
|
ItemStack newTrident = trident.getItemStack();
|
||||||
ItemMeta newTridentMeta;
|
|
||||||
if (type.equalsIgnoreCase("player")) {
|
if (type.equalsIgnoreCase("player")) {
|
||||||
newTridentMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
ItemMeta newTridentMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||||
} else {
|
|
||||||
int count = 1;
|
|
||||||
if (toolStats.roseStacker != null) {
|
|
||||||
count = toolStats.roseStacker.countMobs(entity);
|
|
||||||
}
|
|
||||||
newTridentMeta = toolStats.itemLore.updateMobKills(newTrident, count);
|
|
||||||
}
|
|
||||||
if (newTridentMeta != null) {
|
if (newTridentMeta != null) {
|
||||||
newTrident.setItemMeta(newTridentMeta);
|
newTrident.setItemMeta(newTridentMeta);
|
||||||
trident.setItemStack(newTrident);
|
trident.setItemStack(newTrident);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTridentDamage(Trident trident, double damage) {
|
private void updateTridentDamage(Trident trident, double damage) {
|
||||||
@@ -327,27 +348,36 @@ public class EntityDamage implements Listener {
|
|||||||
|
|
||||||
private void updateWeaponKills(PlayerInventory playerInventory, String type, LivingEntity entity) {
|
private void updateWeaponKills(PlayerInventory playerInventory, String type, LivingEntity entity) {
|
||||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||||
ItemMeta newHeldWeaponMeta = null;
|
|
||||||
if (type.equalsIgnoreCase("player")) {
|
if (type.equalsIgnoreCase("player")) {
|
||||||
newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||||
}
|
|
||||||
if (type.equalsIgnoreCase("mob")) {
|
|
||||||
int count = 1;
|
|
||||||
if (toolStats.roseStacker != null) {
|
|
||||||
count = toolStats.roseStacker.countMobs(entity);
|
|
||||||
}
|
|
||||||
newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, count);
|
|
||||||
}
|
|
||||||
if (newHeldWeaponMeta != null) {
|
if (newHeldWeaponMeta != null) {
|
||||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type.equalsIgnoreCase("mob")) {
|
||||||
|
if (toolStats.roseStacker != null) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBossesKilled(PlayerInventory playerInventory, String boss, LivingEntity entity) {
|
private void updateBossesKilled(PlayerInventory playerInventory, String boss, LivingEntity entity) {
|
||||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||||
int count = 1;
|
int count = 1;
|
||||||
if (toolStats.roseStacker != null) {
|
if (toolStats.roseStacker != null) {
|
||||||
count = toolStats.roseStacker.countMobs(entity);
|
//count = toolStats.roseStacker.countMobs(entity);
|
||||||
}
|
}
|
||||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldWeapon, count, boss);
|
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldWeapon, count, boss);
|
||||||
if (newHeldWeaponMeta != null) {
|
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 isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||||
|
|
||||||
int count = 1;
|
|
||||||
if (toolStats.roseStacker != null) {
|
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 (newHeldWeaponMeta != null) {
|
||||||
if (isMain && isOffHand) {
|
if (isMain && isOffHand) {
|
||||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||||
|
|||||||
@@ -36,32 +36,61 @@ package lol.hyper.toolstats.support.rosestacker;
|
|||||||
|
|
||||||
import dev.rosewood.rosestacker.api.RoseStackerAPI;
|
import dev.rosewood.rosestacker.api.RoseStackerAPI;
|
||||||
import dev.rosewood.rosestacker.stack.StackedEntity;
|
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 org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class RoseStacker {
|
public class RoseStacker {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
private final RoseStackerAPI rsAPI;
|
private final RoseStackerAPI rsAPI;
|
||||||
|
|
||||||
public RoseStacker() {
|
public RoseStacker(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
this.rsAPI = RoseStackerAPI.getInstance();
|
this.rsAPI = RoseStackerAPI.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int countMobs(LivingEntity entity) {
|
public void countMobs(LivingEntity entity, Consumer<Integer> callback) {
|
||||||
if (!rsAPI.isEntityStacked(entity)) {
|
if (!rsAPI.isEntityStacked(entity)) {
|
||||||
// if the entity is not stacked, ignore
|
// if the entity is not stacked, ignore
|
||||||
return 1;
|
callback.accept(1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
StackedEntity stackedEntity = rsAPI.getStackedEntity(entity);
|
StackedEntity stackedEntity = rsAPI.getStackedEntity(entity);
|
||||||
if (stackedEntity == null) {
|
if (stackedEntity == null) {
|
||||||
return 1;
|
callback.accept(1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int before = stackedEntity.getStackSize();
|
||||||
boolean killAll = stackedEntity.getStackSettings().shouldKillEntireStackOnDeath();
|
boolean killAll = stackedEntity.getStackSettings().shouldKillEntireStackOnDeath();
|
||||||
// if we kill the entire stack, add the entire stack to the count
|
// if we kill the entire stack, add the entire stack to the count
|
||||||
if (killAll) {
|
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