From b4fc55e33a3de4c9b0152724d7490e51d8979c9a Mon Sep 17 00:00:00 2001 From: KevDaDev <65958288+KevinDaGame@users.noreply.github.com> Date: Sat, 21 Jan 2023 23:47:14 +0100 Subject: [PATCH 1/8] Version 8.4.3 --- buildSrc/src/main/kotlin/voxel-core.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/voxel-core.gradle.kts b/buildSrc/src/main/kotlin/voxel-core.gradle.kts index b326b8e4..3f620274 100644 --- a/buildSrc/src/main/kotlin/voxel-core.gradle.kts +++ b/buildSrc/src/main/kotlin/voxel-core.gradle.kts @@ -48,7 +48,7 @@ java { } group = "com.github.kevindagame" -version = "8.4.2" +version = "8.4.3" //java.sourceCompatibility = JavaVersion.VERSION_16 tasks.withType { @@ -93,4 +93,4 @@ publishing { from(components["java"]) } } -} \ No newline at end of file +} From b743dc651567a3f044e00e66ff4456f030790e95 Mon Sep 17 00:00:00 2001 From: Lennart99 Date: Mon, 30 Jan 2023 18:32:13 +0100 Subject: [PATCH 2/8] make drain brush clear watterlogged blocks + some other improvements (#118) * #92: Make drain brush also drain waterlogged blocks and bubble columns * Clear Sniper when a player leaves the server, retry brush creation when getting brush (this makes the brush automatically populate when the player got OP after he joined) * Improved brush command * changed message in brush command * Embed Sniper into Player, unfortunately still requires some code in the spigot module * Forcefully instantiate default brush in SnipeTool constructor * remove permission check from SnipeTool --- .../kevindagame/VoxelProfileManager.java | 37 ------------------- .../github/kevindagame/brush/DrainBrush.java | 10 ++++- .../command/VoxelBrushCommand.java | 25 ++++++++----- .../command/VoxelBrushToolCommand.java | 3 +- .../command/VoxelDefaultCommand.java | 3 +- .../kevindagame/command/VoxelInkCommand.java | 5 +-- .../command/VoxelInkReplaceCommand.java | 5 +-- .../command/VoxelPerformerCommand.java | 3 +- .../command/VoxelReplaceCommand.java | 3 +- .../command/VoxelSniperCommand.java | 3 +- .../kevindagame/command/VoxelUndoCommand.java | 6 +-- .../command/VoxelVariablesCommand.java | 3 +- .../command/VoxelVoxelCommand.java | 3 +- .../github/kevindagame/snipe/SnipeTool.java | 20 ++++------ .../com/github/kevindagame/snipe/Sniper.java | 6 ++- .../com/github/kevindagame/util/Messages.java | 1 + .../blockdata/waterlogged/IWaterlogged.java | 8 ++++ .../voxelsniper/entity/player/IPlayer.java | 4 ++ .../voxelsniper/material/VoxelMaterial.java | 2 +- VoxelSniperCore/src/main/resources/lang.yml | 3 +- .../voxelsniper/SniperManagerTest.java | 8 ++-- .../voxelsniper/SpigotVoxelSniper.java | 4 -- .../voxelsniper/VoxelSniperListener.java | 5 +-- .../blockdata/SpigotBlockData.java | 8 +++- .../waterlogged/SpigotWaterlogged.java | 21 +++++++++++ .../entity/player/SpigotPlayer.java | 9 +++++ 26 files changed, 106 insertions(+), 102 deletions(-) delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelProfileManager.java create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/IWaterlogged.java create mode 100644 VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/SpigotWaterlogged.java diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelProfileManager.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelProfileManager.java deleted file mode 100644 index 46def28a..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelProfileManager.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.kevindagame; - -import com.github.kevindagame.snipe.Sniper; -import com.github.kevindagame.voxelsniper.entity.player.IPlayer; -import com.google.common.collect.Maps; - -import java.util.Map; -import java.util.UUID; - -/** - * Profile manager for Sniper instances. Each SniperProfile object represents a single player. - */ -public class VoxelProfileManager { - - private static VoxelProfileManager instance = null; - - private final Map sniperInstances = Maps.newHashMap(); - - public static VoxelProfileManager getInstance() { - return instance; - } - - public static void initialize() { - VoxelProfileManager profileManager = getInstance(); - - if (profileManager == null) { - instance = new VoxelProfileManager(); - } - } - - public Sniper getSniperForPlayer(IPlayer player) { - if (sniperInstances.get(player.getUniqueId()) == null) { - sniperInstances.put(player.getUniqueId(), new Sniper(player)); - } - return sniperInstances.get(player.getUniqueId()); - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java index 887b2be9..8ac557c6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java @@ -5,6 +5,7 @@ import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; import com.github.kevindagame.util.brushOperation.BlockOperation; +import com.github.kevindagame.voxelsniper.blockdata.waterlogged.IWaterlogged; import com.github.kevindagame.voxelsniper.material.VoxelMaterial; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; @@ -34,8 +35,13 @@ private void drain(final SnipeData v) { var positions = this.disc ? Shapes.disc(getTargetBlock().getLocation(), v.getBrushSize(), smooth) : Shapes.ball(getTargetBlock().getLocation(), v.getBrushSize(), smooth); for (var pos : positions) { var block = pos.getBlock(); - if (block.getMaterial().isFluid()) { - addOperation(new BlockOperation(pos, block.getBlockData(), VoxelMaterial.AIR.createBlockData())); + var blockData = block.getBlockData(); + if (blockData.getMaterial().isFluid()) { + addOperation(new BlockOperation(pos, blockData, VoxelMaterial.AIR.createBlockData())); + } else if (blockData instanceof IWaterlogged waterlogged && waterlogged.isWaterlogged()) { + var newData = (IWaterlogged) waterlogged.getCopy(); + newData.setWaterlogged(false); + addOperation(new BlockOperation(pos, blockData, newData)); } } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java index 642a99a7..bf82d8ab 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java @@ -1,7 +1,6 @@ package com.github.kevindagame.command; import com.github.kevindagame.VoxelBrushManager; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.brush.IBrush; import com.github.kevindagame.brush.perform.IPerformerBrush; import com.github.kevindagame.snipe.SnipeData; @@ -36,7 +35,7 @@ public List registerTabCompletion() { @Override public boolean doCommand(IPlayer player, final String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); String currentToolId = sniper.getCurrentToolId(); SnipeData snipeData = sniper.getSnipeData(currentToolId); @@ -57,17 +56,21 @@ public boolean doCommand(IPlayer player, final String[] args) { // Command: /b -- Change brush size try { int originalSize = snipeData.getBrushSize(); + int newSize = Integer.parseInt(args[0]); var brush = sniper.getBrush(currentToolId); - if (brush == null) return false; - - if (!new PlayerBrushSizeChangedEvent(player, currentToolId, brush, originalSize, snipeData.getBrushSize()).callEvent().isCancelled()) { - snipeData.setBrushSize(Integer.parseInt(args[0])); - snipeData.getVoxelMessage().size(); + if (brush == null) { + snipeData.sendMessage(Messages.NO_BRUSH_SELECTED); return true; + } + if (new PlayerBrushSizeChangedEvent(player, currentToolId, brush, originalSize, newSize).callEvent().isCancelled()) { + snipeData.sendMessage(Messages.ACTION_CANCELLED); + } else { + snipeData.setBrushSize(newSize); + snipeData.getVoxelMessage().size(); } - return false; + return true; } catch (NumberFormatException ignored) { } @@ -87,7 +90,7 @@ public boolean doCommand(IPlayer player, final String[] args) { IBrush oldBrush = sniper.getBrush(currentToolId); IBrush newBrush = sniper.instantiateBrush(brush); - if (newBrush == null) { + if (newBrush == null || !player.hasPermission(newBrush.getPermissionNode())) { snipeData.sendMessage(Messages.VOXEL_BRUSH_NO_PERMISSION); return true; } @@ -103,7 +106,9 @@ public boolean doCommand(IPlayer player, final String[] args) { newBrush.parseParameters(args[0], additionalParameters, snipeData); } } - if (!new PlayerBrushChangedEvent(player, currentToolId, oldBrush, newBrush).callEvent().isCancelled()) { + if (new PlayerBrushChangedEvent(player, currentToolId, oldBrush, newBrush).callEvent().isCancelled()) { + snipeData.sendMessage(Messages.ACTION_CANCELLED); + } else { sniper.setBrush(currentToolId, newBrush); sniper.displayInfo(); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushToolCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushToolCommand.java index 904fe9aa..e99d228c 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushToolCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushToolCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeAction; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.Messages; @@ -23,7 +22,7 @@ public VoxelBrushToolCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); // Default command // Command: /btool, /btool help, /btool info diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelDefaultCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelDefaultCommand.java index 5ff70dca..c4bc006a 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelDefaultCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelDefaultCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.Messages; import com.github.kevindagame.voxelsniper.entity.player.IPlayer; @@ -18,7 +17,7 @@ public VoxelDefaultCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); // Default command // Command: /d info, /d help diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkCommand.java index b8fa1153..258b8ed7 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.BlockHelper; @@ -22,7 +21,7 @@ public VoxelInkCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); // Default command @@ -65,7 +64,7 @@ public boolean doCommand(IPlayer player, String[] args) { @Override public List doSuggestion(IPlayer player, String[] args) { // TODO: Very hacky parsing, find a more elegant solution. - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); String[] a = snipeData.getVoxelSubstance().getAsString().split("\\["); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkReplaceCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkReplaceCommand.java index 912912f4..8c7b8203 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkReplaceCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelInkReplaceCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.BlockHelper; @@ -22,7 +21,7 @@ public VoxelInkReplaceCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); // Default command @@ -64,7 +63,7 @@ public boolean doCommand(IPlayer player, String[] args) { @Override public List doSuggestion(IPlayer player, String[] args) { // TODO: Very hacky parsing, find a more elegant solution. - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); String[] a = snipeData.getReplaceSubstance().getAsString().split("\\["); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelPerformerCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelPerformerCommand.java index 2939b7c0..e118be40 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelPerformerCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelPerformerCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.brush.IBrush; import com.github.kevindagame.brush.perform.IPerformerBrush; import com.github.kevindagame.brush.perform.Performer; @@ -28,7 +27,7 @@ public List registerTabCompletion() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); // Default command diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelReplaceCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelReplaceCommand.java index 566d25f1..44f0fab7 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelReplaceCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelReplaceCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.BlockHelper; @@ -21,7 +20,7 @@ public VoxelReplaceCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); // Default command diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelSniperCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelSniperCommand.java index b4995ffc..3c49c230 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelSniperCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelSniperCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.Messages; @@ -21,7 +20,7 @@ public VoxelSniperCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); // Default command diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelUndoCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelUndoCommand.java index 1db21031..e4f73816 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelUndoCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelUndoCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.VoxelSniper; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.Messages; @@ -20,8 +19,7 @@ public VoxelUndoCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - VoxelProfileManager profileManager = VoxelProfileManager.getInstance(); - Sniper sniper = profileManager.getSniperForPlayer(player); + Sniper sniper = player.getSniper(); if ((args.length == 1 && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("info"))) || args.length > 2) { sniper.sendMessage(Messages.VOXEL_UNDO_COMMAND_USAGE_START.replace("%alias%", getActiveAlias()).replace("%name%", getName())); @@ -61,7 +59,7 @@ public boolean doCommand(IPlayer player, String[] args) { return true; } - Sniper targetSniper = profileManager.getSniperForPlayer(targetPlayer); + Sniper targetSniper = targetPlayer.getSniper(); int undoAmount = 1; // Command: /u [playerName] [amount] <- Undo the previous [amount] changes made by [playerName]. diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVariablesCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVariablesCommand.java index 2aec6084..3a787455 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVariablesCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVariablesCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.Messages; @@ -25,7 +24,7 @@ public VoxelVariablesCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); if (getActiveAlias().equalsIgnoreCase("vc")) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVoxelCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVoxelCommand.java index b82ff973..5e3eff7d 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVoxelCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelVoxelCommand.java @@ -1,6 +1,5 @@ package com.github.kevindagame.command; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.util.BlockHelper; @@ -21,7 +20,7 @@ public VoxelVoxelCommand() { @Override public boolean doCommand(IPlayer player, String[] args) { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); // Default command diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java index d44afdc7..1425c3a9 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java @@ -7,6 +7,9 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableBiMap; + +import java.util.Objects; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -16,28 +19,19 @@ public class SnipeTool { private final BiMap actionTools = HashBiMap.create(); - private IBrush currentBrush = null; + private @NotNull IBrush currentBrush; private IBrush previousBrush = null; private final VoxelMessage messageHelper; private final SnipeData snipeData; protected SnipeTool(Sniper owner) { - this(owner.instantiateBrush(SnipeBrush.class), new SnipeData(owner)); - } - - protected SnipeTool(@Nullable IBrush brush, SnipeData snipeData) { - this.snipeData = snipeData; + this.snipeData = new SnipeData(owner); messageHelper = new VoxelMessage(snipeData); snipeData.setVoxelMessage(messageHelper); - if (brush != null && snipeData.owner().getPlayer().hasPermission(brush.getPermissionNode())) { // npe brush.getPermissionNode() - this.currentBrush = brush; - } + this.currentBrush = Objects.requireNonNull(owner.instantiateBrush(SnipeBrush.class, true)); } - public @Nullable IBrush getCurrentBrush() { - if (currentBrush == null) { - return null; - } + public @NotNull IBrush getCurrentBrush() { return currentBrush; } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java index 8b2969e0..24af78d6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java @@ -293,9 +293,13 @@ public final void sendMessage(final @NotNull ComponentLike message) { } public @Nullable IBrush instantiateBrush(Class brush) { + return this.instantiateBrush(brush, false); + } + + public @Nullable IBrush instantiateBrush(Class brush, boolean force) { try { var brushInstance = brush.newInstance(); - if(getPlayer().hasPermission(brushInstance.getPermissionNode())) + if(force || getPlayer().hasPermission(brushInstance.getPermissionNode())) return brushInstance; } catch (InstantiationException | IllegalAccessException e) { return null; diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java index 182c73e3..50ef68e3 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java @@ -354,6 +354,7 @@ public enum Messages implements ComponentLike { UNDERLAY_DEPTH_SET, UNDERLAY_MODE, UNDERLAY_ON_MODE_DEPTH, + ACTION_CANCELLED, ; // diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/IWaterlogged.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/IWaterlogged.java new file mode 100644 index 00000000..9f9e1ed0 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/IWaterlogged.java @@ -0,0 +1,8 @@ +package com.github.kevindagame.voxelsniper.blockdata.waterlogged; + +import com.github.kevindagame.voxelsniper.blockdata.IBlockData; + +public interface IWaterlogged extends IBlockData { + boolean isWaterlogged(); + void setWaterlogged(boolean waterlogged); +} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/entity/player/IPlayer.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/entity/player/IPlayer.java index 773a7fff..ead93dee 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/entity/player/IPlayer.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/entity/player/IPlayer.java @@ -1,5 +1,6 @@ package com.github.kevindagame.voxelsniper.entity.player; +import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.voxelsniper.block.IBlock; import com.github.kevindagame.voxelsniper.entity.IEntity; import com.github.kevindagame.voxelsniper.entity.entitytype.VoxelEntityType; @@ -34,6 +35,9 @@ public interface IPlayer extends IEntity, Audience { VoxelMaterial getItemInHand(); + @NotNull + Sniper getSniper(); + @Override void sendMessage(final @NotNull Identity source, final @NotNull Component message, final @NotNull MessageType type); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/material/VoxelMaterial.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/material/VoxelMaterial.java index 42acd173..ac1d65e0 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/material/VoxelMaterial.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/material/VoxelMaterial.java @@ -669,7 +669,7 @@ public class VoxelMaterial implements IMaterial { public static final VoxelMaterial POTTED_BAMBOO = register("minecraft", "potted_bamboo"); public static final VoxelMaterial VOID_AIR = register("minecraft", "void_air", Tags.AIR); public static final VoxelMaterial CAVE_AIR = register("minecraft", "cave_air", Tags.AIR); - public static final VoxelMaterial BUBBLE_COLUMN = register("minecraft", "bubble_column"); + public static final VoxelMaterial BUBBLE_COLUMN = register("minecraft", "bubble_column", Tags.FLUIDS); public static final VoxelMaterial POLISHED_GRANITE_STAIRS = register("minecraft", "polished_granite_stairs"); public static final VoxelMaterial SMOOTH_RED_SANDSTONE_STAIRS = register("minecraft", "smooth_red_sandstone_stairs"); public static final VoxelMaterial MOSSY_STONE_BRICK_STAIRS = register("minecraft", "mossy_stone_brick_stairs"); diff --git a/VoxelSniperCore/src/main/resources/lang.yml b/VoxelSniperCore/src/main/resources/lang.yml index 0f033254..53349447 100644 --- a/VoxelSniperCore/src/main/resources/lang.yml +++ b/VoxelSniperCore/src/main/resources/lang.yml @@ -584,4 +584,5 @@ GENERATED_CHUNK: Generate that chunk! %chunk.getX% %chunk.getZ% FILE_ALREADY_EXISTS: This file already exists. UNDERLAY_DEPTH_SET: Underlay depth set to %depth% UNDERLAY_MODE: Underlaying on %mode% blocks -UNDERLAY_ON_MODE_DEPTH: Will underlay on %mode% blocks, %depth% blocks deep. \ No newline at end of file +UNDERLAY_ON_MODE_DEPTH: Will underlay on %mode% blocks, %depth% blocks deep. +ACTION_CANCELLED: The action was cancelled \ No newline at end of file diff --git a/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/SniperManagerTest.java b/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/SniperManagerTest.java index b3eabbbc..970de0ec 100644 --- a/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/SniperManagerTest.java +++ b/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/SniperManagerTest.java @@ -1,6 +1,5 @@ package com.github.kevindagame.voxelsniper; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.VoxelSniper; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.voxelsniper.blockdata.IBlockData; @@ -39,15 +38,16 @@ public void setUp() { Mockito.when(main.getMaterial(VoxelMaterial.AIR)).thenReturn(mat); VoxelSniper.voxelsniper = main; - VoxelProfileManager.initialize(); + Sniper sniper = new Sniper(absplayer); + Mockito.when(absplayer.getSniper()).thenReturn(sniper); } @Test public void testGetSniperForPlayer() { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(absplayer); + Sniper sniper = absplayer.getSniper(); Assert.assertSame(absplayer, sniper.getPlayer()); - Assert.assertSame(sniper, VoxelProfileManager.getInstance().getSniperForPlayer(absplayer)); + Assert.assertSame(sniper, absplayer.getSniper()); } } diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/SpigotVoxelSniper.java b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/SpigotVoxelSniper.java index cc6d3a2f..2d17d965 100644 --- a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/SpigotVoxelSniper.java +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/SpigotVoxelSniper.java @@ -1,7 +1,6 @@ package com.github.kevindagame.voxelsniper; import com.github.kevindagame.VoxelBrushManager; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.VoxelSniper; import com.github.kevindagame.util.Messages; import com.github.kevindagame.voxelsniper.entity.player.IPlayer; @@ -71,9 +70,6 @@ public void onEnable() { this.fileHandler = new SpigotFileHandler(this); - // Initialize profile manager (Sniper) - VoxelProfileManager.initialize(); - // Initialize messages Messages.load(this); SpigotVoxelSniper.adventure = BukkitAudiences.create(this); diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/VoxelSniperListener.java b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/VoxelSniperListener.java index 37b20908..89b4454a 100644 --- a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/VoxelSniperListener.java +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/VoxelSniperListener.java @@ -1,6 +1,5 @@ package com.github.kevindagame.voxelsniper; -import com.github.kevindagame.VoxelProfileManager; import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.voxelsniper.block.BlockFace; import com.github.kevindagame.voxelsniper.block.SpigotBlock; @@ -46,7 +45,7 @@ public final void onPlayerInteract(final PlayerInteractEvent event) { if (!player.hasPermission(SNIPER_PERMISSION)) return; if (cooldown.contains(player.getUniqueId())) return; try { - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); if (sniper.isEnabled() && sniper.snipe( Sniper.Action.valueOf(event.getAction().name()), VoxelMaterial.getMaterial(event.getMaterial().getKey().getKey()), @@ -67,7 +66,7 @@ public final void onPlayerInteract(final PlayerInteractEvent event) { @EventHandler public final void onPlayerJoin(final PlayerJoinEvent event) { IPlayer player = SpigotVoxelSniper.getInstance().getPlayer(event.getPlayer()); - Sniper sniper = VoxelProfileManager.getInstance().getSniperForPlayer(player); + Sniper sniper = player.getSniper(); if (player.hasPermission(SNIPER_PERMISSION) && plugin.getVoxelSniperConfiguration().isMessageOnLoginEnabled()) { sniper.displayInfo(); diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java index 2346ff04..e114fb1b 100644 --- a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java @@ -1,9 +1,11 @@ package com.github.kevindagame.voxelsniper.blockdata; import com.github.kevindagame.voxelsniper.blockdata.redstoneWire.SpigotRedstoneWire; +import com.github.kevindagame.voxelsniper.blockdata.waterlogged.SpigotWaterlogged; import com.github.kevindagame.voxelsniper.material.SpigotMaterial; import com.github.kevindagame.voxelsniper.material.VoxelMaterial; import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.RedstoneWire; public class SpigotBlockData implements IBlockData { @@ -16,6 +18,8 @@ protected SpigotBlockData(BlockData blockData) { public static IBlockData fromSpigotData(BlockData blockData) { if (blockData instanceof RedstoneWire redstone) return new SpigotRedstoneWire(redstone); + if (blockData instanceof Waterlogged waterlogged) + return new SpigotWaterlogged(waterlogged); return new SpigotBlockData(blockData); } @@ -40,11 +44,11 @@ public String getAsString() { @Override public IBlockData merge(IBlockData newData) { - return new SpigotBlockData(this.blockData.merge(((SpigotBlockData) newData).getBlockData())); + return SpigotBlockData.fromSpigotData(this.blockData.merge(((SpigotBlockData) newData).getBlockData())); } @Override public IBlockData getCopy() { - return new SpigotBlockData(blockData.clone()); + return SpigotBlockData.fromSpigotData(blockData.clone()); } } diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/SpigotWaterlogged.java b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/SpigotWaterlogged.java new file mode 100644 index 00000000..68866788 --- /dev/null +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/waterlogged/SpigotWaterlogged.java @@ -0,0 +1,21 @@ +package com.github.kevindagame.voxelsniper.blockdata.waterlogged; + +import com.github.kevindagame.voxelsniper.blockdata.SpigotBlockData; + +import org.bukkit.block.data.Waterlogged; + +public class SpigotWaterlogged extends SpigotBlockData implements IWaterlogged { + public SpigotWaterlogged(Waterlogged blockData) { + super(blockData); + } + + @Override + public boolean isWaterlogged() { + return ((Waterlogged)this.blockData).isWaterlogged(); + } + + @Override + public void setWaterlogged(boolean waterlogged) { + ((Waterlogged)this.blockData).setWaterlogged(waterlogged); + } +} diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/entity/player/SpigotPlayer.java b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/entity/player/SpigotPlayer.java index f04d5623..defb1c8a 100644 --- a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/entity/player/SpigotPlayer.java +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/entity/player/SpigotPlayer.java @@ -1,5 +1,6 @@ package com.github.kevindagame.voxelsniper.entity.player; +import com.github.kevindagame.snipe.Sniper; import com.github.kevindagame.voxelsniper.SpigotVoxelSniper; import com.github.kevindagame.voxelsniper.block.IBlock; import com.github.kevindagame.voxelsniper.block.SpigotBlock; @@ -30,10 +31,12 @@ public class SpigotPlayer extends SpigotEntity implements IPlayer { private final Player player; + private final @NotNull Sniper sniper; public SpigotPlayer(Player player) { super(player); this.player = player; + this.sniper = new Sniper(this); } @Override @@ -95,6 +98,12 @@ public VoxelMaterial getItemInHand() { return mat != null ? mat : VoxelMaterial.AIR; } + @Override + @NotNull + public Sniper getSniper() { + return this.sniper; + } + @Override public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) { SpigotVoxelSniper.getAdventure().player(this.player).sendMessage(source, message, type); From fa3e1aea959d9815ae076b7b717423a5c0d6782f Mon Sep 17 00:00:00 2001 From: Lennart99 Date: Tue, 28 Feb 2023 18:33:57 +0100 Subject: [PATCH 3/8] Fixed rotation brushes (#120) * #47: Fixed 2d rotation brushes, abstracted the actual rotation logic * #47: Rewrote 3D rotation brush to work in the same way as the 2D versions. still thinking about merging the 2D and 3D rotation logic together in some way * Changed rotation method to use a shape, need to fix the vertical brush separately, since that one needs a slightly different shape * Make it possible to rotate the disc and cylinder shapes, rotate the shape for Rot2DvertBrush * remove old comment --- .../github/kevindagame/VoxelBrushManager.java | 6 +- .../github/kevindagame/brush/AbstractBrush.kt | 2 +- .../kevindagame/brush/BlendDiscBrush.java | 3 +- .../kevindagame/brush/CloneStampBrush.java | 3 +- .../kevindagame/brush/CylinderBrush.java | 3 +- .../github/kevindagame/brush/DiscBrush.java | 3 +- .../github/kevindagame/brush/DrainBrush.java | 3 +- .../github/kevindagame/brush/Rot2DBrush.java | 127 ++----------- .../kevindagame/brush/Rot2DvertBrush.java | 130 ++------------ .../github/kevindagame/brush/Rot3DBrush.java | 167 ++---------------- .../kevindagame/brush/SplatterDiscBrush.java | 3 +- .../com/github/kevindagame/util/Actions.java | 47 +++++ .../github/kevindagame/util/RotationAxis.kt | 12 ++ .../com/github/kevindagame/util/Shapes.java | 18 +- .../voxelsniper/location/BaseLocation.java | 4 + .../voxelsniper/location/VoxelLocation.java | 4 + .../kevindagame/voxelsniper/world/IWorld.java | 4 + 17 files changed, 137 insertions(+), 402 deletions(-) create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/util/RotationAxis.kt diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java index f9aa92c4..b74447d0 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java @@ -103,9 +103,9 @@ public static VoxelBrushManager initialize() { //brushManager.registerSniperBrush(StencilBrush.class, "st", "stencil"); //brushManager.registerSniperBrush(StencilListBrush.class, "sl", "stencillist"); - //brushManager.registerSniperBrush(Rot2DBrush.class, "rot2", "rotation2d"); - //brushManager.registerSniperBrush(Rot2DvertBrush.class, "rot2v", "rotation2dvertical"); - //brushManager.registerSniperBrush(Rot3DBrush.class, "rot3", "rotation3d"); + brushManager.registerSniperBrush(Rot2DBrush.class, "rot2", "rotation2d"); + brushManager.registerSniperBrush(Rot2DvertBrush.class, "rot2v", "rotation2dvertical"); + brushManager.registerSniperBrush(Rot3DBrush.class, "rot3", "rotation3d"); //these brushes have an unknown status diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt index 682c9a5b..36e9012b 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt @@ -245,7 +245,7 @@ abstract class AbstractBrush : IBrush { protected get() = world.maxWorldHeight protected fun isInWorldHeight(height: Int): Boolean { - return minHeight <= height && maxHeight > height + return world.isInWorldHeight(height) } /** diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java index fbf11bca..91d7a7a5 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java @@ -2,6 +2,7 @@ import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.brushOperation.BlockOperation; import com.github.kevindagame.voxelsniper.material.VoxelMaterial; @@ -20,7 +21,7 @@ public BlendDiscBrush() { @Override protected final void blend(final SnipeData v) { - var positions = Shapes.disc(this.getTargetBlock().getLocation(), v.getBrushSize(), false); + var positions = Shapes.disc(this.getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), false); var brushSize = v.getBrushSize(); var newMaterials = this.blend2D(brushSize); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java index f6822e20..d9226cd7 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java @@ -3,6 +3,7 @@ import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.util.BlockWrapper; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; import com.github.kevindagame.voxelsniper.location.BaseLocation; @@ -42,7 +43,7 @@ private void clone(final SnipeData v) { VoxelLocation point = getTargetBlock().getLocation().makeMutable(); point.add(0, v.getcCen(), 0); this.startingPoint = point.makeImmutable(); - var positions = Shapes.cylinder(startingPoint, v.getBrushSize(), v.getVoxelHeight(), 0, false); + var positions = Shapes.cylinder(startingPoint, RotationAxis.Y, v.getBrushSize(), v.getVoxelHeight(), 0, false); this.clone.clear(); this.toStamp.clear(); this.sorted = false; diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java index 8d69c310..a8bc258b 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java @@ -3,6 +3,7 @@ import com.github.kevindagame.brush.perform.PerformerBrush; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; import com.google.common.collect.Lists; @@ -28,7 +29,7 @@ public CylinderBrush() { } private void cylinder(final SnipeData v) { - this.positions = Shapes.cylinder(this.getTargetBlock().getLocation(), v.getBrushSize(), v.getVoxelHeight(), v.getcCen(), this.smoothCircle); + this.positions = Shapes.cylinder(this.getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), v.getVoxelHeight(), v.getcCen(), this.smoothCircle); } @Override diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java index 5e23ab7f..e03a8c11 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java @@ -3,6 +3,7 @@ import com.github.kevindagame.brush.perform.PerformerBrush; import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; import com.github.kevindagame.voxelsniper.block.IBlock; @@ -35,7 +36,7 @@ public DiscBrush() { * @param v SnipeData */ private void disc(final SnipeData v, final IBlock targetBlock) { - this.positions = Shapes.disc(targetBlock.getLocation(), v.getBrushSize(), this.smoothCircle); + this.positions = Shapes.disc(targetBlock.getLocation(), RotationAxis.Y, v.getBrushSize(), this.smoothCircle); } @Override diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java index 8ac557c6..53438bfe 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java @@ -2,6 +2,7 @@ import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; import com.github.kevindagame.util.brushOperation.BlockOperation; @@ -32,7 +33,7 @@ public DrainBrush() { } private void drain(final SnipeData v) { - var positions = this.disc ? Shapes.disc(getTargetBlock().getLocation(), v.getBrushSize(), smooth) : Shapes.ball(getTargetBlock().getLocation(), v.getBrushSize(), smooth); + var positions = this.disc ? Shapes.disc(getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), smooth) : Shapes.ball(getTargetBlock().getLocation(), v.getBrushSize(), smooth); for (var pos : positions) { var block = pos.getBlock(); var blockData = block.getBlockData(); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java index bdaaca09..e92319db 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java @@ -2,13 +2,11 @@ import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.BlockWrapper; +import com.github.kevindagame.util.Actions; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; +import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.util.brushOperation.BlockOperation; -import com.github.kevindagame.voxelsniper.block.IBlock; -import com.github.kevindagame.voxelsniper.blockdata.IBlockData; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; @@ -20,8 +18,7 @@ * ... */ public class Rot2DBrush extends AbstractBrush { - private BlockWrapper[][][] snap; - private double se; + private double angle = 90; /** * @@ -30,122 +27,20 @@ public Rot2DBrush() { this.setName("2D Rotation"); } - private void getMatrix(final int bSize) { - int brushSize = (bSize * 2) + 1; - - this.snap = new BlockWrapper[brushSize][brushSize][brushSize]; - - final double brushSizeSquared = Math.pow(bSize + 0.5, 2); - int sx = this.getTargetBlock().getX() - bSize; - int sy = this.getTargetBlock().getY() - bSize; - int sz = this.getTargetBlock().getZ() - bSize; - - for (int x = 0; x < this.snap.length; x++) { - sz = this.getTargetBlock().getZ() - bSize; - final double xSquared = Math.pow(x - bSize, 2); - for (int y = 0; y < this.snap.length; y++) { - sy = this.getTargetBlock().getY() - bSize; - if (xSquared + Math.pow(y - bSize, 2) <= brushSizeSquared) { - for (int z = 0; z < this.snap.length; z++) { - final IBlock block = getWorld().getBlock(sx, sy, sz); - this.snap[x][z][y] = new BlockWrapper(block); - addOperation(new BlockOperation(block.getLocation(), block.getBlockData(), VoxelMaterial.AIR.createBlockData())); - sy++; - } - } - sz++; - } - sx++; - } - } - - private void rotate(final int bSize, final SnipeData v) { - final double brushSiyeSquared = Math.pow(bSize + 0.5, 2); - final double cos = Math.cos(this.se); - final double sin = Math.sin(this.se); - final boolean[][] doNotFill = new boolean[this.snap.length][this.snap.length]; - // I put y in the inside loop, since it doesn't have any power functions, should be much faster. - // Also, new array keeps track of which x and z coords are being assigned in the rotated space so that we can - // do a targeted filling of only those columns later that were left out. - - for (int x = 0; x < this.snap.length; x++) { - final int xx = x - bSize; - final double xSquared = Math.pow(xx, 2); - - for (int y = 0; y < this.snap.length; y++) { - final int zz = y - bSize; - - if (xSquared + Math.pow(zz, 2) <= brushSiyeSquared) { - final double newX = (xx * cos) - (zz * sin); - final double newZ = (xx * sin) + (zz * cos); - - doNotFill[(int) newX + bSize][(int) newZ + bSize] = true; - - for (int currentY = 0; currentY < this.snap.length; currentY++) { - final int yy = currentY - bSize; - final BlockWrapper block = this.snap[x][currentY][y]; - - if (block.getMaterial().isAir()) { - continue; - } - var b = getWorld().getBlock(this.getTargetBlock().getX() + (int) newX, this.getTargetBlock().getY() + yy, this.getTargetBlock().getZ() + (int) newZ); - addOperation(new BlockOperation(b.getLocation(), b.getBlockData(), block.getBlockData())); - - } - } - } - } - for (int x = 0; x < this.snap.length; x++) { - final double xSquared = Math.pow(x - bSize, 2); - final int fx = x + this.getTargetBlock().getX() - bSize; - - for (int z = 0; z < this.snap.length; z++) { - if (xSquared + Math.pow(z - bSize, 2) <= brushSiyeSquared) { - final int fz = z + this.getTargetBlock().getZ() - bSize; - - if (!doNotFill[x][z]) { - // smart fill stuff - - for (int y = 0; y < this.snap.length; y++) { - final int fy = y + this.getTargetBlock().getY() - bSize; - - final IBlockData a = this.getBlockDataAt(fx + 1, fy, fz); - final IBlockData d = this.getBlockDataAt(fx - 1, fy, fz); - final IBlockData c = this.getBlockDataAt(fx, fy, fz + 1); - final IBlockData b = this.getBlockDataAt(fx, fy, fz - 1); - - IBlockData winner; - - if (a.getMaterial() == b.getMaterial() || a.getMaterial() == c.getMaterial() || a.getMaterial() == d.getMaterial()) { // 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; - } else if (b == d || c == d) { - winner = d; - } else { - winner = b; // blockPositionY making this default, it will also automatically cover situations where B = C; - } - var block = getWorld().getBlock(fx, fy, fz); - addOperation(new BlockOperation(block.getLocation(), block.getBlockData(), winner)); - } - } - } - } - } - } - @Override protected final void arrow(final SnipeData v) { int bSize = v.getBrushSize(); - this.getMatrix(bSize); - this.rotate(bSize, v); - + var cyl = Shapes.cylinder(getTargetBlock().getLocation(), RotationAxis.Y, bSize, (bSize*2)+1, 0, true); + this.addOperations(Actions.rotate3D(getTargetBlock(), cyl, 0, this.angle, 0)); } @Override protected final void powder(final SnipeData v) { - this.arrow(v); + int bSize = v.getBrushSize(); + + var cyl = Shapes.cylinder(getTargetBlock().getLocation(), RotationAxis.Y, bSize, (bSize*2)+1, 0, true); + this.addOperations(Actions.rotate3D(getTargetBlock(), cyl, 0, this.angle * -1, 0)); } @@ -163,7 +58,7 @@ public final void parseParameters(@NotNull final String triggerHandle, final Str try { double degrees = Double.parseDouble(params[0]); - this.se = Math.toRadians(degrees); + this.angle = degrees; v.sendMessage(Messages.ANGLE_SET.replace("%se%", String.valueOf(degrees))); } catch (NumberFormatException temp) { v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java index b699403c..cd9e55e3 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java @@ -1,29 +1,19 @@ package com.github.kevindagame.brush; import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.BlockWrapper; +import com.github.kevindagame.util.Actions; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; +import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.voxelsniper.block.IBlock; -import com.github.kevindagame.voxelsniper.blockdata.IBlockData; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -// TODO: Dissect this - -/** - * @author Gavjenks, hack job from the other 2d rotation brush blockPositionY piotr - */ -// The X Y and Z variable names in this file do NOT MAKE ANY SENSE. Do not attempt to actually figure out what on earth is going on here. Just go to the -// original 2d horizontal brush if you wish to make anything similar to this, and start there. I didn't bother renaming everything. public class Rot2DvertBrush extends AbstractBrush { - - private BlockWrapper[][][] snap; - private double se; + private double angle = 90; /** * @@ -32,119 +22,21 @@ public Rot2DvertBrush() { this.setName("2D Rotation"); } - private void getMatrix(final int bSize) { - int brushSize = (bSize * 2) + 1; - - this.snap = new BlockWrapper[brushSize][brushSize][brushSize]; - - int sx = this.getTargetBlock().getX() - bSize; - int sy = this.getTargetBlock().getY() - bSize; - int sz = this.getTargetBlock().getZ() - bSize; - - for (int x = 0; x < this.snap.length; x++) { - sz = this.getTargetBlock().getZ() - bSize; - - for (int z = 0; z < this.snap.length; z++) { - sy = this.getTargetBlock().getY() - bSize; - - for (int y = 0; y < this.snap.length; y++) { - final IBlock block = this.getWorld().getBlock(sx, sy, sz); // why is this not sx + x, sy + y sz + z? - this.snap[x][y][z] = new BlockWrapper(block); - block.setMaterial(VoxelMaterial.AIR); - sy++; - } - - sz++; - } - sx++; - } - } - - private void rotate(final int bSize, final SnipeData v) { - final double brushSizeSquared = Math.pow(bSize + 0.5, 2); - final double cos = Math.cos(this.se); - final double sin = Math.sin(this.se); - final boolean[][] doNotFill = new boolean[this.snap.length][this.snap.length]; - // I put y in the inside loop, since it doesn't have any power functions, should be much faster. - // Also, new array keeps track of which x and z coords are being assigned in the rotated space so that we can - // do a targeted filling of only those columns later that were left out. - - for (int x = 0; x < this.snap.length; x++) { - final int xx = x - bSize; - final double xSquared = Math.pow(xx, 2); - - for (int z = 0; z < this.snap.length; z++) { - final int zz = z - bSize; - - if (xSquared + Math.pow(zz, 2) <= brushSizeSquared) { - final double newX = (xx * cos) - (zz * sin); - final double newZ = (xx * sin) + (zz * cos); - - doNotFill[(int) newX + bSize][(int) newZ + bSize] = true; - - for (int y = 0; y < this.snap.length; y++) { - final int yy = y - bSize; - - final BlockWrapper block = this.snap[y][x][z]; - if (block.getMaterial().isAir()) { - continue; - } - this.getWorld().getBlock(this.getTargetBlock().getX() + yy, this.getTargetBlock().getY() + (int) newX, this.getTargetBlock().getZ() + (int) newZ).setBlockData(block.getBlockData()); - } - } - } - } - - for (int x = 0; x < this.snap.length; x++) { - final double xSquared = Math.pow(x - bSize, 2); - final int fx = x + this.getTargetBlock().getX() - bSize; - - for (int z = 0; z < this.snap.length; z++) { - if (xSquared + Math.pow(z - bSize, 2) <= brushSizeSquared) { - final int fz = z + this.getTargetBlock().getZ() - bSize; - - if (!doNotFill[x][z]) { - // smart fill stuff - for (int y = 0; y < this.snap.length; y++) { - final int fy = y + this.getTargetBlock().getY() - bSize; - - final IBlockData a = this.getBlockDataAt(fy, fx + 1, fz); - final IBlockData d = this.getBlockDataAt(fy, fx - 1, fz); - final IBlockData c = this.getBlockDataAt(fy, fx, fz + 1); - final IBlockData b = this.getBlockDataAt(fy, fx, fz - 1); - - IBlockData winner; - - if (a.getMaterial() == b.getMaterial() || a.getMaterial() == c.getMaterial() || a.getMaterial() == d.getMaterial()) { // 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; - } else if (b == d || c == d) { - winner = d; - } else { - winner = b; // blockPositionY making this default, it will also automatically cover situations where B = C; - } - - this.getWorld().getBlock(fy, fx, fz).setBlockData(winner); - } - } - } - } - } - } - @Override protected final void arrow(final SnipeData v) { int bSize = v.getBrushSize(); - this.getMatrix(bSize); - this.rotate(bSize, v); + var cyl = Shapes.cylinder(getTargetBlock().getLocation(), RotationAxis.X, bSize, (bSize*2)+1, 0, true); + this.addOperations(Actions.rotate3D(getTargetBlock(), cyl, this.angle, 0, 0)); } @Override protected final void powder(final SnipeData v) { - this.arrow(v); + int bSize = v.getBrushSize(); + + var cyl = Shapes.cylinder(getTargetBlock().getLocation(), RotationAxis.X, bSize, (bSize*2)+1, 0, true); + this.addOperations(Actions.rotate3D(getTargetBlock(), cyl, this.angle * -1, 0, 0)); } @Override @@ -161,7 +53,7 @@ public final void parseParameters(@NotNull final String triggerHandle, final Str try { double degrees = Double.parseDouble(params[0]); - this.se = Math.toRadians(degrees); + this.angle = degrees; v.sendMessage(Messages.ANGLE_SET.replace("%se%", String.valueOf(degrees))); } catch (NumberFormatException temp) { v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java index 05f460f3..6d79784d 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java @@ -1,13 +1,10 @@ package com.github.kevindagame.brush; import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.snipe.Undo; -import com.github.kevindagame.util.BlockWrapper; +import com.github.kevindagame.util.Actions; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.Shapes; import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.voxelsniper.block.IBlock; -import com.github.kevindagame.voxelsniper.blockdata.IBlockData; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; @@ -19,11 +16,9 @@ * ... */ public class Rot3DBrush extends AbstractBrush { - - private BlockWrapper[][][] snap; - private double seYaw; - private double sePitch; - private double seRoll; + private double yaw; + private double pitch; + private double roll; /** * @@ -50,34 +45,32 @@ public final void parseParameters(@NotNull final String triggerHandle, final Str } try { if (params[0].equalsIgnoreCase("pitch")) { - this.sePitch = Math.toRadians(Double.parseDouble(params[1])); - v.sendMessage(Messages.ANGLE_AROUND_AXIS_SET.replace("%axis%", "Z").replace("%angle%", String.valueOf(this.sePitch))); - if (this.sePitch < 0 || this.sePitch > 359) { + this.pitch = Double.parseDouble(params[1]); + v.sendMessage(Messages.ANGLE_AROUND_AXIS_SET.replace("%axis%", "Z").replace("%angle%", String.valueOf(this.pitch))); + if (this.pitch < 0 || this.pitch > 359) { v.sendMessage(Messages.INVALID_BRUSH_PARAM_ANGLE); } return; } if (params[0].equalsIgnoreCase("roll")) { - this.seRoll = Math.toRadians(Double.parseDouble(params[1])); - v.sendMessage(Messages.ANGLE_AROUND_AXIS_SET.replace("%axis%", "X").replace("%angle%", String.valueOf(this.seRoll))); - if (this.seRoll < 0 || this.seRoll > 359) { + this.roll = Double.parseDouble(params[1]); + v.sendMessage(Messages.ANGLE_AROUND_AXIS_SET.replace("%axis%", "X").replace("%angle%", String.valueOf(this.roll))); + if (this.roll < 0 || this.roll > 359) { v.sendMessage(Messages.INVALID_BRUSH_PARAM_ANGLE); } return; } if (params[0].equalsIgnoreCase("yaw")) { - this.seYaw = Math.toRadians(Double.parseDouble(params[1])); - v.sendMessage(Messages.ANGLE_AROUND_AXIS_SET.replace("%axis%", "Y").replace("%angle%", String.valueOf(this.seYaw))); - if (this.seYaw < 0 || this.seYaw > 359) { + this.yaw = Double.parseDouble(params[1]); + v.sendMessage(Messages.ANGLE_AROUND_AXIS_SET.replace("%axis%", "Y").replace("%angle%", String.valueOf(this.yaw))); + if (this.yaw < 0 || this.yaw > 359) { v.sendMessage(Messages.INVALID_BRUSH_PARAM_ANGLE); } return; } - } catch (NumberFormatException e) { - e.printStackTrace(); - } + } catch (NumberFormatException ignored) { } v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); } @@ -102,138 +95,12 @@ public HashMap> registerArgumentValues() { return argumentValues; } - private void getMatrix(final int bSize) { // only need to do once. But y needs to change + sphere - final double brushSizeSquared = Math.pow(bSize + 0.5, 2); - int brushSize = (bSize * 2) + 1; - - this.snap = new BlockWrapper[brushSize][brushSize][brushSize]; - - int sx = this.getTargetBlock().getX() - bSize; - int sz = this.getTargetBlock().getZ() - bSize; - - for (int x = 0; x < this.snap.length; x++) { - final double xSquared = Math.pow(x - bSize, 2); - sz = this.getTargetBlock().getZ() - bSize; - - for (int z = 0; z < this.snap.length; z++) { - final double zSquared = Math.pow(z - bSize, 2); - sz = this.getTargetBlock().getY() - bSize; - - for (int y = 0; y < this.snap.length; y++) { - if (xSquared + zSquared + Math.pow(y - bSize, 2) <= brushSizeSquared) { - final IBlock block = this.getWorld().getBlock(sx, sz, sz); - this.snap[x][y][z] = new BlockWrapper(block); - block.setMaterial(VoxelMaterial.AIR); - sz++; - } - } - - sz++; - } - sx++; - } - - } - - private void rotate(final int bSize, final SnipeData v) { - // basically 1) make it a sphere we are rotating in, not a cylinder - // 2) do three rotations in a row, one in each dimension, unless some dimensions are set to zero or udnefined or whatever, then skip those. - // --> Why not utilize Sniper'world new oportunities and have arrow rotate all 3, powder rotate x, goldsisc y, otherdisc z. Or something like that. Or - // we - // could just use arrow and powder and just differenciate between left and right click that gis 4 different situations - // --> Well, there would be 7 different possibilities... X, Y, Z, XY, XZ, YZ, XYZ, and different numbers of parameters for each, so I think each having - // and item is too confusing. How about this: arrow = rotate one dimension, based on the face you click, and takes 1 param... powder: rotates all three - // at once, and takes 3 params. - final double brushSizeSquared = Math.pow(bSize + 0.5, 2); - final double cosYaw = Math.cos(this.seYaw); - final double sinYaw = Math.sin(this.seYaw); - final double cosPitch = Math.cos(this.sePitch); - final double sinPitch = Math.sin(this.sePitch); - final double cosRoll = Math.cos(this.seRoll); - final double sinRoll = Math.sin(this.seRoll); - final boolean[][][] doNotFill = new boolean[this.snap.length][this.snap.length][this.snap.length]; - final Undo undo = new Undo(); - - for (int x = 0; x < this.snap.length; x++) { - final int xx = x - bSize; - final double xSquared = Math.pow(xx, 2); - - for (int z = 0; z < this.snap.length; z++) { - final int zz = z - bSize; - final double zSquared = Math.pow(zz, 2); - final double newxzX = (xx * cosYaw) - (zz * sinYaw); - final double newxzZ = (xx * sinYaw) + (zz * cosYaw); - - for (int y = 0; y < this.snap.length; y++) { - final int yy = y - bSize; - if (xSquared + zSquared + Math.pow(yy, 2) <= brushSizeSquared) { - undo.put(this.getWorld().getBlock(this.getTargetBlock().getX() + xx, this.getTargetBlock().getY() + yy, this.getTargetBlock().getZ() + zz)); // just store - // whole sphere in undo, too complicated otherwise, since this brush both adds and remos things unpredictably. - - final double newxyX = (newxzX * cosPitch) - (yy * sinPitch); - final double newxyY = (newxzX * sinPitch) + (yy * cosPitch); // calculates all three in succession in precise math space - final double newyzY = (newxyY * cosRoll) - (newxzZ * sinRoll); - final double newyzZ = (newxyY * sinRoll) + (newxzZ * cosRoll); - - doNotFill[(int) newxyX + bSize][(int) newyzY + bSize][(int) newyzZ + bSize] = true; // only rounds off to nearest - // block - // after all three, though. - - final BlockWrapper block = this.snap[x][y][z]; - if (block.getMaterial().isAir()) { - continue; - } - this.getWorld().getBlock(this.getTargetBlock().getX() + (int) newxyX, this.getTargetBlock().getY() + (int) newyzY, this.getTargetBlock().getZ() + (int) newyzZ).setBlockData(block.getBlockData()); - } - } - } - } - - for (int x = 0; x < this.snap.length; x++) { - final double xSquared = Math.pow(x - bSize, 2); - final int fx = x + this.getTargetBlock().getX() - bSize; - - for (int z = 0; z < this.snap.length; z++) { - final double zSquared = Math.pow(z - bSize, 2); - final int fz = z + this.getTargetBlock().getZ() - bSize; - - for (int y = 0; y < this.snap.length; y++) { - if (xSquared + zSquared + Math.pow(y - bSize, 2) <= brushSizeSquared) { - if (!doNotFill[x][y][z]) { - // smart fill stuff - final int fy = y + this.getTargetBlock().getY() - bSize; - final IBlockData a = this.getBlockDataAt(fx + 1, fy, fz); - final IBlockData d = this.getBlockDataAt(fx - 1, fy, fz); - final IBlockData c = this.getBlockDataAt(fx, fy, fz + 1); - final IBlockData b = this.getBlockDataAt(fx, fy, fz - 1); - - IBlockData winner; - - if (a.getMaterial() == b.getMaterial() || a.getMaterial() == c.getMaterial() || a.getMaterial() == d.getMaterial()) { // 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; - } else if (b == d || c == d) { - winner = d; - } else { - winner = b; // blockPositionY making this default, it will also automatically cover situations where B = C; - } - - this.getWorld().getBlock(fx, fy, fz).setBlockData(winner); - } - } - } - } - } - v.owner().storeUndo(undo); - } - @Override protected final void arrow(final SnipeData v) { int bSize = v.getBrushSize(); - this.getMatrix(bSize); - this.rotate(bSize, v); + var ball = Shapes.ball(getTargetBlock().getLocation(), bSize, true); + this.addOperations(Actions.rotate3D(getTargetBlock(), ball, this.roll, this.yaw, this.pitch)); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java index c0f55b75..f4ebbde9 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java @@ -2,6 +2,7 @@ import com.github.kevindagame.snipe.SnipeData; import com.github.kevindagame.util.Messages; +import com.github.kevindagame.util.RotationAxis; import com.github.kevindagame.util.Shapes; /** @@ -17,7 +18,7 @@ public SplatterDiscBrush() { } private void splatterDisc(final SnipeData v) { - var positions = Shapes.disc(this.getTargetBlock().getLocation(), v.getBrushSize(), false); + var positions = Shapes.disc(this.getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), false); var splat = splatter2D(v); final int brushSize = v.getBrushSize(); for (var position : positions) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Actions.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Actions.java index f173b5a1..fc69bdb6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Actions.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Actions.java @@ -1,7 +1,13 @@ package com.github.kevindagame.util; +import com.github.kevindagame.util.brushOperation.BlockOperation; +import com.github.kevindagame.voxelsniper.block.IBlock; +import com.github.kevindagame.voxelsniper.blockdata.IBlockData; import com.github.kevindagame.voxelsniper.location.BaseLocation; +import com.github.kevindagame.voxelsniper.material.VoxelMaterial; +import com.github.kevindagame.voxelsniper.world.IWorld; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -18,4 +24,45 @@ public static List checker(List locations, boolean e return locations.stream().filter(location -> (location.getBlockX() + location.getBlockY() + location.getBlockZ()) % 2 != (even ? 0 : 1)).collect(Collectors.toList()); } + + public static List rotate3D(final IBlock target, List locations, final double roll, final double yaw, final double pitch) { + // basically rotates the blocks at all the positions in the List around the target block, doing three rotations in a row, one in each dimension + + List operations = new ArrayList<>(); + final IWorld world = target.getWorld(); + + final double seYaw = Math.toRadians(yaw * -1); + final double sePitch = Math.toRadians(pitch * -1); + final double seRoll = Math.toRadians(roll * -1); + final double cosYaw = Math.cos(seYaw); + final double sinYaw = Math.sin(seYaw); + final double cosPitch = Math.cos(sePitch); + final double sinPitch = Math.sin(sePitch); + final double cosRoll = Math.cos(seRoll); + final double sinRoll = Math.sin(seRoll); + + for (BaseLocation newPos : locations) { + if (newPos.isInWorldHeight()) { + final int dx = newPos.getBlockX() - target.getX(); + final int dy = newPos.getBlockY() - target.getY(); + final int dz = newPos.getBlockZ() - target.getZ(); + + // calculate where we are rotating from, this is more reliable than calculating where to rotate to + final double oldxzX = (dx * cosYaw) - (dz * sinYaw); + final double oldxzZ = (dx * sinYaw) + (dz * cosYaw); + final double oldxyY = (oldxzX * sinPitch) + (dy * cosPitch); + final int oldX = target.getX() + (int) Math.round((oldxzX * cosPitch) - (dy * sinPitch)); + final int oldY = target.getY() + (int) Math.round((oldxyY * cosRoll) - (oldxzZ * sinRoll)); + final int oldZ = target.getZ() + (int) Math.round((oldxyY * sinRoll) + (oldxzZ * cosRoll)); + + final IBlockData oldPosBlockData = world.isInWorldHeight(oldY) ? world.getBlock(oldX, oldY, oldZ).getBlockData() : VoxelMaterial.AIR.createBlockData(); + final IBlockData newPosBlockData = newPos.getBlock().getBlockData(); + + if (!newPosBlockData.matches(oldPosBlockData)) + operations.add(new BlockOperation(newPos, newPosBlockData, oldPosBlockData)); + } + } + + return operations; + } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/RotationAxis.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/RotationAxis.kt new file mode 100644 index 00000000..f2711d97 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/RotationAxis.kt @@ -0,0 +1,12 @@ +package com.github.kevindagame.util + +import com.github.kevindagame.voxelsniper.location.VoxelLocation +import com.github.kevindagame.voxelsniper.world.IWorld + +enum class RotationAxis(val locationTranslator: Function4) { + X({world: IWorld, w: Int, h: Int, d: Int -> VoxelLocation(world, h, w, d) }), + Y({world: IWorld, w: Int, h: Int, d: Int -> VoxelLocation(world, w, h, d) }), + Z({world: IWorld, w: Int, h: Int, d: Int -> VoxelLocation(world, w, d, h) }) + + +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Shapes.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Shapes.java index 9bf28463..f64175a6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Shapes.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Shapes.java @@ -4,6 +4,7 @@ import com.github.kevindagame.voxelsniper.block.BlockFace; import com.github.kevindagame.voxelsniper.block.IBlock; import com.github.kevindagame.voxelsniper.location.BaseLocation; +import com.github.kevindagame.voxelsniper.location.VoxelLocation; import com.github.kevindagame.voxelsniper.vector.VoxelVector; import com.github.kevindagame.voxelsniper.world.IWorld; @@ -51,18 +52,19 @@ public static List voxel(BaseLocation location, int brushSize) { return positions; } - public static List disc(BaseLocation location, int brushSize, boolean smooth) { + public static List disc(BaseLocation centerPoint, RotationAxis axis, int brushSize, boolean smooth) { List positions = new ArrayList<>(); final double radiusSquared = (brushSize + (smooth ? SMOOTH_CIRCLE_VALUE : VOXEL_CIRCLE_VALUE)) * (brushSize + (smooth ? SMOOTH_CIRCLE_VALUE : VOXEL_CIRCLE_VALUE)); - final VoxelVector centerPoint = location.toVector(); - final VoxelVector currentPoint = centerPoint.clone(); + final VoxelLocation currentPoint = centerPoint.makeMutable(); for (int x = -brushSize; x <= brushSize; x++) { currentPoint.setX(centerPoint.getX() + x); for (int z = -brushSize; z <= brushSize; z++) { currentPoint.setZ(centerPoint.getZ() + z); if (centerPoint.distanceSquared(currentPoint) <= radiusSquared) { - positions.add(new BaseLocation(location.getWorld(), currentPoint.getBlockX(), currentPoint.getBlockY(), currentPoint.getBlockZ())); + var pos = axis.getLocationTranslator().invoke(centerPoint.getWorld(), x, 0, z); + pos.add(centerPoint); + positions.add(pos.makeImmutable()); } } } @@ -79,16 +81,18 @@ public static List voxelDisc(BaseLocation location, int brushSize) return positions; } - public static List cylinder(BaseLocation location, int brushSize, int height, int shift, boolean smooth) { + public static List cylinder(BaseLocation centerPoint, RotationAxis axis, int brushSize, int height, int shift, boolean smooth) { List positions = new ArrayList<>(); for (int y = 0; y < height; y++) { - positions.addAll(disc(new BaseLocation(location.getWorld(), location.getX(), location.getY() + y - (height / 2.0) + 1 + shift, location.getZ()), brushSize, smooth)); + var pos = axis.getLocationTranslator().invoke(centerPoint.getWorld(), 0, (int) (y - (height / 2.0) + 1 + shift), 0); + pos.add(centerPoint); + positions.addAll(disc(pos, axis, brushSize, smooth)); } return positions; } public static List discFace(BaseLocation location, int brushSize, boolean smooth, BlockFace face) { - List disc = disc(location, brushSize, smooth); + List disc = disc(location, RotationAxis.Y, brushSize, smooth); return face(location, disc, face); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/BaseLocation.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/BaseLocation.java index f381db1a..c45c6bec 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/BaseLocation.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/BaseLocation.java @@ -77,6 +77,10 @@ public final IWorld getWorld() { return this.world; } + public final boolean isInWorldHeight() { + return this.world.isInWorldHeight(this.getBlockY()); + } + @Override public BaseLocation clone() { try { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/VoxelLocation.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/VoxelLocation.java index 581a00c5..206ccf62 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/VoxelLocation.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/location/VoxelLocation.java @@ -13,6 +13,10 @@ public VoxelLocation(IWorld world, double x, double y, double z) { super(world, x, y, z); } + public VoxelLocation(IWorld world, int x, int y, int z) { + this(world, x, y, z, 0, 0); + } + public void setX(double x) { this.x = x; } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/world/IWorld.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/world/IWorld.java index 5f060357..56cf6c5f 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/world/IWorld.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/world/IWorld.java @@ -80,4 +80,8 @@ default List generateTree(BaseLocation location, VoxelTreeType t Iterator getBlockIterator(VoxelVector origin, VoxelVector direction, double yOffset, int maxDistance); VoxelBiome getBiome(BaseLocation location); + + default boolean isInWorldHeight(int height) { + return this.getMinWorldHeight() <= height && this.getMaxWorldHeight() >height; + } } From 3c037eff394a1a14cafceeca243414f441a1440c Mon Sep 17 00:00:00 2001 From: KevDaDev <65958288+KevinDaGame@users.noreply.github.com> Date: Fri, 17 Mar 2023 15:07:16 +0100 Subject: [PATCH 4/8] Feat/brush builder (#117) * Initial builder setup * Suggestion for using suppliers instead of classes to create brushes - this also eliminates the need for some try-catch blocks * Update brush methods, made initonce name and permission on AbstractBrush.kt * Rename .java to .kt * Removed name and permission from brushes. Now use the permission from the builder * BallBrush through PolyBrush works! * Concept for properties * Concept for property setting * Fixed unit tests * Swithced out class reference to supplier reference * Made info message for PolyBrush * Needs testing: Fixed null safety of target- and lastBlock added descriptions to javadoc * Reformatted basic brushes * Removed classes that are no longer necessary * Made setup for operations * Updated properties and operations * Improved aliases logic with vararg arguments * Added blend operation to PolyBrush * Fixed exeptions * Added command for drain brush * Restored multiple aliases * Improved getters for PolyBrush properties * Fix biome brushes * Remove classes that are no longer used * Fix duplicate positions in newPositions * Added aliases to properties. BiomeBallBrush no longer has the performer property * Update VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrush.kt Co-authored-by: Lennart99 --------- Co-authored-by: Lennart99 --- .../github/kevindagame/VoxelBrushManager.java | 454 ++++++++++++++---- .../github/kevindagame/brush/AbstractBrush.kt | 62 +-- .../github/kevindagame/brush/BallBrush.java | 81 ---- .../kevindagame/brush/BiomeBallBrush.java | 75 --- .../github/kevindagame/brush/BiomeBrush.java | 9 +- .../kevindagame/brush/BlendBallBrush.java | 44 -- .../kevindagame/brush/BlendBrushBase.java | 216 --------- .../kevindagame/brush/BlendDiscBrush.java | 50 -- .../kevindagame/brush/BlendVoxelBrush.java | 48 -- .../brush/BlendVoxelDiscBrush.java | 49 -- .../github/kevindagame/brush/BlobBrush.java | 9 +- .../kevindagame/brush/BlockResetBrush.java | 11 - .../brush/BlockResetSurfaceBrush.java | 11 - .../github/kevindagame/brush/BrushBuilder.kt | 57 +++ .../com/github/kevindagame/brush/BrushData.kt | 5 + .../brush/CheckerVoxelDiscBrush.java | 9 +- .../kevindagame/brush/CleanSnowBrush.java | 11 - .../kevindagame/brush/CloneStampBrush.java | 11 - .../github/kevindagame/brush/CometBrush.java | 11 - .../kevindagame/brush/CylinderBrush.java | 118 ----- .../github/kevindagame/brush/DiscBrush.java | 89 ---- .../kevindagame/brush/DiscFaceBrush.java | 11 - .../github/kevindagame/brush/DomeBrush.java | 12 - .../github/kevindagame/brush/DrainBrush.java | 11 - .../kevindagame/brush/EllipseBrush.java | 11 - .../kevindagame/brush/EllipsoidBrush.java | 11 - .../github/kevindagame/brush/EntityBrush.java | 11 - .../kevindagame/brush/EntityRemovalBrush.java | 6 - .../github/kevindagame/brush/EraserBrush.java | 11 - .../github/kevindagame/brush/ErodeBrush.java | 11 - .../kevindagame/brush/FillDownBrush.java | 11 - .../com/github/kevindagame/brush/IBrush.java | 65 --- .../com/github/kevindagame/brush/IBrush.kt | 56 +++ .../kevindagame/brush/JaggedLineBrush.java | 11 - .../github/kevindagame/brush/JockeyBrush.java | 11 - .../kevindagame/brush/LightningBrush.java | 11 - .../github/kevindagame/brush/LineBrush.java | 11 - .../kevindagame/brush/OverlayBrush.java | 9 +- .../kevindagame/brush/PaintingBrush.java | 11 - .../brush/RegenerateChunkBrush.java | 11 +- .../github/kevindagame/brush/RingBrush.java | 11 - .../github/kevindagame/brush/Rot2DBrush.java | 11 - .../kevindagame/brush/Rot2DvertBrush.java | 11 - .../github/kevindagame/brush/Rot3DBrush.java | 11 - .../github/kevindagame/brush/RulerBrush.java | 11 - .../kevindagame/brush/ScannerBrush.java | 11 - .../github/kevindagame/brush/SetBrush.java | 11 - .../kevindagame/brush/SignOverwriteBrush.java | 7 - .../github/kevindagame/brush/SnipeBrush.java | 11 - .../kevindagame/brush/SplatterBallBrush.java | 9 +- .../kevindagame/brush/SplatterDiscBrush.java | 9 +- .../brush/SplatterOverlayBrush.java | 9 +- .../kevindagame/brush/SplatterVoxelBrush.java | 9 +- .../brush/SplatterVoxelDiscBrush.java | 11 - .../github/kevindagame/brush/SplineBrush.java | 11 +- .../github/kevindagame/brush/StampBrush.java | 11 - .../brush/ThreePointCircleBrush.java | 9 +- .../kevindagame/brush/TreeSnipeBrush.java | 11 - .../kevindagame/brush/TriangleBrush.java | 11 - .../kevindagame/brush/UnderlayBrush.java | 11 - .../kevindagame/brush/VoltMeterBrush.java | 11 - .../github/kevindagame/brush/VoxelBrush.java | 46 -- .../kevindagame/brush/VoxelDiscBrush.java | 46 -- .../kevindagame/brush/VoxelDiscFaceBrush.java | 11 - .../github/kevindagame/brush/WarpBrush.java | 11 - .../brush/multiBlock/CanyonBrush.java | 12 - .../multiBlock/CanyonSelectionBrush.java | 12 - .../brush/multiBlock/CopyPastaBrush.java | 11 - .../brush/multiBlock/ExtrudeBrush.java | 12 - .../brush/multiBlock/FlatOceanBrush.java | 12 - .../brush/multiBlock/GenerateTreeBrush.java | 12 - .../brush/multiBlock/MoveBrush.java | 12 - .../brush/multiBlock/OceanBrush.java | 11 - .../brush/multiBlock/PullBrush.java | 9 +- .../brush/perform/BasePerformer.java | 3 +- .../brush/perform/PerformerBrush.java | 4 +- .../brush/polymorphic/PolyBrush.kt | 212 ++++++++ .../brush/polymorphic/PolyBrushBuilder.kt | 74 +++ .../brush/polymorphic/PolyBrushData.kt | 14 + .../brush/polymorphic/PolyBrushShape.kt | 39 ++ .../brush/polymorphic/PolyLocation.kt | 9 + .../brush/polymorphic/PolyOperationType.kt | 5 + .../polymorphic/operation/BlendOperation.kt | 87 ++++ .../polymorphic/operation/PolyOperation.kt | 12 + .../polymorphic/property/BiomeProperty.kt | 18 + .../polymorphic/property/BooleanProperty.kt | 11 + .../property/ExcludeAirProperty.kt | 4 + .../property/ExcludeWaterProperty.kt | 4 + .../polymorphic/property/PerformerProperty.kt | 18 + .../property/PolyPropertiesEnum.kt | 11 + .../polymorphic/property/PolyProperty.kt | 15 + .../polymorphic/property/SmoothProperty.kt | 3 + .../brush/shell/ShellBallBrush.java | 11 - .../brush/shell/ShellSetBrush.java | 11 - .../brush/shell/ShellVoxelBrush.java | 11 - .../command/VoxelBrushCommand.java | 7 +- .../command/VoxelCommandManager.java | 35 +- .../github/kevindagame/snipe/SnipeTool.java | 9 +- .../com/github/kevindagame/snipe/Sniper.java | 56 ++- .../github/kevindagame/util/BlockHelper.java | 24 +- .../com/github/kevindagame/util/Messages.java | 2 + .../src/main/kotlin/util/InitOnceProperty.kt | 25 + VoxelSniperCore/src/main/resources/lang.yml | 4 +- .../kevindagame/voxelsniper/BrushesTest.java | 58 +-- .../worldguard/WorldGuardIntegration.kt | 2 +- 105 files changed, 1201 insertions(+), 1763 deletions(-) delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BallBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBallBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBallBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBrushBase.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelDiscBrush.java create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushBuilder.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushData.kt delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.java create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelBrush.java delete mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscBrush.java create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrush.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushBuilder.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushData.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushShape.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyLocation.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyOperationType.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/BlendOperation.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/PolyOperation.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BiomeProperty.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BooleanProperty.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeAirProperty.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeWaterProperty.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PerformerProperty.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyPropertiesEnum.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyProperty.kt create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/SmoothProperty.kt create mode 100644 VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java index b74447d0..bad3d1f4 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/VoxelBrushManager.java @@ -2,10 +2,15 @@ import com.github.kevindagame.brush.*; import com.github.kevindagame.brush.multiBlock.*; +import com.github.kevindagame.brush.polymorphic.PolyBrushBuilder; +import com.github.kevindagame.brush.polymorphic.PolyBrushShape; +import com.github.kevindagame.brush.polymorphic.PolyOperationType; +import com.github.kevindagame.brush.polymorphic.operation.BlendOperation; import com.github.kevindagame.brush.shell.ShellBallBrush; import com.github.kevindagame.brush.shell.ShellSetBrush; import com.github.kevindagame.brush.shell.ShellVoxelBrush; import com.google.common.base.Preconditions; +import org.jetbrains.annotations.NotNull; import java.util.*; @@ -16,7 +21,7 @@ public class VoxelBrushManager { private static VoxelBrushManager instance = null; - private final Map> brushes = new HashMap<>(); + private final Map brushes = new HashMap<>(); public static VoxelBrushManager getInstance() { return instance; @@ -31,81 +36,81 @@ public static VoxelBrushManager initialize() { brushManager = getInstance(); } - brushManager.registerSniperBrush(BallBrush.class, "b", "ball"); - brushManager.registerSniperBrush(BiomeBrush.class, "bio", "biome"); - brushManager.registerSniperBrush(BiomeBallBrush.class, "bioball", "biomeball"); - brushManager.registerSniperBrush(BlendBallBrush.class, "bb", "blendball"); - brushManager.registerSniperBrush(BlendDiscBrush.class, "bd", "blenddisc"); - brushManager.registerSniperBrush(BlendVoxelBrush.class, "bv", "blendvoxel"); - 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"); - brushManager.registerSniperBrush(CleanSnowBrush.class, "cls", "cleansnow"); - brushManager.registerSniperBrush(CloneStampBrush.class, "cs", "clonestamp"); - brushManager.registerSniperBrush(CometBrush.class, "com", "comet"); - brushManager.registerSniperBrush(CopyPastaBrush.class, "cp", "copypasta"); - brushManager.registerSniperBrush(CylinderBrush.class, "c", "cylinder"); - brushManager.registerSniperBrush(DiscBrush.class, "d", "disc"); - brushManager.registerSniperBrush(DiscFaceBrush.class, "df", "discface"); - brushManager.registerSniperBrush(DomeBrush.class, "dome", "domebrush"); - brushManager.registerSniperBrush(DrainBrush.class, "drain"); - brushManager.registerSniperBrush(EllipseBrush.class, "el", "ellipse"); - brushManager.registerSniperBrush(EllipsoidBrush.class, "elo", "ellipsoid"); - brushManager.registerSniperBrush(EntityBrush.class, "en", "entity"); - brushManager.registerSniperBrush(EntityRemovalBrush.class, "er", "entityremoval"); - brushManager.registerSniperBrush(EraserBrush.class, "erase", "eraser"); - brushManager.registerSniperBrush(ErodeBrush.class, "e", "erode"); - brushManager.registerSniperBrush(ExtrudeBrush.class, "ex", "extrude"); - brushManager.registerSniperBrush(FillDownBrush.class, "fd", "filldown"); - brushManager.registerSniperBrush(FlatOceanBrush.class, "fo", "flatocean"); - brushManager.registerSniperBrush(GenerateTreeBrush.class, "gt", "generatetree"); - brushManager.registerSniperBrush(JaggedLineBrush.class, "j", "jagged"); - brushManager.registerSniperBrush(JockeyBrush.class, "jockey"); - brushManager.registerSniperBrush(LightningBrush.class, "light", "lightning"); - brushManager.registerSniperBrush(LineBrush.class, "l", "line"); - brushManager.registerSniperBrush(MoveBrush.class, "mv", "move"); - brushManager.registerSniperBrush(OceanBrush.class, "o", "ocean"); - brushManager.registerSniperBrush(OverlayBrush.class, "over", "overlay"); - brushManager.registerSniperBrush(PaintingBrush.class, "painting"); - brushManager.registerSniperBrush(PullBrush.class, "pull"); - brushManager.registerSniperBrush(RegenerateChunkBrush.class, "rc", "regeneratechunk"); - brushManager.registerSniperBrush(RingBrush.class, "ri", "ring"); - brushManager.registerSniperBrush(RulerBrush.class, "r", "ruler"); - brushManager.registerSniperBrush(ScannerBrush.class, "sc", "scanner"); - brushManager.registerSniperBrush(SetBrush.class, "set"); - brushManager.registerSniperBrush(ShellBallBrush.class, "shb", "shellball"); - brushManager.registerSniperBrush(ShellSetBrush.class, "shs", "shellset"); - brushManager.registerSniperBrush(ShellVoxelBrush.class, "shv", "shellvoxel"); - brushManager.registerSniperBrush(SignOverwriteBrush.class, "sio", "signoverwriter"); - brushManager.registerSniperBrush(SnipeBrush.class, "s", "snipe"); - brushManager.registerSniperBrush(SplatterBallBrush.class, "sb", "splatball"); - brushManager.registerSniperBrush(SplatterDiscBrush.class, "sd", "splatdisc"); - brushManager.registerSniperBrush(SplatterOverlayBrush.class, "sover", "splatteroverlay"); - brushManager.registerSniperBrush(SplineBrush.class, "sp", "spline"); - brushManager.registerSniperBrush(SplatterVoxelBrush.class, "sv", "splattervoxel"); - brushManager.registerSniperBrush(SplatterDiscBrush.class, "svd", "splatvoxeldisc"); - brushManager.registerSniperBrush(SplineBrush.class, "sp", "spline"); - brushManager.registerSniperBrush(ThreePointCircleBrush.class, "tpc", "threepointcircle"); - brushManager.registerSniperBrush(TreeSnipeBrush.class, "t", "tree", "treesnipe"); - brushManager.registerSniperBrush(TriangleBrush.class, "tri", "triangle"); - brushManager.registerSniperBrush(UnderlayBrush.class, "under", "underlay"); - brushManager.registerSniperBrush(VoltMeterBrush.class, "volt", "voltmeter"); - brushManager.registerSniperBrush(VoxelBrush.class, "v", "voxel"); - brushManager.registerSniperBrush(VoxelDiscBrush.class, "vd", "voxeldisc"); - brushManager.registerSniperBrush(VoxelDiscFaceBrush.class, "vdf", "voxeldiscface"); - brushManager.registerSniperBrush(WarpBrush.class, "w", "warp"); + brushManager.registerSniperBrush(ballBrush()); + brushManager.registerSniperBrush(biomeBrush()); + brushManager.registerSniperBrush(biomeBallBrush()); + brushManager.registerSniperBrush(blendBallBrush()); + brushManager.registerSniperBrush(blendDiscBrush()); + brushManager.registerSniperBrush(blendVoxelBrush()); + brushManager.registerSniperBrush(blendVoxelDiscBrush()); + brushManager.registerSniperBrush(blobBrush()); + brushManager.registerSniperBrush(blockResetBrush()); + brushManager.registerSniperBrush(blockResetSurfaceBrush()); + brushManager.registerSniperBrush(canyonBrush()); + brushManager.registerSniperBrush(canyonSelectionBrush()); + brushManager.registerSniperBrush(checkerVoxelDiscBrush()); + brushManager.registerSniperBrush(cleanSnowBrush()); + brushManager.registerSniperBrush(cloneStampBrush()); + brushManager.registerSniperBrush(cometBrush()); + brushManager.registerSniperBrush(copyPastaBrush()); + brushManager.registerSniperBrush(cylinderBrush()); + brushManager.registerSniperBrush(discBrush()); + brushManager.registerSniperBrush(discFaceBrush()); + brushManager.registerSniperBrush(domeBrush()); + brushManager.registerSniperBrush(drainBrush()); + brushManager.registerSniperBrush(ellipseBrush()); + brushManager.registerSniperBrush(ellipsoidBrush()); + brushManager.registerSniperBrush(entityBrush()); + brushManager.registerSniperBrush(entityRemovalBrush()); + brushManager.registerSniperBrush(eraserBrush()); + brushManager.registerSniperBrush(erodeBrush()); + brushManager.registerSniperBrush(extrudeBrush()); + brushManager.registerSniperBrush(fillDownBrush()); + brushManager.registerSniperBrush(flatOceanBrush()); + brushManager.registerSniperBrush(generateTreeBrush()); + brushManager.registerSniperBrush(jaggedLineBrush()); + brushManager.registerSniperBrush(jockeyBrush()); + brushManager.registerSniperBrush(lightningBrush()); + brushManager.registerSniperBrush(lineBrush()); + brushManager.registerSniperBrush(moveBrush()); + brushManager.registerSniperBrush(oceanBrush()); + brushManager.registerSniperBrush(overlayBrush()); + brushManager.registerSniperBrush(paintingBrush()); + brushManager.registerSniperBrush(pullBrush()); + brushManager.registerSniperBrush(regenerateChunkBrush()); + brushManager.registerSniperBrush(ringBrush()); + brushManager.registerSniperBrush(rulerBrush()); + brushManager.registerSniperBrush(scannerBrush()); + brushManager.registerSniperBrush(setBrush()); + brushManager.registerSniperBrush(shellBallBrush()); + brushManager.registerSniperBrush(shellSetBrush()); + brushManager.registerSniperBrush(shellVoxelBrush()); + brushManager.registerSniperBrush(signOverwriteBrush()); + brushManager.registerSniperBrush(snipeBrush()); + brushManager.registerSniperBrush(splatterBallBrush()); + brushManager.registerSniperBrush(splatterDiscBrush()); + brushManager.registerSniperBrush(splatterOverlayBrush()); + brushManager.registerSniperBrush(splineBrush()); + brushManager.registerSniperBrush(splatterVoxelBrush()); + brushManager.registerSniperBrush(splatterVoxelDiscBrush()); + brushManager.registerSniperBrush(threePointCircleBrush()); + brushManager.registerSniperBrush(treeSnipeBrush()); + brushManager.registerSniperBrush(triangleBrush()); + brushManager.registerSniperBrush(underlayBrush()); + brushManager.registerSniperBrush(voltMeterBrush()); + brushManager.registerSniperBrush(voxelBrush()); + brushManager.registerSniperBrush(voxelDiscBrush()); + brushManager.registerSniperBrush(voxelDiscFaceBrush()); + brushManager.registerSniperBrush(warpBrush()); + + brushManager.registerSniperBrush(rot2DBrush()); + brushManager.registerSniperBrush(rot2DVertBrush()); + brushManager.registerSniperBrush(rot3DBrush()); //these brushes are currently removed/broken //brushManager.registerSniperBrush(StencilBrush.class, "st", "stencil"); //brushManager.registerSniperBrush(StencilListBrush.class, "sl", "stencillist"); - brushManager.registerSniperBrush(Rot2DBrush.class, "rot2", "rotation2d"); - brushManager.registerSniperBrush(Rot2DvertBrush.class, "rot2v", "rotation2dvertical"); - brushManager.registerSniperBrush(Rot3DBrush.class, "rot3", "rotation3d"); //these brushes have an unknown status @@ -115,16 +120,294 @@ public static VoxelBrushManager initialize() { return getInstance(); } + + // region + private static BrushData ballBrush() { + return new PolyBrushBuilder().name("Ball").alias("b", "ball").permission("voxelsniper.brush.ball").shape(PolyBrushShape.BALL).build(); + } + + private static BrushData biomeBrush() { + return new BrushBuilder().name("Biome").alias("bio", "biome").setSupplier(BiomeBrush::new).setPermission("voxelsniper.brush.biome").build(); + } + + private static BrushData biomeBallBrush() { + return new PolyBrushBuilder().name("Biomeball").alias("bioball", "biomeball").permission("voxelsniper.brush.biomeball").operationType(PolyOperationType.BIOME).shape(PolyBrushShape.BALL).build(); + } + + private static BrushData blendBallBrush() { + return new PolyBrushBuilder().name("Blendball").alias("bb", "blendball").shape(PolyBrushShape.BALL).operation(BlendOperation::new).permission("voxelsniper.brush.blendball").build(); + } + + private static BrushData blendDiscBrush() { + return new PolyBrushBuilder().name("Blenddisc").alias("bd", "blenddisc").shape(PolyBrushShape.DISC).operation(BlendOperation::new).permission("voxelsniper.brush.blenddisc").build(); + } + + private static BrushData blendVoxelBrush() { + return new PolyBrushBuilder().name("Blendvoxel").alias("bv", "blendvoxel").shape(PolyBrushShape.VOXEL).operation(BlendOperation::new).permission("voxelsniper.brush.blendvoxel").build(); + } + + private static BrushData blendVoxelDiscBrush() { + return new PolyBrushBuilder().name("Blendvoxeldisc").alias("bvd", "blendvoxeldisc").shape(PolyBrushShape.VOXEL_DISC).operation(BlendOperation::new).permission("voxelsniper.brush.blendvoxeldisc").build(); + } + + private static BrushData blobBrush() { + return new BrushBuilder().name("Splatblob").alias("blob", "splatblob").setSupplier(BlobBrush::new).setPermission("voxelsniper.brush.splatblob").build(); + } + + private static BrushData blockResetBrush() { + return new BrushBuilder().name("Blockresetbrush").alias("brb", "blockresetbrush").setSupplier(BlockResetBrush::new).setPermission("voxelsniper.brush.blockresetbrush").build(); + } + + private static BrushData blockResetSurfaceBrush() { + return new BrushBuilder().name("Blockresetbrushsurface").alias("brbs", "blockresetbrushsurface").setSupplier(BlockResetSurfaceBrush::new).setPermission("voxelsniper.brush.blockresetbrushsurface").build(); + } + + private static BrushData canyonBrush() { + return new BrushBuilder().name("Canyon").alias("ca", "canyon").setSupplier(CanyonBrush::new).setPermission("voxelsniper.brush.canyon").build(); + } + + private static BrushData canyonSelectionBrush() { + return new BrushBuilder().name("Canyonselection").alias("cas", "canyonselection").setSupplier(CanyonSelectionBrush::new).setPermission("voxelsniper.brush.canyonselection").build(); + } + + private static BrushData checkerVoxelDiscBrush() { + return new BrushBuilder().name("Checkervoxeldisc").alias("cvd", "checkervoxeldisc").setSupplier(CheckerVoxelDiscBrush::new).setPermission("voxelsniper.brush.checkervoxeldisc").build(); + } + + private static BrushData cleanSnowBrush() { + return new BrushBuilder().name("Cleansnow").alias("cls", "cleansnow").setSupplier(CleanSnowBrush::new).setPermission("voxelsniper.brush.cleansnow").build(); + } + + private static BrushData cloneStampBrush() { + return new BrushBuilder().name("Clonestamp").alias("cs", "clonestamp").setSupplier(CloneStampBrush::new).setPermission("voxelsniper.brush.clonestamp").build(); + } + + private static BrushData cometBrush() { + return new BrushBuilder().name("Comet").alias("com", "comet").setSupplier(CometBrush::new).setPermission("voxelsniper.brush.comet").build(); + } + + private static BrushData copyPastaBrush() { + return new BrushBuilder().name("Copypasta").alias("cp", "copypasta").setSupplier(CopyPastaBrush::new).setPermission("voxelsniper.brush.copypasta").build(); + } + + private static BrushData cylinderBrush() { + return new PolyBrushBuilder().name("Cylinder").alias("c", "cylinder").permission("voxelsniper.brush.cylinder").shape(PolyBrushShape.CYLINDER).build(); + } + + private static BrushData discBrush() { + return new PolyBrushBuilder().name("Disc").alias("d", "disc").shape(PolyBrushShape.DISC).permission("voxelsniper.brush.disc").build(); + } + + private static BrushData discFaceBrush() { + return new BrushBuilder().name("Discface").alias("df", "discface").setSupplier(DiscFaceBrush::new).setPermission("voxelsniper.brush.discface").build(); + } + + private static BrushData domeBrush() { + return new BrushBuilder().name("Domebrush").alias("dome", "domebrush").setSupplier(DomeBrush::new).setPermission("voxelsniper.brush.domebrush").build(); + } + + private static BrushData drainBrush() { + return new BrushBuilder().name("drain").alias("drain").setSupplier(DrainBrush::new).setPermission("voxelsniper.brush.drain").build(); + } + + private static BrushData ellipseBrush() { + return new BrushBuilder().name("Ellipse").alias("el", "ellipse").setSupplier(EllipseBrush::new).setPermission("voxelsniper.brush.ellipse").build(); + } + + private static BrushData ellipsoidBrush() { + return new BrushBuilder().name("Ellipsoid").alias("elo", "ellipsoid").setSupplier(EllipsoidBrush::new).setPermission("voxelsniper.brush.ellipsoid").build(); + } + + private static BrushData entityBrush() { + return new BrushBuilder().name("Entity").alias("en", "entity").setSupplier(EntityBrush::new).setPermission("voxelsniper.brush.entity").build(); + } + + private static BrushData entityRemovalBrush() { + return new BrushBuilder().name("Entityremoval").alias("er", "entityremoval").setSupplier(EntityRemovalBrush::new).setPermission("voxelsniper.brush.entityremoval").build(); + } + + private static BrushData eraserBrush() { + return new BrushBuilder().name("Eraser").alias("erase", "eraser").setSupplier(EraserBrush::new).setPermission("voxelsniper.brush.eraser").build(); + } + + private static BrushData erodeBrush() { + return new BrushBuilder().name("Erode").alias("e", "erode").setSupplier(ErodeBrush::new).setPermission("voxelsniper.brush.erode").build(); + } + + private static BrushData extrudeBrush() { + return new BrushBuilder().name("Extrude").alias("ex", "extrude").setSupplier(ExtrudeBrush::new).setPermission("voxelsniper.brush.extrude").build(); + } + + private static BrushData fillDownBrush() { + return new BrushBuilder().name("Filldown").alias("fd", "filldown").setSupplier(FillDownBrush::new).setPermission("voxelsniper.brush.filldown").build(); + } + + private static BrushData flatOceanBrush() { + return new BrushBuilder().name("Flatocean").alias("fo", "flatocean").setSupplier(FlatOceanBrush::new).setPermission("voxelsniper.brush.flatocean").build(); + } + + private static BrushData generateTreeBrush() { + return new BrushBuilder().name("Generatetree").alias("gt", "generatetree").setSupplier(GenerateTreeBrush::new).setPermission("voxelsniper.brush.generatetree").build(); + } + + private static BrushData jaggedLineBrush() { + return new BrushBuilder().name("Jagged").alias("j", "jagged").setSupplier(JaggedLineBrush::new).setPermission("voxelsniper.brush.jagged").build(); + } + + private static BrushData jockeyBrush() { + return new BrushBuilder().name("jockey").setSupplier(JockeyBrush::new).setPermission("voxelsniper.brush.jockey").build(); + } + + private static BrushData lightningBrush() { + return new BrushBuilder().name("Lightning").alias("light", "lightning").setSupplier(LightningBrush::new).setPermission("voxelsniper.brush.lightning").build(); + } + + private static BrushData lineBrush() { + return new BrushBuilder().name("Line").alias("l", "line").setSupplier(LineBrush::new).setPermission("voxelsniper.brush.line").build(); + } + + private static BrushData moveBrush() { + return new BrushBuilder().name("Move").alias("mv", "move").setSupplier(MoveBrush::new).setPermission("voxelsniper.brush.move").build(); + } + + private static BrushData oceanBrush() { + return new BrushBuilder().name("Ocean").alias("o", "ocean").setSupplier(OceanBrush::new).setPermission("voxelsniper.brush.ocean").build(); + } + + private static BrushData overlayBrush() { + return new BrushBuilder().name("Overlay").alias("over", "overlay").setSupplier(OverlayBrush::new).setPermission("voxelsniper.brush.overlay").build(); + } + + private static BrushData paintingBrush() { + return new BrushBuilder().name("painting").alias("painting").setSupplier(PaintingBrush::new).setPermission("voxelsniper.brush.painting").build(); + } + + private static BrushData pullBrush() { + return new BrushBuilder().name("pull").alias("pull").setSupplier(PullBrush::new).setPermission("voxelsniper.brush.pull").build(); + } + + private static BrushData regenerateChunkBrush() { + return new BrushBuilder().name("Regeneratechunk").alias("rc", "regeneratechunk").setSupplier(RegenerateChunkBrush::new).setPermission("voxelsniper.brush.regeneratechunk").build(); + } + + private static BrushData ringBrush() { + return new BrushBuilder().name("Ring").alias("ri", "ring").setSupplier(RingBrush::new).setPermission("voxelsniper.brush.ring").build(); + } + + private static BrushData rulerBrush() { + return new BrushBuilder().name("Ruler").alias("r", "ruler").setSupplier(RulerBrush::new).setPermission("voxelsniper.brush.ruler").build(); + } + + private static BrushData rot2DBrush() { + return new BrushBuilder().name("Rot2D").alias("rot2", "rotation2d").setSupplier(Rot2DBrush::new).setPermission("voxelsniper.brush.rot2d").build(); + } + + private static BrushData rot2DVertBrush() { + return new BrushBuilder().name("Rot2DVert").alias("rot2dv", "rotation2dvertical").setSupplier(Rot2DvertBrush::new).setPermission("voxelsniper.brush.rot2dvert").build(); + } + + private static BrushData rot3DBrush() { + return new BrushBuilder().name("Rot3D").alias("rot3", "rotation3d").setSupplier(Rot3DBrush::new).setPermission("voxelsniper.brush.rot3d").build(); + } + + private static BrushData scannerBrush() { + return new BrushBuilder().name("Scanner").alias("sc", "scanner").setSupplier(ScannerBrush::new).setPermission("voxelsniper.brush.scanner").build(); + } + + private static BrushData setBrush() { + return new BrushBuilder().name("set").alias("set").setSupplier(SetBrush::new).setPermission("voxelsniper.brush.set").build(); + } + + private static BrushData shellBallBrush() { + return new BrushBuilder().name("Shellball").alias("shb", "shellball").setSupplier(ShellBallBrush::new).setPermission("voxelsniper.brush.shellball").build(); + } + + private static BrushData shellSetBrush() { + return new BrushBuilder().name("Shellset").alias("shs", "shellset").setSupplier(ShellSetBrush::new).setPermission("voxelsniper.brush.shellset").build(); + } + + private static BrushData shellVoxelBrush() { + return new BrushBuilder().name("Shellvoxel").alias("shv", "shellvoxel").setSupplier(ShellVoxelBrush::new).setPermission("voxelsniper.brush.shellvoxel").build(); + } + + private static BrushData signOverwriteBrush() { + return new BrushBuilder().name("Signoverwriter").alias("sio", "signoverwriter").setSupplier(SignOverwriteBrush::new).setPermission("voxelsniper.brush.signoverwriter").build(); + } + + private static BrushData snipeBrush() { + return new BrushBuilder().name("Snipe").alias("s", "snipe").setSupplier(SnipeBrush::new).setPermission("voxelsniper.brush.snipe").build(); + } + + private static BrushData splatterBallBrush() { + return new BrushBuilder().name("Splatball").alias("sb", "splatball").setSupplier(SplatterBallBrush::new).setPermission("voxelsniper.brush.splatball").build(); + } + + private static BrushData splatterDiscBrush() { + return new BrushBuilder().name("Splatdisc").alias("sd", "splatdisc").setSupplier(SplatterDiscBrush::new).setPermission("voxelsniper.brush.splatdisc").build(); + } + + private static BrushData splatterOverlayBrush() { + return new BrushBuilder().name("Splatteroverlay").alias("sover", "splatteroverlay").setSupplier(SplatterOverlayBrush::new).setPermission("voxelsniper.brush.splatteroverlay").build(); + } + + private static BrushData splineBrush() { + return new BrushBuilder().name("Spline").alias("sp", "spline").setSupplier(SplineBrush::new).setPermission("voxelsniper.brush.spline").build(); + } + + private static BrushData splatterVoxelBrush() { + return new BrushBuilder().name("Splattervoxel").alias("sv", "splattervoxel").setSupplier(SplatterVoxelBrush::new).setPermission("voxelsniper.brush.splattervoxel").build(); + } + + private static BrushData splatterVoxelDiscBrush() { + return new BrushBuilder().name("Splatvoxeldisc").alias("svd", "splatvoxeldisc").setSupplier(SplatterVoxelDiscBrush::new).setPermission("voxelsniper.brush.splatvoxeldisc").build(); + } + + private static BrushData threePointCircleBrush() { + return new BrushBuilder().name("Threepointcircle").alias("tpc", "threepointcircle").setSupplier(ThreePointCircleBrush::new).setPermission("voxelsniper.brush.threepointcircle").build(); + } + + private static BrushData treeSnipeBrush() { + return new BrushBuilder().name("Treesnipe").alias("t", "treesnipe").setSupplier(TreeSnipeBrush::new).setPermission("voxelsniper.brush.t").build(); + } + + private static BrushData triangleBrush() { + return new BrushBuilder().name("Triangle").alias("tri", "triangle").setSupplier(TriangleBrush::new).setPermission("voxelsniper.brush.triangle").build(); + } + + private static BrushData underlayBrush() { + return new BrushBuilder().name("Underlay").alias("under", "underlay").setSupplier(UnderlayBrush::new).setPermission("voxelsniper.brush.underlay").build(); + } + + private static BrushData voltMeterBrush() { + return new BrushBuilder().name("Voltmeter").alias("volt", "voltmeter").setSupplier(VoltMeterBrush::new).setPermission("voxelsniper.brush.voltmeter").build(); + } + + private static BrushData voxelBrush() { + return new PolyBrushBuilder().name("Voxel").alias("v", "voxel").shape(PolyBrushShape.VOXEL).permission("voxelsniper.brush.voxel").build(); + } + + private static BrushData voxelDiscBrush() { + return new PolyBrushBuilder().name("Voxeldisc").alias("vd", "voxeldisc").permission("voxelsniper.brush.voxeldisc").shape(PolyBrushShape.VOXEL_DISC).build(); + + } + + private static BrushData voxelDiscFaceBrush() { + return new BrushBuilder().name("Voxeldiscface").alias("vdf", "voxeldiscface").setSupplier(VoxelDiscFaceBrush::new).setPermission("voxelsniper.brush.voxeldiscface").build(); + } + + private static BrushData warpBrush() { + return new BrushBuilder().name("Warp").alias("w", "warp").setSupplier(WarpBrush::new).setPermission("voxelsniper.brush.warp").build(); + } + //endregion + /** * Register a brush for VoxelSniper to be able to use. * - * @param clazz Brush implementing IBrush interface. - * @param handles Handles under which the brush can be accessed ingame. + * @param brushData The brush data to register. */ - public void registerSniperBrush(Class clazz, String... handles) { - Preconditions.checkNotNull(clazz, "Cannot register null as a class."); - for (String handle : handles) { - brushes.put(handle.toLowerCase(), clazz); + public void registerSniperBrush(@NotNull BrushData brushData) { + for (String handle : brushData.getAliases()) { + brushes.put(handle.toLowerCase(), brushData); } } @@ -134,7 +417,7 @@ public void registerSniperBrush(Class clazz, String... handles * @param handle Case-insensitive brush handle * @return Brush class */ - public Class getBrushForHandle(String handle) { + public BrushData getBrushForHandle(String handle) { Preconditions.checkNotNull(handle, "Brushhandle can not be null."); return brushes.get(handle.toLowerCase()); @@ -155,13 +438,13 @@ public int registeredSniperBrushHandles() { } /** - * @param clazz Brush class + * @param brushData The brush data to check. * @return All Sniper registered handles for the brush. */ - public Set getSniperBrushHandles(Class clazz) { + public Set getSniperBrushHandles(BrushData brushData) { Set handles = new HashSet<>(); for (String key : brushes.keySet()) { - if (brushes.get(key).equals(clazz)) { + if (brushes.get(key).equals(brushData)) { handles.add(key); } } @@ -171,10 +454,17 @@ public Set getSniperBrushHandles(Class clazz) { /** * @return Immutable Map copy of all the registered brushes */ - public Map> getRegisteredBrushesMap() { + public Map getRegisteredBrushesMap() { return Map.copyOf(brushes); } + /** + * @return The brush data for the default brush. + */ + public BrushData getDefaultBrush() { + return brushes.get("snipe"); + } + public List getBrushHandles() { return new ArrayList<>(brushes.keySet()); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt index 36e9012b..ed8b27aa 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/AbstractBrush.kt @@ -16,28 +16,18 @@ import com.github.kevindagame.voxelsniper.events.player.PlayerSnipeEvent import com.github.kevindagame.voxelsniper.material.VoxelMaterial import com.github.kevindagame.voxelsniper.world.IWorld import com.google.common.collect.ImmutableList -import java.util.* + /** * Abstract implementation of the [IBrush] interface. */ abstract class AbstractBrush : IBrush { - /** - * @return the targetBlock - */ - /** - * @param targetBlock the targetBlock to set - */ + /** * Targeted Block. */ - protected lateinit var targetBlock: IBlock - /** - * @return Block before target Block. - */ - /** - * @param lastBlock Last Block before target Block. - */ + lateinit var targetBlock: IBlock + /** * Last Block before targeted Block. */ @@ -51,7 +41,8 @@ abstract class AbstractBrush : IBrush { /** * Brush name. */ - private var name = "Undefined" + override var name by initOnce() + override var permissionNode: String by initOnce() protected var snipeAction: SnipeAction? = null private fun preparePerform(v: SnipeData, clickedBlock: IBlock, clickedFace: BlockFace): Boolean { @@ -150,14 +141,14 @@ abstract class AbstractBrush : IBrush { * * @param v Sniper caller */ - protected open fun arrow(v: SnipeData?) {} + protected open fun arrow(v: SnipeData) {} /** * The powder action. Executed when a player RightClicks with Gunpowder * * @param v Sniper caller */ - protected open fun powder(v: SnipeData?) {} + protected open fun powder(v: SnipeData) {} abstract override fun info(vm: VoxelMessage) override fun parseParameters(triggerHandle: String, params: Array, v: SnipeData) { v.sendMessage(Messages.BRUSH_NO_PARAMS_ACCEPTED) @@ -182,7 +173,10 @@ abstract class AbstractBrush : IBrush { * @return boolean */ protected fun getTarget(v: SnipeData, clickedBlock: IBlock?, clickedFace: BlockFace?): Boolean { - return if (clickedBlock != null) { + val targetBlock: IBlock? + val lastBlock: IBlock? + + if (clickedBlock != null) { targetBlock = clickedBlock lastBlock = clickedBlock.getRelative(clickedFace) if (lastBlock == null) { @@ -192,7 +186,6 @@ abstract class AbstractBrush : IBrush { if (v.owner().getSnipeData(v.owner().currentToolId).isLightningEnabled) { world.strikeLightning(targetBlock.location) } - true } else { val rangeBlockHelper: BlockHelper if (v.owner().getSnipeData(v.owner().currentToolId).isRanged) { @@ -203,7 +196,7 @@ abstract class AbstractBrush : IBrush { targetBlock = rangeBlockHelper.rangeBlock } else { rangeBlockHelper = BlockHelper(v.owner().player) - targetBlock = rangeBlockHelper.targetBlock + targetBlock = rangeBlockHelper.targetBlock!! } if (targetBlock != null) { lastBlock = rangeBlockHelper.lastBlock @@ -214,35 +207,22 @@ abstract class AbstractBrush : IBrush { if (v.owner().getSnipeData(v.owner().currentToolId).isLightningEnabled) { world.strikeLightning(targetBlock.location) } - true } else { v.sendMessage(Messages.TARGET_MUST_BE_VISIBLE) - false + return false } } - } - - override fun getName(): String { - return name - } - - override fun setName(name: String) { - this.name = name - } - - override fun getBrushCategory(): String { - return "General" + this.lastBlock = lastBlock + this.targetBlock = targetBlock + return true } /** * @return the world */ - protected val world: IWorld - protected get() = targetBlock.world - protected val minHeight: Int - protected get() = world.minWorldHeight - protected val maxHeight: Int - protected get() = world.maxWorldHeight + protected val world: IWorld get() = targetBlock.world + protected val minHeight: Int get() = world.minWorldHeight + protected val maxHeight: Int get() = world.maxWorldHeight protected fun isInWorldHeight(height: Int): Boolean { return world.isInWorldHeight(height) @@ -256,7 +236,7 @@ abstract class AbstractBrush : IBrush { * @param z Z coordinate * @return Type ID of Block at given coordinates in the world of the targeted Block. */ - protected fun getBlockMaterialAt(x: Int, y: Int, z: Int): VoxelMaterial { + fun getBlockMaterialAt(x: Int, y: Int, z: Int): VoxelMaterial { return if (isInWorldHeight(y)) world.getBlock(x, y, z).material else VoxelMaterial.AIR } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BallBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BallBrush.java deleted file mode 100644 index 8bd0b7ec..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BallBrush.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.brush.perform.PerformerBrush; -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.voxelsniper.block.IBlock; -import com.google.common.collect.Lists; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * A brush that creates a solid ball. ... - * - * @author Piotr - */ -public class BallBrush extends PerformerBrush { - - - private boolean smoothSphere = false; - - public BallBrush() { - this.setName("Ball"); - } - - private void ball(final SnipeData v, IBlock targetBlock) { - this.positions = Shapes.ball(targetBlock.getLocation(), v.getBrushSize(), this.smoothSphere); - } - - - @Override - protected final void doArrow(final SnipeData v) { - this.ball(v, this.getTargetBlock()); - } - - @Override - protected final void doPowder(final SnipeData v) { - this.ball(v, this.getLastBlock()); - } - - @Override - public final void info(final VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.BALLBRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - if (params[0].equalsIgnoreCase("smooth")) { - this.smoothSphere = !this.smoothSphere; - v.sendMessage(Messages.SMOOTHSPHERE_ALGORITHM.replace("%smoothSphere%", String.valueOf(this.smoothSphere))); - return; - } - - v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); - sendPerformerMessage(triggerHandle, v); - } - - - @NotNull - @Override - public List registerArguments() { - List arguments = new ArrayList<>(); - arguments.addAll(Lists.newArrayList("smooth")); - - arguments.addAll(super.registerArguments()); - return arguments; - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.ball"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBallBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBallBrush.java deleted file mode 100644 index 1f400978..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBallBrush.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.util.brushOperation.BiomeOperation; -import com.github.kevindagame.voxelsniper.biome.VoxelBiome; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -import static java.util.stream.Collectors.toList; - -/** - * ... - */ -public class BiomeBallBrush extends AbstractBrush { - - private VoxelBiome selectedBiome = VoxelBiome.PLAINS; - - public BiomeBallBrush() { - this.setName("Biome ball"); - } - - @Override - public void info(VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - vm.custom(Messages.SELECTED_BIOME_TYPE.replace("%selectedBiome%", this.selectedBiome.key())); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.biomeball"; - } - - - @Override - public void arrow(SnipeData v) { - this.biome(v); - } - - @Override - protected void powder(SnipeData v) { - this.biome(v); - } - - private void biome(final SnipeData v) { - this.addOperations(Shapes.ball(this.getTargetBlock().getLocation(), v.getBrushSize(), true).stream().map(location -> new BiomeOperation(location, getWorld().getBiome(location), this.selectedBiome)).collect(toList())); - - } - - @Override - public final void parseParameters(@NotNull final String triggerHandle, final String[] params, @NotNull final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.BIOMEBALL_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - try { - this.selectedBiome = VoxelBiome.getBiome(params[0].toLowerCase()); - v.sendMessage(Messages.SELECTED_BIOME_TYPE.replace("%selectedBiome%", this.selectedBiome.key())); - } catch (IllegalArgumentException e) { - v.sendMessage(Messages.BIOME_DOES_NOT_EXIST); - } - } - - @NotNull - @Override - public List registerArguments() { - - return VoxelBiome.BIOMES.values().stream().map(VoxelBiome::getKey).collect(toList()); - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBrush.java index 417d59e2..77854ccf 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BiomeBrush.java @@ -18,9 +18,7 @@ public class BiomeBrush extends AbstractBrush { private VoxelBiome selectedBiome = VoxelBiome.PLAINS; - public BiomeBrush() { - this.setName("Biome"); - } + private void biome(final SnipeData v) { final int brushSize = v.getBrushSize(); @@ -77,9 +75,4 @@ public List registerArguments() { return VoxelBiome.BIOMES.values().stream().map(VoxelBiome::getKey).collect(Collectors.toList()); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.biome"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBallBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBallBrush.java deleted file mode 100644 index 3157ba45..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBallBrush.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.brushOperation.BlockOperation; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; - -/** - * ... - */ -public class BlendBallBrush extends BlendBrushBase { - public BlendBallBrush() { - this.setName("Blend Ball"); - } - - @Override - protected final void blend(final SnipeData v) { - var brushSize = v.getBrushSize(); - var positions = Shapes.ball(this.getTargetBlock().getLocation(), v.getBrushSize(), false); - var newMaterials = this.blend3D(brushSize); - for (var position : positions) { - var material = newMaterials[position.getBlockX() - this.getTargetBlock().getX() + brushSize][position.getBlockY() - this.getTargetBlock().getY() + brushSize][position.getBlockZ() - this.getTargetBlock().getZ() + brushSize]; - if (!(this.excludeAir && material.isAir()) && !(this.excludeWater && (material == VoxelMaterial.WATER))) { - addOperation(new BlockOperation(position, position.getBlock().getBlockData(), material.createBlockData())); - } - } - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.BLEND_BALL_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - super.parseParameters(triggerHandle, params, v); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blendball"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBrushBase.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBrushBase.java deleted file mode 100644 index 38bbc8b0..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendBrushBase.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; -import com.google.common.collect.Lists; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Monofraps - */ -public abstract class BlendBrushBase extends AbstractBrush { - - protected boolean excludeAir = true; - protected boolean excludeWater = true; - - protected abstract void blend(SnipeData v); - - protected VoxelMaterial[][][] blend3D(int brushSize) { - final int brushSizeDoubled = 2 * brushSize; - // Array that holds the original materials plus a buffer - final VoxelMaterial[][][] oldMaterials = new VoxelMaterial[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; - // Array that holds the blended materials - final VoxelMaterial[][][] newMaterials = new VoxelMaterial[brushSizeDoubled + 1][brushSizeDoubled + 1][brushSizeDoubled + 1]; - - // Log current materials into oldmats - for (int x = 0; x <= 2 * (brushSize + 1); x++) { - for (int y = 0; y <= 2 * (brushSize + 1); y++) { - for (int z = 0; z <= 2 * (brushSize + 1); z++) { - oldMaterials[x][y][z] = this.getBlockMaterialAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY() - brushSize - 1 + y, this.getTargetBlock().getZ() - brushSize - 1 + z); - } - } - } - - // Log current materials into newmats - for (int x = 0; x <= brushSizeDoubled; x++) { - for (int y = 0; y <= brushSizeDoubled; y++) { - System.arraycopy(oldMaterials[x + 1][y + 1], 1, newMaterials[x][y], 0, brushSizeDoubled + 1); - } - } - - // Blend materials - for (int x = 0; x <= brushSizeDoubled; x++) { - for (int y = 0; y <= brushSizeDoubled; y++) { - for (int z = 0; z <= brushSizeDoubled; z++) { - Map materialFrequency = new HashMap<>(); - - boolean tiecheck = true; - - for (int m = -1; m <= 1; m++) { - for (int n = -1; n <= 1; n++) { - for (int o = -1; o <= 1; o++) { - if (!(m == 0 && n == 0 && o == 0)) { - VoxelMaterial currentMaterial = oldMaterials[x + 1 + m][y + 1 + n][z + 1 + o]; - int currentFrequency = materialFrequency.getOrDefault(currentMaterial, 0) + 1; - - materialFrequency.put(currentMaterial, currentFrequency); - } - } - } - } - - int highestMaterialCount = 0; - VoxelMaterial highestMaterial = VoxelMaterial.AIR; - - // Find most common neighbouring material - for (Map.Entry e : materialFrequency.entrySet()) { - if (e.getValue() > highestMaterialCount && !(this.excludeAir && e.getKey().isAir()) && !(this.excludeWater && e.getKey() == VoxelMaterial.WATER)) { - highestMaterialCount = e.getValue(); - highestMaterial = e.getKey(); - } - } - - // Make sure that there's no tie in highest material - for (Map.Entry e : materialFrequency.entrySet()) { - if (e.getValue() == highestMaterialCount && !(this.excludeAir && e.getKey().isAir()) && !(this.excludeWater && e.getKey() == VoxelMaterial.WATER)) { - if (e.getKey() == highestMaterial) { - continue; - } - tiecheck = false; - } - } - - // Record most common neighbor material for this block - if (tiecheck) { - newMaterials[x][y][z] = highestMaterial; - } - } - } - } - return newMaterials; - } - - protected VoxelMaterial[][] blend2D(int brushSize) { - final int brushSizeDoubled = 2 * brushSize; - final VoxelMaterial[][] oldMaterials = new VoxelMaterial[2 * (brushSize + 1) + 1][2 * (brushSize + 1) + 1]; // Array that holds the original materials plus a buffer - final VoxelMaterial[][] newMaterials = new VoxelMaterial[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.getBlockMaterialAt(this.getTargetBlock().getX() - brushSize - 1 + x, this.getTargetBlock().getY(), this.getTargetBlock().getZ() - brushSize - 1 + z); - } - } - - // Log current materials into newmats - for (int x = 0; x <= brushSizeDoubled; x++) { - System.arraycopy(oldMaterials[x + 1], 1, newMaterials[x], 0, brushSizeDoubled + 1); - } - - // Blend materials - for (int x = 0; x <= brushSizeDoubled; x++) { - for (int z = 0; z <= brushSizeDoubled; z++) { - Map materialFrequency = new HashMap<>(); - - boolean tiecheck = true; - - for (int m = -1; m <= 1; m++) { - for (int n = -1; n <= 1; n++) { - if (!(m == 0 && n == 0)) { - VoxelMaterial currentMaterial = oldMaterials[x + 1 + m][z + 1 + n]; - int currentFrequency = materialFrequency.getOrDefault(currentMaterial, 0) + 1; - - materialFrequency.put(currentMaterial, currentFrequency); - } - } - } - - int highestMaterialCount = 0; - VoxelMaterial highestMaterial = VoxelMaterial.AIR; - - // Find most common neighboring material. - for (Map.Entry e : materialFrequency.entrySet()) { - if (e.getValue() > highestMaterialCount && !(this.excludeAir && e.getKey().isAir()) && !(this.excludeWater && e.getKey() == VoxelMaterial.WATER)) { - highestMaterialCount = e.getValue(); - highestMaterial = e.getKey(); - } - } - - // Make sure that there's no tie in highest material - for (Map.Entry e : materialFrequency.entrySet()) { - if (e.getValue() == highestMaterialCount && !(this.excludeAir && e.getKey().isAir()) && !(this.excludeWater && e.getKey() == VoxelMaterial.WATER)) { - if (e.getKey() == highestMaterial) { - continue; - } - tiecheck = false; - } - } - - // Record most common neighbor material for this block - if (tiecheck) { - newMaterials[x][z] = highestMaterial; - } - } - } - return newMaterials; - } - - @Override - protected final void arrow(final SnipeData v) { - this.excludeAir = false; - this.blend(v); - } - - @Override - protected final void powder(final SnipeData v) { - this.excludeAir = true; - this.blend(v); - } - - @Override - public final void info(final VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - vm.voxel(); - vm.custom(Messages.BLEND_BRUSH_WATER_MODE.replace("%excludeWater%", (this.excludeWater ? "exclude" : "include"))); - } - - @Override - public void parseParameters(@NotNull final String triggerHandle, final String[] params, @NotNull final SnipeData v) { - if (params[0].equalsIgnoreCase("water")) { - if (params.length >= 2) { - this.excludeWater = !Boolean.parseBoolean(params[1].toLowerCase()); - } else { - this.excludeWater = !this.excludeWater; - } - v.sendMessage(Messages.BLEND_BRUSH_WATER_MODE.replace("%excludeWater%", (this.excludeWater ? "exclude" : "include"))); - return; - } - - v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); - } - - @NotNull - @Override - public List registerArguments() { - return new ArrayList<>(Lists.newArrayList("water")); - } - - @NotNull - @Override - public HashMap> registerArgumentValues() { - HashMap> argumentValues = new HashMap<>(); - - - argumentValues.put("water", Lists.newArrayList("true", "false")); - - return argumentValues; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java deleted file mode 100644 index 91d7a7a5..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendDiscBrush.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.RotationAxis; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.brushOperation.BlockOperation; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; - -/** - * ... - */ -public class BlendDiscBrush extends BlendBrushBase { - - /** - * - */ - public BlendDiscBrush() { - this.setName("Blend Disc"); - } - - @Override - protected final void blend(final SnipeData v) { - var positions = Shapes.disc(this.getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), false); - var brushSize = v.getBrushSize(); - var newMaterials = this.blend2D(brushSize); - - for (var position : positions) { - var material = newMaterials[position.getBlockX() - this.getTargetBlock().getX() + brushSize][position.getBlockZ() - this.getTargetBlock().getZ() + brushSize]; - if (!(this.excludeAir && material.isAir()) && !(this.excludeWater && (material == VoxelMaterial.WATER))) { - addOperation(new BlockOperation(position, position.getBlock().getBlockData(), material.createBlockData())); - } - } - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.BLEND_DISC_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - super.parseParameters(triggerHandle, params, v); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blenddisc"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelBrush.java deleted file mode 100644 index 3ad5a107..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelBrush.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.brushOperation.BlockOperation; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; - -/** - * ... - */ -public class BlendVoxelBrush extends BlendBrushBase { - - /** - * - */ - public BlendVoxelBrush() { - this.setName("Blend Voxel"); - } - - @Override - protected final void blend(final SnipeData v) { - var brushSize = v.getBrushSize(); - var positions = Shapes.voxel(this.getTargetBlock().getLocation(), v.getBrushSize()); - var newMaterials = this.blend3D(brushSize); - for (var position : positions) { - var material = newMaterials[position.getBlockX() - this.getTargetBlock().getX() + brushSize][position.getBlockY() - this.getTargetBlock().getY() + brushSize][position.getBlockZ() - this.getTargetBlock().getZ() + brushSize]; - if (!(this.excludeAir && material.isAir()) && !(this.excludeWater && (material == VoxelMaterial.WATER))) { - addOperation(new BlockOperation(position, position.getBlock().getBlockData(), material.createBlockData())); - } - } - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.BLEND_VOXEL_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - super.parseParameters(triggerHandle, params, v); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blendvoxel"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelDiscBrush.java deleted file mode 100644 index 5ecb5571..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlendVoxelDiscBrush.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.brushOperation.BlockOperation; -import com.github.kevindagame.voxelsniper.material.VoxelMaterial; - -/** - * ... - */ -public class BlendVoxelDiscBrush extends BlendBrushBase { - - /** - * - */ - public BlendVoxelDiscBrush() { - this.setName("Blend Voxel Disc"); - } - - @Override - protected final void blend(final SnipeData v) { - var positions = Shapes.voxelDisc(this.getTargetBlock().getLocation(), v.getBrushSize()); - var brushSize = v.getBrushSize(); - var newMaterials = this.blend2D(brushSize); - - for (var position : positions) { - var material = newMaterials[position.getBlockX() - this.getTargetBlock().getX() + brushSize][position.getBlockZ() - this.getTargetBlock().getZ() + brushSize]; - if (!(this.excludeAir && material.isAir()) && !(this.excludeWater && (material == VoxelMaterial.WATER))) { - addOperation(new BlockOperation(position, position.getBlock().getBlockData(), material.createBlockData())); - } - } - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.BALL_BLEND_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - super.parseParameters(triggerHandle, params, v); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blendvoxeldisc"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlobBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlobBrush.java index 062e779f..fa2f54a3 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlobBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlobBrush.java @@ -27,9 +27,7 @@ public class BlobBrush extends PerformerBrush { private final Random randomGenerator = new Random(); private int growPercent = GROW_PERCENT_DEFAULT; // chance block on recursion pass is made active - public BlobBrush() { - this.setName("Blob"); - } + private void checkValidGrowPercent(final SnipeData v) { if (this.growPercent < GROW_PERCENT_MIN || this.growPercent > GROW_PERCENT_MAX) { @@ -274,9 +272,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blob"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetBrush.java index f889fd6e..aab740d6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetBrush.java @@ -48,12 +48,6 @@ public class BlockResetBrush extends AbstractBrush { BlockResetBrush.DENIED_UPDATES.add(VoxelMaterial.OAK_FENCE_GATE); } - /** - * - */ - public BlockResetBrush() { - this.setName("Block Reset Brush"); - } private void applyBrush(final SnipeData v) { addOperations(Shapes.voxel(this.getTargetBlock().getLocation(), v.getBrushSize()).stream().map(BaseLocation::getBlock) @@ -74,9 +68,4 @@ protected final void powder(final SnipeData v) { public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blockreset"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetSurfaceBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetSurfaceBrush.java index 3d34b3c3..dca80b70 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetSurfaceBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BlockResetSurfaceBrush.java @@ -63,12 +63,6 @@ public class BlockResetSurfaceBrush extends AbstractBrush { BlockResetSurfaceBrush.DENIED_UPDATES.add(VoxelMaterial.CAVE_AIR); } - /** - * - */ - public BlockResetSurfaceBrush() { - this.setName("Block Reset Brush Surface Only"); - } private void applyBrush(final SnipeData v) { final IWorld world = this.getWorld(); @@ -129,9 +123,4 @@ protected final void powder(final SnipeData v) { public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.blockresetsurface"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushBuilder.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushBuilder.kt new file mode 100644 index 00000000..571f07df --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushBuilder.kt @@ -0,0 +1,57 @@ +package com.github.kevindagame.brush + +import java.util.* +import java.util.function.Supplier + +/** + * Builder class for (old) brushes + */ +class BrushBuilder { + private lateinit var name: String + private lateinit var permission: String + private val aliases: MutableList = mutableListOf() + private lateinit var supplier: Supplier + + /** + * Sets the name of the brush. + */ + fun name(name: String): BrushBuilder + { + this.name = name + return this + } + + /** + * Add aliases for the brush. + */ + fun alias(vararg aliases: String): BrushBuilder + { + this.aliases.addAll(aliases) + return this + } + + /** + * Sets the permission of the brush. + */ + fun setPermission(permission: String): BrushBuilder + { + this.permission = permission + return this + } + + /** + * Sets the class of the brush. + */ + fun setSupplier(supplier: Supplier): BrushBuilder + { + this.supplier = supplier + return this + } + + fun build(): BrushData { + if(!::permission.isInitialized) { + permission = "voxelsniper.brush.${name.lowercase(Locale.getDefault())}" + } + return BrushData(name, permission, aliases, supplier) + } +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushData.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushData.kt new file mode 100644 index 00000000..21929f9f --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/BrushData.kt @@ -0,0 +1,5 @@ +package com.github.kevindagame.brush + +import java.util.function.Supplier + +open class BrushData(val name: String, val permission: String, val aliases: MutableList, var supplier: Supplier) diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CheckerVoxelDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CheckerVoxelDiscBrush.java index 399812eb..14f10586 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CheckerVoxelDiscBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CheckerVoxelDiscBrush.java @@ -23,9 +23,7 @@ public class CheckerVoxelDiscBrush extends PerformerBrush { /** * Default constructor. */ - public CheckerVoxelDiscBrush() { - this.setName("Checker Voxel Disc"); - } + /** * @param v @@ -77,9 +75,4 @@ public List registerArguments() { arguments.addAll(super.registerArguments()); return arguments; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.checkervoxeldisc"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CleanSnowBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CleanSnowBrush.java index 0e6a0014..53618ebc 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CleanSnowBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CleanSnowBrush.java @@ -23,12 +23,6 @@ public class CleanSnowBrush extends AbstractBrush { private boolean smoothSphere = false; - /** - * - */ - public CleanSnowBrush() { - this.setName("Clean Snow"); - } private void cleanSnow(final SnipeData v) { var positions = Shapes.ball(this.getTargetBlock().getLocation(), v.getBrushSize(), smoothSphere); @@ -79,9 +73,4 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("smooth")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.cleansnow"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java index d9226cd7..b932db30 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CloneStampBrush.java @@ -24,12 +24,6 @@ public class CloneStampBrush extends StampBrush { private BaseLocation startingPoint; - /** - * - */ - public CloneStampBrush() { - this.setName("Clone"); - } /** * The clone method is used to grab a snapshot of the selected area dictated blockPositionY targetBlock.x y z v.brushSize v.voxelHeight and v.cCen. @@ -123,9 +117,4 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("air", "fill", "default")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.clonestamp"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CometBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CometBrush.java index 2448d543..4bc80648 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CometBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CometBrush.java @@ -25,12 +25,6 @@ public class CometBrush extends CustomBrush { private boolean useBigBalls = false; - /** - * - */ - public CometBrush() { - this.setName("Comet"); - } private void doFireball(final SnipeData v) { final VoxelVector targetCoords = new VoxelVector(this.getTargetBlock().getX() + .5 * this.getTargetBlock().getX() / Math.abs(this.getTargetBlock().getX()), this.getTargetBlock().getY() + .5, this.getTargetBlock().getZ() + .5 * this.getTargetBlock().getZ() / Math.abs(this.getTargetBlock().getZ())); @@ -86,11 +80,6 @@ public final void info(final VoxelMessage vm) { vm.custom(Messages.COMET_SIZE.replace("%size%", size)); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.comet"; - } - @Override public boolean perform(ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { if (operations.size() != 2) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java deleted file mode 100644 index a8bc258b..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/CylinderBrush.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.brush.perform.PerformerBrush; -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.RotationAxis; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.VoxelMessage; -import com.google.common.collect.Lists; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * @author Kavutop - * ... - */ -public class CylinderBrush extends PerformerBrush { - - private boolean smoothCircle = false; - - /** - * - */ - public CylinderBrush() { - this.setName("Cylinder"); - } - - private void cylinder(final SnipeData v) { - this.positions = Shapes.cylinder(this.getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), v.getVoxelHeight(), v.getcCen(), this.smoothCircle); - } - - @Override - protected final void doArrow(final SnipeData v) { - this.cylinder(v); - } - - @Override - protected final void doPowder(final SnipeData v) { - this.cylinder(v); - } - - @Override - public final void info(final VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - vm.height(); - vm.center(); - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.CYLINDER_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - if (params[0].startsWith("smooth")) { - this.smoothCircle = !this.smoothCircle; - v.sendMessage(Messages.BRUSH_SMOOTH_CIRCLE.replace("%smoothCircle%", String.valueOf(this.smoothCircle))); - return; - } - - if (params[0].startsWith("height")) { - try { - v.setVoxelHeight(Integer.parseInt(params[1])); - v.getVoxelMessage().height(); - return; - } catch (NumberFormatException | ArrayIndexOutOfBoundsException temp) { - temp.printStackTrace(); - } - } - - if (params[0].startsWith("shift")) { - try { - v.setcCen(Integer.parseInt(params[1])); - v.sendMessage(Messages.CYLINDER_SHIFT_Y.replace("%count%", String.valueOf(v.getcCen()))); - return; - } catch (NumberFormatException | ArrayIndexOutOfBoundsException temp) { - temp.printStackTrace(); - } - } - - v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); - sendPerformerMessage(triggerHandle, v); - } - - @NotNull - @Override - public List registerArguments() { - List arguments = new ArrayList<>(); - arguments.addAll(Lists.newArrayList("shift", "height", "smooth")); - - arguments.addAll(super.registerArguments()); - return arguments; - } - - @NotNull - @Override - public HashMap> registerArgumentValues() { - HashMap> argumentValues = new HashMap<>(); - - - argumentValues.put("shift", Lists.newArrayList("[number]")); - - argumentValues.put("height", Lists.newArrayList("[number]")); - - argumentValues.putAll(super.registerArgumentValues()); - return argumentValues; - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.cylinder"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java deleted file mode 100644 index e03a8c11..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscBrush.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.brush.perform.PerformerBrush; -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Messages; -import com.github.kevindagame.util.RotationAxis; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.voxelsniper.block.IBlock; -import com.google.common.collect.Lists; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * ... - * - * @author Voxel - */ -public class DiscBrush extends PerformerBrush { - - - private boolean smoothCircle = false; - - /** - * Default Constructor. - */ - public DiscBrush() { - this.setName("Disc"); - } - - /** - * Disc executor. - * - * @param v SnipeData - */ - private void disc(final SnipeData v, final IBlock targetBlock) { - this.positions = Shapes.disc(targetBlock.getLocation(), RotationAxis.Y, v.getBrushSize(), this.smoothCircle); - } - - @Override - protected final void doArrow(final SnipeData v) { - this.disc(v, this.getTargetBlock()); - } - - @Override - protected final void doPowder(final SnipeData v) { - this.disc(v, this.getLastBlock()); - } - - @Override - public final void info(final VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - } - - @Override - public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) { - if (params[0].equalsIgnoreCase("info")) { - v.sendMessage(Messages.DISC_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle)); - return; - } - - if (params[0].startsWith("smooth")) { - this.smoothCircle = !this.smoothCircle; - v.sendMessage(Messages.BRUSH_SMOOTH_CIRCLE.replace("%smoothCircle%", String.valueOf(this.smoothCircle))); - return; - } - - v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); - sendPerformerMessage(triggerHandle, v); - } - - @NotNull - @Override - public List registerArguments() { - List arguments = new ArrayList<>(); - arguments.addAll(Lists.newArrayList("smooth")); - - arguments.addAll(super.registerArguments()); - return arguments; - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.disc"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscFaceBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscFaceBrush.java index c5735942..0b3715be 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscFaceBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DiscFaceBrush.java @@ -23,12 +23,6 @@ public class DiscFaceBrush extends PerformerBrush { private boolean smoothCircle = false; - /** - * - */ - public DiscFaceBrush() { - this.setName("Disc Face"); - } private void discFace(final SnipeData v) { this.positions = Shapes.discFace(this.getTargetBlock().getLocation(), v.getBrushSize(), this.smoothCircle, this.getTargetBlock().getFace(this.getLastBlock())); @@ -76,9 +70,4 @@ public List registerArguments() { arguments.addAll(super.registerArguments()); return arguments; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.discface"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DomeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DomeBrush.java index 043436c7..307d2dfb 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DomeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DomeBrush.java @@ -14,13 +14,6 @@ */ public class DomeBrush extends PerformerBrush { - /** - * - */ - public DomeBrush() { - this.setName("Dome"); - } - /** * @param v */ @@ -51,9 +44,4 @@ protected final void doArrow(final SnipeData v) { protected final void doPowder(final SnipeData v) { this.generateDome(v); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.dome"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java index 53438bfe..b3284c87 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/DrainBrush.java @@ -25,12 +25,6 @@ public class DrainBrush extends AbstractBrush { private final boolean smooth = true; private boolean disc = false; - /** - * - */ - public DrainBrush() { - this.setName("Drain"); - } private void drain(final SnipeData v) { var positions = this.disc ? Shapes.disc(getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), smooth) : Shapes.ball(getTargetBlock().getLocation(), v.getBrushSize(), smooth); @@ -87,9 +81,4 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("shape")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.drain"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipseBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipseBrush.java index 6d89e9c0..2fb623f4 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipseBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipseBrush.java @@ -33,12 +33,6 @@ public class EllipseBrush extends PerformerBrush { private double stepSize; private boolean fill; - /** - * - */ - public EllipseBrush() { - this.setName("Ellipse"); - } private void ellipse(final SnipeData v, IBlock targetBlock) { try { @@ -263,9 +257,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.ellipse"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipsoidBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipsoidBrush.java index a04e21c3..2df2e350 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipsoidBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EllipsoidBrush.java @@ -22,12 +22,6 @@ public class EllipsoidBrush extends PerformerBrush { private double yRad; private double zRad; - /** - * - */ - public EllipsoidBrush() { - this.setName("Ellipsoid"); - } private void execute(final SnipeData v) { positions.add(getTargetBlock().getLocation()); @@ -136,9 +130,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.ellipsoid"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityBrush.java index 7d6368bc..97e8acb3 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityBrush.java @@ -19,12 +19,6 @@ public class EntityBrush extends AbstractBrush { private VoxelEntityType entityType = VoxelEntityType.ZOMBIE; - /** - * - */ - public EntityBrush() { - this.setName("Entity"); - } private void spawn(final SnipeData v) { for (int x = 0; x < v.getBrushSize(); x++) { @@ -87,9 +81,4 @@ public List registerArguments() { return entities; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.entity"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityRemovalBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityRemovalBrush.java index 1ba178ea..3b35ee3e 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityRemovalBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EntityRemovalBrush.java @@ -27,7 +27,6 @@ public class EntityRemovalBrush extends AbstractBrush { * */ public EntityRemovalBrush() { - this.setName("Entity Removal Brush"); defaultValues(); } @@ -185,9 +184,4 @@ public HashMap> registerArgumentValues() { argumentValues.put("-", entities); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.entityremoval"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EraserBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EraserBrush.java index 9f1b34f0..e6da2127 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EraserBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/EraserBrush.java @@ -20,12 +20,6 @@ public class EraserBrush extends AbstractBrush { private static final Set EXCLUSIVE_LIQUIDS = Set.of( VoxelMaterial.WATER, VoxelMaterial.LAVA); - /** - * - */ - public EraserBrush() { - this.setName("Eraser"); - } private void doErase(final SnipeData v) { @@ -55,9 +49,4 @@ public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); vm.size(); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.eraser"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ErodeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ErodeBrush.java index 90b74ac8..d8799dbf 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ErodeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ErodeBrush.java @@ -28,12 +28,6 @@ public class ErodeBrush extends AbstractBrush { private ErosionPreset currentPreset = new ErosionPreset(0, 1, 0, 1); private BlockChangeTracker blockTracker; - /** - * - */ - public ErodeBrush() { - this.setName("Erode"); - } @Override @@ -178,11 +172,6 @@ public List registerArguments() { return Arrays.stream(Preset.values()).map(Enum::name).collect(Collectors.toList()); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.erode"; - } - /** * @author MikeMatrix */ diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/FillDownBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/FillDownBrush.java index 1a30c0ae..b89328f0 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/FillDownBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/FillDownBrush.java @@ -25,12 +25,6 @@ public class FillDownBrush extends PerformerBrush { private boolean fillLiquid = true; private boolean fromExisting = false; - /** - * - */ - public FillDownBrush() { - this.setName("Fill Down"); - } private void fillDown(final SnipeData v, final IBlock b) { final int brushSize = v.getBrushSize(); @@ -131,9 +125,4 @@ public List registerArguments() { arguments.addAll(super.registerArguments()); return arguments; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.filldown"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.java deleted file mode 100644 index e4795fbe..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.snipe.SnipeAction; -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.VoxelMessage; -import com.github.kevindagame.voxelsniper.block.IBlock; - -import java.util.HashMap; -import java.util.List; - -/** - * Brush Interface. - */ -public interface IBrush { - - /** - * @param vm Message object - */ - void info(VoxelMessage vm); - - /** - * Handles parameters passed to brushes. - * - * @param triggerHandle the handle that triggered this brush - * @param params Array of string containing parameters - * @param v Snipe Data - */ - void parseParameters(String triggerHandle, String[] params, SnipeData v); - - boolean perform(SnipeAction action, SnipeData data, IBlock targetBlock, IBlock lastBlock); - - /** - * @return The name of the Brush - */ - String getName(); - - /** - * @param name New name for the Brush - */ - void setName(String name); - - /** - * @return The name of the category the brush is in. - */ - String getBrushCategory(); - - /** - * @return Permission node required to use this brush - */ - String getPermissionNode(); - - /** - * Registers the additional arguments for the tab completion - * - * @return - */ - List registerArguments(); - - /** - * Registers the additional arguments for the tab completion - * - * @return - */ - HashMap> registerArgumentValues(); -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt new file mode 100644 index 00000000..5969e13b --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt @@ -0,0 +1,56 @@ +package com.github.kevindagame.brush + +import com.github.kevindagame.snipe.SnipeAction +import com.github.kevindagame.snipe.SnipeData +import com.github.kevindagame.util.VoxelMessage +import com.github.kevindagame.voxelsniper.block.IBlock +import util.InitOnceProperty +import kotlin.properties.ReadWriteProperty + +inline fun initOnce(): ReadWriteProperty = InitOnceProperty() + +/** + * Brush Interface. + */ +interface IBrush { + /** + * @param vm Message object + */ + fun info(vm: VoxelMessage) + + /** + * Handles parameters passed to brushes. + * + * @param triggerHandle the handle that triggered this brush + * @param params Array of string containing parameters + * @param v Snipe Data + */ + fun parseParameters(triggerHandle: String, params: Array, v: SnipeData) + fun perform(action: SnipeAction, data: SnipeData, targetBlock: IBlock, lastBlock: IBlock): Boolean + /** + * @return The name of the Brush + */ + /** + * @param name New name for the Brush + */ + var name: String + + /** + * @return Permission node required to use this brush + */ + var permissionNode: String + + /** + * Registers the additional arguments for the tab completion + * + * @return + */ + fun registerArguments(): List + + /** + * Registers the additional arguments for the tab completion + * + * @return + */ + fun registerArgumentValues(): HashMap> +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JaggedLineBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JaggedLineBrush.java index 1474c731..ff1a9411 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JaggedLineBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JaggedLineBrush.java @@ -34,12 +34,6 @@ public class JaggedLineBrush extends PerformerBrush { private int recursion = RECURSION_DEFAULT; private int spread = SPREAD_DEFAULT; - /** - * - */ - public JaggedLineBrush() { - this.setName("Jagged Line"); - } private void jaggedP(final SnipeData v) { final VoxelVector originClone = this.originCoords.clone().add(JaggedLineBrush.HALF_BLOCK_OFFSET); @@ -142,9 +136,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.jaggedline"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JockeyBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JockeyBrush.java index be364da8..0381dfc2 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JockeyBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/JockeyBrush.java @@ -29,12 +29,6 @@ public class JockeyBrush extends CustomBrush { private boolean playerOnly = false; - /** - * - */ - public JockeyBrush() { - this.setName("Jockey"); - } private void sitOn(final SnipeData v) { BaseLocation location = this.getLastBlock().getLocation(); @@ -158,11 +152,6 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("inverse", "stack", "normal")); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.jockey"; - } - @Override public boolean perform(@NotNull ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { if (operations.size() != 1) return false; diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LightningBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LightningBrush.java index 83aaef95..0065cded 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LightningBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LightningBrush.java @@ -15,12 +15,6 @@ */ public class LightningBrush extends CustomBrush { - /** - * - */ - public LightningBrush() { - this.setName("Lightning"); - } @Override public final void info(final VoxelMessage vm) { @@ -38,11 +32,6 @@ protected final void powder(final SnipeData v) { addOperation(new CustomOperation(this.getTargetBlock().getLocation(), this, v, CustomOperationContext.TARGETLOCATION)); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.lightning"; - } - @Override public boolean perform(@NotNull ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { operations.forEach(operation -> operation.getLocation().getWorld().strikeLightning(operation.getLocation())); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LineBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LineBrush.java index c7ee9b3a..7271cfcf 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LineBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/LineBrush.java @@ -20,12 +20,6 @@ public class LineBrush extends PerformerBrush { private VoxelVector targetCoords = new VoxelVector(); private IWorld targetWorld; - /** - * - */ - public LineBrush() { - this.setName("Line"); - } @Override public final void info(final VoxelMessage vm) { @@ -63,9 +57,4 @@ protected final void doPowder(final SnipeData v) { this.linePowder(v); } } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.line"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/OverlayBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/OverlayBrush.java index dc296c12..9a1a6d36 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/OverlayBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/OverlayBrush.java @@ -27,9 +27,7 @@ public class OverlayBrush extends PerformerBrush { private boolean allBlocks = false; private boolean useVoxelList = false; - public OverlayBrush() { - this.setName("Overlay (Topsoil Filling)"); - } + private void overlay(final SnipeData v) { final int brushSize = v.getBrushSize(); @@ -192,9 +190,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.overlay"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/PaintingBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/PaintingBrush.java index 11527710..40200a88 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/PaintingBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/PaintingBrush.java @@ -18,12 +18,6 @@ */ public class PaintingBrush extends CustomBrush { - /** - * - */ - public PaintingBrush() { - this.setName("Painting"); - } /** * Scroll painting forward. @@ -50,11 +44,6 @@ public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.painting"; - } - @Override public boolean perform(@NotNull ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { switch (Objects.requireNonNull(getSnipeAction())) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RegenerateChunkBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RegenerateChunkBrush.java index 9cc84da5..57f4d742 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RegenerateChunkBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RegenerateChunkBrush.java @@ -20,9 +20,7 @@ public class RegenerateChunkBrush extends CustomBrush { private int originalSize; - public RegenerateChunkBrush() { - this.setName("Chunk Generator 40k"); - } + private void generateChunk(final SnipeData v) { final IChunk chunk = this.getTargetBlock().getChunk(); @@ -52,15 +50,10 @@ public final void info(final VoxelMessage vm) { vm.brushMessage(Messages.REGENERATE_CHUNK_MESSAGE); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.regeneratechunk"; - } - @Override public boolean perform(@NotNull ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { final IChunk chunk = this.getTargetBlock().getChunk(); - //check if no operation has been cancelled by comparing the size to the amount of loops + //check if no operationType has been cancelled by comparing the size to the amount of loops if (operations.stream().filter(o -> !o.isCancelled()).count() != originalSize) { return false; } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RingBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RingBrush.java index f148b9a3..57e3397f 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RingBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RingBrush.java @@ -27,12 +27,6 @@ public class RingBrush extends PerformerBrush { private double innerSize = 0; - /** - * - */ - public RingBrush() { - this.setName("Ring"); - } private void ring(final SnipeData v, IBlock targetBlock) { this.positions = Shapes.ring(this.getTargetBlock().getLocation(), v.getBrushSize(), this.innerSize, this.smoothCircle); @@ -103,9 +97,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.ring"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java index e92319db..bdffb844 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DBrush.java @@ -20,12 +20,6 @@ public class Rot2DBrush extends AbstractBrush { private double angle = 90; - /** - * - */ - public Rot2DBrush() { - this.setName("2D Rotation"); - } @Override protected final void arrow(final SnipeData v) { @@ -71,9 +65,4 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("[number]")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.rot2d"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java index cd9e55e3..7b157ef6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot2DvertBrush.java @@ -15,12 +15,6 @@ public class Rot2DvertBrush extends AbstractBrush { private double angle = 90; - /** - * - */ - public Rot2DvertBrush() { - this.setName("2D Rotation"); - } @Override protected final void arrow(final SnipeData v) { @@ -66,9 +60,4 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("[number]")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.rot2dvert"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java index 6d79784d..c5031e68 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/Rot3DBrush.java @@ -20,12 +20,6 @@ public class Rot3DBrush extends AbstractBrush { private double pitch; private double roll; - /** - * - */ - public Rot3DBrush() { - this.setName("3D Rotation"); - } @Override public final void info(final VoxelMessage vm) { @@ -108,9 +102,4 @@ protected final void arrow(final SnipeData v) { protected final void powder(final SnipeData v) { this.arrow(v); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.rot3d"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RulerBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RulerBrush.java index 1e49e8fa..6944be40 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RulerBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/RulerBrush.java @@ -25,12 +25,6 @@ public class RulerBrush extends CustomBrush { private boolean first = true; private VoxelVector coords = new VoxelVector(); - /** - * - */ - public RulerBrush() { - this.setName("Ruler"); - } @Override protected final void arrow(final SnipeData v) { @@ -63,11 +57,6 @@ public final void parseParameters(@NotNull final String triggerHandle, final Str v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.ruler"; - } - @Override public boolean perform(ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { if (operations.size() != 1) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ScannerBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ScannerBrush.java index 97e5a6e7..3acf33c6 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ScannerBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ScannerBrush.java @@ -28,12 +28,6 @@ public class ScannerBrush extends CustomBrush { private int depth = DEPTH_DEFAULT; - /** - * - */ - public ScannerBrush() { - this.setName("Scanner"); - } private int clamp(final int value, final int min, final int max) { if (value < min) { @@ -109,11 +103,6 @@ public HashMap> registerArgumentValues() { return argumentValues; } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.scanner"; - } - @Override public boolean perform(ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { if (operations.size() != 1) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SetBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SetBrush.java index 03ee26e6..b4965951 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SetBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SetBrush.java @@ -17,12 +17,6 @@ public class SetBrush extends PerformerBrush { private static final int SELECTION_SIZE_MAX = 5000000; private IBlock block = null; - /** - * - */ - public SetBrush() { - this.setName("Set"); - } /** * NOTE: TRUE when first point was selected, or second point is in different world @@ -80,9 +74,4 @@ public final void info(final VoxelMessage vm) { this.block = null; vm.brushName(this.getName()); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.set"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SignOverwriteBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SignOverwriteBrush.java index dafabbcf..76314a0f 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SignOverwriteBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SignOverwriteBrush.java @@ -41,8 +41,6 @@ public class SignOverwriteBrush extends CustomBrush { * */ public SignOverwriteBrush() { - this.setName("Sign Overwrite Brush"); - clearBuffer(); resetStates(); } @@ -375,11 +373,6 @@ public final void info(final VoxelMessage vm) { } } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.signoverwrite"; - } - @Override public boolean perform(@NotNull ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { switch (Objects.requireNonNull(getSnipeAction())) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SnipeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SnipeBrush.java index 9c75fe89..916fa070 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SnipeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SnipeBrush.java @@ -11,12 +11,6 @@ */ public class SnipeBrush extends PerformerBrush { - /** - * - */ - public SnipeBrush() { - this.setName("Snipe"); - } @Override protected final void doArrow(final SnipeData v) { @@ -32,9 +26,4 @@ protected final void doPowder(final SnipeData v) { public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.snipe"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterBallBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterBallBrush.java index bfcd99c2..cf42abc7 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterBallBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterBallBrush.java @@ -17,9 +17,7 @@ */ public class SplatterBallBrush extends SplatterBrushBase { - public SplatterBallBrush() { - this.setName("Splatter Ball"); - } + private void splatterBall(final SnipeData v) { final int brushSize = v.getBrushSize(); @@ -81,9 +79,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.splatterball"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java index f4ebbde9..2a6eb98f 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterDiscBrush.java @@ -13,9 +13,7 @@ public class SplatterDiscBrush extends SplatterBrushBase { - public SplatterDiscBrush() { - this.setName("Splatter Disc"); - } + private void splatterDisc(final SnipeData v) { var positions = Shapes.disc(this.getTargetBlock().getLocation(), RotationAxis.Y, v.getBrushSize(), false); @@ -49,9 +47,4 @@ public final void parseParameters(final String triggerHandle, final String[] par v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); sendPerformerMessage(triggerHandle, v); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.splatterdisc"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterOverlayBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterOverlayBrush.java index 13dc3d52..e99228c5 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterOverlayBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterOverlayBrush.java @@ -24,9 +24,7 @@ public class SplatterOverlayBrush extends SplatterBrushBase { private int depth = 3; private boolean allBlocks = false; private boolean useVoxelList = false; - public SplatterOverlayBrush() { - this.setName("Splatter Overlay"); - } + private void sOverlay(final SnipeData v) { @@ -194,9 +192,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.splatteroverlay"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelBrush.java index 3a7cda35..a6e3e40a 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelBrush.java @@ -12,9 +12,7 @@ */ public class SplatterVoxelBrush extends SplatterBrushBase { - public SplatterVoxelBrush() { - this.setName("Splatter Voxel"); - } + private void vSplatterBall(final SnipeData v, IBlock targetBlock) { final int brushSize = v.getBrushSize(); @@ -49,9 +47,4 @@ public final void parseParameters(final String triggerHandle, final String[] par v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); sendPerformerMessage(triggerHandle, v); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.splattervoxel"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelDiscBrush.java index cf42049e..51fb5a72 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelDiscBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplatterVoxelDiscBrush.java @@ -11,12 +11,6 @@ public class SplatterVoxelDiscBrush extends SplatterBrushBase { - /** - * - */ - public SplatterVoxelDiscBrush() { - this.setName("Splatter Voxel Disc"); - } private void vSplatterDisc(final SnipeData v, IBlock targetBlock) { var positions = Shapes.voxelDisc(this.getTargetBlock().getLocation(), v.getBrushSize()); @@ -50,9 +44,4 @@ public final void parseParameters(final String triggerHandle, final String[] par v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); sendPerformerMessage(triggerHandle, v); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.splattervoxeldisc"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplineBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplineBrush.java index 342ae4a7..8c65a1a9 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplineBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SplineBrush.java @@ -27,9 +27,7 @@ public class SplineBrush extends PerformerBrush { protected boolean set; protected boolean ctrl; - public SplineBrush() { - this.setName("Spline"); - } + public final void addToSet(final SnipeData v, final boolean ep, IBlock targetBlock) { String pos = "(" + targetBlock.getX() + ", " + targetBlock.getY() + ", " + targetBlock.getZ() + ") "; @@ -100,7 +98,7 @@ public final boolean spline(final Point start, final Point end, final Point c1, positions.add(new BaseLocation(getWorld(), px, py, pz)); } //manually add operations because the performer logic is not called here - addOperations(currentPerformer.perform(positions)); + addOperations(currentPerformer.perform(positions, v)); return true; } catch (final Exception exception) { v.sendMessage(Messages.SPLINE_BRUSH_NOT_ENOUGH_POINTS.replace("%endPts%", String.valueOf(this.endPts.size())).replace("%ctrlPts%", String.valueOf(this.ctrlPts.size()))); @@ -211,11 +209,6 @@ public List registerArguments() { return arguments; } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.spline"; - } - // Vector class for splines private static class Point { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/StampBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/StampBrush.java index 1724c9b8..2212e420 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/StampBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/StampBrush.java @@ -21,12 +21,6 @@ public class StampBrush extends AbstractBrush { protected boolean sorted = false; protected StampType stamp = StampType.DEFAULT; - /** - * - */ - public StampBrush() { - this.setName("Stamp"); - } /** * @@ -138,11 +132,6 @@ public void info(@NotNull final VoxelMessage vm) { throw new UnsupportedOperationException("Not supported yet."); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.stamp"; - } - /** * @author Monofraps */ diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ThreePointCircleBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ThreePointCircleBrush.java index 7509f897..cfcbe7ce 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ThreePointCircleBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/ThreePointCircleBrush.java @@ -27,9 +27,7 @@ public class ThreePointCircleBrush extends PerformerBrush { /** * Default Constructor. */ - public ThreePointCircleBrush() { - this.setName("3-Point Circle"); - } + @Override protected final void doArrow(final SnipeData v) { @@ -177,11 +175,6 @@ public List registerArguments() { return arguments; } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.threepointcircle"; - } - /** * Enumeration on Tolerance values. * diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TreeSnipeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TreeSnipeBrush.java index 1d4e8cc4..37f38c6e 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TreeSnipeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TreeSnipeBrush.java @@ -24,12 +24,6 @@ public class TreeSnipeBrush extends AbstractBrush { private VoxelTreeType treeType = VoxelTreeType.TREE; - /** - * - */ - public TreeSnipeBrush() { - this.setName("Tree Snipe"); - } private void single(final SnipeData v, IBlock targetBlock) { var result = this.getWorld().generateTree(targetBlock.getLocation(), this.treeType, false); @@ -109,9 +103,4 @@ public List registerArguments() { return Arrays.stream(VoxelTreeType.values()).filter(VoxelTreeType::isSupported).map(Enum::name).toList(); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.treesnipe"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TriangleBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TriangleBrush.java index 4f5f139e..d6936606 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TriangleBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/TriangleBrush.java @@ -23,12 +23,6 @@ public class TriangleBrush extends PerformerBrush { private final double[] normalVector = new double[3]; private int cornernumber = 1; - /** - * - */ - public TriangleBrush() { - this.setName("Triangle"); - } private void triangleA(final SnipeData v) { switch (this.cornernumber) { @@ -295,9 +289,4 @@ public final void parseParameters(final String triggerHandle, final String[] par v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle)); sendPerformerMessage(triggerHandle, v); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.triangle"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/UnderlayBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/UnderlayBrush.java index ccc40e1c..59b2d7f7 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/UnderlayBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/UnderlayBrush.java @@ -28,12 +28,6 @@ public class UnderlayBrush extends PerformerBrush { private boolean allBlocks = false; private boolean useVoxelList = false; - /** - * - */ - public UnderlayBrush() { - this.setName("Underlay (Reverse Overlay)"); - } private void underlay(final SnipeData v) { final int[][] memory = new int[v.getBrushSize() * 2 + 1][v.getBrushSize() * 2 + 1]; @@ -180,9 +174,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.underlay"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoltMeterBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoltMeterBrush.java index 3ca9c2c4..56371899 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoltMeterBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoltMeterBrush.java @@ -21,12 +21,6 @@ */ public class VoltMeterBrush extends CustomBrush { - /** - * - */ - public VoltMeterBrush() { - this.setName("VoltMeter"); - } private void data(final SnipeData v) { final IBlockData data = getTargetBlock().getBlockData(); @@ -64,11 +58,6 @@ public final void info(final VoxelMessage vm) { vm.brushMessage(Messages.VOLTMETER_BRUSH_MESSAGE); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.voltmeter"; - } - @Override public boolean perform(@NotNull ImmutableList operations, @NotNull SnipeData snipeData, @NotNull Undo undo) { switch (Objects.requireNonNull(this.getSnipeAction())) { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelBrush.java deleted file mode 100644 index 7ae1ef77..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelBrush.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.brush.perform.PerformerBrush; -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.VoxelMessage; - -/** - * ... - * - * @author Piotr - */ -public class VoxelBrush extends PerformerBrush { - - /** - * - */ - public VoxelBrush() { - this.setName("Voxel"); - } - - private void voxel(final SnipeData v) { - this.positions = Shapes.voxel(this.getTargetBlock().getLocation(), v.getBrushSize()); - } - - @Override - protected final void doArrow(final SnipeData v) { - this.voxel(v); - } - - @Override - protected final void doPowder(final SnipeData v) { - this.voxel(v); - } - - @Override - public final void info(final VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.voxel"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscBrush.java deleted file mode 100644 index 94d78c76..00000000 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscBrush.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.kevindagame.brush; - -import com.github.kevindagame.brush.perform.PerformerBrush; -import com.github.kevindagame.snipe.SnipeData; -import com.github.kevindagame.util.Shapes; -import com.github.kevindagame.util.VoxelMessage; - -/** - * ... - * - * @author Voxel - */ -public class VoxelDiscBrush extends PerformerBrush { - - /** - * - */ - public VoxelDiscBrush() { - this.setName("Voxel Disc"); - } - - private void voxelDisc(final SnipeData v) { - this.positions = Shapes.voxelDisc(this.getTargetBlock().getLocation(), v.getBrushSize()); - } - - @Override - protected final void doArrow(final SnipeData v) { - this.voxelDisc(v); - } - - @Override - protected final void doPowder(final SnipeData v) { - this.voxelDisc(v); - } - - @Override - public final void info(final VoxelMessage vm) { - vm.brushName(this.getName()); - vm.size(); - } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.voxeldisc"; - } -} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscFaceBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscFaceBrush.java index ff50aadf..1c2a31d1 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscFaceBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/VoxelDiscFaceBrush.java @@ -12,12 +12,6 @@ */ public class VoxelDiscFaceBrush extends PerformerBrush { - /** - * - */ - public VoxelDiscFaceBrush() { - this.setName("Voxel Disc Face"); - } private void voxelDiscFace(final SnipeData v) { this.positions = Shapes.voxelDiscFace(this.getTargetBlock().getLocation(), v.getBrushSize(), this.getTargetBlock().getFace(this.getLastBlock())); @@ -38,9 +32,4 @@ public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); vm.size(); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.voxeldiscface"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/WarpBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/WarpBrush.java index 5f013d3b..fe612a7e 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/WarpBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/WarpBrush.java @@ -11,12 +11,6 @@ */ public class WarpBrush extends AbstractBrush { - /** - * - */ - public WarpBrush() { - this.setName("Warp"); - } @Override public final void info(final VoxelMessage vm) { @@ -43,9 +37,4 @@ protected final void powder(final SnipeData v) { location.setYaw(playerLocation.getYaw()); player.teleport(location); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.warp"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonBrush.java index 63c77e46..fbaaf57e 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonBrush.java @@ -26,13 +26,6 @@ public class CanyonBrush extends AbstractBrush { private static final int SHIFT_LEVEL_MAX = 60; private int yLevel = -53; - /** - * - */ - public CanyonBrush() { - this.setName("Canyon"); - } - /** * @param chunk */ @@ -131,9 +124,4 @@ protected final int getYLevel() { protected final void setYLevel(int yLevel) { this.yLevel = yLevel; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.canyon"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonSelectionBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonSelectionBrush.java index a1b4878b..ecdde423 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonSelectionBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CanyonSelectionBrush.java @@ -17,13 +17,6 @@ public class CanyonSelectionBrush extends CanyonBrush { private int fx; private int fz; - /** - * - */ - public CanyonSelectionBrush() { - this.setName("Canyon Selection"); - } - private void execute(final SnipeData v) { final IChunk chunk = getTargetBlock().getChunk(); @@ -66,9 +59,4 @@ public final void info(final VoxelMessage vm) { vm.brushName(this.getName()); vm.custom(Messages.SHIFT_LEVEL_SET.replace("%getYLevel%", String.valueOf(this.getYLevel()))); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.canyonselection"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CopyPastaBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CopyPastaBrush.java index f648e199..8fbff72d 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CopyPastaBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/CopyPastaBrush.java @@ -35,12 +35,6 @@ public class CopyPastaBrush extends AbstractBrush { private IBlockData[] substanceArray; private int pivot = 0; // ccw degrees - /** - * - */ - public CopyPastaBrush() { - this.setName("CopyPasta"); - } private void doCopy(final SnipeData v) { for (int i = 0; i < 3; i++) { @@ -199,9 +193,4 @@ public HashMap> registerArgumentValues() { return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.copypasta"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/ExtrudeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/ExtrudeBrush.java index 215d36c2..2ee15db1 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/ExtrudeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/ExtrudeBrush.java @@ -24,13 +24,6 @@ public class ExtrudeBrush extends AbstractBrush { private static final double VOXEL_CIRCLE_VALUE = 0.0; private boolean smoothCircle = false; - /** - * - */ - public ExtrudeBrush() { - this.setName("Extrude"); - } - private void extrudeUpOrDown(final SnipeData v, boolean isUp) { final int brushSize = v.getBrushSize(); final double brushSizeSquared = Math.pow(brushSize + (smoothCircle ? SMOOTH_CIRCLE_VALUE : VOXEL_CIRCLE_VALUE), 2); @@ -170,9 +163,4 @@ public List registerArguments() { return new ArrayList<>(Lists.newArrayList("smooth")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.extrude"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/FlatOceanBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/FlatOceanBrush.java index b1090d60..d6970b98 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/FlatOceanBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/FlatOceanBrush.java @@ -26,13 +26,6 @@ public class FlatOceanBrush extends AbstractBrush { private int waterLevel = DEFAULT_WATER_LEVEL; private int floorLevel = DEFAULT_FLOOR_LEVEL; - /** - * - */ - public FlatOceanBrush() { - this.setName("FlatOcean"); - } - private void flatOcean(final IChunk chunk) { for (int x = 0; x < CHUNK_SIZE; x++) { for (int z = 0; z < CHUNK_SIZE; z++) { @@ -135,9 +128,4 @@ public HashMap> registerArgumentValues() { argumentValues.putAll(super.registerArgumentValues()); return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.flatocean"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java index dac26877..605e5e3d 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java @@ -43,13 +43,6 @@ public class GenerateTreeBrush extends AbstractBrush { private int nodeMax = 4; private int nodeMin = 3; - /** - * - */ - public GenerateTreeBrush() { - this.setName("Generate Tree"); - } - // Branch Creation based on direction chosen from the parameters passed. private void branchCreate(BaseLocation origin, final int xDirection, final int zDirection) { VoxelLocation location = origin.makeMutable(); @@ -589,9 +582,4 @@ public HashMap> registerArgumentValues() { return argumentValues; } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.generatetree"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/MoveBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/MoveBrush.java index 27586261..0d8ea879 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/MoveBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/MoveBrush.java @@ -36,13 +36,6 @@ public class MoveBrush extends AbstractBrush { */ private Selection selection = null; - /** - * - */ - public MoveBrush() { - this.setName("Move"); - } - /** * Moves the given selection blockPositionY the amount given in direction and saves an undo for the player. * @@ -177,11 +170,6 @@ public HashMap> registerArgumentValues() { return argumentValues; } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.move"; - } - private static class ComponentException extends Exception implements ComponentLike { private final ComponentLike component; diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/OceanBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/OceanBrush.java index 28279b1a..e76ab7f1 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/OceanBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/OceanBrush.java @@ -87,12 +87,6 @@ public class OceanBrush extends AbstractBrush { private int waterLevel = WATER_LEVEL_DEFAULT; private boolean coverFloor = false; - /** - * - */ - public OceanBrush() { - this.setName("OCEANATOR 5000(tm)"); - } private int getHeight(final int bx, final int bz) { for (int y = this.getWorld().getHighestBlockYAt(bx, bz); y > this.getMinHeight(); y--) { @@ -222,9 +216,4 @@ public final void info(final VoxelMessage vm) { vm.custom(Messages.WATER_LEVEL_SET.replace("%waterLevel%", String.valueOf(waterLevel + 1))); // +1 since we are working with 0-based array indices vm.custom(Messages.OCEAN_FLOOR_COVER.replace("%state%", this.coverFloor ? "enabled" : "disabled")); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.ocean"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/PullBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/PullBrush.java index d2417a45..f7498d2c 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/PullBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/PullBrush.java @@ -27,9 +27,7 @@ public class PullBrush extends AbstractBrush { /** * Default Constructor. */ - public PullBrush() { - this.setName("pull"); - } + @Override public final void info(final VoxelMessage vm) { @@ -277,11 +275,6 @@ protected final void powder(final SnipeData v) { } } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.pull"; - } - /** * @author Piotr */ diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/BasePerformer.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/BasePerformer.java index fc2c7b64..1aa74fca 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/BasePerformer.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/BasePerformer.java @@ -39,7 +39,8 @@ public void setUndo() { protected abstract BlockOperation perform(IBlock b); - public List perform(List positions) { + public List perform(List positions, SnipeData v) { + init(v); return positions.stream().map(BaseLocation::getBlock).filter(this).map(this::perform).collect(Collectors.toList()); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/PerformerBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/PerformerBrush.java index 01cc3bd9..50fa817a 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/PerformerBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/perform/PerformerBrush.java @@ -100,13 +100,13 @@ public void showInfo(VoxelMessage vm) { protected final void arrow(SnipeData v) { positions.clear(); doArrow(v); - addOperations(currentPerformer.perform(positions)); + addOperations(currentPerformer.perform(positions, v)); } @Override protected final void powder(SnipeData v) { positions.clear(); doPowder(v); - addOperations(currentPerformer.perform(positions)); + addOperations(currentPerformer.perform(positions, v)); } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrush.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrush.kt new file mode 100644 index 00000000..9714202d --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrush.kt @@ -0,0 +1,212 @@ +package com.github.kevindagame.brush.polymorphic + +import com.github.kevindagame.brush.AbstractBrush +import com.github.kevindagame.brush.perform.BasePerformer +import com.github.kevindagame.brush.polymorphic.operation.PolyOperation +import com.github.kevindagame.brush.polymorphic.property.* +import com.github.kevindagame.snipe.SnipeData +import com.github.kevindagame.util.Messages +import com.github.kevindagame.util.VoxelMessage +import com.github.kevindagame.util.brushOperation.BiomeOperation +import com.github.kevindagame.util.brushOperation.BlockOperation +import com.github.kevindagame.voxelsniper.biome.VoxelBiome +import com.github.kevindagame.voxelsniper.events.player.PlayerBrushChangedEvent +import com.github.kevindagame.voxelsniper.location.BaseLocation +import com.github.kevindagame.voxelsniper.material.VoxelMaterial +import kotlin.math.pow + +class PolyBrush( + name: String, + permissionNode: String, + val shapes: MutableList, + val operationType: PolyOperationType, + val operation: PolyOperation?, +) : AbstractBrush() { + var properties: MutableList> = mutableListOf() + private var positions: MutableList = ArrayList() + + init { + this.name = name + this.permissionNode = permissionNode + val properties = mutableSetOf() + for (shape in shapes) { + properties.addAll(shape.parameters.toList()) + } + when (operationType) { + PolyOperationType.BLOCK -> { + properties.add(PolyPropertiesEnum.PERFORMER) + } + + PolyOperationType.BIOME -> { + properties.add(PolyPropertiesEnum.BIOME) + } + } + if (operation != null) { + properties.add(PolyPropertiesEnum.EXCLUDEWATER) + properties.add(PolyPropertiesEnum.EXCLUDEAIR) + + } + for (property in properties) { + this.properties.add(property.supplier()) + } + } + + override fun info(vm: VoxelMessage) { + vm.brushName(name) + vm.size() + } + + override fun arrow(v: SnipeData) { + positions.clear() + doArrow(v) + } + + override fun powder(v: SnipeData) { + positions.clear() + doPowder(v) + } + + fun doArrow(v: SnipeData) { + executeBrush(v) + } + + fun doPowder(v: SnipeData) { + executeBrush(v) + } + + + fun executeBrush(v: SnipeData) { + this.positions = getPositions(v) + if (operationType == PolyOperationType.BIOME) { + for (position in positions) { + addOperation(BiomeOperation(position, world.getBiome(position), biome)) + } + return + } + if (operation != null) { + val brushSize = v.brushSize + val newMaterials = operation.apply(brushSize, this, excludeAir, excludeWater) + for (position in positions) { + val material: VoxelMaterial = + newMaterials[position.blockX - targetBlock.x + brushSize][position.blockY - targetBlock.y + brushSize][position.blockZ - targetBlock.z + brushSize] + if (!(excludeAir && material.isAir) && !(excludeWater && material === VoxelMaterial.WATER)) { + addOperation(BlockOperation(position, position.block.blockData, material.createBlockData())) + } + } + } else { + addOperations(currentPerformer.perform(positions, v)) + } + } + + private fun getPositions(v: SnipeData): MutableList { + val positions = initPositions(v) + val newPositions = mutableListOf() + val radiusSquared = (v.brushSize + if (smooth) SMOOTH_CIRCLE_VALUE else VOXEL_CIRCLE_VALUE).pow(2) + val center = targetBlock + + for (position in positions) { + if (shapes.all { it.apply(v, position, radiusSquared) }) { + newPositions.add( + BaseLocation( + world, + (center.x + position.dx).toDouble(), + (center.y + position.dy).toDouble(), + (center.z + position.dz).toDouble() + ) + ) + } + } + return newPositions + } + + /** + * Initialize the positions for every block in the brush radius in the shape of a cube + * "A relative location a day keeps the Math pain away" - KevinDaGame + */ + private fun initPositions(v: SnipeData): MutableList { + val positions = mutableListOf() + val brushSize = v.brushSize + for (z in brushSize downTo -brushSize) { + for (x in brushSize downTo -brushSize) { + for (y in brushSize downTo -brushSize) { + positions.add( + PolyLocation(x, y, z) + ) + } + } + } + return positions + } + + private inline fun getPropertyValue(): RET { + for (property in properties) { + if (property is T) { + return property.value as RET + } + } + val classname = T::class.simpleName + throw IllegalStateException("The requested property is not defined: $classname") + } + + private val smooth: Boolean get() = getPropertyValue() + private val excludeAir: Boolean get() = getPropertyValue() + private val excludeWater get() = getPropertyValue() + private val currentPerformer: BasePerformer get() = getPropertyValue() + private val biome: VoxelBiome get() = getPropertyValue() + + override fun registerArguments(): List { + val arguments = mutableListOf() + properties.forEach { + arguments.add(it.name) + arguments.addAll(it.aliases) + } + arguments.addAll(super.registerArguments()) + return arguments + } + + override fun parseParameters(triggerHandle: String, params: Array, v: SnipeData) { + if (params[0].equals("info", ignoreCase = true)) { + val info = Messages.POLY_BRUSH_USAGE.replace("brushName", name) + for (property in properties) { + info.append( + Messages.POLY_BRUSH_USAGE_LINE.replace("brushHandle", triggerHandle) + .replace("parameter", property.name).replace("description", property.description).toString() + ) + } + } + if (params.size == 1) { + v.owner().player.sendMessage(Messages.PARAMETER_PARSE_ERROR.replace("parameter", params[0])) + return + } + for (property in properties) { + if (property.name.equals(params[0], ignoreCase = true) || property.aliases.any { it.equals(params[0], ignoreCase = true) }) { + if (!PlayerBrushChangedEvent( + v.owner().player, + v.owner().currentToolId, + this, + this + ).callEvent().isCancelled + ) { + property.set(params[1]) + } + break + } + } + } + + override fun registerArgumentValues(): HashMap> { + val map = HashMap>() + for (property in properties) { + map.put(property.name, property.getValues()) + property.aliases.forEach { alias -> map.put(alias, property.getValues()) } + } + super.registerArgumentValues().forEach { (t, u) -> map.put(t, u) } + return map + } + + companion object { + var SMOOTH_CIRCLE_VALUE = 0.5 + var VOXEL_CIRCLE_VALUE = 0.0 + } + +} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushBuilder.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushBuilder.kt new file mode 100644 index 00000000..24fea8e7 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushBuilder.kt @@ -0,0 +1,74 @@ +package com.github.kevindagame.brush.polymorphic + +import com.github.kevindagame.brush.polymorphic.operation.PolyOperation +import java.util.function.Supplier + +class PolyBrushBuilder { + private lateinit var name: String + private lateinit var permission: String + private var operation: Supplier? = null + private var operationType: PolyOperationType = PolyOperationType.BLOCK + private val aliases: MutableList = mutableListOf() + private val shapes: MutableList = mutableListOf() + + /** + * Sets the name of the brush. + */ + fun name(name: String): PolyBrushBuilder { + this.name = name + return this + } + + /** + * Add aliases for the brush. + */ + fun alias(vararg aliases: String): PolyBrushBuilder { + this.aliases.addAll(aliases) + return this + } + + /** + * Sets the permission of the brush. + */ + fun permission(permission: String): PolyBrushBuilder { + this.permission = permission + return this + } + + /** + * Add an operation to the brush. + */ + fun shape(shape: PolyBrushShape): PolyBrushBuilder { + shapes.add(shape) + return this + } + + /** + * Set the operationType type of the brush By default this is {PolyOperationType.BLOCK} + */ + fun operationType(operationType: PolyOperationType): PolyBrushBuilder { + this.operationType = operationType + return this + } + + /** + * Set an operation to apply to the brush area + */ + fun operation(operation: Supplier): PolyBrushBuilder { + this.operation = operation + return this + } + + /** + * Build the brush + */ + fun build(): PolyBrushData { + return PolyBrushData( + name, + permission, aliases, + { PolyBrush(name, permission, shapes, operationType, operation?.get()) }, + shapes, + operationType + ) + } +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushData.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushData.kt new file mode 100644 index 00000000..7909997c --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushData.kt @@ -0,0 +1,14 @@ +package com.github.kevindagame.brush.polymorphic + +import com.github.kevindagame.brush.BrushData +import com.github.kevindagame.brush.IBrush +import java.util.function.Supplier + +class PolyBrushData( + name: String, + permission: String, + aliases: MutableList, + supplier: Supplier, + val shapes: MutableList?, + val operation: PolyOperationType +) : BrushData(name, permission, aliases, supplier) diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushShape.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushShape.kt new file mode 100644 index 00000000..ea7f0476 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyBrushShape.kt @@ -0,0 +1,39 @@ +package com.github.kevindagame.brush.polymorphic + +import com.github.kevindagame.brush.polymorphic.property.PolyPropertiesEnum +import com.github.kevindagame.snipe.SnipeData +import kotlin.math.pow + +enum class PolyBrushShape(vararg val parameters: PolyPropertiesEnum) : IPolyBrushShape { + BALL(PolyPropertiesEnum.SMOOTH) { + override fun apply(v: SnipeData, location: PolyLocation, radiusSquared: Double): Boolean { + return (location.dx.toDouble().pow(2) + location.dy.toDouble().pow(2) + location.dz.toDouble() + .pow(2) <= radiusSquared) + } + }, + CYLINDER(PolyPropertiesEnum.SMOOTH) { + override fun apply(v: SnipeData, location: PolyLocation, radiusSquared: Double): Boolean { + return (location.dx.toDouble().pow(2) + location.dz.toDouble().pow(2) <= radiusSquared) + } + }, + VOXEL() { + override fun apply(v: SnipeData, location: PolyLocation, radiusSquared: Double): Boolean { + return true + } + }, + DISC(PolyPropertiesEnum.SMOOTH) { + override fun apply(v: SnipeData, location: PolyLocation, radiusSquared: Double): Boolean { + return (location.dx.toDouble().pow(2) + 0 + location.dz.toDouble() + .pow(2) <= radiusSquared) && location.dy == 0 + } + }, + VOXEL_DISC() { + override fun apply(v: SnipeData, location: PolyLocation, radiusSquared: Double): Boolean { + return location.dy == 0 + } + }; +} + +interface IPolyBrushShape { + fun apply(v: SnipeData, location: PolyLocation, radiusSquared: Double): Boolean +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyLocation.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyLocation.kt new file mode 100644 index 00000000..441e1e6b --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyLocation.kt @@ -0,0 +1,9 @@ +package com.github.kevindagame.brush.polymorphic + +/** + * A location in the brush radius + * @param x The x coordinate relative to the brush center + * @param y The y coordinate relative to the brush center + * @param z The z coordinate relative to the brush center + */ +data class PolyLocation(val dx: Int, val dy: Int, val dz: Int) \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyOperationType.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyOperationType.kt new file mode 100644 index 00000000..eeebeeff --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/PolyOperationType.kt @@ -0,0 +1,5 @@ +package com.github.kevindagame.brush.polymorphic + +enum class PolyOperationType { + BLOCK, BIOME +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/BlendOperation.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/BlendOperation.kt new file mode 100644 index 00000000..ae415e2e --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/BlendOperation.kt @@ -0,0 +1,87 @@ +package com.github.kevindagame.brush.polymorphic.operation + +import com.github.kevindagame.brush.polymorphic.PolyBrush +import com.github.kevindagame.brush.polymorphic.PolyOperationType +import com.github.kevindagame.voxelsniper.material.VoxelMaterial + +class BlendOperation: PolyOperation(listOf(PolyOperationType.BLOCK)) { + override fun apply( + brushSize: Int, + brush: PolyBrush, + excludeAir: Boolean, + excludeWater: Boolean + ): Array>> { + val targetBlock = brush.targetBlock + val brushSizeDoubled = 2 * brushSize + // Array that holds the original materials plus a buffer + val oldMaterials = Array(2 * (brushSize + 1) + 1) { + Array(2 * (brushSize + 1) + 1) { + arrayOfNulls(2 * (brushSize + 1) + 1) + } + } + + // populate oldmats with the current materials + for (x in 0..2 * (brushSize + 1)) { + for (y in 0..2 * (brushSize + 1)) { + for (z in 0..2 * (brushSize + 1)) { + oldMaterials[x][y][z] = brush.getBlockMaterialAt( + targetBlock.x - brushSize - 1 + x, + targetBlock.y - brushSize - 1 + y, + targetBlock.z - brushSize - 1 + z + ) + } + } + } + //TODO: Validate that this is the correct way to clone the array + //clone oldMaterials into newMaterials + val newMaterials = oldMaterials.clone() + + // Blend materials + for (x in 0..brushSizeDoubled) { + for (y in 0..brushSizeDoubled) { + for (z in 0..brushSizeDoubled) { + val materialFrequency: MutableMap = HashMap() + var tiecheck = true + for (m in -1..1) { + for (n in -1..1) { + for (o in -1..1) { + if (!(m == 0 && n == 0 && o == 0)) { + val currentMaterial = oldMaterials[x + 1 + m][y + 1 + n][z + 1 + o] + val currentFrequency = materialFrequency.getOrDefault(currentMaterial, 0) + 1 + materialFrequency[currentMaterial] = currentFrequency + } + } + } + } + var highestMaterialCount = 0 + var highestMaterial = VoxelMaterial.AIR + + // Find most common neighbouring material + for ((key, value) in materialFrequency) { + if (value > highestMaterialCount && !(excludeAir && key!!.isAir) && !(excludeWater && key === VoxelMaterial.WATER)) { + highestMaterialCount = value + highestMaterial = key + } + } + + // Make sure that there's no tie in the highest material + for ((key, value) in materialFrequency) { + if (value == highestMaterialCount && !(excludeAir && key!!.isAir) && !(excludeWater && key === VoxelMaterial.WATER)) { + if (key === highestMaterial) { + continue + } + tiecheck = false + } + } + + // Record most common neighbor material for this block + if (tiecheck) { + newMaterials[x][y][z] = highestMaterial + } + } + } + } + return newMaterials as Array>> + } + +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/PolyOperation.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/PolyOperation.kt new file mode 100644 index 00000000..fe76166c --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/operation/PolyOperation.kt @@ -0,0 +1,12 @@ +package com.github.kevindagame.brush.polymorphic.operation + +import com.github.kevindagame.brush.polymorphic.PolyBrush +import com.github.kevindagame.brush.polymorphic.PolyOperationType +import com.github.kevindagame.voxelsniper.material.VoxelMaterial + +/** + * Base class for operations such as blending and splatter + */ +abstract class PolyOperation(val supportedOperationTypes: List) { + abstract fun apply(brushSize: Int, brush: PolyBrush, excludeAir: Boolean, excludeWater: Boolean): Array>> +} diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BiomeProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BiomeProperty.kt new file mode 100644 index 00000000..bafc7799 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BiomeProperty.kt @@ -0,0 +1,18 @@ +package com.github.kevindagame.brush.polymorphic.property + +import com.github.kevindagame.brush.perform.BasePerformer +import com.github.kevindagame.brush.perform.Performer +import com.github.kevindagame.brush.perform.pMaterial +import com.github.kevindagame.voxelsniper.biome.VoxelBiome + +class BiomeProperty : PolyProperty("biome", "Set the biome", VoxelBiome.PLAINS) { + override fun set(value: String?) { + val newBiome = VoxelBiome.getBiome(value) ?: return + this.value = newBiome + } + + + override fun getValues(): List { + return VoxelBiome.BIOMES.values.map { it.key } + } +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BooleanProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BooleanProperty.kt new file mode 100644 index 00000000..b76ee8e3 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/BooleanProperty.kt @@ -0,0 +1,11 @@ +package com.github.kevindagame.brush.polymorphic.property + +open class BooleanProperty(name: String, description: String, default: Boolean): PolyProperty(name, description, default) { + override fun set(value: String?) { + this.value = value?.toBoolean() ?: !this.value + } + + override fun getValues(): List { + return listOf("true", "false") + } +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeAirProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeAirProperty.kt new file mode 100644 index 00000000..1239131e --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeAirProperty.kt @@ -0,0 +1,4 @@ +package com.github.kevindagame.brush.polymorphic.property + +class ExcludeAirProperty: BooleanProperty("excludeAir", "Toggle excluding air", false) { +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeWaterProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeWaterProperty.kt new file mode 100644 index 00000000..0b4ed418 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/ExcludeWaterProperty.kt @@ -0,0 +1,4 @@ +package com.github.kevindagame.brush.polymorphic.property + +class ExcludeWaterProperty: BooleanProperty("excludeWater", "Toggle excluding water", false) { +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PerformerProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PerformerProperty.kt new file mode 100644 index 00000000..adc74d5d --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PerformerProperty.kt @@ -0,0 +1,18 @@ +package com.github.kevindagame.brush.polymorphic.property + +import com.github.kevindagame.brush.perform.BasePerformer +import com.github.kevindagame.brush.perform.Performer +import com.github.kevindagame.brush.perform.pMaterial +import com.google.common.collect.ImmutableList + +class PerformerProperty : PolyProperty("performer", "Set the performer", pMaterial(), aliases = ImmutableList.of("p")) { + override fun set(value: String?) { + val newPerfomer = Performer.getPerformer(value) ?: return + this.value = newPerfomer + } + + + override fun getValues(): List { + return Performer.getPerformerHandles().toList() + } +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyPropertiesEnum.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyPropertiesEnum.kt new file mode 100644 index 00000000..55f19ac7 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyPropertiesEnum.kt @@ -0,0 +1,11 @@ +package com.github.kevindagame.brush.polymorphic.property + +import kotlin.reflect.KFunction0 + +enum class PolyPropertiesEnum(val supplier: KFunction0>) { + SMOOTH(::SmoothProperty), + EXCLUDEWATER(::ExcludeWaterProperty), + EXCLUDEAIR(::ExcludeAirProperty), + PERFORMER(::PerformerProperty), + BIOME(::BiomeProperty), +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyProperty.kt new file mode 100644 index 00000000..17006d42 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/PolyProperty.kt @@ -0,0 +1,15 @@ +package com.github.kevindagame.brush.polymorphic.property + +import com.google.common.collect.ImmutableList + +abstract class PolyProperty(val name: String, val description: String, default: T, val aliases: ImmutableList = ImmutableList.of()) { + + var value: T = default + fun get(): T { + return value + } + + abstract fun set(value: String?) + + abstract fun getValues(): List +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/SmoothProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/SmoothProperty.kt new file mode 100644 index 00000000..b311bd41 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/polymorphic/property/SmoothProperty.kt @@ -0,0 +1,3 @@ +package com.github.kevindagame.brush.polymorphic.property + +class SmoothProperty : BooleanProperty("smooth", "Toggle using smooth sphere algorithm (default: false)", false) diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellBallBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellBallBrush.java index c6f73ce4..0b46cfd3 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellBallBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellBallBrush.java @@ -12,12 +12,6 @@ */ public class ShellBallBrush extends ShellBrushBase { - /** - * - */ - public ShellBallBrush() { - this.setName("Shell Ball"); - } @Override protected final void shell(final SnipeData v) { @@ -30,9 +24,4 @@ protected final void shell(final SnipeData v) { } v.sendMessage(Messages.SHELL_BRUSH_COMPLETE); } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.shellball"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellSetBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellSetBrush.java index ee8f881c..0770ba98 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellSetBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellSetBrush.java @@ -19,12 +19,6 @@ public class ShellSetBrush extends ShellBrushBase { private final ArrayList operations = new ArrayList<>(); private IBlock block = null; - /** - * - */ - public ShellSetBrush() { - this.setName("Shell Set"); - } private boolean set(final IBlock bl, final SnipeData v) { operations.clear(); @@ -99,9 +93,4 @@ protected final void powder(final SnipeData v) { } } - - @Override - public String getPermissionNode() { - return "voxelsniper.brush.shellset"; - } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellVoxelBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellVoxelBrush.java index 7ec96d0b..eafe3cd7 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellVoxelBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/shell/ShellVoxelBrush.java @@ -12,12 +12,6 @@ */ public class ShellVoxelBrush extends ShellBrushBase { - /** - * - */ - public ShellVoxelBrush() { - this.setName("Shell Voxel"); - } @Override protected void shell(SnipeData v) { @@ -31,9 +25,4 @@ protected void shell(SnipeData v) { v.sendMessage(Messages.SHELL_BRUSH_COMPLETE); } - @Override - public String getPermissionNode() { - return "voxelsniper.brush.shellvoxel"; - } - } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java index bf82d8ab..968aa9df 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java @@ -1,6 +1,7 @@ package com.github.kevindagame.command; import com.github.kevindagame.VoxelBrushManager; +import com.github.kevindagame.brush.BrushData; import com.github.kevindagame.brush.IBrush; import com.github.kevindagame.brush.perform.IPerformerBrush; import com.github.kevindagame.snipe.SnipeData; @@ -82,13 +83,13 @@ public boolean doCommand(IPlayer player, final String[] args) { } // Command: /b -- change brush to - Class brush = VoxelBrushManager.getInstance().getBrushForHandle(args[0]); + BrushData data = VoxelBrushManager.getInstance().getBrushForHandle(args[0]); - if (brush == null) { + if (data == null) { snipeData.sendMessage(Messages.BRUSH_HANDLE_NOT_FOUND.replace("%arg%", args[0])); } else { IBrush oldBrush = sniper.getBrush(currentToolId); - IBrush newBrush = sniper.instantiateBrush(brush); + IBrush newBrush = sniper.instantiateBrush(data); if (newBrush == null || !player.hasPermission(newBrush.getPermissionNode())) { snipeData.sendMessage(Messages.VOXEL_BRUSH_NO_PERMISSION); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelCommandManager.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelCommandManager.java index 8120e294..b75fb5ff 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelCommandManager.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelCommandManager.java @@ -8,7 +8,6 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; /** * @author ervinnnc @@ -44,29 +43,25 @@ public static VoxelCommandManager getInstance() { public abstract void registerCommand(VoxelCommand command); public void registerBrushSubcommands() { - try { - for (String brushHandle : VoxelBrushManager.getInstance().getBrushHandles()) { - // Initialize brush to retrieve subcommand map - IBrush brush = VoxelBrushManager.getInstance().getBrushForHandle(brushHandle).newInstance(); + for (String brushHandle : VoxelBrushManager.getInstance().getBrushHandles()) { + // Initialize brush to retrieve subcommand map + IBrush brush = VoxelBrushManager.getInstance().getBrushForHandle(brushHandle).getSupplier().get(); - if (argumentsMap.containsKey(BRUSH_SUBCOMMAND_PREFIX + brushHandle)) { - VoxelSniper.voxelsniper.getLogger().log(Level.WARNING, "Did not add clashing argument map: {0}, Brush handle: {1}", new Object[]{BRUSH_SUBCOMMAND_PREFIX + brushHandle, brushHandle}); - return; - } + if (argumentsMap.containsKey(BRUSH_SUBCOMMAND_PREFIX + brushHandle)) { + VoxelSniper.voxelsniper.getLogger().log(Level.WARNING, "Did not add clashing argument map: {0}, Brush handle: {1}", new Object[]{BRUSH_SUBCOMMAND_PREFIX + brushHandle, brushHandle}); + return; + } - argumentsMap.put(BRUSH_SUBCOMMAND_PREFIX + brushHandle, brush.registerArguments()); + argumentsMap.put(BRUSH_SUBCOMMAND_PREFIX + brushHandle, brush.registerArguments()); - brush.registerArgumentValues().forEach((identifier, arguments) -> { - if (argumentsMap.containsKey(BRUSH_SUBCOMMAND_PREFIX + brushHandle + BRUSH_SUBCOMMAND_SUFFIX + identifier)) { - VoxelSniper.voxelsniper.getLogger().log(Level.WARNING, "Did not add clashing argument map: {0}, Brush handle: {1}", new Object[]{BRUSH_SUBCOMMAND_PREFIX + brushHandle + identifier, brushHandle}); - return; - } + brush.registerArgumentValues().forEach((identifier, arguments) -> { + if (argumentsMap.containsKey(BRUSH_SUBCOMMAND_PREFIX + brushHandle + BRUSH_SUBCOMMAND_SUFFIX + identifier)) { + VoxelSniper.voxelsniper.getLogger().log(Level.WARNING, "Did not add clashing argument map: {0}, Brush handle: {1}", new Object[]{BRUSH_SUBCOMMAND_PREFIX + brushHandle + identifier, brushHandle}); + return; + } - argumentsMap.put(BRUSH_SUBCOMMAND_PREFIX + brushHandle + BRUSH_SUBCOMMAND_SUFFIX + identifier, arguments); - }); - } - } catch (InstantiationException | IllegalAccessException ex) { - Logger.getLogger(VoxelCommandManager.class.getName()).log(Level.SEVERE, "Could not initialize brush subcommand arguments!", ex); + argumentsMap.put(BRUSH_SUBCOMMAND_PREFIX + brushHandle + BRUSH_SUBCOMMAND_SUFFIX + identifier, arguments); + }); } } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java index 1425c3a9..44f4c57a 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/SnipeTool.java @@ -1,5 +1,6 @@ package com.github.kevindagame.snipe; +import com.github.kevindagame.VoxelBrushManager; import com.github.kevindagame.brush.IBrush; import com.github.kevindagame.brush.SnipeBrush; import com.github.kevindagame.util.VoxelMessage; @@ -25,10 +26,14 @@ public class SnipeTool { private final SnipeData snipeData; protected SnipeTool(Sniper owner) { - this.snipeData = new SnipeData(owner); + this(owner.instantiateBrush(VoxelBrushManager.getInstance().getDefaultBrush()), new SnipeData(owner)); + } + + protected SnipeTool(@Nullable IBrush brush, SnipeData snipeData) { + this.snipeData = snipeData; messageHelper = new VoxelMessage(snipeData); snipeData.setVoxelMessage(messageHelper); - this.currentBrush = Objects.requireNonNull(owner.instantiateBrush(SnipeBrush.class, true)); + this.currentBrush = brush; } public @NotNull IBrush getCurrentBrush() { diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java index 24af78d6..e88d2d1e 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/snipe/Sniper.java @@ -1,9 +1,11 @@ package com.github.kevindagame.snipe; import com.github.kevindagame.VoxelSniper; +import com.github.kevindagame.brush.BrushData; import com.github.kevindagame.brush.IBrush; import com.github.kevindagame.brush.perform.IPerformerBrush; import com.github.kevindagame.brush.perform.PerformerBrush; +import com.github.kevindagame.brush.polymorphic.PolyBrush; import com.github.kevindagame.util.BlockHelper; import com.github.kevindagame.util.Messages; import com.github.kevindagame.voxelsniper.block.BlockFace; @@ -25,13 +27,13 @@ */ public class Sniper { - private final UUID player; + public final IPlayer player; private final LinkedList undoList = new LinkedList<>(); private final Map tools = Maps.newHashMap(); private boolean enabled = true; public Sniper(IPlayer player) { - this.player = player.getUniqueId(); + this.player = player; SnipeTool sniperTool = new SnipeTool(this); sniperTool.assignAction(SnipeAction.ARROW, new VoxelMaterial("arrow")); sniperTool.assignAction(SnipeAction.GUNPOWDER, new VoxelMaterial("gunpowder")); @@ -39,7 +41,7 @@ public Sniper(IPlayer player) { } public String getCurrentToolId() { - return getToolId((getPlayer().getItemInHand() != null) ? getPlayer().getItemInHand() : VoxelMaterial.AIR); + return getToolId((player.getItemInHand() != null) ? player.getItemInHand() : VoxelMaterial.AIR); } public String getToolId(VoxelMaterial itemInHand) { @@ -55,10 +57,6 @@ public String getToolId(VoxelMaterial itemInHand) { return null; } - public IPlayer getPlayer() { - return VoxelSniper.voxelsniper.getPlayer(this.player); - } - /** * Sniper execution call. * @@ -84,7 +82,7 @@ public boolean snipe(Action action, VoxelMaterial itemInHand, IBlock clickedBloc } String permissionNode = sniperTool.getCurrentBrush().getPermissionNode(); - if (!getPlayer().hasPermission(permissionNode)) { + if (!player.hasPermission(permissionNode)) { sendMessage(Messages.NO_PERMISSION_BRUSH.replace("%permissionNode%", permissionNode)); return true; } @@ -97,7 +95,7 @@ public boolean snipe(Action action, VoxelMaterial itemInHand, IBlock clickedBloc targetBlock = clickedBlock; lastBlock = targetBlock.getRelative(clickedFace); } else { - BlockHelper rangeBlockHelper = snipeData.isRanged() ? new BlockHelper(getPlayer(), snipeData.getRange()) : new BlockHelper(getPlayer()); + BlockHelper rangeBlockHelper = snipeData.isRanged() ? new BlockHelper(player, snipeData.getRange()) : new BlockHelper(player); targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock(); lastBlock = rangeBlockHelper.getLastBlock(); } @@ -105,7 +103,7 @@ public boolean snipe(Action action, VoxelMaterial itemInHand, IBlock clickedBloc switch (action) { case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: - if (getPlayer().isSneaking()) { + if (player.isSneaking()) { return handleSneakLeftClick(toolId, snipeData, snipeAction, targetBlock); } break; @@ -171,6 +169,7 @@ public IBrush setBrush(String toolId, @NotNull IBrush brush) { /** * For the given toolID, sets the current Brush to the previous Brush, and then returns the new Brush + * * @return The new Brush, or null if there is no previous Brush */ public @Nullable IBrush previousBrush(String toolId) { @@ -269,6 +268,10 @@ public SnipeData getSnipeData(String toolId) { return tools.containsKey(toolId) ? tools.get(toolId).getSnipeData() : null; } + public IPlayer getPlayer() { + return player; + } + public void displayInfo() { String currentToolId = getCurrentToolId(); SnipeTool sniperTool = tools.get(currentToolId); @@ -289,21 +292,34 @@ public SnipeTool getSnipeTool(String toolId) { } public final void sendMessage(final @NotNull ComponentLike message) { - this.getPlayer().sendMessage(message); + player.sendMessage(message); } - public @Nullable IBrush instantiateBrush(Class brush) { - return this.instantiateBrush(brush, false); + /** + * Create the instance of a brush based on the BrushData + * + * @param brushData + * @return {IBrush} The brush instance + **/ + public @Nullable IBrush instantiateBrush(BrushData brushData) { + return this.instantiateBrush(brushData, false); } - public @Nullable IBrush instantiateBrush(Class brush, boolean force) { - try { - var brushInstance = brush.newInstance(); - if(force || getPlayer().hasPermission(brushInstance.getPermissionNode())) - return brushInstance; - } catch (InstantiationException | IllegalAccessException e) { - return null; + /** + * Create the instance of a brush based on the BrushData + * + * @param brushData + * @param force + * @return {IBrush} The brush instance + **/ + public @Nullable IBrush instantiateBrush(BrushData brushData, boolean force) { + var brushInstance = brushData.getSupplier().get(); + if (!(brushInstance instanceof PolyBrush)) { + brushInstance.setPermissionNode(brushData.getPermission()); + brushInstance.setName(brushData.getName()); } + if (force || player.hasPermission(brushInstance.getPermissionNode())) + return brushInstance; return null; } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/BlockHelper.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/BlockHelper.java index a3399be1..bd3e26eb 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/BlockHelper.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/BlockHelper.java @@ -11,6 +11,8 @@ import com.github.kevindagame.voxelsniper.vector.VoxelVector; import com.github.kevindagame.voxelsniper.world.IWorld; +import org.jetbrains.annotations.Nullable; + /** * @author Voxel @@ -31,7 +33,7 @@ public class BlockHelper { /** * Constructor requiring location, uses default values. * - * @param location + * @param location The location */ public BlockHelper(final BaseLocation location) { this(location, BlockHelper.DEFAULT_RANGE, BlockHelper.DEFAULT_STEP); @@ -40,9 +42,9 @@ public BlockHelper(final BaseLocation location) { /** * Constructor requiring location, max range, and a stepping value. * - * @param location - * @param range - * @param step + * @param location the location + * @param range The maximum distance to raytrace + * @param step The step amount to raytrace */ public BlockHelper(final BaseLocation location, final double range, final double step) { this.world = location.getWorld(); @@ -52,9 +54,9 @@ public BlockHelper(final BaseLocation location, final double range, final double /** * Constructor requiring player, max range, and a stepping value. * - * @param player - * @param range - * @param step + * @param player The player whose location should be the location + * @param range The maximum distance to raytrace + * @param step The step amount to raytrace */ public BlockHelper(final IPlayer player, final double range, final double step) { this(player.getEyeLocation(), range, step); @@ -63,7 +65,7 @@ public BlockHelper(final IPlayer player, final double range, final double step) /** * Constructor requiring player, uses default values. * - * @param player + * @param player The player whose location should be the location */ public BlockHelper(final IPlayer player) { this(player, BlockHelper.DEFAULT_RANGE); @@ -71,8 +73,8 @@ public BlockHelper(final IPlayer player) { } /** - * @param player - * @param range + * @param player The player whose location should be the location + * @param range The maximum range to raytrace */ public BlockHelper(final IPlayer player, final double range) { this(player, range, BlockHelper.DEFAULT_STEP); @@ -191,11 +193,13 @@ public final IBlock getRangeBlock() { * * @return IBlock */ + @Nullable public final IBlock getTargetBlock() { IBlock current; while (((current = this.getNextBlock()) != null) && (current.getMaterial().isAir())) { } + return this.getCurBlock(); } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java index 50ef68e3..04c28e67 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java @@ -354,6 +354,8 @@ public enum Messages implements ComponentLike { UNDERLAY_DEPTH_SET, UNDERLAY_MODE, UNDERLAY_ON_MODE_DEPTH, + POLY_BRUSH_USAGE, + POLY_BRUSH_USAGE_LINE, ACTION_CANCELLED, ; // diff --git a/VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt b/VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt new file mode 100644 index 00000000..172c4f94 --- /dev/null +++ b/VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt @@ -0,0 +1,25 @@ +package util + +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty + +class InitOnceProperty: ReadWriteProperty { + private object EMPTY + + private var value: Any? = EMPTY + + override fun getValue(thisRef: Any, property: KProperty<*>): T { + if (value == EMPTY) { + throw IllegalStateException("Value isn't initialized") + } else { + return value as T + } + } + + override fun setValue(thisRef: Any, property: KProperty<*>, value: T) { + if (this.value != EMPTY) { + throw IllegalStateException("Value is initialized") + } + this.value = value + } +} \ No newline at end of file diff --git a/VoxelSniperCore/src/main/resources/lang.yml b/VoxelSniperCore/src/main/resources/lang.yml index 53349447..cb278e05 100644 --- a/VoxelSniperCore/src/main/resources/lang.yml +++ b/VoxelSniperCore/src/main/resources/lang.yml @@ -585,4 +585,6 @@ FILE_ALREADY_EXISTS: This file already exists. UNDERLAY_DEPTH_SET: Underlay depth set to %depth% UNDERLAY_MODE: Underlaying on %mode% blocks UNDERLAY_ON_MODE_DEPTH: Will underlay on %mode% blocks, %depth% blocks deep. -ACTION_CANCELLED: The action was cancelled \ No newline at end of file +POLY_BRUSH_USAGE: %brushName% brush parameters +POLY_BRUSH_USAGE_LINE: %triggerHandle% %property% -- %description% +ACTION_CANCELLED: The action was cancelled diff --git a/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/BrushesTest.java b/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/BrushesTest.java index cd1fe6f8..a35db135 100644 --- a/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/BrushesTest.java +++ b/VoxelSniperCore/src/test/java/com/github/kevindagame/voxelsniper/BrushesTest.java @@ -2,7 +2,10 @@ import com.github.kevindagame.VoxelBrushManager; import com.github.kevindagame.VoxelSniper; +import com.github.kevindagame.brush.BrushBuilder; +import com.github.kevindagame.brush.BrushData; import com.github.kevindagame.brush.IBrush; +import com.github.kevindagame.brush.SnipeBrush; import com.github.kevindagame.brush.perform.Performer; import com.github.kevindagame.brush.perform.PerformerBrush; import org.junit.Assert; @@ -35,32 +38,30 @@ public void testBrushesEmpty() { @Test public void testGetBrushForHandle() { - 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")); + var brushData = new BrushBuilder().name("mock").alias("mockhandle", "testhandle").setSupplier(SnipeBrush::new).build(); + brushes.registerSniperBrush(brushData); + Assert.assertEquals(brushData, brushes.getBrushForHandle("mockhandle")); + Assert.assertEquals(brushData, brushes.getBrushForHandle("testhandle")); Assert.assertNull(brushes.getBrushForHandle("notExistant")); } @Test public void testRegisteredSniperBrushes() { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + brushes.registerSniperBrush(new BrushBuilder().name("mock").alias("mockhandle", "testhandle").setSupplier(SnipeBrush::new).build()); Assert.assertEquals(2, brushes.registeredSniperBrushHandles()); } @Test public void testRegisteredSniperBrushHandles() { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); + brushes.registerSniperBrush(new BrushBuilder().name("mock").alias("mockhandle", "testhandle").setSupplier(SnipeBrush::new).build()); Assert.assertEquals(2, brushes.registeredSniperBrushHandles()); } @Test public void testGetSniperBrushHandles() { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Set sniperBrushHandles = brushes.getSniperBrushHandles(brush.getClass()); + var brushData = new BrushBuilder().name("mock").alias("mockhandle", "testhandle").setSupplier(SnipeBrush::new).build(); + brushes.registerSniperBrush(brushData); + Set sniperBrushHandles = brushes.getSniperBrushHandles(brushData); Assert.assertTrue(sniperBrushHandles.contains("mockhandle")); Assert.assertTrue(sniperBrushHandles.contains("testhandle")); Assert.assertFalse(sniperBrushHandles.contains("notInSet")); @@ -68,18 +69,17 @@ public void testGetSniperBrushHandles() { @Test public void testGetRegisteredBrushesMap() { - IBrush brush = Mockito.mock(IBrush.class); - brushes.registerSniperBrush(brush.getClass(), "mockhandle", "testhandle"); - Map> registeredBrushesMap = brushes.getRegisteredBrushesMap(); - Assert.assertTrue(registeredBrushesMap.containsValue(brush.getClass())); - Assert.assertFalse(registeredBrushesMap.containsValue(IBrush.class)); - Assert.assertSame(registeredBrushesMap.get("mockhandle"), brush.getClass()); - Assert.assertSame(registeredBrushesMap.get("testhandle"), brush.getClass()); - Assert.assertNotSame(registeredBrushesMap.get("notAnEntry"), brush.getClass()); + var brushData = new BrushBuilder().name("mock").alias("mockhandle", "testhandle").setSupplier(SnipeBrush::new).build(); + brushes.registerSniperBrush(brushData); + Map registeredBrushesMap = brushes.getRegisteredBrushesMap(); + Assert.assertTrue(registeredBrushesMap.containsValue(brushData)); + Assert.assertSame(registeredBrushesMap.get("mockhandle"), brushData); + Assert.assertSame(registeredBrushesMap.get("testhandle"), brushData); + Assert.assertNotSame(registeredBrushesMap.get("notAnEntry"), brushData); } @Test - public void testPerformerBrushesArgumentsOverloading() throws Exception { + public void testPerformerBrushesArgumentsOverloading() { // Load all brushes brushes = VoxelBrushManager.initialize(); @@ -95,14 +95,14 @@ public void testPerformerBrushesArgumentsOverloading() throws Exception { System.out.println("======================================================================"); for (String brushHandle : brushes.getBrushHandles()) { - Class clazz = brushes.getBrushForHandle(brushHandle); - IBrush brush = clazz.getDeclaredConstructor().newInstance(); + BrushData brushData = brushes.getBrushForHandle(brushHandle); + IBrush brush = brushData.getSupplier().get(); if (brush instanceof PerformerBrush) { List arguments = brush.registerArguments(); - Assert.assertTrue("PERFORMER ARGUMENTS TEST: Please see the HINT A above. Failing at: " + clazz.getName(), arguments.contains("p")); + Assert.assertTrue("PERFORMER ARGUMENTS TEST: Please see the HINT A above. Failing at: " + brushData.getName(), arguments.contains("p")); - Assert.assertEquals("PERFORMER ARGUMENTS TEST: Duplicate argument 'p'. Please see the HINT Z above. Failing at: " + clazz.getName(), 1, Collections.frequency(arguments, "p")); + Assert.assertEquals("PERFORMER ARGUMENTS TEST: Duplicate argument 'p'. Please see the HINT Z above. Failing at: " + brushData.getName(), 1, Collections.frequency(arguments, "p")); } } System.out.println("Performer Arguments Test OK!"); @@ -112,7 +112,7 @@ public void testPerformerBrushesArgumentsOverloading() throws Exception { } @Test - public void testPerformerBrushesArgumentValuesOverloading() throws Exception { + public void testPerformerBrushesArgumentValuesOverloading() { // Load all brushes brushes = VoxelBrushManager.initialize(); System.out.println(" "); @@ -129,13 +129,13 @@ public void testPerformerBrushesArgumentValuesOverloading() throws Exception { Collection performerHandles = Performer.getPerformerHandles(); for (String brushHandle : brushes.getBrushHandles()) { - Class clazz = brushes.getBrushForHandle(brushHandle); - IBrush brush = clazz.getDeclaredConstructor().newInstance(); + BrushData brushData = brushes.getBrushForHandle(brushHandle); + IBrush brush = brushData.getSupplier().get(); if (brush instanceof PerformerBrush) { HashMap> argumentValues = brush.registerArgumentValues(); - Assert.assertTrue("PERFORMER ARGUMENTS VALUES TEST: Please see the HINT A above. Failing at: " + clazz.getName(), argumentValues.containsKey("p")); - Assert.assertTrue("PERFORMER ARGUMENTS VALUES TEST: Please see the HINT Z above. Failing at: " + clazz.getName(), argumentValues.get("p").containsAll(performerHandles)); + Assert.assertTrue("PERFORMER ARGUMENTS VALUES TEST: Please see the HINT A above. Failing at: " + brushData.getName(), argumentValues.containsKey("p")); + Assert.assertTrue("PERFORMER ARGUMENTS VALUES TEST: Please see the HINT Z above. Failing at: " + brushData.getName(), argumentValues.get("p").containsAll(performerHandles)); } } System.out.println("Performer Arguments VALUES Test OK!"); diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/integration/worldguard/WorldGuardIntegration.kt b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/integration/worldguard/WorldGuardIntegration.kt index 2f5efe7f..d8c87871 100644 --- a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/integration/worldguard/WorldGuardIntegration.kt +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/integration/worldguard/WorldGuardIntegration.kt @@ -17,7 +17,7 @@ class WorldGuardIntegration { private fun handleEvent(event: PlayerSnipeEvent) { if (event.isCancelled) return if (event.player.hasPermission("voxelsniper.bypass.worldguard")) return - //Check if each operation is within the worldguard area + //Check if each operationType is within the worldguard area val instance = WorldGuard.getInstance() val localPlayer = WorldGuardPlugin.inst().wrapPlayer((event.player as SpigotPlayer).player) val world = localPlayer.world From b0b9da7fb94aa5936b27e587ab21881dc44183c9 Mon Sep 17 00:00:00 2001 From: KevDaDev <65958288+KevinDaGame@users.noreply.github.com> Date: Fri, 17 Mar 2023 22:28:31 +0100 Subject: [PATCH 5/8] GenerateTreeBrush fixes (#121) * GenerateTreeBrush leaves are now persistant if leaf block is instance of leaves * Fixed roots * GenerateTreeBrush now works with any material * Optimize leaves performance * Rename IPersistent.kt to ILeaves.kt * Convert hashmap to hashSet * Refactor to placedLocations, fix floating roots * Remove log, fix merge conflict --- .../brush/multiBlock/GenerateTreeBrush.java | 74 ++++++++++--------- .../command/VoxelBrushCommand.java | 3 +- .../voxelsniper/blockdata/leaves/ILeaves.kt | 6 ++ .../blockdata/SpigotBlockData.java | 4 + .../blockdata/leaves/SpigotLeaves.kt | 14 ++++ 5 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/ILeaves.kt create mode 100644 VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/SpigotLeaves.kt diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java index 605e5e3d..de47b6a5 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/multiBlock/GenerateTreeBrush.java @@ -6,6 +6,7 @@ import com.github.kevindagame.util.VoxelMessage; import com.github.kevindagame.util.brushOperation.BlockOperation; import com.github.kevindagame.voxelsniper.block.IBlock; +import com.github.kevindagame.voxelsniper.blockdata.leaves.ILeaves; import com.github.kevindagame.voxelsniper.location.BaseLocation; import com.github.kevindagame.voxelsniper.location.VoxelLocation; import com.github.kevindagame.voxelsniper.material.VoxelMaterial; @@ -13,6 +14,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; +import java.util.stream.Collectors; // Proposal: Use /v and /vr for leave and wood material // or two more parameters -- Monofraps @@ -26,6 +28,7 @@ public class GenerateTreeBrush extends AbstractBrush { // Tree Variables. private final Random random = new Random(); private final ArrayList branchBlocks = new ArrayList<>(); + private final HashSet placedLocations = new HashSet<>(); private final int twistChance = 5; // This is a hidden value not available through Parameters. Otherwise messy. // If these default values are edited. Remember to change default values in the default preset. private VoxelMaterial leavesMaterial = VoxelMaterial.OAK_LEAVES; @@ -68,7 +71,8 @@ private void branchCreate(BaseLocation origin, final int xDirection, final int z } // Creates a branch block. - addOperation(new BlockOperation(location, location.getBlock().getBlockData(), this.woodMaterial.createBlockData())); + placedLocations.add(location.getBlock().getLocation()); + addOperation(new BlockOperation(location.clone(), location.getBlock().getBlockData(), this.woodMaterial.createBlockData())); this.branchBlocks.add(location.getBlock()); } } @@ -93,10 +97,7 @@ private void leafNodeCreate(final BaseLocation origin) { // Chance to skip creation of a block. if (this.chance(70)) { // If block is Air, create a leaf block. - if (location.getBlock().getRelative(x, y, z).getMaterial().isAir()) { - var block = location.getBlock().getRelative(x, y, z); - addOperation(new BlockOperation(block.getLocation(), block.getBlockData(), this.leavesMaterial.createBlockData())); - } + this.createLeaf(location, x, y, z); } for (int dx : new int[]{-1, 1}) { for (int dy : new int[]{-1, 1}) { @@ -112,12 +113,29 @@ private void leafNodeCreate(final BaseLocation origin) { } private void createLeaf(final BaseLocation location, int x, int y, int z) { - if (location.getBlock().getRelative(x, y, z).getMaterial().isAir()) { - var block = location.getBlock().getRelative(x, y, z); - addOperation(new BlockOperation(block.getLocation(), block.getBlockData(), this.leavesMaterial.createBlockData())); + var block = location.getBlock().getRelative(x, y, z); + if (block.getMaterial().isAir() && !placedLocations.contains(block.getLocation())) { + var blockData = this.leavesMaterial.createBlockData(); + if (blockData instanceof ILeaves) { + ((ILeaves) blockData).setPersistent(true); + } + var newLocation = block.getLocation(); + + addOperation(new BlockOperation(newLocation, block.getBlockData(), blockData)); + placedLocations.add(newLocation); } } + /** + * Generate a key for a location + * + * @param location the location + * @return "x:y:z" + */ + private String getKey(final BaseLocation location) { + return location.getX() + ":" + location.getY() + ":" + location.getZ(); + } + /** * Code Concerning Root Generation. * @@ -150,14 +168,11 @@ private void rootCreate(BaseLocation origin, final int xDirection, final int zDi // If not solid then... // Save for undo function - if (location.getBlock().getMaterial() != woodMaterial) { + if (location.getBlock().getMaterial() != woodMaterial && !location.getBlock().getMaterial().isAir()) { // Place log block. - addOperation(new BlockOperation(location, location.getBlock().getBlockData(), this.woodMaterial.createBlockData())); - } else { - // If solid then... - // End loop - break; + placedLocations.add(location.getBlock().getLocation()); + addOperation(new BlockOperation(location.clone(), location.getBlock().getBlockData(), this.woodMaterial.createBlockData())); } List blocks = Arrays.asList(VoxelMaterial.WATER, VoxelMaterial.SNOW, VoxelMaterial.OAK_LOG, VoxelMaterial.BIRCH_LOG, VoxelMaterial.ACACIA_LOG, VoxelMaterial.DARK_OAK_LOG, VoxelMaterial.SPRUCE_LOG, VoxelMaterial.JUNGLE_LOG); // Checks is block below is solid @@ -226,9 +241,10 @@ private void trunkCreate(final BaseLocation location) { private void createTrunk(final BaseLocation location, int x, int z) { // If block is air, then create a block. - if (location.getBlock().getRelative(x, 0, z).getMaterial().isAir()) { + var block = location.getBlock().getRelative(x, 0, z); + if (block.getMaterial().isAir() && !placedLocations.contains(block.getLocation())) { // Creates block. - var block = location.getBlock().getRelative(x, 0, z); + placedLocations.add(location.getBlock().getLocation()); addOperation(new BlockOperation(block.getLocation(), block.getBlockData(), this.woodMaterial.createBlockData())); } } @@ -335,7 +351,6 @@ private void trunkGen(final BaseLocation origin) { @Override protected final void arrow(final SnipeData v) { - this.branchBlocks.clear(); // Sets the location variables. @@ -392,14 +407,8 @@ public final void parseParameters(@NotNull final String triggerHandle, final Str if (params[0].equalsIgnoreCase("leaves")) { VoxelMaterial material = VoxelMaterial.getMaterial(params[1]); if (material == null) throw new IllegalArgumentException(); - - if (material == VoxelMaterial.OAK_LEAVES || material == VoxelMaterial.ACACIA_LEAVES || material == VoxelMaterial.SPRUCE_LEAVES - || material == VoxelMaterial.JUNGLE_LEAVES || material == VoxelMaterial.DARK_OAK_LEAVES || material == VoxelMaterial.BIRCH_LEAVES) { - this.leavesMaterial = material; - v.sendMessage(Messages.LEAVES_MAT_SET.replace("%leavesMaterial.name%", String.valueOf(this.leavesMaterial.getName()))); - } else { - throw new IllegalArgumentException(); - } + this.leavesMaterial = material; + v.sendMessage(Messages.LEAVES_MAT_SET.replace("%leavesMaterial.name%", String.valueOf(this.leavesMaterial.getName()))); return; } @@ -407,13 +416,8 @@ public final void parseParameters(@NotNull final String triggerHandle, final Str VoxelMaterial material = VoxelMaterial.getMaterial(params[1]); if (material == null) throw new IllegalArgumentException(); - if (material == VoxelMaterial.OAK_WOOD || material == VoxelMaterial.ACACIA_WOOD || material == VoxelMaterial.SPRUCE_WOOD - || material == VoxelMaterial.JUNGLE_WOOD || material == VoxelMaterial.DARK_OAK_WOOD || material == VoxelMaterial.BIRCH_WOOD) { - this.woodMaterial = material; - v.sendMessage(Messages.WOOD_LOG_MAT_SET.replace("%woodMaterial.name%", String.valueOf(this.woodMaterial.getName()))); - } else { - throw new IllegalArgumentException(); - } + this.woodMaterial = material; + v.sendMessage(Messages.WOOD_LOG_MAT_SET.replace("%woodMaterial.name%", String.valueOf(this.woodMaterial.getName()))); return; } } catch (IllegalArgumentException e) { @@ -573,12 +577,10 @@ public HashMap> registerArgumentValues() { argumentValues.put("rootFloat", Lists.newArrayList("true", "false")); // Wood material variables - argumentValues.put("wood", Lists.newArrayList(VoxelMaterial.OAK_WOOD.getName(), VoxelMaterial.ACACIA_WOOD.getName(), VoxelMaterial.SPRUCE_WOOD.getName(), VoxelMaterial.JUNGLE_WOOD.getName(), - VoxelMaterial.DARK_OAK_WOOD.getName(), VoxelMaterial.BIRCH_WOOD.getName())); + argumentValues.put("wood", VoxelMaterial.getMaterials().stream().map(VoxelMaterial::getName).collect(Collectors.toList())); // Leaves material variables - argumentValues.put("leaves", Lists.newArrayList(VoxelMaterial.OAK_LEAVES.getName(), VoxelMaterial.ACACIA_LEAVES.getName(), VoxelMaterial.SPRUCE_LEAVES.getName(), VoxelMaterial.JUNGLE_LEAVES.getName(), - VoxelMaterial.DARK_OAK_LEAVES.getName(), VoxelMaterial.BIRCH_LEAVES.getName())); + argumentValues.put("leaves", VoxelMaterial.getMaterials().stream().map(VoxelMaterial::getName).collect(Collectors.toList())); return argumentValues; } diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java index 968aa9df..8ddd1c99 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelBrushCommand.java @@ -84,12 +84,11 @@ public boolean doCommand(IPlayer player, final String[] args) { // Command: /b -- change brush to BrushData data = VoxelBrushManager.getInstance().getBrushForHandle(args[0]); - if (data == null) { snipeData.sendMessage(Messages.BRUSH_HANDLE_NOT_FOUND.replace("%arg%", args[0])); } else { IBrush oldBrush = sniper.getBrush(currentToolId); - IBrush newBrush = sniper.instantiateBrush(data); + IBrush newBrush = oldBrush != null && oldBrush.getName().equals(data.getName()) ? oldBrush : sniper.instantiateBrush(data); if (newBrush == null || !player.hasPermission(newBrush.getPermissionNode())) { snipeData.sendMessage(Messages.VOXEL_BRUSH_NO_PERMISSION); diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/ILeaves.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/ILeaves.kt new file mode 100644 index 00000000..ac0bf116 --- /dev/null +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/ILeaves.kt @@ -0,0 +1,6 @@ +package com.github.kevindagame.voxelsniper.blockdata.leaves + +interface ILeaves { + fun isPersistent(): Boolean + fun setPersistent(persistent: Boolean) +} \ No newline at end of file diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java index e114fb1b..0505b5ec 100644 --- a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/SpigotBlockData.java @@ -1,11 +1,13 @@ package com.github.kevindagame.voxelsniper.blockdata; +import com.github.kevindagame.voxelsniper.blockdata.leaves.SpigotLeaves; import com.github.kevindagame.voxelsniper.blockdata.redstoneWire.SpigotRedstoneWire; import com.github.kevindagame.voxelsniper.blockdata.waterlogged.SpigotWaterlogged; import com.github.kevindagame.voxelsniper.material.SpigotMaterial; import com.github.kevindagame.voxelsniper.material.VoxelMaterial; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; +import org.bukkit.block.data.type.Leaves; import org.bukkit.block.data.type.RedstoneWire; public class SpigotBlockData implements IBlockData { @@ -18,6 +20,8 @@ protected SpigotBlockData(BlockData blockData) { public static IBlockData fromSpigotData(BlockData blockData) { if (blockData instanceof RedstoneWire redstone) return new SpigotRedstoneWire(redstone); + if (blockData instanceof Leaves leaves) + return new SpigotLeaves(leaves); if (blockData instanceof Waterlogged waterlogged) return new SpigotWaterlogged(waterlogged); return new SpigotBlockData(blockData); diff --git a/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/SpigotLeaves.kt b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/SpigotLeaves.kt new file mode 100644 index 00000000..be39fea1 --- /dev/null +++ b/VoxelSniperSpigot/src/main/java/com/github/kevindagame/voxelsniper/blockdata/leaves/SpigotLeaves.kt @@ -0,0 +1,14 @@ +package com.github.kevindagame.voxelsniper.blockdata.leaves + +import com.github.kevindagame.voxelsniper.blockdata.SpigotBlockData +import org.bukkit.block.data.type.Leaves + +class SpigotLeaves(blockData: Leaves) : SpigotBlockData(blockData), ILeaves { + override fun isPersistent(): Boolean { + return (blockData as Leaves).isPersistent + } + + override fun setPersistent(persistent: Boolean) { + (blockData as Leaves).isPersistent = persistent + } +} From 957b239551db7220ea8e9d8dee5e684f96fcd0e5 Mon Sep 17 00:00:00 2001 From: KevDaDev <65958288+KevinDaGame@users.noreply.github.com> Date: Fri, 17 Mar 2023 22:52:29 +0100 Subject: [PATCH 6/8] Create PolymorphicBrushTest.kt --- .../brush/polymorphic/PolymorphicBrushTest.kt | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 VoxelSniperCore/src/test/java/com/github/kevindagame/brush/polymorphic/PolymorphicBrushTest.kt diff --git a/VoxelSniperCore/src/test/java/com/github/kevindagame/brush/polymorphic/PolymorphicBrushTest.kt b/VoxelSniperCore/src/test/java/com/github/kevindagame/brush/polymorphic/PolymorphicBrushTest.kt new file mode 100644 index 00000000..a2105602 --- /dev/null +++ b/VoxelSniperCore/src/test/java/com/github/kevindagame/brush/polymorphic/PolymorphicBrushTest.kt @@ -0,0 +1,73 @@ +package com.github.kevindagame.brush.polymorphic + +import com.github.kevindagame.brush.polymorphic.operation.BlendOperation +import com.github.kevindagame.brush.polymorphic.operation.PolyOperation +import com.github.kevindagame.brush.polymorphic.property.* +import org.junit.Before +import org.junit.Test + +class PolymorphicBrushTest { + + @Test + fun ball_brush_should_have_performer_and_smooth() { + //arrange + val brush = PolyBrush( + "Test", + "test", + mutableListOf(PolyBrushShape.BALL), + PolyOperationType.BLOCK, + null + ) + + //act + val hasPerformers = brush.properties.any { it is PerformerProperty } + val hasSmooth = brush.properties.any { it is SmoothProperty } + + //assert + assert(hasPerformers) + assert(hasSmooth) + } + + @Test + fun biome_should_not_have_performer_or_smooth_but_biome_property() { + //arrange + val brush = PolyBrush( + "Test", + "test", + mutableListOf(), + PolyOperationType.BIOME, + null + ) + + //act + val hasPerformers = brush.properties.any { it is PerformerProperty } + val hasBiome = brush.properties.any { it is BiomeProperty } + val hasSmoothProperty = brush.properties.any { it is SmoothProperty } + + //assert + assert(!hasPerformers) + assert(hasBiome) + assert(!hasSmoothProperty) + } + + @Test + fun operation_brush_should_have_exclude_water_and_exclude_air() { + //arrange + val brush = PolyBrush( + "Test", + "test", + mutableListOf(), + PolyOperationType.BLOCK, + BlendOperation() + ) + + //act + val hasExcludeWater = brush.properties.any { it is ExcludeWaterProperty } + val hasExcludeAir = brush.properties.any { it is ExcludeAirProperty } + + //assert + assert(hasExcludeWater) + assert(hasExcludeAir) + } + +} \ No newline at end of file From 016f64bc00316c7c6d823d536a621697ab4a21f5 Mon Sep 17 00:00:00 2001 From: KevDaDev <65958288+KevinDaGame@users.noreply.github.com> Date: Fri, 17 Mar 2023 23:05:05 +0100 Subject: [PATCH 7/8] Move InitOnceProperty --- .../src/main/java/com/github/kevindagame/brush/IBrush.kt | 2 +- .../com/github/kevindagame}/util/InitOnceProperty.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename VoxelSniperCore/src/main/{kotlin => java/com/github/kevindagame}/util/InitOnceProperty.kt (94%) diff --git a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt index 5969e13b..e92df47f 100644 --- a/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/brush/IBrush.kt @@ -4,7 +4,7 @@ import com.github.kevindagame.snipe.SnipeAction import com.github.kevindagame.snipe.SnipeData import com.github.kevindagame.util.VoxelMessage import com.github.kevindagame.voxelsniper.block.IBlock -import util.InitOnceProperty +import com.github.kevindagame.util.InitOnceProperty import kotlin.properties.ReadWriteProperty inline fun initOnce(): ReadWriteProperty = InitOnceProperty() diff --git a/VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/InitOnceProperty.kt similarity index 94% rename from VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt rename to VoxelSniperCore/src/main/java/com/github/kevindagame/util/InitOnceProperty.kt index 172c4f94..cf6fb7ec 100644 --- a/VoxelSniperCore/src/main/kotlin/util/InitOnceProperty.kt +++ b/VoxelSniperCore/src/main/java/com/github/kevindagame/util/InitOnceProperty.kt @@ -1,4 +1,4 @@ -package util +package com.github.kevindagame.util import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty From b957d59d53d821358d8d687948ceb395ba0df0d6 Mon Sep 17 00:00:00 2001 From: KevDaDev <65958288+KevinDaGame@users.noreply.github.com> Date: Fri, 17 Mar 2023 23:05:33 +0100 Subject: [PATCH 8/8] Bump version --- buildSrc/src/main/kotlin/voxel-core.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/voxel-core.gradle.kts b/buildSrc/src/main/kotlin/voxel-core.gradle.kts index 3f620274..6bff8cb6 100644 --- a/buildSrc/src/main/kotlin/voxel-core.gradle.kts +++ b/buildSrc/src/main/kotlin/voxel-core.gradle.kts @@ -48,7 +48,7 @@ java { } group = "com.github.kevindagame" -version = "8.4.3" +version = "8.5.0" //java.sourceCompatibility = JavaVersion.VERSION_16 tasks.withType {