2024-04-24 01:15:00 +10:00

61 lines
1.6 KiB
Java

package org.bukkit.craftbukkit.block;
import net.minecraft.world.ChestLock;
import net.minecraft.world.level.block.entity.TileEntityContainer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Container;
import org.bukkit.craftbukkit.util.CraftChatMessage;
public abstract class CraftContainer<T extends TileEntityContainer> extends CraftBlockEntityState<T> implements Container {
public CraftContainer(World world, T tileEntity) {
super(world, tileEntity);
}
protected CraftContainer(CraftContainer<T> state, Location location) {
super(state, location);
}
@Override
public boolean isLocked() {
return !this.getSnapshot().lockKey.key().isEmpty();
}
@Override
public String getLock() {
return this.getSnapshot().lockKey.key();
}
@Override
public void setLock(String key) {
this.getSnapshot().lockKey = (key == null) ? ChestLock.NO_LOCK : new ChestLock(key);
}
@Override
public String getCustomName() {
T container = this.getSnapshot();
return container.name != null ? CraftChatMessage.fromComponent(container.getCustomName()) : null;
}
@Override
public void setCustomName(String name) {
this.getSnapshot().name = CraftChatMessage.fromStringOrNull(name);
}
@Override
public void applyTo(T container) {
super.applyTo(container);
if (this.getSnapshot().name == null) {
container.name = null;
}
}
@Override
public abstract CraftContainer<T> copy();
@Override
public abstract CraftContainer<T> copy(Location location);
}