Minor FAVS cleanup

This commit is contained in:
NotMyFault 2019-04-19 13:50:03 +02:00
parent a22ba45b1c
commit 8d182abd3e
30 changed files with 292 additions and 657 deletions

View File

@ -1,10 +1,6 @@
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'maven' apply plugin: 'maven'
repositories {
maven {url "https://ci.athion.net/job/FAWE-WorldGuard-1.13/lastSuccessfulBuild/artifact/mvn"}
}
dependencies { dependencies {
compile project(':worldedit-bukkit') compile project(':worldedit-bukkit')
compile 'com.martiansoftware:jsap:2.1' compile 'com.martiansoftware:jsap:2.1'

View File

@ -13,21 +13,18 @@ import java.util.Set;
/** /**
* Brush registration manager. * Brush registration manager.
*/ */
public class Brushes public class Brushes {
{
private Multimap<Class<? extends IBrush>, String> brushes = HashMultimap.create(); private Multimap<Class<? extends IBrush>, String> brushes = HashMultimap.create();
/** /**
* Register a brush for VoxelSniper to be able to use. * Register a brush for VoxelSniper to be able to use.
* *
* @param clazz Brush implementing IBrush interface. * @param clazz Brush implementing IBrush interface.
* @param handles Handles under which the brush can be accessed ingame. * @param handles Handles under which the brush can be accessed ingame.
*/ */
public void registerSniperBrush(Class<? extends IBrush> clazz, String... handles) public void registerSniperBrush(Class<? extends IBrush> clazz, String... handles) {
{
Preconditions.checkNotNull(clazz, "Cannot register null as a class."); Preconditions.checkNotNull(clazz, "Cannot register null as a class.");
for (String handle : handles) for (String handle : handles) {
{
brushes.put(clazz, handle.toLowerCase()); brushes.put(clazz, handle.toLowerCase());
} }
} }
@ -38,18 +35,14 @@ public class Brushes
* @param handle Case insensitive brush handle * @param handle Case insensitive brush handle
* @return Brush class * @return Brush class
*/ */
public Class<? extends IBrush> getBrushForHandle(String handle) public Class<? extends IBrush> getBrushForHandle(String handle) {
{
Preconditions.checkNotNull(handle, "Brushhandle can not be null."); Preconditions.checkNotNull(handle, "Brushhandle can not be null.");
if (!brushes.containsValue(handle.toLowerCase())) if (!brushes.containsValue(handle.toLowerCase())) {
{
return null; return null;
} }
for (Map.Entry<Class<? extends IBrush>, String> entry : brushes.entries()) for (Map.Entry<Class<? extends IBrush>, String> entry : brushes.entries()) {
{ if (entry.getValue().equalsIgnoreCase(handle)) {
if (entry.getValue().equalsIgnoreCase(handle))
{
return entry.getKey(); return entry.getKey();
} }
} }
@ -59,34 +52,29 @@ public class Brushes
/** /**
* @return Amount of IBrush classes registered with the system under Sniper visibility. * @return Amount of IBrush classes registered with the system under Sniper visibility.
*/ */
public int registeredSniperBrushes() public int registeredSniperBrushes() {
{
return brushes.keySet().size(); return brushes.keySet().size();
} }
/** /**
* @return Amount of handles registered with the system under Sniper visibility. * @return Amount of handles registered with the system under Sniper visibility.
*/ */
public int registeredSniperBrushHandles() public int registeredSniperBrushHandles() {
{
return brushes.size(); return brushes.size();
} }
/** /**
*
* @param clazz Brush class * @param clazz Brush class
* @return All Sniper registered handles for the brush. * @return All Sniper registered handles for the brush.
*/ */
public Set<String> getSniperBrushHandles(Class<? extends IBrush> clazz) public Set<String> getSniperBrushHandles(Class<? extends IBrush> clazz) {
{
return new HashSet<>(brushes.get(clazz)); return new HashSet<>(brushes.get(clazz));
} }
/** /**
* @return Immutable Multimap copy of all the registered brushes * @return Immutable Multimap copy of all the registered brushes
*/ */
public Multimap<Class<?extends IBrush>, String> getRegisteredBrushesMultimap() public Multimap<Class<? extends IBrush>, String> getRegisteredBrushesMultimap() {
{
return ImmutableMultimap.copyOf(brushes); return ImmutableMultimap.copyOf(brushes);
} }
} }

View File

@ -1,23 +1,19 @@
package com.thevoxelbox.voxelsniper; package com.thevoxelbox.voxelsniper;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
/** /**
* *
*/ */
public class Message public class Message {
{
private static final int BRUSH_SIZE_WARNING_THRESHOLD = 20; private static final int BRUSH_SIZE_WARNING_THRESHOLD = 20;
private final SnipeData snipeData; private final SnipeData snipeData;
/** /**
* @param snipeData * @param snipeData
*/ */
public Message(SnipeData snipeData) public Message(SnipeData snipeData) {
{
this.snipeData = snipeData; this.snipeData = snipeData;
} }
@ -26,8 +22,7 @@ public class Message
* *
* @param brushMessage * @param brushMessage
*/ */
public void brushMessage(String brushMessage) public void brushMessage(String brushMessage) {
{
snipeData.sendMessage(ChatColor.LIGHT_PURPLE + brushMessage); snipeData.sendMessage(ChatColor.LIGHT_PURPLE + brushMessage);
} }
@ -36,16 +31,14 @@ public class Message
* *
* @param brushName * @param brushName
*/ */
public void brushName(String brushName) public void brushName(String brushName) {
{
snipeData.sendMessage(ChatColor.AQUA + "Brush Type: " + ChatColor.LIGHT_PURPLE + brushName); snipeData.sendMessage(ChatColor.AQUA + "Brush Type: " + ChatColor.LIGHT_PURPLE + brushName);
} }
/** /**
* Display Center Parameter. * Display Center Parameter.
*/ */
public void center() public void center() {
{
snipeData.sendMessage(ChatColor.DARK_BLUE + "Brush Center: " + ChatColor.DARK_RED + snipeData.getcCen()); snipeData.sendMessage(ChatColor.DARK_BLUE + "Brush Center: " + ChatColor.DARK_RED + snipeData.getcCen());
} }
@ -54,24 +47,21 @@ public class Message
* *
* @param message * @param message
*/ */
public void custom(String message) public void custom(String message) {
{
snipeData.sendMessage(message); snipeData.sendMessage(message);
} }
/** /**
* Display data value. * Display data value.
*/ */
public void data() public void data() {
{
snipeData.sendMessage(ChatColor.BLUE + "Data Variable: " + ChatColor.DARK_RED + snipeData.getPropertyId()); snipeData.sendMessage(ChatColor.BLUE + "Data Variable: " + ChatColor.DARK_RED + snipeData.getPropertyId());
} }
/** /**
* Display voxel height. * Display voxel height.
*/ */
public void height() public void height() {
{
snipeData.sendMessage(ChatColor.DARK_AQUA + "Brush Height: " + ChatColor.DARK_RED + snipeData.getVoxelHeight()); snipeData.sendMessage(ChatColor.DARK_AQUA + "Brush Height: " + ChatColor.DARK_RED + snipeData.getVoxelHeight());
} }
@ -80,8 +70,7 @@ public class Message
* *
* @param performerName * @param performerName
*/ */
public void performerName(String performerName) public void performerName(String performerName) {
{
this.snipeData.sendMessage(ChatColor.DARK_PURPLE + "Performer: " + ChatColor.DARK_GREEN + performerName); this.snipeData.sendMessage(ChatColor.DARK_PURPLE + "Performer: " + ChatColor.DARK_GREEN + performerName);
} }
@ -89,27 +78,23 @@ public class Message
* Displaye replace material. * Displaye replace material.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void replace() public void replace() {
{
snipeData.sendMessage(ChatColor.AQUA + "Replace Material: " + BlockTypes.get(snipeData.getReplaceId())); snipeData.sendMessage(ChatColor.AQUA + "Replace Material: " + BlockTypes.get(snipeData.getReplaceId()));
} }
/** /**
* Display replace data value. * Display replace data value.
*/ */
public void replaceData() public void replaceData() {
{
snipeData.sendMessage(ChatColor.DARK_GRAY + "Replace Data Variable: " + ChatColor.DARK_RED + snipeData.getReplaceData()); snipeData.sendMessage(ChatColor.DARK_GRAY + "Replace Data Variable: " + ChatColor.DARK_RED + snipeData.getReplaceData());
} }
/** /**
* Display brush size. * Display brush size.
*/ */
public void size() public void size() {
{
snipeData.sendMessage(ChatColor.GREEN + "Brush Size: " + ChatColor.DARK_RED + snipeData.getBrushSize()); snipeData.sendMessage(ChatColor.GREEN + "Brush Size: " + ChatColor.DARK_RED + snipeData.getBrushSize());
if (snipeData.getBrushSize() >= BRUSH_SIZE_WARNING_THRESHOLD) if (snipeData.getBrushSize() >= BRUSH_SIZE_WARNING_THRESHOLD) {
{
snipeData.sendMessage(ChatColor.RED + "WARNING: Large brush size selected!"); snipeData.sendMessage(ChatColor.RED + "WARNING: Large brush size selected!");
} }
} }
@ -117,24 +102,21 @@ public class Message
/** /**
* Display toggle lightning message. * Display toggle lightning message.
*/ */
public void toggleLightning() public void toggleLightning() {
{
snipeData.sendMessage(ChatColor.GOLD + "Lightning mode has been toggled " + ChatColor.DARK_RED + ((snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).isLightningEnabled()) ? "on" : "off")); snipeData.sendMessage(ChatColor.GOLD + "Lightning mode has been toggled " + ChatColor.DARK_RED + ((snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).isLightningEnabled()) ? "on" : "off"));
} }
/** /**
* Display toggle printout message. * Display toggle printout message.
*/ */
public final void togglePrintout() public final void togglePrintout() {
{
snipeData.sendMessage(ChatColor.GOLD + "Brush info printout mode has been toggled " + ChatColor.DARK_RED + ((snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).isLightningEnabled()) ? "on" : "off")); snipeData.sendMessage(ChatColor.GOLD + "Brush info printout mode has been toggled " + ChatColor.DARK_RED + ((snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).isLightningEnabled()) ? "on" : "off"));
} }
/** /**
* Display toggle range message. * Display toggle range message.
*/ */
public void toggleRange() public void toggleRange() {
{
snipeData.sendMessage(ChatColor.GOLD + "Distance Restriction toggled " + ChatColor.DARK_RED + ((snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).isRanged()) ? "on" : "off") + ChatColor.GOLD + ". Range is " + ChatColor.LIGHT_PURPLE + (double) snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).getRange()); snipeData.sendMessage(ChatColor.GOLD + "Distance Restriction toggled " + ChatColor.DARK_RED + ((snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).isRanged()) ? "on" : "off") + ChatColor.GOLD + ". Range is " + ChatColor.LIGHT_PURPLE + (double) snipeData.owner().getSnipeData(snipeData.owner().getCurrentToolId()).getRange());
} }
@ -142,22 +124,17 @@ public class Message
* Display voxel type. * Display voxel type.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void voxel() public void voxel() {
{
snipeData.sendMessage(ChatColor.GOLD + "Voxel: " + ChatColor.RED + BlockTypes.get(snipeData.getVoxelId())); snipeData.sendMessage(ChatColor.GOLD + "Voxel: " + ChatColor.RED + BlockTypes.get(snipeData.getVoxelId()));
} }
/** /**
* Display voxel list. * Display voxel list.
*/ */
public void voxelList() public void voxelList() {
{ if (snipeData.getVoxelList().isEmpty()) {
if (snipeData.getVoxelList().isEmpty())
{
snipeData.sendMessage(ChatColor.DARK_GREEN + "No blocks selected!"); snipeData.sendMessage(ChatColor.DARK_GREEN + "No blocks selected!");
} } else {
else
{
String returnValueBuilder = ChatColor.DARK_GREEN + "Block Types Selected: " + ChatColor.AQUA String returnValueBuilder = ChatColor.DARK_GREEN + "Block Types Selected: " + ChatColor.AQUA
+ snipeData.getVoxelList(); + snipeData.getVoxelList();
snipeData.sendMessage(returnValueBuilder); snipeData.sendMessage(returnValueBuilder);

View File

@ -4,96 +4,72 @@ import org.bukkit.Art;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Painting; import org.bukkit.entity.Painting;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Set;
/** /**
* Painting state change handler. * Painting state change handler.
* *
* @author Piotr * @author Piotr
*/ */
public final class PaintingWrapper public final class PaintingWrapper {
{
private PaintingWrapper() private PaintingWrapper() {
{
} }
/** /**
* The paint method used to scroll or set a painting to a specific type. * The paint method used to scroll or set a painting to a specific type.
* *
* @param p * @param p The player executing the method
* The player executing the method * @param auto Scroll automatically? If false will use 'choice' to try and set the painting
* @param auto * @param back Scroll in reverse?
* Scroll automatically? If false will use 'choice' to try and set the painting * @param choice Chosen index to set the painting to
* @param back
* Scroll in reverse?
* @param choice
* Chosen index to set the painting to
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void paint(final Player p, final boolean auto, final boolean back, final int choice) public static void paint(final Player p, final boolean auto, final boolean back, final int choice) {
{
Location targetLocation = p.getTargetBlock(null, 4).getLocation(); Location targetLocation = p.getTargetBlock(null, 4).getLocation();
Chunk paintingChunk = p.getTargetBlock(null, 4).getLocation().getChunk(); Chunk paintingChunk = p.getTargetBlock(null, 4).getLocation().getChunk();
Double bestDistanceMatch = 50D; Double bestDistanceMatch = 50D;
Painting bestMatch = null; Painting bestMatch = null;
for (Entity entity : paintingChunk.getEntities()) for (Entity entity : paintingChunk.getEntities()) {
{ if (entity.getType() == EntityType.PAINTING) {
if (entity.getType() == EntityType.PAINTING)
{
Double distance = targetLocation.distanceSquared(entity.getLocation()); Double distance = targetLocation.distanceSquared(entity.getLocation());
if (distance <= 4 && distance < bestDistanceMatch) if (distance <= 4 && distance < bestDistanceMatch) {
{
bestDistanceMatch = distance; bestDistanceMatch = distance;
bestMatch = (Painting) entity; bestMatch = (Painting) entity;
} }
} }
} }
if (bestMatch != null) if (bestMatch != null) {
{ if (auto) {
if (auto) try {
{
try
{
final int i = bestMatch.getArt().getId() + (back ? -1 : 1); final int i = bestMatch.getArt().getId() + (back ? -1 : 1);
Art art = Art.getById(i); Art art = Art.getById(i);
if (art == null) if (art == null) {
{
p.sendMessage(ChatColor.RED + "This is the final painting, try scrolling to the other direction."); p.sendMessage(ChatColor.RED + "This is the final painting, try scrolling to the other direction.");
return; return;
} }
bestMatch.setArt(art); bestMatch.setArt(art);
p.sendMessage(ChatColor.GREEN + "Painting set to ID: " + (i)); p.sendMessage(ChatColor.GREEN + "Painting set to ID: " + (i));
} } catch (final Exception e) {
catch (final Exception e)
{
p.sendMessage(ChatColor.RED + "Oops. Something went wrong."); p.sendMessage(ChatColor.RED + "Oops. Something went wrong.");
} }
} } else {
else try {
{
try
{
Art art = Art.getById(choice); Art art = Art.getById(choice);
bestMatch.setArt(art); bestMatch.setArt(art);
p.sendMessage(ChatColor.GREEN + "Painting set to ID: " + choice); p.sendMessage(ChatColor.GREEN + "Painting set to ID: " + choice);
} } catch (final Exception exception) {
catch (final Exception exception)
{
p.sendMessage(ChatColor.RED + "Your input was invalid somewhere."); p.sendMessage(ChatColor.RED + "Your input was invalid somewhere.");
} }
} }

View File

@ -30,8 +30,6 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class RangeBlockHelper { public class RangeBlockHelper {

View File

@ -1,9 +1,8 @@
package com.thevoxelbox.voxelsniper; package com.thevoxelbox.voxelsniper;
/** /**
* *
*/ */
public enum SnipeAction public enum SnipeAction {
{
ARROW, GUNPOWDER ARROW, GUNPOWDER
} }

View File

@ -44,25 +44,16 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.*; import com.google.common.collect.*;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.MaskingExtent; import com.sk89q.worldedit.extent.MaskingExtent;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.brush.IBrush; import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.brush.SnipeBrush; import com.thevoxelbox.voxelsniper.brush.SnipeBrush;
import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush;
import com.thevoxelbox.voxelsniper.brush.perform.Performer; import com.thevoxelbox.voxelsniper.brush.perform.Performer;
import com.thevoxelbox.voxelsniper.event.SniperMaterialChangedEvent;
import com.thevoxelbox.voxelsniper.event.SniperReplaceMaterialChangedEvent;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -72,9 +63,13 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class Sniper { public class Sniper {
private VoxelSniper plugin; private VoxelSniper plugin;
private final UUID player; private final UUID player;

View File

@ -9,20 +9,16 @@ import java.util.UUID;
/** /**
* *
*/ */
public class SniperManager public class SniperManager {
{
private Map<UUID, Sniper> sniperInstances = Maps.newHashMap(); private Map<UUID, Sniper> sniperInstances = Maps.newHashMap();
private VoxelSniper plugin; private VoxelSniper plugin;
public SniperManager(VoxelSniper plugin) public SniperManager(VoxelSniper plugin) {
{
this.plugin = plugin; this.plugin = plugin;
} }
public Sniper getSniperForPlayer(Player player) public Sniper getSniperForPlayer(Player player) {
{ if (sniperInstances.get(player.getUniqueId()) == null) {
if (sniperInstances.get(player.getUniqueId()) == null)
{
sniperInstances.put(player.getUniqueId(), new Sniper(plugin, player)); sniperInstances.put(player.getUniqueId(), new Sniper(plugin, player));
} }
return sniperInstances.get(player.getUniqueId()); return sniperInstances.get(player.getUniqueId());

View File

@ -1,34 +1,19 @@
package com.thevoxelbox.voxelsniper; package com.thevoxelbox.voxelsniper;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.BukkitCommand; import com.boydti.fawe.bukkit.BukkitCommand;
import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.util.Jars;
import com.boydti.fawe.util.MainUtil;
import com.google.common.base.Preconditions;
import com.thevoxelbox.voxelsniper.brush.*; import com.thevoxelbox.voxelsniper.brush.*;
import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush;
import com.thevoxelbox.voxelsniper.command.VoxelVoxelCommand;
import com.thevoxelbox.voxelsniper.event.SniperBrushChangedEvent;
import com.thevoxelbox.voxelsniper.event.SniperMaterialChangedEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/** /**
* Bukkit extension point. * Bukkit extension point.
*/ */
public class VoxelSniper extends JavaPlugin public class VoxelSniper extends JavaPlugin {
{
private static VoxelSniper instance; private static VoxelSniper instance;
private SniperManager sniperManager = new SniperManager(this); private SniperManager sniperManager = new SniperManager(this);
private final VoxelSniperListener voxelSniperListener = new VoxelSniperListener(this); private final VoxelSniperListener voxelSniperListener = new VoxelSniperListener(this);
@ -39,8 +24,7 @@ public class VoxelSniper extends JavaPlugin
* *
* @return Brush Manager for current instance. * @return Brush Manager for current instance.
*/ */
public Brushes getBrushManager() public Brushes getBrushManager() {
{
return brushManager; return brushManager;
} }
@ -49,8 +33,7 @@ public class VoxelSniper extends JavaPlugin
/** /**
* @return {@link VoxelSniper} * @return {@link VoxelSniper}
*/ */
public static VoxelSniper getInstance() public static VoxelSniper getInstance() {
{
return VoxelSniper.instance; return VoxelSniper.instance;
} }
@ -59,8 +42,7 @@ public class VoxelSniper extends JavaPlugin
* *
* @return {@link VoxelSniperConfiguration} object for accessing global VoxelSniper options. * @return {@link VoxelSniperConfiguration} object for accessing global VoxelSniper options.
*/ */
public VoxelSniperConfiguration getVoxelSniperConfiguration() public VoxelSniperConfiguration getVoxelSniperConfiguration() {
{
return voxelSniperConfiguration; return voxelSniperConfiguration;
} }
@ -69,20 +51,16 @@ public class VoxelSniper extends JavaPlugin
* *
* @return SniperManager * @return SniperManager
*/ */
public SniperManager getSniperManager() public SniperManager getSniperManager() {
{
return sniperManager; return sniperManager;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
{ if (sender instanceof Player) {
if (sender instanceof Player)
{
String[] arguments = args; String[] arguments = args;
if (arguments == null) if (arguments == null) {
{
arguments = new String[0]; arguments = new String[0];
} }
@ -94,8 +72,7 @@ public class VoxelSniper extends JavaPlugin
} }
@Override @Override
public void onEnable() public void onEnable() {
{
VoxelSniper.instance = this; VoxelSniper.instance = this;
registerBrushes(); registerBrushes();
@ -134,14 +111,14 @@ public class VoxelSniper extends JavaPlugin
} }
}); });
} catch (Throwable ignore) {} } catch (Throwable ignore) {
}
} }
/** /**
* Registers all brushes. * Registers all brushes.
*/ */
public void registerBrushes() public void registerBrushes() {
{
brushManager.registerSniperBrush(BallBrush.class, "b", "ball"); brushManager.registerSniperBrush(BallBrush.class, "b", "ball");
brushManager.registerSniperBrush(BiomeBrush.class, "bio", "biome"); brushManager.registerSniperBrush(BiomeBrush.class, "bio", "biome");
brushManager.registerSniperBrush(BlendBallBrush.class, "bb", "blendball"); brushManager.registerSniperBrush(BlendBallBrush.class, "bb", "blendball");

View File

@ -8,8 +8,7 @@ import java.util.List;
/** /**
* Configuration storage defining global configurations for VoxelSniper. * Configuration storage defining global configurations for VoxelSniper.
*/ */
public class VoxelSniperConfiguration public class VoxelSniperConfiguration {
{
public static final String CONFIG_IDENTIFIER_LITESNIPER_MAX_BRUSH_SIZE = "litesniper-max-brush-size"; public static final String CONFIG_IDENTIFIER_LITESNIPER_MAX_BRUSH_SIZE = "litesniper-max-brush-size";
public static final String CONFIG_IDENTIFIER_UNDO_CACHE_SIZE = "undo-cache-size"; public static final String CONFIG_IDENTIFIER_UNDO_CACHE_SIZE = "undo-cache-size";
public static final String CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS = "litesniper-restricted-items"; public static final String CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS = "litesniper-restricted-items";
@ -22,8 +21,7 @@ public class VoxelSniperConfiguration
/** /**
* @param configuration Configuration that is going to be used. * @param configuration Configuration that is going to be used.
*/ */
public VoxelSniperConfiguration(FileConfiguration configuration) public VoxelSniperConfiguration(FileConfiguration configuration) {
{
this.configuration = configuration; this.configuration = configuration;
} }
@ -32,8 +30,7 @@ public class VoxelSniperConfiguration
* *
* @return the maximum amount of snipes stored in the undo cache of snipers * @return the maximum amount of snipes stored in the undo cache of snipers
*/ */
public int getUndoCacheSize() public int getUndoCacheSize() {
{
return configuration.getInt(CONFIG_IDENTIFIER_UNDO_CACHE_SIZE, DEFAULT_UNDO_CACHE_SIZE); return configuration.getInt(CONFIG_IDENTIFIER_UNDO_CACHE_SIZE, DEFAULT_UNDO_CACHE_SIZE);
} }
@ -42,8 +39,7 @@ public class VoxelSniperConfiguration
* *
* @param size size of undo cache * @param size size of undo cache
*/ */
public void setUndoCacheSize(int size) public void setUndoCacheSize(int size) {
{
configuration.set(CONFIG_IDENTIFIER_UNDO_CACHE_SIZE, size); configuration.set(CONFIG_IDENTIFIER_UNDO_CACHE_SIZE, size);
} }
@ -52,8 +48,7 @@ public class VoxelSniperConfiguration
* *
* @return maximum size * @return maximum size
*/ */
public int getLiteSniperMaxBrushSize() public int getLiteSniperMaxBrushSize() {
{
return configuration.getInt(CONFIG_IDENTIFIER_LITESNIPER_MAX_BRUSH_SIZE, DEFAULT_LITESNIPER_MAX_BRUSH_SIZE); return configuration.getInt(CONFIG_IDENTIFIER_LITESNIPER_MAX_BRUSH_SIZE, DEFAULT_LITESNIPER_MAX_BRUSH_SIZE);
} }
@ -62,8 +57,7 @@ public class VoxelSniperConfiguration
* *
* @param size maximum size * @param size maximum size
*/ */
public void setLiteSniperMaxBrushSize(int size) public void setLiteSniperMaxBrushSize(int size) {
{
configuration.set(CONFIG_IDENTIFIER_LITESNIPER_MAX_BRUSH_SIZE, size); configuration.set(CONFIG_IDENTIFIER_LITESNIPER_MAX_BRUSH_SIZE, size);
} }
@ -72,8 +66,7 @@ public class VoxelSniperConfiguration
* *
* @return List of restricted Litesniper Items * @return List of restricted Litesniper Items
*/ */
public List<Integer> getLiteSniperRestrictedItems() public List<Integer> getLiteSniperRestrictedItems() {
{
return configuration.getIntegerList(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS); return configuration.getIntegerList(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS);
} }
@ -82,8 +75,7 @@ public class VoxelSniperConfiguration
* *
* @param restrictedItems List of restricted Litesniper Items * @param restrictedItems List of restricted Litesniper Items
*/ */
public void setLitesniperRestrictedItems(List<Integer> restrictedItems) public void setLitesniperRestrictedItems(List<Integer> restrictedItems) {
{
Preconditions.checkNotNull(restrictedItems, "Restricted items must be a list."); Preconditions.checkNotNull(restrictedItems, "Restricted items must be a list.");
configuration.set(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS, restrictedItems); configuration.set(CONFIG_IDENTIFIER_LITESNIPER_RESTRICTED_ITEMS, restrictedItems);
} }
@ -93,8 +85,7 @@ public class VoxelSniperConfiguration
* *
* @return true if message on login is enabled, false otherwise. * @return true if message on login is enabled, false otherwise.
*/ */
public boolean isMessageOnLoginEnabled() public boolean isMessageOnLoginEnabled() {
{
return configuration.getBoolean(CONFIG_IDENTIFIER_MESSAGE_ON_LOGIN_ENABLED, DEFAULT_MESSAGE_ON_LOGIN_ENABLED); return configuration.getBoolean(CONFIG_IDENTIFIER_MESSAGE_ON_LOGIN_ENABLED, DEFAULT_MESSAGE_ON_LOGIN_ENABLED);
} }
@ -103,8 +94,7 @@ public class VoxelSniperConfiguration
* *
* @param enabled Message on Login enabled * @param enabled Message on Login enabled
*/ */
public void setMessageOnLoginEnabled(boolean enabled) public void setMessageOnLoginEnabled(boolean enabled) {
{
configuration.set(CONFIG_IDENTIFIER_MESSAGE_ON_LOGIN_ENABLED, enabled); configuration.set(CONFIG_IDENTIFIER_MESSAGE_ON_LOGIN_ENABLED, enabled);
} }
} }

View File

@ -16,13 +16,11 @@ import org.bukkit.event.player.PlayerJoinEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
/** /**
* @author Voxel * @author Voxel
*/ */
public class VoxelSniperListener implements Listener public class VoxelSniperListener implements Listener {
{
private static final String SNIPER_PERMISSION = "voxelsniper.sniper"; private static final String SNIPER_PERMISSION = "voxelsniper.sniper";
private final VoxelSniper plugin; private final VoxelSniper plugin;
@ -31,8 +29,7 @@ public class VoxelSniperListener implements Listener
/** /**
* @param plugin * @param plugin
*/ */
public VoxelSniperListener(final VoxelSniper plugin) public VoxelSniperListener(final VoxelSniper plugin) {
{
this.plugin = plugin; this.plugin = plugin;
addCommand(new VoxelBrushCommand(plugin)); addCommand(new VoxelBrushCommand(plugin));
addCommand(new VoxelBrushToolCommand(plugin)); addCommand(new VoxelBrushToolCommand(plugin));
@ -53,8 +50,7 @@ public class VoxelSniperListener implements Listener
addCommand(new VoxelVoxelCommand(plugin)); addCommand(new VoxelVoxelCommand(plugin));
} }
private void addCommand(final VoxelCommand command) private void addCommand(final VoxelCommand command) {
{
this.commands.put(command.getIdentifier().toLowerCase(), command); this.commands.put(command.getIdentifier().toLowerCase(), command);
} }
@ -64,16 +60,13 @@ public class VoxelSniperListener implements Listener
* @param command * @param command
* @return boolean Success. * @return boolean Success.
*/ */
public boolean onCommand(final Player player, final String[] split, final String command) public boolean onCommand(final Player player, final String[] split, final String command) {
{
VoxelCommand found = this.commands.get(command.toLowerCase()); VoxelCommand found = this.commands.get(command.toLowerCase());
if (found == null) if (found == null) {
{
return false; return false;
} }
if (!hasPermission(found, player)) if (!hasPermission(found, player)) {
{
player.sendMessage(ChatColor.RED + "Insufficient Permissions."); player.sendMessage(ChatColor.RED + "Insufficient Permissions.");
return true; return true;
} }
@ -111,20 +104,14 @@ public class VoxelSniperListener implements Listener
return true; return true;
} }
private boolean hasPermission(final VoxelCommand command, final Player player) private boolean hasPermission(final VoxelCommand command, final Player player) {
{ if (command == null || player == null) {
if (command == null || player == null)
{
// Just a usual check for nulls // Just a usual check for nulls
return false; return false;
} } else if (command.getPermission() == null || command.getPermission().isEmpty()) {
else if (command.getPermission() == null || command.getPermission().isEmpty())
{
// This is for commands that do not require a permission node to be executed // This is for commands that do not require a permission node to be executed
return true; return true;
} } else {
else
{
// Should utilize Vault for permission checks if available // Should utilize Vault for permission checks if available
return player.hasPermission(command.getPermission()); return player.hasPermission(command.getPermission());
} }
@ -134,25 +121,19 @@ public class VoxelSniperListener implements Listener
* @param event * @param event
*/ */
@EventHandler(ignoreCancelled = false) @EventHandler(ignoreCancelled = false)
public final void onPlayerInteract(final PlayerInteractEvent event) public final void onPlayerInteract(final PlayerInteractEvent event) {
{
Player player = event.getPlayer(); Player player = event.getPlayer();
if (!player.hasPermission(SNIPER_PERMISSION)) if (!player.hasPermission(SNIPER_PERMISSION)) {
{
return; return;
} }
try try {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
if (sniper.isEnabled() && sniper.snipe(event.getAction(), event.getMaterial(), event.getClickedBlock(), event.getBlockFace())) if (sniper.isEnabled() && sniper.snipe(event.getAction(), event.getMaterial(), event.getClickedBlock(), event.getBlockFace())) {
{
event.setCancelled(true); event.setCancelled(true);
} }
} } catch (final Throwable ignored) {
catch (final Throwable ignored)
{
ignored.printStackTrace(); ignored.printStackTrace();
} }
} }
@ -161,13 +142,11 @@ public class VoxelSniperListener implements Listener
* @param event * @param event
*/ */
@EventHandler @EventHandler
public final void onPlayerJoin(final PlayerJoinEvent event) public final void onPlayerJoin(final PlayerJoinEvent event) {
{
Player player = event.getPlayer(); Player player = event.getPlayer();
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
if (player.hasPermission(SNIPER_PERMISSION) && plugin.getVoxelSniperConfiguration().isMessageOnLoginEnabled()) if (player.hasPermission(SNIPER_PERMISSION) && plugin.getVoxelSniperConfiguration().isMessageOnLoginEnabled()) {
{
sniper.displayInfo(); sniper.displayInfo();
} }
} }

View File

@ -3,9 +3,9 @@ package com.thevoxelbox.voxelsniper.command;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import com.thevoxelbox.voxelsniper.brush.IBrush; import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.brush.perform.Performer; import com.thevoxelbox.voxelsniper.brush.perform.Performer;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import com.thevoxelbox.voxelsniper.event.SniperBrushChangedEvent; import com.thevoxelbox.voxelsniper.event.SniperBrushChangedEvent;
import com.thevoxelbox.voxelsniper.event.SniperBrushSizeChangedEvent; import com.thevoxelbox.voxelsniper.event.SniperBrushSizeChangedEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -13,35 +13,27 @@ import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.Arrays;
public class VoxelBrushCommand extends VoxelCommand public class VoxelBrushCommand extends VoxelCommand {
{ public VoxelBrushCommand(final VoxelSniper plugin) {
public VoxelBrushCommand(final VoxelSniper plugin)
{
super("VoxelBrush", plugin); super("VoxelBrush", plugin);
setIdentifier("b"); setIdentifier("b");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
String currentToolId = sniper.getCurrentToolId(); String currentToolId = sniper.getCurrentToolId();
SnipeData snipeData = sniper.getSnipeData(currentToolId); SnipeData snipeData = sniper.getSnipeData(currentToolId);
if (args == null || args.length == 0) if (args == null || args.length == 0) {
{
sniper.previousBrush(currentToolId); sniper.previousBrush(currentToolId);
sniper.displayInfo(); sniper.displayInfo();
return true; return true;
} } else if (args.length > 0) {
else if (args.length > 0) try {
{
try
{
int newBrushSize = Integer.parseInt(args[0]); int newBrushSize = Integer.parseInt(args[0]);
if (!player.hasPermission("voxelsniper.ignorelimitations") && newBrushSize > plugin.getVoxelSniperConfiguration().getLiteSniperMaxBrushSize()) if (!player.hasPermission("voxelsniper.ignorelimitations") && newBrushSize > plugin.getVoxelSniperConfiguration().getLiteSniperMaxBrushSize()) {
{
player.sendMessage("Size is restricted to " + plugin.getVoxelSniperConfiguration().getLiteSniperMaxBrushSize() + " for you."); player.sendMessage("Size is restricted to " + plugin.getVoxelSniperConfiguration().getLiteSniperMaxBrushSize() + " for you.");
newBrushSize = plugin.getVoxelSniperConfiguration().getLiteSniperMaxBrushSize(); newBrushSize = plugin.getVoxelSniperConfiguration().getLiteSniperMaxBrushSize();
} }
@ -51,28 +43,21 @@ public class VoxelBrushCommand extends VoxelCommand
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
snipeData.getVoxelMessage().size(); snipeData.getVoxelMessage().size();
return true; return true;
} } catch (NumberFormatException ingored) {
catch (NumberFormatException ingored)
{
} }
Class<? extends IBrush> brush = plugin.getBrushManager().getBrushForHandle(args[0]); Class<? extends IBrush> brush = plugin.getBrushManager().getBrushForHandle(args[0]);
if (brush != null) if (brush != null) {
{
IBrush orignalBrush = sniper.getBrush(currentToolId); IBrush orignalBrush = sniper.getBrush(currentToolId);
sniper.setBrush(currentToolId, brush); sniper.setBrush(currentToolId, brush);
if (args.length > 1) if (args.length > 1) {
{
IBrush currentBrush = sniper.getBrush(currentToolId); IBrush currentBrush = sniper.getBrush(currentToolId);
if (currentBrush instanceof Performer) if (currentBrush instanceof Performer) {
{
String[] parameters = Arrays.copyOfRange(args, 1, args.length); String[] parameters = Arrays.copyOfRange(args, 1, args.length);
((Performer) currentBrush).parse(parameters, snipeData); ((Performer) currentBrush).parse(parameters, snipeData);
return true; return true;
} } else {
else
{
String[] parameters = hackTheArray(Arrays.copyOfRange(args, 1, args.length)); String[] parameters = hackTheArray(Arrays.copyOfRange(args, 1, args.length));
currentBrush.parameters(parameters, snipeData); currentBrush.parameters(parameters, snipeData);
return true; return true;
@ -81,9 +66,7 @@ public class VoxelBrushCommand extends VoxelCommand
SniperBrushChangedEvent event = new SniperBrushChangedEvent(sniper, currentToolId, orignalBrush, sniper.getBrush(currentToolId)); SniperBrushChangedEvent event = new SniperBrushChangedEvent(sniper, currentToolId, orignalBrush, sniper.getBrush(currentToolId));
sniper.displayInfo(); sniper.displayInfo();
return true; return true;
} } else {
else
{
player.sendMessage("Couldn't find Brush for brush handle \"" + args[0] + "\""); player.sendMessage("Couldn't find Brush for brush handle \"" + args[0] + "\"");
return true; return true;
} }

View File

@ -7,75 +7,53 @@ import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelBrushToolCommand extends VoxelCommand public class VoxelBrushToolCommand extends VoxelCommand {
{ public VoxelBrushToolCommand(final VoxelSniper plugin) {
public VoxelBrushToolCommand(final VoxelSniper plugin)
{
super("VoxelBrushTool", plugin); super("VoxelBrushTool", plugin);
setIdentifier("btool"); setIdentifier("btool");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
if (args != null && args.length > 0) if (args != null && args.length > 0) {
{ if (args[0].equalsIgnoreCase("assign")) {
if (args[0].equalsIgnoreCase("assign"))
{
SnipeAction action; SnipeAction action;
if (args[1].equalsIgnoreCase("arrow")) if (args[1].equalsIgnoreCase("arrow")) {
{
action = SnipeAction.ARROW; action = SnipeAction.ARROW;
} } else if (args[1].equalsIgnoreCase("powder")) {
else if (args[1].equalsIgnoreCase("powder"))
{
action = SnipeAction.GUNPOWDER; action = SnipeAction.GUNPOWDER;
} } else {
else
{
player.sendMessage("/btool assign <arrow|powder> <toolid>"); player.sendMessage("/btool assign <arrow|powder> <toolid>");
return true; return true;
} }
if (args.length == 3 && args[2] != null && !args[2].isEmpty()) if (args.length == 3 && args[2] != null && !args[2].isEmpty()) {
{
Material itemInHand = (player.getItemInHand() != null) ? player.getItemInHand().getType() : null; Material itemInHand = (player.getItemInHand() != null) ? player.getItemInHand().getType() : null;
if (itemInHand == null) if (itemInHand == null) {
{
player.sendMessage("/btool assign <arrow|powder> <toolid>"); player.sendMessage("/btool assign <arrow|powder> <toolid>");
return true; return true;
} }
if (sniper.setTool(args[2], action, itemInHand)) if (sniper.setTool(args[2], action, itemInHand)) {
{
player.sendMessage(itemInHand.name() + " has been assigned to '" + args[2] + "' as action " + action.name() + "."); player.sendMessage(itemInHand.name() + " has been assigned to '" + args[2] + "' as action " + action.name() + ".");
} } else {
else
{
player.sendMessage("Couldn't assign tool."); player.sendMessage("Couldn't assign tool.");
} }
return true; return true;
} }
} } else if (args[0].equalsIgnoreCase("remove")) {
else if (args[0].equalsIgnoreCase("remove")) if (args.length == 2 && args[1] != null && !args[1].isEmpty()) {
{
if (args.length == 2 && args[1] != null && !args[1].isEmpty())
{
sniper.removeTool(args[1]); sniper.removeTool(args[1]);
return true; return true;
} } else {
else
{
Material itemInHand = (player.getItemInHand() != null) ? player.getItemInHand().getType() : null; Material itemInHand = (player.getItemInHand() != null) ? player.getItemInHand().getType() : null;
if (itemInHand == null) if (itemInHand == null) {
{
player.sendMessage("Can't unassign empty hands."); player.sendMessage("Can't unassign empty hands.");
return true; return true;
} }
if (sniper.getCurrentToolId() == null) if (sniper.getCurrentToolId() == null) {
{
player.sendMessage("Can't unassign default tool."); player.sendMessage("Can't unassign default tool.");
return true; return true;
} }

View File

@ -7,30 +7,24 @@ import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelCenterCommand extends VoxelCommand public class VoxelCenterCommand extends VoxelCommand {
{ public VoxelCenterCommand(final VoxelSniper plugin) {
public VoxelCenterCommand(final VoxelSniper plugin)
{
super("VoxelCenter", plugin); super("VoxelCenter", plugin);
setIdentifier("vc"); setIdentifier("vc");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId());
try try {
{
int center = Integer.parseInt(args[0]); int center = Integer.parseInt(args[0]);
snipeData.setcCen(center); snipeData.setcCen(center);
snipeData.getVoxelMessage().center(); snipeData.getVoxelMessage().center();
return true; return true;
} } catch (final Exception exception) {
catch (final Exception exception)
{
player.sendMessage(ChatColor.RED + "Invalid input."); player.sendMessage(ChatColor.RED + "Invalid input.");
return true; return true;
} }

View File

@ -4,17 +4,14 @@ import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelChunkCommand extends VoxelCommand public class VoxelChunkCommand extends VoxelCommand {
{ public VoxelChunkCommand(final VoxelSniper plugin) {
public VoxelChunkCommand(final VoxelSniper plugin)
{
super("VoxelChunk", plugin); super("VoxelChunk", plugin);
setIdentifier("vchunk"); setIdentifier("vchunk");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
player.getWorld().refreshChunk(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); player.getWorld().refreshChunk(player.getLocation().getBlockX(), player.getLocation().getBlockZ());
return true; return true;
} }

View File

@ -6,18 +6,15 @@ import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelDefaultCommand extends VoxelCommand public class VoxelDefaultCommand extends VoxelCommand {
{ public VoxelDefaultCommand(final VoxelSniper plugin) {
public VoxelDefaultCommand(final VoxelSniper plugin)
{
super("VoxelDefault", plugin); super("VoxelDefault", plugin);
setIdentifier("d"); setIdentifier("d");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
sniper.reset(sniper.getCurrentToolId()); sniper.reset(sniper.getCurrentToolId());

View File

@ -6,28 +6,22 @@ import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelGoToCommand extends VoxelCommand public class VoxelGoToCommand extends VoxelCommand {
{ public VoxelGoToCommand(final VoxelSniper plugin) {
public VoxelGoToCommand(final VoxelSniper plugin)
{
super("VoxelGoTo", plugin); super("VoxelGoTo", plugin);
setIdentifier("goto"); setIdentifier("goto");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{ try {
try
{
final int x = Integer.parseInt(args[0]); final int x = Integer.parseInt(args[0]);
final int z = Integer.parseInt(args[1]); final int z = Integer.parseInt(args[1]);
player.teleport(new Location(player.getWorld(), x, player.getWorld().getHighestBlockYAt(x, z), z)); player.teleport(new Location(player.getWorld(), x, player.getWorld().getHighestBlockYAt(x, z), z));
player.sendMessage(ChatColor.GREEN + "Woosh!"); player.sendMessage(ChatColor.GREEN + "Woosh!");
return true; return true;
} } catch (final Exception exception) {
catch (final Exception exception)
{
player.sendMessage(ChatColor.RED + "Invalid syntax."); player.sendMessage(ChatColor.RED + "Invalid syntax.");
return true; return true;
} }

View File

@ -7,30 +7,24 @@ import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelHeightCommand extends VoxelCommand public class VoxelHeightCommand extends VoxelCommand {
{ public VoxelHeightCommand(final VoxelSniper plugin) {
public VoxelHeightCommand(final VoxelSniper plugin)
{
super("VoxelHeight", plugin); super("VoxelHeight", plugin);
setIdentifier("vh"); setIdentifier("vh");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId());
try try {
{
int height = Integer.parseInt(args[0]); int height = Integer.parseInt(args[0]);
snipeData.setVoxelHeight(height); snipeData.setVoxelHeight(height);
snipeData.getVoxelMessage().height(); snipeData.getVoxelMessage().height();
return true; return true;
} } catch (final Exception exception) {
catch (final Exception exception)
{
player.sendMessage(ChatColor.RED + "Invalid input."); player.sendMessage(ChatColor.RED + "Invalid input.");
return true; return true;
} }

View File

@ -7,45 +7,32 @@ import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelInkCommand extends VoxelCommand public class VoxelInkCommand extends VoxelCommand {
{ public VoxelInkCommand(final VoxelSniper plugin) {
public VoxelInkCommand(final VoxelSniper plugin)
{
super("VoxelInk", plugin); super("VoxelInk", plugin);
setIdentifier("vi"); setIdentifier("vi");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
int dataValue; int dataValue;
if (args.length == 0) if (args.length == 0) {
{
AsyncBlock targetBlock = new RangeBlockHelper(player, sniper.getWorld()).getTargetBlock(); AsyncBlock targetBlock = new RangeBlockHelper(player, sniper.getWorld()).getTargetBlock();
if (targetBlock != null) if (targetBlock != null) {
{
dataValue = targetBlock.getPropertyId(); dataValue = targetBlock.getPropertyId();
} } else {
else
{
return true; return true;
} }
} } else {
else try {
{
try
{
dataValue = Integer.parseInt(args[0]); dataValue = Integer.parseInt(args[0]);
} } catch (NumberFormatException exception) {
catch (NumberFormatException exception)
{
BlockState state = BlockState.get(args[0]); BlockState state = BlockState.get(args[0]);
if (state == null) { if (state == null) {
player.sendMessage("Couldn't parse input."); player.sendMessage("Couldn't parse input.");

View File

@ -7,45 +7,32 @@ import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelInkReplaceCommand extends VoxelCommand public class VoxelInkReplaceCommand extends VoxelCommand {
{ public VoxelInkReplaceCommand(final VoxelSniper plugin) {
public VoxelInkReplaceCommand(final VoxelSniper plugin)
{
super("VoxelInkReplace", plugin); super("VoxelInkReplace", plugin);
setIdentifier("vir"); setIdentifier("vir");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
int dataValue; int dataValue;
if (args.length == 0) if (args.length == 0) {
{
AsyncBlock targetBlock = new RangeBlockHelper(player, sniper.getWorld()).getTargetBlock(); AsyncBlock targetBlock = new RangeBlockHelper(player, sniper.getWorld()).getTargetBlock();
if (targetBlock != null) if (targetBlock != null) {
{
dataValue = targetBlock.getPropertyId(); dataValue = targetBlock.getPropertyId();
} } else {
else
{
return true; return true;
} }
} } else {
else try {
{
try
{
dataValue = Integer.parseInt(args[0]); dataValue = Integer.parseInt(args[0]);
} } catch (NumberFormatException exception) {
catch (NumberFormatException exception)
{
BlockState state = BlockState.get(args[0]); BlockState state = BlockState.get(args[0]);
if (state == null) { if (state == null) {
player.sendMessage("Couldn't parse input."); player.sendMessage("Couldn't parse input.");

View File

@ -1,61 +1,44 @@
package com.thevoxelbox.voxelsniper.command; package com.thevoxelbox.voxelsniper.command;
import com.boydti.fawe.bukkit.wrapper.AsyncBlock; import com.boydti.fawe.bukkit.wrapper.AsyncBlock;
import com.boydti.fawe.object.FawePlayer;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.factory.MaskFactory;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.extent.NullExtent;
import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.RangeBlockHelper;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelListCommand extends VoxelCommand public class VoxelListCommand extends VoxelCommand {
{ public VoxelListCommand(final VoxelSniper plugin) {
public VoxelListCommand(final VoxelSniper plugin)
{
super("VoxelList", plugin); super("VoxelList", plugin);
setIdentifier("vl"); setIdentifier("vl");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId());
if (args.length == 0) if (args.length == 0) {
{
final RangeBlockHelper rangeBlockHelper = new RangeBlockHelper(player, sniper.getWorld()); final RangeBlockHelper rangeBlockHelper = new RangeBlockHelper(player, sniper.getWorld());
final AsyncBlock targetBlock = rangeBlockHelper.getTargetBlock(); final AsyncBlock targetBlock = rangeBlockHelper.getTargetBlock();
snipeData.getVoxelList().add(BukkitAdapter.adapt(targetBlock.getBlockData())); snipeData.getVoxelList().add(BukkitAdapter.adapt(targetBlock.getBlockData()));
snipeData.getVoxelMessage().voxelList(); snipeData.getVoxelMessage().voxelList();
return true; return true;
} } else {
else if (args[0].equalsIgnoreCase("clear")) {
{
if (args[0].equalsIgnoreCase("clear"))
{
snipeData.getVoxelList().clear(); snipeData.getVoxelList().clear();
snipeData.getVoxelMessage().voxelList(); snipeData.getVoxelMessage().voxelList();
return true; return true;
} }
} }
for (String string : args) for (String string : args) {
{
boolean remove = false; boolean remove = false;
if (string.charAt(0) == '-') { if (string.charAt(0) == '-') {
string = string.substring(1); string = string.substring(1);

View File

@ -6,41 +6,29 @@ import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelPaintCommand extends VoxelCommand public class VoxelPaintCommand extends VoxelCommand {
{ public VoxelPaintCommand(final VoxelSniper plugin) {
public VoxelPaintCommand(final VoxelSniper plugin)
{
super("VoxelPaint", plugin); super("VoxelPaint", plugin);
setIdentifier("paint"); setIdentifier("paint");
setPermission("voxelsniper.paint"); setPermission("voxelsniper.paint");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{ if (args.length == 1) {
if (args.length == 1) if (args[0].equalsIgnoreCase("back")) {
{
if (args[0].equalsIgnoreCase("back"))
{
PaintingWrapper.paint(player, true, true, 0); PaintingWrapper.paint(player, true, true, 0);
return true; return true;
} } else {
else try {
{
try
{
PaintingWrapper.paint(player, false, false, Integer.parseInt(args[0])); PaintingWrapper.paint(player, false, false, Integer.parseInt(args[0]));
return true; return true;
} } catch (final Exception exception) {
catch (final Exception exception)
{
player.sendMessage(ChatColor.RED + "Invalid input."); player.sendMessage(ChatColor.RED + "Invalid input.");
return true; return true;
} }
} }
} } else {
else
{
PaintingWrapper.paint(player, true, false, 0); PaintingWrapper.paint(player, true, false, 0);
return true; return true;
} }

View File

@ -3,58 +3,43 @@ package com.thevoxelbox.voxelsniper.command;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import com.thevoxelbox.voxelsniper.brush.IBrush; import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.brush.perform.Performer; import com.thevoxelbox.voxelsniper.brush.perform.Performer;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.logging.Level; import java.util.logging.Level;
public class VoxelPerformerCommand extends VoxelCommand public class VoxelPerformerCommand extends VoxelCommand {
{ public VoxelPerformerCommand(final VoxelSniper plugin) {
public VoxelPerformerCommand(final VoxelSniper plugin)
{
super("VoxelPerformer", plugin); super("VoxelPerformer", plugin);
setIdentifier("p"); setIdentifier("p");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId());
try try {
{ if (args == null || args.length == 0) {
if (args == null || args.length == 0)
{
IBrush brush = sniper.getBrush(sniper.getCurrentToolId()); IBrush brush = sniper.getBrush(sniper.getCurrentToolId());
if (brush instanceof Performer) if (brush instanceof Performer) {
{ ((Performer) brush).parse(new String[]{"m"}, snipeData);
((Performer) brush).parse(new String[]{ "m" }, snipeData); } else {
}
else
{
player.sendMessage("This brush is not a performer brush."); player.sendMessage("This brush is not a performer brush.");
} }
} } else {
else
{
IBrush brush = sniper.getBrush(sniper.getCurrentToolId()); IBrush brush = sniper.getBrush(sniper.getCurrentToolId());
if (brush instanceof Performer) if (brush instanceof Performer) {
{
((Performer) brush).parse(args, snipeData); ((Performer) brush).parse(args, snipeData);
} } else {
else
{
player.sendMessage("This brush is not a performer brush."); player.sendMessage("This brush is not a performer brush.");
} }
} }
return true; return true;
} } catch (Exception exception) {
catch (Exception exception)
{
plugin.getLogger().log(Level.WARNING, "Command error from " + player.getName(), exception); plugin.getLogger().log(Level.WARNING, "Command error from " + player.getName(), exception);
return true; return true;
} }

View File

@ -6,19 +6,17 @@ import com.google.common.collect.Multimap;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.brush.perform.PerformerE; import com.thevoxelbox.voxelsniper.brush.perform.PerformerE;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
public class VoxelSniperCommand extends VoxelCommand public class VoxelSniperCommand extends VoxelCommand {
{
public VoxelSniperCommand(final VoxelSniper plugin) public VoxelSniperCommand(final VoxelSniper plugin) {
{
super("VoxelSniper", plugin); super("VoxelSniper", plugin);
setIdentifier("vs"); setIdentifier("vs");
@ -26,79 +24,56 @@ public class VoxelSniperCommand extends VoxelCommand
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = VoxelSniper.getInstance().getSniperManager().getSniperForPlayer(player); Sniper sniper = VoxelSniper.getInstance().getSniperManager().getSniperForPlayer(player);
if (args.length >= 1) if (args.length >= 1) {
{ if (args[0].equalsIgnoreCase("brushes")) {
if (args[0].equalsIgnoreCase("brushes"))
{
Multimap<Class<? extends IBrush>, String> registeredBrushesMultimap = VoxelSniper.getInstance().getBrushManager().getRegisteredBrushesMultimap(); Multimap<Class<? extends IBrush>, String> registeredBrushesMultimap = VoxelSniper.getInstance().getBrushManager().getRegisteredBrushesMultimap();
List<String> allHandles = Lists.newLinkedList(); List<String> allHandles = Lists.newLinkedList();
for (Class<? extends IBrush> brushClass : registeredBrushesMultimap.keySet()) for (Class<? extends IBrush> brushClass : registeredBrushesMultimap.keySet()) {
{
allHandles.addAll(registeredBrushesMultimap.get(brushClass)); allHandles.addAll(registeredBrushesMultimap.get(brushClass));
} }
player.sendMessage(Joiner.on(", ").skipNulls().join(allHandles)); player.sendMessage(Joiner.on(", ").skipNulls().join(allHandles));
return true; return true;
} } else if (args[0].equalsIgnoreCase("range")) {
else if (args[0].equalsIgnoreCase("range"))
{
SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId());
if (args.length == 2) if (args.length == 2) {
{ try {
try
{
int range = Integer.parseInt(args[1]); int range = Integer.parseInt(args[1]);
if (range < 0) if (range < 0) {
{
player.sendMessage("Negative values are not allowed."); player.sendMessage("Negative values are not allowed.");
} }
snipeData.setRange(range); snipeData.setRange(range);
snipeData.setRanged(true); snipeData.setRanged(true);
snipeData.getVoxelMessage().toggleRange(); snipeData.getVoxelMessage().toggleRange();
} } catch (NumberFormatException exception) {
catch (NumberFormatException exception)
{
player.sendMessage("Can't parse number."); player.sendMessage("Can't parse number.");
} }
return true; return true;
} } else {
else
{
snipeData.setRanged(!snipeData.isRanged()); snipeData.setRanged(!snipeData.isRanged());
snipeData.getVoxelMessage().toggleRange(); snipeData.getVoxelMessage().toggleRange();
return true; return true;
} }
} } else if (args[0].equalsIgnoreCase("perf")) {
else if (args[0].equalsIgnoreCase("perf"))
{
player.sendMessage(ChatColor.AQUA + "Available performers (abbreviated):"); player.sendMessage(ChatColor.AQUA + "Available performers (abbreviated):");
player.sendMessage(PerformerE.performer_list_short); player.sendMessage(PerformerE.performer_list_short);
return true; return true;
} } else if (args[0].equalsIgnoreCase("perflong")) {
else if (args[0].equalsIgnoreCase("perflong"))
{
player.sendMessage(ChatColor.AQUA + "Available performers:"); player.sendMessage(ChatColor.AQUA + "Available performers:");
player.sendMessage(PerformerE.performer_list_long); player.sendMessage(PerformerE.performer_list_long);
return true; return true;
} } else if (args[0].equalsIgnoreCase("enable") && player.hasPermission("voxelsniper.command.vs.enable")) {
else if (args[0].equalsIgnoreCase("enable") && player.hasPermission("voxelsniper.command.vs.enable"))
{
sniper.setEnabled(true); sniper.setEnabled(true);
player.sendMessage("VoxelSniper is " + (sniper.isEnabled() ? "enabled" : "disabled")); player.sendMessage("VoxelSniper is " + (sniper.isEnabled() ? "enabled" : "disabled"));
return true; return true;
} } else if (args[0].equalsIgnoreCase("disable") && player.hasPermission("voxelsniper.command.vs.enable")) {
else if (args[0].equalsIgnoreCase("disable") && player.hasPermission("voxelsniper.command.vs.enable"))
{
sniper.setEnabled(false); sniper.setEnabled(false);
player.sendMessage("VoxelSniper is " + (sniper.isEnabled() ? "enabled" : "disabled")); player.sendMessage("VoxelSniper is " + (sniper.isEnabled() ? "enabled" : "disabled"));
return true; return true;
} } else if (args[0].equalsIgnoreCase("toggle") && player.hasPermission("voxelsniper.command.vs.enable")) {
else if (args[0].equalsIgnoreCase("toggle") && player.hasPermission("voxelsniper.command.vs.enable"))
{
sniper.setEnabled(!sniper.isEnabled()); sniper.setEnabled(!sniper.isEnabled());
player.sendMessage("VoxelSniper is " + (sniper.isEnabled() ? "enabled" : "disabled")); player.sendMessage("VoxelSniper is " + (sniper.isEnabled() ? "enabled" : "disabled"));
return true; return true;

View File

@ -5,34 +5,25 @@ import com.thevoxelbox.voxelsniper.VoxelSniper;
import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelUndoCommand extends VoxelCommand public class VoxelUndoCommand extends VoxelCommand {
{ public VoxelUndoCommand(final VoxelSniper plugin) {
public VoxelUndoCommand(final VoxelSniper plugin)
{
super("VoxelUndo", plugin); super("VoxelUndo", plugin);
setIdentifier("u"); setIdentifier("u");
setPermission("voxelsniper.sniper"); setPermission("voxelsniper.sniper");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{
Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player); Sniper sniper = plugin.getSniperManager().getSniperForPlayer(player);
if (args.length == 1) if (args.length == 1) {
{ try {
try
{
int amount = Integer.parseInt(args[0]); int amount = Integer.parseInt(args[0]);
sniper.undo(amount); sniper.undo(amount);
} } catch (NumberFormatException exception) {
catch (NumberFormatException exception)
{
player.sendMessage("Error while parsing amount of undo. Number format exception."); player.sendMessage("Error while parsing amount of undo. Number format exception.");
} }
} } else {
else
{
sniper.undo(); sniper.undo();
} }
plugin.getLogger().info("Player \"" + player.getName() + "\" used /u"); plugin.getLogger().info("Player \"" + player.getName() + "\" used /u");

View File

@ -6,25 +6,19 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class VoxelUndoUserCommand extends VoxelCommand public class VoxelUndoUserCommand extends VoxelCommand {
{ public VoxelUndoUserCommand(final VoxelSniper plugin) {
public VoxelUndoUserCommand(final VoxelSniper plugin)
{
super("VoxelUndoUser", plugin); super("VoxelUndoUser", plugin);
setIdentifier("uu"); setIdentifier("uu");
setPermission("voxelsniper.command.uu"); setPermission("voxelsniper.command.uu");
} }
@Override @Override
public boolean onCommand(Player player, String[] args) public boolean onCommand(Player player, String[] args) {
{ try {
try
{
plugin.getSniperManager().getSniperForPlayer(Bukkit.getPlayer(args[0])).undo(); plugin.getSniperManager().getSniperForPlayer(Bukkit.getPlayer(args[0])).undo();
return true; return true;
} } catch (final Exception exception) {
catch (final Exception exception)
{
player.sendMessage(ChatColor.GREEN + "Player not found."); player.sendMessage(ChatColor.GREEN + "Player not found.");
return true; return true;
} }

View File

@ -1,57 +1,48 @@
package com.thevoxelbox.voxelsniper.event; package com.thevoxelbox.voxelsniper.event;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
* *
*/ */
public class SniperBrushSizeChangedEvent extends Event public class SniperBrushSizeChangedEvent extends Event {
{
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final Sniper sniper; private final Sniper sniper;
private final int originalSize; private final int originalSize;
private final int newSize; private final int newSize;
private final String toolId; private final String toolId;
public SniperBrushSizeChangedEvent(Sniper sniper, String toolId, int originalSize, int newSize) public SniperBrushSizeChangedEvent(Sniper sniper, String toolId, int originalSize, int newSize) {
{
this.sniper = sniper; this.sniper = sniper;
this.originalSize = originalSize; this.originalSize = originalSize;
this.newSize = newSize; this.newSize = newSize;
this.toolId = toolId; this.toolId = toolId;
} }
public static HandlerList getHandlerList() public static HandlerList getHandlerList() {
{
return handlers; return handlers;
} }
public int getOriginalSize() public int getOriginalSize() {
{
return originalSize; return originalSize;
} }
public int getNewSize() public int getNewSize() {
{
return newSize; return newSize;
} }
public Sniper getSniper() public Sniper getSniper() {
{
return sniper; return sniper;
} }
public String getToolId() public String getToolId() {
{
return toolId; return toolId;
} }
@Override @Override
public HandlerList getHandlers() public HandlerList getHandlers() {
{
return handlers; return handlers;
} }
} }

View File

@ -3,28 +3,23 @@ package com.thevoxelbox.voxelsniper.event;
import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.Sniper;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.material.MaterialData;
/** /**
* *
*/ */
public class SniperReplaceMaterialChangedEvent extends SniperMaterialChangedEvent public class SniperReplaceMaterialChangedEvent extends SniperMaterialChangedEvent {
{
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
public SniperReplaceMaterialChangedEvent(Sniper sniper, String toolId, BlockData originalMaterial, BlockData newMaterial) public SniperReplaceMaterialChangedEvent(Sniper sniper, String toolId, BlockData originalMaterial, BlockData newMaterial) {
{
super(sniper, toolId, originalMaterial, newMaterial); super(sniper, toolId, originalMaterial, newMaterial);
} }
public static HandlerList getHandlerList() public static HandlerList getHandlerList() {
{
return handlers; return handlers;
} }
@Override @Override
public HandlerList getHandlers() public HandlerList getHandlers() {
{
return handlers; return handlers;
} }
} }

View File

@ -1,5 +1,12 @@
package com.thevoxelbox.voxelsniper.jsap; package com.thevoxelbox.voxelsniper.jsap;
import com.martiansoftware.jsap.JSAP;
import com.martiansoftware.jsap.JSAPException;
import com.martiansoftware.jsap.JSAPResult;
import com.martiansoftware.jsap.Switch;
import com.martiansoftware.util.StringUtils;
import org.bukkit.ChatColor;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
@ -7,21 +14,12 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import com.martiansoftware.jsap.JSAP;
import com.martiansoftware.jsap.JSAPException;
import com.martiansoftware.jsap.JSAPResult;
import com.martiansoftware.jsap.Switch;
import com.martiansoftware.util.StringUtils;
import org.bukkit.ChatColor;
/** /**
* JSAP parser with help generating code. * JSAP parser with help generating code.
* *
* @author MikeMatrix * @author MikeMatrix
*/ */
public class HelpJSAP extends JSAP public class HelpJSAP extends JSAP {
{
private String name; private String name;
private String explanation; private String explanation;
@ -32,20 +30,16 @@ public class HelpJSAP extends JSAP
* @param explanation * @param explanation
* @param screenWidth * @param screenWidth
*/ */
public HelpJSAP(final String name, final String explanation, final int screenWidth) public HelpJSAP(final String name, final String explanation, final int screenWidth) {
{
super(); super();
this.name = name; this.name = name;
this.explanation = explanation; this.explanation = explanation;
this.screenWidth = screenWidth; this.screenWidth = screenWidth;
try try {
{
this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page.")); this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page."));
} } catch (final JSAPException e) {
catch (final JSAPException e)
{
} }
} }
@ -54,26 +48,19 @@ public class HelpJSAP extends JSAP
* @param explanation * @param explanation
* @param screenWidth * @param screenWidth
* @param resourceName * @param resourceName
* * @throws java.io.IOException if an I/O error occurs
* @throws java.io.IOException * @throws com.martiansoftware.jsap.JSAPException if the configuration is not valid
* if an I/O error occurs
* @throws com.martiansoftware.jsap.JSAPException
* if the configuration is not valid
*/ */
public HelpJSAP(final String name, final String explanation, final int screenWidth, final String resourceName) throws IOException, JSAPException public HelpJSAP(final String name, final String explanation, final int screenWidth, final String resourceName) throws IOException, JSAPException {
{
super(resourceName); super(resourceName);
this.name = name; this.name = name;
this.explanation = explanation; this.explanation = explanation;
this.screenWidth = screenWidth; this.screenWidth = screenWidth;
try try {
{
this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page.")); this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page."));
} } catch (final JSAPException e) {
catch (final JSAPException e)
{
} }
} }
@ -82,95 +69,74 @@ public class HelpJSAP extends JSAP
* @param explanation * @param explanation
* @param screenWidth * @param screenWidth
* @param jsapXML * @param jsapXML
* * @throws java.io.IOException if an I/O error occurs
* @throws java.io.IOException * @throws com.martiansoftware.jsap.JSAPException if the configuration is not valid
* if an I/O error occurs
* @throws com.martiansoftware.jsap.JSAPException
* if the configuration is not valid
*/ */
public HelpJSAP(final String name, final String explanation, final int screenWidth, final URL jsapXML) throws IOException, JSAPException public HelpJSAP(final String name, final String explanation, final int screenWidth, final URL jsapXML) throws IOException, JSAPException {
{
super(jsapXML); super(jsapXML);
this.name = name; this.name = name;
this.explanation = explanation; this.explanation = explanation;
this.screenWidth = screenWidth; this.screenWidth = screenWidth;
try try {
{
this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page.")); this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page."));
} } catch (final JSAPException e) {
catch (final JSAPException e)
{
} }
} }
/** /**
* @return the explanation * @return the explanation
*/ */
public final String getExplanation() public final String getExplanation() {
{
return this.explanation; return this.explanation;
} }
/** /**
* @param explanation * @param explanation the explanation to set
* the explanation to set
*/ */
public final void setExplanation(final String explanation) public final void setExplanation(final String explanation) {
{
this.explanation = explanation; this.explanation = explanation;
} }
/** /**
* @return the name * @return the name
*/ */
public final String getName() public final String getName() {
{
return this.name; return this.name;
} }
/** /**
* @param name * @param name the name to set
* the name to set
*/ */
public final void setName(final String name) public final void setName(final String name) {
{
this.name = name; this.name = name;
} }
/** /**
* @return the screenWidth * @return the screenWidth
*/ */
public final int getScreenWidth() public final int getScreenWidth() {
{
return this.screenWidth; return this.screenWidth;
} }
/** /**
* @param screenWidth * @param screenWidth the screenWidth to set
* the screenWidth to set
*/ */
public final void setScreenWidth(final int screenWidth) public final void setScreenWidth(final int screenWidth) {
{
this.screenWidth = screenWidth; this.screenWidth = screenWidth;
} }
/** /**
* @param jsapResult * @param jsapResult
*
* @return if something has been written on writer. * @return if something has been written on writer.
*/ */
public final List<String> writeHelpOrErrorMessageIfRequired(final JSAPResult jsapResult) public final List<String> writeHelpOrErrorMessageIfRequired(final JSAPResult jsapResult) {
{ if (!(jsapResult.success()) || jsapResult.getBoolean("help")) {
if (!(jsapResult.success()) || jsapResult.getBoolean("help"))
{
List<String> returnValue = new LinkedList<>(); List<String> returnValue = new LinkedList<>();
// To avoid spurious missing argument errors we never print errors if help is required. // To avoid spurious missing argument errors we never print errors if help is required.
if (!jsapResult.getBoolean("help")) if (!jsapResult.getBoolean("help")) {
{ for (final Iterator<?> err = jsapResult.getErrorMessageIterator(); err.hasNext(); ) {
for (final Iterator<?> err = jsapResult.getErrorMessageIterator(); err.hasNext(); )
{
returnValue.add(ChatColor.RED + "Error: " + ChatColor.DARK_RED + err.next()); returnValue.add(ChatColor.RED + "Error: " + ChatColor.DARK_RED + err.next());
} }
@ -179,17 +145,14 @@ public class HelpJSAP extends JSAP
returnValue.add(ChatColor.GOLD + "Usage:"); returnValue.add(ChatColor.GOLD + "Usage:");
List<?> l = StringUtils.wrapToList(this.name + " " + this.getUsage(), this.screenWidth); List<?> l = StringUtils.wrapToList(this.name + " " + this.getUsage(), this.screenWidth);
for (final Object aL : l) for (final Object aL : l) {
{
returnValue.add(" " + aL.toString()); returnValue.add(" " + aL.toString());
} }
if (this.explanation != null) if (this.explanation != null) {
{
returnValue.add(""); returnValue.add("");
l = StringUtils.wrapToList(this.explanation, this.screenWidth); l = StringUtils.wrapToList(this.explanation, this.screenWidth);
for (final Object aL : l) for (final Object aL : l) {
{
final String next = (String) aL; final String next = (String) aL;
returnValue.add(ChatColor.AQUA + next); returnValue.add(ChatColor.AQUA + next);
} }

View File

@ -10,22 +10,20 @@ import com.martiansoftware.jsap.StringParser;
* @see com.martiansoftware.jsap.StringParser * @see com.martiansoftware.jsap.StringParser
* @see Integer * @see Integer
*/ */
public class NullableIntegerStringParser extends StringParser public class NullableIntegerStringParser extends StringParser {
{
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final NullableIntegerStringParser INSTANCE = new NullableIntegerStringParser(); private static final NullableIntegerStringParser INSTANCE = new NullableIntegerStringParser();
/** /**
* Returns a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}. * Returns a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}.
* * <p>
* * <p>
* Convenient access to the only instance returned by this method is available through {@link com.martiansoftware.jsap.JSAP#INTEGER_PARSER}. * Convenient access to the only instance returned by this method is available through {@link com.martiansoftware.jsap.JSAP#INTEGER_PARSER}.
* *
* @return a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}. * @return a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}.
*/ */
public static NullableIntegerStringParser getParser() public static NullableIntegerStringParser getParser() {
{
return new NullableIntegerStringParser(); return new NullableIntegerStringParser();
} }
@ -34,8 +32,7 @@ public class NullableIntegerStringParser extends StringParser
* *
* @deprecated Use {@link #getParser()} or, even better, {@link com.martiansoftware.jsap.JSAP#INTEGER_PARSER}. * @deprecated Use {@link #getParser()} or, even better, {@link com.martiansoftware.jsap.JSAP#INTEGER_PARSER}.
*/ */
public NullableIntegerStringParser() public NullableIntegerStringParser() {
{
super(); super();
} }
@ -43,31 +40,22 @@ public class NullableIntegerStringParser extends StringParser
* Parses the specified argument into an Integer. This method delegates the parsing to <code>Integer.decode(arg)</code>. If <code>Integer.decode()</code> * Parses the specified argument into an Integer. This method delegates the parsing to <code>Integer.decode(arg)</code>. If <code>Integer.decode()</code>
* throws a NumberFormatException, it is encapsulated into a ParseException and re-thrown. * throws a NumberFormatException, it is encapsulated into a ParseException and re-thrown.
* *
* @param arg * @param arg the argument to parse
* the argument to parse
*
* @return an Integer object with the value contained in the specified argument. * @return an Integer object with the value contained in the specified argument.
* * @throws com.martiansoftware.jsap.ParseException if <code>Integer.decode(arg)</code> throws a NumberFormatException.
* @throws com.martiansoftware.jsap.ParseException
* if <code>Integer.decode(arg)</code> throws a NumberFormatException.
* @see Integer * @see Integer
* @see com.martiansoftware.jsap.StringParser#parse(String) * @see com.martiansoftware.jsap.StringParser#parse(String)
*/ */
@Override @Override
public final Object parse(final String arg) throws ParseException public final Object parse(final String arg) throws ParseException {
{ if (arg == null) {
if (arg == null)
{
return null; return null;
} }
Integer result; Integer result;
try try {
{
result = Integer.decode(arg); result = Integer.decode(arg);
} } catch (NumberFormatException nfe) {
catch (NumberFormatException nfe)
{
throw (new ParseException("Unable to convert '" + arg + "' to an Integer.", nfe)); throw (new ParseException("Unable to convert '" + arg + "' to an Integer.", nfe));
} }
return (result); return (result);