Skip to content

Commit

Permalink
Feat/version 8.4.0 code cleanup (#104)
Browse files Browse the repository at this point in the history
* Code cleanup

* Intellij automated code cleanup
  • Loading branch information
KevinDaGame authored Jan 8, 2023
1 parent 03dc3c8 commit 4941250
Show file tree
Hide file tree
Showing 144 changed files with 557 additions and 528 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.kevindagame;

import com.github.kevindagame.brush.MultiBlock.*;
import com.github.kevindagame.brush.Shell.*;
import com.google.common.base.Preconditions;
import com.github.kevindagame.brush.*;
import com.github.kevindagame.brush.multiBlock.*;
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 java.util.*;

Expand All @@ -15,6 +17,7 @@ public class VoxelBrushManager {
private static VoxelBrushManager instance = null;

private final Map<String, Class<? extends IBrush>> brushes = new HashMap<>();

public static VoxelBrushManager getInstance() {
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.kevindagame;

import com.google.common.collect.Maps;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ abstract class AbstractBrush : IBrush {
* Brush name.
*/
private var name = "Undefined"
protected var cancelled = false
protected var snipeAction: SnipeAction? = null

private fun preparePerform(v: SnipeData, clickedBlock: IBlock, clickedFace: BlockFace): Boolean {
Expand Down Expand Up @@ -93,22 +92,27 @@ abstract class AbstractBrush : IBrush {

protected fun performOperations(data: SnipeData): Boolean {
if (operations.size == 0) return false
val event = PlayerSnipeEvent(data.owner().player, this, ImmutableList.copyOf(operations), operations.any { o -> o is CustomOperation }).callEvent()
val event = PlayerSnipeEvent(
data.owner().player,
this,
ImmutableList.copyOf(operations),
operations.any { o -> o is CustomOperation }).callEvent()
if (!event.isCancelled) {
val undo = Undo()
var reloadArea = false
if (event.isCustom && this is CustomBrush) {
this.perform(event.operations.stream().filter { o -> !o.isCancelled && o is CustomOperation }.map { o -> o as CustomOperation }.collect(ImmutableList.toImmutableList()), data, undo)
this.perform(event.operations.stream().filter { o -> !o.isCancelled && o is CustomOperation }
.map { o -> o as CustomOperation }.collect(ImmutableList.toImmutableList()), data, undo)
} else {
for (operation in event.operations) {
if (!operation.isCancelled) {
if (executeOperation(operation, undo)) {
reloadArea = true;
reloadArea = true
}
}
}
}
data.owner().storeUndo(undo);
data.owner().storeUndo(undo)
if (reloadArea) {
reloadBrushArea(data)
}
Expand Down Expand Up @@ -193,7 +197,7 @@ abstract class AbstractBrush : IBrush {
val rangeBlockHelper: BlockHelper
if (v.owner().getSnipeData(v.owner().currentToolId).isRanged) {
rangeBlockHelper = BlockHelper(
v.owner().player, v.owner().getSnipeData(v.owner().currentToolId).range
v.owner().player, v.owner().getSnipeData(v.owner().currentToolId).range
.toDouble()
)
targetBlock = rangeBlockHelper.rangeBlock
Expand Down Expand Up @@ -282,10 +286,6 @@ abstract class AbstractBrush : IBrush {
}
}

protected fun cancel() {
cancelled = true
}

companion object {
protected const val CHUNK_SIZE = 16
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -62,6 +63,8 @@ public final void parseParameters(final String triggerHandle, final String[] par
sendPerformerMessage(triggerHandle, v);
}


@NotNull
@Override
public List<String> registerArguments() {
List<String> arguments = new ArrayList<>();
Expand All @@ -70,6 +73,7 @@ public List<String> registerArguments() {
arguments.addAll(super.registerArguments());
return arguments;
}

@Override
public String getPermissionNode() {
return "voxelsniper.brush.ball";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BiomeOperation;
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;

Expand All @@ -16,10 +17,11 @@
*/
public class BiomeBallBrush extends AbstractBrush {

private VoxelBiome selectedBiome = VoxelBiome.PLAINS;

public BiomeBallBrush() {
this.setName("Biome ball");
}
private VoxelBiome selectedBiome = VoxelBiome.PLAINS;

@Override
public void info(VoxelMessage vm) {
Expand Down Expand Up @@ -48,8 +50,9 @@ 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(final String triggerHandle, final String[] params, final SnipeData v) {
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;
Expand All @@ -63,6 +66,7 @@ public final void parseParameters(final String triggerHandle, final String[] par
}
}

@NotNull
@Override
public List<String> registerArguments() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BiomeOperation;
import com.github.kevindagame.util.Messages;
import com.github.kevindagame.util.VoxelMessage;
import com.github.kevindagame.util.brushOperation.BiomeOperation;
import com.github.kevindagame.voxelsniper.biome.VoxelBiome;
import com.github.kevindagame.voxelsniper.location.BaseLocation;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -56,7 +57,7 @@ public final void info(final VoxelMessage vm) {
}

@Override
public final void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) {
public final void parseParameters(@NotNull final String triggerHandle, final String[] params, @NotNull final SnipeData v) {
if (params[0].equalsIgnoreCase("info")) {
v.sendMessage(Messages.BIOME_BRUSH_USAGE.replace("%triggerHandle%", triggerHandle));
return;
Expand All @@ -70,6 +71,7 @@ public final void parseParameters(final String triggerHandle, final String[] par
}
}

@NotNull
@Override
public List<String> registerArguments() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BlockOperation;
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;

/**
* <a href="https://github.com/KevinDaGame/VoxelSniper-Reimagined/wiki/Brushes#blend-ball-brush">...</a>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.voxelsniper.material.VoxelMaterial;
import com.google.common.collect.Lists;
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;
Expand All @@ -19,10 +20,8 @@ public abstract class BlendBrushBase extends AbstractBrush {
protected boolean excludeAir = true;
protected boolean excludeWater = true;

/**
* @param v
*/
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
Expand Down Expand Up @@ -184,7 +183,7 @@ public final void info(final VoxelMessage vm) {
}

@Override
public void parseParameters(final String triggerHandle, final String[] params, final SnipeData v) {
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());
Expand All @@ -198,11 +197,13 @@ public void parseParameters(final String triggerHandle, final String[] params, f
v.sendMessage(Messages.BRUSH_INVALID_PARAM.replace("%triggerHandle%", triggerHandle));
}

@NotNull
@Override
public List<String> registerArguments() {
return new ArrayList<>(Lists.newArrayList("water"));
}

@NotNull
@Override
public HashMap<String, List<String>> registerArgumentValues() {
HashMap<String, List<String>> argumentValues = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BlockOperation;
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;

/**
Expand All @@ -24,7 +24,7 @@ protected final void blend(final SnipeData v) {
var brushSize = v.getBrushSize();
var newMaterials = this.blend2D(brushSize);

for(var position : positions) {
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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BlockOperation;
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;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BlockOperation;
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;

/**
Expand All @@ -24,7 +24,7 @@ protected final void blend(final SnipeData v) {
var brushSize = v.getBrushSize();
var newMaterials = this.blend2D(brushSize);

for(var position : positions) {
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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.voxelsniper.location.BaseLocation;
import com.google.common.collect.Lists;
import com.github.kevindagame.brush.perform.PerformerBrush;
import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.Messages;
import com.github.kevindagame.util.VoxelMessage;
import com.github.kevindagame.voxelsniper.location.BaseLocation;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

/**
* <a href="https://github.com/KevinDaGame/VoxelSniper-Reimagined/wiki/Brushes#blob-brush">...</a>
Expand Down Expand Up @@ -249,6 +253,7 @@ public final void parseParameters(final String triggerHandle, final String[] par
sendPerformerMessage(triggerHandle, v);
}

@NotNull
@Override
public List<String> registerArguments() {
List<String> arguments = new ArrayList<>();
Expand All @@ -258,6 +263,7 @@ public List<String> registerArguments() {
return arguments;
}

@NotNull
@Override
public HashMap<String, List<String>> registerArgumentValues() {
HashMap<String, List<String>> argumentValues = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.util.brushOperation.BlockOperation;
import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.Shapes;
import com.github.kevindagame.util.VoxelMessage;
import com.github.kevindagame.util.brushOperation.BlockOperation;
import com.github.kevindagame.voxelsniper.location.BaseLocation;
import com.github.kevindagame.voxelsniper.material.VoxelMaterial;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.kevindagame.brush;

import com.github.kevindagame.snipe.SnipeData;
import com.github.kevindagame.util.brushOperation.BlockOperation;
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.location.BaseLocation;
import com.github.kevindagame.voxelsniper.material.VoxelMaterial;
Expand All @@ -24,6 +24,7 @@
* be about 1.5x slower than the original brush. Savings increase for larger brushes.
* <br>
* <a href="https://github.com/KevinDaGame/VoxelSniper-Reimagined/wiki/Brushes#block-reset-brush-surface-only-brush">...</a>
*
* @author GavJenks
*/
public class BlockResetSurfaceBrush extends AbstractBrush {
Expand Down Expand Up @@ -83,7 +84,7 @@ private void applyBrush(final SnipeData v) {
boolean airFound;

airFound = checkBlock(world, x + 1, y, z);
airFound = checkBlock(world, x -1, y, z) || airFound;
airFound = checkBlock(world, x - 1, y, z) || airFound;
airFound = checkBlock(world, x, y + 1, z) || airFound;
airFound = checkBlock(world, x, y - 1, z) || airFound;
airFound = checkBlock(world, x, y, z + 1) || airFound;
Expand Down
Loading

0 comments on commit 4941250

Please sign in to comment.