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 releaseHost();
void destroy(); 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.amount = entity.getMetadata("US_AMOUNT").get(0).asInt();
} }
this.hostEntity = entity; this.hostEntity = entity;
updateNameTag();
} }
/** /**
@ -226,7 +225,7 @@ public class EntityStackImpl implements EntityStack {
hostEntity = null; hostEntity = null;
} }
private void updateNameTag() { public void updateNameTag() {
if (hostEntity == null) { if (hostEntity == null) {
return; return;
} }

View File

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