Skip to content

Commit

Permalink
Add some events
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon5550 committed Aug 24, 2016
1 parent 4af2927 commit 3ad20df
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 36 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/thevoxelbox/voxelsniper/Brushes.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import com.google.common.collect.Maps;
import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.event.RegisterBrushEvent;
import org.spongepowered.api.Sponge;

import java.util.Map;

Expand Down Expand Up @@ -57,7 +59,9 @@ private Brushes() {
*/
public void registerSniperBrush(Class<? extends IBrush> clazz, String... handles) {
checkNotNull(clazz, "Cannot register null as a brush.");
for (String handle : handles) {
RegisterBrushEvent event = new RegisterBrushEvent(clazz, handles, VoxelSniper.plugin_cause);
Sponge.getEventManager().post(event);
for (String handle : event.getAliases()) {
this.brushes.put(handle.toLowerCase(), clazz);
}
this.brush_count++;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/thevoxelbox/voxelsniper/Sniper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.thevoxelbox.voxelsniper.brush.IBrush;
import com.thevoxelbox.voxelsniper.brush.PerformBrush;
import com.thevoxelbox.voxelsniper.brush.shape.SnipeBrush;
import com.thevoxelbox.voxelsniper.event.sniper.ChangeBrushEvent;
import com.thevoxelbox.voxelsniper.util.SniperStats;

import com.google.common.base.Preconditions;
Expand All @@ -39,6 +40,7 @@
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.ItemStack;
Expand Down Expand Up @@ -453,6 +455,9 @@ public IBrush setCurrentBrush(Class<? extends IBrush> brush) {
}

if (this.snipeData.owner().getPlayer().hasPermission(brushInstance.getPermissionNode())) {
ChangeBrushEvent event =
new ChangeBrushEvent(brushInstance, this.currentBrush, this.snipeData, VoxelSniper.plugin_cause.with(NamedCause.source(this.snipeData.owner().getPlayer())));
Sponge.getEventManager().post(event);
this.previousBrush = this.currentBrush;
this.currentBrush = brush;
return brushInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public abstract class PerformBrush extends Brush {
public void parse(String[] args, SnipeData v) {
String handle = args[0];
if (handle.length() == 1 || handle.length() == 2) {
// @Spongify throw brush change event?
PerformerType pl = null;
char p = handle.charAt(0);
if (p == 'm' || p == 'M') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ private BlockState get(int x, int y, Direction axis, Location<World> target) {

private void set(int x, int y, Direction axis, Location<World> target, BlockState state, int offs) {
if (axis == Direction.UP || axis == Direction.DOWN) {
if(axis == Direction.DOWN) {
if (axis == Direction.DOWN) {
offs *= -1;
}
setBlockState(x + target.getBlockX(), target.getBlockY() + offs, y + target.getBlockZ(), state);
} else if (axis == Direction.EAST || axis == Direction.WEST) {
if(axis == Direction.EAST) {
if (axis == Direction.EAST) {
offs *= -1;
}
setBlockState(target.getBlockX() + offs, x + target.getBlockY(), y + target.getBlockZ(), state);
} else {
if(axis == Direction.NORTH) {
if (axis == Direction.NORTH) {
offs *= -1;
}
setBlockState(x + target.getBlockX(), y + target.getBlockY(), target.getBlockZ() + offs, state);
Expand All @@ -103,36 +103,6 @@ private void pre(final SnipeData v, Location<World> target, boolean towards) {
extrude(v, target, this.lastBlock.getBlockZ() > this.targetBlock.getBlockZ() ^ towards ? Direction.NORTH : Direction.SOUTH);
}
}
// @Spongify

// private void extrudeUpOrDown(final SnipeData v, boolean isUp)
// {
// final int brushSize = v.getBrushSize();
// final double brushSizeSquared = Math.pow(brushSize + this.trueCircle, 2);
// Undo undo = new Undo();
//
// for (int x = -brushSize; x <= brushSize; x++)
// {
// final double xSquared = Math.pow(x, 2);
// for (int z = -brushSize; z <= brushSize; z++)
// {
// if ((xSquared + Math.pow(z, 2)) <= brushSizeSquared)
// {
// final int direction = (isUp ? 1 : -1);
// for (int y = 0; y < Math.abs(v.getVoxelHeight()); y++)
// {
// final int tempY = y * direction;
// undo = this.perform(
// this.clampY(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + tempY, this.getTargetBlock().getZ() + z),
// this.clampY(this.getTargetBlock().getX() + x, this.getTargetBlock().getY() + tempY + direction, this.getTargetBlock().getZ() + z),
// v, undo);
// }
// }
// }
// }
//
// v.owner().storeUndo(undo);
// }

@Override
protected final void arrow(final SnipeData v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class SplatterOverlayBrush extends PerformBrush {
private Random generator = new Random();
private int depth = 3;

// @Spongify
public SplatterOverlayBrush() {
this.setName("Splatter Overlay");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of VoxelSniper, licensed under the MIT License (MIT).
*
* Copyright (c) The VoxelBox <http://thevoxelbox.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.thevoxelbox.voxelsniper.event;

import com.google.common.collect.Lists;
import com.thevoxelbox.voxelsniper.brush.IBrush;
import org.spongepowered.api.event.cause.Cause;

import java.util.List;

public class RegisterBrushEvent extends VoxelSniperEvent {

private final Class<? extends IBrush> type;
private final List<String> aliases;

public RegisterBrushEvent(Class<? extends IBrush> type, String[] aliases, Cause c) {
super(c);
this.type = type;
this.aliases = Lists.newArrayList(aliases);
}

public Class<? extends IBrush> getBrushType() {
return this.type;
}

public List<String> getAliases() {
return this.aliases;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of VoxelSniper, licensed under the MIT License (MIT).
*
* Copyright (c) The VoxelBox <http://thevoxelbox.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.thevoxelbox.voxelsniper.event;

import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.cause.Cause;

/**
* Top level event for all voxelsniper events.
*/
public class VoxelSniperEvent implements Event {

private final Cause cause;

public VoxelSniperEvent(Cause c) {
this.cause = c;
}

@Override
public Cause getCause() {
return this.cause;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of VoxelSniper, licensed under the MIT License (MIT).
*
* Copyright (c) The VoxelBox <http://thevoxelbox.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.thevoxelbox.voxelsniper.event.sniper;

import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.brush.IBrush;
import org.spongepowered.api.event.cause.Cause;

public class ChangeBrushEvent extends VoxelSniperPlayerEvent {

private final IBrush brush;
private final Class<? extends IBrush> previous;

public ChangeBrushEvent(IBrush brush, Class<? extends IBrush> prev, SnipeData v, Cause c) {
super(v, c);
this.brush = brush;
this.previous = prev;
}

public IBrush getNewBrush() {
return this.brush;
}

public Class<? extends IBrush> getPreviousBrush() {
return this.previous;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of VoxelSniper, licensed under the MIT License (MIT).
*
* Copyright (c) The VoxelBox <http://thevoxelbox.com>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.thevoxelbox.voxelsniper.event.sniper;

import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Sniper;
import com.thevoxelbox.voxelsniper.event.VoxelSniperEvent;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause;

public class VoxelSniperPlayerEvent extends VoxelSniperEvent {

private final SnipeData v;

public VoxelSniperPlayerEvent(SnipeData v, Cause c) {
super(c);
this.v = v;
}

public SnipeData getSnipeData() {
return this.v;
}

public Sniper getSniper() {
return this.v.owner();
}

public Player getPlayer() {
return this.v.owner().getPlayer();
}

}

0 comments on commit 3ad20df

Please sign in to comment.