fix nametag optimization still consuming item when consumption is disabled

fix datahandlers returning wrong values when checking for cooldown millis
remove unused dependency
This commit is contained in:
xGinko 2024-05-11 12:14:43 +02:00
parent 9525a2b3ba
commit 11ef3eedac
5 changed files with 13 additions and 17 deletions

12
pom.xml
View File

@ -122,25 +122,19 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
</dependency>
<!-- Needed to actually display colors in ComponentLogger -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-ansi</artifactId>
<version>4.16.0</version>
</dependency>
<!-- Adventure plaintext serializer for reading unstyled content of components -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-plain</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
</dependency>
<!-- Adventure ComponentLogger for colorful slf4j logging -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-logger-slf4j</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
</dependency>
<!-- Bukkit bStats -->
<dependency>

View File

@ -111,8 +111,8 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener {
if (!optimizeEvent.callEvent()) return;
if (!consume_nametag) {
event.setCancelled(true);
villager.customName(meta.displayName());
player.getInventory().addItem(usedItem.asOne());
player.updateInventory();
}
wVillager.setOptimizationType(optimizeEvent.getOptimizationType());

View File

@ -92,14 +92,13 @@ public class AVLVillagerDataHandlerImpl implements VillagerDataHandler {
@Override
public void saveOptimizeTime() {
dataContainer.set(Keyring.AntiVillagerLag.NEXT_OPTIMIZATION_SYSTIME_SECONDS.getKey(), PersistentDataType.LONG,
TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 30);
// We do nothing here to not break stuff
}
@Override
public long getOptimizeCooldownMillis(long cooldown_millis) {
if (dataContainer.has(Keyring.AntiVillagerLag.NEXT_OPTIMIZATION_SYSTIME_SECONDS.getKey(), PersistentDataType.LONG)) {
return Math.max(cooldown_millis, System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(dataContainer.get(Keyring.AntiVillagerLag.NEXT_OPTIMIZATION_SYSTIME_SECONDS.getKey(), PersistentDataType.LONG)));
return TimeUnit.SECONDS.toMillis(dataContainer.get(Keyring.AntiVillagerLag.NEXT_OPTIMIZATION_SYSTIME_SECONDS.getKey(), PersistentDataType.LONG) - System.currentTimeMillis());
}
return cooldown_millis;
}
@ -130,7 +129,7 @@ public class AVLVillagerDataHandlerImpl implements VillagerDataHandler {
@Override
public void saveLastLevelUp() {
dataContainer.set(Keyring.AntiVillagerLag.NEXT_LEVELUP_SYSTIME_SECONDS.getKey(), PersistentDataType.LONG, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 30);
// We do nothing here to not break stuff
}
@Override

View File

@ -82,7 +82,10 @@ public class MainVillagerDataHandlerImpl implements VillagerDataHandler {
@Override
public long getOptimizeCooldownMillis(long cooldown_millis) {
return Math.max(System.currentTimeMillis() - getLastOptimize(), cooldown_millis);
if (getLastOptimize() > 0L) {
return cooldown_millis - (System.currentTimeMillis() - getLastOptimize());
}
return cooldown_millis;
}
@Override

View File

@ -126,7 +126,7 @@ public class WrappedVillager implements VillagerDataHandler {
@Override
public long getOptimizeCooldownMillis(long cooldown_millis) {
long cooldown = cooldown_millis;
long cooldown = 0L;
for (VillagerDataHandler handler : dataHandlers) {
cooldown = Math.max(cooldown, handler.getOptimizeCooldownMillis(cooldown_millis));
}