summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorSenmori <thesenmori@gmail.com>2018-02-12 10:29:51 +1100
committermd_5 <git@md-5.net>2018-02-12 10:33:19 +1100
commitf8411ea1e5865e6d512e4673f4d59255a078e169 (patch)
tree428f53a182737dc5bf38f9da0907dd797575e723 /src/main
parent8bb4f6ccc150ed89eb522571ed643ad84765ca91 (diff)
downloadcraftbukkit-f8411ea1e5865e6d512e4673f4d59255a078e169.tar
craftbukkit-f8411ea1e5865e6d512e4673f4d59255a078e169.tar.gz
craftbukkit-f8411ea1e5865e6d512e4673f4d59255a078e169.tar.lz
craftbukkit-f8411ea1e5865e6d512e4673f4d59255a078e169.tar.xz
craftbukkit-f8411ea1e5865e6d512e4673f4d59255a078e169.zip
Expand Structure Block API
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java172
1 files changed, 171 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java
index ecf12ee3..536c8131 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java
@@ -1,10 +1,24 @@
package org.bukkit.craftbukkit.block;
+import com.google.common.base.Preconditions;
+import net.minecraft.server.BlockPosition;
+import net.minecraft.server.EnumBlockMirror;
+import net.minecraft.server.EnumBlockRotation;
import net.minecraft.server.TileEntityStructure;
+import org.apache.commons.lang3.Validate;
import org.bukkit.Material;
import org.bukkit.block.Block;
+import org.bukkit.block.Structure;
+import org.bukkit.block.structure.Mirror;
+import org.bukkit.block.structure.StructureRotation;
+import org.bukkit.block.structure.UsageMode;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.util.BlockVector;
-public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructure> {
+public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructure> implements Structure {
+
+ private static final int MAX_SIZE = 32;
public CraftStructureBlock(Block block) {
super(block, TileEntityStructure.class);
@@ -13,4 +27,160 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
public CraftStructureBlock(Material material, TileEntityStructure structure) {
super(material, structure);
}
+
+ @Override
+ public String getStructureName() {
+ return getSnapshot().a(); // PAIL: rename getStructureName
+ }
+
+ @Override
+ public void setStructureName(String name) {
+ Preconditions.checkArgument(name != null, "Structure Name cannot be null");
+ getSnapshot().a(name); // PAIL: rename setStructureName
+ }
+
+ @Override
+ public String getAuthor() {
+ return getSnapshot().f;
+ }
+
+ @Override
+ public void setAuthor(String author) {
+ Preconditions.checkArgument(author != null && !author.isEmpty(), "Author name cannot be null nor empty");
+ getSnapshot().f = author; // PAIL: rename author
+ }
+
+ @Override
+ public void setAuthor(LivingEntity entity) {
+ Preconditions.checkArgument(entity != null, "Structure Block author entity cannot be null");
+ getSnapshot().a(((CraftLivingEntity) entity).getHandle()); // PAIL: rename setAuthor
+ }
+
+ @Override
+ public BlockVector getRelativePosition() {
+ return new BlockVector(getSnapshot().h.getX(), getSnapshot().h.getY(), getSnapshot().h.getZ()); // PAIL: rename relativePosition
+ }
+
+ @Override
+ public void setRelativePosition(BlockVector vector) {
+ Validate.isTrue(isBetween(vector.getBlockX(), -MAX_SIZE, MAX_SIZE), "Structure Size (X) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
+ Validate.isTrue(isBetween(vector.getBlockY(), -MAX_SIZE, MAX_SIZE), "Structure Size (Y) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
+ Validate.isTrue(isBetween(vector.getBlockZ(), -MAX_SIZE, MAX_SIZE), "Structure Size (Z) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
+ getSnapshot().h = new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); // PAIL: rename relativePosition
+ }
+
+ @Override
+ public BlockVector getStructureSize() {
+ return new BlockVector(getSnapshot().i.getX(), getSnapshot().i.getY(), getSnapshot().i.getZ()); // PAIL: rename size
+ }
+
+ @Override
+ public void setStructureSize(BlockVector vector) {
+ Validate.isTrue(isBetween(vector.getBlockX(), 0, MAX_SIZE), "Structure Size (X) must be between 0 and " + MAX_SIZE);
+ Validate.isTrue(isBetween(vector.getBlockY(), 0, MAX_SIZE), "Structure Size (Y) must be between 0 and " + MAX_SIZE);
+ Validate.isTrue(isBetween(vector.getBlockZ(), 0, MAX_SIZE), "Structure Size (Z) must be between 0 and " + MAX_SIZE);
+ getSnapshot().c(new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ())); // PAIL: setStructureSize
+ }
+
+ @Override
+ public void setMirror(Mirror mirror) {
+ getSnapshot().j = EnumBlockMirror.valueOf(mirror.name()); // PAIL: rename mirror
+ }
+
+ @Override
+ public Mirror getMirror() {
+ return Mirror.valueOf(getSnapshot().j.name()); // PAIL: rename mirror
+ }
+
+ @Override
+ public void setRotation(StructureRotation rotation) {
+ getSnapshot().k = EnumBlockRotation.valueOf(rotation.name()); // PAIL: rename rotation
+ }
+
+ @Override
+ public StructureRotation getRotation() {
+ return StructureRotation.valueOf(getSnapshot().k.name()); // PAIL: rename rotation
+ }
+
+ @Override
+ public void setUsageMode(UsageMode mode) {
+ getSnapshot().a(TileEntityStructure.UsageMode.valueOf(mode.name())); // PAIL: rename setUsageMode
+ }
+
+ @Override
+ public UsageMode getUsageMode() {
+ return UsageMode.valueOf(getSnapshot().k().name()); // PAIL rename getUsageMode
+ }
+
+ @Override
+ public void setIgnoreEntities(boolean flag) {
+ getSnapshot().m = flag; // PAIL: rename ignoreEntities
+ }
+
+ @Override
+ public boolean isIgnoreEntities() {
+ return getSnapshot().m; // PAIL: rename ignoreEntities
+ }
+
+ @Override
+ public void setShowAir(boolean showAir) {
+ getSnapshot().o = showAir; // PAIL rename showAir
+ }
+
+ @Override
+ public boolean isShowAir() {
+ return getSnapshot().o; // PAIL: rename showAir
+ }
+
+ @Override
+ public void setBoundingBoxVisible(boolean showBoundingBox) {
+ getSnapshot().p = showBoundingBox; // PAIL: rename boundingBoxVisible
+ }
+
+ @Override
+ public boolean isBoundingBoxVisible() {
+ return getSnapshot().p; // PAIL: rename boundingBoxVisible
+ }
+
+ @Override
+ public void setIntegrity(float integrity) {
+ Validate.isTrue(isBetween(integrity, 0.0f, 1.0f), "Integrity must be between 0.0f and 1.0f");
+ getSnapshot().q = integrity; // PAIL: rename integrity
+ }
+
+ @Override
+ public float getIntegrity() {
+ return getSnapshot().q; // PAIL: rename integrity
+ }
+
+ @Override
+ public void setSeed(long seed) {
+ getSnapshot().r = seed; // PAIL: rename seed
+ }
+
+ @Override
+ public long getSeed() {
+ return getSnapshot().r; // PAIL: rename seed
+ }
+
+ @Override
+ public void setMetadata(String metadata) {
+ Validate.notNull(metadata, "Structure metadata cannot be null");
+ if (getUsageMode() == UsageMode.DATA) {
+ getSnapshot().g = metadata; // PAIL: rename metadata
+ }
+ }
+
+ @Override
+ public String getMetadata() {
+ return getSnapshot().g; // PAIL: rename metadata
+ }
+
+ private static boolean isBetween(int num, int min, int max) {
+ return num >= min && num <= max;
+ }
+
+ private static boolean isBetween(float num, float min, float max) {
+ return num >= min && num <= max;
+ }
}