Improve performance

This commit is contained in:
ceze88 2023-10-09 17:43:55 +02:00
parent 084d2c8348
commit 5d41e6ea36
3 changed files with 8 additions and 3 deletions

View File

@ -21,4 +21,6 @@ public interface EntityStack extends Stackable {
void releaseHost();
void destroy();
void updateNameTag();
}

View File

@ -50,7 +50,6 @@ public class EntityStackImpl implements EntityStack {
this.amount = entity.getMetadata("US_AMOUNT").get(0).asInt();
}
this.hostEntity = entity;
updateNameTag();
}
/**
@ -226,7 +225,7 @@ public class EntityStackImpl implements EntityStack {
hostEntity = null;
}
private void updateNameTag() {
public void updateNameTag() {
if (hostEntity == null) {
return;
}

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import uk.antiperson.stackmob.api.StackedEntity;
import java.util.UUID;
@ -21,7 +22,9 @@ public class EntityStackManagerImpl implements EntityStackManager {
@Override
public EntityStack createStackedEntity(LivingEntity entity, int amount) {
return new EntityStackImpl(entity, amount);
EntityStackImpl stackedEntity = new EntityStackImpl(entity, amount);
stackedEntity.updateNameTag();
return stackedEntity;
}
@Override
@ -74,6 +77,7 @@ public class EntityStackManagerImpl implements EntityStackManager {
EntityStack stack = getStackedEntity(oldEntity);
if (stack == null) return null;
EntityStack newStack = new EntityStackImpl(newEntity, takeOne ? stack.getAmount()-1 : stack.getAmount());
newStack.updateNameTag();
stack.destroy();
return newStack;
}