diff --git a/pom.xml b/pom.xml index 92d04bd2..03d8ff87 100644 --- a/pom.xml +++ b/pom.xml @@ -1,243 +1,231 @@ - - 4.0.0 - - com.thevoxelbox - VoxelSniper - 5.171.0-SNAPSHOT - jar - - VoxelSniper - World editing from ingame using 3D brushes. - http://www.voxelwiki.com/minecraft/VoxelSniper - - - https://github.com/TVPT/VoxelSniper - scm:git:git@github.com:TVPT/VoxelSniper.git - scm:git:git://github.com/TVPT/VoxelSniper.git - - - - UTF-8 - UNKNOWN - ${project.version} - - - - - jenkins - - - env.BUILD_NUMBER - - - - jnks${env.BUILD_NUMBER}-git${buildNumber} - ${project.version}-${project.build.identifier} - - - - - - - tvpt-repo - TVPT Snapshot Repository - http://vault.voxelmodpack.com/content/repositories/snapshots - - - tvpt-repo - TVPT Release Repository - http://vault.voxelmodpack.com/content/repositories/releases - - - - - - tvpt-repo - http://vault.voxelmodpack.com/content/repositories/central/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - - - org.bukkit - bukkit - 1.13-R0.1-SNAPSHOT - - - com.martiansoftware - jsap - 2.1 - - - com.google.guava - guava - 17.0 - - - junit - junit - 4.11 - test - - - org.mockito - mockito-all - 1.9.5 - test - - - - - - - src/main/resources - true - - - - - - org.codehaus.mojo - buildnumber-maven-plugin - 1.3 - - 7 - - - - validate - - create - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.5 - - - - true - - - ${buildNumber} - ${timestamp} - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.3 - - - attach-sources - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.3 - - - package - - shade - - - true - - - org.bukkit:craftbukkit - org.bukkit:bukkit - junit:junit - - - - - com.martiansoftware - com.thevoxelbox.voxelsniper.libs.com.martiansoftware - - - com.google.common - com.thevoxelbox.voxelsniper.libs.com.google.common - - - - - - - - - - - - checkstyle - - validate - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.12.1 - - checkstyle.xml - - - - - maven-deploy-plugin - org.apache.maven.plugins - 2.8.1 - - - - org.apache.maven.plugins - maven-release-plugin - 2.4.2 - - clean install deploy - - - - - + + 4.0.0 + + com.thevoxelbox + VoxelSniper + 5.171.0-SNAPSHOT + jar + + VoxelSniper + World editing from ingame using 3D brushes. + http://www.voxelwiki.com/minecraft/VoxelSniper + + + https://github.com/TVPT/VoxelSniper + scm:git:git@github.com:TVPT/VoxelSniper.git + scm:git:git://github.com/TVPT/VoxelSniper.git + + + + UTF-8 + UNKNOWN + ${project.version} + + + + + jenkins + + + env.BUILD_NUMBER + + + + jnks${env.BUILD_NUMBER}-git${buildNumber} + ${project.version}-${project.build.identifier} + + + + + + + tvpt-repo + TVPT Snapshot Repository + http://vault.voxelmodpack.com/content/repositories/snapshots + + + tvpt-repo + TVPT Release Repository + http://vault.voxelmodpack.com/content/repositories/releases + + + + + + tvpt-repo + http://vault.voxelmodpack.com/content/repositories/central/ + + + paper-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype-nexus + https://oss.sonatype.org/content/groups/public + + + + + + io.papermc.paper + paper-api + 1.18.2-R0.1-SNAPSHOT + provided + + + com.martiansoftware + jsap + 2.1 + + + com.google.guava + guava + 21.0 + + + com.flowpowered + flow-nbt + 1.0.1-SNAPSHOT + + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + org.mockito + mockito-core + 5.6.0 + test + + + + + + + src/main/resources + true + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.3 + + 7 + + + + validate + + create + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 17 + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.5 + + + + true + + + ${buildNumber} + ${timestamp} + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.3 + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.5.0 + + + package + + shade + + + true + + + com.martiansoftware + com.thevoxelbox.voxelsniper.libs.com.martiansoftware + + + com.google.common + com.thevoxelbox.voxelsniper.libs.com.google.common + + + + + + + + + + + + checkstyle + + validate + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.12.1 + + checkstyle.xml + + + + + maven-deploy-plugin + org.apache.maven.plugins + 2.8.1 + + + + org.apache.maven.plugins + maven-release-plugin + 2.4.2 + + clean install deploy + + + + + diff --git a/src/main/java/com/thevoxelbox/voxelsniper/Message.java b/src/main/java/com/thevoxelbox/voxelsniper/Message.java index c7c0f9f8..7d05bb43 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/Message.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/Message.java @@ -2,6 +2,8 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.data.BlockData; /** * @@ -57,14 +59,6 @@ public void custom(String message) snipeData.sendMessage(message); } - /** - * Display data value. - */ - public void data() - { - snipeData.sendMessage(ChatColor.BLUE + "Data Variable: " + ChatColor.DARK_RED + snipeData.getData()); - } - /** * Display voxel height. */ @@ -86,18 +80,23 @@ public void performerName(String performerName) /** * Displaye replace material. */ - @SuppressWarnings("deprecation") public void replace() { - snipeData.sendMessage(ChatColor.AQUA + "Replace Material: " + ChatColor.RED + snipeData.getReplaceId() + ChatColor.GRAY + " (" + Material.getMaterial(snipeData.getReplaceId()).toString() + ")"); + snipeData.sendMessage(ChatColor.AQUA + "Replace Material: " + ChatColor.RED + snipeData.getReplaceMat().getKey().toString()); } /** - * Display replace data value. + * Display replace ink. */ - public void replaceData() + public void replaceInk() { - snipeData.sendMessage(ChatColor.DARK_GRAY + "Replace Data Variable: " + ChatColor.DARK_RED + snipeData.getReplaceData()); + snipeData.sendMessage(ChatColor.DARK_GRAY + "Replace ink: " + ChatColor.DARK_RED + snipeData.getReplaceInk()); + } + + public void tag() + { + //TODO: Add tag which retains id? + snipeData.sendMessage(ChatColor.DARK_GRAY + "Replace tag: #" + ChatColor.DARK_RED + (snipeData.getTag() != null ? snipeData.getTag().toString() : "None")); } /** @@ -139,10 +138,14 @@ public void toggleRange() /** * Display voxel type. */ - @SuppressWarnings("deprecation") public void voxel() { - snipeData.sendMessage(ChatColor.GOLD + "Voxel: " + ChatColor.RED + snipeData.getVoxelId() + ChatColor.GRAY + " (" + Material.getMaterial(snipeData.getVoxelId()).toString() + ")"); + snipeData.sendMessage(ChatColor.GOLD + "Voxel: " + ChatColor.RED + snipeData.getVoxelMat().getKey().toString()); + } + + public void voxelInk() + { + snipeData.sendMessage(ChatColor.BLUE + "Voxel ink: " + ChatColor.DARK_RED + snipeData.getVoxelInk()); } /** @@ -161,14 +164,20 @@ public void voxelList() returnValueBuilder.append("Block Types Selected: "); returnValueBuilder.append(ChatColor.AQUA); - for (int[] valuePair : snipeData.getVoxelList().getList()) + for (BlockData data : snipeData.getVoxelList().getBlockList()) + { + returnValueBuilder.append(data.getAsString()); + returnValueBuilder.append(" "); + } + + returnValueBuilder.append(ChatColor.DARK_GREEN); + returnValueBuilder.append("Tags Selected: "); + returnValueBuilder.append(ChatColor.AQUA); + + for (Tag tag: snipeData.getVoxelList().getTagList()) { - returnValueBuilder.append(valuePair[0]); - if (valuePair[1] != -1) - { - returnValueBuilder.append(":"); - returnValueBuilder.append(valuePair[1]); - } + //TODO: Create a wrapper for tag that holds the name? + returnValueBuilder.append(tag.toString()); returnValueBuilder.append(" "); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/MetricsManager.java b/src/main/java/com/thevoxelbox/voxelsniper/MetricsManager.java deleted file mode 100644 index 0ab523a9..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/MetricsManager.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.thevoxelbox.voxelsniper; - -import com.google.common.collect.Maps; -import com.thevoxelbox.voxelsniper.brush.IBrush; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.util.NumberConversions; -import org.mcstats.Metrics; -import org.mcstats.Metrics.Graph; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map; - -/** - * @author Monofraps - */ -public final class MetricsManager -{ - private static int snipesDone = 0; - private static long snipeCounterInitTimeStamp = 0; - private static MetricsManager instance; - private static Map brushUsageCounter = Maps.newHashMap(); - - private MetricsManager() - { - } - - /** - * @return {@link MetricsManager} - */ - public static MetricsManager getInstance() - { - if (MetricsManager.instance == null) - { - MetricsManager.instance = new MetricsManager(); - } - - return MetricsManager.instance; - } - - /** - * Increase the Snipes Counter. - */ - public static void increaseSnipeCounter() - { - MetricsManager.snipesDone++; - } - - /** - * Increase usage for a specific brush. - * - * @param brushName Name of the Brush - */ - public static void increaseBrushUsage(String brushName) - { - if (brushUsageCounter.get(brushName) == null) - { - brushUsageCounter.put(brushName, 0); - } - brushUsageCounter.put(brushName, brushUsageCounter.get(brushName)); - } - - /** - * Set Initialization time for reference when calculating average Snipes per Minute. - * - * @param currentTimeMillis - */ - public static void setSnipeCounterInitTimeStamp(final long currentTimeMillis) - { - MetricsManager.snipeCounterInitTimeStamp = currentTimeMillis; - } - - /** - * Start sending Metrics. - */ - public void start() - { - try - { - final Metrics metrics = new Metrics(VoxelSniper.getInstance()); - - final Graph defaultGraph = metrics.createGraph("Default"); - defaultGraph.addPlotter(new Metrics.Plotter("Average Snipes per Minute") - { - - @Override - public int getValue() - { - final int currentSnipes = MetricsManager.snipesDone; - final long initializationTimeStamp = MetricsManager.snipeCounterInitTimeStamp; - final double deltaTime = System.currentTimeMillis() - initializationTimeStamp; - - double average = 0; - if (deltaTime < 60000) - { - average = currentSnipes; - } - else - { - final double timeRunning = deltaTime / 60000; - average = currentSnipes / timeRunning; - } - - // quite unlikely ... - if (average > 10000) - { - average = 0; - } - - return NumberConversions.floor(average); - } - }); - - - final Graph brushUsageGraph = metrics.createGraph("Brush Usage"); - - for (final Map.Entry entry : brushUsageCounter.entrySet()) - { - brushUsageGraph.addPlotter(new Metrics.Plotter(entry.getKey()) - { - @Override - public int getValue() - { - return entry.getValue(); - } - - @Override - public void reset() - { - brushUsageCounter.remove(entry.getKey()); - } - }); - } - - metrics.start(); - } - catch (final IOException exception) - { - VoxelSniper.getInstance().getLogger().finest("Failed to submit Metrics Data."); - } - } -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java b/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java index 25df54ee..d9f40f54 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java @@ -37,7 +37,6 @@ private PaintingWrapper() * @param choice * Chosen index to set the painting to */ - @SuppressWarnings("deprecation") public static void paint(final Player p, final boolean auto, final boolean back, final int choice) { Location targetLocation = p.getTargetBlock((Set) null, 4).getLocation(); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/RangeBlockHelper.java b/src/main/java/com/thevoxelbox/voxelsniper/RangeBlockHelper.java index fe5d2c16..b90af258 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/RangeBlockHelper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/RangeBlockHelper.java @@ -1,6 +1,7 @@ package com.thevoxelbox.voxelsniper; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -165,10 +166,9 @@ public final Block getCurBlock() * * @return Block */ - @SuppressWarnings("deprecation") - public final Block getFaceBlock() + public final Block getFaceBlock() { - while ((this.getNextBlock() != null) && (this.getCurBlock().getTypeId() == 0)) + while ((this.getNextBlock() != null) && (this.getCurBlock().getType() == Material.AIR)) { } @@ -252,11 +252,10 @@ public final Block getRangeBlock() * * @return Block */ - @SuppressWarnings("deprecation") - public final Block getTargetBlock() + public final Block getTargetBlock() { this.fromOffworld(); - while ((this.getNextBlock() != null) && (this.getCurBlock().getTypeId() == 0)) + while ((this.getNextBlock() != null) && (this.getCurBlock().getType() == Material.AIR)) { } @@ -268,12 +267,11 @@ public final Block getTargetBlock() * * @param type */ - @SuppressWarnings("deprecation") - public final void setCurBlock(final int type) + public final void setCurBlock(final Material type) { if (this.getCurBlock() != null) { - this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).setTypeId(type); + this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).setType(type); } } @@ -282,16 +280,15 @@ public final void setCurBlock(final int type) * * @param type */ - @SuppressWarnings("deprecation") - public final void setFaceBlock(final int type) + public final void setFaceBlock(final Material type) { - while ((this.getNextBlock() != null) && (this.getCurBlock().getTypeId() == 0)) + while ((this.getNextBlock() != null) && (this.getCurBlock().getType() == Material.AIR)) { } if (this.getCurBlock() != null) { - this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).setTypeId(type); + this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).setType(type); } } @@ -300,12 +297,11 @@ public final void setFaceBlock(final int type) * * @param type */ - @SuppressWarnings("deprecation") - public final void setLastBlock(final int type) + public final void setLastBlock(final Material type) { if (this.getLastBlock() != null) { - this.world.getBlockAt(this.lastX, this.lastY, this.lastZ).setTypeId(type); + this.world.getBlockAt(this.lastX, this.lastY, this.lastZ).setType(type); } } @@ -314,21 +310,19 @@ public final void setLastBlock(final int type) * * @param type */ - @SuppressWarnings("deprecation") - public final void setTargetBlock(final int type) + public final void setTargetBlock(final Material type) { - while ((this.getNextBlock() != null) && (this.getCurBlock().getTypeId() == 0)) + while ((this.getNextBlock() != null) && (this.getCurBlock().getType() == Material.AIR)) { } if (this.getCurBlock() != null) { - this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).setTypeId(type); + this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).setType(type); } } - @SuppressWarnings("deprecation") - private Block getRange() + private Block getRange() { this.lastX = this.targetX; this.lastY = this.targetY; @@ -350,7 +344,7 @@ private Block getRange() } while ((this.length <= this.range) && ((this.targetX == this.lastX) && (this.targetY == this.lastY) && (this.targetZ == this.lastZ))); - if (this.world.getBlockTypeIdAt(this.targetX, this.targetY, this.targetZ) != 0) + if (this.world.getBlockAt(this.targetX, this.targetY, this.targetZ).getType() != Material.AIR) { return this.world.getBlockAt(this.targetX, this.targetY, this.targetZ); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/SnipeData.java b/src/main/java/com/thevoxelbox/voxelsniper/SnipeData.java index 7912058b..7e9dfdb4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/SnipeData.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/SnipeData.java @@ -1,8 +1,9 @@ package com.thevoxelbox.voxelsniper; +import com.thevoxelbox.voxelsniper.util.Inker; import com.thevoxelbox.voxelsniper.util.VoxelList; - import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.data.BlockData; @@ -12,13 +13,11 @@ public class SnipeData { - public static final int DEFAULT_REPLACE_DATA_VALUE = 0; public static final int DEFAULT_CYLINDER_CENTER = 0; public static final int DEFAULT_VOXEL_HEIGHT = 1; public static final int DEFAULT_BRUSH_SIZE = 3; - public static final int DEFAULT_DATA_VALUE = 0; - public static final int DEFAULT_REPLACE_ID = 0; - public static final int DEFAULT_VOXEL_ID = 0; + public static final Material DEFAULT_MATERIAL = Material.AIR; + public static final String DEFAULT_INK = ""; private final Sniper owner; private Message voxelMessage; @@ -26,26 +25,6 @@ public class SnipeData * Brush size -- set blockPositionY /b #. */ private int brushSize = SnipeData.DEFAULT_BRUSH_SIZE; - /** - * Voxel Id -- set blockPositionY /v (#,name). - */ - @Deprecated - private int voxelId = SnipeData.DEFAULT_VOXEL_ID; - /** - * Voxel Replace Id -- set blockPositionY /vr #. - */ - @Deprecated - private int replaceId = SnipeData.DEFAULT_REPLACE_ID; - /** - * Voxel 'ink' -- set blockPositionY /vi #. - */ - @Deprecated - private byte data = SnipeData.DEFAULT_DATA_VALUE; - /** - * Voxel 'ink' Replace -- set blockPositionY /vir #. - */ - @Deprecated - private byte replaceData = SnipeData.DEFAULT_REPLACE_DATA_VALUE; /** * Voxel List of ID's -- set blockPositionY /vl # # # -#. */ @@ -61,7 +40,13 @@ public class SnipeData private int range = 0; private boolean ranged = false; private boolean lightning = false; - private BlockData blockData = Material.AIR.createBlockData(); + private Material voxelMat = SnipeData.DEFAULT_MATERIAL; + private String voxelInk = SnipeData.DEFAULT_INK; + private BlockData voxelData = null; + private Material replaceMat = SnipeData.DEFAULT_MATERIAL; + private String replaceInk = SnipeData.DEFAULT_INK; + private BlockData replaceData = null; + private Tag tag = null; /** * @param vs @@ -87,33 +72,6 @@ public final int getcCen() return this.cCen; } - /** - * @return the data - */ - @Deprecated - public final byte getData() - { - return this.data; - } - - /** - * @return the replaceData - */ - @Deprecated - public final byte getReplaceData() - { - return this.replaceData; - } - - /** - * @return the replaceId - */ - @Deprecated - public final int getReplaceId() - { - return this.replaceId; - } - /** * @return the voxelHeight */ @@ -122,15 +80,6 @@ public final int getVoxelHeight() return this.voxelHeight; } - /** - * @return the voxelId - */ - @Deprecated - public final int getVoxelId() - { - return this.voxelId; - } - /** * @return the voxelList */ @@ -168,13 +117,16 @@ public final Sniper owner() */ public final void reset() { - this.voxelId = SnipeData.DEFAULT_VOXEL_ID; - this.replaceId = SnipeData.DEFAULT_REPLACE_ID; - this.data = SnipeData.DEFAULT_DATA_VALUE; + this.voxelMat = SnipeData.DEFAULT_MATERIAL; + this.voxelInk = SnipeData.DEFAULT_INK; + this.voxelData = null; + this.replaceMat = SnipeData.DEFAULT_MATERIAL; + this.replaceInk = SnipeData.DEFAULT_INK; + this.replaceData = null; + this.tag = null; this.brushSize = SnipeData.DEFAULT_BRUSH_SIZE; this.voxelHeight = SnipeData.DEFAULT_VOXEL_HEIGHT; this.cCen = SnipeData.DEFAULT_CYLINDER_CENTER; - this.replaceData = SnipeData.DEFAULT_REPLACE_DATA_VALUE; this.voxelList = new VoxelList(); } @@ -204,33 +156,6 @@ public final void setcCen(final int cCen) this.cCen = cCen; } - /** - * @param data - * the data to set - */ - public final void setData(final byte data) - { - this.data = data; - } - - /** - * @param replaceData - * the replaceData to set - */ - public final void setReplaceData(final byte replaceData) - { - this.replaceData = replaceData; - } - - /** - * @param replaceId - * the replaceId to set - */ - public final void setReplaceId(final int replaceId) - { - this.replaceId = replaceId; - } - /** * @param voxelHeight * the voxelHeight to set @@ -240,15 +165,6 @@ public final void setVoxelHeight(final int voxelHeight) this.voxelHeight = voxelHeight; } - /** - * @param voxelId - * the voxelId to set - */ - public final void setVoxelId(final int voxelId) - { - this.voxelId = voxelId; - } - /** * @param voxelList * the voxelList to set @@ -297,11 +213,75 @@ public void setLightningEnabled(boolean lightning) this.lightning = lightning; } - public void setVoxelData(BlockData blockData) { - this.blockData = blockData; + public BlockData getVoxelData() + { + if(this.voxelData == null) { + this.voxelData = Inker.inkMat(voxelMat, voxelInk); + } + + return voxelData; } - public BlockData getVoxelData() { - return this.blockData; + public Material getVoxelMat() + { + return voxelMat; + } + + public String getVoxelInk() + { + return voxelInk; + } + + public BlockData getReplaceData() + { + if (this.replaceData == null) { + this.replaceData = Inker.inkMat(replaceMat, replaceInk); + } + + return replaceData; + } + + public Material getReplaceMat() + { + return replaceMat; + } + + public String getReplaceInk() + { + return replaceInk; + } + + public Tag getTag() + { + return tag; + } + + public void setVoxelMat(Material voxelMat) + { + this.voxelData = null; + this.voxelMat = voxelMat; + } + + public void setVoxelInk(String voxelInk) + { + this.voxelData = null; + this.voxelInk = voxelInk; + } + + public void setReplaceMat(Material replaceMat) + { + this.replaceData = null; + this.replaceMat = replaceMat; + } + + public void setReplaceInk(String replaceInk) + { + this.replaceData = null; + this.replaceInk = replaceInk; + } + + public void setTag(Tag tag) + { + this.tag = tag; } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java b/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java index 9919b312..ed6fe62d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java @@ -18,12 +18,9 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; -import org.bukkit.material.MaterialData; -import java.lang.ref.WeakReference; import java.util.LinkedList; import java.util.Map; import java.util.UUID; @@ -138,44 +135,23 @@ public boolean snipe(Action action, Material itemInHand, Block clickedBlock, Blo switch (snipeAction) { case ARROW: + Material originalVoxel = snipeData.getVoxelMat(); + String ink = snipeData.getVoxelInk(); if (targetBlock != null) { - BlockData originalVoxel = snipeData.getVoxelData(); - final BlockData blockData = targetBlock.getBlockData(); - snipeData.setVoxelData(blockData); - SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, originalVoxel, blockData); + final Material mat = targetBlock.getType(); + snipeData.setVoxelMat(mat); + SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, originalVoxel, ink, mat, ink); Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().voxel(); - return true; } else { - int originalVoxel = snipeData.getVoxelId(); - snipeData.setVoxelId(0); - SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(originalVoxel, snipeData.getData()), new MaterialData(snipeData.getVoxelId(), snipeData.getData())); + snipeData.setVoxelMat(Material.AIR); + SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, originalVoxel, ink, snipeData.getVoxelMat(), ink); Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().voxel(); - return true; - } - case GUNPOWDER: - if (targetBlock != null) - { - byte originalData = snipeData.getData(); - snipeData.setData(targetBlock.getData()); - SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getVoxelId(), originalData), new MaterialData(snipeData.getVoxelId(), snipeData.getData())); - Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().data(); - return true; - } - else - { - byte originalData = snipeData.getData(); - snipeData.setData((byte) 0); - SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getVoxelId(), originalData), new MaterialData(snipeData.getVoxelId(), snipeData.getData())); - Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().data(); - return true; } + snipeData.getVoxelMessage().voxel(); + return true; default: break; } @@ -195,43 +171,22 @@ public boolean snipe(Action action, Material itemInHand, Block clickedBlock, Blo switch (snipeAction) { case ARROW: + Material original = snipeData.getReplaceMat(); + String ink = snipeData.getVoxelInk(); if (targetBlock != null) { - int originalId = snipeData.getReplaceId(); - snipeData.setReplaceId(targetBlock.getTypeId()); - SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(originalId, snipeData.getReplaceData()), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData())); - Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().replace(); - return true; - } - else - { - int originalId = snipeData.getReplaceId(); - snipeData.setReplaceId(0); - SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(originalId, snipeData.getReplaceData()), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData())); - Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().replace(); - return true; - } - case GUNPOWDER: - if (targetBlock != null) - { - byte originalData = snipeData.getReplaceData(); - snipeData.setReplaceData(targetBlock.getData()); - SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getReplaceId(), originalData), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData())); + snipeData.setReplaceMat(targetBlock.getType()); + SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, original, ink, snipeData.getReplaceMat(), ink); Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().replaceData(); - return true; } else { - byte originalData = snipeData.getReplaceData(); - snipeData.setReplaceData((byte) 0); - SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getReplaceId(), originalData), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData())); + snipeData.setReplaceMat(Material.AIR); + SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, original, ink, snipeData.getReplaceMat(), ink); Bukkit.getPluginManager().callEvent(event); - snipeData.getVoxelMessage().replaceData(); - return true; } + snipeData.getVoxelMessage().replace(); + return true; default: break; } @@ -284,12 +239,7 @@ public boolean snipe(Action action, Material itemInHand, Block clickedBlock, Blo performerBrush.initP(snipeData); } - boolean result = sniperTool.getCurrentBrush().perform(snipeAction, snipeData, targetBlock, lastBlock); - if (result) - { - MetricsManager.increaseBrushUsage(sniperTool.getCurrentBrush().getName()); - } - return result; + return sniperTool.getCurrentBrush().perform(snipeAction, snipeData, targetBlock, lastBlock); } } return false; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/Undo.java b/src/main/java/com/thevoxelbox/voxelsniper/Undo.java index 69411cd7..9263d01e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/Undo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/Undo.java @@ -1,7 +1,7 @@ package com.thevoxelbox.voxelsniper; import com.google.common.collect.Sets; -import org.bukkit.Material; +import net.kyori.adventure.text.Component; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.BrewingStand; @@ -9,11 +9,11 @@ import org.bukkit.block.CreatureSpawner; import org.bukkit.block.Dispenser; import org.bukkit.block.Furnace; -import org.bukkit.block.NoteBlock; import org.bukkit.block.Sign; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.NoteBlock; import org.bukkit.util.Vector; -import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -24,51 +24,6 @@ */ public class Undo { - private static final Set FALLING_MATERIALS = EnumSet.of( - Material.WATER, - Material.STATIONARY_WATER, - Material.LAVA, - Material.STATIONARY_LAVA); - private static final Set FALLOFF_MATERIALS = EnumSet.of( - Material.SAPLING, - Material.BED_BLOCK, - Material.POWERED_RAIL, - Material.DETECTOR_RAIL, - Material.LONG_GRASS, - Material.DEAD_BUSH, - Material.PISTON_EXTENSION, - Material.YELLOW_FLOWER, - Material.RED_ROSE, - Material.BROWN_MUSHROOM, - Material.RED_MUSHROOM, - Material.TORCH, - Material.FIRE, - Material.CROPS, - Material.SIGN_POST, - Material.WOODEN_DOOR, - Material.LADDER, - Material.RAILS, - Material.WALL_SIGN, - Material.LEVER, - Material.STONE_PLATE, - Material.IRON_DOOR_BLOCK, - Material.WOOD_PLATE, - Material.REDSTONE_TORCH_OFF, - Material.REDSTONE_TORCH_ON, - Material.REDSTONE_WIRE, - Material.STONE_BUTTON, - Material.SNOW, - Material.CACTUS, - Material.SUGAR_CANE_BLOCK, - Material.CAKE_BLOCK, - Material.DIODE_BLOCK_OFF, - Material.DIODE_BLOCK_ON, - Material.TRAP_DOOR, - Material.PUMPKIN_STEM, - Material.MELON_STEM, - Material.VINE, - Material.WATER_LILY, - Material.NETHER_WARTS); private final Set containing = Sets.newHashSet(); private final List all; private final List falloff; @@ -103,9 +58,9 @@ public void put(Block block) { return; } this.containing.add(pos); - if (Undo.FALLING_MATERIALS.contains(block.getType())) { + if (VTags.LIQUID.isTagged(block.getType())) { dropdown.add(block.getState()); - } else if (Undo.FALLOFF_MATERIALS.contains(block.getType())) { + } else if (VTags.POP_OFF.isTagged(block.getType())) { falloff.add(block.getState()); } else { all.add(block.getState()); @@ -139,6 +94,9 @@ public void undo() { */ private void updateSpecialBlocks(BlockState blockState) { BlockState currentState = blockState.getBlock().getState(); + BlockData blockData = blockState.getBlockData(); + BlockData currentData = currentState.getBlockData(); + if (blockState instanceof BrewingStand && currentState instanceof BrewingStand) { ((BrewingStand) currentState).getInventory().setContents(((BrewingStand) blockState).getInventory().getContents()); } else if (blockState instanceof Chest && currentState instanceof Chest) { @@ -156,13 +114,13 @@ private void updateSpecialBlocks(BlockState blockState) { ((Furnace) currentState).setBurnTime(((Furnace) blockState).getBurnTime()); ((Furnace) currentState).setCookTime(((Furnace) blockState).getCookTime()); currentState.update(); - } else if (blockState instanceof NoteBlock && currentState instanceof NoteBlock) { - ((NoteBlock) currentState).setNote(((NoteBlock) blockState).getNote()); - currentState.update(); + } else if(blockData instanceof NoteBlock && currentData instanceof NoteBlock) { + ((NoteBlock) currentData).setNote(((NoteBlock) blockData).getNote()); + ((NoteBlock) currentData).setInstrument(((NoteBlock) blockData).getInstrument()); } else if (blockState instanceof Sign && currentState instanceof Sign) { int i = 0; - for (String text : ((Sign) blockState).getLines()) { - ((Sign) currentState).setLine(i++, text); + for (Component text : ((Sign) blockState).lines()) { + ((Sign) currentState).line(i++, text); } currentState.update(); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/VTags.java b/src/main/java/com/thevoxelbox/voxelsniper/VTags.java new file mode 100644 index 00000000..3d1b5a3d --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/VTags.java @@ -0,0 +1,240 @@ +package com.thevoxelbox.voxelsniper; + +import com.thevoxelbox.voxelsniper.util.SetTag; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; + +import java.util.EnumSet; +import java.util.Set; + +public class VTags { + + private static NamespacedKey vKey(String name) + { + return new NamespacedKey(VoxelSniper.getInstance(), name); + } + + private static Tag getBlockTag(String name, Set defaults) + { + Tag tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, vKey(name), Material.class); + return tag == null ? new SetTag(defaults, vKey(name)) : tag; + } + + private static final Set NATURAL_MATERIALS = EnumSet.of(Material.STONE, + Material.GRASS_BLOCK, + Material.DIRT, + Material.SAND, + Material.GRAVEL, + Material.GOLD_ORE, + Material.IRON_ORE, + Material.COAL_ORE, + Material.SANDSTONE, + Material.MOSSY_COBBLESTONE, + Material.CLAY, + Material.OBSIDIAN, + Material.SNOW); + public static final Tag NATURAL = getBlockTag("natural", NATURAL_MATERIALS); + + private static final Set EXCLUSIVE_MATERIALS = EnumSet.of( + Material.AIR, Material.STONE, Material.GRASS, Material.DIRT, Material.SAND, Material.GRAVEL, Material.SANDSTONE); + public static final Tag ERASER_EXCLUSIVE = getBlockTag("eraser_exclusive", EXCLUSIVE_MATERIALS); + + private static final Set LIQUID_MATERIALS = EnumSet.of( + Material.WATER, + Material.LAVA); + public static final Tag LIQUID = getBlockTag("liquid", LIQUID_MATERIALS); + + private static final Set POP_OFF_MATERIALS = EnumSet.of( + Material.OAK_SAPLING, + Material.JUNGLE_SAPLING, + Material.DARK_OAK_SAPLING, + Material.BIRCH_SAPLING, + Material.ACACIA_SAPLING, + Material.SPRUCE_SAPLING, + Material.BLACK_BED, + Material.BLUE_BED, + Material.BROWN_BED, + Material.CYAN_BED, + Material.GRAY_BED, + Material.GREEN_BED, + Material.LIGHT_BLUE_BED, + Material.LIGHT_GRAY_BED, + Material.LIME_BED, + Material.MAGENTA_BED, + Material.ORANGE_BED, + Material.PINK_BED, + Material.PURPLE_BED, + Material.RED_BED, + Material.WHITE_BED, + Material.YELLOW_BED, + Material.TALL_GRASS, + Material.DEAD_BUSH, + Material.PISTON_HEAD, + Material.DANDELION, + Material.POPPY, + Material.BROWN_MUSHROOM, + Material.RED_MUSHROOM, + Material.TORCH, + Material.FIRE, + Material.WHEAT, + Material.OAK_SIGN, + Material.SPRUCE_SIGN, + Material.BIRCH_SIGN, + Material.JUNGLE_SIGN, + Material.ACACIA_SIGN, + Material.DARK_OAK_SIGN, + Material.CRIMSON_SIGN, + Material.WARPED_SIGN, + Material.DARK_OAK_DOOR, + Material.ACACIA_DOOR, + Material.BIRCH_DOOR, + Material.IRON_DOOR, + Material.JUNGLE_DOOR, + Material.OAK_DOOR, + Material.SPRUCE_DOOR, + Material.LADDER, + Material.RAIL, + Material.ACTIVATOR_RAIL, + Material.DETECTOR_RAIL, + Material.POWERED_RAIL, + Material.OAK_WALL_SIGN, + Material.SPRUCE_WALL_SIGN, + Material.BIRCH_WALL_SIGN, + Material.JUNGLE_WALL_SIGN, + Material.ACACIA_WALL_SIGN, + Material.DARK_OAK_WALL_SIGN, + Material.CRIMSON_WALL_SIGN, + Material.WARPED_WALL_SIGN, + Material.LEVER, + Material.ACACIA_PRESSURE_PLATE, + Material.BIRCH_PRESSURE_PLATE, + Material.JUNGLE_PRESSURE_PLATE, + Material.OAK_PRESSURE_PLATE, + Material.SPRUCE_PRESSURE_PLATE, + Material.STONE_PRESSURE_PLATE, + Material.DARK_OAK_PRESSURE_PLATE, + Material.HEAVY_WEIGHTED_PRESSURE_PLATE, + Material.LIGHT_WEIGHTED_PRESSURE_PLATE, + Material.REDSTONE_TORCH, + Material.REDSTONE_WIRE, + Material.STONE_BUTTON, + Material.SNOW, + Material.CACTUS, + Material.SUGAR_CANE, + Material.CAKE, + Material.REPEATER, + Material.ACACIA_TRAPDOOR, + Material.BIRCH_TRAPDOOR, + Material.DARK_OAK_TRAPDOOR, + Material.IRON_TRAPDOOR, + Material.JUNGLE_TRAPDOOR, + Material.OAK_TRAPDOOR, + Material.SPRUCE_TRAPDOOR, + Material.PUMPKIN_STEM, + Material.MELON_STEM, + Material.VINE, + Material.LILY_PAD, + Material.NETHER_WART); + public static final Tag POP_OFF = getBlockTag("pop_off", POP_OFF_MATERIALS); + + private static final Set RESET_DENIED_UPDATE_MATERIALS = EnumSet.of( + Material.OAK_SIGN, + Material.SPRUCE_SIGN, + Material.BIRCH_SIGN, + Material.JUNGLE_SIGN, + Material.ACACIA_SIGN, + Material.DARK_OAK_SIGN, + Material.CRIMSON_SIGN, + Material.WARPED_SIGN, + Material.OAK_WALL_SIGN, + Material.SPRUCE_WALL_SIGN, + Material.BIRCH_WALL_SIGN, + Material.JUNGLE_WALL_SIGN, + Material.ACACIA_WALL_SIGN, + Material.DARK_OAK_WALL_SIGN, + Material.CRIMSON_WALL_SIGN, + Material.WARPED_WALL_SIGN, + Material.CHEST, + Material.FURNACE, + Material.REDSTONE_TORCH, + Material.REDSTONE_WIRE, + Material.REPEATER, + Material.SPRUCE_DOOR, + Material.OAK_DOOR, + Material.JUNGLE_DOOR, + Material.BIRCH_DOOR, + Material.ACACIA_DOOR, + Material.DARK_OAK_DOOR, + Material.IRON_DOOR, + Material.ACACIA_FENCE_GATE, + Material.BIRCH_FENCE_GATE, + Material.JUNGLE_FENCE_GATE, + Material.OAK_FENCE_GATE, + Material.SPRUCE_FENCE_GATE, + Material.DARK_OAK_FENCE_GATE, + Material.AIR); + public static final Tag RESET_DENIED_UPDATE = getBlockTag("reset_denied_update", RESET_DENIED_UPDATE_MATERIALS); + + private static Set fallingMaterials() + { + Set accum = EnumSet.noneOf(Material.class); + + for (Material material : Material.values()) + { + if(material.hasGravity()) + { + accum.add(material); + } + } + + //Fluids aren't considered by the method + accum.add(Material.WATER); + accum.add(Material.LAVA); + + return accum; + } + + private static final Set FALLING_MATERIALS = fallingMaterials(); + public static final Tag FALLING = getBlockTag("falling", FALLING_MATERIALS); + + private static final Set OCEAN_EXLUCDED_MATERIALS = EnumSet.of( + Material.AIR, + Material.OAK_SAPLING, + Material.JUNGLE_SAPLING, + Material.DARK_OAK_SAPLING, + Material.BIRCH_SAPLING, + Material.ACACIA_SAPLING, + Material.SPRUCE_SAPLING, + Material.WATER, + Material.LAVA, + Material.ACACIA_LOG, + Material.BIRCH_LOG, + Material.DARK_OAK_LOG, + Material.JUNGLE_LOG, + Material.OAK_LOG, + Material.SPRUCE_LOG, + Material.ACACIA_LEAVES, + Material.BIRCH_LEAVES, + Material.DARK_OAK_LEAVES, + Material.JUNGLE_LEAVES, + Material.OAK_LEAVES, + Material.SPRUCE_LEAVES, + Material.DANDELION, + Material.POPPY, + Material.RED_MUSHROOM, + Material.BROWN_MUSHROOM, + Material.MELON, + Material.MELON_STEM, + Material.PUMPKIN, + Material.PUMPKIN_STEM, + Material.COCOA, + Material.SNOW, + Material.SNOW_BLOCK, + Material.ICE, + Material.SUGAR_CANE, + Material.TALL_GRASS, + Material.SNOW); + public static final Tag OCEAN_EXCLUDED = getBlockTag("ocean_excluded", OCEAN_EXLUCDED_MATERIALS); +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java index 53b8c6c7..42322509 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper; -import com.google.common.base.Preconditions; import com.thevoxelbox.voxelsniper.brush.*; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -8,11 +7,6 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - /** * Bukkit extension point. */ @@ -90,8 +84,6 @@ public void onEnable() registerBrushes(); getLogger().info("Registered " + brushManager.registeredSniperBrushes() + " Sniper Brushes with " + brushManager.registeredSniperBrushHandles() + " handles."); - MetricsManager.getInstance().start(); - saveDefaultConfig(); voxelSniperConfiguration = new VoxelSniperConfiguration(getConfig()); @@ -113,7 +105,6 @@ public void registerBrushes() brushManager.registerSniperBrush(BlendVoxelDiscBrush.class, "bvd", "blendvoxeldisc"); brushManager.registerSniperBrush(BlobBrush.class, "blob", "splatblob"); brushManager.registerSniperBrush(BlockResetBrush.class, "brb", "blockresetbrush"); - brushManager.registerSniperBrush(BlockResetSurfaceBrush.class, "brbs", "blockresetbrushsurface"); brushManager.registerSniperBrush(CanyonBrush.class, "ca", "canyon"); brushManager.registerSniperBrush(CanyonSelectionBrush.class, "cas", "canyonselection"); brushManager.registerSniperBrush(CheckerVoxelDiscBrush.class, "cvd", "checkervoxeldisc"); @@ -163,7 +154,6 @@ public void registerBrushes() brushManager.registerSniperBrush(SignOverwriteBrush.class, "sio", "signoverwriter"); brushManager.registerSniperBrush(SnipeBrush.class, "s", "snipe"); brushManager.registerSniperBrush(SnowConeBrush.class, "snow", "snowcone"); - brushManager.registerSniperBrush(SpiralStaircaseBrush.class, "sstair", "spiralstaircase"); brushManager.registerSniperBrush(SplatterBallBrush.class, "sb", "splatball"); brushManager.registerSniperBrush(SplatterDiscBrush.class, "sd", "splatdisc"); brushManager.registerSniperBrush(SplatterOverlayBrush.class, "sover", "splatteroverlay"); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperConfiguration.java b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperConfiguration.java index 3b226a41..dd6be23a 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperConfiguration.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperConfiguration.java @@ -1,8 +1,10 @@ package com.thevoxelbox.voxelsniper; import com.google.common.base.Preconditions; +import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; +import java.util.ArrayList; import java.util.List; /** @@ -72,9 +74,21 @@ public void setLiteSniperMaxBrushSize(int size) * * @return List of restricted Litesniper Items */ - public List getLiteSniperRestrictedItems() + public List getLiteSniperRestrictedItems() { - return configuration.getIntegerList(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS); + List materialsStrs = configuration.getStringList(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS); + List materials = new ArrayList(); + + for (String strMat : materialsStrs) + { + Material mat = Material.getMaterial(strMat); + if (mat != null) + { + materials.add(mat); + } + } + + return materials; } /** @@ -82,10 +96,17 @@ public List getLiteSniperRestrictedItems() * * @param restrictedItems List of restricted Litesniper Items */ - public void setLitesniperRestrictedItems(List restrictedItems) + public void setLitesniperRestrictedItems(List restrictedItems) { Preconditions.checkNotNull(restrictedItems, "Restricted items must be a list."); - configuration.set(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS, restrictedItems); + List materialsStrs = new ArrayList(); + + for (Material mat : restrictedItems) + { + materialsStrs.add(mat.name()); + } + + configuration.set(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS, materialsStrs); } /** diff --git a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java index dc3f6af1..bfc400b6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java @@ -28,7 +28,6 @@ public class VoxelSniperListener implements Listener public VoxelSniperListener(final VoxelSniper plugin) { this.plugin = plugin; - MetricsManager.setSnipeCounterInitTimeStamp(System.currentTimeMillis()); addCommand(new VoxelBrushCommand(plugin)); addCommand(new VoxelBrushToolCommand(plugin)); addCommand(new VoxelCenterCommand(plugin)); @@ -113,7 +112,6 @@ public final void onPlayerInteract(final PlayerInteractEvent event) Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); if (sniper.isEnabled() && sniper.snipe(event.getAction(), event.getMaterial(), event.getClickedBlock(), event.getBlockFace())) { - MetricsManager.increaseSnipeCounter(); event.setCancelled(true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java index 788574e0..b5c266e2 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java @@ -1,126 +1,133 @@ -package com.thevoxelbox.voxelsniper.brush; - -import com.thevoxelbox.voxelsniper.Message; -import com.thevoxelbox.voxelsniper.SnipeData; -import org.bukkit.ChatColor; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; - -/** - * - */ -public class BiomeBrush extends Brush -{ - private Biome selectedBiome = Biome.PLAINS; - - /** - * - */ - public BiomeBrush() - { - this.setName("Biome (/b biome [Biome Name])"); - } - - private void biome(final SnipeData v) - { - final int brushSize = v.getBrushSize(); - final double brushSizeSquared = Math.pow(brushSize, 2); - - for (int x = -brushSize; x <= brushSize; x++) - { - final double xSquared = Math.pow(x, 2); - - for (int z = -brushSize; z <= brushSize; z++) - { - if ((xSquared + Math.pow(z, 2)) <= brushSizeSquared) - { - this.getWorld().setBiome(this.getTargetBlock().getX() + x, this.getTargetBlock().getZ() + z, this.selectedBiome); - } - } - } - - final Block block1 = this.getWorld().getBlockAt(this.getTargetBlock().getX() - brushSize, 0, this.getTargetBlock().getZ() - brushSize); - final Block block2 = this.getWorld().getBlockAt(this.getTargetBlock().getX() + brushSize, 0, this.getTargetBlock().getZ() + brushSize); - - final int lowChunkX = (block1.getX() <= block2.getX()) ? block1.getChunk().getX() : block2.getChunk().getX(); - final int lowChunkZ = (block1.getZ() <= block2.getZ()) ? block1.getChunk().getZ() : block2.getChunk().getZ(); - final int highChunkX = (block1.getX() >= block2.getX()) ? block1.getChunk().getX() : block2.getChunk().getX(); - final int highChunkZ = (block1.getZ() >= block2.getZ()) ? block1.getChunk().getZ() : block2.getChunk().getZ(); - - for (int x = lowChunkX; x <= highChunkX; x++) - { - for (int z = lowChunkZ; z <= highChunkZ; z++) - { - this.getWorld().refreshChunk(x, z); - } - } - } - - @Override - protected final void arrow(final SnipeData v) - { - this.biome(v); - } - - @Override - protected final void powder(final SnipeData v) - { - this.biome(v); - } - - @Override - public final void info(final Message vm) - { - vm.brushName(this.getName()); - vm.size(); - vm.custom(ChatColor.GOLD + "Currently selected biome type: " + ChatColor.DARK_GREEN + this.selectedBiome.name()); - } - - @Override - public final void parameters(final String[] args, final SnipeData v) - { - if (args[1].equalsIgnoreCase("info")) - { - v.sendMessage(ChatColor.GOLD + "Biome Brush Parameters:"); - String availableBiomes = ""; - - for (final Biome biome : Biome.values()) - { - if (availableBiomes.isEmpty()) - { - availableBiomes = ChatColor.DARK_GREEN + biome.name(); - continue; - } - - availableBiomes += ChatColor.RED + ", " + ChatColor.DARK_GREEN + biome.name(); - - } - v.sendMessage(ChatColor.DARK_BLUE + "Available biomes: " + availableBiomes); - } - else - { - // allows biome names with spaces in their name - String biomeName = args[1]; - for (int i = 2; i < args.length; i++) - { - biomeName += " " + args[i]; - } - - for (final Biome biome : Biome.values()) - { - if (biome.name().equalsIgnoreCase(biomeName)) - { - this.selectedBiome = biome; - break; - } - } - v.sendMessage(ChatColor.GOLD + "Currently selected biome type: " + ChatColor.DARK_GREEN + this.selectedBiome.name()); - } - } - - @Override - public String getPermissionNode() - { - return "voxelsniper.brush.biome"; - } -} +package com.thevoxelbox.voxelsniper.brush; + +import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.SnipeData; +import org.bukkit.ChatColor; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; + +/** + * + */ +public class BiomeBrush extends Brush +{ + private Biome selectedBiome = Biome.PLAINS; + + /** + * + */ + public BiomeBrush() + { + this.setName("Biome (/b biome [Biome Name])"); + } + + private void biome(final SnipeData v) + { + final int brushSize = v.getBrushSize(); + final double brushSizeSquared = Math.pow(brushSize, 2); + + for (int x = -brushSize; x <= brushSize; x++) + { + final double xSquared = Math.pow(x, 2); + + for (int y = -brushSize; y <= brushSize; y++) + { + final double ySquared = Math.pow(y, 2); + + for (int z = -brushSize; z <= brushSize; z++) + { + final double zSquared = Math.pow(z, 2); + + if ((xSquared + ySquared + zSquared) <= brushSizeSquared) + { + this.getWorld().setBiome(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z, this.selectedBiome); + } + } + } + } + + final Block block1 = this.getWorld().getBlockAt(this.getTargetBlock().getX() - brushSize, 0, this.getTargetBlock().getZ() - brushSize); + final Block block2 = this.getWorld().getBlockAt(this.getTargetBlock().getX() + brushSize, 0, this.getTargetBlock().getZ() + brushSize); + + final int lowChunkX = (block1.getX() <= block2.getX()) ? block1.getChunk().getX() : block2.getChunk().getX(); + final int lowChunkZ = (block1.getZ() <= block2.getZ()) ? block1.getChunk().getZ() : block2.getChunk().getZ(); + final int highChunkX = (block1.getX() >= block2.getX()) ? block1.getChunk().getX() : block2.getChunk().getX(); + final int highChunkZ = (block1.getZ() >= block2.getZ()) ? block1.getChunk().getZ() : block2.getChunk().getZ(); + + for (int x = lowChunkX; x <= highChunkX; x++) + { + for (int z = lowChunkZ; z <= highChunkZ; z++) + { + this.getWorld().refreshChunk(x, z); + } + } + } + + @Override + protected final void arrow(final SnipeData v) + { + this.biome(v); + } + + @Override + protected final void powder(final SnipeData v) + { + this.biome(v); + } + + @Override + public final void info(final Message vm) + { + vm.brushName(this.getName()); + vm.size(); + vm.custom(ChatColor.GOLD + "Currently selected biome type: " + ChatColor.DARK_GREEN + this.selectedBiome.name()); + } + + @Override + public final void parameters(final String[] args, final SnipeData v) + { + if (args[1].equalsIgnoreCase("info")) + { + v.sendMessage(ChatColor.GOLD + "Biome Brush Parameters:"); + String availableBiomes = ""; + + for (final Biome biome : Biome.values()) + { + if (availableBiomes.isEmpty()) + { + availableBiomes = ChatColor.DARK_GREEN + biome.name(); + continue; + } + + availableBiomes += ChatColor.RED + ", " + ChatColor.DARK_GREEN + biome.name(); + + } + v.sendMessage(ChatColor.DARK_BLUE + "Available biomes: " + availableBiomes); + } + else + { + // allows biome names with spaces in their name + String biomeName = args[1]; + for (int i = 2; i < args.length; i++) + { + biomeName += " " + args[i]; + } + + for (final Biome biome : Biome.values()) + { + if (biome.name().equalsIgnoreCase(biomeName)) + { + this.selectedBiome = biome; + break; + } + } + v.sendMessage(ChatColor.GOLD + "Currently selected biome type: " + ChatColor.DARK_GREEN + this.selectedBiome.name()); + } + } + + @Override + public String getPermissionNode() + { + return "voxelsniper.brush.biome"; + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java index 9cd9ba9d..9ee2d81c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java @@ -6,6 +6,9 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import java.util.EnumMap; +import java.util.Map; + /** * http://www.voxelwiki.com/minecraft/Voxelsniper#Blend_Brushes */ @@ -19,16 +22,15 @@ public BlendBallBrush() this.setName("Blend Ball"); } - @SuppressWarnings("deprecation") - @Override + @Override protected final void blend(final SnipeData v) { final int brushSize = v.getBrushSize(); final int brushSizeDoubled = 2 * brushSize; // Array that holds the original materials plus a buffer - final int[][][] oldMaterials = new int[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; + final Material[][][] oldMaterials = new Material[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the blended materials - final int[][][] newMaterials = new int[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; + final Material[][][] newMaterials = new Material[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; // Log current materials into oldmats for (int x = 0; x <= 2 * (brushSize + 1); x++) @@ -37,7 +39,7 @@ protected final void blend(final SnipeData v) { for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][y][z] = this.getBlockIdAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY() - brushSize - 1 + y, this.getTargetBlock().getZ() - brushSize - 1 + z); + oldMaterials[x][y][z] = this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY() - brushSize - 1 + y, this.getTargetBlock().getZ() - brushSize - 1 + z); } } } @@ -61,9 +63,10 @@ protected final void blend(final SnipeData v) { for (int z = 0; z <= brushSizeDoubled; z++) { - final int[] materialFrequency = new int[BlendBrushBase.getMaxBlockMaterialID() + 1]; // Array that tracks frequency of materials neighboring given block + // Map that tracks frequency of materials neighboring given block + final Map materialFrequency = new EnumMap(Material.class); int modeMatCount = 0; - int modeMatId = 0; + Material modeMat = Material.AIR; boolean tiecheck = true; for (int m = -1; m <= 1; m++) @@ -74,25 +77,31 @@ protected final void blend(final SnipeData v) { if (!(m == 0 && n == 0 && o == 0)) { - materialFrequency[oldMaterials[x + 1 + m][y + 1 + n][z + 1 + o]]++; + Material material = oldMaterials[x + 1 + m][y + 1 + n][z + 1 + o]; + materialFrequency.put(material, materialFrequency.get(material) + 1); } } } } // Find most common neighboring material. - for (int i = 0; i <= BlendBrushBase.getMaxBlockMaterialID(); i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] > modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + int freq = materialFrequency.get(material); + if (freq > modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { - modeMatCount = materialFrequency[i]; - modeMatId = i; + modeMatCount = freq; + modeMat = material; } } + // Make sure there'world not a tie for most common - for (int i = 0; i < modeMatId; i++) - { - if (materialFrequency[i] == modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + for (Material material : BLOCK_MATERIALS) { + if (material == modeMat) { + break; + } + + if (materialFrequency.get(material) == modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { tiecheck = false; } @@ -101,7 +110,7 @@ protected final void blend(final SnipeData v) // Record most common neighbor material for this block if (tiecheck) { - newMaterials[x][y][z] = modeMatId; + newMaterials[x][y][z] = modeMat; } } } @@ -123,13 +132,13 @@ protected final void blend(final SnipeData v) { if (xSquared + ySquared + Math.pow(z - brushSize - 1, 2) <= rSquared) { - if (!(this.excludeAir && newMaterials[x][y][z] == Material.AIR.getId()) && !(this.excludeWater && (newMaterials[x][y][z] == Material.WATER.getId() || newMaterials[x][y][z] == Material.STATIONARY_WATER.getId()))) + if (!(this.excludeAir && newMaterials[x][y][z] == Material.AIR) && !(this.excludeWater && (newMaterials[x][y][z] == Material.WATER))) { - if (this.getBlockIdAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][y][z]) + if (this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][y][z]) { undo.put(this.clampY(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, this.getTargetBlock().getZ() - brushSize + z)); } - this.setBlockIdAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, newMaterials[x][y][z]); + this.setBlockTypeAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, newMaterials[x][y][z]); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBrushBase.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBrushBase.java index d6f7d5ff..9a886fb2 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBrushBase.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBrushBase.java @@ -6,23 +6,31 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import java.util.ArrayList; +import java.util.List; + /** * @author Monofraps */ -@SuppressWarnings("deprecation") public abstract class BlendBrushBase extends Brush { - private static int maxBlockMaterialID; protected boolean excludeAir = true; protected boolean excludeWater = true; + protected static final Material[] BLOCK_MATERIALS; static { - // Find highest placeable block ID - for (Material material : Material.values()) + List temp = new ArrayList(); + + for (Material mat : Material.values()) { - maxBlockMaterialID = ((material.isBlock() && (material.getId() > maxBlockMaterialID)) ? material.getId() : maxBlockMaterialID); + if (mat.isBlock()) + { + temp.add(mat); + } } + + BLOCK_MATERIALS = temp.toArray(new Material[0]); } /** @@ -66,22 +74,6 @@ public void parameters(final String[] par, final SnipeData v) } } - /** - * @return - */ - protected static int getMaxBlockMaterialID() - { - return maxBlockMaterialID; - } - - /** - * @param maxBlockMaterialID - */ - protected static void setMaxBlockMaterialID(int maxBlockMaterialID) - { - BlendBrushBase.maxBlockMaterialID = maxBlockMaterialID; - } - /** * @return */ diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java index 9bf1037e..8597e2b4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java @@ -6,6 +6,9 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import java.util.EnumMap; +import java.util.Map; + /** * http://www.voxelwiki.com/minecraft/Voxelsniper#Blend_Brushes */ @@ -19,21 +22,20 @@ public BlendDiscBrush() this.setName("Blend Disc"); } - @SuppressWarnings("deprecation") - @Override + @Override protected final void blend(final SnipeData v) { final int brushSize = v.getBrushSize(); final int brushSizeDoubled = 2 * brushSize; - final int[][] oldMaterials = new int[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer - final int[][] newMaterials = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Array that holds the blended materials + final Material[][] oldMaterials = new Material[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer + final Material[][] newMaterials = new Material[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Array that holds the blended materials // Log current materials into oldmats for (int x = 0; x <= 2 * (brushSize + 1); x++) { for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][z] = this.getBlockIdAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize - 1 + z); + oldMaterials[x][z] = this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize - 1 + z); } } @@ -51,9 +53,9 @@ protected final void blend(final SnipeData v) { for (int z = 0; z <= brushSizeDoubled; z++) { - final int[] materialFrequency = new int[BlendBrushBase.getMaxBlockMaterialID() + 1]; // Array that tracks frequency of materials neighboring given block + final Map materialFrequency = new EnumMap(Material.class); int modeMatCount = 0; - int modeMatId = 0; + Material modeMat = Material.AIR; boolean tiecheck = true; for (int m = -1; m <= 1; m++) @@ -62,24 +64,30 @@ protected final void blend(final SnipeData v) { if (!(m == 0 && n == 0)) { - materialFrequency[oldMaterials[x + 1 + m][z + 1 + n]]++; + Material material = oldMaterials[x + 1 + m][z + 1 + n]; + materialFrequency.put(material, materialFrequency.get(material) + 1); } } } // Find most common neighboring material. - for (int i = 0; i <= BlendBrushBase.getMaxBlockMaterialID(); i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] > modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + int freq = materialFrequency.get(material); + if (freq > modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { - modeMatCount = materialFrequency[i]; - modeMatId = i; + modeMatCount = freq; + modeMat = material; } } // Make sure there'world not a tie for most common - for (int i = 0; i < modeMatId; i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] == modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + if (material == modeMat) { + break; + } + + if (materialFrequency.get(material) == modeMatCount && !(this.excludeAir && material == Material.AIR) && !(excludeWater && (material == Material.WATER))) { tiecheck = false; } @@ -88,7 +96,7 @@ protected final void blend(final SnipeData v) // Record most common neighbor material for this block if (tiecheck) { - newMaterials[x][z] = modeMatId; + newMaterials[x][z] = modeMat; } } } @@ -105,13 +113,13 @@ protected final void blend(final SnipeData v) { if (xSquared + Math.pow(z - brushSize - 1, 2) <= rSquared) { - if (!(this.excludeAir && newMaterials[x][z] == Material.AIR.getId()) && !(this.excludeWater && (newMaterials[x][z] == Material.WATER.getId() || newMaterials[x][z] == Material.STATIONARY_WATER.getId()))) + if (!(this.excludeAir && newMaterials[x][z] == Material.AIR) && !(this.excludeWater && (newMaterials[x][z] == Material.WATER))) { - if (this.getBlockIdAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][z]) + if (this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][z]) { undo.put(this.clampY(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize + z)); } - this.setBlockIdAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), newMaterials[x][z]); + this.setBlockTypeAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), newMaterials[x][z]); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java index 3d1a96fc..bb6f6fa0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java @@ -6,6 +6,9 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import java.util.EnumMap; +import java.util.Map; + /** * http://www.voxelwiki.com/minecraft/Voxelsniper#Blend_Brushes */ @@ -19,16 +22,15 @@ public BlendVoxelBrush() this.setName("Blend Voxel"); } - @SuppressWarnings("deprecation") - @Override + @Override protected final void blend(final SnipeData v) { final int brushSize = v.getBrushSize(); final int brushSizeDoubled = 2 * brushSize; // Array that holds the original materials plus a buffer - final int[][][] oldMaterials = new int[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; + final Material[][][] oldMaterials = new Material[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the blended materials - final int[][][] newMaterials = new int[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; + final Material[][][] newMaterials = new Material[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; // Log current materials into oldmats for (int x = 0; x <= 2 * (brushSize + 1); x++) @@ -37,7 +39,7 @@ protected final void blend(final SnipeData v) { for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][y][z] = this.getBlockIdAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY() - brushSize - 1 + y, this.getTargetBlock().getZ() - brushSize - 1 + z); + oldMaterials[x][y][z] = this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY() - brushSize - 1 + y, this.getTargetBlock().getZ() - brushSize - 1 + z); } } } @@ -61,9 +63,10 @@ protected final void blend(final SnipeData v) { for (int z = 0; z <= brushSizeDoubled; z++) { - final int[] materialFrequency = new int[BlendBrushBase.getMaxBlockMaterialID() + 1]; // Array that tracks frequency of materials neighboring given block + // Map that tracks frequency of materials neighboring given block + final Map materialFrequency = new EnumMap(Material.class); int modeMatCount = 0; - int modeMatId = 0; + Material modeMat = Material.AIR; boolean tiecheck = true; for (int m = -1; m <= 1; m++) @@ -74,25 +77,30 @@ protected final void blend(final SnipeData v) { if (!(m == 0 && n == 0 && o == 0)) { - materialFrequency[oldMaterials[x + 1 + m][y + 1 + n][z + 1 + o]]++; + Material material = oldMaterials[x + 1 + m][y + 1 + n][z + 1 + o]; + materialFrequency.put(material, materialFrequency.get(material) + 1); } } } } // Find most common neighboring material. - for (int i = 0; i <= BlendBrushBase.getMaxBlockMaterialID(); i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] > modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + int freq = materialFrequency.get(material); + if (freq > modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { - modeMatCount = materialFrequency[i]; - modeMatId = i; + modeMatCount = freq; + modeMat = material; } } // Make sure there'world not a tie for most common - for (int i = 0; i < modeMatId; i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] == modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + if (material == modeMat) { + break; + } + if (materialFrequency.get(material) == modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { tiecheck = false; } @@ -101,7 +109,7 @@ protected final void blend(final SnipeData v) // Record most common neighbor material for this block if (tiecheck) { - newMaterials[x][y][z] = modeMatId; + newMaterials[x][y][z] = modeMat; } } } @@ -116,13 +124,13 @@ protected final void blend(final SnipeData v) { for (int z = brushSizeDoubled; z >= 0; z--) { - if (!(this.excludeAir && newMaterials[x][y][z] == Material.AIR.getId()) && !(this.excludeWater && (newMaterials[x][y][z] == Material.WATER.getId() || newMaterials[x][y][z] == Material.STATIONARY_WATER.getId()))) + if (!(this.excludeAir && newMaterials[x][y][z] == Material.AIR) && !(this.excludeWater && (newMaterials[x][y][z] == Material.WATER))) { - if (this.getBlockIdAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][y][z]) + if (this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][y][z]) { undo.put(this.clampY(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, this.getTargetBlock().getZ() - brushSize + z)); } - this.setBlockIdAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, newMaterials[x][y][z]); + this.setBlockTypeAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY() - brushSize + y, newMaterials[x][y][z]); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java index c597f793..75e3813c 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java @@ -6,6 +6,9 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import java.util.EnumMap; +import java.util.Map; + /** * http://www.voxelwiki.com/minecraft/Voxelsniper#Blend_Brushes */ @@ -19,21 +22,20 @@ public BlendVoxelDiscBrush() this.setName("Blend Voxel Disc"); } - @SuppressWarnings("deprecation") - @Override + @Override protected final void blend(final SnipeData v) { final int brushSize = v.getBrushSize(); final int brushSizeDoubled = 2 * brushSize; - final int[][] oldMaterials = new int[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer - final int[][] newMaterials = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Array that holds the blended materials + final Material[][] oldMaterials = new Material[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer + final Material[][] newMaterials = new Material[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Array that holds the blended materials // Log current materials into oldmats for (int x = 0; x <= 2 * (brushSize + 1); x++) { for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][z] = this.getBlockIdAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize - 1 + z); + oldMaterials[x][z] = this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize - 1 + z); } } @@ -51,9 +53,10 @@ protected final void blend(final SnipeData v) { for (int z = 0; z <= brushSizeDoubled; z++) { - final int[] materialFrequency = new int[BlendBrushBase.getMaxBlockMaterialID() + 1]; // Array that tracks frequency of materials neighboring given block + // Map that tracks frequency of materials neighboring given block + final Map materialFrequency = new EnumMap(Material.class); int modeMatCount = 0; - int modeMatId = 0; + Material modeMat = Material.AIR; boolean tiecheck = true; for (int m = -1; m <= 1; m++) @@ -62,24 +65,29 @@ protected final void blend(final SnipeData v) { if (!(m == 0 && n == 0)) { - materialFrequency[oldMaterials[x + 1 + m][z + 1 + n]]++; + Material material = oldMaterials[x + 1 + m][z + 1 + n]; + materialFrequency.put(material, materialFrequency.get(material) + 1); } } } // Find most common neighboring material. - for (int i = 0; i <= BlendBrushBase.getMaxBlockMaterialID(); i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] > modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + int freq = materialFrequency.get(material); + if (freq > modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { - modeMatCount = materialFrequency[i]; - modeMatId = i; + modeMatCount = freq; + modeMat = material; } } // Make sure there'world not a tie for most common - for (int i = 0; i < modeMatId; i++) + for (Material material : BLOCK_MATERIALS) { - if (materialFrequency[i] == modeMatCount && !(this.excludeAir && i == Material.AIR.getId()) && !(this.excludeWater && (i == Material.WATER.getId() || i == Material.STATIONARY_WATER.getId()))) + if (material == modeMat) { + break; + } + if (materialFrequency.get(material) == modeMatCount && !(this.excludeAir && material == Material.AIR) && !(this.excludeWater && (material == Material.WATER))) { tiecheck = false; } @@ -88,7 +96,7 @@ protected final void blend(final SnipeData v) // Record most common neighbor material for this block if (tiecheck) { - newMaterials[x][z] = modeMatId; + newMaterials[x][z] = modeMat; } } } @@ -100,13 +108,13 @@ protected final void blend(final SnipeData v) { for (int z = brushSizeDoubled; z >= 0; z--) { - if (!(this.excludeAir && newMaterials[x][z] == Material.AIR.getId()) && !(this.excludeWater && (newMaterials[x][z] == Material.WATER.getId() || newMaterials[x][z] == Material.STATIONARY_WATER.getId()))) + if (!(this.excludeAir && newMaterials[x][z] == Material.AIR) && !(this.excludeWater && (newMaterials[x][z] == Material.WATER))) { - if (this.getBlockIdAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][z]) + if (this.getBlockTypeAt(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize + z) != newMaterials[x][z]) { undo.put(this.clampY(this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize + z)); } - this.setBlockIdAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), newMaterials[x][z]); + this.setBlockTypeAt(this.getTargetBlock().getZ() - brushSize + z, this.getTargetBlock().getX() - brushSize + x, this.getTargetBlock().getY(), newMaterials[x][z]); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java index 6738b696..4315415f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java @@ -1,11 +1,8 @@ package com.thevoxelbox.voxelsniper.brush; -import java.util.ArrayList; - import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; - -import org.bukkit.Material; +import com.thevoxelbox.voxelsniper.VTags; import org.bukkit.block.Block; /** @@ -13,28 +10,6 @@ */ public class BlockResetBrush extends Brush { - private static final ArrayList DENIED_UPDATES = new ArrayList(); - - static - { - BlockResetBrush.DENIED_UPDATES.add(Material.SIGN); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_SIGN_POST); - BlockResetBrush.DENIED_UPDATES.add(Material.WALL_SIGN); - BlockResetBrush.DENIED_UPDATES.add(Material.CHEST); - BlockResetBrush.DENIED_UPDATES.add(Material.FURNACE); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_BURNING_FURNACE); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_REDSTONE_TORCH_OFF); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_REDSTONE_TORCH_ON); - BlockResetBrush.DENIED_UPDATES.add(Material.REDSTONE_WIRE); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_DIODE_BLOCK_OFF); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_DIODE_BLOCK_ON); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_WOODEN_DOOR); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_WOOD_DOOR); - BlockResetBrush.DENIED_UPDATES.add(Material.IRON_DOOR); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_IRON_DOOR_BLOCK); - BlockResetBrush.DENIED_UPDATES.add(Material.LEGACY_FENCE_GATE); - } - /** * */ @@ -43,8 +18,7 @@ public BlockResetBrush() this.setName("Block Reset Brush"); } - @SuppressWarnings("deprecation") - private void applyBrush(final SnipeData v) + private void applyBrush(final SnipeData v) { for (int z = -v.getBrushSize(); z <= v.getBrushSize(); z++) { @@ -53,7 +27,7 @@ private void applyBrush(final SnipeData v) for (int y = -v.getBrushSize(); y <= v.getBrushSize(); y++) { final Block block = this.getWorld().getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z); - if (BlockResetBrush.DENIED_UPDATES.contains(block.getType())) + if (VTags.RESET_DENIED_UPDATE.isTagged(block.getType())) { continue; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetSurfaceBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetSurfaceBrush.java deleted file mode 100644 index 3cbc7344..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetSurfaceBrush.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.thevoxelbox.voxelsniper.brush; - -import java.util.ArrayList; - -import com.thevoxelbox.voxelsniper.Message; -import com.thevoxelbox.voxelsniper.SnipeData; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; - -/** - * This brush only looks for solid blocks, and then changes those plus any air blocks touching them. If it works, this brush should be faster than the original - * blockPositionY an amount proportional to the volume of a snipe selection area / the number of blocks touching air in the selection. This is because every solid block - * surrounded blockPositionY others should take equally long to check and not change as it would take MC to change them and then check and find no lighting to update. For - * air blocks surrounded blockPositionY other air blocks, this brush saves about 80-100 checks blockPositionY not updating them or their lighting. And for air blocks touching solids, - * this brush is slower, because it replaces the air once per solid block it is touching. I assume on average this is about 2 blocks. So every air block - * touching a solid negates one air block floating in air. Thus, for selections that have more air blocks surrounded blockPositionY air than air blocks touching solids, - * this brush will be faster, which is almost always the case, especially for undeveloped terrain and for larger brush sizes (unlike the original brush, this - * should only slow down blockPositionY the square of the brush size, not the cube of the brush size). For typical terrain, blockPositionY my calculations, overall speed increase is - * about a factor of 5-6 for a size 20 brush. For a complicated city or ship, etc., this may be only a factor of about 2. In a hypothetical worst case scenario - * of a 3d checkerboard of stone and air every other block, this brush should only be about 1.5x slower than the original brush. Savings increase for larger - * brushes. - * - * @author GavJenks - */ -public class BlockResetSurfaceBrush extends Brush -{ - private static final ArrayList DENIED_UPDATES = new ArrayList(); - - static - { - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.SIGN); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.SIGN_POST); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.WALL_SIGN); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.CHEST); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.FURNACE); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.BURNING_FURNACE); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.REDSTONE_TORCH_OFF); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.REDSTONE_TORCH_ON); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.REDSTONE_WIRE); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.DIODE_BLOCK_OFF); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.DIODE_BLOCK_ON); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.WOODEN_DOOR); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.WOOD_DOOR); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.IRON_DOOR); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.IRON_DOOR_BLOCK); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.FENCE_GATE); - BlockResetSurfaceBrush.DENIED_UPDATES.add(Material.AIR); - } - - /** - * - */ - public BlockResetSurfaceBrush() - { - this.setName("Block Reset Brush Surface Only"); - } - - @SuppressWarnings("deprecation") - private void applyBrush(final SnipeData v) - { - final World world = this.getWorld(); - - for (int z = -v.getBrushSize(); z <= v.getBrushSize(); z++) - { - for (int x = -v.getBrushSize(); x <= v.getBrushSize(); x++) - { - for (int y = -v.getBrushSize(); y <= v.getBrushSize(); y++) - { - - Block block = world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z); - if (BlockResetSurfaceBrush.DENIED_UPDATES.contains(block.getType())) - { - continue; - } - - boolean airFound = false; - - if (world.getBlockAt(this.getTargetBlock().getX() + x + 1, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z).getTypeId() == 0) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x + 1, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z); - final byte oldData = block.getData(); - resetBlock(block, oldData); - airFound = true; - } - - if (world.getBlockAt(this.getTargetBlock().getX() + x - 1, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z).getTypeId() == 0) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x - 1, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z); - final byte oldData = block.getData(); - resetBlock(block, oldData); - airFound = true; - } - - if (world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y + 1, this.getTargetBlock().getZ() + z).getTypeId() == 0) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y + 1, this.getTargetBlock().getZ() + z); - final byte oldData = block.getData(); - resetBlock(block, oldData); - airFound = true; - } - - if (world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y - 1, this.getTargetBlock().getZ() + z).getTypeId() == 0) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y - 1, this.getTargetBlock().getZ() + z); - final byte oldData = block.getData(); - resetBlock(block, oldData); - airFound = true; - } - - if (world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z + 1).getTypeId() == 0) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z + 1); - final byte oldData = block.getData(); - resetBlock(block, oldData); - airFound = true; - } - - if (world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z - 1).getTypeId() == 0) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z - 1); - final byte oldData = block.getData(); - resetBlock(block, oldData); - airFound = true; - } - - if (airFound) - { - block = world.getBlockAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + y, this.getTargetBlock().getZ() + z); - final byte oldData = block.getData(); - resetBlock(block, oldData); - } - } - } - } - } - - @SuppressWarnings("deprecation") - private void resetBlock(Block block, final byte oldData) - { - block.setTypeIdAndData(block.getTypeId(), (byte) ((block.getData() + 1) & 0xf), true); - block.setTypeIdAndData(block.getTypeId(), oldData, true); - } - - @Override - protected final void arrow(final SnipeData v) - { - applyBrush(v); - } - - @Override - protected final void powder(final SnipeData v) - { - applyBrush(v); - } - - @Override - public final void info(final Message vm) - { - vm.brushName(this.getName()); - } - - @Override - public String getPermissionNode() - { - return "voxelsniper.brush.blockresetsurface"; - } -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java index 76995f5e..c7782a88 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/Brush.java @@ -7,9 +7,11 @@ import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; import com.thevoxelbox.voxelsniper.util.BlockWrapper; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; /** * Abstract implementation of the {@link IBrush} interface. @@ -220,10 +222,9 @@ protected final World getWorld() * @param z Z coordinate * @return Type ID of Block at given coordinates in the world of the targeted Block. */ - @SuppressWarnings("deprecation") - protected int getBlockIdAt(int x, int y, int z) + protected Material getBlockTypeAt(int x, int y, int z) { - return getWorld().getBlockTypeIdAt(x, y, z); + return getWorld().getBlockAt(x, y, z).getType(); } /** @@ -234,10 +235,9 @@ protected int getBlockIdAt(int x, int y, int z) * @param z Z coordinate * @return Block Data Value of Block at given coordinates in the world of the targeted Block. */ - @SuppressWarnings("deprecation") - protected byte getBlockDataAt(int x, int y, int z) + protected BlockData getBlockDataAt(int x, int y, int z) { - return this.getWorld().getBlockAt(x, y, z).getData(); + return this.getWorld().getBlockAt(x, y, z).getBlockData(); } /** @@ -264,7 +264,7 @@ protected final void setLastBlock(Block lastBlock) @Deprecated protected final void setBlock(BlockWrapper blockWrapper) { - this.getWorld().getBlockAt(blockWrapper.getX(), blockWrapper.getY(), blockWrapper.getZ()).setTypeId(blockWrapper.getId()); + this.getWorld().getBlockAt(blockWrapper.getX(), blockWrapper.getY(), blockWrapper.getZ()).setBlockData(blockWrapper.getBlockData()); } /** @@ -273,12 +273,11 @@ protected final void setBlock(BlockWrapper blockWrapper) * @param z Z coordinate * @param x X coordinate * @param y Y coordinate - * @param id The id the block will be set to + * @param type The type the block will be set to */ - @SuppressWarnings("deprecation") - protected final void setBlockIdAt(int z, int x, int y, int id) + protected final void setBlockTypeAt(int z, int x, int y, Material type) { - this.getWorld().getBlockAt(x, y, z).setTypeId(id); + this.getWorld().getBlockAt(x, y, z).setType(type); } /** @@ -287,12 +286,10 @@ protected final void setBlockIdAt(int z, int x, int y, int id) * @param x X coordinate * @param y Y coordinate * @param z Z coordinate - * @param id The id the block will be set to - * @param data The data value the block will be set to + * @param blockData The block data the block will be set to */ - @SuppressWarnings("deprecation") - protected final void setBlockIdAndDataAt(int x, int y, int z, int id, byte data) + protected final void setBlockDataAt(int x, int y, int z, BlockData blockData) { - this.getWorld().getBlockAt(x, y, z).setTypeIdAndData(id, data, true); + this.getWorld().getBlockAt(x, y, z).setBlockData(blockData, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/CanyonBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/CanyonBrush.java index 27191ba7..076c4111 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/CanyonBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/CanyonBrush.java @@ -31,8 +31,7 @@ public CanyonBrush() * @param chunk * @param undo */ - @SuppressWarnings("deprecation") - protected final void canyon(final Chunk chunk, final Undo undo) + protected final void canyon(final Chunk chunk, final Undo undo) { for (int x = 0; x < CHUNK_SIZE; x++) { @@ -48,7 +47,7 @@ protected final void canyon(final Chunk chunk, final Undo undo) undo.put(block); undo.put(currentYLevelBlock); - currentYLevelBlock.setTypeId(block.getTypeId(), false); + currentYLevelBlock.setType(block.getType(), false); block.setType(Material.AIR); currentYLevel++; @@ -56,7 +55,7 @@ protected final void canyon(final Chunk chunk, final Undo undo) final Block block = chunk.getBlock(x, 0, z); undo.put(block); - block.setTypeId(Material.BEDROCK.getId()); + block.setType(Material.BEDROCK); for (int y = 1; y < SHIFT_LEVEL_MIN; y++) { diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/CleanSnowBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/CleanSnowBrush.java index cbddd084..fc9e1301 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/CleanSnowBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/CleanSnowBrush.java @@ -45,7 +45,7 @@ private void cleanSnow(final SnipeData v) if ((this.clampY(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, this.getTargetBlock().getZ() + y - brushSize).getType() == Material.SNOW) && ((this.clampY(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize - 1, this.getTargetBlock().getZ() + y - brushSize).getType() == Material.SNOW) || (this.clampY(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize - 1, this.getTargetBlock().getZ() + y - brushSize).getType() == Material.AIR))) { undo.put(this.clampY(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + z, this.getTargetBlock().getZ() + y)); - this.setBlockIdAt(this.getTargetBlock().getZ() + y - brushSize, this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, 0); + this.setBlockTypeAt(this.getTargetBlock().getZ() + y - brushSize, this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, Material.AIR); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/CopyPastaBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/CopyPastaBrush.java index 9cf770fa..83e69e7d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/CopyPastaBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/CopyPastaBrush.java @@ -5,7 +5,9 @@ import com.thevoxelbox.voxelsniper.Undo; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * http://www.voxelwiki.com/minecraft/Voxelsniper#CopyPasta_Brush @@ -24,8 +26,7 @@ public class CopyPastaBrush extends Brush private int[] pastePoint = new int[3]; private int[] minPoint = new int[3]; private int[] offsetPoint = new int[3]; - private int[] blockArray; - private byte[] dataArray; + private BlockData[] blockDataArray; private int[] arraySize = new int[3]; private int pivot = 0; // ccw degrees @@ -37,8 +38,7 @@ public CopyPastaBrush() this.setName("CopyPasta"); } - @SuppressWarnings("deprecation") - private void doCopy(final SnipeData v) + private void doCopy(final SnipeData v) { for (int i = 0; i < 3; i++) { @@ -51,8 +51,7 @@ private void doCopy(final SnipeData v) if (this.numBlocks > 0 && this.numBlocks < CopyPastaBrush.BLOCK_LIMIT) { - this.blockArray = new int[this.numBlocks]; - this.dataArray = new byte[this.numBlocks]; + this.blockDataArray = new BlockData[this.numBlocks]; for (int i = 0; i < this.arraySize[0]; i++) { @@ -61,8 +60,7 @@ private void doCopy(final SnipeData v) for (int k = 0; k < this.arraySize[2]; k++) { final int currentPosition = i + this.arraySize[0] * j + this.arraySize[0] * this.arraySize[1] * k; - this.blockArray[currentPosition] = this.getWorld().getBlockTypeIdAt(this.minPoint[0] + i, this.minPoint[1] + j, this.minPoint[2] + k); - this.dataArray[currentPosition] = this.clampY(this.minPoint[0] + i, this.minPoint[1] + j, this.minPoint[2] + k).getData(); + this.blockDataArray[currentPosition] = this.clampY(this.minPoint[0] + i, this.minPoint[1] + j, this.minPoint[2] + k).getBlockData(); } } } @@ -75,8 +73,7 @@ private void doCopy(final SnipeData v) } } - @SuppressWarnings("deprecation") - private void doPasta(final SnipeData v) + private void doPasta(final SnipeData v) { final Undo undo = new Undo(); @@ -105,13 +102,14 @@ private void doPasta(final SnipeData v) break; } - if (!(this.blockArray[currentPosition] == 0 && !this.pasteAir)) + if (!(this.blockDataArray[currentPosition].getMaterial() == Material.AIR && !this.pasteAir)) { - if (block.getTypeId() != this.blockArray[currentPosition] || block.getData() != this.dataArray[currentPosition]) + BlockData data = this.blockDataArray[currentPosition]; + if (!block.getBlockData().equals(data)) { undo.put(block); } - block.setTypeIdAndData(this.blockArray[currentPosition], this.dataArray[currentPosition], true); + block.setBlockData(data, true); } } } @@ -144,8 +142,7 @@ protected final void arrow(final com.thevoxelbox.voxelsniper.SnipeData v) this.firstPoint = new int[3]; this.secondPoint = new int[3]; this.numBlocks = 0; - this.blockArray = new int[1]; - this.dataArray = new byte[1]; + this.blockDataArray = new BlockData[1]; this.points = 0; v.sendMessage(ChatColor.GRAY + "Points cleared."); break; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java index 1dabe0a5..78504794 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java @@ -40,8 +40,7 @@ public final void info(final Message vm) * @param v * @param targetBlock */ - @SuppressWarnings("deprecation") - private void generateDome(final SnipeData v, final Block targetBlock) + private void generateDome(final SnipeData v, final Block targetBlock) { if (v.getVoxelHeight() == 0) @@ -88,10 +87,10 @@ private void generateDome(final SnipeData v, final Block targetBlock) for (final Vector vector : changeablePositions) { final Block currentTargetBlock = vector.toLocation(this.getTargetBlock().getWorld()).getBlock(); - if (currentTargetBlock.getTypeId() != v.getVoxelId() || currentTargetBlock.getData() != v.getData()) + if (!currentTargetBlock.getBlockData().matches(v.getVoxelData())) { undo.put(currentTargetBlock); - currentTargetBlock.setTypeIdAndData(v.getVoxelId(), v.getData(), true); + currentTargetBlock.setBlockData(v.getVoxelData(), true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/DrainBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/DrainBrush.java index 4d40f24f..aa5dcb24 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/DrainBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/DrainBrush.java @@ -26,13 +26,15 @@ public DrainBrush() this.setName("Drain"); } - @SuppressWarnings("deprecation") - private void drain(final SnipeData v) + private void drain(final SnipeData v) { final int brushSize = v.getBrushSize(); final double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2); final Undo undo = new Undo(); + int tx = this.getTargetBlock().getX(); + int ty = this.getTargetBlock().getY(); + int tz = this.getTargetBlock().getZ(); if (this.disc) { for (int x = brushSize; x >= 0; x--) @@ -43,28 +45,28 @@ private void drain(final SnipeData v) { if ((xSquared + Math.pow(y, 2)) <= brushSizeSquared) { - if (this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.STATIONARY_WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.LAVA.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.STATIONARY_LAVA.getId()) + if (this.getBlockTypeAt(tx + x, ty, tz + y) == Material.WATER || this.getBlockTypeAt(tx + x, ty, tz + y) == Material.LAVA) { - undo.put(this.clampY(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y)); - this.setBlockIdAt(this.getTargetBlock().getZ() + y, this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), Material.AIR.getId()); + undo.put(this.clampY(tx + x, ty, tz + y)); + this.setBlockTypeAt(tz + y, tx + x, ty, Material.AIR); } - if (this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.STATIONARY_WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.LAVA.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.STATIONARY_LAVA.getId()) + if (this.getBlockTypeAt(tx + x, ty, tz - y) == Material.WATER|| this.getBlockTypeAt(tx + x, ty, tz - y) == Material.LAVA) { - undo.put(this.clampY(this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y)); - this.setBlockIdAt(this.getTargetBlock().getZ() - y, this.getTargetBlock().getX() + x, this.getTargetBlock().getY(), Material.AIR.getId()); + undo.put(this.clampY(tx + x, ty, tz - y)); + this.setBlockTypeAt(tz - y, tx + x, ty, Material.AIR); } - if (this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.STATIONARY_WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.LAVA.getId() || this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y) == Material.STATIONARY_LAVA.getId()) + if (this.getBlockTypeAt(tx - x, ty, tz + y) == Material.WATER || this.getBlockTypeAt(tx - x, ty, tz + y) == Material.LAVA) { - undo.put(this.clampY(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() + y)); - this.setBlockIdAt(this.getTargetBlock().getZ() + y, this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), Material.AIR.getId()); + undo.put(this.clampY(tx - x, ty, tz + y)); + this.setBlockTypeAt(tz + y, tx - x, ty, Material.AIR); } - if (this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.STATIONARY_WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.LAVA.getId() || this.getBlockIdAt(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y) == Material.STATIONARY_LAVA.getId()) + if (this.getBlockTypeAt(tx - x, ty, tz - y) == Material.WATER || this.getBlockTypeAt(tx - x, ty, tz - y) == Material.LAVA) { - undo.put(this.clampY(this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - y)); - this.setBlockIdAt(this.getTargetBlock().getZ() - y, this.getTargetBlock().getX() - x, this.getTargetBlock().getY(), Material.AIR.getId()); + undo.put(this.clampY(tx - x, ty, tz - y)); + this.setBlockTypeAt(tz - y, tx - x, ty, Material.AIR); } } } @@ -84,10 +86,14 @@ private void drain(final SnipeData v) { if ((xSquared + Math.pow(z - brushSize, 2) + ySquared) <= brushSizeSquared) { - if (this.getBlockIdAt(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, this.getTargetBlock().getZ() + y - brushSize) == Material.WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, this.getTargetBlock().getZ() + y - brushSize) == Material.STATIONARY_WATER.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, this.getTargetBlock().getZ() + y - brushSize) == Material.LAVA.getId() || this.getBlockIdAt(this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, this.getTargetBlock().getZ() + y - brushSize) == Material.STATIONARY_LAVA.getId()) + int bsx = tx + x - brushSize; + int bsy = ty + z - brushSize; + int bsz = tz + y - brushSize; + if (this.getBlockTypeAt(bsx, bsy, bsz) == Material.WATER || this.getBlockTypeAt(bsx, bsy, bsz) == Material.LAVA) { - undo.put(this.clampY(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + z, this.getTargetBlock().getZ() + y)); - this.setBlockIdAt(this.getTargetBlock().getZ() + y - brushSize, this.getTargetBlock().getX() + x - brushSize, this.getTargetBlock().getY() + z - brushSize, Material.AIR.getId()); + undo.put(this.clampY( + tx + x, ty + z, tz + y)); + this.setBlockTypeAt(bsz, bsx, bsy, Material.AIR); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityBrush.java index 0ef9fdb6..6fbbbd54 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityBrush.java @@ -1,98 +1,96 @@ -package com.thevoxelbox.voxelsniper.brush; - -import com.thevoxelbox.voxelsniper.Message; -import com.thevoxelbox.voxelsniper.SnipeData; - -import org.bukkit.ChatColor; -import org.bukkit.entity.EntityType; - -/** - * http://www.voxelwiki.com/minecraft/Voxelsniper#The_Entity_Brush - * - * @author Piotr - */ -public class EntityBrush extends Brush -{ - private EntityType entityType = EntityType.ZOMBIE; - - /** - * - */ - public EntityBrush() - { - this.setName("Entity"); - } - - private void spawn(final SnipeData v) - { - for (int x = 0; x < v.getBrushSize(); x++) - { - try - { - this.getWorld().spawn(this.getLastBlock().getLocation(), this.entityType.getEntityClass()); - } - catch (final IllegalArgumentException exception) - { - v.sendMessage(ChatColor.RED + "Cannot spawn entity!"); - } - } - } - - @Override - protected final void arrow(final SnipeData v) - { - this.spawn(v); - } - - @Override - protected final void powder(final SnipeData v) - { - this.spawn(v); - } - - @SuppressWarnings("deprecation") - @Override - public final void info(final Message vm) - { - vm.brushMessage(ChatColor.LIGHT_PURPLE + "Entity brush" + " (" + this.entityType.getName() + ")"); - vm.size(); - } - - @SuppressWarnings("deprecation") - @Override - public final void parameters(final String[] par, final SnipeData v) - { - if (par[1].equalsIgnoreCase("info")) - { - String names = ""; - - v.sendMessage(ChatColor.BLUE + "The available entity types are as follows:"); - for (final EntityType currentEntity : EntityType.values()) - { - - names += ChatColor.AQUA + " | " + ChatColor.DARK_GREEN + currentEntity.getName(); - } - names += ChatColor.AQUA + " |"; - v.sendMessage(names); - } - else - { - final EntityType currentEntity = EntityType.fromName(par[1]); - if (currentEntity != null) - { - this.entityType = currentEntity; - v.sendMessage(ChatColor.GREEN + "Entity type set to " + this.entityType.getName()); - } - else - { - v.sendMessage(ChatColor.RED + "This is not a valid entity!"); - } - } - } - - @Override - public String getPermissionNode() - { - return "voxelsniper.brush.entity"; - } -} +package com.thevoxelbox.voxelsniper.brush; + +import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.SnipeData; + +import org.bukkit.ChatColor; +import org.bukkit.entity.EntityType; + +/** + * http://www.voxelwiki.com/minecraft/Voxelsniper#The_Entity_Brush + * + * @author Piotr + */ +public class EntityBrush extends Brush +{ + private EntityType entityType = EntityType.ZOMBIE; + + /** + * + */ + public EntityBrush() + { + this.setName("Entity"); + } + + private void spawn(final SnipeData v) + { + for (int x = 0; x < v.getBrushSize(); x++) + { + try + { + this.getWorld().spawn(this.getLastBlock().getLocation(), this.entityType.getEntityClass()); + } + catch (final IllegalArgumentException exception) + { + v.sendMessage(ChatColor.RED + "Cannot spawn entity!"); + } + } + } + + @Override + protected final void arrow(final SnipeData v) + { + this.spawn(v); + } + + @Override + protected final void powder(final SnipeData v) + { + this.spawn(v); + } + + @Override + public final void info(final Message vm) + { + vm.brushMessage(ChatColor.LIGHT_PURPLE + "Entity brush" + " (" + this.entityType.getName() + ")"); + vm.size(); + } + + @Override + public final void parameters(final String[] par, final SnipeData v) + { + if (par[1].equalsIgnoreCase("info")) + { + String names = ""; + + v.sendMessage(ChatColor.BLUE + "The available entity types are as follows:"); + for (final EntityType currentEntity : EntityType.values()) + { + + names += ChatColor.AQUA + " | " + ChatColor.DARK_GREEN + currentEntity.getName(); + } + names += ChatColor.AQUA + " |"; + v.sendMessage(names); + } + else + { + final EntityType currentEntity = EntityType.fromName(par[1]); + if (currentEntity != null) + { + this.entityType = currentEntity; + v.sendMessage(ChatColor.GREEN + "Entity type set to " + this.entityType.getName()); + } + else + { + v.sendMessage(ChatColor.RED + "This is not a valid entity!"); + } + } + } + + @Override + public String getPermissionNode() + { + return "voxelsniper.brush.entity"; + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/EraserBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/EraserBrush.java index d520b045..6e49531e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/EraserBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/EraserBrush.java @@ -3,8 +3,7 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; -import java.util.EnumSet; -import java.util.Set; +import com.thevoxelbox.voxelsniper.VTags; import org.bukkit.Material; import org.bukkit.World; @@ -18,11 +17,6 @@ public class EraserBrush extends Brush { - private static final Set EXCLUSIVE_MATERIALS = EnumSet.of( - Material.AIR, Material.STONE, Material.GRASS, Material.DIRT, Material.SAND, Material.GRAVEL, Material.SANDSTONE); - private static final Set EXCLUSIVE_LIQUIDS = EnumSet.of( - Material.WATER, Material.STATIONARY_WATER, Material.LAVA, Material.STATIONARY_LAVA); - /** * */ @@ -48,8 +42,7 @@ private void doErase(final SnipeData v, final boolean keepWater) { int currentZ = this.getTargetBlock().getZ() - brushSize + z; Block currentBlock = world.getBlockAt(currentX, currentY, currentZ); - if (EXCLUSIVE_MATERIALS.contains(currentBlock.getType()) - || (keepWater && EXCLUSIVE_LIQUIDS.contains(currentBlock.getType()))) + if (VTags.ERASER_EXCLUSIVE.isTagged(currentBlock.getType()) || (keepWater && VTags.LIQUID.isTagged(currentBlock.getType()))) { continue; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java index 0ddb8b7c..a7b99844 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java @@ -15,6 +15,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.util.ChatPaginator; import org.bukkit.util.Vector; @@ -83,8 +84,7 @@ protected final void arrow(final SnipeData v) this.erosion(v, this.currentPreset); } - @SuppressWarnings("deprecation") - private void erosion(final SnipeData v, final ErosionPreset erosionPreset) + private void erosion(final SnipeData v, final ErosionPreset erosionPreset) { final BlockChangeTracker blockChangeTracker = new BlockChangeTracker(this.getTargetBlock().getWorld()); @@ -104,8 +104,9 @@ private void erosion(final SnipeData v, final ErosionPreset erosionPreset) final Undo undo = new Undo(); for (final BlockWrapper blockWrapper : blockChangeTracker.getAll()) { + System.out.println(blockWrapper.getBlock()); undo.put(blockWrapper.getBlock()); - blockWrapper.getBlock().setTypeIdAndData(blockWrapper.getMaterial().getId(), blockWrapper.getData(), true); + blockWrapper.getBlock().setBlockData(blockWrapper.getBlockData()); } v.owner().storeUndo(undo); @@ -142,7 +143,7 @@ private void fillIteration(final SnipeData v, final ErosionPreset erosionPreset, if (!(relativeBlock.isEmpty() || relativeBlock.isLiquid())) { count++; - final BlockWrapper typeBlock = new BlockWrapper(null, relativeBlock.getMaterial(), relativeBlock.getData()); + final BlockWrapper typeBlock = new BlockWrapper(null, relativeBlock.getBlockData()); if (blockCount.containsKey(typeBlock)) { blockCount.put(typeBlock, blockCount.get(typeBlock) + 1); @@ -154,7 +155,7 @@ private void fillIteration(final SnipeData v, final ErosionPreset erosionPreset, } } - BlockWrapper currentMaterial = new BlockWrapper(null, Material.AIR, (byte) 0); + BlockWrapper currentMaterial = new BlockWrapper(null, Material.AIR.createBlockData()); int amount = 0; for (final BlockWrapper wrapper : blockCount.keySet()) @@ -169,7 +170,7 @@ private void fillIteration(final SnipeData v, final ErosionPreset erosionPreset, if (count >= erosionPreset.getFillFaces()) { - blockChangeTracker.put(currentPosition, new BlockWrapper(currentBlock.getBlock(), currentMaterial.getMaterial(), currentMaterial.getData()), currentIteration); + blockChangeTracker.put(currentPosition, new BlockWrapper(currentBlock.getBlock(), currentMaterial.getBlockData()), currentIteration); } } } @@ -210,7 +211,7 @@ private void erosionIteration(final SnipeData v, final ErosionPreset erosionPres if (count >= erosionPreset.getErosionFaces()) { - blockChangeTracker.put(currentPosition, new BlockWrapper(currentBlock.getBlock(), Material.AIR, (byte) 0), currentIteration); + blockChangeTracker.put(currentPosition, new BlockWrapper(currentBlock.getBlock(), Material.AIR.createBlockData()), currentIteration); } } } @@ -414,21 +415,17 @@ private static final class BlockWrapper { private final Block block; - private final Material material; - private final byte data; + private final BlockData data; - @SuppressWarnings("deprecation") - public BlockWrapper(final Block block) + public BlockWrapper(final Block block) { this.block = block; - this.data = block.getData(); - this.material = block.getType(); + this.data = block.getBlockData(); } - public BlockWrapper(final Block block, final Material material, final byte data) + public BlockWrapper(final Block block, final BlockData data) { this.block = block; - this.material = material; this.data = data; } @@ -443,25 +440,17 @@ public Block getBlock() /** * @return the data */ - public byte getData() + public BlockData getBlockData() { return this.data; } - /** - * @return the material - */ - public Material getMaterial() - { - return this.material; - } - /** * @return if the block is Empty. */ public boolean isEmpty() { - return this.material == Material.AIR; + return this.data.getMaterial() == Material.AIR; } /** @@ -469,12 +458,10 @@ public boolean isEmpty() */ public boolean isLiquid() { - switch (this.material) + switch (this.data.getMaterial()) { case WATER: - case STATIONARY_WATER: case LAVA: - case STATIONARY_LAVA: return true; default: return false; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/ExtrudeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/ExtrudeBrush.java index dcf08d7a..7a2e58b1 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/ExtrudeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/ExtrudeBrush.java @@ -112,14 +112,12 @@ private void extrudeEastOrWest(final SnipeData v, boolean isEast) v.owner().storeUndo(undo); } - @SuppressWarnings("deprecation") - private Undo perform(final Block b1, final Block b2, final SnipeData v, final Undo undo) + private Undo perform(final Block b1, final Block b2, final SnipeData v, final Undo undo) { - if (v.getVoxelList().contains(new int[]{this.getBlockIdAt(b1.getX(), b1.getY(), b1.getZ()), this.getBlockDataAt(b1.getX(), b1.getY(), b1.getZ())})) + if (v.getVoxelList().contains(this.getBlockDataAt(b1.getX(), b1.getY(), b1.getZ()))) { undo.put(b2); - this.setBlockIdAt(b2.getZ(), b2.getX(), b2.getY(), this.getBlockIdAt(b1.getX(), b1.getY(), b1.getZ())); - this.clampY(b2.getX(), b2.getY(), b2.getZ()).setData(this.clampY(b1.getX(), b1.getY(), b1.getZ()).getData()); + this.setBlockDataAt(b2.getZ(), b2.getX(), b2.getY(), this.getBlockDataAt(b1.getX(), b1.getY(), b1.getZ())); } return undo; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/FillDownBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/FillDownBrush.java index 302d5c81..c0b99906 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/FillDownBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/FillDownBrush.java @@ -36,23 +36,23 @@ private void fillDown(final SnipeData v, final Block b) { if (currentXSquared + Math.pow(z, 2) <= brushSizeSquared) { - int y = 0; - boolean found = false; - if(this.fromExisting) { - for(y = -v.getVoxelHeight(); y < v.getVoxelHeight(); y++) { - final Block currentBlock = this.getWorld().getBlockAt( - targetBlock.getX() + x, - targetBlock.getY() + y, - targetBlock.getZ() + z); - if(!currentBlock.isEmpty()) { - found = true; - break; - } - } - if(!found) continue; - y--; - } - for (; y >= -targetBlock.getY(); --y) + int y = 0; + boolean found = false; + if(this.fromExisting) { + for(y = -v.getVoxelHeight(); y < v.getVoxelHeight(); y++) { + final Block currentBlock = this.getWorld().getBlockAt( + targetBlock.getX() + x, + targetBlock.getY() + y, + targetBlock.getZ() + z); + if(!currentBlock.isEmpty()) { + found = true; + break; + } + } + if(!found) continue; + y--; + } + for (; y >= -targetBlock.getY(); --y) { final Block currentBlock = this.getWorld().getBlockAt( targetBlock.getX() + x, @@ -125,13 +125,13 @@ else if (par[i].equalsIgnoreCase("all")) else if (par[i].equalsIgnoreCase("some")) { this.fillLiquid = false; - v.setReplaceId(0); + v.setReplaceInk(""); v.sendMessage(ChatColor.AQUA + "Now only filling air."); } else if (par[i].equalsIgnoreCase("-e")) { - this.fromExisting = !this.fromExisting; - v.sendMessage(ChatColor.AQUA + "Now filling down from " + ((this.fromExisting) ? "existing" : "all") + " blocks."); + this.fromExisting = !this.fromExisting; + v.sendMessage(ChatColor.AQUA + "Now filling down from " + ((this.fromExisting) ? "existing" : "all") + " blocks."); } else { diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/FlatOceanBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/FlatOceanBrush.java index f286b07e..11294f13 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/FlatOceanBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/FlatOceanBrush.java @@ -24,8 +24,7 @@ public FlatOceanBrush() this.setName("FlatOcean"); } - @SuppressWarnings("deprecation") - private void flatOcean(final Chunk chunk) + private void flatOcean(final Chunk chunk) { for (int x = 0; x < CHUNK_SIZE; x++) { @@ -39,11 +38,11 @@ private void flatOcean(final Chunk chunk) } else if (y <= this.waterLevel) { - chunk.getBlock(x, y, z).setTypeId(Material.STATIONARY_WATER.getId(), false); + chunk.getBlock(x, y, z).setType(Material.WATER, false); } else { - chunk.getBlock(x, y, z).setTypeId(Material.AIR.getId(), false); + chunk.getBlock(x, y, z).setType(Material.AIR, false); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java index 86141048..82d2aacf 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java @@ -7,9 +7,12 @@ import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; // Proposal: Use /v and /vr for leave and wood material // or two more parameters -- Monofraps @@ -25,8 +28,8 @@ public class GenerateTreeBrush extends Brush private ArrayList branchBlocks = new ArrayList(); private Undo undo; // If these default values are edited. Remember to change default values in the default preset. - private byte leafType = 0; - private byte woodType = 0; + private BlockData leafData = Material.OAK_LEAVES.createBlockData(); + private BlockData woodData = Material.OAK_WOOD.createBlockData(); private boolean rootFloat = false; private int startHeight = 0; private int rootLength = 9; @@ -54,8 +57,7 @@ public GenerateTreeBrush() } // Branch Creation based on direction chosen from the parameters passed. - @SuppressWarnings("deprecation") - private void branchCreate(final int xDirection, final int zDirection) + private void branchCreate(final int xDirection, final int zDirection) { // Sets branch origin. @@ -88,13 +90,13 @@ private void branchCreate(final int xDirection, final int zDirection) } // Add block to undo function. - if (this.getBlockIdAt(blockPositionX, blockPositionY, blockPositionZ) != Material.LOG.getId()) + if (!Tag.LOGS.isTagged(this.getBlockTypeAt(blockPositionX, blockPositionY, blockPositionZ))) { this.undo.put(this.clampY(blockPositionX, blockPositionY, blockPositionZ)); } // Creates a branch block. - this.clampY(blockPositionX, blockPositionY, blockPositionZ).setTypeIdAndData(Material.LOG.getId(), this.woodType, false); + this.clampY(blockPositionX, blockPositionY, blockPositionZ).setBlockData(this.woodData, false); this.branchBlocks.add(this.clampY(blockPositionX, blockPositionY, blockPositionZ)); } @@ -104,8 +106,7 @@ private void branchCreate(final int xDirection, final int zDirection) blockPositionZ = originZ; } - @SuppressWarnings("deprecation") - private void leafNodeCreate() + private void leafNodeCreate() { // Generates the node size. final int nodeRadius = this.randGenerator.nextInt(this.nodeMax - this.nodeMin + 1) + this.nodeMin; @@ -131,92 +132,92 @@ private void leafNodeCreate() if (this.randGenerator.nextInt(100) >= 30) { // If block is Air, create a leaf block. - if (this.getWorld().getBlockTypeIdAt(blockPositionX + x, blockPositionY + y, blockPositionZ + z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX + x, blockPositionY + y, blockPositionZ + z).getType() == Material.AIR) { // Adds block to undo function. - if (this.getBlockIdAt(blockPositionX + x, blockPositionY + y, blockPositionZ + z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX + x, blockPositionY + y, blockPositionZ + z))) { this.undo.put(this.clampY(blockPositionX + x, blockPositionY + y, blockPositionZ + z)); } // Creates block. - this.clampY(blockPositionX + x, blockPositionY + y, blockPositionZ + z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX + x, blockPositionY + y, blockPositionZ + z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX + x, blockPositionY + y, blockPositionZ - z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX + x, blockPositionY + y, blockPositionZ - z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX + x, blockPositionY + y, blockPositionZ - z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX + x, blockPositionY + y, blockPositionZ - z))) { this.undo.put(this.clampY(blockPositionX + x, blockPositionY + y, blockPositionZ - z)); } - this.clampY(blockPositionX + x, blockPositionY + y, blockPositionZ - z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX + x, blockPositionY + y, blockPositionZ - z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX - x, blockPositionY + y, blockPositionZ + z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX - x, blockPositionY + y, blockPositionZ + z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX - x, blockPositionY + y, blockPositionZ + z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX - x, blockPositionY + y, blockPositionZ + z))) { this.undo.put(this.clampY(blockPositionX - x, blockPositionY + y, blockPositionZ + z)); } - this.clampY(blockPositionX - x, blockPositionY + y, blockPositionZ + z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX - x, blockPositionY + y, blockPositionZ + z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX - x, blockPositionY + y, blockPositionZ - z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX - x, blockPositionY + y, blockPositionZ - z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX - x, blockPositionY + y, blockPositionZ - z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX - x, blockPositionY + y, blockPositionZ - z))) { this.undo.put(this.clampY(blockPositionX - x, blockPositionY + y, blockPositionZ - z)); } - this.clampY(blockPositionX - x, blockPositionY + y, blockPositionZ - z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX - x, blockPositionY + y, blockPositionZ - z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX + x, blockPositionY - y, blockPositionZ + z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX + x, blockPositionY - y, blockPositionZ + z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX + x, blockPositionY - y, blockPositionZ + z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX + x, blockPositionY - y, blockPositionZ + z))) { this.undo.put(this.clampY(blockPositionX + x, blockPositionY - y, blockPositionZ + z)); } - this.clampY(blockPositionX + x, blockPositionY - y, blockPositionZ + z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX + x, blockPositionY - y, blockPositionZ + z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX + x, blockPositionY - y, blockPositionZ - z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX + x, blockPositionY - y, blockPositionZ - z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX + x, blockPositionY - y, blockPositionZ - z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX + x, blockPositionY - y, blockPositionZ - z))) { this.undo.put(this.clampY(blockPositionX + x, blockPositionY - y, blockPositionZ - z)); } - this.clampY(blockPositionX + x, blockPositionY - y, blockPositionZ - z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX + x, blockPositionY - y, blockPositionZ - z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX - x, blockPositionY - y, blockPositionZ + z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX - x, blockPositionY - y, blockPositionZ + z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX - x, blockPositionY - y, blockPositionZ + z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX - x, blockPositionY - y, blockPositionZ + z))) { this.undo.put(this.clampY(blockPositionX - x, blockPositionY - y, blockPositionZ + z)); } - this.clampY(blockPositionX - x, blockPositionY - y, blockPositionZ + z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX - x, blockPositionY - y, blockPositionZ + z).setBlockData(this.leafData, false); } } if (this.randGenerator.nextInt(100) >= 30) { - if (this.getWorld().getBlockTypeIdAt(blockPositionX - x, blockPositionY - y, blockPositionZ - z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX - x, blockPositionY - y, blockPositionZ - z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX - x, blockPositionY - y, blockPositionZ - z) != Material.LEAVES.getId()) + if (!Tag.LEAVES.isTagged(this.getBlockTypeAt(blockPositionX - x, blockPositionY - y, blockPositionZ - z))) { this.undo.put(this.clampY(blockPositionX - x, blockPositionY - y, blockPositionZ - z)); } - this.clampY(blockPositionX - x, blockPositionY - y, blockPositionZ - z).setTypeIdAndData(Material.LEAVES.getId(), this.leafType, false); + this.clampY(blockPositionX - x, blockPositionY - y, blockPositionZ - z).setBlockData(this.leafData, false); } } } @@ -231,8 +232,7 @@ private void leafNodeCreate() * @param xDirection * @param zDirection */ - @SuppressWarnings("deprecation") - private void rootCreate(final int xDirection, final int zDirection) + private void rootCreate(final int xDirection, final int zDirection) { // Sets Origin. final int originX = blockPositionX; @@ -265,12 +265,12 @@ private void rootCreate(final int xDirection, final int zDirection) // If not solid then... // Save for undo function - if (this.getBlockIdAt(blockPositionX, blockPositionY, blockPositionZ) != Material.LOG.getId()) + if (!Tag.LOGS.isTagged(this.getBlockTypeAt(blockPositionX, blockPositionY, blockPositionZ))) { this.undo.put(this.clampY(blockPositionX, blockPositionY, blockPositionZ)); // Place log block. - this.clampY(blockPositionX, blockPositionY, blockPositionZ).setTypeIdAndData(Material.LOG.getId(), this.woodType, false); + this.clampY(blockPositionX, blockPositionY, blockPositionZ).setBlockData(this.woodData, false); } else { @@ -280,7 +280,7 @@ private void rootCreate(final int xDirection, final int zDirection) } // Checks is block below is solid - if (this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.AIR || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.WATER || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.STATIONARY_WATER || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.SNOW || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.LOG) + if (this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.AIR || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.WATER || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.SNOW || Tag.LOGS.isTagged(this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType())) { // Mos down if solid. blockPositionY = blockPositionY - 1; @@ -308,7 +308,7 @@ private void rootCreate(final int xDirection, final int zDirection) blockPositionZ = blockPositionZ + zDirection; } // Checks if new location is solid, if not then move down. - if (this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.AIR || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.WATER || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.STATIONARY_WATER || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.SNOW || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.LOG) + if (this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.AIR || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.WATER || this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType() == Material.SNOW || Tag.LOGS.isTagged(this.clampY(blockPositionX, blockPositionY - 1, blockPositionZ).getType())) { blockPositionY = blockPositionY - 1; } @@ -338,8 +338,7 @@ private void rootGen() this.rootCreate(-1, -1); } - @SuppressWarnings("deprecation") - private void trunkCreate() + private void trunkCreate() { // Creates true circle discs of the set size using the wood type selected. final double bSquared = Math.pow(this.thickness + 0.5, 2); @@ -353,39 +352,39 @@ private void trunkCreate() if ((xSquared + Math.pow(z, 2)) <= bSquared) { // If block is air, then create a block. - if (this.getWorld().getBlockTypeIdAt(blockPositionX + x, blockPositionY, blockPositionZ + z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX + x, blockPositionY, blockPositionZ + z).getType() == Material.AIR) { // Adds block to undo function. - if (this.getBlockIdAt(blockPositionX + x, blockPositionY, blockPositionZ + z) != Material.LOG.getId()) + if (Tag.LOGS.isTagged(this.getBlockTypeAt(blockPositionX + x, blockPositionY, blockPositionZ + z))) { this.undo.put(this.clampY(blockPositionX + x, blockPositionY, blockPositionZ + z)); } // Creates block. - this.clampY(blockPositionX + x, blockPositionY, blockPositionZ + z).setTypeIdAndData(Material.LOG.getId(), this.woodType, false); + this.clampY(blockPositionX + x, blockPositionY, blockPositionZ + z).setBlockData(this.woodData, false); } - if (this.getWorld().getBlockTypeIdAt(blockPositionX + x, blockPositionY, blockPositionZ - z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX + x, blockPositionY, blockPositionZ - z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX + x, blockPositionY, blockPositionZ - z) != Material.LOG.getId()) + if (Tag.LOGS.isTagged(this.getBlockTypeAt(blockPositionX + x, blockPositionY, blockPositionZ - z))) { this.undo.put(this.clampY(blockPositionX + x, blockPositionY, blockPositionZ - z)); } - this.clampY(blockPositionX + x, blockPositionY, blockPositionZ - z).setTypeIdAndData(Material.LOG.getId(), this.woodType, false); + this.clampY(blockPositionX + x, blockPositionY, blockPositionZ - z).setBlockData(this.woodData, false); } - if (this.getWorld().getBlockTypeIdAt(blockPositionX - x, blockPositionY, blockPositionZ + z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX - x, blockPositionY, blockPositionZ + z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX - x, blockPositionY, blockPositionZ + z) != Material.LOG.getId()) + if (Tag.LOGS.isTagged(this.getBlockTypeAt(blockPositionX - x, blockPositionY, blockPositionZ + z))) { this.undo.put(this.clampY(blockPositionX - x, blockPositionY, blockPositionZ + z)); } - this.clampY(blockPositionX - x, blockPositionY, blockPositionZ + z).setTypeIdAndData(Material.LOG.getId(), this.woodType, false); + this.clampY(blockPositionX - x, blockPositionY, blockPositionZ + z).setBlockData(this.woodData, false); } - if (this.getWorld().getBlockTypeIdAt(blockPositionX - x, blockPositionY, blockPositionZ - z) == Material.AIR.getId()) + if (this.getWorld().getBlockAt(blockPositionX - x, blockPositionY, blockPositionZ - z).getType() == Material.AIR) { - if (this.getBlockIdAt(blockPositionX - x, blockPositionY, blockPositionZ - z) != Material.LOG.getId()) + if (Tag.LOGS.isTagged(this.getBlockTypeAt(blockPositionX - x, blockPositionY, blockPositionZ - z))) { this.undo.put(this.clampY(blockPositionX - x, blockPositionY, blockPositionZ - z)); } - this.clampY(blockPositionX - x, blockPositionY, blockPositionZ - z).setTypeIdAndData(Material.LOG.getId(), this.woodType, false); + this.clampY(blockPositionX - x, blockPositionY, blockPositionZ - z).setBlockData(this.woodData, false); } } } @@ -570,6 +569,15 @@ public final void info(final Message vm) vm.brushName(this.getName()); } + private BlockData parseBlock(String param, Tag expected) throws Exception { + BlockData blockData = Bukkit.createBlockData(param); + if (!expected.isTagged(blockData.getMaterial())) { + throw new Exception("Not an accepted material"); + } + + return blockData; + } + @Override public final void parameters(final String[] par, final SnipeData v) { @@ -582,8 +590,8 @@ public final void parameters(final String[] par, final SnipeData v) if (parameter.equalsIgnoreCase("info")) { v.sendMessage(ChatColor.GOLD + "This brush takes the following parameters:"); - v.sendMessage(ChatColor.AQUA + "lt# - leaf type (data value)"); - v.sendMessage(ChatColor.AQUA + "wt# - wood type (data value)"); + v.sendMessage(ChatColor.AQUA + "lt - leaf block"); + v.sendMessage(ChatColor.AQUA + "wt - wood block"); v.sendMessage(ChatColor.AQUA + "tt# - tree thickness (whote number)"); v.sendMessage(ChatColor.AQUA + "rfX - root float (true or false)"); v.sendMessage(ChatColor.AQUA + "sh# - starting height (whole number)"); @@ -608,13 +616,15 @@ public final void parameters(final String[] par, final SnipeData v) } if (parameter.startsWith("lt")) { // Leaf Type - this.leafType = Byte.parseByte(parameter.replace("lt", "")); - v.sendMessage(ChatColor.BLUE + "Leaf Type set to " + this.leafType); + String blockParam = parameter.substring(3); + this.leafData = parseBlock(blockParam, Tag.LEAVES); + v.sendMessage(ChatColor.BLUE + "Leaf Type set to " + blockParam); } else if (parameter.startsWith("wt")) { // Wood Type - this.woodType = Byte.parseByte(parameter.replace("wt", "")); - v.sendMessage(ChatColor.BLUE + "Wood Type set to " + this.woodType); + String blockParam = parameter.substring(3); + this.woodData = parseBlock(blockParam, Tag.LOGS); + v.sendMessage(ChatColor.BLUE + "Wood Type set to " + blockParam); } else if (parameter.startsWith("tt")) { // Tree Thickness @@ -714,8 +724,8 @@ else if (parameter.startsWith("minl")) } else if (parameter.startsWith("default")) { // Default settings. - this.leafType = 0; - this.woodType = 0; + this.leafData = Material.OAK_LEAVES.createBlockData(); + this.woodData = Material.OAK_WOOD.createBlockData(); this.rootFloat = false; this.startHeight = 0; this.rootLength = 9; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java index 6d68ab7b..f7deb7b4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java @@ -1,6 +1,5 @@ package com.thevoxelbox.voxelsniper.brush; -import java.util.ArrayList; import java.util.Random; import com.thevoxelbox.voxelsniper.Message; @@ -22,41 +21,16 @@ public class HeatRayBrush extends Brush { - /** - * @author MikeMatrix - */ - private enum FlameableBlock - { - WOOD(Material.WOOD), SAPLING(Material.SAPLING), LOG(Material.LOG), LEAVES(Material.LEAVES), SPONGE(Material.SPONGE), WEB(Material.WEB), LONG_GRASS(Material.LONG_GRASS), DEAD_BUSH(Material.DEAD_BUSH), WOOL(Material.WOOL), YELLOW_FLOWER(Material.YELLOW_FLOWER), RED_ROSE(Material.RED_ROSE), TORCH(Material.TORCH), FIRE(Material.FIRE), WOOD_STAIRS(Material.WOOD_STAIRS), CROPS(Material.CROPS), SIGN_POST(Material.SIGN_POST), WOODEN_DOOR(Material.WOODEN_DOOR), LADDER(Material.LADDER), WALL_SIGN(Material.WALL_SIGN), WOOD_PLATE(Material.WOOD_PLATE), SNOW(Material.SNOW), ICE(Material.ICE), SUGAR_CANE_BLOCK(Material.SUGAR_CANE_BLOCK), FENCE(Material.FENCE), TRAP_DOOR(Material.TRAP_DOOR), VINE(Material.VINE), FENCE_GATE(Material.FENCE_GATE), WATER_LILLY(Material.WATER_LILY); - - private Material material; - - FlameableBlock(final Material material) - { - this.material = material; - } - } - private static final double REQUIRED_OBSIDIAN_DENSITY = 0.6; private static final double REQUIRED_COBBLE_DENSITY = 0.5; private static final double REQUIRED_FIRE_DENSITY = -0.25; private static final double REQUIRED_AIR_DENSITY = 0; - private static final ArrayList FLAMABLE_BLOCKS = new ArrayList(); - private int octaves = 5; private double frequency = 1; private double amplitude = 0.3; - static - { - for (final FlameableBlock flameableBlock : FlameableBlock.values()) - { - HeatRayBrush.FLAMABLE_BLOCKS.add(flameableBlock.material); - } - } - /** * Default Constructor. @@ -105,7 +79,7 @@ public final void heatRay(final SnipeData v) continue; } - if (HeatRayBrush.FLAMABLE_BLOCKS.contains(currentBlock.getType())) + if (currentBlock.getType().isFlammable()) { undo.put(currentBlock); currentBlock.setType(Material.FIRE); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java index 9ec69a28..67f4f88e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java @@ -3,6 +3,7 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import com.thevoxelbox.voxelsniper.VTags; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -12,8 +13,6 @@ import java.util.ArrayList; import java.util.HashSet; -import java.util.Set; -import java.util.TreeSet; /** * Moves a selection blockPositionY a certain amount. @@ -23,52 +22,6 @@ */ public class MoveBrush extends Brush { - /** - * Breakable Blocks to determine if no-physics should be used. - */ - private static final Set BREAKABLE_MATERIALS = new TreeSet(); - - static - { - MoveBrush.BREAKABLE_MATERIALS.add(Material.SAPLING); - MoveBrush.BREAKABLE_MATERIALS.add(Material.BED_BLOCK); - MoveBrush.BREAKABLE_MATERIALS.add(Material.POWERED_RAIL); - MoveBrush.BREAKABLE_MATERIALS.add(Material.DETECTOR_RAIL); - MoveBrush.BREAKABLE_MATERIALS.add(Material.LONG_GRASS); - MoveBrush.BREAKABLE_MATERIALS.add(Material.DEAD_BUSH); - MoveBrush.BREAKABLE_MATERIALS.add(Material.PISTON_EXTENSION); - MoveBrush.BREAKABLE_MATERIALS.add(Material.YELLOW_FLOWER); - MoveBrush.BREAKABLE_MATERIALS.add(Material.RED_ROSE); - MoveBrush.BREAKABLE_MATERIALS.add(Material.BROWN_MUSHROOM); - MoveBrush.BREAKABLE_MATERIALS.add(Material.RED_MUSHROOM); - MoveBrush.BREAKABLE_MATERIALS.add(Material.TORCH); - MoveBrush.BREAKABLE_MATERIALS.add(Material.FIRE); - MoveBrush.BREAKABLE_MATERIALS.add(Material.CROPS); - MoveBrush.BREAKABLE_MATERIALS.add(Material.SIGN_POST); - MoveBrush.BREAKABLE_MATERIALS.add(Material.WOODEN_DOOR); - MoveBrush.BREAKABLE_MATERIALS.add(Material.LADDER); - MoveBrush.BREAKABLE_MATERIALS.add(Material.RAILS); - MoveBrush.BREAKABLE_MATERIALS.add(Material.WALL_SIGN); - MoveBrush.BREAKABLE_MATERIALS.add(Material.LEVER); - MoveBrush.BREAKABLE_MATERIALS.add(Material.STONE_PLATE); - MoveBrush.BREAKABLE_MATERIALS.add(Material.IRON_DOOR_BLOCK); - MoveBrush.BREAKABLE_MATERIALS.add(Material.WOOD_PLATE); - MoveBrush.BREAKABLE_MATERIALS.add(Material.REDSTONE_TORCH_OFF); - MoveBrush.BREAKABLE_MATERIALS.add(Material.REDSTONE_TORCH_ON); - MoveBrush.BREAKABLE_MATERIALS.add(Material.STONE_BUTTON); - MoveBrush.BREAKABLE_MATERIALS.add(Material.SNOW); - MoveBrush.BREAKABLE_MATERIALS.add(Material.CACTUS); - MoveBrush.BREAKABLE_MATERIALS.add(Material.SUGAR_CANE_BLOCK); - MoveBrush.BREAKABLE_MATERIALS.add(Material.CAKE_BLOCK); - MoveBrush.BREAKABLE_MATERIALS.add(Material.DIODE_BLOCK_OFF); - MoveBrush.BREAKABLE_MATERIALS.add(Material.DIODE_BLOCK_ON); - MoveBrush.BREAKABLE_MATERIALS.add(Material.TRAP_DOOR); - MoveBrush.BREAKABLE_MATERIALS.add(Material.PUMPKIN_STEM); - MoveBrush.BREAKABLE_MATERIALS.add(Material.MELON_STEM); - MoveBrush.BREAKABLE_MATERIALS.add(Material.VINE); - MoveBrush.BREAKABLE_MATERIALS.add(Material.WATER_LILY); - MoveBrush.BREAKABLE_MATERIALS.add(Material.NETHER_WARTS); - } /** * Saved direction. @@ -94,8 +47,7 @@ public MoveBrush() * @param selection * @param direction */ - @SuppressWarnings("deprecation") - private void moveSelection(final SnipeData v, final Selection selection, final int[] direction) + private void moveSelection(final SnipeData v, final Selection selection, final int[] direction) { if (selection.getBlockStates().size() > 0) { @@ -142,8 +94,7 @@ private void moveSelection(final SnipeData v, final Selection selection, final i for (final BlockState blockState : selection.getBlockStates()) { final Block affectedBlock = world.getBlockAt(blockState.getX() + direction[0], blockState.getY() + direction[1], blockState.getZ() + direction[2]); - affectedBlock.setTypeId(blockState.getTypeId(), !MoveBrush.BREAKABLE_MATERIALS.contains(blockState.getType())); - affectedBlock.setData(blockState.getRawData()); + affectedBlock.setBlockData(blockState.getBlockData(), !VTags.POP_OFF.isTagged(blockState.getType())); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/OceanBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/OceanBrush.java index 105e9228..4e8bc22f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/OceanBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/OceanBrush.java @@ -3,14 +3,12 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import com.thevoxelbox.voxelsniper.VTags; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import java.util.LinkedList; -import java.util.List; - /** * http://www.voxelwiki.com/minecraft/Voxelsniper#The_OCEANATOR_5000 * @@ -21,34 +19,6 @@ public class OceanBrush extends Brush private static final int WATER_LEVEL_DEFAULT = 62; // y=63 -- we are using array indices here private static final int WATER_LEVEL_MIN = 12; private static final int LOW_CUT_LEVEL = 12; - private static final List EXCLUDED_MATERIALS = new LinkedList(); - - static - { - EXCLUDED_MATERIALS.add(Material.AIR); - EXCLUDED_MATERIALS.add(Material.SAPLING); - EXCLUDED_MATERIALS.add(Material.WATER); - EXCLUDED_MATERIALS.add(Material.STATIONARY_WATER); - EXCLUDED_MATERIALS.add(Material.LAVA); - EXCLUDED_MATERIALS.add(Material.STATIONARY_LAVA); - EXCLUDED_MATERIALS.add(Material.LOG); - EXCLUDED_MATERIALS.add(Material.LEAVES); - EXCLUDED_MATERIALS.add(Material.YELLOW_FLOWER); - EXCLUDED_MATERIALS.add(Material.RED_ROSE); - EXCLUDED_MATERIALS.add(Material.RED_MUSHROOM); - EXCLUDED_MATERIALS.add(Material.BROWN_MUSHROOM); - EXCLUDED_MATERIALS.add(Material.MELON_BLOCK); - EXCLUDED_MATERIALS.add(Material.MELON_STEM); - EXCLUDED_MATERIALS.add(Material.PUMPKIN); - EXCLUDED_MATERIALS.add(Material.PUMPKIN_STEM); - EXCLUDED_MATERIALS.add(Material.COCOA); - EXCLUDED_MATERIALS.add(Material.SNOW); - EXCLUDED_MATERIALS.add(Material.SNOW_BLOCK); - EXCLUDED_MATERIALS.add(Material.ICE); - EXCLUDED_MATERIALS.add(Material.SUGAR_CANE_BLOCK); - EXCLUDED_MATERIALS.add(Material.LONG_GRASS); - EXCLUDED_MATERIALS.add(Material.SNOW); - } private int waterLevel = WATER_LEVEL_DEFAULT; private boolean coverFloor = false; @@ -66,7 +36,7 @@ private int getHeight(final int bx, final int bz) for (int y = this.getWorld().getHighestBlockYAt(bx, bz); y > 0; y--) { final Material material = this.clampY(bx, y, bz).getType(); - if (!EXCLUDED_MATERIALS.contains(material)) + if (!VTags.OCEAN_EXCLUDED.isTagged(material)) { return y; } @@ -78,8 +48,7 @@ private int getHeight(final int bx, final int bz) * @param v * @param undo */ - @SuppressWarnings("deprecation") - protected final void oceanator(final SnipeData v, final Undo undo) + protected final void oceanator(final SnipeData v, final Undo undo) { final World world = this.getWorld(); @@ -113,14 +82,14 @@ protected final void oceanator(final SnipeData v, final Undo undo) for (int y = this.waterLevel; y > newSeaFloorLevel; y--) { final Block block = world.getBlockAt(x, y, z); - if (!block.getType().equals(Material.STATIONARY_WATER)) + if (!block.getType().equals(Material.WATER)) { // do not put blocks into the undo we already put into if (!block.getType().equals(Material.AIR)) { undo.put(block); } - block.setType(Material.STATIONARY_WATER); + block.setType(Material.WATER); } } @@ -128,10 +97,10 @@ protected final void oceanator(final SnipeData v, final Undo undo) if (this.coverFloor && (newSeaFloorLevel < this.waterLevel)) { Block block = world.getBlockAt(x, newSeaFloorLevel, z); - if (block.getTypeId() != v.getVoxelId()) + if (block.getType() != v.getVoxelMat()) { undo.put(block); - block.setTypeId(v.getVoxelId()); + block.setType(v.getVoxelMat()); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java index 997f4433..34f0e88f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java @@ -2,6 +2,7 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; +import com.thevoxelbox.voxelsniper.VTags; import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -37,21 +38,21 @@ private void overlay(final SnipeData v) { // check if column is valid // column is valid if it has no solid block right above the clicked layer - final int materialId = this.getBlockIdAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + 1, this.getTargetBlock().getZ() + z); - if (isIgnoredBlock(materialId)) + final Material material = this.getBlockTypeAt(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + 1, this.getTargetBlock().getZ() + z); + if (isIgnoredBlock(material)) { if ((Math.pow(x, 2) + Math.pow(z, 2)) <= brushSizeSquared) { for (int y = this.getTargetBlock().getY(); y > 0; y--) { // check for surface - final int layerBlockId = this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z); - if (!isIgnoredBlock(layerBlockId)) + final Material layerBlock = this.getBlockTypeAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z); + if (!isIgnoredBlock(layerBlock)) { for (int currentDepth = y; y - currentDepth < depth; currentDepth--) { - final int currentBlockId = this.getBlockIdAt(this.getTargetBlock().getX() + x, currentDepth, this.getTargetBlock().getZ() + z); - if (isOverrideableMaterial(currentBlockId)) + final Material currentBlock = this.getBlockTypeAt(this.getTargetBlock().getX() + x, currentDepth, this.getTargetBlock().getZ() + z); + if (isOverrideableMaterial(currentBlock)) { this.current.perform(this.clampY(this.getTargetBlock().getX() + x, currentDepth, this.getTargetBlock().getZ() + z)); } @@ -67,37 +68,19 @@ private void overlay(final SnipeData v) v.owner().storeUndo(this.current.getUndo()); } - @SuppressWarnings("deprecation") - private boolean isIgnoredBlock(int materialId) + private boolean isIgnoredBlock(Material material) { - return materialId == 9 || materialId == 8 || Material.getMaterial(materialId).isTransparent() || materialId == Material.CACTUS.getId(); + return material == Material.WATER || material.isTransparent() || material == Material.CACTUS; } - @SuppressWarnings("deprecation") - private boolean isOverrideableMaterial(int materialId) + private boolean isOverrideableMaterial(Material material) { - if (allBlocks && !(materialId == Material.AIR.getId())) + if (allBlocks && !(material == Material.AIR)) { return true; } - switch (materialId) - { - case 1: - case 2: - case 3: - case 12: - case 13: - case 24: - case 48: - case 82: - case 49: - case 78: - return true; - - default: - return false; - } + return VTags.NATURAL.isTagged(material); } private void overlayTwo(final SnipeData v) @@ -117,40 +100,22 @@ private void overlayTwo(final SnipeData v) { // if haven't already found the surface in this column if ((Math.pow(x, 2) + Math.pow(z, 2)) <= brushSizeSquared) { // if inside of the column... - if (this.getBlockIdAt(this.getTargetBlock().getX() + x, y - 1, this.getTargetBlock().getZ() + z) != 0) + if (this.getBlockTypeAt(this.getTargetBlock().getX() + x, y - 1, this.getTargetBlock().getZ() + z) != Material.AIR) { // if not a floating block (like one of Notch'world pools) - if (this.getBlockIdAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z) == 0) + if (this.getBlockTypeAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z) == Material.AIR) { // must start at surface... this prevents it filling stuff in if // you click in a wall and it starts out below surface. if (!this.allBlocks) { // if the override parameter has not been activated, go to the switch that filters out manmade stuff. - switch (this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)) - { - case 1: - case 2: - case 3: - case 12: - case 13: - case 14: - case 15: - case 16: - case 24: - case 48: - case 82: - case 49: - case 78: - for (int d = 1; (d < this.depth + 1); d++) - { - this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify - // in parameters - memory[x + brushSize][z + brushSize] = 1; // stop it from checking any other blocks in this vertical 1x1 column. - } - surfaceFound = true; - break; - - default: - break; + if (VTags.NATURAL.isTagged(this.getBlockTypeAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z))) { + for (int d = 1; (d < this.depth + 1); d++) + { + this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify + // in parameters + memory[x + brushSize][z + brushSize] = 1; // stop it from checking any other blocks in this vertical 1x1 column. + } + surfaceFound = true; } } else diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java index 40bc1249..445db696 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java @@ -3,7 +3,9 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import java.util.HashSet; @@ -100,45 +102,39 @@ private void getSurface(final SnipeData v) */ private boolean isSurface(final int x, final int y, final int z) { - return this.getBlockIdAt(x, y, z) != 0 && ((this.getBlockIdAt(x, y - 1, z) == 0) || (this.getBlockIdAt(x, y + 1, z) == 0) || (this.getBlockIdAt(x + 1, y, z) == 0) || (this.getBlockIdAt(x - 1, y, z) == 0) || (this.getBlockIdAt(x, y, z + 1) == 0) || (this.getBlockIdAt(x, y, z - 1) == 0)); + return this.getBlockTypeAt(x, y, z) != Material.AIR && ((this.getBlockTypeAt(x, y - 1, z) == Material.AIR) || (this.getBlockTypeAt(x, y + 1, z) == Material.AIR) || (this.getBlockTypeAt(x + 1, y, z) == Material.AIR) || (this.getBlockTypeAt(x - 1, y, z) == Material.AIR) || (this.getBlockTypeAt(x, y, z + 1) == Material.AIR) || (this.getBlockTypeAt(x, y, z - 1) == Material.AIR)); } - @SuppressWarnings("deprecation") - private void setBlock(final BlockWrapper block) + private void setBlock(final BlockWrapper block) { final Block currentBlock = this.clampY(block.getX(), block.getY() + (int) (this.vh * block.getStr()), block.getZ()); - if (this.getBlockIdAt(block.getX(), block.getY() - 1, block.getZ()) == 0) + if (this.getBlockTypeAt(block.getX(), block.getY() - 1, block.getZ()) == Material.AIR) { - currentBlock.setTypeId(block.getId()); - currentBlock.setData(block.getD()); + currentBlock.setBlockData(block.getBD()); for (int y = block.getY(); y < currentBlock.getY(); y++) { - this.setBlockIdAt(block.getZ(), block.getX(), y, 0); + this.setBlockTypeAt(block.getZ(), block.getX(), y, Material.AIR); } } else { - currentBlock.setTypeId(block.getId()); - currentBlock.setData(block.getD()); + currentBlock.setBlockData(block.getBD()); for (int y = block.getY() - 1; y < currentBlock.getY(); y++) { final Block current = this.clampY(block.getX(), y, block.getZ()); - current.setTypeId(block.getId()); - current.setData(block.getD()); + current.setBlockData(block.getBD()); } } } - @SuppressWarnings("deprecation") - private void setBlockDown(final BlockWrapper block) + private void setBlockDown(final BlockWrapper block) { final Block currentBlock = this.clampY(block.getX(), block.getY() + (int) (this.vh * block.getStr()), block.getZ()); - currentBlock.setTypeId(block.getId()); - currentBlock.setData(block.getD()); + currentBlock.setBlockData(block.getBD()); for (int y = block.getY(); y > currentBlock.getY(); y--) { - this.setBlockIdAt(block.getZ(), block.getX(), y, 0); + this.setBlockTypeAt(block.getZ(), block.getX(), y, Material.AIR); } // } } @@ -165,8 +161,7 @@ else if (this.vh < 0) } } - @SuppressWarnings("deprecation") - @Override + @Override protected final void powder(final SnipeData v) { this.vh = v.getVoxelHeight(); @@ -179,7 +174,7 @@ protected final void powder(final SnipeData v) double str; final double brushSizeSquared = Math.pow(v.getBrushSize() + 0.5, 2); - int id; + Material mat; // Are we pulling up ? if (this.vh > 0) @@ -206,7 +201,7 @@ protected final void powder(final SnipeData v) final double volume = zSquared + xSquared + (y * y); // Is this in the range of the brush? - if (volume <= brushSizeSquared && this.getWorld().getBlockTypeIdAt(actualX, this.getTargetBlock().getY() + y, actualZ) != 0) + if (volume <= brushSizeSquared && this.getWorld().getBlockAt(actualX, this.getTargetBlock().getY() + y, actualZ).getType() != Material.AIR) { int actualY = this.getTargetBlock().getY() + y; @@ -216,7 +211,7 @@ protected final void powder(final SnipeData v) lastStr = (int) (this.vh * str); lastY = actualY + lastStr; - this.clampY(actualX, lastY, actualZ).setTypeId(this.getWorld().getBlockTypeIdAt(actualX, actualY, actualZ)); + this.clampY(actualX, lastY, actualZ).setType(this.getWorld().getBlockAt(actualX, actualY, actualZ).getType()); if (str == 1) { @@ -231,10 +226,10 @@ protected final void powder(final SnipeData v) } lastStr = (int) (this.vh * str); newY = actualY + lastStr; - id = this.getWorld().getBlockTypeIdAt(actualX, actualY, actualZ); + mat = this.getWorld().getBlockAt(actualX, actualY, actualZ).getType(); for (int i = newY; i < lastY; i++) { - this.clampY(actualX, i, actualZ).setTypeId(id); + this.clampY(actualX, i, actualZ).setType(mat); } lastY = newY; actualY--; @@ -258,20 +253,20 @@ protected final void powder(final SnipeData v) for (int y = -v.getBrushSize(); y <= v.getBrushSize(); y++) { double volume = (xSquared + Math.pow(y, 2) + zSquared); - if (volume <= brushSizeSquared && this.getWorld().getBlockTypeIdAt(actualX, this.getTargetBlock().getY() + y, actualZ) != 0) + if (volume <= brushSizeSquared && this.getWorld().getBlockAt(actualX, this.getTargetBlock().getY() + y, actualZ).getType() != Material.AIR) { final int actualY = this.getTargetBlock().getY() + y; lastY = actualY + (int) (this.vh * this.getStr(volume / brushSizeSquared)); - this.clampY(actualX, lastY, actualZ).setTypeId(this.getWorld().getBlockTypeIdAt(actualX, actualY, actualZ)); + this.clampY(actualX, lastY, actualZ).setType(this.getWorld().getBlockAt(actualX, actualY, actualZ).getType()); y++; volume = (xSquared + Math.pow(y, 2) + zSquared); while (volume <= brushSizeSquared) { final int blockY = this.getTargetBlock().getY() + y + (int) (this.vh * this.getStr(volume / brushSizeSquared)); - final int blockId = this.getWorld().getBlockTypeIdAt(actualX, this.getTargetBlock().getY() + y, actualZ); + final Material mat2 = this.getWorld().getBlockAt(actualX, this.getTargetBlock().getY() + y, actualZ).getType(); for (int i = blockY; i < lastY; i++) { - this.clampY(actualX, i, actualZ).setTypeId(blockId); + this.clampY(actualX, i, actualZ).setType(mat2); } lastY = blockY; y++; @@ -291,8 +286,7 @@ protected final void powder(final SnipeData v) private final class BlockWrapper { - private final int id; - private final byte d; + private final BlockData bd; private final double str; private final int x; private final int y; @@ -302,11 +296,9 @@ private final class BlockWrapper * @param block * @param st */ - @SuppressWarnings("deprecation") - public BlockWrapper(final Block block, final double st) + public BlockWrapper(final Block block, final double st) { - this.id = block.getTypeId(); - this.d = block.getData(); + this.bd = block.getBlockData(); this.x = block.getX(); this.y = block.getY(); this.z = block.getZ(); @@ -314,19 +306,11 @@ public BlockWrapper(final Block block, final double st) } /** - * @return the d - */ - public byte getD() - { - return this.d; - } - - /** - * @return the id + * @return the bd */ - public int getId() + public BlockData getBD() { - return this.id; + return this.bd; } /** diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/PunishBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/PunishBrush.java index 527bf277..c06d8754 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/PunishBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/PunishBrush.java @@ -1,377 +1,376 @@ -package com.thevoxelbox.voxelsniper.brush; - -import com.thevoxelbox.voxelsniper.Message; -import com.thevoxelbox.voxelsniper.SnipeData; -import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.Vector; - -import java.util.List; -import java.util.Random; - -/** - * http://www.voxelwiki.com/minecraft/Voxelsniper#Punish_Brush - * - * @author Monofraps - * @author Deamon - * @author MikeMatrix - */ -public class PunishBrush extends PerformBrush -{ - private static final int MAXIMAL_RANDOM_TELEPORTATION_RANGE = 400; - private static final int TICKS_PER_SECOND = 20; - private static final int INFINIPUNISH_SIZE = -3; - private static final int DEFAULT_PUNISH_LEVEL = 10; - private static final int DEFAULT_PUSNIH_DURATION = 60; - private Punishment punishment = Punishment.FIRE; - private int punishLevel = DEFAULT_PUNISH_LEVEL; - private int punishDuration = DEFAULT_PUSNIH_DURATION; - private boolean specificPlayer = false; - private String punishPlayerName = ""; - private boolean hypnoAffectLandscape = false; - private boolean hitsSelf = false; - - /** - * Default Constructor. - */ - public PunishBrush() - { - this.setName("Punish"); - } - - @SuppressWarnings("deprecation") - private void applyPunishment(final LivingEntity entity, final SnipeData v) - { - switch (this.punishment) - { - case FIRE: - entity.setFireTicks(PunishBrush.TICKS_PER_SECOND * this.punishDuration); - break; - case LIGHTNING: - entity.getWorld().strikeLightning(entity.getLocation()); - break; - case BLINDNESS: - entity.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case DRUNK: - entity.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case SLOW: - entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case JUMP: - entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case ABSORPTION: - entity.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case DAMAGE_RESISTANCE: - entity.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case FAST_DIGGING: - entity.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case FIRE_RESISTANCE: - entity.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case HEAL: - entity.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case HEALTH_BOOST: - entity.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case HUNGER: - entity.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case INCREASE_DAMAGE: - entity.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case INVISIBILITY: - entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case NIGHT_VISION: - entity.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case POISON: - entity.addPotionEffect(new PotionEffect(PotionEffectType.POISON, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case REGENERATION: - entity.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case SATURATION: - entity.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case SLOW_DIGGING: - entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case SPEED: - entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case WATER_BREATHING: - entity.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case WEAKNESS: - entity.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case WITHER: - entity.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case KILL: - entity.setHealth(0d); - break; - case RANDOMTP: - final Random random = new Random(); - final Location targetLocation = entity.getLocation(); - targetLocation.setX(targetLocation.getX() + (random.nextInt(MAXIMAL_RANDOM_TELEPORTATION_RANGE) - (MAXIMAL_RANDOM_TELEPORTATION_RANGE / 2))); - targetLocation.setZ(targetLocation.getZ() + (random.nextInt(PunishBrush.MAXIMAL_RANDOM_TELEPORTATION_RANGE) - PunishBrush.MAXIMAL_RANDOM_TELEPORTATION_RANGE / 2)); - entity.teleport(targetLocation); - break; - case ALL_POTION: - entity.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - entity.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel), true); - break; - case FORCE: - final Vector playerVector = this.getTargetBlock().getLocation().toVector(); - final Vector direction = entity.getLocation().toVector().clone(); - direction.subtract(playerVector); - final double length = direction.length(); - final double stregth = (1 - (length / v.getBrushSize())) * this.punishLevel; - direction.normalize(); - direction.multiply(stregth); - entity.setVelocity(direction); - break; - case HYPNO: - if (entity instanceof Player) - { - final Location location = entity.getLocation(); - Location target = location.clone(); - for (int z = this.punishLevel; z >= -this.punishLevel; z--) - { - for (int x = this.punishLevel; x >= -this.punishLevel; x--) - { - for (int y = this.punishLevel; y >= -this.punishLevel; y--) - { - target.setX(location.getX() + x); - target.setY(location.getY() + y); - target.setZ(location.getZ() + z); - if (this.hypnoAffectLandscape && target.getBlock().getType() == Material.AIR) - { - continue; - } - target = location.clone(); - target.add(x, y, z); - ((Player) entity).sendBlockChange(target, v.getVoxelId(), v.getData()); - } - } - } - } - break; - default: - Bukkit.getLogger().warning("Could not determine the punishment of punish brush!"); - break; - } - } - - @Override - protected final void arrow(final SnipeData v) - { - if (!v.owner().getPlayer().hasPermission("voxelsniper.punish")) - { - v.sendMessage("The server says no!"); - return; - } - - this.punishDuration = v.getVoxelHeight(); - this.punishLevel = v.getcCen(); - - if (this.specificPlayer) - { - final Player punishedPlayer = Bukkit.getPlayer(this.punishPlayerName); - if (punishedPlayer == null) - { - v.sendMessage("No player " + this.punishPlayerName + " found."); - return; - } - - this.applyPunishment(punishedPlayer, v); - return; - } - - final int brushSizeSquare = v.getBrushSize() * v.getBrushSize(); - final Location targetLocation = new Location(v.getWorld(), this.getTargetBlock().getX(), this.getTargetBlock().getY(), this.getTargetBlock().getZ()); - - final List entities = v.getWorld().getLivingEntities(); - int numPunishApps = 0; - for (final LivingEntity entity : entities) - { - if (v.owner().getPlayer() != entity || hitsSelf) - { - if (v.getBrushSize() >= 0) - { - try - { - if (entity.getLocation().distanceSquared(targetLocation) <= brushSizeSquare) - { - numPunishApps++; - this.applyPunishment(entity, v); - } - } - catch (final Exception exception) - { - exception.printStackTrace(); - v.sendMessage("An error occured."); - return; - } - } - else if (v.getBrushSize() == PunishBrush.INFINIPUNISH_SIZE) - { - numPunishApps++; - this.applyPunishment(entity, v); - } - } - } - v.sendMessage(ChatColor.DARK_RED + "Punishment applied to " + numPunishApps + " living entities."); - } - - @Override - protected final void powder(final SnipeData v) - { - if (!v.owner().getPlayer().hasPermission("voxelsniper.punish")) - { - v.sendMessage("The server says no!"); - return; - } - - final int brushSizeSquare = v.getBrushSize() * v.getBrushSize(); - final Location targetLocation = new Location(v.getWorld(), this.getTargetBlock().getX(), this.getTargetBlock().getY(), this.getTargetBlock().getZ()); - - final List entities = v.getWorld().getLivingEntities(); - - for (final LivingEntity entity : entities) - { - if (entity.getLocation().distanceSquared(targetLocation) < brushSizeSquare) - { - entity.setFireTicks(0); - entity.removePotionEffect(PotionEffectType.BLINDNESS); - entity.removePotionEffect(PotionEffectType.CONFUSION); - entity.removePotionEffect(PotionEffectType.SLOW); - entity.removePotionEffect(PotionEffectType.JUMP); - } - } - - } - - @Override - public final void info(final Message vm) - { - vm.brushName(this.getName()); - vm.custom(ChatColor.GREEN + "Punishment: " + this.punishment.toString()); - vm.size(); - vm.center(); - } - - @Override - public final void parameters(final String[] par, final SnipeData v) - { - for (int i = 1; i < par.length; i++) - { - final String parameter = par[i].toLowerCase(); - - if (parameter.equalsIgnoreCase("info")) - { - v.sendMessage(ChatColor.GOLD + "Punish Brush Options:"); - v.sendMessage(ChatColor.AQUA + "Punishments can be set via /b p [punishment]"); - v.sendMessage(ChatColor.AQUA + "Punishment level can be set with /vc [level]"); - v.sendMessage(ChatColor.AQUA + "Punishment duration in seconds can be set with /vh [duration]"); - v.sendMessage(ChatColor.AQUA + "Parameter -toggleHypnoLandscape will make Hypno punishment only affect landscape."); - v.sendMessage(ChatColor.AQUA + "Parameter -toggleSM [playername] will make punishbrush only affect that player."); - v.sendMessage(ChatColor.AQUA + "Parameter -toggleSelf will toggle whether you get hit as well."); - v.sendMessage(ChatColor.AQUA + "Available Punishment Options:"); - final StringBuilder punishmentOptions = new StringBuilder(); - for (final Punishment punishment : Punishment.values()) - { - if (punishmentOptions.length() != 0) - { - punishmentOptions.append(" | "); - } - punishmentOptions.append(punishment.name()); - } - v.sendMessage(ChatColor.GOLD + punishmentOptions.toString()); - return; - } - else if (parameter.equalsIgnoreCase("-toggleSM")) - { - this.specificPlayer = !this.specificPlayer; - if (this.specificPlayer) - { - try - { - this.punishPlayerName = par[++i]; - } - catch (final IndexOutOfBoundsException exception) - { - v.sendMessage(ChatColor.AQUA + "You have to specify a player name after -toggleSM if you want to turn the specific player feature on."); - } - } - } - else if (parameter.equalsIgnoreCase("-toggleSelf")) - { - this.hitsSelf = !this.hitsSelf; - if (hitsSelf) - { - v.sendMessage(ChatColor.AQUA + "Your punishments will now affect you too!"); - } - else - { - v.sendMessage(ChatColor.AQUA + "Your punishments will no longer affect you!"); - } - } - else if (parameter.equalsIgnoreCase("-toggleHypnoLandscape")) - { - this.hypnoAffectLandscape = !this.hypnoAffectLandscape; - } - else - { - try - { - this.punishment = Punishment.valueOf(parameter.toUpperCase()); - v.sendMessage(ChatColor.AQUA + this.punishment.name().toLowerCase() + " punishment selected."); - } - catch (final IllegalArgumentException exception) - { - v.sendMessage(ChatColor.AQUA + "No such Punishment."); - } - } - } - - } - - /** - * @author Monofraps - */ - private enum Punishment - { - // Monofraps - FIRE, LIGHTNING, BLINDNESS, DRUNK, KILL, RANDOMTP, ALL_POTION, - // Deamon - SLOW, JUMP, ABSORPTION, DAMAGE_RESISTANCE, FAST_DIGGING, FIRE_RESISTANCE, HEAL, HEALTH_BOOST, HUNGER, INCREASE_DAMAGE, INVISIBILITY, NIGHT_VISION, POISON, REGENERATION, - SATURATION, SLOW_DIGGING, SPEED, WATER_BREATHING, WEAKNESS, WITHER, - // MikeMatrix - FORCE, HYPNO - } - - @Override - public String getPermissionNode() - { - return "voxelsniper.brush.punish"; - } -} +package com.thevoxelbox.voxelsniper.brush; + +import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.SnipeData; +import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.Random; + +/** + * http://www.voxelwiki.com/minecraft/Voxelsniper#Punish_Brush + * + * @author Monofraps + * @author Deamon + * @author MikeMatrix + */ +public class PunishBrush extends PerformBrush +{ + private static final int MAXIMAL_RANDOM_TELEPORTATION_RANGE = 400; + private static final int TICKS_PER_SECOND = 20; + private static final int INFINIPUNISH_SIZE = -3; + private static final int DEFAULT_PUNISH_LEVEL = 10; + private static final int DEFAULT_PUSNIH_DURATION = 60; + private Punishment punishment = Punishment.FIRE; + private int punishLevel = DEFAULT_PUNISH_LEVEL; + private int punishDuration = DEFAULT_PUSNIH_DURATION; + private boolean specificPlayer = false; + private String punishPlayerName = ""; + private boolean hypnoAffectLandscape = false; + private boolean hitsSelf = false; + + /** + * Default Constructor. + */ + public PunishBrush() + { + this.setName("Punish"); + } + + private void applyPunishment(final LivingEntity entity, final SnipeData v) + { + switch (this.punishment) + { + case FIRE: + entity.setFireTicks(PunishBrush.TICKS_PER_SECOND * this.punishDuration); + break; + case LIGHTNING: + entity.getWorld().strikeLightning(entity.getLocation()); + break; + case BLINDNESS: + entity.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case DRUNK: + entity.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case SLOW: + entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case JUMP: + entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case ABSORPTION: + entity.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case DAMAGE_RESISTANCE: + entity.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case FAST_DIGGING: + entity.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case FIRE_RESISTANCE: + entity.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case HEAL: + entity.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case HEALTH_BOOST: + entity.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case HUNGER: + entity.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case INCREASE_DAMAGE: + entity.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case INVISIBILITY: + entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case NIGHT_VISION: + entity.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case POISON: + entity.addPotionEffect(new PotionEffect(PotionEffectType.POISON, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case REGENERATION: + entity.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case SATURATION: + entity.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case SLOW_DIGGING: + entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case SPEED: + entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case WATER_BREATHING: + entity.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case WEAKNESS: + entity.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case WITHER: + entity.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case KILL: + entity.setHealth(0d); + break; + case RANDOMTP: + final Random random = new Random(); + final Location targetLocation = entity.getLocation(); + targetLocation.setX(targetLocation.getX() + (random.nextInt(MAXIMAL_RANDOM_TELEPORTATION_RANGE) - (MAXIMAL_RANDOM_TELEPORTATION_RANGE / 2))); + targetLocation.setZ(targetLocation.getZ() + (random.nextInt(PunishBrush.MAXIMAL_RANDOM_TELEPORTATION_RANGE) - PunishBrush.MAXIMAL_RANDOM_TELEPORTATION_RANGE / 2)); + entity.teleport(targetLocation); + break; + case ALL_POTION: + entity.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + entity.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + entity.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, PunishBrush.TICKS_PER_SECOND * this.punishDuration, this.punishLevel)); + break; + case FORCE: + final Vector playerVector = this.getTargetBlock().getLocation().toVector(); + final Vector direction = entity.getLocation().toVector().clone(); + direction.subtract(playerVector); + final double length = direction.length(); + final double stregth = (1 - (length / v.getBrushSize())) * this.punishLevel; + direction.normalize(); + direction.multiply(stregth); + entity.setVelocity(direction); + break; + case HYPNO: + if (entity instanceof Player) + { + final Location location = entity.getLocation(); + Location target = location.clone(); + for (int z = this.punishLevel; z >= -this.punishLevel; z--) + { + for (int x = this.punishLevel; x >= -this.punishLevel; x--) + { + for (int y = this.punishLevel; y >= -this.punishLevel; y--) + { + target.setX(location.getX() + x); + target.setY(location.getY() + y); + target.setZ(location.getZ() + z); + if (this.hypnoAffectLandscape && target.getBlock().getType() == Material.AIR) + { + continue; + } + target = location.clone(); + target.add(x, y, z); + ((Player) entity).sendBlockChange(target, v.getVoxelData()); + } + } + } + } + break; + default: + Bukkit.getLogger().warning("Could not determine the punishment of punish brush!"); + break; + } + } + + @Override + protected final void arrow(final SnipeData v) + { + if (!v.owner().getPlayer().hasPermission("voxelsniper.punish")) + { + v.sendMessage("The server says no!"); + return; + } + + this.punishDuration = v.getVoxelHeight(); + this.punishLevel = v.getcCen(); + + if (this.specificPlayer) + { + final Player punishedPlayer = Bukkit.getPlayer(this.punishPlayerName); + if (punishedPlayer == null) + { + v.sendMessage("No player " + this.punishPlayerName + " found."); + return; + } + + this.applyPunishment(punishedPlayer, v); + return; + } + + final int brushSizeSquare = v.getBrushSize() * v.getBrushSize(); + final Location targetLocation = new Location(v.getWorld(), this.getTargetBlock().getX(), this.getTargetBlock().getY(), this.getTargetBlock().getZ()); + + final List entities = v.getWorld().getLivingEntities(); + int numPunishApps = 0; + for (final LivingEntity entity : entities) + { + if (v.owner().getPlayer() != entity || hitsSelf) + { + if (v.getBrushSize() >= 0) + { + try + { + if (entity.getLocation().distanceSquared(targetLocation) <= brushSizeSquare) + { + numPunishApps++; + this.applyPunishment(entity, v); + } + } + catch (final Exception exception) + { + exception.printStackTrace(); + v.sendMessage("An error occured."); + return; + } + } + else if (v.getBrushSize() == PunishBrush.INFINIPUNISH_SIZE) + { + numPunishApps++; + this.applyPunishment(entity, v); + } + } + } + v.sendMessage(ChatColor.DARK_RED + "Punishment applied to " + numPunishApps + " living entities."); + } + + @Override + protected final void powder(final SnipeData v) + { + if (!v.owner().getPlayer().hasPermission("voxelsniper.punish")) + { + v.sendMessage("The server says no!"); + return; + } + + final int brushSizeSquare = v.getBrushSize() * v.getBrushSize(); + final Location targetLocation = new Location(v.getWorld(), this.getTargetBlock().getX(), this.getTargetBlock().getY(), this.getTargetBlock().getZ()); + + final List entities = v.getWorld().getLivingEntities(); + + for (final LivingEntity entity : entities) + { + if (entity.getLocation().distanceSquared(targetLocation) < brushSizeSquare) + { + entity.setFireTicks(0); + entity.removePotionEffect(PotionEffectType.BLINDNESS); + entity.removePotionEffect(PotionEffectType.CONFUSION); + entity.removePotionEffect(PotionEffectType.SLOW); + entity.removePotionEffect(PotionEffectType.JUMP); + } + } + + } + + @Override + public final void info(final Message vm) + { + vm.brushName(this.getName()); + vm.custom(ChatColor.GREEN + "Punishment: " + this.punishment.toString()); + vm.size(); + vm.center(); + } + + @Override + public final void parameters(final String[] par, final SnipeData v) + { + for (int i = 1; i < par.length; i++) + { + final String parameter = par[i].toLowerCase(); + + if (parameter.equalsIgnoreCase("info")) + { + v.sendMessage(ChatColor.GOLD + "Punish Brush Options:"); + v.sendMessage(ChatColor.AQUA + "Punishments can be set via /b p [punishment]"); + v.sendMessage(ChatColor.AQUA + "Punishment level can be set with /vc [level]"); + v.sendMessage(ChatColor.AQUA + "Punishment duration in seconds can be set with /vh [duration]"); + v.sendMessage(ChatColor.AQUA + "Parameter -toggleHypnoLandscape will make Hypno punishment only affect landscape."); + v.sendMessage(ChatColor.AQUA + "Parameter -toggleSM [playername] will make punishbrush only affect that player."); + v.sendMessage(ChatColor.AQUA + "Parameter -toggleSelf will toggle whether you get hit as well."); + v.sendMessage(ChatColor.AQUA + "Available Punishment Options:"); + final StringBuilder punishmentOptions = new StringBuilder(); + for (final Punishment punishment : Punishment.values()) + { + if (punishmentOptions.length() != 0) + { + punishmentOptions.append(" | "); + } + punishmentOptions.append(punishment.name()); + } + v.sendMessage(ChatColor.GOLD + punishmentOptions.toString()); + return; + } + else if (parameter.equalsIgnoreCase("-toggleSM")) + { + this.specificPlayer = !this.specificPlayer; + if (this.specificPlayer) + { + try + { + this.punishPlayerName = par[++i]; + } + catch (final IndexOutOfBoundsException exception) + { + v.sendMessage(ChatColor.AQUA + "You have to specify a player name after -toggleSM if you want to turn the specific player feature on."); + } + } + } + else if (parameter.equalsIgnoreCase("-toggleSelf")) + { + this.hitsSelf = !this.hitsSelf; + if (hitsSelf) + { + v.sendMessage(ChatColor.AQUA + "Your punishments will now affect you too!"); + } + else + { + v.sendMessage(ChatColor.AQUA + "Your punishments will no longer affect you!"); + } + } + else if (parameter.equalsIgnoreCase("-toggleHypnoLandscape")) + { + this.hypnoAffectLandscape = !this.hypnoAffectLandscape; + } + else + { + try + { + this.punishment = Punishment.valueOf(parameter.toUpperCase()); + v.sendMessage(ChatColor.AQUA + this.punishment.name().toLowerCase() + " punishment selected."); + } + catch (final IllegalArgumentException exception) + { + v.sendMessage(ChatColor.AQUA + "No such Punishment."); + } + } + } + + } + + /** + * @author Monofraps + */ + private enum Punishment + { + // Monofraps + FIRE, LIGHTNING, BLINDNESS, DRUNK, KILL, RANDOMTP, ALL_POTION, + // Deamon + SLOW, JUMP, ABSORPTION, DAMAGE_RESISTANCE, FAST_DIGGING, FIRE_RESISTANCE, HEAL, HEALTH_BOOST, HUNGER, INCREASE_DAMAGE, INVISIBILITY, NIGHT_VISION, POISON, REGENERATION, + SATURATION, SLOW_DIGGING, SPEED, WATER_BREATHING, WEAKNESS, WITHER, + // MikeMatrix + FORCE, HYPNO + } + + @Override + public String getPermissionNode() + { + return "voxelsniper.brush.punish"; + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/RandomErodeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/RandomErodeBrush.java index 73c36728..34db27b1 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/RandomErodeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/RandomErodeBrush.java @@ -3,7 +3,9 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import java.util.Random; @@ -71,8 +73,7 @@ private boolean erode(final int x, final int y, final int z) } } - @SuppressWarnings("deprecation") - private boolean fill(final int x, final int y, final int z) + private boolean fill(final int x, final int y, final int z) { if (this.snap[x][y][z].isSolid()) { @@ -83,32 +84,32 @@ private boolean fill(final int x, final int y, final int z) int d = 0; if (this.snap[x + 1][y][z].isSolid()) { - this.snap[x][y][z].setId(this.snap[x + 1][y][z].getNativeBlock().getTypeId()); + this.snap[x][y][z].setBD(this.snap[x + 1][y][z].getNativeBlock().getBlockData()); d++; } if (this.snap[x - 1][y][z].isSolid()) { - this.snap[x][y][z].setId(this.snap[x - 1][y][z].getNativeBlock().getTypeId()); + this.snap[x][y][z].setBD(this.snap[x - 1][y][z].getNativeBlock().getBlockData()); d++; } if (this.snap[x][y + 1][z].isSolid()) { - this.snap[x][y][z].setId(this.snap[x][y + 1][z].getNativeBlock().getTypeId()); + this.snap[x][y][z].setBD(this.snap[x][y + 1][z].getNativeBlock().getBlockData()); d++; } if (this.snap[x][y - 1][z].isSolid()) { - this.snap[x][y][z].setId(this.snap[x][y - 1][z].getNativeBlock().getTypeId()); + this.snap[x][y][z].setBD(this.snap[x][y - 1][z].getNativeBlock().getBlockData()); d++; } if (this.snap[x][y][z + 1].isSolid()) { - this.snap[x][y][z].setId(this.snap[x][y][z + 1].getNativeBlock().getTypeId()); + this.snap[x][y][z].setBD(this.snap[x][y][z + 1].getNativeBlock().getBlockData()); d++; } if (this.snap[x][y][z - 1].isSolid()) { - this.snap[x][y][z].setId(this.snap[x][y][z - 1].getNativeBlock().getTypeId()); + this.snap[x][y][z].setBD(this.snap[x][y][z - 1].getNativeBlock().getBlockData()); d++; } return (d >= this.fillFace); @@ -170,8 +171,7 @@ private void getMatrix() } } - @SuppressWarnings("deprecation") - private void rerosion(final SnipeData v) + private void rerosion(final SnipeData v) { final Undo undo = new Undo(); @@ -197,7 +197,7 @@ private void rerosion(final SnipeData v) { if (this.erode(x, y, z)) { - this.snap[x][y][z].getNativeBlock().setTypeId(0); + this.snap[x][y][z].getNativeBlock().setType(Material.AIR); } } } @@ -228,7 +228,7 @@ private void rerosion(final SnipeData v) { if (this.fill(x, y, z)) { - this.snap[x][y][z].getNativeBlock().setTypeId(this.snap[x][y][z].getId()); + this.snap[x][y][z].getNativeBlock().setType(this.snap[x][y][z].getBD().getMaterial()); } } } @@ -243,7 +243,7 @@ private void rerosion(final SnipeData v) { for (final BlockWrapper block : firstSnapString) { - if (block.getI() != block.getNativeBlock().getTypeId()) + if (block.getBD().getMaterial() != block.getNativeBlock().getType()) { undo.put(block.getNativeBlock()); } @@ -254,8 +254,7 @@ private void rerosion(final SnipeData v) v.owner().storeUndo(undo); } - @SuppressWarnings("deprecation") - private void rfilling(final SnipeData v) + private void rfilling(final SnipeData v) { final Undo undo = new Undo(); @@ -279,7 +278,7 @@ private void rfilling(final SnipeData v) { if (this.fill(x, y, z)) { - this.snap[x][y][z].getNativeBlock().setTypeId(this.snap[x][y][z].getId()); + this.snap[x][y][z].getNativeBlock().setType(this.snap[x][y][z].getBD().getMaterial()); } } } @@ -310,7 +309,7 @@ private void rfilling(final SnipeData v) { if (this.erode(x, y, z)) { - this.snap[x][y][z].getNativeBlock().setTypeId(0); + this.snap[x][y][z].getNativeBlock().setType(Material.AIR); } } } @@ -325,7 +324,7 @@ private void rfilling(final SnipeData v) { for (final BlockWrapper block : firstSnapString) { - if (block.getI() != block.getNativeBlock().getTypeId()) + if (block.getBD().getMaterial() != block.getNativeBlock().getType()) { undo.put(block.getNativeBlock()); } @@ -393,17 +392,15 @@ private class BlockWrapper { private boolean solid; private Block nativeBlock; - private int id; - private int i; + private BlockData bd; /** * @param bl */ - @SuppressWarnings("deprecation") - public BlockWrapper(final Block bl) + public BlockWrapper(final Block bl) { this.setNativeBlock(bl); - this.setI(bl.getTypeId()); + this.setBD(bl.getBlockData()); switch (bl.getType()) { case AIR: @@ -414,13 +411,6 @@ public BlockWrapper(final Block bl) this.setSolid(false); break; - case STATIONARY_WATER: - this.setSolid(false); - break; - - case STATIONARY_LAVA: - this.setSolid(false); - break; case LAVA: this.setSolid(false); break; @@ -450,25 +440,16 @@ public void setNativeBlock(Block nativeBlock) this.nativeBlock = nativeBlock; } - public int getId() + public BlockData getBD() { - return id; + return bd; } - public void setId(int id) + public void setBD(BlockData bd) { - this.id = id; + this.bd = bd; } - public int getI() - { - return i; - } - - public void setI(int i) - { - this.i = i; - } } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java index 9b47e671..be01c12f 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java @@ -5,7 +5,9 @@ import com.thevoxelbox.voxelsniper.util.BlockWrapper; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Piotr @@ -26,8 +28,7 @@ public Rot2DBrush() this.setName("2D Rotation"); } - @SuppressWarnings("deprecation") - private void getMatrix() + private void getMatrix() { this.brushSize = (this.bSize * 2) + 1; @@ -51,7 +52,7 @@ private void getMatrix() { final Block block = this.clampY(sx, sy, sz); // why is this not sx + x, sy + y sz + z? this.snap[x][z][y] = new BlockWrapper(block); - block.setTypeId(0); + block.setType(Material.AIR); sy++; } } @@ -92,11 +93,11 @@ private void rotate(final SnipeData v) final int yy = currentY - this.bSize; final BlockWrapper block = this.snap[x][currentY][y]; - if (block.getId() == 0) + if (block.getBlockData().getMaterial() == Material.AIR) { continue; } - this.setBlockIdAndDataAt(this.getTargetBlock().getX() + (int) newX, this.getTargetBlock().getY() + yy, this.getTargetBlock().getZ() + (int) newZ, block.getId(), block.getData()); + this.setBlockDataAt(this.getTargetBlock().getX() + (int) newX, this.getTargetBlock().getY() + yy, this.getTargetBlock().getZ() + (int) newZ, block.getBlockData()); } } } @@ -120,36 +121,29 @@ private void rotate(final SnipeData v) { final int fy = y + this.getTargetBlock().getY() - this.bSize; - final int a = this.getBlockIdAt(fx + 1, fy, fz); - final byte aData = this.getBlockDataAt(fx + 1, fy, fz); - final int d = this.getBlockIdAt(fx - 1, fy, fz); - final byte dData = this.getBlockDataAt(fx - 1, fy, fz); - final int c = this.getBlockIdAt(fx, fy, fz + 1); - final int b = this.getBlockIdAt(fx, fy, fz - 1); - final byte bData = this.getBlockDataAt(fx, fy, fz - 1); + final BlockData a = this.getBlockDataAt(fx + 1, fy, fz); + final BlockData d = this.getBlockDataAt(fx - 1, fy, fz); + final BlockData c = this.getBlockDataAt(fx, fy, fz + 1); + final BlockData b = this.getBlockDataAt(fx, fy, fz - 1); - int winner; - byte winnerData; + BlockData winner; if (a == b || a == c || a == d) { // I figure that since we are already narrowing it down to ONLY the holes left behind, it // should // be fine to do all 5 checks needed to be legit about it. winner = a; - winnerData = aData; } else if (b == d || c == d) { winner = d; - winnerData = dData; } else { winner = b; // blockPositionY making this default, it will also automatically cover situations where B = C; - winnerData = bData; } - this.setBlockIdAndDataAt(fx, fy, fz, winner, winnerData); + this.setBlockDataAt(fx, fy, fz, winner); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java index bc181590..73633c20 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java @@ -6,7 +6,9 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Gavjenks, hack job from the other 2d rotation brush blockPositionY piotr @@ -29,8 +31,7 @@ public Rot2DvertBrush() this.setName("2D Rotation"); } - @SuppressWarnings("deprecation") - private void getMatrix() + private void getMatrix() { this.brushSize = (this.bSize * 2) + 1; @@ -52,7 +53,7 @@ private void getMatrix() { final Block block = this.clampY(sx, sy, sz); // why is this not sx + x, sy + y sz + z? this.snap[x][y][z] = new BlockWrapper(block); - block.setTypeId(0); + block.setType(Material.AIR); sy++; } @@ -93,11 +94,11 @@ private void rotate(final SnipeData v) final int yy = y - this.bSize; final BlockWrapper block = this.snap[y][x][z]; - if (block.getId() == 0) + if (block.getBlockData().getMaterial() == Material.AIR) { continue; } - this.setBlockIdAndDataAt(this.getTargetBlock().getX() + yy, this.getTargetBlock().getY() + (int) newX, this.getTargetBlock().getZ() + (int) newZ, block.getId(), block.getData()); + this.setBlockDataAt(this.getTargetBlock().getX() + yy, this.getTargetBlock().getY() + (int) newX, this.getTargetBlock().getZ() + (int) newZ, block.getBlockData()); } } } @@ -121,36 +122,29 @@ private void rotate(final SnipeData v) { final int fy = y + this.getTargetBlock().getY() - this.bSize; - final int a = this.getBlockIdAt(fy, fx + 1, fz); - final byte aData = this.getBlockDataAt(fy, fx + 1, fz); - final int d = this.getBlockIdAt(fy, fx - 1, fz); - final byte dData = this.getBlockDataAt(fy, fx - 1, fz); - final int c = this.getBlockIdAt(fy, fx, fz + 1); - final int b = this.getBlockIdAt(fy, fx, fz - 1); - final byte bData = this.getBlockDataAt(fy, fx, fz - 1); + final BlockData a = this.getBlockDataAt(fy, fx + 1, fz); + final BlockData d = this.getBlockDataAt(fy, fx - 1, fz); + final BlockData c = this.getBlockDataAt(fy, fx, fz + 1); + final BlockData b = this.getBlockDataAt(fy, fx, fz - 1); - int winner; - byte winnerData; + BlockData winner; if (a == b || a == c || a == d) { // I figure that since we are already narrowing it down to ONLY the holes left behind, it // should // be fine to do all 5 checks needed to be legit about it. winner = a; - winnerData = aData; } else if (b == d || c == d) { winner = d; - winnerData = dData; } else { winner = b; // blockPositionY making this default, it will also automatically cover situations where B = C; - winnerData = bData; } - this.setBlockIdAndDataAt(fy, fx, fz, winner, winnerData); + this.setBlockDataAt(fy, fx, fz, winner); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java index 2afaf056..5784d214 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java @@ -6,7 +6,9 @@ import com.thevoxelbox.voxelsniper.util.BlockWrapper; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @@ -86,8 +88,7 @@ else if (parameter.startsWith("y")) } } - @SuppressWarnings("deprecation") - private void getMatrix() + private void getMatrix() { // only need to do once. But y needs to change + sphere final double brushSizeSquared = Math.pow(this.bSize + 0.5, 2); this.brushSize = (this.bSize * 2) + 1; @@ -114,7 +115,7 @@ private void getMatrix() { final Block block = this.clampY(sx, sz, sz); this.snap[x][y][z] = new BlockWrapper(block); - block.setTypeId(0); + block.setType(Material.AIR); sz++; } } @@ -176,11 +177,11 @@ private void rotate(final SnipeData v) // after all three, though. final BlockWrapper block = this.snap[x][y][z]; - if (block.getId() == 0) + if (block.getBlockData().getMaterial() == Material.AIR) { continue; } - this.setBlockIdAndDataAt(this.getTargetBlock().getX() + (int) newxyX, this.getTargetBlock().getY() + (int) newyzY, this.getTargetBlock().getZ() + (int) newyzZ, block.getId(), block.getData()); + this.setBlockDataAt(this.getTargetBlock().getX() + (int) newxyX, this.getTargetBlock().getY() + (int) newyzY, this.getTargetBlock().getZ() + (int) newyzZ, block.getBlockData()); } } } @@ -204,36 +205,29 @@ private void rotate(final SnipeData v) { // smart fill stuff final int fy = y + this.getTargetBlock().getY() - this.bSize; - final int a = this.getBlockIdAt(fx + 1, fy, fz); - final byte aData = this.getBlockDataAt(fx + 1, fy, fz); - final int d = this.getBlockIdAt(fx - 1, fy, fz); - final byte dData = this.getBlockDataAt(fx - 1, fy, fz); - final int c = this.getBlockIdAt(fx, fy, fz + 1); - final int b = this.getBlockIdAt(fx, fy, fz - 1); - final byte bData = this.getBlockDataAt(fx, fy, fz - 1); + final BlockData a = this.getBlockDataAt(fx + 1, fy, fz); + final BlockData d = this.getBlockDataAt(fx - 1, fy, fz); + final BlockData c = this.getBlockDataAt(fx, fy, fz + 1); + final BlockData b = this.getBlockDataAt(fx, fy, fz - 1); - int winner; - byte winnerData; + BlockData winner; if (a == b || a == c || a == d) { // I figure that since we are already narrowing it down to ONLY the holes left behind, it // should // be fine to do all 5 checks needed to be legit about it. winner = a; - winnerData = aData; } else if (b == d || c == d) { winner = d; - winnerData = dData; } else { winner = b; // blockPositionY making this default, it will also automatically cover situations where B = C; - winnerData = bData; } - this.setBlockIdAndDataAt(fx, fy, fz, winner, winnerData); + this.setBlockDataAt(fx, fy, fz, winner); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/RulerBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/RulerBrush.java index ebb800c0..8359fd96 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/RulerBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/RulerBrush.java @@ -5,6 +5,7 @@ import com.thevoxelbox.voxelsniper.Undo; import org.bukkit.ChatColor; +import org.bukkit.block.data.BlockData; import org.bukkit.util.Vector; /** @@ -32,7 +33,7 @@ public RulerBrush() @Override protected final void arrow(final SnipeData v) { - final int voxelMaterialId = v.getVoxelId(); + final BlockData voxelData = v.getVoxelData(); this.coords = this.getTargetBlock().getLocation().toVector(); if (this.xOff == 0 && this.yOff == 0 && this.zOff == 0) @@ -45,7 +46,7 @@ protected final void arrow(final SnipeData v) final Undo undo = new Undo(); undo.put(this.clampY(this.getTargetBlock().getX() + this.xOff, this.getTargetBlock().getY() + this.yOff, this.getTargetBlock().getZ() + this.zOff)); - this.setBlockIdAt(this.getTargetBlock().getZ() + this.zOff, this.getTargetBlock().getX() + this.xOff, this.getTargetBlock().getY() + this.yOff, voxelMaterialId); + this.setBlockDataAt(this.getTargetBlock().getZ() + this.zOff, this.getTargetBlock().getX() + this.xOff, this.getTargetBlock().getY() + this.yOff, voxelData); v.owner().storeUndo(undo); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/ScannerBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/ScannerBrush.java index 84f2453c..cb44fc27 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/ScannerBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/ScannerBrush.java @@ -143,19 +143,17 @@ private void scan(final SnipeData v, final BlockFace bf) } } - @SuppressWarnings("deprecation") - @Override + @Override protected final void arrow(final SnipeData v) { - this.checkFor = Material.getMaterial(v.getVoxelId()); + this.checkFor = v.getVoxelMat(); this.scan(v, this.getTargetBlock().getFace(this.getLastBlock())); } - @SuppressWarnings("deprecation") - @Override + @Override protected final void powder(final SnipeData v) { - this.checkFor = Material.getMaterial(v.getVoxelId()); + this.checkFor = v.getVoxelMat(); this.scan(v, this.getTargetBlock().getFace(this.getLastBlock())); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneFlipBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneFlipBrush.java index 204ab289..5e810baf 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneFlipBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneFlipBrush.java @@ -6,6 +6,8 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Repeater; /** * @author Voxel @@ -56,35 +58,22 @@ private boolean set(final Block bl) } } - @SuppressWarnings("deprecation") - private void perform(final Block bl) + private void perform(final Block bl) { - if (bl.getType() == Material.DIODE_BLOCK_ON || bl.getType() == Material.DIODE_BLOCK_OFF) + if (bl.getType() == Material.REPEATER) { + Repeater repeater = (Repeater)bl.getBlockData(); + BlockFace facing = repeater.getFacing(); if (this.northSouth) { - if ((bl.getData() % 4) == 1) - { - this.undo.put(bl); - bl.setData((byte) (bl.getData() + 2)); - } - else if ((bl.getData() % 4) == 3) - { - this.undo.put(bl); - bl.setData((byte) (bl.getData() - 2)); + if(facing == BlockFace.NORTH || facing == BlockFace.SOUTH) { + repeater.setFacing(facing.getOppositeFace()); } } else { - if ((bl.getData() % 4) == 2) - { - this.undo.put(bl); - bl.setData((byte) (bl.getData() - 2)); - } - else if ((bl.getData() % 4) == 0) - { - this.undo.put(bl); - bl.setData((byte) (bl.getData() + 2)); + if(facing == BlockFace.WEST || facing == BlockFace.EAST) { + repeater.setFacing(facing.getOppositeFace()); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneRotateBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneRotateBrush.java index 5707b248..91fa353e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneRotateBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/SetRedstoneRotateBrush.java @@ -6,6 +6,8 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Repeater; /** * @author Voxel @@ -55,13 +57,32 @@ private boolean set(final Block bl) } } - @SuppressWarnings("deprecation") - private void perform(final Block bl) + private void perform(final Block bl) { - if (bl.getType() == Material.DIODE_BLOCK_ON || bl.getType() == Material.DIODE_BLOCK_OFF) + if (bl.getType() == Material.REPEATER) { this.undo.put(bl); - bl.setData((((bl.getData() % 4) + 1 < 5) ? (byte) (bl.getData() + 1) : (byte) (bl.getData() - 4))); + Repeater repeater = (Repeater)bl.getBlockData(); + BlockFace newFace; + switch(repeater.getFacing()) + { + case NORTH: + newFace = BlockFace.EAST; + break; + case EAST: + newFace = BlockFace.SOUTH; + break; + case SOUTH: + newFace = BlockFace.WEST; + break; + case WEST: + newFace = BlockFace.NORTH; + break; + default: + newFace = null; + break; + } + repeater.setFacing(newFace); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java index 7004b2d3..8c7a8378 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java @@ -5,6 +5,7 @@ import com.thevoxelbox.voxelsniper.Undo; import org.bukkit.ChatColor; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * THIS BRUSH SHOULD NOT USE PERFORMERS. @@ -27,8 +28,8 @@ private void bShell(final SnipeData v, Block targetBlock) { final int brushSize = v.getBrushSize(); final int brushSizeDoubled = 2 * brushSize; - final int[][][] oldMaterials = new int[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer - final int[][][] newMaterials = new int[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; // Array that holds the hollowed materials + final BlockData[][][] oldMaterials = new BlockData[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer + final BlockData[][][] newMaterials = new BlockData[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; // Array that holds the hollowed materials int blockPositionX = targetBlock.getX(); int blockPositionY = targetBlock.getY(); @@ -40,7 +41,7 @@ private void bShell(final SnipeData v, Block targetBlock) { for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][y][z] = this.getBlockIdAt(blockPositionX - brushSize - 1 + x, blockPositionY - brushSize - 1 + y, blockPositionZ - brushSize - 1 + z); + oldMaterials[x][y][z] = this.getBlockDataAt(blockPositionX - brushSize - 1 + x, blockPositionY - brushSize - 1 + y, blockPositionZ - brushSize - 1 + z); } } } @@ -68,34 +69,34 @@ private void bShell(final SnipeData v, Block targetBlock) { temp = 0; - if (oldMaterials[x + 1 + 1][y + 1][z + 1] == v.getReplaceId()) + if (oldMaterials[x + 1 + 1][y + 1][z + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1 - 1][y + 1][z + 1] == v.getReplaceId()) + if (oldMaterials[x + 1 - 1][y + 1][z + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][y + 1 + 1][z + 1] == v.getReplaceId()) + if (oldMaterials[x + 1][y + 1 + 1][z + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][y + 1 - 1][z + 1] == v.getReplaceId()) + if (oldMaterials[x + 1][y + 1 - 1][z + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][y + 1][z + 1 + 1] == v.getReplaceId()) + if (oldMaterials[x + 1][y + 1][z + 1 + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][y + 1][z + 1 - 1] == v.getReplaceId()) + if (oldMaterials[x + 1][y + 1][z + 1 - 1].matches(v.getReplaceData())) { temp++; } if (temp == 0) { - newMaterials[x][y][z] = v.getVoxelId(); + newMaterials[x][y][z] = v.getVoxelData(); } } } @@ -117,11 +118,11 @@ private void bShell(final SnipeData v, Block targetBlock) { if (xSquared + ySquared + Math.pow(z - brushSize, 2) <= rSquared) { - if (this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - brushSize + y, blockPositionZ - brushSize + z) != newMaterials[x][y][z]) + if (this.getBlockDataAt(blockPositionX - brushSize + x, blockPositionY - brushSize + y, blockPositionZ - brushSize + z) != newMaterials[x][y][z]) { undo.put(this.clampY(blockPositionX - brushSize + x, blockPositionY - brushSize + y, blockPositionZ - brushSize + z)); } - this.setBlockIdAt(blockPositionZ - brushSize + z, blockPositionX - brushSize + x, blockPositionY - brushSize + y, newMaterials[x][y][z]); + this.setBlockDataAt(blockPositionZ - brushSize + z, blockPositionX - brushSize + x, blockPositionY - brushSize + y, newMaterials[x][y][z]); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java index a139bbe8..0c73ab9b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java @@ -26,8 +26,7 @@ public ShellSetBrush() this.setName("Shell Set"); } - @SuppressWarnings("deprecation") - private boolean set(final Block bl, final SnipeData v) + private boolean set(final Block bl, final SnipeData v) { if (this.block == null) { @@ -63,31 +62,31 @@ private boolean set(final Block bl, final SnipeData v) { for (int z = lowZ; z <= highZ; z++) { - if (this.getWorld().getBlockTypeIdAt(x, y, z) == v.getReplaceId()) + if (this.getWorld().getBlockAt(x, y, z).getType() == v.getReplaceData().getMaterial()) { continue; } - else if (this.getWorld().getBlockTypeIdAt(x + 1, y, z) == v.getReplaceId()) + else if (this.getWorld().getBlockAt(x + 1, y, z).getType() == v.getReplaceData().getMaterial()) { continue; } - else if (this.getWorld().getBlockTypeIdAt(x - 1, y, z) == v.getReplaceId()) + else if (this.getWorld().getBlockAt(x - 1, y, z).getType() == v.getReplaceData().getMaterial()) { continue; } - else if (this.getWorld().getBlockTypeIdAt(x, y, z + 1) == v.getReplaceId()) + else if (this.getWorld().getBlockAt(x, y, z + 1).getType() == v.getReplaceData().getMaterial()) { continue; } - else if (this.getWorld().getBlockTypeIdAt(x, y, z - 1) == v.getReplaceId()) + else if (this.getWorld().getBlockAt(x, y, z - 1).getType() == v.getReplaceData().getMaterial()) { continue; } - else if (this.getWorld().getBlockTypeIdAt(x, y + 1, z) == v.getReplaceId()) + else if (this.getWorld().getBlockAt(x, y + 1, z).getType() == v.getReplaceData().getMaterial()) { continue; } - else if (this.getWorld().getBlockTypeIdAt(x, y - 1, z) == v.getReplaceId()) + else if (this.getWorld().getBlockAt(x, y - 1, z).getType() == v.getReplaceData().getMaterial()) { continue; } @@ -102,10 +101,10 @@ else if (this.getWorld().getBlockTypeIdAt(x, y - 1, z) == v.getReplaceId()) final Undo undo = new Undo(); for (final Block currentBlock : blocks) { - if (currentBlock.getTypeId() != v.getVoxelId()) + if (currentBlock.getType() != v.getVoxelMat()) { undo.put(currentBlock); - currentBlock.setTypeId(v.getVoxelId()); + currentBlock.setType(v.getVoxelMat()); } } v.owner().storeUndo(undo); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java index ce394c27..a321e5c2 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java @@ -5,6 +5,7 @@ import com.thevoxelbox.voxelsniper.Undo; import org.bukkit.ChatColor; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * THIS BRUSH SHOULD NOT USE PERFORMERS. @@ -26,8 +27,8 @@ private void vShell(final SnipeData v, Block targetBlock) { final int brushSize = v.getBrushSize(); final int brushSizeSquared = 2 * brushSize; - final int[][][] oldMaterials = new int[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer - final int[][][] newMaterials = new int[2 * brushSize + 1][2 * brushSize + 1][2 * brushSize + 1]; // Array that holds the hollowed materials + final BlockData[][][] oldMaterials = new BlockData[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer + final BlockData[][][] newMaterials = new BlockData[2 * brushSize + 1][2 * brushSize + 1][2 * brushSize + 1]; // Array that holds the hollowed materials int blockPositionX = targetBlock.getX(); int blockPositionY = targetBlock.getY(); @@ -39,7 +40,7 @@ private void vShell(final SnipeData v, Block targetBlock) { for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][y][z] = this.getBlockIdAt(blockPositionX - brushSize - 1 + x, blockPositionY - brushSize - 1 + y, blockPositionZ - brushSize - 1 + z); + oldMaterials[x][y][z] = this.getBlockDataAt(blockPositionX - brushSize - 1 + x, blockPositionY - brushSize - 1 + y, blockPositionZ - brushSize - 1 + z); } } } @@ -66,34 +67,34 @@ private void vShell(final SnipeData v, Block targetBlock) { temp = 0; - if (oldMaterials[x + 1 + 1][z + 1][y + 1] == v.getReplaceId()) + if (oldMaterials[x + 1 + 1][z + 1][y + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1 - 1][z + 1][y + 1] == v.getReplaceId()) + if (oldMaterials[x + 1 - 1][z + 1][y + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][z + 1 + 1][y + 1] == v.getReplaceId()) + if (oldMaterials[x + 1][z + 1 + 1][y + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][z + 1 - 1][y + 1] == v.getReplaceId()) + if (oldMaterials[x + 1][z + 1 - 1][y + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][z + 1][y + 1 + 1] == v.getReplaceId()) + if (oldMaterials[x + 1][z + 1][y + 1 + 1].matches(v.getReplaceData())) { temp++; } - if (oldMaterials[x + 1][z + 1][y + 1 - 1] == v.getReplaceId()) + if (oldMaterials[x + 1][z + 1][y + 1 - 1].matches(v.getReplaceData())) { temp++; } if (temp == 0) { - newMaterials[x][z][y] = v.getVoxelId(); + newMaterials[x][z][y] = v.getVoxelData(); } } } @@ -108,11 +109,11 @@ private void vShell(final SnipeData v, Block targetBlock) { for (int z = brushSizeSquared; z >= 0; z--) { - if (this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - brushSize + y, blockPositionZ - brushSize + z) != newMaterials[x][y][z]) + if (this.getBlockTypeAt(blockPositionX - brushSize + x, blockPositionY - brushSize + y, blockPositionZ - brushSize + z) != newMaterials[x][y][z].getMaterial()) { undo.put(this.clampY(blockPositionX - brushSize + x, blockPositionY - brushSize + y, blockPositionZ - brushSize + z)); } - this.setBlockIdAt(blockPositionZ - brushSize + z, blockPositionX - brushSize + x, blockPositionY - brushSize + y, newMaterials[x][y][z]); + this.setBlockDataAt(blockPositionZ - brushSize + z, blockPositionX - brushSize + x, blockPositionY - brushSize + y, newMaterials[x][y][z]); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java index 6166fb0d..98377ebb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java @@ -1,190 +1,202 @@ -package com.thevoxelbox.voxelsniper.brush; - - -import com.thevoxelbox.voxelsniper.Message; -import com.thevoxelbox.voxelsniper.SnipeData; -import com.thevoxelbox.voxelsniper.Undo; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -/** - * http://www.voxelwiki.com/minecraft/Voxelsniper#Snow_cone_brush - * - * @author Voxel - */ -public class SnowConeBrush extends Brush -{ - @SuppressWarnings("deprecation") - private void addSnow(final SnipeData v, Block targetBlock) - { - int brushSize; - int blockPositionX = targetBlock.getX(); - int blockPositionY = targetBlock.getY(); - int blockPositionZ = targetBlock.getZ(); - if (this.getBlockIdAt(blockPositionX, blockPositionY, blockPositionZ) == Material.AIR.getId()) - { - brushSize = 0; - } - else - { - brushSize = this.clampY(blockPositionX, blockPositionY, blockPositionZ).getData() + 1; - } - - final int brushSizeDoubled = 2 * brushSize; - final int[][] snowcone = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Will hold block IDs - final int[][] snowconeData = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Will hold data values for snowcone - final int[][] yOffset = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; - // prime the arrays - - for (int x = 0; x <= brushSizeDoubled; x++) - { - for (int z = 0; z <= brushSizeDoubled; z++) - { - boolean flag = true; - - for (int i = 0; i < 10; i++) - { // overlay - if (flag) - { - if ((this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - i, blockPositionZ - brushSize + z) == 0 || this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - i, blockPositionZ - brushSize + z) == Material.SNOW.getId()) && this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - i - 1, blockPositionZ - brushSize + z) != Material.AIR.getId() && this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - i - 1, blockPositionZ - brushSize + z) != Material.SNOW.getId()) - { - flag = false; - yOffset[x][z] = i; - } - } - } - snowcone[x][z] = this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z); - snowconeData[x][z] = this.clampY(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z).getData(); - } - } - - // figure out new snowheights - for (int x = 0; x <= brushSizeDoubled; x++) - { - final double xSquared = Math.pow(x - brushSize, 2); - - for (int z = 0; z <= 2 * brushSize; z++) - { - final double zSquared = Math.pow(z - brushSize, 2); - final double dist = Math.pow(xSquared + zSquared, .5); // distance from center of array - final int snowData = brushSize - (int) Math.ceil(dist); - - if (snowData >= 0) - { // no funny business - switch (snowData) - { - case 0: - if (snowcone[x][z] == Material.AIR.getId()) - { - snowcone[x][z] = Material.SNOW.getId(); - snowconeData[x][z] = 0; - } - break; - case 7: // Turn largest snowtile into snowblock - if (snowcone[x][z] == Material.SNOW.getId()) - { - snowcone[x][z] = Material.SNOW_BLOCK.getId(); - snowconeData[x][z] = 0; - } - break; - default: // Increase snowtile size, if smaller than target - - if (snowData > snowconeData[x][z]) - { - switch (snowcone[x][z]) - { - case 0: - snowconeData[x][z] = snowData; - snowcone[x][z] = Material.SNOW.getId(); - case 78: - snowconeData[x][z] = snowData; - break; - default: - break; - - } - } - else if (yOffset[x][z] > 0 && snowcone[x][z] == Material.SNOW.getId()) - { - snowconeData[x][z]++; - if (snowconeData[x][z] == 7) - { - snowconeData[x][z] = 0; - snowcone[x][z] = Material.SNOW_BLOCK.getId(); - } - } - break; - } - } - } - } - - final Undo undo = new Undo(); - - for (int x = 0; x <= brushSizeDoubled; x++) - { - for (int z = 0; z <= brushSizeDoubled; z++) - { - - if (this.getBlockIdAt(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z) != snowcone[x][z] || this.clampY(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z).getData() != snowconeData[x][z]) - { - undo.put(this.clampY(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z)); - } - this.setBlockIdAt(blockPositionZ - brushSize + z, blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], snowcone[x][z]); - this.clampY(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z).setData((byte) snowconeData[x][z]); - - } - } - v.owner().storeUndo(undo); - } - - @Override - protected final void arrow(final SnipeData v) - { - } - - @Override - protected final void powder(final SnipeData v) - { - switch (getTargetBlock().getType()) - { - case SNOW: - this.addSnow(v, this.getTargetBlock()); - break; - default: - Block blockAbove = getTargetBlock().getRelative(BlockFace.UP); - if (blockAbove != null && blockAbove.getType() == Material.AIR) - { - addSnow(v, blockAbove); - } - else - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "Error: Center block neither snow nor air."); - } - break; - } - } - - @Override - public final void info(final Message vm) - { - vm.brushName("Snow Cone"); - } - - @Override - public final void parameters(final String[] par, final SnipeData v) - { - if (par[1].equalsIgnoreCase("info")) - { - v.sendMessage(ChatColor.GOLD + "Snow Cone Parameters:"); - } - } - - @Override - public String getPermissionNode() - { - return "voxelsniper.brush.snowcone"; - } -} +package com.thevoxelbox.voxelsniper.brush; + + +import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.SnipeData; +import com.thevoxelbox.voxelsniper.Undo; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Snow; + +/** + * http://www.voxelwiki.com/minecraft/Voxelsniper#Snow_cone_brush + * + * @author Voxel + */ +public class SnowConeBrush extends Brush +{ + private void addSnow(final SnipeData v, Block targetBlock) + { + int brushSize; + int blockPositionX = targetBlock.getX(); + int blockPositionY = targetBlock.getY(); + int blockPositionZ = targetBlock.getZ(); + if (this.getBlockTypeAt(blockPositionX, blockPositionY, blockPositionZ) == Material.AIR) + { + brushSize = 0; + } + else + { + Block block = this.clampY(blockPositionX, blockPositionY, blockPositionZ); + if (block instanceof Snow) { + brushSize = ((Snow) block).getLayers() + 1; + } else { + brushSize = 0; + } + } + + final int brushSizeDoubled = 2 * brushSize; + final Material[][] snowcone = new Material[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Will hold block IDs + final int[][] snowconeData = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; // Will hold data values for snowcone + final int[][] yOffset = new int[brushSizeDoubled + 1][brushSizeDoubled + 1]; + // prime the arrays + + for (int x = 0; x <= brushSizeDoubled; x++) + { + for (int z = 0; z <= brushSizeDoubled; z++) + { + boolean flag = true; + + int brushX = blockPositionX - brushSize + x; + int brushZ = blockPositionZ - brushSize + z; + for (int i = 0; i < 10; i++) + { // overlay + if (flag) + { + int iy = blockPositionY - i; + if ((this.getBlockTypeAt(brushX, iy, brushZ) == Material.AIR || this.getBlockTypeAt(brushX, iy, brushZ) == Material.SNOW) && this.getBlockTypeAt(brushX, iy - 1, brushZ) != Material.AIR && this.getBlockTypeAt(brushX, iy - 1, brushZ) != Material.SNOW) + { + flag = false; + yOffset[x][z] = i; + } + } + } + snowcone[x][z] = this.getBlockTypeAt(brushX, blockPositionY - yOffset[x][z], brushZ); + Block dataBlock = this.clampY(brushX, blockPositionY - yOffset[x][z], brushZ); + snowconeData[x][z] = dataBlock.getType() == Material.SNOW ? ((Snow)dataBlock.getBlockData()).getLayers() : 0; + } + } + + // figure out new snowheights + for (int x = 0; x <= brushSizeDoubled; x++) + { + final double xSquared = Math.pow(x - brushSize, 2); + + for (int z = 0; z <= 2 * brushSize; z++) + { + final double zSquared = Math.pow(z - brushSize, 2); + final double dist = Math.pow(xSquared + zSquared, .5); // distance from center of array + final int snowData = brushSize - (int) Math.ceil(dist); + + if (snowData >= 0) + { // no funny business + switch (snowData) + { + case 0: + if (snowcone[x][z] == Material.AIR) + { + snowcone[x][z] = Material.SNOW; + snowconeData[x][z] = 0; + } + break; + case 7: // Turn largest snowtile into snowblock + if (snowcone[x][z] == Material.SNOW) + { + snowcone[x][z] = Material.SNOW_BLOCK; + snowconeData[x][z] = 0; + } + break; + default: // Increase snowtile size, if smaller than target + + if (snowData > snowconeData[x][z]) + { + switch (snowcone[x][z]) + { + case AIR: + snowconeData[x][z] = snowData; + snowcone[x][z] = Material.SNOW; + case SNOW: + snowconeData[x][z] = snowData; + break; + default: + break; + + } + } + else if (yOffset[x][z] > 0 && snowcone[x][z] == Material.SNOW) + { + snowconeData[x][z]++; + if (snowconeData[x][z] == 7) + { + snowconeData[x][z] = 0; + snowcone[x][z] = Material.SNOW_BLOCK; + } + } + break; + } + } + } + } + + final Undo undo = new Undo(); + + for (int x = 0; x <= brushSizeDoubled; x++) + { + for (int z = 0; z <= brushSizeDoubled; z++) + { + + Block block = this.clampY(blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], blockPositionZ - brushSize + z); + Snow oldSnow = block.getType() == Material.SNOW ? (Snow)block.getBlockData() : null; + if (block.getType() != snowcone[x][z] || (oldSnow != null && oldSnow.getLayers() != snowconeData[x][z])) + { + undo.put(block); + } + this.setBlockTypeAt(blockPositionZ - brushSize + z, blockPositionX - brushSize + x, blockPositionY - yOffset[x][z], snowcone[x][z]); + if(block.getType() == Material.SNOW) { + ((Snow)block.getBlockData()).setLayers(snowconeData[x][z]); + } + } + } + v.owner().storeUndo(undo); + } + + @Override + protected final void arrow(final SnipeData v) + { + } + + @Override + protected final void powder(final SnipeData v) + { + switch (getTargetBlock().getType()) + { + case SNOW: + this.addSnow(v, this.getTargetBlock()); + break; + default: + Block blockAbove = getTargetBlock().getRelative(BlockFace.UP); + if (blockAbove != null && blockAbove.getType() == Material.AIR) + { + addSnow(v, blockAbove); + } + else + { + v.owner().getPlayer().sendMessage(ChatColor.RED + "Error: Center block neither snow nor air."); + } + break; + } + } + + @Override + public final void info(final Message vm) + { + vm.brushName("Snow Cone"); + } + + @Override + public final void parameters(final String[] par, final SnipeData v) + { + if (par[1].equalsIgnoreCase("info")) + { + v.sendMessage(ChatColor.GOLD + "Snow Cone Parameters:"); + } + } + + @Override + public String getPermissionNode() + { + return "voxelsniper.brush.snowcone"; + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java deleted file mode 100644 index cce02cc0..00000000 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java +++ /dev/null @@ -1,830 +0,0 @@ -package com.thevoxelbox.voxelsniper.brush; - -import com.thevoxelbox.voxelsniper.Message; -import com.thevoxelbox.voxelsniper.SnipeData; -import com.thevoxelbox.voxelsniper.Undo; -import org.bukkit.ChatColor; -import org.bukkit.block.Block; - -/** - * http://www.voxelwiki.com/minecraft/Voxelsniper#Spiral_Staircase_Brush - * - * @author giltwist - */ -public class SpiralStaircaseBrush extends Brush -{ - private String stairtype = "block"; // "block" 1x1 blocks (default), "step" alternating step double step, "stair" staircase with blocks on corners - private String sdirect = "c"; // "c" clockwise (default), "cc" counter-clockwise - private String sopen = "n"; // "n" north (default), "e" east, "world" south, "world" west - - /** - * - */ - public SpiralStaircaseBrush() - { - this.setName("Spiral Staircase"); - } - - @SuppressWarnings("deprecation") - private void buildStairWell(final SnipeData v, Block targetBlock) - { - if (v.getVoxelHeight() < 1) - { - v.setVoxelHeight(1); - v.sendMessage(ChatColor.RED + "VoxelHeight must be a natural number! Set to 1."); - } - - final int[][][] spiral = new int[2 * v.getBrushSize() + 1][v.getVoxelHeight()][2 * v.getBrushSize() + 1]; - - // locate first block in staircase - // Note to self, fix these - int startX = 0; - int startZ = 0; - int y = 0; - int xOffset = 0; - int zOffset = 0; - int toggle = 0; - - if (this.sdirect.equalsIgnoreCase("cc")) - { - if (this.sopen.equalsIgnoreCase("n")) - { - startX = 0; - startZ = 2 * v.getBrushSize(); - } - else if (this.sopen.equalsIgnoreCase("e")) - { - startX = 0; - startZ = 0; - } - else if (this.sopen.equalsIgnoreCase("s")) - { - startX = 2 * v.getBrushSize(); - startZ = 0; - } - else - { - startX = 2 * v.getBrushSize(); - startZ = 2 * v.getBrushSize(); - } - } - else - { - if (this.sopen.equalsIgnoreCase("n")) - { - startX = 0; - startZ = 0; - } - else if (this.sopen.equalsIgnoreCase("e")) - { - startX = 2 * v.getBrushSize(); - startZ = 0; - } - else if (this.sopen.equalsIgnoreCase("s")) - { - startX = 2 * v.getBrushSize(); - startZ = 2 * v.getBrushSize(); - } - else - { - startX = 0; - startZ = 2 * v.getBrushSize(); - } - } - - while (y < v.getVoxelHeight()) - { - if (this.stairtype.equalsIgnoreCase("block")) - { - // 1x1x1 voxel material steps - spiral[startX + xOffset][y][startZ + zOffset] = 1; - y++; - } - else if (this.stairtype.equalsIgnoreCase("step")) - { - // alternating step-doublestep, uses data value to determine type - switch (toggle) - { - case 0: - toggle = 2; - spiral[startX + xOffset][y][startZ + zOffset] = 1; - break; - case 1: - toggle = 2; - spiral[startX + xOffset][y][startZ + zOffset] = 1; - break; - case 2: - toggle = 1; - spiral[startX + xOffset][y][startZ + zOffset] = 2; - y++; - break; - default: - break; - } - - } - - // Adjust horizontal position and do stair-option array stuff - if (startX + xOffset == 0) - { // All North - if (startZ + zOffset == 0) - { // NORTHEAST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - xOffset++; - } - else - { - zOffset++; - } - } - else if (startZ + zOffset == 2 * v.getBrushSize()) - { // NORTHWEST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - zOffset--; - } - else - { - xOffset++; - } - } - else - { // JUST PLAIN NORTH - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 5; - y++; - } - zOffset--; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 4; - y++; - } - zOffset++; - } - } - } - else if (startX + xOffset == 2 * v.getBrushSize()) - { // ALL SOUTH - if (startZ + zOffset == 0) - { // SOUTHEAST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - zOffset++; - } - else - { - xOffset--; - } - } - else if (startZ + zOffset == 2 * v.getBrushSize()) - { // SOUTHWEST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - xOffset--; - } - else - { - zOffset--; - } - } - else - { // JUST PLAIN SOUTH - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 4; - y++; - } - zOffset++; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 5; - y++; - } - zOffset--; - } - } - } - else if (startZ + zOffset == 0) - { // JUST PLAIN EAST - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 2; - y++; - } - xOffset++; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 3; - y++; - } - xOffset--; - } - } - else - { // JUST PLAIN WEST - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 3; - y++; - } - xOffset--; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 2; - y++; - } - xOffset++; - } - } - } - - final Undo undo = new Undo(); - // Make the changes - - for (int x = 2 * v.getBrushSize(); x >= 0; x--) - { - for (int i = v.getVoxelHeight() - 1; i >= 0; i--) - { - for (int z = 2 * v.getBrushSize(); z >= 0; z--) - { - int blockPositionX = targetBlock.getX(); - int blockPositionY = targetBlock.getY(); - int blockPositionZ = targetBlock.getZ(); - switch (spiral[x][i][z]) - { - case 0: - if (i != v.getVoxelHeight() - 1) - { - if (!((this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) && spiral[x][i + 1][z] == 1)) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 0) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 0); - } - - } - else - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 0) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 0); - } - - break; - case 1: - if (this.stairtype.equalsIgnoreCase("block")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != v.getVoxelId()) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, v.getVoxelId()); - } - else if (this.stairtype.equalsIgnoreCase("step")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 44) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 44); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z).setData(v.getData()); - } - else if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i - 1, blockPositionZ - v.getBrushSize() + z) != v.getVoxelId()) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i - 1, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i - 1, v.getVoxelId()); - - } - break; - case 2: - if (this.stairtype.equalsIgnoreCase("step")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 43) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 43); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z).setData(v.getData()); - } - else if (this.stairtype.equalsIgnoreCase("woodstair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 53) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 53); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z).setData((byte) 0); - } - else if (this.stairtype.equalsIgnoreCase("cobblestair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 67) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 67); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z).setData((byte) 0); - } - break; - default: - if (this.stairtype.equalsIgnoreCase("woodstair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 53) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 53); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z).setData((byte) (spiral[x][i][z] - 2)); - } - else if (this.stairtype.equalsIgnoreCase("cobblestair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z) != 67) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY + i, 67); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z).setData((byte) (spiral[x][i][z] - 2)); - } - break; - } - } - } - } - v.owner().storeUndo(undo); - } - - @SuppressWarnings("deprecation") - private void digStairWell(final SnipeData v, Block targetBlock) - { - if (v.getVoxelHeight() < 1) - { - v.setVoxelHeight(1); - v.sendMessage(ChatColor.RED + "VoxelHeight must be a natural number! Set to 1."); - } - - // initialize array - final int[][][] spiral = new int[2 * v.getBrushSize() + 1][v.getVoxelHeight()][2 * v.getBrushSize() + 1]; - - // locate first block in staircase - // Note to self, fix these - int startX = 0; - int startZ = 0; - int y = 0; - int xOffset = 0; - int zOffset = 0; - int toggle = 0; - - if (this.sdirect.equalsIgnoreCase("cc")) - { - if (this.sopen.equalsIgnoreCase("n")) - { - startX = 0; - startZ = 2 * v.getBrushSize(); - } - else if (this.sopen.equalsIgnoreCase("e")) - { - startX = 0; - startZ = 0; - } - else if (this.sopen.equalsIgnoreCase("s")) - { - startX = 2 * v.getBrushSize(); - startZ = 0; - } - else - { - startX = 2 * v.getBrushSize(); - startZ = 2 * v.getBrushSize(); - } - } - else - { - if (this.sopen.equalsIgnoreCase("n")) - { - startX = 0; - startZ = 0; - } - else if (this.sopen.equalsIgnoreCase("e")) - { - startX = 2 * v.getBrushSize(); - startZ = 0; - } - else if (this.sopen.equalsIgnoreCase("s")) - { - startX = 2 * v.getBrushSize(); - startZ = 2 * v.getBrushSize(); - } - else - { - startX = 0; - startZ = 2 * v.getBrushSize(); - } - } - - while (y < v.getVoxelHeight()) - { - if (this.stairtype.equalsIgnoreCase("block")) - { - // 1x1x1 voxel material steps - spiral[startX + xOffset][y][startZ + zOffset] = 1; - y++; - } - else if (this.stairtype.equalsIgnoreCase("step")) - { - // alternating step-doublestep, uses data value to determine type - switch (toggle) - { - case 0: - toggle = 2; - spiral[startX + xOffset][y][startZ + zOffset] = 2; - break; - case 1: - toggle = 2; - spiral[startX + xOffset][y][startZ + zOffset] = 2; - break; - case 2: - toggle = 1; - spiral[startX + xOffset][y][startZ + zOffset] = 1; - y++; - break; - default: - break; - } - - } - - // Adjust horizontal position and do stair-option array stuff - if (startX + xOffset == 0) - { // All North - if (startZ + zOffset == 0) - { // NORTHEAST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - xOffset++; - } - else - { - zOffset++; - } - } - else if (startZ + zOffset == 2 * v.getBrushSize()) - { // NORTHWEST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - zOffset--; - } - else - { - xOffset++; - } - } - else - { // JUST PLAIN NORTH - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 4; - y++; - } - zOffset--; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 5; - y++; - } - zOffset++; - } - } - - } - else if (startX + xOffset == 2 * v.getBrushSize()) - { // ALL SOUTH - if (startZ + zOffset == 0) - { // SOUTHEAST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - zOffset++; - } - else - { - xOffset--; - } - } - else if (startZ + zOffset == 2 * v.getBrushSize()) - { // SOUTHWEST - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 1; - } - if (this.sdirect.equalsIgnoreCase("c")) - { - xOffset--; - } - else - { - zOffset--; - } - } - else - { // JUST PLAIN SOUTH - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 5; - y++; - } - zOffset++; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 4; - y++; - } - zOffset--; - } - } - - } - else if (startZ + zOffset == 0) - { // JUST PLAIN EAST - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 3; - y++; - } - xOffset++; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 2; - y++; - } - xOffset--; - } - } - else - { // JUST PLAIN WEST - if (this.sdirect.equalsIgnoreCase("c")) - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 2; - y++; - } - xOffset--; - } - else - { - if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - spiral[startX + xOffset][y][startZ + zOffset] = 3; - y++; - } - xOffset++; - } - } - - } - - final Undo undo = new Undo(); - // Make the changes - - for (int x = 2 * v.getBrushSize(); x >= 0; x--) - { - - for (int i = v.getVoxelHeight() - 1; i >= 0; i--) - { - - for (int z = 2 * v.getBrushSize(); z >= 0; z--) - { - - int blockPositionX = targetBlock.getX(); - int blockPositionY = targetBlock.getY(); - int blockPositionZ = targetBlock.getZ(); - switch (spiral[x][i][z]) - { - case 0: - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 0) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 0); - break; - case 1: - if (this.stairtype.equalsIgnoreCase("block")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != v.getVoxelId()) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, v.getVoxelId()); - } - else if (this.stairtype.equalsIgnoreCase("step")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 44) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 44); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z).setData(v.getData()); - } - else if (this.stairtype.equalsIgnoreCase("woodstair") || this.stairtype.equalsIgnoreCase("cobblestair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != v.getVoxelId()) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, v.getVoxelId()); - } - break; - case 2: - if (this.stairtype.equalsIgnoreCase("step")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 43) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 43); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z).setData(v.getData()); - } - else if (this.stairtype.equalsIgnoreCase("woodstair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 53) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() - x, blockPositionY + i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 53); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z).setData((byte) 0); - } - else if (this.stairtype.equalsIgnoreCase("cobblestair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 67) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 67); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z).setData((byte) 0); - } - break; - default: - if (this.stairtype.equalsIgnoreCase("woodstair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 53) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 53); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z).setData((byte) (spiral[x][i][z] - 2)); - } - else if (this.stairtype.equalsIgnoreCase("cobblestair")) - { - if (this.getBlockIdAt(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z) != 67) - { - undo.put(this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z)); - } - this.setBlockIdAt(blockPositionZ - v.getBrushSize() + z, blockPositionX - v.getBrushSize() + x, blockPositionY - i, 67); - this.clampY(blockPositionX - v.getBrushSize() + x, blockPositionY - i, blockPositionZ - v.getBrushSize() + z).setData((byte) (spiral[x][i][z] - 2)); - } - break; - } - } - } - } - v.owner().storeUndo(undo); - } - - @Override - protected final void arrow(final SnipeData v) - { - this.digStairWell(v, this.getTargetBlock()); // make stairwell below target - } - - @Override - protected final void powder(final SnipeData v) - { - this.buildStairWell(v, this.getLastBlock()); // make stairwell above target - } - - @Override - public final void info(final Message vm) - { - vm.brushName("Spiral Staircase"); - vm.size(); - vm.voxel(); - vm.height(); - vm.data(); - vm.custom(ChatColor.BLUE + "Staircase type: " + this.stairtype); - vm.custom(ChatColor.BLUE + "Staircase turns: " + this.sdirect); - vm.custom(ChatColor.BLUE + "Staircase opens: " + this.sopen); - } - - @Override - public final void parameters(final String[] par, final SnipeData v) - { - if (par[1].equalsIgnoreCase("info")) - { - v.sendMessage(ChatColor.GOLD + "Spiral Staircase Parameters:"); - v.sendMessage(ChatColor.AQUA + "/b sstair 'block' (default) | 'step' | 'woodstair' | 'cobblestair' -- set the type of staircase"); - v.sendMessage(ChatColor.AQUA + "/b sstair 'c' (default) | 'cc' -- set the turning direction of staircase"); - v.sendMessage(ChatColor.AQUA + "/b sstair 'n' (default) | 'e' | 's' | 'world' -- set the opening direction of staircase"); - return; - } - - for (int i = 1; i < par.length; i++) - { - if (par[i].equalsIgnoreCase("block") || par[i].equalsIgnoreCase("step") || par[i].equalsIgnoreCase("woodstair") || par[i].equalsIgnoreCase("cobblestair")) - { - this.stairtype = par[i]; - v.sendMessage(ChatColor.BLUE + "Staircase type: " + this.stairtype); - } - else if (par[i].equalsIgnoreCase("c") || par[i].equalsIgnoreCase("cc")) - { - this.sdirect = par[i]; - v.sendMessage(ChatColor.BLUE + "Staircase turns: " + this.sdirect); - } - else if (par[i].equalsIgnoreCase("n") || par[i].equalsIgnoreCase("e") || par[i].equalsIgnoreCase("s") || par[i].equalsIgnoreCase("world")) - { - this.sopen = par[i]; - v.sendMessage(ChatColor.BLUE + "Staircase opens: " + this.sopen); - } - else - { - v.sendMessage(ChatColor.RED + "Invalid brush parameters! use the info parameter to display parameter info."); - } - } - } - - @Override - public String getPermissionNode() - { - return "voxelsniper.brush.spiralstaircase"; - } -} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java index 8fc2b149..9c0309b7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java @@ -2,8 +2,10 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; +import com.thevoxelbox.voxelsniper.VTags; import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; import org.bukkit.ChatColor; +import org.bukkit.Material; import java.util.Random; @@ -40,8 +42,7 @@ public SplatterOverlayBrush() this.setName("Splatter Overlay"); } - @SuppressWarnings("deprecation") - private void sOverlay(final SnipeData v) + private void sOverlay(final SnipeData v) { // Splatter Time @@ -125,41 +126,28 @@ private void sOverlay(final SnipeData v) if ((Math.pow(x, 2) + Math.pow(z, 2)) <= brushSizeSquared && splat[x + v.getBrushSize()][z + v.getBrushSize()] == 1) { // if inside of the column && if to be splattered - final int check = this.getBlockIdAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z); - if (check == 0 || check == 8 || check == 9) + final Material check = this.getBlockTypeAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z); + if (check == Material.AIR || check == Material.WATER) { // must start at surface... this prevents it filling stuff in if you click in a wall // and it starts out below surface. if (!this.allBlocks) { // if the override parameter has not been activated, go to the switch that filters out manmade stuff. - switch (this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)) + if (VTags.NATURAL.isTagged(this.getBlockTypeAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z))) { - case 1: - case 2: - case 3: - case 12: - case 13: - case 24:// These cases filter out any manufactured or refined blocks, any trees and leas, etc. that you don't want to mess with. - case 48: - case 82: - case 49: - case 78: - final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth; + final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth; - for (int d = this.depth - 1; ((this.depth - d) <= depth); d--) + for (int d = this.depth - 1; ((this.depth - d) <= depth); d--) + { + if (this.clampY(this.getTargetBlock().getX() + x, y - d, this.getTargetBlock().getZ() + z).getType() != Material.AIR) { - if (this.clampY(this.getTargetBlock().getX() + x, y - d, this.getTargetBlock().getZ() + z).getTypeId() != 0) - { - // fills down as many layers as you specify in parameters - this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y - d + yOffset, this.getTargetBlock().getZ() + z)); - // stop it from checking any other blocks in this vertical 1x1 column. - memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; - } + // fills down as many layers as you specify in parameters + this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y - d + yOffset, this.getTargetBlock().getZ() + z)); + // stop it from checking any other blocks in this vertical 1x1 column. + memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; } - break; - default: - break; + } } } else @@ -167,7 +155,7 @@ private void sOverlay(final SnipeData v) final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth; for (int d = this.depth - 1; ((this.depth - d) <= depth); d--) { - if (this.clampY(this.getTargetBlock().getX() + x, y - d, this.getTargetBlock().getZ() + z).getTypeId() != 0) + if (this.clampY(this.getTargetBlock().getX() + x, y - d, this.getTargetBlock().getZ() + z).getType() != Material.AIR) { // fills down as many layers as you specify in parameters this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y - d + yOffset, this.getTargetBlock().getZ() + z)); @@ -269,40 +257,23 @@ private void soverlayTwo(final SnipeData v) { // if haven't already found the surface in this column if ((Math.pow(x, 2) + Math.pow(z, 2)) <= brushSizeSquared && splat[x + v.getBrushSize()][z + v.getBrushSize()] == 1) { // if inside of the column...&& if to be splattered - if (this.getBlockIdAt(this.getTargetBlock().getX() + x, y - 1, this.getTargetBlock().getZ() + z) != 0) + if (this.getBlockTypeAt(this.getTargetBlock().getX() + x, y - 1, this.getTargetBlock().getZ() + z) != Material.AIR) { // if not a floating block (like one of Notch'world pools) - if (this.getBlockIdAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z) == 0) + if (this.getBlockTypeAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z) == Material.AIR) { // must start at surface... this prevents it filling stuff in if // you click in a wall and it starts out below surface. if (!this.allBlocks) { // if the override parameter has not been activated, go to the switch that filters out manmade stuff. - switch (this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)) + if (VTags.NATURAL.isTagged(this.getBlockTypeAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z))) { - case 1: - case 2: - case 3: - case 12: - case 13: - case 14: // These cases filter out any manufactured or refined blocks, any trees and leas, etc. that you don't want to - // mess with. - case 15: - case 16: - case 24: - case 48: - case 82: - case 49: - case 78: - final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth; - for (int d = 1; (d < depth + 1); d++) - { - this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d + yOffset, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify - // in parameters - memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; // stop it from checking any other blocks in this vertical 1x1 column. - } - break; - default: - break; + final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth; + for (int d = 1; (d < depth + 1); d++) + { + this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d + yOffset, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify + // in parameters + memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; // stop it from checking any other blocks in this vertical 1x1 column. + } } } else diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java index b1eb30f2..c1426418 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java @@ -5,9 +5,12 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import com.thevoxelbox.voxelsniper.VTags; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @@ -19,11 +22,10 @@ public class StampBrush extends Brush */ protected class BlockWrapper { - public int id; + public BlockData bd; public int x; public int y; public int z; - public byte d; /** * @param b @@ -31,11 +33,9 @@ protected class BlockWrapper * @param bly * @param blz */ - @SuppressWarnings("deprecation") - public BlockWrapper(final Block b, final int blx, final int bly, final int blz) + public BlockWrapper(final Block b, final int blx, final int bly, final int blz) { - this.id = b.getTypeId(); - this.d = b.getData(); + this.bd = b.getBlockData(); this.x = blx; this.y = bly; this.z = blz; @@ -75,80 +75,26 @@ public final void reSort() this.sorted = false; } - /** - * @param id - * - * @return - */ - protected final boolean falling(final int id) - { - return (id > 7 && id < 14); - } - - /** - * @param id - * - * @return - */ - protected final boolean fallsOff(final int id) - { - switch (id) - { - // 6, 37, 38, 39, 40, 50, 51, 55, 59, 63, 64, 65, 66, 69, 70, 71, 72, 75, 76, 77, 83 - case (6): - case (37): - case (38): - case (39): - case (40): - case (50): - case (51): - case (55): - case (59): - case (63): - case (64): - case (65): - case (66): - case (68): - case (69): - case (70): - case (71): - case (72): - case (75): - case (76): - case (77): - case (78): - case (83): - case (93): - case (94): - default: - return false; - } - } - /** * @param cb */ - @SuppressWarnings("deprecation") - protected final void setBlock(final BlockWrapper cb) + protected final void setBlock(final BlockWrapper cb) { final Block block = this.clampY(this.getTargetBlock().getX() + cb.x, this.getTargetBlock().getY() + cb.y, this.getTargetBlock().getZ() + cb.z); this.undo.put(block); - block.setTypeId(cb.id); - block.setData(cb.d); + block.setBlockData(cb.bd); } /** * @param cb */ - @SuppressWarnings("deprecation") - protected final void setBlockFill(final BlockWrapper cb) + protected final void setBlockFill(final BlockWrapper cb) { final Block block = this.clampY(this.getTargetBlock().getX() + cb.x, this.getTargetBlock().getY() + cb.y, this.getTargetBlock().getZ() + cb.z); - if (block.getTypeId() == 0) + if (block.getType() == Material.AIR) { this.undo.put(block); - block.setTypeId(cb.id); - block.setData(cb.d); + block.setBlockData(cb.bd); } } @@ -189,11 +135,11 @@ protected final void stamp(final SnipeData v) this.solid.clear(); for (final BlockWrapper block : this.clone) { - if (this.fallsOff(block.id)) + if (VTags.POP_OFF.isTagged(block.bd.getMaterial())) { this.fall.add(block); } - else if (this.falling(block.id)) + else if (VTags.FALLING.isTagged(block.bd.getMaterial())) { this.drop.add(block); } @@ -247,15 +193,15 @@ protected final void stampFill(final SnipeData v) this.solid.clear(); for (final BlockWrapper block : this.clone) { - if (this.fallsOff(block.id)) + if (VTags.POP_OFF.isTagged(block.bd.getMaterial())) { this.fall.add(block); } - else if (this.falling(block.id)) + else if (VTags.FALLING.isTagged(block.bd.getMaterial())) { this.drop.add(block); } - else if (block.id != 0) + else if (block.bd.getMaterial() != Material.AIR) { this.solid.add(block); this.setBlockFill(block); @@ -305,15 +251,15 @@ protected final void stampNoAir(final SnipeData v) this.solid.clear(); for (final BlockWrapper block : this.clone) { - if (this.fallsOff(block.id)) + if (VTags.POP_OFF.isTagged(block.bd.getMaterial())) { this.fall.add(block); } - else if (this.falling(block.id)) + else if (VTags.FALLING.isTagged(block.bd.getMaterial())) { this.drop.add(block); } - else if (block.id != 0) + else if (block.bd.getMaterial() != Material.AIR) { this.solid.add(block); this.setBlock(block); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilBrush.java index 95946fa8..266051db 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilBrush.java @@ -1,385 +1,151 @@ package com.thevoxelbox.voxelsniper.brush; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import com.google.common.io.Files; import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import com.thevoxelbox.voxelsniper.util.SpongeSchematic; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.util.BlockVector; +import org.bukkit.util.Vector; /** - * This is paste only currently. Assumes files exist, and thus has no usefulness until I add in saving stencils later. Uses sniper-exclusive stencil format: 3 - * shorts for X,Z,Y size of cuboid 3 shorts for X,Z,Y offsets from the -X,-Z,-Y corner. This is the reference point for pasting, corresponding to where you - * click your brush. 1 long integer saying how many runs of blocks are in the schematic (data is compressed into runs) 1 per run: ( 1 boolean: true = compressed - * line ahead, false = locally unique block ahead. This wastes a bit instead of a byte, and overall saves space, as long as at least 1/8 of all RUNS are going - * to be size 1, which in Minecraft is almost definitely true. IF boolean was true, next unsigned byte stores the number of consecutive blocks of the same type, - * up to 256. IF boolean was false, there is no byte here, goes straight to ID and data instead, which applies to just one block. 2 bytes to identify type of - * block. First byte is ID, second is data. This applies to every one of the line of consecutive blocks if boolean was true. ) - * - * TODO: Make limit a config option + * Allows the copying and pasting of stencils. Stencils are stored using the Mcedit schematic format. Allows rotation and flipping of + * stencils. * - * @author Gavjenks + * @author Katrix, Gavjenks */ public class StencilBrush extends Brush { private byte pasteOption = 1; // 0 = full, 1 = fill, 2 = replace - private String filename = "NoFileLoaded"; - private short x; - private short z; - private short y; - private short xRef; - private short zRef; - private short yRef; - private byte pasteParam = 0; - private int[] firstPoint = new int[3]; - private int[] secondPoint = new int[3]; - private int[] pastePoint = new int[3]; + private String filename = ""; + private SpongeSchematic schematic; + private BlockVector firstPoint = new BlockVector(0, 0, 0); + private BlockVector secondPoint = new BlockVector(0, 0, 0); + private BlockVector pastePoint = new BlockVector(0, 0, 0); private byte point = 1; + private double pitch = 0; + private double yaw = 0; + private double roll = 0; + private boolean xFlipped = false; + private boolean yFlipped = false; + private boolean zFlipped = false; - /** - * - */ public StencilBrush() { this.setName("Stencil"); } - @SuppressWarnings("deprecation") - private void stencilPaste(final SnipeData v) + private void stencilPaste(final SnipeData v) { - if (this.filename.matches("NoFileLoaded")) + if (schematic == null) { - v.sendMessage(ChatColor.RED + "You did not specify a filename. This is required."); + if (this.filename.isEmpty()) + { + v.sendMessage(ChatColor.RED + "No region has been copied yet, and no filename was specified."); + return; + } + + final File file = getSchematicFile(); + + if(!file.exists()) { + v.sendMessage(ChatColor.RED + "Sorry, no region was loaded, and no stencil by that name was saved yet."); + return; + } + + try { + schematic = SpongeSchematic.read(file); + } + catch (IOException e) { + v.sendMessage(ChatColor.RED + "There was an issue loading the schematic " + file.getName() + ": " + e.getMessage()); + return; + } + } + + if(pasteOption != 0 && pasteOption != 1 && pasteOption != 2) { + v.sendMessage(ChatColor.RED + "Invalid paste option: " + pasteOption); return; } final Undo undo = new Undo(); - final File file = new File("plugins/VoxelSniper/stencils/" + this.filename + ".vstencil"); - if (file.exists()) - { - try - { - final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); - - this.x = in.readShort(); - this.z = in.readShort(); - this.y = in.readShort(); - - this.xRef = in.readShort(); - this.zRef = in.readShort(); - this.yRef = in.readShort(); - - final int numRuns = in.readInt(); - - int currX = -this.xRef; // so if your ref point is +5 x, you want to start pasting -5 blocks from the clicked point (the reference) to get the - // corner, for example. - int currZ = -this.zRef; - int currY = -this.yRef; - int id; - int data; - int blockPositionX = getTargetBlock().getX(); - int blockPositionY = getTargetBlock().getY(); - int blockPositionZ = getTargetBlock().getZ(); - if (this.pasteOption == 0) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - undo.put(this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ)); - this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).setTypeIdAndData(id, (byte) data, false); - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - else - { - undo.put(this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ)); - this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).setTypeIdAndData((in.readByte() + 128), (byte) (in.readByte() + 128), false); - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } + Vector offset = schematic.getOffset(); + int offX = offset.getBlockX(); + int offY = offset.getBlockY(); + int offZ = offset.getBlockZ(); + int width = schematic.getWidth(); + int height = schematic.getHeight(); + int length = schematic.getLength(); + + Block targetBlock = getTargetBlock(); + int posX = targetBlock.getX() + offX; + int posY = targetBlock.getY() + offY; + int posZ = targetBlock.getZ() + offZ; + + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + for (int z = 0; z < length; z++) { + Block block = this.clampY(posX + x, posY + y, posZ + z); + + boolean test = true; + if(pasteOption == 0) { + test = block.getType() == Material.AIR; } - } - else if (this.pasteOption == 1) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - if (id != 0 && this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).getTypeId() == 0) - { - undo.put(this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ)); - this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0 && this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).getTypeId() == 0) - { - undo.put(this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ)); - // v.sendMessage("currX:" + currX + " currZ:"+currZ + " currY:" + currY + " id:" + id + " data:" + (byte)data); - this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } + else if (pasteOption == 2) { + test = block.getType() != Material.AIR; } - } - else - { // replace - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < (numLoops); j++) - { - if (id != 0) - { - undo.put(this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ)); - this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).setTypeIdAndData(id, (byte) data, false); - } - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0) - { - undo.put(this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ)); - this.clampY(blockPositionX + currX, blockPositionY + currY, blockPositionZ + currZ).setTypeIdAndData(id, (byte) data, false); - } - currX++; - if (currX == this.x) - { - currX = 0; - currZ++; - if (currZ == this.z) - { - currZ = 0; - currY++; - } - } - } + + if(test) { + undo.put(block); + block.setBlockData(schematic.getBlockAt(x, y, z), false); } } - in.close(); - v.owner().storeUndo(undo); - - } - catch (final Exception exception) - { - v.sendMessage(ChatColor.RED + "Something went wrong."); - exception.printStackTrace(); } } - else - { - v.sendMessage(ChatColor.RED + "You need to type a stencil name / your specified stencil does not exist."); - } } - @SuppressWarnings("deprecation") - private void stencilSave(final SnipeData v) + private void stencilSave(final SnipeData v) { + schematic = SpongeSchematic.createFromWorld(v.getWorld(), this.firstPoint, this.secondPoint, this.pastePoint); - final File file = new File("plugins/VoxelSniper/stencils/" + this.filename + ".vstencil"); - try + if (!filename.isEmpty()) { - this.x = (short) (Math.abs((this.firstPoint[0] - this.secondPoint[0])) + 1); - this.z = (short) (Math.abs((this.firstPoint[1] - this.secondPoint[1])) + 1); - this.y = (short) (Math.abs((this.firstPoint[2] - this.secondPoint[2])) + 1); - this.xRef = (short) ((this.firstPoint[0] > this.secondPoint[0]) ? (this.pastePoint[0] - this.secondPoint[0]) : (this.pastePoint[0] - this.firstPoint[0])); - this.zRef = (short) ((this.firstPoint[1] > this.secondPoint[1]) ? (this.pastePoint[1] - this.secondPoint[1]) : (this.pastePoint[1] - this.firstPoint[1])); - this.yRef = (short) ((this.firstPoint[2] > this.secondPoint[2]) ? (this.pastePoint[2] - this.secondPoint[2]) : (this.pastePoint[2] - this.firstPoint[2])); - - if ((this.x * this.y * this.z) > 50000) - { - v.sendMessage(ChatColor.AQUA + "Volume exceeds maximum limit."); - return; - } - - Files.createParentDirs(file); - file.createNewFile(); - final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); - int blockPositionX = (this.firstPoint[0] > this.secondPoint[0]) ? this.secondPoint[0] : this.firstPoint[0]; - int blockPositionZ = (this.firstPoint[1] > this.secondPoint[1]) ? this.secondPoint[1] : this.firstPoint[1]; - int blockPositionY = (this.firstPoint[2] > this.secondPoint[2]) ? this.secondPoint[2] : this.firstPoint[2]; - out.writeShort(this.x); - out.writeShort(this.z); - out.writeShort(this.y); - out.writeShort(this.xRef); - out.writeShort(this.zRef); - out.writeShort(this.yRef); - - v.sendMessage(ChatColor.AQUA + "Volume: " + this.x * this.z * this.y + " blockPositionX:" + blockPositionX + " blockPositionZ:" + blockPositionZ + " blockPositionY:" + blockPositionY); - - byte[] blockArray = new byte[this.x * this.z * this.y]; - byte[] dataArray = new byte[this.x * this.z * this.y]; - byte[] runSizeArray = new byte[this.x * this.z * this.y]; - - byte lastId = (byte) (this.getWorld().getBlockTypeIdAt(blockPositionX, blockPositionY, blockPositionZ) - 128); - byte lastData = (byte) (this.clampY(blockPositionX, blockPositionY, blockPositionZ).getData() - 128); - byte thisId; - byte thisData; - int counter = 0; - int arrayIndex = 0; - for (int y = 0; y < this.y; y++) + final File file = getSchematicFile(); + try { - for (int z = 0; z < this.z; z++) - { - for (int x = 0; x < this.x; x++) - { - Block currentBlock = getWorld().getBlockAt(blockPositionX + x, blockPositionY + y, blockPositionZ + z); - thisId = (byte) (currentBlock.getTypeId() - 128); - thisData = (byte) (currentBlock.getData() - 128); - if (thisId != lastId || thisData != lastData || counter == 255) - { - blockArray[arrayIndex] = lastId; - dataArray[arrayIndex] = lastData; - runSizeArray[arrayIndex] = (byte) (counter - 128); - arrayIndex++; - counter = 1; - lastId = thisId; - lastData = thisData; - } - else - { - counter++; - lastId = thisId; - lastData = thisData; - } - } - } + schematic.writeTo(file); } - blockArray[arrayIndex] = lastId; // saving last run, which will always be left over. - dataArray[arrayIndex] = lastData; - runSizeArray[arrayIndex] = (byte) (counter - 128); - - out.writeInt(arrayIndex + 1); - // v.sendMessage("number of runs = " + arrayIndex); - for (int i = 0; i < arrayIndex + 1; i++) + catch (IOException e) { - if (runSizeArray[i] > -127) - { - out.writeBoolean(true); - out.writeByte(runSizeArray[i]); - out.writeByte(blockArray[i]); - out.writeByte(dataArray[i]); - } - else - { - out.writeBoolean(false); - out.writeByte(blockArray[i]); - out.writeByte(dataArray[i]); - } + v.sendMessage(ChatColor.RED + "There was an issue while saving your schematic " + file.getName() + ": " + e.getMessage()); } - - v.sendMessage(ChatColor.BLUE + "Saved as '" + this.filename + "'."); - out.close(); - - } - catch (final Exception exception) - { - v.sendMessage(ChatColor.RED + "Something went wrong."); - exception.printStackTrace(); } + + v.sendMessage(ChatColor.RED + "Region was successfully copied!"); } @Override protected final void arrow(final SnipeData v) - { // will be used to copy/save later on? + { + BlockVector vec = this.getTargetBlock().getLocation().toVector().toBlockVector(); if (this.point == 1) { - this.firstPoint[0] = this.getTargetBlock().getX(); - this.firstPoint[1] = this.getTargetBlock().getZ(); - this.firstPoint[2] = this.getTargetBlock().getY(); + this.firstPoint = vec; v.sendMessage(ChatColor.GRAY + "First point"); - v.sendMessage("X:" + this.firstPoint[0] + " Z:" + this.firstPoint[1] + " Y:" + this.firstPoint[2]); + v.sendMessage(this.formatVector(this.firstPoint)); this.point = 2; } else if (this.point == 2) { - this.secondPoint[0] = this.getTargetBlock().getX(); - this.secondPoint[1] = this.getTargetBlock().getZ(); - this.secondPoint[2] = this.getTargetBlock().getY(); - if ((Math.abs(this.firstPoint[0] - this.secondPoint[0]) * Math.abs(this.firstPoint[1] - this.secondPoint[1]) * Math.abs(this.firstPoint[2] - this.secondPoint[2])) > 5000000) + this.secondPoint = vec; + if (this.vecArea(this.firstPoint, this.secondPoint) > 5000000) { v.sendMessage(ChatColor.DARK_RED + "Area selected is too large. (Limit is 5,000,000 blocks)"); this.point = 1; @@ -387,23 +153,33 @@ else if (this.point == 2) else { v.sendMessage(ChatColor.GRAY + "Second point"); - v.sendMessage("X:" + this.secondPoint[0] + " Z:" + this.secondPoint[1] + " Y:" + this.secondPoint[2]); + v.sendMessage(this.formatVector(this.secondPoint)); this.point = 3; } } else if (this.point == 3) { - this.pastePoint[0] = this.getTargetBlock().getX(); - this.pastePoint[1] = this.getTargetBlock().getZ(); - this.pastePoint[2] = this.getTargetBlock().getY(); + this.pastePoint = vec; v.sendMessage(ChatColor.GRAY + "Paste Reference point"); - v.sendMessage("X:" + this.pastePoint[0] + " Z:" + this.pastePoint[1] + " Y:" + this.pastePoint[2]); + v.sendMessage(this.formatVector(this.pastePoint)); this.point = 1; this.stencilSave(v); } } + private File getSchematicFile() { + return new File("plugins/VoxelSniper/stencils/" + this.filename + ".schem"); + } + + private String formatVector(BlockVector vec) { + return "X:" + vec.getBlockX() + " Z:" + vec.getBlockZ() + " Y:" + vec.getBlockZ(); + } + + private int vecArea(BlockVector v1, BlockVector v2) { + return (Math.abs(v1.getBlockX() - v2.getBlockX()) * Math.abs(v1.getBlockY() - v2.getBlockY()) * Math.abs(v1.getBlockZ() - v2.getBlockZ())); + } + @Override protected final void powder(final SnipeData v) { // will be used to paste later on @@ -414,50 +190,178 @@ protected final void powder(final SnipeData v) public final void info(final Message vm) { vm.brushName(this.getName()); - vm.custom("File loaded: " + this.filename); + vm.custom("File loaded: " + (this.filename.isEmpty() ? "None; Using clipboard only." : this.filename)); } @Override - public final void parameters(final String[] par, final SnipeData v) + public final void parameters(final String[] pars, final SnipeData v) { - if (par[1].equalsIgnoreCase("info")) + int parN = 1; + String par = pars[parN]; + if (par.equalsIgnoreCase("info")) { v.sendMessage(ChatColor.GOLD + "Stencil brush Parameters:"); - v.sendMessage(ChatColor.AQUA + "/b schem [optional: 'full' 'fill' or 'replace', with fill as default] [name] -- Loads the specified schematic. Allowed size of schematic is based on rank. Full/fill/replace must come first. Full = paste all blocks, fill = paste only into air blocks, replace = paste full blocks in only, but replace anything in their way."); - v.sendMessage(ChatColor.BLUE + "Size of the stencils you are allowed to paste depends on rank (member / lite, sniper, curator, admin)"); + v.sendMessage(ChatColor.AQUA + "/b st (full|fill|replace) [name] (-r #) (-f N|S|E|W|NORTH|SOUTH|EAST|WEST) (p#) (y#) (r#) -- Loads the specified schematic. '-r #' or 'y#' specify yaw 'p#' specifies pitch and 'r#' specifies roll. -f specifies which axis to flip. All rotations are in degrees, not restricted to multiples of 90."); return; } - else if (par[1].equalsIgnoreCase("full")) + else if (par.equalsIgnoreCase("full")) { this.pasteOption = 0; - this.pasteParam = 1; + parN++; } - else if (par[1].equalsIgnoreCase("fill")) + else if (par.equalsIgnoreCase("fill")) { this.pasteOption = 1; - this.pasteParam = 1; + parN++; } - else if (par[1].equalsIgnoreCase("replace")) + else if (par.equalsIgnoreCase("replace")) { this.pasteOption = 2; - this.pasteParam = 1; + parN++; } - try + + if (pars.length > parN) { - this.filename = par[1 + this.pasteParam]; - final File file = new File("plugins/VoxelSniper/stencils/" + this.filename + ".vstencil"); + this.filename = pars[parN++]; + final File file = getSchematicFile(); + if (!file.getParentFile().exists()) + { + file.getParentFile().mkdirs(); + } + if (file.exists()) { - v.sendMessage(ChatColor.RED + "Stencil '" + this.filename + "' exists and was loaded. Make sure you are using powder if you do not want any chance of overwriting the file."); + try { + schematic = SpongeSchematic.read(file); + v.sendMessage(ChatColor.RED + "Stencil '" + this.filename + "' exists and was loaded. Make sure you are using powder if you do not want any chance of overwriting the file."); + } + catch (IOException e) { + v.sendMessage(ChatColor.DARK_RED + "There was an issue loading " + this.filename + ".schem " + e.getMessage()); + v.sendMessage(ChatColor.AQUA + "Running in clipboard mode. Can copy/paste but will not save to file."); + this.schematic = null; + this.filename = ""; + return; + } } else { v.sendMessage(ChatColor.AQUA + "Stencil '" + this.filename + "' does not exist. Ready to be saved to, but cannot be pasted."); } } - catch (final Exception exception) + else + { + this.filename = ""; + v.sendMessage(ChatColor.AQUA + "No filename specified, running in clipboard mode. Can copy/paste but will not save to file."); + } + + xFlipped = yFlipped = zFlipped = false; + yaw = pitch = roll = 0; + + for (int i = parN; i < pars.length; i++) { - v.sendMessage(ChatColor.RED + "You need to type a stencil name."); + if ((pars[i].equalsIgnoreCase("-r") || pars[i].equalsIgnoreCase("-rotate")) && i < pars.length - 1) + { + try + { + double rot = Double.parseDouble(pars[++i]); + this.yaw = (-rot) % 360; + v.sendMessage("Stencil yaw set to " + rot + " degrees."); + } + catch (NumberFormatException e) + { + continue; + } + } + + if ((pars[i].equalsIgnoreCase("-f") || pars[i].equalsIgnoreCase("-flip")) && i < pars.length - 1) + { + String dir = pars[++i]; + int start = 0; + Pattern pat = Pattern.compile("(north|n|south|s)|(east|e|west|w)|(up|u|down|d)"); + Matcher matcher = pat.matcher(dir); + int end = dir.length(); + while (start < end) + { + matcher.region(start, end); + if (matcher.find()) { + start = matcher.end(); + + if (matcher.group(1) != null) + { + xFlipped = true; + } + + if (matcher.group(2) != null) + { + zFlipped = true; + } + + if (matcher.group(3) != null) + { + yFlipped = true; + } + } + else + { + start++; + } + } + + if (xFlipped) + { + v.sendMessage("Stencil set to flip on the X axis."); + } + if (yFlipped) + { + v.sendMessage("Stencil set to flip on the Y axis."); + } + if (zFlipped) + { + v.sendMessage("Stencil set to flip on the Z axis."); + } + } + + if (pars[i].startsWith("p")) + { + try + { + double rot = Double.parseDouble(pars[i].substring(1)); + this.pitch = rot % 360; + v.sendMessage("Stencil pitch set to " + rot + " degrees."); + } + catch (NumberFormatException e) + { + continue; + } + } + + if (pars[i].startsWith("y")) + { + try + { + double rot = Double.parseDouble(pars[i].substring(1)); + this.yaw = (-rot) % 360; + v.sendMessage("Stencil yaw set to " + rot + " degrees."); + } + catch (NumberFormatException e) + { + continue; + } + } + + if (pars[i].startsWith("r")) + { + try + { + double rot = Double.parseDouble(pars[i].substring(1)); + this.roll = rot % 360; + v.sendMessage("Stencil roll set to " + rot + " degrees."); + } + catch (NumberFormatException e) + { + continue; + } + } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java index 8dd58253..d7575f08 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java @@ -1,16 +1,25 @@ package com.thevoxelbox.voxelsniper.brush; +import com.google.common.io.Files; import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Undo; +import com.thevoxelbox.voxelsniper.util.SpongeSchematic; import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.util.BlockVector; +import org.bukkit.util.Vector; import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; -import java.util.HashMap; +import java.nio.charset.Charset; import java.util.Scanner; +import java.util.List; +import java.util.Random; +import java.util.ArrayList; /** * @author Gavjenks @@ -26,7 +35,16 @@ public class StencilListBrush extends Brush private short zRef; private short yRef; private byte pasteParam = 0; - private HashMap stencilList = new HashMap(); + private List schematics = null; + + private final Random rand = new Random(); + + private static final BlockVector[] ROTATIONS = new BlockVector[] { + new BlockVector(1, 1, 1), + new BlockVector(1, -1, 1), + new BlockVector(-1, 1, 1), + new BlockVector(-1, -1, 1), + }; /** * @@ -36,885 +54,124 @@ public StencilListBrush() this.setName("StencilList"); } - private String readRandomStencil(final SnipeData v) - { - double rand = Math.random() * (this.stencilList.size()); - final int choice = (int) rand; - return this.stencilList.get(choice); + private File listFile() { + return new File("plugins/VoxelSniper/stencilLists/" + this.filename + ".txt"); } private void readStencilList(final String listname, final SnipeData v) { - final File file = new File("plugins/VoxelSniper/stencilLists/" + this.filename + ".txt"); - if (file.exists()) - { - try - { - final Scanner scanner = new Scanner(file); - int counter = 0; - while (scanner.hasNext()) - { - this.stencilList.put(counter, scanner.nextLine()); - counter++; - } - scanner.close(); - } - catch (final Exception exception) - { - exception.printStackTrace(); - } - } - } - - @SuppressWarnings("deprecation") - private void stencilPaste(final SnipeData v) - { - if (this.filename.matches("NoFileLoaded")) - { - v.sendMessage(ChatColor.RED + "You did not specify a filename for the list. This is required."); - return; - } - - final String stencilName = this.readRandomStencil(v); - v.sendMessage(stencilName); - - final Undo undo = new Undo(); - final File file = new File("plugins/VoxelSniper/stencils/" + stencilName + ".vstencil"); + schematics = null; + final File file = listFile(); if (file.exists()) { try { - final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); - - this.x = in.readShort(); - this.z = in.readShort(); - this.y = in.readShort(); - - this.xRef = in.readShort(); - this.zRef = in.readShort(); - this.yRef = in.readShort(); - - final int numRuns = in.readInt(); - // Something here that checks ranks using sanker'world thingie he added to Sniper and boots you out with error message if too big. - final int volume = this.x * this.y * this.z; - v.owner().getPlayer().sendMessage(ChatColor.AQUA + this.filename + " pasted. Volume is " + volume + " blocks."); - - int currX = -this.xRef; // so if your ref point is +5 x, you want to start pasting -5 blocks from the clicked point (the reference) to get the - // corner, for example. - int currZ = -this.zRef; - int currY = -this.yRef; - int id; - int data; - if (this.pasteOption == 0) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - else - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData((in.readByte() + 128), (byte) (in.readByte() + 128), false); - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - } - else if (this.pasteOption == 1) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } + List schemaFilesNames = Files.readLines(file, Charset.forName("UTF-8")); + List accum = new ArrayList(); + for (String schemaFileName : schemaFilesNames) { + File schemaFile = new File(schemaFileName); + + if(!schemaFile.exists()) { + v.sendMessage(ChatColor.RED + schemaFileName + " does not exist, skipping."); + continue; } + + accum.add(SpongeSchematic.read(schemaFile)); } - else - { // replace - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < (numLoops); j++) - { - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currX++; - if (currX == this.x - this.xRef) - { - currX = -this.xRef; - currZ++; - if (currZ == this.z - this.zRef) - { - currZ = -this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currX++; - if (currX == this.x) - { - currX = 0; - currZ++; - if (currZ == this.z) - { - currZ = 0; - currY++; - } - } - } - } + + if(schematics.isEmpty()) { + v.sendMessage(ChatColor.RED + "No valid schematics found in " + listname + "."); + return; } - in.close(); - v.owner().storeUndo(undo); + schematics = accum; } catch (final Exception exception) { - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); + v.sendMessage(ChatColor.RED + "There was an issue loading the list " + file.getName() + ": " + exception.getMessage()); exception.printStackTrace(); } } - else - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "You need to type a stencil name / your specified stencil does not exist."); - } } - @SuppressWarnings("deprecation") - private void stencilPaste180(final SnipeData v) - { - if (this.filename.matches("NoFileLoaded")) - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "You did not specify a filename for the list. This is required."); - return; - } - - final String stencilName = this.readRandomStencil(v); - - final Undo undo = new Undo(); - final File file = new File("plugins/VoxelSniper/stencils/" + stencilName + ".vstencil"); - - if (file.exists()) - { - try + private void stencilPaste(final SnipeData v, BlockVector rotation) { + if(schematics == null) { + if (this.filename.matches("NoFileLoaded")) { - final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); - - this.x = in.readShort(); - this.z = in.readShort(); - this.y = in.readShort(); - - this.xRef = in.readShort(); - this.zRef = in.readShort(); - this.yRef = in.readShort(); - - final int numRuns = in.readInt(); - // Something here that checks ranks using sanker'world thingie he added to Sniper and boots you out with error message if too big. - final int volume = this.x * this.y * this.z; - v.owner().getPlayer().sendMessage(ChatColor.AQUA + this.filename + " pasted. Volume is " + volume + " blocks."); - - int currX = +this.xRef; // so if your ref point is +5 x, you want to start pasting -5 blocks from the clicked point (the reference) to get the - // corner, for example. - int currZ = +this.zRef; - int currY = -this.yRef; - int id; - int data; - if (this.pasteOption == 0) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - currX--; - if (currX == -this.x + this.xRef) - { - currX = this.xRef; - currZ--; - if (currZ == -this.z + this.zRef) - { - currZ = +this.zRef; - currY++; - } - } - } - } - else - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData((in.readByte() + 128), (byte) (in.readByte() + 128), false); - currX--; - if (currX == -this.x + this.xRef) - { - currX = this.xRef; - currZ--; - if (currZ == -this.z + this.zRef) - { - currZ = +this.zRef; - currY++; - } - } - } - } - } - else if (this.pasteOption == 1) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currX--; - if (currX == -this.x + this.xRef) - { - currX = this.xRef; - currZ--; - if (currZ == -this.z + this.zRef) - { - currZ = +this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currX--; - if (currX == -this.x + this.xRef) - { - currX = this.xRef; - currZ--; - if (currZ == -this.z + this.zRef) - { - currZ = +this.zRef; - currY++; - } - } - } - } - } - else - { // replace - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < (numLoops); j++) - { - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currX--; - if (currX == -this.x + this.xRef) - { - currX = this.xRef; - currZ--; - if (currZ == -this.z + this.zRef) - { - currZ = +this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currX--; - if (currX == -this.x + this.xRef) - { - currX = this.xRef; - currZ--; - if (currZ == -this.z + this.zRef) - { - currZ = +this.zRef; - currY++; - } - } - } - } - } - in.close(); - v.owner().storeUndo(undo); + v.sendMessage(ChatColor.RED + "You did not specify a filename for the list. This is required."); + return; + } + final File file = listFile(); + if(!file.exists()) { + v.sendMessage(ChatColor.RED + "Sorry, no list was loaded."); + return; } - catch (final Exception exception) - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); - exception.printStackTrace(); + + readStencilList(filename, v); + + if(schematics == null) { + return; } } - else - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "You need to type a stencil name / your specified stencil does not exist."); - } - } - @SuppressWarnings("deprecation") - private void stencilPaste270(final SnipeData v) - { - if (this.filename.matches("NoFileLoaded")) - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "You did not specify a filename for the list. This is required."); + if(pasteOption != 0 && pasteOption != 1 && pasteOption != 2) { + v.sendMessage(ChatColor.RED + "Invalid paste option: " + pasteOption); return; } - final String stencilName = this.readRandomStencil(v); - final Undo undo = new Undo(); - final File file = new File("plugins/VoxelSniper/stencils/" + stencilName + ".vstencil"); - if (file.exists()) - { - try - { - final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); - - this.x = in.readShort(); - this.z = in.readShort(); - this.y = in.readShort(); - - this.xRef = in.readShort(); - this.zRef = in.readShort(); - this.yRef = in.readShort(); - - final int numRuns = in.readInt(); - // Something here that checks ranks using sanker'world thingie he added to Sniper and boots you out with error message if too big. - final int volume = this.x * this.y * this.z; - v.owner().getPlayer().sendMessage(ChatColor.AQUA + this.filename + " pasted. Volume is " + volume + " blocks."); - - int currX = +this.zRef; // so if your ref point is +5 x, you want to start pasting -5 blocks from the clicked point (the reference) to get the - // corner, for example. - int currZ = -this.xRef; - int currY = -this.yRef; - int id; - int data; - if (this.pasteOption == 0) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - currZ++; - if (currZ == this.x - this.xRef) - { - currZ = -this.xRef; - currX--; - if (currX == -this.z + this.zRef) - { - currX = +this.zRef; - currY++; - } - } - } - } - else - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData((in.readByte() + 128), (byte) (in.readByte() + 128), false); - currZ++; - currZ++; - if (currZ == this.x - this.xRef) - { - currZ = -this.xRef; - currX--; - if (currX == -this.z + this.zRef) - { - currX = +this.zRef; - currY++; - } - } - } - } - } - else if (this.pasteOption == 1) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { // no reason to paste air over - // air, and it prevents us - // most of the time from - // having to even check the - // block. - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currZ++; - if (currZ == this.x - this.xRef) - { - currZ = -this.xRef; - currX--; - if (currX == -this.z + this.zRef) - { - currX = +this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { // no reason to paste air over - // air, and it prevents us most of - // the time from having to even - // check the block. - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currZ++; - if (currZ == this.x - this.xRef) - { - currZ = -this.xRef; - currX--; - if (currX == -this.z + this.zRef) - { - currX = +this.zRef; - currY++; - } - } - } - } - } - else - { // replace - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < (numLoops); j++) - { - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currZ++; - if (currZ == this.x - this.xRef) - { - currZ = -this.xRef; - currX--; - if (currX == -this.z + this.zRef) - { - currX = +this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currZ++; - if (currZ == this.x - this.xRef) - { - currZ = -this.xRef; - currX--; - if (currX == -this.z + this.zRef) - { - currX = +this.zRef; - currY++; - } - } - } - } - } - in.close(); - v.owner().storeUndo(undo); + SpongeSchematic schematic = schematics.get(rand.nextInt(schematics.size())); - } - catch (final Exception exception) - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); - exception.printStackTrace(); - } - } - else - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "You need to type a stencil name / your specified stencil does not exist."); - } - } + Vector offset = schematic.getOffset().multiply(rotation); + int offX = offset.getBlockX(); + int offY = offset.getBlockY(); + int offZ = offset.getBlockZ(); + int width = schematic.getWidth(); + int height = schematic.getHeight(); + int length = schematic.getLength(); - @SuppressWarnings("deprecation") - private void stencilPaste90(final SnipeData v) - { - if (this.filename.matches("NoFileLoaded")) - { - v.sendMessage(ChatColor.RED + "You did not specify a filename for the list. This is required."); - return; - } + Block targetBlock = getTargetBlock(); + int posX = targetBlock.getX() + offX; + int posY = targetBlock.getY() + offY; + int posZ = targetBlock.getZ() + offZ; - final String stencilName = this.readRandomStencil(v); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + for (int z = 0; z < length; z++) { + Vector rotated = new BlockVector(x, y, z).multiply(rotation); - final Undo undo = new Undo(); - final File file = new File("plugins/VoxelSniper/stencils/" + stencilName + ".vstencil"); + Block block = this.clampY(posX + rotated.getBlockX(), posY + rotated.getBlockY(), posZ + rotated.getBlockZ()); - if (file.exists()) - { - try - { - final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); - - this.x = in.readShort(); - this.z = in.readShort(); - this.y = in.readShort(); - - this.xRef = in.readShort(); - this.zRef = in.readShort(); - this.yRef = in.readShort(); - - final int numRuns = in.readInt(); - // Something here that checks ranks using sanker'world thingie he added to Sniper and boots you out with error message if too big. - final int volume = this.x * this.y * this.z; - v.sendMessage(ChatColor.AQUA + this.filename + " pasted. Volume is " + volume + " blocks."); - - int currX = -this.zRef; // so if your ref point is +5 x, you want to start pasting -5 blocks from the clicked point (the reference) to get the - // corner, for example. - int currZ = +this.xRef; - int currY = -this.yRef; - int id; - int data; - if (this.pasteOption == 0) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - currZ--; - if (currZ == -this.x + this.xRef) - { - currZ = this.xRef; - currX++; - if (currX == this.z - this.zRef) - { - currX = -this.zRef; - currY++; - } - } - } - } - else - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData((in.readByte() + 128), (byte) (in.readByte() + 128), false); - currZ--; - if (currZ == -this.x + this.xRef) - { - currZ = this.xRef; - currX++; - if (currX == this.z - this.zRef) - { - currX = -this.zRef; - currY++; - } - } - } + boolean test = true; + if(pasteOption == 0) { + test = block.getType() == Material.AIR; } - } - else if (this.pasteOption == 1) - { - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < numLoops; j++) - { - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currZ--; - if (currZ == -this.x + this.xRef) - { - currZ = this.xRef; - currX++; - if (currX == this.z - this.zRef) - { - currX = -this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0 && this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).getTypeId() == 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) (data), false); - } - currZ--; - if (currZ == -this.x + this.xRef) - { - currZ = this.xRef; - currX++; - if (currX == this.z - this.zRef) - { - currX = -this.zRef; - currY++; - } - } - } + else if (pasteOption == 2) { + test = block.getType() != Material.AIR; } - } - else - { // replace - for (int i = 1; i < numRuns + 1; i++) - { - if (in.readBoolean()) - { - final int numLoops = in.readByte() + 128; - id = (in.readByte() + 128); - data = (in.readByte() + 128); - for (int j = 0; j < (numLoops); j++) - { - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currZ--; - if (currZ == -this.x + this.xRef) - { - currZ = this.xRef; - currX++; - if (currX == this.z - this.zRef) - { - currX = -this.zRef; - currY++; - } - } - } - } - else - { - id = (in.readByte() + 128); - data = (in.readByte() + 128); - if (id != 0) - { - undo.put(this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ)); - this.clampY(this.getTargetBlock().getX() + currX, this.getTargetBlock().getY() + currY, this.getTargetBlock().getZ() + currZ).setTypeIdAndData(id, (byte) data, false); - } - currZ--; - if (currZ == -this.x + this.xRef) - { - currZ = this.xRef; - currX++; - if (currX == this.z - this.zRef) - { - currX = -this.zRef; - currY++; - } - } - } + + if(test) { + undo.put(block); + block.setBlockData(schematic.getBlockAt(x, y, z), false); } } - in.close(); - v.owner().storeUndo(undo); - - } - catch (final Exception exception) - { - v.sendMessage(ChatColor.RED + "Something went wrong."); - exception.printStackTrace(); } } - else - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "You need to type a stencil name / your specified stencil does not exist."); - } } private void stencilPasteRotation(final SnipeData v) { // just randomly chooses a rotation and then calls stencilPaste. - this.readStencilList(this.filename, v); - final double random = Math.random(); - if (random < 0.26) - { - this.stencilPaste(v); - } - else if (random < 0.51) - { - this.stencilPaste90(v); - } - else if (random < 0.76) - { - this.stencilPaste180(v); - } - else - { - this.stencilPaste270(v); - } - + this.stencilPaste(v, ROTATIONS[rand.nextInt(ROTATIONS.length)]); } @Override protected final void arrow(final SnipeData v) { - this.stencilPaste(v); + this.stencilPaste(v, ROTATIONS[0]); } @Override @@ -958,7 +215,7 @@ else if (par[1].equalsIgnoreCase("replace")) try { this.filename = par[1 + this.pasteParam]; - final File file = new File("plugins/VoxelSniper/stencilLists/" + this.filename + ".txt"); + final File file = listFile(); if (file.exists()) { v.sendMessage(ChatColor.RED + "Stencil List '" + this.filename + "' exists and was loaded."); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/TreeSnipeBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/TreeSnipeBrush.java index 917ae78b..7040c8e2 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/TreeSnipeBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/TreeSnipeBrush.java @@ -30,8 +30,7 @@ public TreeSnipeBrush() this.setName("Tree Snipe"); } - @SuppressWarnings("deprecation") - private void single(final SnipeData v, Block targetBlock) + private void single(final SnipeData v, Block targetBlock) { UndoDelegate undoDelegate = new UndoDelegate(targetBlock.getWorld()); Block blockBelow = targetBlock.getRelative(BlockFace.DOWN); @@ -40,7 +39,7 @@ private void single(final SnipeData v, Block targetBlock) blockBelow.setType(Material.GRASS); this.getWorld().generateTree(targetBlock.getLocation(), this.treeType, undoDelegate); Undo undo = undoDelegate.getUndo(); - blockBelow.setTypeIdAndData(currentState.getTypeId(), currentState.getRawData(), true); + blockBelow.setBlockData(currentState.getBlockData(), true); undo.put(blockBelow); v.owner().storeUndo(undo); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/UnderlayBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/UnderlayBrush.java index cc40c45d..5c5d2197 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/UnderlayBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/UnderlayBrush.java @@ -2,8 +2,10 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; +import com.thevoxelbox.voxelsniper.VTags; import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; import org.bukkit.ChatColor; +import org.bukkit.Material; /** * http://www.voxelwiki.com/minecraft/Voxelsniper#Underlay_Brush @@ -25,8 +27,7 @@ public UnderlayBrush() this.setName("Underlay (Reverse Overlay)"); } - @SuppressWarnings("deprecation") - private void underlay(final SnipeData v) + private void underlay(final SnipeData v) { final int[][] memory = new int[v.getBrushSize() * 2 + 1][v.getBrushSize() * 2 + 1]; final double brushSizeSquared = Math.pow(v.getBrushSize() + 0.5, 2); @@ -43,38 +44,23 @@ private void underlay(final SnipeData v) { // if inside of the column... if (!this.allBlocks) { // if the override parameter has not been activated, go to the switch that filters out manmade stuff. - switch (this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)) - { - case 1: - case 2: - case 3: - case 12: - case 13: - case 24:// These cases filter out any manufactured or refined blocks, any trees and leas, etc. that you don't want to mess with. - case 48: - case 82: - case 49: - case 78: - for (int d = 0; (d < this.depth); d++) + if(VTags.NATURAL.isTagged(this.getBlockTypeAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z))) { + for (int d = 0; (d < this.depth); d++) + { + if (this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z).getType() != Material.AIR) { - if (this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z).getTypeId() != 0) - { - this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify in - // parameters - memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; // stop it from checking any other blocks in this vertical 1x1 column. - } + this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify in + // parameters + memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; // stop it from checking any other blocks in this vertical 1x1 column. } - break; - - default: - break; + } } } else { for (int d = 0; (d < this.depth); d++) { - if (this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z).getTypeId() != 0) + if (this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z).getType() != Material.AIR) { this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y + d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify in // parameters @@ -111,31 +97,14 @@ private void underlay2(final SnipeData v) if (!this.allBlocks) { // if the override parameter has not been activated, go to the switch that filters out manmade stuff. - switch (this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)) + if(VTags.NATURAL.isTagged(this.getBlockTypeAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z))) { - case 1: - case 2: - case 3: - case 12: - case 13: - case 14: // These cases filter out any manufactured or refined blocks, any trees and leas, etc. that you don't want to mess - // with. - case 15: - case 16: - case 24: - case 48: - case 82: - case 49: - case 78: - for (int d = -1; (d < this.depth - 1); d++) - { - this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y - d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify in - // parameters - memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; // stop it from checking any other blocks in this vertical 1x1 column. - } - break; - default: - break; + for (int d = -1; (d < this.depth - 1); d++) + { + this.current.perform(this.clampY(this.getTargetBlock().getX() + x, y - d, this.getTargetBlock().getZ() + z)); // fills down as many layers as you specify in + // parameters + memory[x + v.getBrushSize()][z + v.getBrushSize()] = 1; // stop it from checking any other blocks in this vertical 1x1 column. + } } } else diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/VoltMeterBrush.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/VoltMeterBrush.java index 2d35e3ad..a9902aed 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/VoltMeterBrush.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/VoltMeterBrush.java @@ -21,11 +21,10 @@ public VoltMeterBrush() this.setName("VoltMeter"); } - @SuppressWarnings("deprecation") - private void data(final SnipeData v) + private void data(final SnipeData v) { final Block block = this.clampY(this.getTargetBlock().getX(), this.getTargetBlock().getY(), this.getTargetBlock().getZ()); - final byte data = block.getData(); + final int data = block.getBlockPower(); v.sendMessage(ChatColor.AQUA + "Blocks until repeater needed: " + data); } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pCombo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pCombo.java index c11d31cb..5dc6436b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pCombo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pCombo.java @@ -7,6 +7,7 @@ import com.thevoxelbox.voxelsniper.Message; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,8 +15,7 @@ public class pCombo extends vPerformer { - private int i; - private byte d; + private BlockData bd; public pCombo() { @@ -27,22 +27,20 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.data(); + vm.voxelInk(); } @Override public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - d = v.getData(); + bd = v.getVoxelData(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { h.put(b); - b.setTypeIdAndData(i, d, true); + b.setBlockData(bd, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboCombo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboCombo.java index ebbdee9a..929b4967 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboCombo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboCombo.java @@ -7,6 +7,7 @@ import com.thevoxelbox.voxelsniper.Message; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,10 +15,8 @@ public class pComboCombo extends vPerformer { - private byte d; - private byte dr; - private int i; - private int ir; + private BlockData vd; + private BlockData rd; public pComboCombo() { @@ -28,10 +27,8 @@ public pComboCombo() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); - i = v.getVoxelId(); - ir = v.getReplaceId(); + vd = v.getVoxelData(); + rd = v.getReplaceData(); } @Override @@ -39,19 +36,18 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); + vm.voxelInk(); vm.replace(); - vm.data(); - vm.replaceData(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir && b.getData() == dr) + if (b.getBlockData().matches(rd)) { h.put(b); - b.setTypeIdAndData(i, d, true); + b.setBlockData(vd, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboComboNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboComboNoPhys.java index 83cdc3dc..2f39bea1 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboComboNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboComboNoPhys.java @@ -7,6 +7,7 @@ import com.thevoxelbox.voxelsniper.Message; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,10 +15,8 @@ public class pComboComboNoPhys extends vPerformer { - private byte d; - private byte dr; - private int i; - private int ir; + private BlockData vd; + private BlockData rd; public pComboComboNoPhys() { @@ -28,10 +27,8 @@ public pComboComboNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); - i = v.getVoxelId(); - ir = v.getReplaceId(); + vd = v.getVoxelData(); + rd = v.getReplaceData(); } @Override @@ -39,20 +36,18 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); + vm.voxelInk(); vm.replace(); - vm.data(); - vm.replaceData(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir && b.getData() == dr) + if (b.getBlockData().matches(rd)) { h.put(b); - b.setTypeId(i, false); - b.setData(d); + b.setBlockData(vd, false); } } @@ -61,4 +56,4 @@ public boolean isUsingReplaceMaterial() { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInk.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInk.java index 8e31c042..75eb66f6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInk.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInk.java @@ -5,8 +5,10 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +16,8 @@ public class pComboInk extends vPerformer { - private byte d; - private byte dr; - private int i; + private BlockData bd; + private String i; public pComboInk() { @@ -27,9 +28,8 @@ public pComboInk() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); - i = v.getVoxelId(); + bd = v.getVoxelData(); + i = v.getReplaceInk(); } @Override @@ -37,18 +37,17 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.data(); - vm.replaceData(); + vm.voxelInk(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() == dr) + if (Inker.matches(b, i)) { h.put(b); - b.setTypeIdAndData(i, d, true); + b.setBlockData(bd, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInkNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInkNoPhys.java index d0589aca..3acc2b6e 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInkNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboInkNoPhys.java @@ -5,8 +5,10 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +16,8 @@ public class pComboInkNoPhys extends vPerformer { - private byte d; - private byte dr; - private int i; + private BlockData bd; + private String i; public pComboInkNoPhys() { @@ -27,9 +28,8 @@ public pComboInkNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); - i = v.getVoxelId(); + bd = v.getVoxelData(); + i = v.getReplaceInk(); } @Override @@ -37,18 +37,17 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.data(); - vm.replaceData(); + vm.voxelInk(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() == dr) + if (Inker.matches(b, i)) { h.put(b); - b.setTypeIdAndData(i, d, false); + b.setBlockData(bd, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMat.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMat.java index d1acb003..7bcb4e8b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMat.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMat.java @@ -6,7 +6,9 @@ import com.thevoxelbox.voxelsniper.Message; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +16,8 @@ public class pComboMat extends vPerformer { - private byte d; - private int i; - private int ir; + private BlockData vd; + private Material rt; public pComboMat() { @@ -27,9 +28,8 @@ public pComboMat() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - i = v.getVoxelId(); - ir = v.getReplaceId(); + vd = v.getVoxelData(); + rt = v.getReplaceMat(); } @Override @@ -37,18 +37,17 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); + vm.voxelInk(); vm.replace(); - vm.data(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir) + if (b.getType() == rt) { h.put(b); - b.setTypeIdAndData(i, d, true); + b.setBlockData(vd, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMatNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMatNoPhys.java index 67719d13..16b22a9b 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMatNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboMatNoPhys.java @@ -6,7 +6,9 @@ import com.thevoxelbox.voxelsniper.Message; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +16,8 @@ public class pComboMatNoPhys extends vPerformer { - private byte d; - private int i; - private int ir; + private BlockData vd; + private Material rt; public pComboMatNoPhys() { @@ -27,9 +28,8 @@ public pComboMatNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - i = v.getVoxelId(); - ir = v.getReplaceId(); + vd = v.getVoxelData(); + rt = v.getReplaceMat(); } @Override @@ -37,18 +37,17 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); + vm.voxelInk(); vm.replace(); - vm.data(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir) + if (b.getType() == rt) { h.put(b); - b.setTypeIdAndData(i, d, false); + b.setBlockData(vd, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoPhys.java index 42606f6e..2701c0b4 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoPhys.java @@ -7,6 +7,7 @@ import com.thevoxelbox.voxelsniper.Message; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,8 +15,7 @@ public class pComboNoPhys extends vPerformer { - private int i; - private byte d; + private BlockData bd; public pComboNoPhys() { @@ -27,22 +27,20 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.data(); + vm.voxelInk(); } @Override public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - d = v.getData(); + bd = v.getVoxelData(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { h.put(b); - b.setTypeIdAndData(i, d, false); + b.setBlockData(bd, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoUndo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoUndo.java index 2946adbe..e571bd71 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoUndo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pComboNoUndo.java @@ -7,6 +7,7 @@ import com.thevoxelbox.voxelsniper.Message; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,8 +15,7 @@ public class pComboNoUndo extends vPerformer { - private int i; - private byte d; + private BlockData bd; public pComboNoUndo() { @@ -26,8 +26,7 @@ public pComboNoUndo() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - d = v.getData(); + bd = v.getVoxelData(); } @Override @@ -35,16 +34,15 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.data(); + vm.voxelInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() != i || b.getData() != d) + if (b.getBlockData().matches(bd)) { - b.setTypeIdAndData(i, d, true); + b.setBlockData(bd, true); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeCombo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeCombo.java index 26de37c9..fe91c8f5 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeCombo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeCombo.java @@ -8,6 +8,7 @@ import com.thevoxelbox.voxelsniper.util.VoxelList; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -16,8 +17,7 @@ public class pExcludeCombo extends vPerformer { private VoxelList excludeList; - private int id; - private byte data; + private BlockData bd; public pExcludeCombo() { @@ -30,26 +30,23 @@ public void info(Message vm) vm.performerName(name); vm.voxelList(); vm.voxel(); - vm.data(); + vm.voxelInk(); } @Override public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - id = v.getVoxelId(); - data = v.getData(); + bd = v.getVoxelData(); excludeList = v.getVoxelList(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (!excludeList.contains(new int[] {b.getTypeId(), b.getData()})) - { + if(!excludeList.contains(b.getBlockData())) { h.put(b); - b.setTypeIdAndData(id, data, true); + b.setBlockData(bd, true); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeInk.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeInk.java index ecd4e94f..f905c2a6 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeInk.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeInk.java @@ -5,6 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import com.thevoxelbox.voxelsniper.util.VoxelList; import org.bukkit.block.Block; @@ -16,7 +17,7 @@ public class pExcludeInk extends vPerformer { private VoxelList excludeList; - private byte data; + private String ink; public pExcludeInk() { @@ -28,25 +29,24 @@ public void info(Message vm) { vm.performerName(name); vm.voxelList(); - vm.data(); + vm.voxelInk(); } @Override public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - data = v.getData(); + ink = v.getVoxelInk(); excludeList = v.getVoxelList(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (!excludeList.contains(new int[] {b.getTypeId(), b.getData()})) + if (!excludeList.contains(b.getBlockData())) { h.put(b); - b.setData(data); + Inker.ink(b, ink); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeMat.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeMat.java index 902d60c9..503d4271 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeMat.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pExcludeMat.java @@ -6,7 +6,7 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.util.VoxelList; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -16,7 +16,7 @@ public class pExcludeMat extends vPerformer { private VoxelList excludeList; - private int id; + private Material t; public pExcludeMat() { @@ -35,18 +35,17 @@ public void info(Message vm) public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - id = v.getVoxelId(); + t = v.getVoxelMat(); excludeList = v.getVoxelList(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (!excludeList.contains(new int[] {b.getTypeId(), b.getData()})) + if (!excludeList.contains(b.getBlockData())) { h.put(b); - b.setTypeId(id); + b.setType(t); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeCombo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeCombo.java index 66f8c513..4aa47886 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeCombo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeCombo.java @@ -8,6 +8,7 @@ import com.thevoxelbox.voxelsniper.util.VoxelList; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -16,8 +17,7 @@ public class pIncludeCombo extends vPerformer { private VoxelList includeList; - private int id; - private byte data; + private BlockData bd; public pIncludeCombo() { @@ -30,26 +30,24 @@ public void info(Message vm) vm.performerName(name); vm.voxelList(); vm.voxel(); - vm.data(); + vm.voxelInk(); } @Override public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - id = v.getVoxelId(); - data = v.getData(); + bd = v.getVoxelData(); includeList = v.getVoxelList(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (includeList.contains(new int[] {b.getTypeId(), b.getData()})) + if (includeList.contains(b.getBlockData())) { h.put(b); - b.setTypeIdAndData(id, data, true); + b.setBlockData(bd, true); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeInk.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeInk.java index a943d9be..a98757c7 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeInk.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeInk.java @@ -5,10 +5,10 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import com.thevoxelbox.voxelsniper.util.VoxelList; import org.bukkit.block.Block; - /** * @author Voxel */ @@ -16,7 +16,7 @@ public class pIncludeInk extends vPerformer { private VoxelList includeList; - private byte data; + private String ink; public pIncludeInk() { @@ -28,25 +28,24 @@ public void info(Message vm) { vm.performerName(name); vm.voxelList(); - vm.data(); + vm.voxelInk(); } @Override public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - data = v.getData(); + ink = v.getVoxelInk(); includeList = v.getVoxelList(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (includeList.contains(new int[]{b.getTypeId(), b.getData()})) + if (includeList.contains(b.getBlockData())) { h.put(b); - b.setData(data); + Inker.ink(b, ink); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeMat.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeMat.java index 489c84c3..76e6e436 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeMat.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pIncludeMat.java @@ -6,7 +6,7 @@ import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.util.VoxelList; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -16,7 +16,7 @@ public class pIncludeMat extends vPerformer { private VoxelList includeList; - private int id; + private Material t; public pIncludeMat() { @@ -35,18 +35,17 @@ public void info(Message vm) public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - id = v.getVoxelId(); + t = v.getVoxelMat(); includeList = v.getVoxelList(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (includeList.contains(new int[]{b.getTypeId(), b.getData()})) + if (includeList.contains(b.getBlockData())) { h.put(b); - b.setTypeId(id); + b.setType(t); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInk.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInk.java index cde05310..ad769957 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInk.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInk.java @@ -5,6 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import org.bukkit.block.Block; @@ -14,7 +15,7 @@ public class pInk extends vPerformer { - private byte d; + private String i; public pInk() { @@ -25,21 +26,20 @@ public pInk() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); + i = v.getVoxelInk(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); + vm.voxelInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { h.put(b); - b.setData(d); + Inker.ink(b, i); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkCombo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkCombo.java index c1d992ca..2c7ff593 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkCombo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkCombo.java @@ -5,8 +5,10 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +16,8 @@ public class pInkCombo extends vPerformer { - private byte d; - private byte dr; - private int ir; + private String i; + private BlockData rbd; public pInkCombo() { @@ -27,9 +28,8 @@ public pInkCombo() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); - ir = v.getReplaceId(); + i = v.getVoxelInk(); + rbd = v.getReplaceData(); } @Override @@ -37,18 +37,17 @@ public void info(Message vm) { vm.performerName(name); vm.replace(); - vm.data(); - vm.replaceData(); + vm.voxelInk(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir && b.getData() == dr) + if (b.getBlockData().matches(rbd)) { h.put(b); - b.setData(d); + Inker.ink(b, i); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkComboNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkComboNoPhys.java index 5b3a0152..644c30bb 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkComboNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkComboNoPhys.java @@ -1,8 +1,10 @@ package com.thevoxelbox.voxelsniper.brush.perform; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; /** * @author Voxel @@ -10,9 +12,8 @@ public class pInkComboNoPhys extends vPerformer { - private byte d; - private byte dr; - private int ir; + private String i; + private BlockData rbd; public pInkComboNoPhys() { @@ -23,9 +24,8 @@ public pInkComboNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); - ir = v.getReplaceId(); + i = v.getVoxelInk(); + rbd = v.getReplaceData(); } @Override @@ -33,18 +33,17 @@ public void info(Message vm) { vm.performerName(name); vm.replace(); - vm.data(); - vm.replaceData(); + vm.voxelInk(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir && b.getData() == dr) + if (b.getBlockData().matches(rbd)) { h.put(b); - b.setData(d, false); + Inker.ink(b, i, false); } } @@ -53,4 +52,4 @@ public boolean isUsingReplaceMaterial() { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInk.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInk.java index 588bbdf3..52b78876 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInk.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInk.java @@ -5,6 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import org.bukkit.block.Block; @@ -14,8 +15,8 @@ public class pInkInk extends vPerformer { - private byte d; - private byte dr; + private String i; + private String ri; public pInkInk() { @@ -26,26 +27,25 @@ public pInkInk() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); + i = v.getVoxelInk(); + ri = v.getReplaceInk(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); - vm.replaceData(); + vm.voxelInk(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() == dr) + if (Inker.matches(b, ri)) { h.put(b); - b.setData(d, true); + Inker.ink(b, i, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInkNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInkNoPhys.java index 090f9863..e58ce0aa 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInkNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkInkNoPhys.java @@ -3,6 +3,7 @@ import org.bukkit.block.Block; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; /** * @author Voxel @@ -10,8 +11,8 @@ public class pInkInkNoPhys extends vPerformer { - private byte d; - private byte dr; + private String i; + private String ri; public pInkInkNoPhys() { @@ -22,26 +23,25 @@ public pInkInkNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - dr = v.getReplaceData(); + i = v.getVoxelInk(); + ri = v.getReplaceInk(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); - vm.replaceData(); + vm.voxelInk(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() == dr) + if (Inker.matches(b, ri)) { h.put(b); - b.setData(d, false); + Inker.ink(b, i, false); } } @@ -50,4 +50,4 @@ public boolean isUsingReplaceMaterial() { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMat.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMat.java index 68c5577d..e4bd7482 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMat.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMat.java @@ -5,7 +5,9 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,8 +16,8 @@ public class pInkMat extends vPerformer { - private byte d; - private int ir; + private String i; + private Material rm; public pInkMat() { @@ -26,26 +28,25 @@ public pInkMat() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - ir = v.getReplaceId(); + i = v.getVoxelInk(); + rm = v.getReplaceMat(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); + vm.voxelInk(); vm.replace(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir) + if (b.getType() == rm) { h.put(b); - b.setData(d, true); + Inker.ink(b, i, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMatNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMatNoPhys.java index 6a6baa09..b42f71e8 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMatNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkMatNoPhys.java @@ -1,8 +1,10 @@ package com.thevoxelbox.voxelsniper.brush.perform; +import org.bukkit.Material; import org.bukkit.block.Block; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; /** * @author Voxel @@ -10,8 +12,8 @@ public class pInkMatNoPhys extends vPerformer { - private byte d; - private int ir; + private String i; + private Material rm; public pInkMatNoPhys() { @@ -22,26 +24,25 @@ public pInkMatNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); - ir = v.getReplaceId(); + i = v.getVoxelInk(); + rm = v.getReplaceMat(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); + vm.voxelInk(); vm.replace(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir) + if (b.getType() == rm) { h.put(b); - b.setData(d, false); + Inker.ink(b, i, false); } } @@ -50,4 +51,4 @@ public boolean isUsingReplaceMaterial() { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoPhys.java index 7b977f8e..bd077486 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoPhys.java @@ -3,6 +3,7 @@ import org.bukkit.block.Block; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; /** * @author Voxel @@ -10,7 +11,7 @@ public class pInkNoPhys extends vPerformer { - private byte d; + private String i; public pInkNoPhys() { @@ -21,21 +22,20 @@ public pInkNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); + i = v.getVoxelInk(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); + vm.voxelInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { h.put(b); - b.setData(d, false); + Inker.ink(b, i, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoUndo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoUndo.java index a2264f6e..862e1ad3 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoUndo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pInkNoUndo.java @@ -5,6 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; import org.bukkit.block.Block; @@ -14,7 +15,7 @@ public class pInkNoUndo extends vPerformer { - private byte d; + private String i; public pInkNoUndo() { @@ -25,23 +26,22 @@ public pInkNoUndo() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - d = v.getData(); + i = v.getVoxelInk(); } @Override public void info(Message vm) { vm.performerName(name); - vm.data(); + vm.voxelInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() != d) + if (Inker.matches(b, i)) { - b.setData(d); + Inker.ink(b, i); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatCombo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatCombo.java index 75d94066..b0ccf042 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatCombo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatCombo.java @@ -5,8 +5,9 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +15,8 @@ public class pMatCombo extends vPerformer { - private byte dr; - private int i; - private int ir; + private BlockData rd; + private Material t; public pMatCombo() { @@ -27,9 +27,8 @@ public pMatCombo() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - dr = v.getReplaceData(); - i = v.getVoxelId(); - ir = v.getReplaceId(); + rd = v.getReplaceData(); + t = v.getVoxelMat(); } @Override @@ -38,17 +37,16 @@ public void info(Message vm) vm.performerName(name); vm.voxel(); vm.replace(); - vm.replaceData(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir && b.getData() == dr) + if (b.getBlockData().matches(rd)) { h.put(b); - b.setTypeId(i, true); + b.setType(t, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatComboNophys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatComboNophys.java index 8ce7c7b9..449fe1af 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatComboNophys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatComboNophys.java @@ -5,8 +5,9 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author Voxel @@ -14,9 +15,8 @@ public class pMatComboNophys extends vPerformer { - private byte dr; - private int i; - private int ir; + private BlockData rd; + private Material t; public pMatComboNophys() { @@ -27,9 +27,8 @@ public pMatComboNophys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - dr = v.getReplaceData(); - i = v.getVoxelId(); - ir = v.getReplaceId(); + rd = v.getReplaceData(); + t = v.getVoxelMat(); } @Override @@ -38,17 +37,16 @@ public void info(Message vm) vm.performerName(name); vm.voxel(); vm.replace(); - vm.replaceData(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == ir && b.getData() == dr) + if (b.getBlockData().matches(rd)) { h.put(b); - b.setTypeId(i, false); + b.setType(t, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInk.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInk.java index 7b275bf0..d1ac6475 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInk.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInk.java @@ -5,7 +5,9 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,8 +16,8 @@ public class pMatInk extends vPerformer { - private int i; - private byte dr; + private Material m; + private String ri; public pMatInk() { @@ -26,8 +28,8 @@ public pMatInk() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - dr = v.getReplaceData(); + m = v.getVoxelMat(); + ri = v.getReplaceInk(); } @Override @@ -35,17 +37,16 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.replaceData(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() == dr) + if (Inker.matches(b, ri)) { h.put(b); - b.setTypeId(i, true); + b.setType(m, true); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInkNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInkNoPhys.java index cda76c6a..d2708e79 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInkNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatInkNoPhys.java @@ -5,7 +5,9 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; +import com.thevoxelbox.voxelsniper.util.Inker; +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,8 +16,8 @@ public class pMatInkNoPhys extends vPerformer { - private int i; - private byte dr; + private Material m; + private String ri; public pMatInkNoPhys() { @@ -26,8 +28,8 @@ public pMatInkNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - dr = v.getReplaceData(); + m = v.getVoxelMat(); + ri = v.getReplaceInk(); } @Override @@ -35,17 +37,16 @@ public void info(Message vm) { vm.performerName(name); vm.voxel(); - vm.replaceData(); + vm.replaceInk(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getData() == dr) + if (Inker.matches(b, ri)) { h.put(b); - b.setTypeId(i, false); + b.setType(m, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMat.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMat.java index f332f0b3..a19f4ffc 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMat.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMat.java @@ -5,7 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,8 +14,8 @@ public class pMatMat extends vPerformer { - private int i; - private int r; + private Material vt; + private Material rt; public pMatMat() { @@ -26,8 +26,8 @@ public pMatMat() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - r = v.getReplaceId(); + vt = v.getVoxelMat(); + rt = v.getReplaceMat(); } @Override @@ -38,14 +38,13 @@ public void info(Message vm) vm.replace(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == r) + if (b.getType() == rt) { h.put(b); - b.setTypeId(i); + b.setType(vt); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMatNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMatNoPhys.java index 24a12b6c..3f9b0b36 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMatNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMatMatNoPhys.java @@ -5,7 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,8 +14,8 @@ public class pMatMatNoPhys extends vPerformer { - private int i; - private int r; + private Material vt; + private Material rt; public pMatMatNoPhys() { @@ -26,8 +26,8 @@ public pMatMatNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); - r = v.getReplaceId(); + vt = v.getVoxelMat(); + rt = v.getReplaceMat(); } @Override @@ -38,14 +38,13 @@ public void info(Message vm) vm.replace(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() == r) + if (b.getType() == rt) { h.put(b); - b.setTypeId(i, false); + b.setType(vt, false); } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterial.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterial.java index 1525804f..1148bace 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterial.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterial.java @@ -5,7 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,7 +14,7 @@ public class pMaterial extends vPerformer { - private int i; + private Material t; public pMaterial() { @@ -25,7 +25,7 @@ public pMaterial() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); + t = v.getVoxelMat(); } @Override @@ -35,14 +35,13 @@ public void info(Message vm) vm.voxel(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() != i) + if (b.getType() != t) { h.put(b); - b.setTypeId(i); + b.setType(t); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterialNoPhys.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterialNoPhys.java index aadd0e9d..e2256dc9 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterialNoPhys.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pMaterialNoPhys.java @@ -5,7 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -13,7 +13,7 @@ */ public class pMaterialNoPhys extends vPerformer { - private int i; + private Material t; public pMaterialNoPhys() { @@ -24,7 +24,7 @@ public pMaterialNoPhys() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); + t = v.getVoxelMat(); } @Override @@ -34,14 +34,13 @@ public void info(Message vm) vm.voxel(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() != i) + if (b.getType() != t) { h.put(b); - b.setTypeId(i, false); + b.setType(t, false); } } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pNoUndo.java b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pNoUndo.java index f5da5808..5298b467 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pNoUndo.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/pNoUndo.java @@ -5,7 +5,7 @@ package com.thevoxelbox.voxelsniper.brush.perform; import com.thevoxelbox.voxelsniper.Message; - +import org.bukkit.Material; import org.bukkit.block.Block; /** @@ -14,7 +14,7 @@ public class pNoUndo extends vPerformer { - private int i; + private Material t; public pNoUndo() { @@ -25,7 +25,7 @@ public pNoUndo() public void init(com.thevoxelbox.voxelsniper.SnipeData v) { w = v.getWorld(); - i = v.getVoxelId(); + t = v.getVoxelMat(); } @Override @@ -35,13 +35,12 @@ public void info(Message vm) vm.voxel(); } - @SuppressWarnings("deprecation") - @Override + @Override public void perform(Block b) { - if (b.getTypeId() != i) + if (b.getType() != t) { - b.setTypeId(i); + b.setType(t); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelBrushToolCommand.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelBrushToolCommand.java index b50a7106..e6eda161 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelBrushToolCommand.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelBrushToolCommand.java @@ -42,7 +42,7 @@ else if (args[1].equalsIgnoreCase("powder")) if (args.length == 3 && args[2] != null && !args[2].isEmpty()) { - Material itemInHand = (player.getItemInHand() != null) ? player.getItemInHand().getType() : null; + Material itemInHand = (player.getInventory().getItemInMainHand() != null) ? player.getInventory().getItemInMainHand().getType() : null; if (itemInHand == null) { player.sendMessage("/btool assign "); @@ -68,7 +68,7 @@ else if (args[0].equalsIgnoreCase("remove")) } else { - Material itemInHand = (player.getItemInHand() != null) ? player.getItemInHand().getType() : null; + Material itemInHand = (player.getInventory().getItemInMainHand() != null) ? player.getInventory().getItemInMainHand().getType() : null; if (itemInHand == null) { player.sendMessage("Can't unassign empty hands."); diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkCommand.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkCommand.java index 23f4ee4f..32a97966 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkCommand.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkCommand.java @@ -1,11 +1,9 @@ package com.thevoxelbox.voxelsniper.command; -import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; -import org.bukkit.block.Block; import org.bukkit.entity.Player; public class VoxelInkCommand extends VoxelCommand @@ -22,36 +20,28 @@ public boolean onCommand(Player player, String[] args) { Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); - byte dataValue; + String ink; if (args.length == 0) { - Block targetBlock = new RangeBlockHelper(player, player.getWorld()).getTargetBlock(); - if (targetBlock != null) - { - dataValue = targetBlock.getData(); - } - else - { - return true; - } + ink = ""; } else { - try - { - dataValue = Byte.parseByte(args[0]); + String arg = args[0]; + // We do some basic validation, but hard to do much here. Maybe we could do more in the future. + if (arg.startsWith("[") && arg.endsWith("]")) { + ink = arg; } - catch (NumberFormatException exception) - { - player.sendMessage("Couldn't parse input."); + else { + player.sendMessage("Input is not a valid trait list."); return true; } } SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); - snipeData.setData(dataValue); - snipeData.getVoxelMessage().data(); + snipeData.setVoxelInk(ink); + snipeData.getVoxelMessage().voxelInk(); return true; } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkReplaceCommand.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkReplaceCommand.java index e75d9174..c28b9039 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkReplaceCommand.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelInkReplaceCommand.java @@ -1,11 +1,9 @@ package com.thevoxelbox.voxelsniper.command; -import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; -import org.bukkit.block.Block; import org.bukkit.entity.Player; public class VoxelInkReplaceCommand extends VoxelCommand @@ -22,36 +20,28 @@ public boolean onCommand(Player player, String[] args) { Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); - byte dataValue; + String ink; if (args.length == 0) { - Block targetBlock = new RangeBlockHelper(player, player.getWorld()).getTargetBlock(); - if (targetBlock != null) - { - dataValue = targetBlock.getData(); - } - else - { - return true; - } + ink = ""; } else { - try - { - dataValue = Byte.parseByte(args[0]); + String arg = args[0]; + // We do some basic validation, but hard to do much here. Maybe we could do more in the future. + if (arg.startsWith("[") && arg.endsWith("]")) { + ink = arg; } - catch (NumberFormatException exception) - { - player.sendMessage("Couldn't parse input."); + else { + player.sendMessage("Input is not a valid trait list."); return true; } } SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); - snipeData.setReplaceData(dataValue); - snipeData.getVoxelMessage().replaceData(); + snipeData.setReplaceInk(ink); + snipeData.getVoxelMessage().replaceInk(); return true; } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelListCommand.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelListCommand.java index c58ddcec..e0f4245d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelListCommand.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelListCommand.java @@ -5,8 +5,12 @@ import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; public class VoxelListCommand extends VoxelCommand @@ -18,6 +22,7 @@ public VoxelListCommand(final VoxelSniper plugin) setPermission("voxelsniper.sniper"); } + @SuppressWarnings("deprecation") @Override public boolean onCommand(Player player, String[] args) { @@ -28,7 +33,7 @@ public boolean onCommand(Player player, String[] args) { final RangeBlockHelper rangeBlockHelper = new RangeBlockHelper(player, player.getWorld()); final Block targetBlock = rangeBlockHelper.getTargetBlock(); - snipeData.getVoxelList().add(new int[]{ targetBlock.getTypeId(), targetBlock.getData() }); + snipeData.getVoxelList().addBlock(targetBlock.getBlockData()); snipeData.getVoxelMessage().voxelList(); return true; } @@ -46,53 +51,70 @@ public boolean onCommand(Player player, String[] args) for (final String string : args) { - String tmpint; - Integer xint; - Integer xdat; + String tmpint = string; + boolean isTag = false; if (string.startsWith("-")) { remove = true; tmpint = string.replaceAll("-", ""); } - else + else if (string.startsWith("#")) { - tmpint = string; + isTag = true; + tmpint = string.replaceAll("#", ""); } try { - if (tmpint.contains(":")) + if (isTag) { - String[] tempintsplit = tmpint.split(":"); - xint = Integer.parseInt(tempintsplit[0]); - xdat = Integer.parseInt(tempintsplit[1]); + String[] parts = tmpint.split(":", 2); + + NamespacedKey key; + if (parts.length == 1) + { + key = NamespacedKey.minecraft(parts[0]); + } + else + { + key = new NamespacedKey(parts[0], parts[1]); + } + + Tag tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, key, Material.class); + + if (tag != null) + { + if (remove) + { + snipeData.getVoxelList().addTag(tag); + } + else + { + snipeData.getVoxelList().removeTag(tag); + } + } } else { - xint = Integer.parseInt(tmpint); - xdat = -1; - } + BlockData blockData = Bukkit.createBlockData(tmpint); - if (Material.getMaterial(xint) != null && Material.getMaterial(xint).isBlock()) - { - if (!remove) + if(remove) { - snipeData.getVoxelList().add(new int[]{ xint, xdat }); - snipeData.getVoxelMessage().voxelList(); + snipeData.getVoxelList().removeBlock(blockData); } else { - snipeData.getVoxelList().removeValue(new int[]{ xint, xdat }); - snipeData.getVoxelMessage().voxelList(); + snipeData.getVoxelList().addBlock(blockData); } } - } - catch (NumberFormatException ignored) + catch (IllegalArgumentException ignored) { } } + snipeData.getVoxelMessage().voxelList(); + return true; } } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelReplaceCommand.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelReplaceCommand.java index 006a8ef4..64457445 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelReplaceCommand.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelReplaceCommand.java @@ -30,7 +30,7 @@ public boolean onCommand(Player player, String[] args) Block targetBlock = new RangeBlockHelper(player, player.getWorld()).getTargetBlock(); if (targetBlock != null) { - snipeData.setReplaceId(targetBlock.getTypeId()); + snipeData.setReplaceMat(targetBlock.getType()); snipeData.getVoxelMessage().replace(); } return true; @@ -41,7 +41,7 @@ public boolean onCommand(Player player, String[] args) { if (material.isBlock()) { - snipeData.setReplaceId(material.getId()); + snipeData.setReplaceMat(material); snipeData.getVoxelMessage().replace(); return true; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java index fb466c67..421828e0 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java @@ -30,12 +30,12 @@ public boolean onCommand(Player player, String[] args) Block targetBlock = new RangeBlockHelper(player, player.getWorld()).getTargetBlock(); if (targetBlock != null) { - if (!player.hasPermission("voxelsniper.ignorelimitations") && plugin.getVoxelSniperConfiguration().getLiteSniperRestrictedItems().contains(targetBlock.getTypeId())) + if (!player.hasPermission("voxelsniper.ignorelimitations") && plugin.getVoxelSniperConfiguration().getLiteSniperRestrictedItems().contains(targetBlock.getType())) { player.sendMessage("You are not allowed to use " + targetBlock.getType().name() + "."); return true; } - snipeData.setVoxelId(targetBlock.getTypeId()); + snipeData.setVoxelMat(targetBlock.getType()); snipeData.getVoxelMessage().voxel(); } return true; @@ -44,12 +44,12 @@ public boolean onCommand(Player player, String[] args) Material material = Material.matchMaterial(args[0]); if (material != null && material.isBlock()) { - if (!player.hasPermission("voxelsniper.ignorelimitations") && plugin.getVoxelSniperConfiguration().getLiteSniperRestrictedItems().contains(material.getId())) + if (!player.hasPermission("voxelsniper.ignorelimitations") && plugin.getVoxelSniperConfiguration().getLiteSniperRestrictedItems().contains(material)) { player.sendMessage("You are not allowed to use " + material.name() + "."); return true; } - snipeData.setVoxelId(material.getId()); + snipeData.setVoxelMat(material); snipeData.getVoxelMessage().voxel(); return true; } diff --git a/src/main/java/com/thevoxelbox/voxelsniper/event/SniperMaterialChangedEvent.java b/src/main/java/com/thevoxelbox/voxelsniper/event/SniperMaterialChangedEvent.java index 61094d9d..76429727 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/event/SniperMaterialChangedEvent.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/event/SniperMaterialChangedEvent.java @@ -1,11 +1,9 @@ package com.thevoxelbox.voxelsniper.event; import com.thevoxelbox.voxelsniper.Sniper; -import org.bukkit.block.data.BlockData; -import org.bukkit.event.Cancellable; +import org.bukkit.Material; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.material.MaterialData; /** * @@ -14,15 +12,19 @@ public class SniperMaterialChangedEvent extends Event { private static final HandlerList handlers = new HandlerList(); private final Sniper sniper; - private final BlockData originalMaterial; - private final BlockData newMaterial; + private final Material originalMaterial; + private final String originalInk; + private final Material newMaterial; + private final String newInk; private final String toolId; - public SniperMaterialChangedEvent(Sniper sniper, String toolId, BlockData originalMaterial, BlockData newMaterial) + public SniperMaterialChangedEvent(Sniper sniper, String toolId, Material originalMaterial, String originalInk, Material newMaterial, String newInk) { this.sniper = sniper; this.originalMaterial = originalMaterial; + this.originalInk = originalInk; this.newMaterial = newMaterial; + this.newInk = newInk; this.toolId = toolId; } @@ -31,16 +33,26 @@ public static HandlerList getHandlerList() return handlers; } - public BlockData getOriginalMaterial() + public Material getOriginalMaterial() { return originalMaterial; } - public BlockData getNewMaterial() + public String getOriginalInk() + { + return originalInk; + } + + public Material getNewMaterial() { return newMaterial; } + public String getNewInk() + { + return newInk; + } + public Sniper getSniper() { return sniper; diff --git a/src/main/java/com/thevoxelbox/voxelsniper/event/SniperReplaceMaterialChangedEvent.java b/src/main/java/com/thevoxelbox/voxelsniper/event/SniperReplaceMaterialChangedEvent.java index bdb6f1f5..9ca37bc3 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/event/SniperReplaceMaterialChangedEvent.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/event/SniperReplaceMaterialChangedEvent.java @@ -1,8 +1,8 @@ package com.thevoxelbox.voxelsniper.event; import com.thevoxelbox.voxelsniper.Sniper; +import org.bukkit.Material; import org.bukkit.event.HandlerList; -import org.bukkit.material.MaterialData; /** * @@ -11,9 +11,9 @@ public class SniperReplaceMaterialChangedEvent extends SniperMaterialChangedEven { private static final HandlerList handlers = new HandlerList(); - public SniperReplaceMaterialChangedEvent(Sniper sniper, String toolId, MaterialData originalMaterial, MaterialData newMaterial) + public SniperReplaceMaterialChangedEvent(Sniper sniper, String toolId, Material originalMaterial, String originalInk, Material newMaterial, String newInk) { - super(sniper, toolId, originalMaterial, newMaterial); + super(sniper, toolId, originalMaterial, originalInk, newMaterial, newInk); } public static HandlerList getHandlerList() diff --git a/src/main/java/com/thevoxelbox/voxelsniper/jsap/NullableIntegerStringParser.java b/src/main/java/com/thevoxelbox/voxelsniper/jsap/NullableIntegerStringParser.java index 30d196bf..d95aea74 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/jsap/NullableIntegerStringParser.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/jsap/NullableIntegerStringParser.java @@ -14,7 +14,7 @@ public class NullableIntegerStringParser extends StringParser { @SuppressWarnings("unused") - private static final NullableIntegerStringParser INSTANCE = new NullableIntegerStringParser(); + private static final NullableIntegerStringParser INSTANCE = new NullableIntegerStringParser(); /** * Returns a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}. diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java b/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java index 739787e6..7de86b04 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java @@ -2,6 +2,7 @@ import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @author MikeMatrix @@ -9,43 +10,29 @@ public class BlockWrapper { - private int id; + private BlockData data; private int x; private int y; private int z; - private byte data; private World world; /** * @param block */ - @SuppressWarnings("deprecation") - public BlockWrapper(final Block block) + public BlockWrapper(final Block block) { - this.setId(block.getTypeId()); + this.setBlockData(block.getBlockData()); this.setX(block.getX()); this.setY(block.getY()); this.setZ(block.getZ()); - this.setData(block.getData()); this.setWorld(block.getWorld()); } - /** - * @return the data - */ - public final byte getData() + public final BlockData getBlockData() { return this.data; } - /** - * @return the id - */ - public final int getId() - { - return this.id; - } - /** * @return the world */ @@ -78,24 +65,11 @@ public final int getZ() return this.z; } - /** - * @param data - * the data to set - */ - public final void setData(final byte data) + public final void setBlockData(final BlockData data) { this.data = data; } - /** - * @param id - * the id to set - */ - public final void setId(final int id) - { - this.id = id; - } - /** * @param world * the world to set diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/Inker.java b/src/main/java/com/thevoxelbox/voxelsniper/util/Inker.java new file mode 100644 index 00000000..06b473d0 --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/Inker.java @@ -0,0 +1,93 @@ +package com.thevoxelbox.voxelsniper.util; + +import com.google.common.base.Objects; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.util.concurrent.UncheckedExecutionException; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +public class Inker { + + private static Cache cache = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).maximumSize(100).build(); + + public static void ink(final Block existing, final String ink, boolean applyPhysics) { + BlockData inkData = inkMat(existing.getType(), ink); + BlockData existingData = existing.getBlockData(); + existing.setBlockData(existingData.merge(inkData), applyPhysics); + } + + public static void ink(Block existing, String ink) { + ink(existing, ink, true); + } + + public static BlockData inkMat(final Material mat, final String ink) { + try { + return cache.get(new CacheTuple(mat, ink), new Callable() { + + @Override + public BlockData call() { + try + { + return mat.createBlockData(ink); + } + catch (IllegalArgumentException e) + { + return mat.createBlockData(); + } + } + }); + } + catch (ExecutionException e) { + return mat.createBlockData(); + } + } + + public static boolean matches(final Block block, final String ink) { + try { + BlockData match = cache.get(new CacheTuple(block.getType(), ink), new Callable() { + + @Override + public BlockData call() { + return block.getType().createBlockData(ink); + } + }); + + return block.getBlockData().matches(match); + } + catch (ExecutionException e) { + return false; + } + catch (UncheckedExecutionException e) { + return false; + } + } + + private static class CacheTuple { + Material material; + String ink; + + private CacheTuple(Material material, String ink) { + this.material = material; + this.ink = ink; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CacheTuple that = (CacheTuple)o; + return material == that.material && Objects.equal(ink, that.ink); + } + + @Override + public int hashCode() { + return Objects.hashCode(material, ink); + } + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/SetTag.java b/src/main/java/com/thevoxelbox/voxelsniper/util/SetTag.java new file mode 100644 index 00000000..6d9fdeed --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/SetTag.java @@ -0,0 +1,35 @@ +package com.thevoxelbox.voxelsniper.util; + +import com.google.common.collect.ImmutableSet; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; + +import java.util.Set; +import org.jetbrains.annotations.NotNull; + +public class SetTag implements Tag { + + private final Set values; + private final NamespacedKey key; + + public SetTag(Set values, NamespacedKey key) { + this.values = ImmutableSet.copyOf(values); + this.key = key; + } + + @Override + public boolean isTagged(T item) { + return values.contains(item); + } + + @Override + public Set getValues() { + return values; + } + + @Override + public @NotNull NamespacedKey getKey() { + return key; + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/SpongeSchematic.java b/src/main/java/com/thevoxelbox/voxelsniper/util/SpongeSchematic.java new file mode 100644 index 00000000..8123cb0b --- /dev/null +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/SpongeSchematic.java @@ -0,0 +1,270 @@ +package com.thevoxelbox.voxelsniper.util; + +import com.flowpowered.nbt.CompoundMap; +import com.flowpowered.nbt.CompoundTag; +import com.flowpowered.nbt.IntArrayTag; +import com.flowpowered.nbt.IntTag; +import com.flowpowered.nbt.ShortTag; +import com.flowpowered.nbt.Tag; +import com.flowpowered.nbt.stream.NBTInputStream; +import com.flowpowered.nbt.stream.NBTOutputStream; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.block.data.BlockData; +import org.bukkit.util.BlockVector; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class SpongeSchematic +{ + + private int width; + private int height; + private int length; + private BlockVector offset; + private BlockData[] blockData; + + private SpongeSchematic(int width, int height, int length, BlockVector offset, BlockData[] blockData) + { + this.width = width; + this.height = height; + this.length = length; + this.offset = offset; + this.blockData = blockData; + } + + private SpongeSchematic(short width, short height, short length, BlockVector offset, BlockData[] blockData) + { + this(width & 0xFFFF, height & 0xFFFF, length & 0xFFFF, offset, blockData); + } + + public static SpongeSchematic read(File file) throws IOException + { + NBTInputStream nbtIs = null; + try + { + nbtIs = new NBTInputStream(new FileInputStream(file), true); + Tag tag = nbtIs.readTag(); + return loadSchematic(tag); + } finally + { + if (nbtIs != null) + { + nbtIs.close(); + } + } + } + + public static SpongeSchematic createFromWorld(World world, BlockVector firstPoint, BlockVector secondPoint, + BlockVector pastePoint) + { + int startX = Math.min(firstPoint.getBlockX(), secondPoint.getBlockX()); + int startY = Math.min(firstPoint.getBlockY(), secondPoint.getBlockY()); + int startZ = Math.min(firstPoint.getBlockZ(), secondPoint.getBlockZ()); + + int width = Math.abs(firstPoint.getBlockX() - secondPoint.getBlockX()); + int height = Math.abs(firstPoint.getBlockY() - secondPoint.getBlockY()); + int length = Math.abs(firstPoint.getBlockZ() - secondPoint.getBlockZ()); + BlockVector offset = pastePoint.clone(); + + int blockDataSize = width * height * length; + BlockData[] blockData = new BlockData[blockDataSize]; + for (int x = startX; x < width; x++) + { + for (int y = startY; y < length; y++) + { + for (int z = startZ; z < length; z++) + { + blockData[x + z * width + y * width * length] = world.getBlockAt(x, y, z).getBlockData(); + } + } + } + + return new SpongeSchematic(width, height, length, offset, blockData); + } + + private static SpongeSchematic loadSchematic(Tag tag) throws IOException + { + if(!(tag instanceof CompoundTag)) + { + throw new IOException("Invalid Schematic"); + } + + CompoundMap map = (CompoundMap)tag.getValue(); + + int version = getMapValue(map, "Version", IntTag.class).getValue(); + if (version != 1) + { + throw new IOException("Unsupported schematic version " + version); + } + + short width = getMapValue(map, "Width", ShortTag.class).getValue(); + short height = getMapValue(map, "Height", ShortTag.class).getValue(); + short length = getMapValue(map, "Length", ShortTag.class).getValue(); + + int[] offsetArr = getMapValue(map, "Offset", IntArrayTag.class).getValue(); + if (offsetArr.length != 3) + { + throw new IOException("Invalid length on schematic offset"); + } + + BlockVector offset = new BlockVector(offsetArr[0], offsetArr[1], offsetArr[2]); + + int paletteMax = getMapValue(map, "PaletteMax", IntTag.class).getValue(); + BlockData[] palette = new BlockData[paletteMax]; + + CompoundMap paletteMap = getMapValue(map, "Palette", CompoundTag.class).getValue(); + if (paletteMap == null) + { + throw new IOException("No palette found for schematic. VoxelSniper only supports schematics with palettes"); + } + + for (Map.Entry> paletteEntry : paletteMap.entrySet()) + { + String key = paletteEntry.getKey(); + try + { + BlockData data = Bukkit.createBlockData(key); + Tag tagNum = paletteEntry.getValue(); + + if (!(tagNum instanceof IntTag)) + { + throw new IOException("Unexpected tag type for palette value"); + } + + int id = (Integer)tagNum.getValue(); + palette[id] = data; + } + catch (IllegalArgumentException e) + { + throw new IOException("Not a valid block state: " + key); + } + } + + int[] blockDataPalette = getMapValue(map, "BlockData", IntArrayTag.class).getValue(); + int blockDataSize = width * height * length; + if (blockDataPalette.length != blockDataSize) + { + throw new IOException("Expected " + blockDataSize + ", got " + blockDataPalette.length); + } + + BlockData[] blockData = new BlockData[blockDataSize]; + for (int i = 0; i < blockDataPalette.length; i++) + { + blockData[i] = palette[blockDataPalette[i]]; + } + + return new SpongeSchematic(width, height, length, offset, blockData); + } + + @SuppressWarnings("unchecked") + private static > T getMapValue(CompoundMap map, String key, Class clazz) throws IOException + { + Tag tag = map.get(key); + if(tag == null || clazz.isInstance(tag)) + { + return (T)tag; + } + else + { + throw new IOException("Unexpected type found for " + key); + } + } + + public void writeTo(File file) throws IOException + { + NBTOutputStream os = null; + + try + { + os = new NBTOutputStream(new FileOutputStream(file)); + os.writeTag(writeSchematic()); + } finally + { + if (os != null) + { + os.close(); + } + } + } + + private CompoundTag writeSchematic() throws IOException + { + CompoundMap map = new CompoundMap(); + map.put(new IntTag("Version", 1)); + map.put(new ShortTag("Width", (short)(width << 4))); + map.put(new ShortTag("Height", (short)(height << 4))); + map.put(new ShortTag("Length", (short)(length << 4))); + map.put(new IntArrayTag("Offset", new int[] {offset.getBlockX(), offset.getBlockY(), offset.getBlockZ()})); + + Map idMap = new HashMap(); + int lastId = Integer.MIN_VALUE; + for (BlockData data : blockData) + { + if (!idMap.containsKey(data)) + { + int nextId = lastId++; + if (nextId < lastId) + { + throw new IOException("Ran out of pallete space. Too many block types"); + } + + idMap.put(data, nextId); + lastId = nextId; + } + } + + map.put(new IntTag("PaletteMax", idMap.size())); + + CompoundMap pallete = new CompoundMap(); + for (Map.Entry entry : idMap.entrySet()) + { + pallete.put(new IntTag(entry.getKey().getAsString(), entry.getValue())); + } + map.put(new CompoundTag("Pallete", pallete)); + + int[] blockDataArr = new int[width * height * length]; + for (int i = 0; i < blockData.length; i++) + { + blockDataArr[i] = idMap.get(blockData[i]); + } + map.put(new IntArrayTag("BlockData", blockDataArr)); + + return new CompoundTag("", map); + } + + public BlockData getBlockAt(int x, int y, int z) + { + return blockData[x + z * width + y * width * length]; + } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } + + public int getLength() + { + return length; + } + + public BlockVector getOffset() + { + return offset; + } + + public BlockData[] getBlockData() + { + return blockData; + } +} diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/UndoDelegate.java b/src/main/java/com/thevoxelbox/voxelsniper/util/UndoDelegate.java index c17a6b98..ce5fc3ab 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/UndoDelegate.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/UndoDelegate.java @@ -5,6 +5,7 @@ import org.bukkit.BlockChangeDelegate; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; /** * @@ -27,51 +28,25 @@ public UndoDelegate(World targetWorld) this.currentUndo = new Undo(); } - @SuppressWarnings("deprecation") - @Override - public boolean setRawTypeId(int x, int y, int z, int typeId) - { - this.currentUndo.put(targetWorld.getBlockAt(x, y, z)); - return this.targetWorld.getBlockAt(x, y, z).setTypeId(typeId, false); - } - - @SuppressWarnings("deprecation") - @Override - public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) - { - this.currentUndo.put(targetWorld.getBlockAt(x, y, z)); - return this.targetWorld.getBlockAt(x, y, z).setTypeIdAndData(typeId, (byte) data, false); - } - - @SuppressWarnings("deprecation") - @Override - public boolean setTypeId(int x, int y, int z, int typeId) - { - this.currentUndo.put(targetWorld.getBlockAt(x, y, z)); - return this.targetWorld.getBlockAt(x, y, z).setTypeId(typeId); - } - - @SuppressWarnings("deprecation") - @Override - public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) + @Override + public boolean setBlockData(int x, int y, int z, BlockData data) { this.currentUndo.put(targetWorld.getBlockAt(x, y, z)); - return this.targetWorld.getBlockAt(x, y, z).setTypeIdAndData(typeId, (byte) data, true); + this.targetWorld.getBlockAt(x, y, z).setBlockData(data, true); + return true; } - @SuppressWarnings("deprecation") - public boolean setBlock(Block b) + public void setBlock(Block b) { this.currentUndo.put(this.targetWorld.getBlockAt(b.getLocation())); - return this.targetWorld.getBlockAt(b.getLocation()).setTypeIdAndData(b.getTypeId(), b.getData(), true); + this.targetWorld.getBlockAt(b.getLocation()).setBlockData(b.getBlockData(), true); } - @SuppressWarnings("deprecation") - @Override - public int getTypeId(int x, int y, int z) + @Override + public BlockData getBlockData(int x, int y, int z) { - return this.targetWorld.getBlockAt(x, y, z).getTypeId(); + return this.targetWorld.getBlockAt(x, y, z).getBlockData(); } @Override diff --git a/src/main/java/com/thevoxelbox/voxelsniper/util/VoxelList.java b/src/main/java/com/thevoxelbox/voxelsniper/util/VoxelList.java index 7781364e..ab8f810d 100644 --- a/src/main/java/com/thevoxelbox/voxelsniper/util/VoxelList.java +++ b/src/main/java/com/thevoxelbox/voxelsniper/util/VoxelList.java @@ -2,10 +2,10 @@ import com.google.common.collect.ImmutableList; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.data.BlockData; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -14,73 +14,66 @@ public class VoxelList { - private static final BlockData AIR = Material.AIR.createBlockData(); - - private List valuePairs = new ArrayList(); + private List blocks = new ArrayList(); + private List> tags = new ArrayList>(); /** - * Adds the specified id, data value pair to the VoxelList. A data value of -1 will operate on all data values of that id. + * Adds the specified block data the VoxelList. * * @param i */ - public void add(BlockData[] i) + public void addBlock(BlockData i) { - if (i[1] == AIR) + if (!blocks.contains(i)) { - if (!valuePairs.contains(i)) - { - for (Iterator it = valuePairs.iterator(); it.hasNext(); ) - { - BlockData[] in = it.next(); - if (in[0] == i[0]) - { - it.remove(); - } - } - valuePairs.add(i); - } + blocks.add(i); } - else + } + + /** + * Adds the specified tag to the VoxelList. + */ + public void addTag(Tag tag) + { + if (!tags.contains(tag)) { - if (!valuePairs.contains(i)) - { - valuePairs.add(i); - } + tags.add(tag); } } /** - * Removes the specified id, data value pair from the VoxelList. - * + * Removes the specified block data from the VoxelList. + * * @param i * @return true if this list contained the specified element */ - public boolean removeValue(final BlockData[] i) + public boolean removeBlock(final BlockData i) { - if (valuePairs.isEmpty()) + if (blocks.isEmpty()) { return false; } else { - boolean ret = false; - if (i[1] == -1) - { - for (Iterator it = valuePairs.iterator(); it.hasNext(); ) - { - int[] in = it.next(); - if (in[0] == i[0]) - { - it.remove(); - ret = true; - } - } - } - else - { - ret = valuePairs.remove(i); - } - return ret; + return blocks.remove(i); + } + } + + /** + * Removes the specified tag from the VoxelList. + * + * @return true if this list contained the specified element + */ + public boolean removeTag(final Tag tag) + { + //TODO: Does equality work on tags? + if (tags.isEmpty()) + { + return false; + } + else + { + return tags.remove(tag); } } @@ -88,12 +81,18 @@ public boolean removeValue(final BlockData[] i) * @param i * @return true if this list contains the specified element */ - public boolean contains(final BlockData[] i) + public boolean contains(final BlockData i) { - for (BlockData[] in : valuePairs) + for (BlockData in : blocks) + { + if (i.matches(in)) { + return true; + } + } + + for (Tag tag : tags) { - if (in[0].matches(i[0]) && (in[1] == i[1] || in[1] == AIR)) - { + if (tag.isTagged(i.getMaterial())) { return true; } } @@ -105,7 +104,8 @@ public boolean contains(final BlockData[] i) */ public void clear() { - valuePairs.clear(); + blocks.clear(); + tags.clear(); } /** @@ -115,18 +115,27 @@ public void clear() */ public boolean isEmpty() { - return valuePairs.isEmpty(); + return blocks.isEmpty() && tags.isEmpty(); } /** - * Returns a defensive copy of the List with pairs. + * Returns a defensive copy of the List. * - * @return defensive copy of the List with pairs + * @return defensive copy of the List */ - public List getList() + public List getBlockList() { - return ImmutableList.copyOf(valuePairs); + return ImmutableList.copyOf(blocks); } + /** + * Returns a defensive copy of the List. + * + * @return defensive copy of the List + */ + public List> getTagList() + { + return ImmutableList.copyOf(tags); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 650f5f50..87c71b90 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,355 +1,356 @@ -name: ${project.artifactId} -main: com.thevoxelbox.voxelsniper.VoxelSniper -version: ${project.build.version} -website: ${project.url} -authors: [przerwap, MikeMatrix, Gavjenks, giltwist, psanker, Deamon5550, DivineRage] -description: ${project.description} -softdepend: [VoxelModPackPlugin] -commands: - paint: - description: Change the selected painting to another painting. - usage: | - / - Example: / -- Cycles through paintings. You must be adjacent to the painting and aiming at it. - goto: - description: Warps to the specified coordinates. - permission: voxelsniper.goto - usage: | - / [X] [Z] - Example: / 100 -100 -- Takes the user to the coordinates X: 100, Z: -100. The Y-coordinate will always be 1 more than the Y-coordinate of the highest block at the X and Z-coordinates provided. - u: - description: Undoes the last snipe. - permission: voxelsniper.sniper - usage: | - / - Example: / -- Undoes your most recent snipe. - uu: - description: UndoUser undoes another sniper user's snipes. - permission: voxelsniper.sniper - usage: | - / [playername] - Example: / bads -- Undoes BadSniper's last snipe. BadSniper must be online for name detection to function. Truncation allowed. - d: - description: VoxelSniper Default. - permission: voxelsniper.sniper - usage: | - / - Example: / -- Resets the brush settings to their default values. - p: - description: Voxelsniper performer. - permission: voxelsniper.sniper - aliases: [perf, performer] - usage: | - / - Example: / -- Sets the performer of the current brush to "m". - / - Example: / -- Sets the performer of the current brush to . - vs: - description: VoxelSniper Settings. - permission: voxelsniper.sniper - usage: | - / - Example: / -- Returns the current brush settings. - vc: - description: VoxelCentroid. - permission: voxelsniper.sniper - usage: | - / - Example: / -1 -- Sets the Clone Cylinder's Y value for the base relative to the Clone Point. - vh: - description: VoxelHeight. - permission: voxelsniper.sniper - usage: | - / [voxel-height] - Example: / -- Sets the brush height. - vi: - description: VoxelInk (Data Value). - permission: voxelsniper.sniper - usage: | - / [0-16] - Example: / -- sets a data value of 6 (e.g. pink wool). - vr: - description: VoxelReplace. - permission: voxelsniper.sniper - usage: | - / [0-159] - Example: / 12 -- Sets a replace brush to select sand blocks for replacement. - vl: - description: VoxelBlockExclusion list - permission: voxelsniper.sniper - usage: | - / - Example: / 89 -5 -- Adds glowstone to the voxel list and removes planks from the voxel list. - vir: - description: VoxelInkReplace. - permission: voxelsniper.sniper - usage: | - / [0-16] - Example: / 12 -- Sets a replace ink brush to select data 6 blocks for replacement. - v: - description: Voxel input. - permission: voxelsniper.sniper - usage: | - / [0-159] - Example: / 1 -- Loads the sniper with Stone blocks. - b: - description: Brush. - permission: voxelsniper.sniper - usage: | - / [brush-size] - Example: / 5 -- Sets a brush radius size of 5 (11 spaces across). - Example: / b cm -- Sets your brush to the Ball Brush with the combo-mat performer. - btool: - description: Brush Tool Command. - permission: voxelsniper.sniper - usage : | - / -- Prints out command usage information. - vchunk: - description: Update the chunk you are standing in. - usage: | - / - Example: / -- Loads the chunk you're standing in. -permissions: - voxelsniper.sniper: - default: op - voxelsniper.ignorelimitations: - default: op - voxelsniper.goto: - default: op - voxelsniper.brush.*: - default: op - children: - voxelsniper.brush.ball: true - voxelsniper.brush.biome: true - voxelsniper.brush.blendball: true - voxelsniper.brush.blenddisc: true - voxelsniper.brush.blendvoxel: true - voxelsniper.brush.blendvoxeldisc: true - voxelsniper.brush.blob: true - voxelsniper.brush.blockreset: true - voxelsniper.brush.blockresetsurface: true - voxelsniper.brush.canyon: true - voxelsniper.brush.canyonselection: true - voxelsniper.brush.checkervoxeldisc: true - voxelsniper.brush.cleansnow: true - voxelsniper.brush.clonestamp: true - voxelsniper.brush.comet: true - voxelsniper.brush.copypasta: true - voxelsniper.brush.cylinder: true - voxelsniper.brush.disc: true - voxelsniper.brush.discface: true - voxelsniper.brush.dome: true - voxelsniper.brush.drain: true - voxelsniper.brush.ellipse: true - voxelsniper.brush.ellipsoid: true - voxelsniper.brush.entity: true - voxelsniper.brush.entityremoval: true - voxelsniper.brush.eraser: true - voxelsniper.brush.erode: true - voxelsniper.brush.extrude: true - voxelsniper.brush.filldown: true - voxelsniper.brush.flatocean: true - voxelsniper.brush.generatetree: true - voxelsniper.brush.heatray: true - voxelsniper.brush.jaggedline: true - voxelsniper.brush.jockey: true - voxelsniper.brush.lightning: true - voxelsniper.brush.line: true - voxelsniper.brush.move: true - voxelsniper.brush.ocean: true - voxelsniper.brush.overlay: true - voxelsniper.brush.painting: true - voxelsniper.brush.pull: true - voxelsniper.brush.punish: true - voxelsniper.brush.randomerode: true - voxelsniper.brush.regeneratechunk: true - voxelsniper.brush.ring: true - voxelsniper.brush.rot2d: true - voxelsniper.brush.rot2dvert: true - voxelsniper.brush.rot3d: true - voxelsniper.brush.ruler: true - voxelsniper.brush.scanner: true - voxelsniper.brush.set: true - voxelsniper.brush.setredstoneflip: true - voxelsniper.brush.setredstonerotate: true - voxelsniper.brush.shellball: true - voxelsniper.brush.shellset: true - voxelsniper.brush.shellvoxel: true - voxelsniper.brush.signoverwrite: true - voxelsniper.brush.snipe: true - voxelsniper.brush.snowcone: true - voxelsniper.brush.spiralstaircase: true - voxelsniper.brush.splatterball: true - voxelsniper.brush.splatterdisc: true - voxelsniper.brush.splatteroverlay: true - voxelsniper.brush.splattervoxel: true - voxelsniper.brush.splattervoxeldisc: true - voxelsniper.brush.spline: true - voxelsniper.brush.stamp: true - voxelsniper.brush.stencil: true - voxelsniper.brush.stencillist: true - voxelsniper.brush.threepointcircle: true - voxelsniper.brush.treesnipe: true - voxelsniper.brush.triangle: true - voxelsniper.brush.underlay: true - voxelsniper.brush.voltmeter: true - voxelsniper.brush.voxel: true - voxelsniper.brush.voxeldisc: true - voxelsniper.brush.voxeldiscface: true - voxelsniper.brush.warp: true - voxelsniper.brush.ball: - default: op - voxelsniper.brush.biome: - default: op - voxelsniper.brush.blendball: - default: op - voxelsniper.brush.blenddisc: - default: op - voxelsniper.brush.blendvoxel: - default: op - voxelsniper.brush.blendvoxeldisc: - default: op - voxelsniper.brush.blob: - default: op - voxelsniper.brush.blockreset: - default: op - voxelsniper.brush.blockresetsurface: - default: op - voxelsniper.brush.canyon: - default: op - voxelsniper.brush.canyonselection: - default: op - voxelsniper.brush.checkervoxeldisc: - default: op - voxelsniper.brush.cleansnow: - default: op - voxelsniper.brush.clonestamp: - default: op - voxelsniper.brush.comet: - default: op - voxelsniper.brush.copypasta: - default: op - voxelsniper.brush.cylinder: - default: op - voxelsniper.brush.disc: - default: op - voxelsniper.brush.discface: - default: op - voxelsniper.brush.dome: - default: op - voxelsniper.brush.drain: - default: op - voxelsniper.brush.ellipse: - default: op - voxelsniper.brush.ellipsoid: - default: op - voxelsniper.brush.entity: - default: op - voxelsniper.brush.entityremoval: - default: op - voxelsniper.brush.eraser: - default: op - voxelsniper.brush.erode: - default: op - voxelsniper.brush.extrude: - default: op - voxelsniper.brush.filldown: - default: op - voxelsniper.brush.flatocean: - default: op - voxelsniper.brush.generatetree: - default: op - voxelsniper.brush.heatray: - default: op - voxelsniper.brush.jaggedline: - default: op - voxelsniper.brush.jockey: - default: op - voxelsniper.brush.lightning: - default: op - voxelsniper.brush.line: - default: op - voxelsniper.brush.move: - default: op - voxelsniper.brush.ocean: - default: op - voxelsniper.brush.overlay: - default: op - voxelsniper.brush.painting: - default: op - voxelsniper.brush.pull: - default: op - voxelsniper.brush.punish: - default: op - voxelsniper.brush.randomerode: - default: op - voxelsniper.brush.regeneratechunk: - default: op - voxelsniper.brush.ring: - default: op - voxelsniper.brush.rot2d: - default: op - voxelsniper.brush.rot2dvert: - default: op - voxelsniper.brush.rot3d: - default: op - voxelsniper.brush.ruler: - default: op - voxelsniper.brush.scanner: - default: op - voxelsniper.brush.set: - default: op - voxelsniper.brush.setredstoneflip: - default: op - voxelsniper.brush.setredstonerotate: - default: op - voxelsniper.brush.shellball: - default: op - voxelsniper.brush.shellset: - default: op - voxelsniper.brush.shellvoxel: - default: op - voxelsniper.brush.signoverwrite: - default: op - voxelsniper.brush.snipe: - default: op - voxelsniper.brush.snowcone: - default: op - voxelsniper.brush.spiralstaircase: - default: op - voxelsniper.brush.splatterball: - default: op - voxelsniper.brush.splatterdisc: - default: op - voxelsniper.brush.splatteroverlay: - default: op - voxelsniper.brush.splattervoxel: - default: op - voxelsniper.brush.splattervoxeldisc: - default: op - voxelsniper.brush.spline: - default: op - voxelsniper.brush.stamp: - default: op - voxelsniper.brush.stencil: - default: op - voxelsniper.brush.stencillist: - default: op - voxelsniper.brush.threepointcircle: - default: op - voxelsniper.brush.treesnipe: - default: op - voxelsniper.brush.triangle: - default: op - voxelsniper.brush.underlay: - default: op - voxelsniper.brush.voltmeter: - default: op - voxelsniper.brush.voxel: - default: op - voxelsniper.brush.voxeldisc: - default: op - voxelsniper.brush.voxeldiscface: - default: op - voxelsniper.brush.warp: - default: op +name: ${project.artifactId} +main: com.thevoxelbox.voxelsniper.VoxelSniper +version: ${project.build.version} +api-version: "1.18" +website: ${project.url} +authors: [przerwap, MikeMatrix, Gavjenks, giltwist, psanker, Deamon5550, DivineRage] +description: ${project.description} +softdepend: [VoxelModPackPlugin] +commands: + paint: + description: Change the selected painting to another painting. + usage: | + / + Example: / -- Cycles through paintings. You must be adjacent to the painting and aiming at it. + goto: + description: Warps to the specified coordinates. + permission: voxelsniper.goto + usage: | + / [X] [Z] + Example: / 100 -100 -- Takes the user to the coordinates X: 100, Z: -100. The Y-coordinate will always be 1 more than the Y-coordinate of the highest block at the X and Z-coordinates provided. + u: + description: Undoes the last snipe. + permission: voxelsniper.sniper + usage: | + / + Example: / -- Undoes your most recent snipe. + uu: + description: UndoUser undoes another sniper user's snipes. + permission: voxelsniper.sniper + usage: | + / [playername] + Example: / bads -- Undoes BadSniper's last snipe. BadSniper must be online for name detection to function. Truncation allowed. + d: + description: VoxelSniper Default. + permission: voxelsniper.sniper + usage: | + / + Example: / -- Resets the brush settings to their default values. + p: + description: Voxelsniper performer. + permission: voxelsniper.sniper + aliases: [perf, performer] + usage: | + / + Example: / -- Sets the performer of the current brush to "m". + / + Example: / -- Sets the performer of the current brush to . + vs: + description: VoxelSniper Settings. + permission: voxelsniper.sniper + usage: | + / + Example: / -- Returns the current brush settings. + vc: + description: VoxelCentroid. + permission: voxelsniper.sniper + usage: | + / + Example: / -1 -- Sets the Clone Cylinder's Y value for the base relative to the Clone Point. + vh: + description: VoxelHeight. + permission: voxelsniper.sniper + usage: | + / [voxel-height] + Example: / -- Sets the brush height. + vi: + description: VoxelInk (Data Value). + permission: voxelsniper.sniper + usage: | + / [0-16] + Example: / -- sets a data value of 6 (e.g. pink wool). + vr: + description: VoxelReplace. + permission: voxelsniper.sniper + usage: | + / [0-159] + Example: / 12 -- Sets a replace brush to select sand blocks for replacement. + vl: + description: VoxelBlockExclusion list + permission: voxelsniper.sniper + usage: | + / + Example: / 89 -5 -- Adds glowstone to the voxel list and removes planks from the voxel list. + vir: + description: VoxelInkReplace. + permission: voxelsniper.sniper + usage: | + / [0-16] + Example: / 12 -- Sets a replace ink brush to select data 6 blocks for replacement. + v: + description: Voxel input. + permission: voxelsniper.sniper + usage: | + / [0-159] + Example: / 1 -- Loads the sniper with Stone blocks. + b: + description: Brush. + permission: voxelsniper.sniper + usage: | + / [brush-size] + Example: / 5 -- Sets a brush radius size of 5 (11 spaces across). + Example: / b cm -- Sets your brush to the Ball Brush with the combo-mat performer. + btool: + description: Brush Tool Command. + permission: voxelsniper.sniper + usage : | + / -- Prints out command usage information. + vchunk: + description: Update the chunk you are standing in. + usage: | + / + Example: / -- Loads the chunk you're standing in. +permissions: + voxelsniper.sniper: + default: op + voxelsniper.ignorelimitations: + default: op + voxelsniper.goto: + default: op + voxelsniper.brush.*: + default: op + children: + voxelsniper.brush.ball: true + voxelsniper.brush.biome: true + voxelsniper.brush.blendball: true + voxelsniper.brush.blenddisc: true + voxelsniper.brush.blendvoxel: true + voxelsniper.brush.blendvoxeldisc: true + voxelsniper.brush.blob: true + voxelsniper.brush.blockreset: true + voxelsniper.brush.blockresetsurface: true + voxelsniper.brush.canyon: true + voxelsniper.brush.canyonselection: true + voxelsniper.brush.checkervoxeldisc: true + voxelsniper.brush.cleansnow: true + voxelsniper.brush.clonestamp: true + voxelsniper.brush.comet: true + voxelsniper.brush.copypasta: true + voxelsniper.brush.cylinder: true + voxelsniper.brush.disc: true + voxelsniper.brush.discface: true + voxelsniper.brush.dome: true + voxelsniper.brush.drain: true + voxelsniper.brush.ellipse: true + voxelsniper.brush.ellipsoid: true + voxelsniper.brush.entity: true + voxelsniper.brush.entityremoval: true + voxelsniper.brush.eraser: true + voxelsniper.brush.erode: true + voxelsniper.brush.extrude: true + voxelsniper.brush.filldown: true + voxelsniper.brush.flatocean: true + voxelsniper.brush.generatetree: true + voxelsniper.brush.heatray: true + voxelsniper.brush.jaggedline: true + voxelsniper.brush.jockey: true + voxelsniper.brush.lightning: true + voxelsniper.brush.line: true + voxelsniper.brush.move: true + voxelsniper.brush.ocean: true + voxelsniper.brush.overlay: true + voxelsniper.brush.painting: true + voxelsniper.brush.pull: true + voxelsniper.brush.punish: true + voxelsniper.brush.randomerode: true + voxelsniper.brush.regeneratechunk: true + voxelsniper.brush.ring: true + voxelsniper.brush.rot2d: true + voxelsniper.brush.rot2dvert: true + voxelsniper.brush.rot3d: true + voxelsniper.brush.ruler: true + voxelsniper.brush.scanner: true + voxelsniper.brush.set: true + voxelsniper.brush.setredstoneflip: true + voxelsniper.brush.setredstonerotate: true + voxelsniper.brush.shellball: true + voxelsniper.brush.shellset: true + voxelsniper.brush.shellvoxel: true + voxelsniper.brush.signoverwrite: true + voxelsniper.brush.snipe: true + voxelsniper.brush.snowcone: true + voxelsniper.brush.spiralstaircase: true + voxelsniper.brush.splatterball: true + voxelsniper.brush.splatterdisc: true + voxelsniper.brush.splatteroverlay: true + voxelsniper.brush.splattervoxel: true + voxelsniper.brush.splattervoxeldisc: true + voxelsniper.brush.spline: true + voxelsniper.brush.stamp: true + voxelsniper.brush.stencil: true + voxelsniper.brush.stencillist: true + voxelsniper.brush.threepointcircle: true + voxelsniper.brush.treesnipe: true + voxelsniper.brush.triangle: true + voxelsniper.brush.underlay: true + voxelsniper.brush.voltmeter: true + voxelsniper.brush.voxel: true + voxelsniper.brush.voxeldisc: true + voxelsniper.brush.voxeldiscface: true + voxelsniper.brush.warp: true + voxelsniper.brush.ball: + default: op + voxelsniper.brush.biome: + default: op + voxelsniper.brush.blendball: + default: op + voxelsniper.brush.blenddisc: + default: op + voxelsniper.brush.blendvoxel: + default: op + voxelsniper.brush.blendvoxeldisc: + default: op + voxelsniper.brush.blob: + default: op + voxelsniper.brush.blockreset: + default: op + voxelsniper.brush.blockresetsurface: + default: op + voxelsniper.brush.canyon: + default: op + voxelsniper.brush.canyonselection: + default: op + voxelsniper.brush.checkervoxeldisc: + default: op + voxelsniper.brush.cleansnow: + default: op + voxelsniper.brush.clonestamp: + default: op + voxelsniper.brush.comet: + default: op + voxelsniper.brush.copypasta: + default: op + voxelsniper.brush.cylinder: + default: op + voxelsniper.brush.disc: + default: op + voxelsniper.brush.discface: + default: op + voxelsniper.brush.dome: + default: op + voxelsniper.brush.drain: + default: op + voxelsniper.brush.ellipse: + default: op + voxelsniper.brush.ellipsoid: + default: op + voxelsniper.brush.entity: + default: op + voxelsniper.brush.entityremoval: + default: op + voxelsniper.brush.eraser: + default: op + voxelsniper.brush.erode: + default: op + voxelsniper.brush.extrude: + default: op + voxelsniper.brush.filldown: + default: op + voxelsniper.brush.flatocean: + default: op + voxelsniper.brush.generatetree: + default: op + voxelsniper.brush.heatray: + default: op + voxelsniper.brush.jaggedline: + default: op + voxelsniper.brush.jockey: + default: op + voxelsniper.brush.lightning: + default: op + voxelsniper.brush.line: + default: op + voxelsniper.brush.move: + default: op + voxelsniper.brush.ocean: + default: op + voxelsniper.brush.overlay: + default: op + voxelsniper.brush.painting: + default: op + voxelsniper.brush.pull: + default: op + voxelsniper.brush.punish: + default: op + voxelsniper.brush.randomerode: + default: op + voxelsniper.brush.regeneratechunk: + default: op + voxelsniper.brush.ring: + default: op + voxelsniper.brush.rot2d: + default: op + voxelsniper.brush.rot2dvert: + default: op + voxelsniper.brush.rot3d: + default: op + voxelsniper.brush.ruler: + default: op + voxelsniper.brush.scanner: + default: op + voxelsniper.brush.set: + default: op + voxelsniper.brush.setredstoneflip: + default: op + voxelsniper.brush.setredstonerotate: + default: op + voxelsniper.brush.shellball: + default: op + voxelsniper.brush.shellset: + default: op + voxelsniper.brush.shellvoxel: + default: op + voxelsniper.brush.signoverwrite: + default: op + voxelsniper.brush.snipe: + default: op + voxelsniper.brush.snowcone: + default: op + voxelsniper.brush.spiralstaircase: + default: op + voxelsniper.brush.splatterball: + default: op + voxelsniper.brush.splatterdisc: + default: op + voxelsniper.brush.splatteroverlay: + default: op + voxelsniper.brush.splattervoxel: + default: op + voxelsniper.brush.splattervoxeldisc: + default: op + voxelsniper.brush.spline: + default: op + voxelsniper.brush.stamp: + default: op + voxelsniper.brush.stencil: + default: op + voxelsniper.brush.stencillist: + default: op + voxelsniper.brush.threepointcircle: + default: op + voxelsniper.brush.treesnipe: + default: op + voxelsniper.brush.triangle: + default: op + voxelsniper.brush.underlay: + default: op + voxelsniper.brush.voltmeter: + default: op + voxelsniper.brush.voxel: + default: op + voxelsniper.brush.voxeldisc: + default: op + voxelsniper.brush.voxeldiscface: + default: op + voxelsniper.brush.warp: + default: op diff --git a/src/test/java/com/thevoxelbox/voxelsniper/BrushesTest.java b/src/test/java/com/thevoxelbox/voxelsniper/BrushesTest.java index d0df991b..ca2d0812 100644 --- a/src/test/java/com/thevoxelbox/voxelsniper/BrushesTest.java +++ b/src/test/java/com/thevoxelbox/voxelsniper/BrushesTest.java @@ -1,85 +1,85 @@ -package com.thevoxelbox.voxelsniper; - -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import com.thevoxelbox.voxelsniper.brush.IBrush; -import org.bukkit.util.Vector; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import java.util.Set; - -/** - * - */ -public class BrushesTest -{ - private Brushes brushes; - - @Before - public void setUp() throws Exception - { - brushes = new Brushes(); - } - - @Test - public void testRegisterSniperBrush() throws Exception - { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - } - - @Test - public void testGetBrushForHandle() throws Exception - { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Assert.assertEquals(brush.getClass(), brushes.getBrushForHandle("mockhandle")); - Assert.assertEquals(brush.getClass(), brushes.getBrushForHandle("testhandle")); - Assert.assertNull(brushes.getBrushForHandle("notExistant")); - } - - @Test - public void testRegisteredSniperBrushes() throws Exception - { - Assert.assertEquals(0, brushes.registeredSniperBrushes()); - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Assert.assertEquals(1, brushes.registeredSniperBrushes()); - } - - @Test - public void testRegisteredSniperBrushHandles() throws Exception - { - Assert.assertEquals(0, brushes.registeredSniperBrushHandles()); - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Assert.assertEquals(2, brushes.registeredSniperBrushHandles()); - } - - @Test - public void testGetSniperBrushHandles() throws Exception - { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Set sniperBrushHandles = brushes.getSniperBrushHandles(brush.getClass()); - Assert.assertTrue(sniperBrushHandles.contains("mockhandle")); - Assert.assertTrue(sniperBrushHandles.contains("testhandle")); - Assert.assertFalse(sniperBrushHandles.contains("notInSet")); - } - - @Test - public void testGetRegisteredBrushesMultimap() throws Exception - { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Multimap,String> registeredBrushesMultimap = brushes.getRegisteredBrushesMultimap(); - Assert.assertTrue(registeredBrushesMultimap.containsKey(brush.getClass())); - Assert.assertFalse(registeredBrushesMultimap.containsKey(IBrush.class)); - Assert.assertTrue(registeredBrushesMultimap.containsEntry(brush.getClass(), "mockhandle")); - Assert.assertTrue(registeredBrushesMultimap.containsEntry(brush.getClass(), "testhandle")); - Assert.assertFalse(registeredBrushesMultimap.containsEntry(brush.getClass(), "notAnEntry")); - } -} +package com.thevoxelbox.voxelsniper; + +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; +import com.thevoxelbox.voxelsniper.brush.IBrush; +import org.bukkit.util.Vector; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.mockito.Mockito; + +import java.util.Set; + +@TestInstance(Lifecycle.PER_CLASS) +public class BrushesTest +{ + private Brushes brushes; + + @BeforeEach + public void setUp() throws Exception + { + brushes = new Brushes(); + } + + @Test + public void testRegisterSniperBrush() throws Exception + { + IBrush brush = Mockito.mock(IBrush.class); + brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + } + + @Test + public void testGetBrushForHandle() throws Exception + { + IBrush brush = Mockito.mock(IBrush.class); + brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + Assertions.assertEquals(brush.getClass(), brushes.getBrushForHandle("mockhandle")); + Assertions.assertEquals(brush.getClass(), brushes.getBrushForHandle("testhandle")); + Assertions.assertNull(brushes.getBrushForHandle("notExistant")); + } + + @Test + public void testRegisteredSniperBrushes() throws Exception + { + Assertions.assertEquals(0, brushes.registeredSniperBrushes()); + IBrush brush = Mockito.mock(IBrush.class); + brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + Assertions.assertEquals(1, brushes.registeredSniperBrushes()); + } + + @Test + public void testRegisteredSniperBrushHandles() throws Exception + { + Assertions.assertEquals(0, brushes.registeredSniperBrushHandles()); + IBrush brush = Mockito.mock(IBrush.class); + brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + Assertions.assertEquals(2, brushes.registeredSniperBrushHandles()); + } + + @Test + public void testGetSniperBrushHandles() throws Exception + { + IBrush brush = Mockito.mock(IBrush.class); + brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + Set sniperBrushHandles = brushes.getSniperBrushHandles(brush.getClass()); + Assertions.assertTrue(sniperBrushHandles.contains("mockhandle")); + Assertions.assertTrue(sniperBrushHandles.contains("testhandle")); + Assertions.assertFalse(sniperBrushHandles.contains("notInSet")); + } + + @Test + public void testGetRegisteredBrushesMultimap() throws Exception + { + IBrush brush = Mockito.mock(IBrush.class); + brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + Multimap,String> registeredBrushesMultimap = brushes.getRegisteredBrushesMultimap(); + Assertions.assertTrue(registeredBrushesMultimap.containsKey(brush.getClass())); + Assertions.assertFalse(registeredBrushesMultimap.containsKey(IBrush.class)); + Assertions.assertTrue(registeredBrushesMultimap.containsEntry(brush.getClass(), "mockhandle")); + Assertions.assertTrue(registeredBrushesMultimap.containsEntry(brush.getClass(), "testhandle")); + Assertions.assertFalse(registeredBrushesMultimap.containsEntry(brush.getClass(), "notAnEntry")); + } +} diff --git a/src/test/java/com/thevoxelbox/voxelsniper/SniperManagerTest.java b/src/test/java/com/thevoxelbox/voxelsniper/SniperManagerTest.java index 5a907898..81c67898 100644 --- a/src/test/java/com/thevoxelbox/voxelsniper/SniperManagerTest.java +++ b/src/test/java/com/thevoxelbox/voxelsniper/SniperManagerTest.java @@ -1,19 +1,20 @@ -package com.thevoxelbox.voxelsniper; - -import org.junit.Before; -import org.mockito.Mockito; - -/** - * - */ -public class SniperManagerTest -{ - private SniperManager sniperManager; - - @Before - public void setUp() throws Exception - { - sniperManager = new SniperManager(Mockito.mock(VoxelSniper.class)); - } - -} +package com.thevoxelbox.voxelsniper; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.mockito.Mockito; + + +@TestInstance(Lifecycle.PER_CLASS) +public class SniperManagerTest +{ + private SniperManager sniperManager; + + @BeforeEach + public void setUp() throws Exception + { + sniperManager = new SniperManager(Mockito.mock(VoxelSniper.class)); + } + +} diff --git a/src/test/java/com/thevoxelbox/voxelsniper/UndoTest.java b/src/test/java/com/thevoxelbox/voxelsniper/UndoTest.java index c9af7dde..610efc1e 100644 --- a/src/test/java/com/thevoxelbox/voxelsniper/UndoTest.java +++ b/src/test/java/com/thevoxelbox/voxelsniper/UndoTest.java @@ -1,136 +1,135 @@ -package com.thevoxelbox.voxelsniper; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InOrder; -import org.mockito.Mockito; - -/** - * - */ -public class UndoTest -{ - private Undo undo; - - @Before - public void setUp() throws Exception - { - undo = new Undo(); - } - - @Test - public void testGetSize() throws Exception - { - World world = Mockito.mock(World.class); - for (int i = 0; i < 5; i++) - { - Block block = Mockito.mock(Block.class); - BlockState blockState = Mockito.mock(BlockState.class); - Location location = new Location(world, 0, 0, i); - Mockito.when(block.getLocation()) - .thenReturn(location); - Mockito.when(block.getState()) - .thenReturn(blockState); - Mockito.when(blockState.getLocation()) - .thenReturn(location); - undo.put(block); - } - Assert.assertEquals(5, undo.getSize()); - Block block = Mockito.mock(Block.class); - BlockState blockState = Mockito.mock(BlockState.class); - Location location = new Location(world, 0, 0, 6); - Mockito.when(block.getLocation()) - .thenReturn(location); - Mockito.when(block.getState()) - .thenReturn(blockState); - Mockito.when(blockState.getLocation()) - .thenReturn(location); - undo.put(block); - Assert.assertEquals(6, undo.getSize()); - undo.put(block); - Assert.assertEquals(6, undo.getSize()); - - } - - @Test - public void testPut() throws Exception - { - World world = Mockito.mock(World.class); - Block block = Mockito.mock(Block.class); - BlockState blockState = Mockito.mock(BlockState.class); - Location location = new Location(world, 0, 0, 0); - Mockito.when(block.getLocation()) - .thenReturn(location); - Mockito.when(block.getState()) - .thenReturn(blockState); - Mockito.when(blockState.getLocation()) - .thenReturn(location); - - undo.put(block); - } - - @Test - public void testUndo() throws Exception - { - World world = Mockito.mock(World.class); - - Block normalBlock = Mockito.mock(Block.class); - BlockState normalBlockState = Mockito.mock(BlockState.class); - Location normalBlockLocation = new Location(world, 0, 0, 0); - Mockito.when(normalBlock.getLocation()) - .thenReturn(normalBlockLocation); - Mockito.when(normalBlock.getState()) - .thenReturn(normalBlockState); - Mockito.when(normalBlock.getType()) - .thenReturn(Material.STONE); - Mockito.when(normalBlockState.getLocation()) - .thenReturn(normalBlockLocation); - Mockito.when(normalBlockState.getBlock()) - .thenReturn(normalBlock); - - Block fragileBlock = Mockito.mock(Block.class); - BlockState fragileBlockState = Mockito.mock(BlockState.class); - Location fragileBlockLocation = new Location(world, 0, 0, 1); - Mockito.when(fragileBlock.getLocation()) - .thenReturn(fragileBlockLocation); - Mockito.when(fragileBlock.getState()) - .thenReturn(fragileBlockState); - Mockito.when(fragileBlock.getType()) - .thenReturn(Material.TORCH); - Mockito.when(fragileBlockState.getLocation()) - .thenReturn(fragileBlockLocation); - Mockito.when(fragileBlockState.getBlock()) - .thenReturn(fragileBlock); - - Block waterBlock = Mockito.mock(Block.class); - BlockState waterBlockState = Mockito.mock(BlockState.class); - Location waterBlockLocation = new Location(world, 0, 0, 2); - Mockito.when(waterBlock.getLocation()) - .thenReturn(waterBlockLocation); - Mockito.when(waterBlock.getState()) - .thenReturn(waterBlockState); - Mockito.when(waterBlock.getType()) - .thenReturn(Material.WATER); - Mockito.when(waterBlockState.getLocation()) - .thenReturn(waterBlockLocation); - Mockito.when(waterBlockState.getBlock()) - .thenReturn(waterBlock); - - - undo.put(waterBlock); - undo.put(fragileBlock); - undo.put(normalBlock); - undo.undo(); - - InOrder inOrder = Mockito.inOrder(normalBlockState, waterBlockState, fragileBlockState); - inOrder.verify(normalBlockState).update(Mockito.anyBoolean(), Mockito.anyBoolean()); - inOrder.verify(fragileBlockState).update(Mockito.anyBoolean(), Mockito.anyBoolean()); - inOrder.verify(waterBlockState).update(Mockito.anyBoolean(), Mockito.anyBoolean()); - } -} +package com.thevoxelbox.voxelsniper; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.mockito.InOrder; +import org.mockito.Mockito; + +/** + * + */ +public class UndoTest +{ + /* + private Undo undo; + + @Before + public void setUp() throws Exception + { + undo = new Undo(); + } + + @Test + public void testGetSize() throws Exception + { + World world = Mockito.mock(World.class); + for (int i = 0; i < 5; i++) + { + Block block = Mockito.mock(Block.class); + BlockState blockState = Mockito.mock(BlockState.class); + Location location = new Location(world, 0, 0, i); + Mockito.when(block.getLocation()) + .thenReturn(location); + Mockito.when(block.getState()) + .thenReturn(blockState); + Mockito.when(blockState.getLocation()) + .thenReturn(location); + undo.put(block); + } + Assert.assertEquals(5, undo.getSize()); + Block block = Mockito.mock(Block.class); + BlockState blockState = Mockito.mock(BlockState.class); + Location location = new Location(world, 0, 0, 6); + Mockito.when(block.getLocation()) + .thenReturn(location); + Mockito.when(block.getState()) + .thenReturn(blockState); + Mockito.when(blockState.getLocation()) + .thenReturn(location); + undo.put(block); + Assert.assertEquals(6, undo.getSize()); + undo.put(block); + Assert.assertEquals(6, undo.getSize()); + + } + + @Test + public void testPut() throws Exception + { + World world = Mockito.mock(World.class); + Block block = Mockito.mock(Block.class); + BlockState blockState = Mockito.mock(BlockState.class); + Location location = new Location(world, 0, 0, 0); + Mockito.when(block.getLocation()) + .thenReturn(location); + Mockito.when(block.getState()) + .thenReturn(blockState); + Mockito.when(blockState.getLocation()) + .thenReturn(location); + + undo.put(block); + } + + @Test + public void testUndo() throws Exception + { + World world = Mockito.mock(World.class); + + Block normalBlock = Mockito.mock(Block.class); + BlockState normalBlockState = Mockito.mock(BlockState.class); + Location normalBlockLocation = new Location(world, 0, 0, 0); + Mockito.when(normalBlock.getLocation()) + .thenReturn(normalBlockLocation); + Mockito.when(normalBlock.getState()) + .thenReturn(normalBlockState); + Mockito.when(normalBlock.getType()) + .thenReturn(Material.STONE); + Mockito.when(normalBlockState.getLocation()) + .thenReturn(normalBlockLocation); + Mockito.when(normalBlockState.getBlock()) + .thenReturn(normalBlock); + + Block fragileBlock = Mockito.mock(Block.class); + BlockState fragileBlockState = Mockito.mock(BlockState.class); + Location fragileBlockLocation = new Location(world, 0, 0, 1); + Mockito.when(fragileBlock.getLocation()) + .thenReturn(fragileBlockLocation); + Mockito.when(fragileBlock.getState()) + .thenReturn(fragileBlockState); + Mockito.when(fragileBlock.getType()) + .thenReturn(Material.TORCH); + Mockito.when(fragileBlockState.getLocation()) + .thenReturn(fragileBlockLocation); + Mockito.when(fragileBlockState.getBlock()) + .thenReturn(fragileBlock); + + Block waterBlock = Mockito.mock(Block.class); + BlockState waterBlockState = Mockito.mock(BlockState.class); + Location waterBlockLocation = new Location(world, 0, 0, 2); + Mockito.when(waterBlock.getLocation()) + .thenReturn(waterBlockLocation); + Mockito.when(waterBlock.getState()) + .thenReturn(waterBlockState); + Mockito.when(waterBlock.getType()) + .thenReturn(Material.WATER); + Mockito.when(waterBlockState.getLocation()) + .thenReturn(waterBlockLocation); + Mockito.when(waterBlockState.getBlock()) + .thenReturn(waterBlock); + + + undo.put(waterBlock); + undo.put(fragileBlock); + undo.put(normalBlock); + undo.undo(); + + InOrder inOrder = Mockito.inOrder(normalBlockState, waterBlockState, fragileBlockState); + inOrder.verify(normalBlockState).update(Mockito.anyBoolean(), Mockito.anyBoolean()); + inOrder.verify(fragileBlockState).update(Mockito.anyBoolean(), Mockito.anyBoolean()); + inOrder.verify(waterBlockState).update(Mockito.anyBoolean(), Mockito.anyBoolean()); + } + */ +}