From 20098a78c80405e2b3abc1f8b0f6d0a66e3b2e49 Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Thu, 28 Mar 2019 21:19:40 -0400 Subject: [PATCH] Lets show FAVS some love :heart: --- .../com/thevoxelbox/voxelsniper/Message.java | 9 +- .../voxelsniper/PaintingWrapper.java | 6 +- .../com/thevoxelbox/voxelsniper/Sniper.java | 23 +-- .../com/thevoxelbox/voxelsniper/Undo.java | 5 +- .../voxelsniper/VoxelSniperListener.java | 45 ++--- .../voxelsniper/brush/BiomeBrush.java | 15 +- .../voxelsniper/brush/BlendBallBrush.java | 6 +- .../voxelsniper/brush/BlendDiscBrush.java | 5 +- .../voxelsniper/brush/BlendVoxelBrush.java | 6 +- .../brush/BlendVoxelDiscBrush.java | 5 +- .../voxelsniper/brush/BlobBrush.java | 10 +- .../voxelsniper/brush/JockeyBrush.java | 8 +- .../voxelsniper/brush/OverlayBrush.java | 191 ++++++++---------- .../voxelsniper/brush/Rot2DBrush.java | 30 +-- .../voxelsniper/brush/Rot2DvertBrush.java | 30 +-- .../voxelsniper/brush/Rot3DBrush.java | 30 +-- .../voxelsniper/brush/ShellBallBrush.java | 6 +- .../voxelsniper/brush/ShellVoxelBrush.java | 6 +- .../voxelsniper/brush/SnowConeBrush.java | 27 +-- .../brush/SpiralStaircaseBrush.java | 4 +- .../voxelsniper/brush/SplatterBallBrush.java | 7 +- .../voxelsniper/brush/SplatterDiscBrush.java | 6 +- .../brush/SplatterOverlayBrush.java | 12 +- .../voxelsniper/brush/SplatterVoxelBrush.java | 7 +- .../brush/SplatterVoxelDiscBrush.java | 6 +- .../voxelsniper/brush/WallSider.java | 2 +- .../voxelsniper/brush/perform/Performer.java | 4 +- .../voxelsniper/brush/perform/PerformerE.java | 22 +- .../voxelsniper/util/BlockWrapper.java | 11 + 29 files changed, 218 insertions(+), 326 deletions(-) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/Message.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/Message.java index 340fcf282..34e991325 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/Message.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/Message.java @@ -158,12 +158,9 @@ public class Message } else { - StringBuilder returnValueBuilder = new StringBuilder(); - returnValueBuilder.append(ChatColor.DARK_GREEN); - returnValueBuilder.append("Block Types Selected: "); - returnValueBuilder.append(ChatColor.AQUA); - returnValueBuilder.append(snipeData.getVoxelList()); - snipeData.sendMessage(returnValueBuilder.toString()); + String returnValueBuilder = ChatColor.DARK_GREEN + "Block Types Selected: " + ChatColor.AQUA + + snipeData.getVoxelList(); + snipeData.sendMessage(returnValueBuilder); } } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java index 25df54ee1..78a75ef49 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/PaintingWrapper.java @@ -40,8 +40,8 @@ public final class PaintingWrapper @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(); - Chunk paintingChunk = p.getTargetBlock((Set) null, 4).getLocation().getChunk(); + Location targetLocation = p.getTargetBlock(null, 4).getLocation(); + Chunk paintingChunk = p.getTargetBlock(null, 4).getLocation().getChunk(); Double bestDistanceMatch = 50D; Painting bestMatch = null; @@ -66,7 +66,7 @@ public final class PaintingWrapper { try { - final int i = bestMatch.getArt().getId() + (back ? -1 : 1) + Art.values().length % Art.values().length; + final int i = bestMatch.getArt().getId() + (back ? -1 : 1); Art art = Art.getById(i); if (art == null) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java index 4c8e102a9..b0ec73c77 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java @@ -94,7 +94,7 @@ public class Sniper { } public String getCurrentToolId() { - return getToolId((getPlayer().getItemInHand() != null) ? getPlayer().getItemInHand().getType() : null); + return getToolId((getPlayer().getInventory().getItemInMainHand() != null) ? getPlayer().getInventory().getItemInMainHand().getType() : null); } public String getToolId(Material itemInHand) { @@ -169,17 +169,10 @@ public class Sniper { try { Player player = getPlayer(); final FawePlayer fp = FawePlayer.wrap(player); - TaskManager.IMP.taskNow(new Runnable() { - @Override - public void run() { - if (!fp.runAction(new Runnable() { - @Override - public void run() { - snipeOnCurrentThread(fp, action, itemInHand, clickedBlock, clickedFace, sniperTool, toolId); - } - }, false, true)) { - BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); - } + TaskManager.IMP.taskNow(() -> { + if (!fp.runAction( + () -> snipeOnCurrentThread(fp, action, itemInHand, clickedBlock, clickedFace, sniperTool, toolId), false, true)) { + BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); } }, Fawe.isMainThread()); return true; @@ -660,9 +653,7 @@ public class Sniper { private IBrush instantiateBrush(Class brush) { try { return brush.newInstance(); - } catch (InstantiationException e) { - return null; - } catch (IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { return null; } } @@ -671,4 +662,4 @@ public class Sniper { public static Class inject() { return Sniper.class; } -} \ No newline at end of file +} diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/Undo.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/Undo.java index 31c17960e..a999f7bf4 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/Undo.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/Undo.java @@ -26,9 +26,10 @@ package com.thevoxelbox.voxelsniper; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; /** - * Holds {@link org.bukkit.block.BlockState}s that can be later on used to reset those block + * Holds {@link BlockState}s that can be later on used to reset those block * locations back to the recorded states. */ public class Undo { @@ -67,4 +68,4 @@ public class Undo { public void undo() { } -} \ No newline at end of file +} diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java index f0ee3a73e..ffa8189d5 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java @@ -79,35 +79,32 @@ public class VoxelSniperListener implements Listener } FawePlayer fp = FawePlayer.wrap(player); - if (!fp.runAction(new Runnable() { - @Override - public void run() { - ExceptionConverter exceptionConverter = CommandManager.getInstance().getExceptionConverter(); + if (!fp.runAction(() -> { + ExceptionConverter exceptionConverter = CommandManager.getInstance().getExceptionConverter(); + try { try { - try { - found.onCommand(player, split); - return; - } catch (Throwable t) { - Throwable next = t; + found.onCommand(player, split); + return; + } catch (Throwable t) { + Throwable next = t; + exceptionConverter.convert(next); + while (next.getCause() != null) { + next = next.getCause(); exceptionConverter.convert(next); - while (next.getCause() != null) { - next = next.getCause(); - exceptionConverter.convert(next); - } - throw next; } - } catch (CommandException e) { - String message = e.getMessage(); - if (message != null) { - fp.sendMessage(e.getMessage()); - return; - } - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); + throw next; } - fp.sendMessage("An unknown FAWE error has occurred! Please see console."); + } catch (CommandException e) { + String message = e.getMessage(); + if (message != null) { + fp.sendMessage(e.getMessage()); + return; + } + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); } + fp.sendMessage("An unknown FAWE error has occurred! Please see console."); }, false, true)) { BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java index 788574e01..2e2ea9e73 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BiomeBrush.java @@ -82,17 +82,18 @@ public class BiomeBrush extends Brush if (args[1].equalsIgnoreCase("info")) { v.sendMessage(ChatColor.GOLD + "Biome Brush Parameters:"); - String availableBiomes = ""; + StringBuilder availableBiomes = new StringBuilder(); for (final Biome biome : Biome.values()) { - if (availableBiomes.isEmpty()) + if (availableBiomes.length() == 0) { - availableBiomes = ChatColor.DARK_GREEN + biome.name(); + availableBiomes = new StringBuilder(ChatColor.DARK_GREEN + biome.name()); continue; } - availableBiomes += ChatColor.RED + ", " + ChatColor.DARK_GREEN + biome.name(); + availableBiomes.append(ChatColor.RED + ", " + ChatColor.DARK_GREEN) + .append(biome.name()); } v.sendMessage(ChatColor.DARK_BLUE + "Available biomes: " + availableBiomes); @@ -100,15 +101,15 @@ public class BiomeBrush extends Brush else { // allows biome names with spaces in their name - String biomeName = args[1]; + StringBuilder biomeName = new StringBuilder(args[1]); for (int i = 2; i < args.length; i++) { - biomeName += " " + args[i]; + biomeName.append(" ").append(args[i]); } for (final Biome biome : Biome.values()) { - if (biome.name().equalsIgnoreCase(biomeName)) + if (biome.name().equalsIgnoreCase(biomeName.toString())) { this.selectedBiome = biome; break; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java index 634fb2654..34da2c707 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendBallBrush.java @@ -49,10 +49,8 @@ public class BlendBallBrush extends BlendBrushBase { for (int y = 0; y <= brushSizeDoubled; y++) { - for (int z = 0; z <= brushSizeDoubled; z++) - { - newMaterials[x][y][z] = oldMaterials[x + 1][y + 1][z + 1]; - } + System.arraycopy(oldMaterials[x + 1][y + 1], 1, newMaterials[x][y], 0, + brushSizeDoubled + 1); } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java index 876ffa7d8..8e2434f61 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendDiscBrush.java @@ -42,10 +42,7 @@ public class BlendDiscBrush extends BlendBrushBase // Log current materials into newmats for (int x = 0; x <= brushSizeDoubled; x++) { - for (int z = 0; z <= brushSizeDoubled; z++) - { - newMaterials[x][z] = oldMaterials[x + 1][z + 1]; - } + System.arraycopy(oldMaterials[x + 1], 1, newMaterials[x], 0, brushSizeDoubled + 1); } // Blend materials diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java index e0e8fe943..088797779 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelBrush.java @@ -49,10 +49,8 @@ public class BlendVoxelBrush extends BlendBrushBase { for (int y = 0; y <= brushSizeDoubled; y++) { - for (int z = 0; z <= brushSizeDoubled; z++) - { - newMaterials[x][y][z] = oldMaterials[x + 1][y + 1][z + 1]; - } + System.arraycopy(oldMaterials[x + 1][y + 1], 1, newMaterials[x][y], 0, + brushSizeDoubled + 1); } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java index d0abbc680..089710e05 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlendVoxelDiscBrush.java @@ -42,10 +42,7 @@ public class BlendVoxelDiscBrush extends BlendBrushBase // Log current materials into newmats for (int x = 0; x <= brushSizeDoubled; x++) { - for (int z = 0; z <= brushSizeDoubled; z++) - { - newMaterials[x][z] = oldMaterials[x + 1][z + 1]; - } + System.arraycopy(oldMaterials[x + 1], 1, newMaterials[x], 0, brushSizeDoubled + 1); } // Blend materials diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlobBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlobBrush.java index cf51dca5e..0279d2f9e 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlobBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlobBrush.java @@ -120,10 +120,7 @@ public class BlobBrush extends PerformBrush { for (int y = brushSizeDoubled; y >= 0; y--) { - for (int z = brushSizeDoubled; z >= 0; z--) - { - splat[x][y][z] = tempSplat[x][y][z]; - } + System.arraycopy(tempSplat[x][y], 0, splat[x][y], 0, brushSizeDoubled + 1); } } } @@ -218,10 +215,7 @@ public class BlobBrush extends PerformBrush { for (int y = brushSizeDoubled; y >= 0; y--) { - for (int z = brushSizeDoubled; z >= 0; z--) - { - splat[x][y][z] = tempSplat[x][y][z]; - } + System.arraycopy(tempSplat[x][y], 0, splat[x][y], 0, brushSizeDoubled + 1); } } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/JockeyBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/JockeyBrush.java index a4477dd1b..c1e579771 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/JockeyBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/JockeyBrush.java @@ -83,11 +83,11 @@ public class JockeyBrush extends Brush { if (jockeyType == JockeyType.INVERSE_PLAYER_ONLY || jockeyType == JockeyType.INVERSE_ALL_ENTITIES) { - player.setPassenger(closest); + player.addPassenger(closest); } else { - closest.setPassenger(player); + closest.addPassenger(player); jockeyedEntity = closest; } v.sendMessage(ChatColor.GREEN + "You are now saddles on entity: " + closest.getEntityId()); @@ -113,7 +113,7 @@ public class JockeyBrush extends Brush { if (jockeyType == JockeyType.STACK_ALL_ENTITIES) { - lastEntity.setPassenger(entity); + lastEntity.addPassenger(entity); lastEntity = entity; stackHeight++; } @@ -121,7 +121,7 @@ public class JockeyBrush extends Brush { if (entity instanceof Player) { - lastEntity.setPassenger(entity); + lastEntity.addPassenger(entity); lastEntity = entity; stackHeight++; } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java index fac816721..2287b0dc9 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java @@ -1,5 +1,6 @@ package com.thevoxelbox.voxelsniper.brush; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -14,8 +15,7 @@ import org.bukkit.Material; * * @author Gavjenks */ -public class OverlayBrush extends PerformBrush -{ +public class OverlayBrush extends PerformBrush { private static final int DEFAULT_DEPTH = 3; private int depth = DEFAULT_DEPTH; private boolean allBlocks = false; @@ -23,40 +23,38 @@ public class OverlayBrush extends PerformBrush /** * */ - public OverlayBrush() - { + public OverlayBrush() { this.setName("Overlay (Topsoil Filling)"); } - private void overlay(final SnipeData v) - { + private void overlay(final SnipeData v) { final int brushSize = v.getBrushSize(); final double brushSizeSquared = Math.pow(brushSize + 0.5, 2); - for (int z = brushSize; z >= -brushSize; z--) - { - for (int x = brushSize; x >= -brushSize; x--) - { + for (int z = brushSize; z >= -brushSize; z--) { + for (int x = brushSize; x >= -brushSize; x--) { // 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)) - { - if ((Math.pow(x, 2) + Math.pow(z, 2)) <= brushSizeSquared) - { - for (int y = this.getTargetBlock().getY(); y > 0; y--) - { + final int materialId = this.getBlockIdAt(this.getTargetBlock().getX() + x, + this.getTargetBlock().getY() + 1, this.getTargetBlock().getZ() + z); + if (isIgnoredBlock(materialId)) { + 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)) - { - 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)) - { - this.current.perform(this.clampY(this.getTargetBlock().getX() + x, currentDepth, this.getTargetBlock().getZ() + z)); + final int layerBlockId = + this.getBlockIdAt(this.getTargetBlock().getX() + x, y, + this.getTargetBlock().getZ() + z); + if (!isIgnoredBlock(layerBlockId)) { + 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)) { + this.current.perform( + this.clampY(this.getTargetBlock().getX() + x, + currentDepth, this.getTargetBlock().getZ() + z)); } } break; @@ -70,9 +68,7 @@ public class OverlayBrush extends PerformBrush v.owner().storeUndo(this.current.getUndo()); } - @SuppressWarnings("deprecation") - private boolean isIgnoredBlock(int materialId) - { + @SuppressWarnings("deprecation") private boolean isIgnoredBlock(int materialId) { BlockType type = BlockTypes.get(materialId); switch (type.getResource().toUpperCase()) { case "WATER": @@ -84,68 +80,65 @@ public class OverlayBrush extends PerformBrush return mat.isTranslucent(); } - @SuppressWarnings("deprecation") - private boolean isOverrideableMaterial(int materialId) - { + @SuppressWarnings("deprecation") private boolean isOverrideableMaterial(int materialId) { BlockMaterial mat = BlockTypes.get(materialId).getMaterial(); - if (allBlocks && !(mat.isAir())) - { + if (allBlocks && !(mat.isAir())) { return true; } - if (!mat.isFragileWhenPushed() && mat.isFullCube()) { - return true; - } - return false; + return !mat.isFragileWhenPushed() && mat.isFullCube(); } - private void overlayTwo(final SnipeData v) - { + private void overlayTwo(final SnipeData v) { final int brushSize = v.getBrushSize(); final double brushSizeSquared = Math.pow(brushSize + 0.5, 2); final int[][] memory = new int[brushSize * 2 + 1][brushSize * 2 + 1]; - for (int z = brushSize; z >= -brushSize; z--) - { - for (int x = brushSize; x >= -brushSize; x--) - { + for (int z = brushSize; z >= -brushSize; z--) { + for (int x = brushSize; x >= -brushSize; x--) { boolean surfaceFound = false; - for (int y = this.getTargetBlock().getY(); y > 0 && !surfaceFound; y--) - { // start scanning from the height you clicked at - if (memory[x + brushSize][z + brushSize] != 1) - { // 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.getBlockAt(this.getTargetBlock().getX() + x, y - 1, this.getTargetBlock().getZ() + z).isEmpty()) - { // if not a floating block (like one of Notch'world pools) - if (this.getBlockAt(this.getTargetBlock().getX() + x, y + 1, this.getTargetBlock().getZ() + z).isEmpty()) - { // must start at surface... this prevents it filling stuff in if + for (int y = this.getTargetBlock().getY(); + y > 0 && !surfaceFound; y--) { // start scanning from the height you clicked at + if (memory[x + brushSize][z + brushSize] + != 1) { // 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.getBlockAt(this.getTargetBlock().getX() + x, y - 1, + this.getTargetBlock().getZ() + z) + .isEmpty()) { // if not a floating block (like one of Notch'world pools) + if (this.getBlockAt(this.getTargetBlock().getX() + x, y + 1, + this.getTargetBlock().getZ() + z) + .isEmpty()) { // 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. + if (!this.allBlocks) { // if the override parameter has not been activated, go to the switch that filters out manmade stuff. - BlockType type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)); + BlockType type = BukkitAdapter.asBlockType((this + .getBlockType(this.getTargetBlock().getX() + x, y, + this.getTargetBlock().getZ() + z))); BlockMaterial mat = type.getMaterial(); - if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer()) { + if (mat.isSolid() && mat.isFullCube() && !mat + .hasContainer()) { 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 + 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. + memory[x + brushSize][z + brushSize] = + 1; // stop it from checking any other blocks in this vertical 1x1 column. } surfaceFound = true; - continue; - } else { - continue; } - } - else - { - 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 + } else { + 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. + memory[x + brushSize][z + brushSize] = + 1; // stop it from checking any other blocks in this vertical 1x1 column. } surfaceFound = true; } @@ -161,74 +154,58 @@ public class OverlayBrush extends PerformBrush v.owner().storeUndo(this.current.getUndo()); } - @Override - protected final void arrow(final SnipeData v) - { + @Override protected final void arrow(final SnipeData v) { this.overlay(v); } - @Override - protected final void powder(final SnipeData v) - { + @Override protected final void powder(final SnipeData v) { this.overlayTwo(v); } - @Override - public final void info(final Message vm) - { + @Override public final void info(final Message vm) { vm.brushName(this.getName()); vm.size(); } - @Override - public final void parameters(final String[] par, final SnipeData v) - { - for (int i = 1; i < par.length; i++) - { + @Override public final void parameters(final String[] par, final SnipeData v) { + for (int i = 1; i < par.length; i++) { final String parameter = par[i]; - if (parameter.equalsIgnoreCase("info")) - { + if (parameter.equalsIgnoreCase("info")) { v.sendMessage(ChatColor.GOLD + "Overlay brush parameters:"); - v.sendMessage(ChatColor.AQUA + "d[number] (ex: d3) How many blocks deep you want to replace from the surface."); - v.sendMessage(ChatColor.BLUE + "all (ex: /b over all) Sets the brush to overlay over ALL materials, not just natural surface ones (will no longer ignore trees and buildings). The parameter /some will set it back to default."); + v.sendMessage(ChatColor.AQUA + + "d[number] (ex: d3) How many blocks deep you want to replace from the surface."); + v.sendMessage(ChatColor.BLUE + + "all (ex: /b over all) Sets the brush to overlay over ALL materials, not just natural surface ones (will no longer ignore trees and buildings). The parameter /some will set it back to default."); return; } - if (parameter.startsWith("d")) - { + if (parameter.startsWith("d")) { try { this.depth = Integer.parseInt(parameter.replace("d", "")); - if (this.depth < 1) - { + if (this.depth < 1) { this.depth = 1; } v.sendMessage(ChatColor.AQUA + "Depth set to " + this.depth); - } catch (NumberFormatException e) { + } catch (NumberFormatException e) { v.sendMessage(ChatColor.RED + "Depth isn't a number."); } - } - else if (parameter.startsWith("all")) - { + } else if (parameter.startsWith("all")) { this.allBlocks = true; v.sendMessage(ChatColor.BLUE + "Will overlay over any block." + this.depth); - } - else if (parameter.startsWith("some")) - { + } else if (parameter.startsWith("some")) { this.allBlocks = false; - v.sendMessage(ChatColor.BLUE + "Will overlay only natural block types." + this.depth); - } - else - { - v.sendMessage(ChatColor.RED + "Invalid brush parameters! use the info parameter to display parameter info."); + v.sendMessage( + ChatColor.BLUE + "Will overlay only natural block types." + this.depth); + } else { + v.sendMessage(ChatColor.RED + + "Invalid brush parameters! use the info parameter to display parameter info."); } } } - @Override - public String getPermissionNode() - { + @Override public String getPermissionNode() { return "voxelsniper.brush.overlay"; } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java index 90733c6a7..b7b30c599 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DBrush.java @@ -163,16 +163,11 @@ public class Rot2DBrush extends Brush { this.bSize = v.getBrushSize(); - switch (this.mode) - { - case 0: - this.getMatrix(); - this.rotate(v); - break; - - default: - v.sendMessage(ChatColor.RED + "Something went wrong."); - break; + if (this.mode == 0) { + this.getMatrix(); + this.rotate(v); + } else { + v.sendMessage(ChatColor.RED + "Something went wrong."); } } @@ -181,16 +176,11 @@ public class Rot2DBrush extends Brush { this.bSize = v.getBrushSize(); - switch (this.mode) - { - case 0: - this.getMatrix(); - this.rotate(v); - break; - - default: - v.sendMessage(ChatColor.RED + "Something went wrong."); - break; + if (this.mode == 0) { + this.getMatrix(); + this.rotate(v); + } else { + v.sendMessage(ChatColor.RED + "Something went wrong."); } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java index f34c43486..c656682f0 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot2DvertBrush.java @@ -164,16 +164,11 @@ public class Rot2DvertBrush extends Brush { this.bSize = v.getBrushSize(); - switch (this.mode) - { - case 0: - this.getMatrix(); - this.rotate(v); - break; - - default: - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); - break; + if (this.mode == 0) { + this.getMatrix(); + this.rotate(v); + } else { + v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); } } @@ -182,16 +177,11 @@ public class Rot2DvertBrush extends Brush { this.bSize = v.getBrushSize(); - switch (this.mode) - { - case 0: - this.getMatrix(); - this.rotate(v); - break; - - default: - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); - break; + if (this.mode == 0) { + this.getMatrix(); + this.rotate(v); + } else { + v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java index 1a9069cd1..79ddcbdf8 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/Rot3DBrush.java @@ -248,16 +248,11 @@ public class Rot3DBrush extends Brush { this.bSize = v.getBrushSize(); - switch (this.mode) - { - case 0: - this.getMatrix(); - this.rotate(v); - break; - - default: - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); - break; + if (this.mode == 0) { + this.getMatrix(); + this.rotate(v); + } else { + v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); } } @@ -266,16 +261,11 @@ public class Rot3DBrush extends Brush { this.bSize = v.getBrushSize(); - switch (this.mode) - { - case 0: - this.getMatrix(); - this.rotate(v); - break; - - default: - v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); - break; + if (this.mode == 0) { + this.getMatrix(); + this.rotate(v); + } else { + v.owner().getPlayer().sendMessage(ChatColor.RED + "Something went wrong."); } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java index 7004b2d39..9c25020ba 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellBallBrush.java @@ -50,10 +50,8 @@ public class ShellBallBrush extends Brush { for (int y = 0; y <= brushSizeDoubled; y++) { - for (int z = 0; z <= brushSizeDoubled; z++) - { - newMaterials[x][y][z] = oldMaterials[x + 1][y + 1][z + 1]; - } + System.arraycopy(oldMaterials[x + 1][y + 1], 1, newMaterials[x][y], 0, + brushSizeDoubled + 1); } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java index ce394c276..2d528fb58 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellVoxelBrush.java @@ -49,10 +49,8 @@ public class ShellVoxelBrush extends Brush { for (int y = 0; y <= brushSizeSquared; y++) { - for (int z = 0; z <= brushSizeSquared; z++) - { - newMaterials[x][y][z] = oldMaterials[x + 1][y + 1][z + 1]; - } + System.arraycopy(oldMaterials[x + 1][y + 1], 1, newMaterials[x][y], 0, + brushSizeSquared + 1); } } int temp; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java index 330af9a27..72f9abc6c 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SnowConeBrush.java @@ -152,22 +152,17 @@ public class SnowConeBrush extends Brush @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 && BukkitAdapter.adapt(blockAbove.getType()).getMaterial().isAir()) - { - addSnow(v, blockAbove); - } - else - { - v.owner().getPlayer().sendMessage(ChatColor.RED + "Error: Center block neither snow nor air."); - } - break; + if (getTargetBlock().getType() == Material.SNOW) { + this.addSnow(v, this.getTargetBlock()); + } else { + Block blockAbove = getTargetBlock().getRelative(BlockFace.UP); + if (blockAbove != null && BukkitAdapter.adapt(blockAbove.getType()).getMaterial() + .isAir()) { + addSnow(v, blockAbove); + } else { + v.owner().getPlayer() + .sendMessage(ChatColor.RED + "Error: Center block neither snow nor air."); + } } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java index 3edd3729a..c3b12d0b4 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SpiralStaircaseBrush.java @@ -730,9 +730,7 @@ public class SpiralStaircaseBrush extends Brush v.sendMessage(ChatColor.BLUE + "Staircase type: " + this.stairtype); return; } catch (InputParseException ignore) {} - switch (par[i].toLowerCase()) { - case "block": - + if ("block".equals(par[i].toLowerCase())) { } if (par[i].equalsIgnoreCase("block") || par[i].equalsIgnoreCase("step") || par[i].equalsIgnoreCase("woodstair") || par[i].equalsIgnoreCase("cobblestair")) { diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterBallBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterBallBrush.java index ec13e95c7..fb45a2b5f 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterBallBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterBallBrush.java @@ -130,10 +130,9 @@ public class SplatterBallBrush extends PerformBrush { for (int y = 2 * v.getBrushSize(); y >= 0; y--) { - for (int z = 2 * v.getBrushSize(); z >= 0; z--) - { - splat[x][y][z] = tempSplat[x][y][z]; - } + if (2 * v.getBrushSize() + 1 >= 0) + System.arraycopy(tempSplat[x][y], 0, splat[x][y], 0, + 2 * v.getBrushSize() + 1); } } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterDiscBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterDiscBrush.java index c67d1e094..05d970753 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterDiscBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterDiscBrush.java @@ -115,10 +115,8 @@ public class SplatterDiscBrush extends PerformBrush // integrate tempsplat back into splat at end of iteration for (int x = 2 * v.getBrushSize(); x >= 0; x--) { - for (int y = 2 * v.getBrushSize(); y >= 0; y--) - { - splat[x][y] = tempSplat[x][y]; - } + if (2 * v.getBrushSize() + 1 >= 0) + System.arraycopy(tempSplat[x], 0, splat[x], 0, 2 * v.getBrushSize() + 1); } } this.growPercent = gref; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java index d11666de7..162f831d0 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterOverlayBrush.java @@ -104,10 +104,8 @@ public class SplatterOverlayBrush extends PerformBrush // integrate tempsplat back into splat at end of iteration for (int x = 2 * v.getBrushSize(); x >= 0; x--) { - for (int y = 2 * v.getBrushSize(); y >= 0; y--) - { - splat[x][y] = tempSplat[x][y]; - } + if (2 * v.getBrushSize() + 1 >= 0) + System.arraycopy(tempSplat[x], 0, splat[x], 0, 2 * v.getBrushSize() + 1); } } this.growPercent = gref; @@ -240,10 +238,8 @@ public class SplatterOverlayBrush extends PerformBrush // integrate tempsplat back into splat at end of iteration for (int x = 2 * v.getBrushSize(); x >= 0; x--) { - for (int y = 2 * v.getBrushSize(); y >= 0; y--) - { - splat[x][y] = tempsplat[x][y]; - } + if (2 * v.getBrushSize() + 1 >= 0) + System.arraycopy(tempsplat[x], 0, splat[x], 0, 2 * v.getBrushSize() + 1); } } this.growPercent = gref; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelBrush.java index cfa39e759..805ab96cd 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelBrush.java @@ -130,10 +130,9 @@ public class SplatterVoxelBrush extends PerformBrush { for (int y = 2 * v.getBrushSize(); y >= 0; y--) { - for (int z = 2 * v.getBrushSize(); z >= 0; z--) - { - splat[x][y][z] = tempSplat[x][y][z]; - } + if (2 * v.getBrushSize() + 1 >= 0) + System.arraycopy(tempSplat[x][y], 0, splat[x][y], 0, + 2 * v.getBrushSize() + 1); } } } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelDiscBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelDiscBrush.java index aea30c080..920a8be7d 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelDiscBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplatterVoxelDiscBrush.java @@ -111,10 +111,8 @@ public class SplatterVoxelDiscBrush extends PerformBrush // integrate tempsplat back into splat at end of iteration for (int x = 2 * v.getBrushSize(); x >= 0; x--) { - for (int y = 2 * v.getBrushSize(); y >= 0; y--) - { - splat[x][y] = tempSplat[x][y]; - } + if (2 * v.getBrushSize() + 1 >= 0) + System.arraycopy(tempSplat[x], 0, splat[x], 0, 2 * v.getBrushSize() + 1); } } this.growPercent = gref; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/WallSider.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/WallSider.java index a083bd4b0..f1b794f4b 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/WallSider.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/WallSider.java @@ -104,7 +104,7 @@ public class WallSider extends Brush{ if (this.c > 4 || this.c < 0) { this.c = 4; } - snipeData.sendMessage(ChatColor.AQUA + "Orientation set to " + this.facings[this.c]); + snipeData.sendMessage(ChatColor.AQUA + "Orientation set to " + facings[this.c]); } else if (lowerCase.startsWith("true")) { this.e = 0.5; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/Performer.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/Performer.java index 01a2a07c5..157d1b6ef 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/Performer.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/Performer.java @@ -12,7 +12,7 @@ import com.thevoxelbox.voxelsniper.Message; public interface Performer { - public void parse(String[] args, com.thevoxelbox.voxelsniper.SnipeData v); + void parse(String[] args, com.thevoxelbox.voxelsniper.SnipeData v); - public void showInfo(Message vm); + void showInfo(Message vm); } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java index eafae4f82..c4f5b819e 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java @@ -99,7 +99,7 @@ public enum PerformerE public static String performer_list_short = ""; public static String performer_list_long = ""; - private PerformerE(Class c, String s, String l) + PerformerE(Class c, String s, String l) { pclass = c; short_name = s; @@ -116,28 +116,12 @@ public enum PerformerE p = pclass.getConstructor().newInstance(); return p; } - catch (InstantiationException ex) - { - Logger.getLogger(PerformerE.class.getName()).log(Level.SEVERE, null, ex); - } - catch (IllegalAccessException ex) - { - Logger.getLogger(PerformerE.class.getName()).log(Level.SEVERE, null, ex); - } - catch (IllegalArgumentException ex) - { - Logger.getLogger(PerformerE.class.getName()).log(Level.SEVERE, null, ex); - } - catch (InvocationTargetException ex) + catch (InstantiationException | IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) { Logger.getLogger(PerformerE.class.getName()).log(Level.SEVERE, null, ex); } } - catch (NoSuchMethodException ex) - { - Logger.getLogger(PerformerE.class.getName()).log(Level.SEVERE, null, ex); - } - catch (SecurityException ex) + catch (NoSuchMethodException | SecurityException ex) { Logger.getLogger(PerformerE.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java index 997ccc1e3..d8f31240c 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/util/BlockWrapper.java @@ -1,6 +1,7 @@ package com.thevoxelbox.voxelsniper.util; import com.boydti.fawe.bukkit.wrapper.AsyncBlock; +import org.bukkit.Material; import org.bukkit.World; /** @@ -10,6 +11,7 @@ public class BlockWrapper { private int id; + private Material type; private int x; private int y; private int z; @@ -38,6 +40,10 @@ public class BlockWrapper return this.data; } + public Material getType() { + return type; + } + /** * @return the id */ @@ -131,4 +137,9 @@ public class BlockWrapper { this.z = z; } + + public void setType(Material type) { + this.type = type; + } + }