WorldEdit block change event, still in test. Also fixed package names.

This commit is contained in:
Richard 2015-12-24 22:23:38 -02:00
parent 653b66e30e
commit 6089934ffd
58 changed files with 261 additions and 112 deletions

View File

@ -1,6 +1,6 @@
name: SkStuff
author: TheBukor
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
version: 1.2.3
main: me.TheBukor.SkStuff
softdepend: [Skript]
version: 1.4
main: me.TheBukor.SkStuff.SkStuff
softdepend: [Skript, WorldEdit]

View File

@ -1,9 +1,11 @@
package me.TheBukor;
package me.TheBukor.SkStuff;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
@ -14,60 +16,65 @@ import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.Classes;
import me.TheBukor.conditions.CondSelectionContains;
import me.TheBukor.effects.EffDrainLiquid;
import me.TheBukor.effects.EffDrawLineWE;
import me.TheBukor.effects.EffMakeCylinder;
import me.TheBukor.effects.EffMakePyramid;
import me.TheBukor.effects.EffMakeSphere;
import me.TheBukor.effects.EffMakeWalls;
import me.TheBukor.effects.EffNaturalize;
import me.TheBukor.effects.EffRememberChanges;
import me.TheBukor.effects.EffReplaceBlocksWE;
import me.TheBukor.effects.EffSetBlocksWE;
import me.TheBukor.effects.EffSimulateSnow;
import me.TheBukor.effects.EffUndoRedoSession;
import me.TheBukor.expressions.ExprAreaOfSchematic;
import me.TheBukor.expressions.ExprAreaOfSelection;
import me.TheBukor.expressions.ExprChangedBlocksSession;
import me.TheBukor.expressions.ExprEditSessionLimit;
import me.TheBukor.expressions.ExprFileNBTv1_8_R1;
import me.TheBukor.expressions.ExprFileNBTv1_8_R2;
import me.TheBukor.expressions.ExprFileNBTv1_8_R3;
import me.TheBukor.expressions.ExprHeightOfSchematic;
import me.TheBukor.expressions.ExprHeightOfSelection;
import me.TheBukor.expressions.ExprItemNBTv1_7_R1;
import me.TheBukor.expressions.ExprItemNBTv1_7_R2;
import me.TheBukor.expressions.ExprItemNBTv1_7_R3;
import me.TheBukor.expressions.ExprItemNBTv1_7_R4;
import me.TheBukor.expressions.ExprItemNBTv1_8_R1;
import me.TheBukor.expressions.ExprItemNBTv1_8_R2;
import me.TheBukor.expressions.ExprItemNBTv1_8_R3;
import me.TheBukor.expressions.ExprLengthOfSchematic;
import me.TheBukor.expressions.ExprLengthOfSelection;
import me.TheBukor.expressions.ExprNBTv1_7_R1;
import me.TheBukor.expressions.ExprNBTv1_7_R2;
import me.TheBukor.expressions.ExprNBTv1_7_R3;
import me.TheBukor.expressions.ExprNBTv1_7_R4;
import me.TheBukor.expressions.ExprNBTv1_8_R1;
import me.TheBukor.expressions.ExprNBTv1_8_R2;
import me.TheBukor.expressions.ExprNBTv1_8_R3;
import me.TheBukor.expressions.ExprNewEditSession;
import me.TheBukor.expressions.ExprSelectionOfPlayer;
import me.TheBukor.expressions.ExprSelectionPos1;
import me.TheBukor.expressions.ExprSelectionPos2;
import me.TheBukor.expressions.ExprTagOfv1_7_R1;
import me.TheBukor.expressions.ExprTagOfv1_7_R2;
import me.TheBukor.expressions.ExprTagOfv1_7_R3;
import me.TheBukor.expressions.ExprTagOfv1_7_R4;
import me.TheBukor.expressions.ExprTagOfv1_8_R1;
import me.TheBukor.expressions.ExprTagOfv1_8_R2;
import me.TheBukor.expressions.ExprTagOfv1_8_R3;
import me.TheBukor.expressions.ExprVolumeOfSchematic;
import me.TheBukor.expressions.ExprVolumeOfSelection;
import me.TheBukor.expressions.ExprWidthOfSchematic;
import me.TheBukor.expressions.ExprWidthOfSelection;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import me.TheBukor.SkStuff.conditions.CondSelectionContains;
import me.TheBukor.SkStuff.effects.EffDrainLiquid;
import me.TheBukor.SkStuff.effects.EffDrawLineWE;
import me.TheBukor.SkStuff.effects.EffMakeCylinder;
import me.TheBukor.SkStuff.effects.EffMakePyramid;
import me.TheBukor.SkStuff.effects.EffMakeSphere;
import me.TheBukor.SkStuff.effects.EffMakeWalls;
import me.TheBukor.SkStuff.effects.EffNaturalize;
import me.TheBukor.SkStuff.effects.EffRememberChanges;
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
import me.TheBukor.SkStuff.effects.EffSetBlocksWE;
import me.TheBukor.SkStuff.effects.EffSimulateSnow;
import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
import me.TheBukor.SkStuff.events.EvtWorldEditChange;
import me.TheBukor.SkStuff.events.WorldEditChangeHandler;
import me.TheBukor.SkStuff.expressions.ExprAreaOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprAreaOfSelection;
import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession;
import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit;
import me.TheBukor.SkStuff.expressions.ExprFileNBTv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprFileNBTv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprFileNBTv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprHeightOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprHeightOfSelection;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R1;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R2;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R3;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R4;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprLengthOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprLengthOfSelection;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R1;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R2;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R3;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R4;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprNewEditSession;
import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer;
import me.TheBukor.SkStuff.expressions.ExprSelectionPos1;
import me.TheBukor.SkStuff.expressions.ExprSelectionPos2;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R1;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R2;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R3;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R4;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprVolumeOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprVolumeOfSelection;
import me.TheBukor.SkStuff.expressions.ExprWidthOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprWidthOfSelection;
import net.minecraft.server.v1_8_R1.MojangsonParser;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R2.MojangsonParseException;
@ -77,6 +84,7 @@ public class SkStuff extends JavaPlugin {
private int exprAmount = 0;
private int typeAmount = 0;
private int effAmount = 0;
private boolean evtWE = false;
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Skript") != null) {
@ -418,8 +426,44 @@ public class SkStuff extends JavaPlugin {
Skript.registerExpression(ExprLengthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of schem[atic] [from] %string%");
Skript.registerExpression(ExprAreaOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "area of schem[atic] [from] %string%");
Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?"));
try {
Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent");
new WorldEditChangeHandler();
Skript.registerEvent("WorldEdit block change", SimpleEvent.class, EvtWorldEditChange.class, "world[ ]edit [block] (chang(e|ing)|edit[ing])");
EventValues.registerEventValue(EvtWorldEditChange.class, Player.class, new Getter<Player, EvtWorldEditChange>() {
@Override
@Nullable
public Player get(EvtWorldEditChange e) {
return EvtWorldEditChange.getPlayer();
}
getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!"));
}, 0);
EventValues.registerEventValue(EvtWorldEditChange.class, Block.class, new Getter<Block, EvtWorldEditChange>() {
@Override
@Nullable
public Block get(EvtWorldEditChange e) {
return EvtWorldEditChange.getBlock();
}
}, -1);
EventValues.registerEventValue(EvtWorldEditChange.class, Block.class, new Getter<Block, EvtWorldEditChange>() {
@Override
@Nullable
public Block get(EvtWorldEditChange e) {
return EvtWorldEditChange.getBlock();
}
}, 0);
EventValues.registerEventValue(EvtWorldEditChange.class, Block.class, new Getter<Block, EvtWorldEditChange>() {
@Override
@Nullable
public Block get(EvtWorldEditChange e) {
return EvtWorldEditChange.getFutureBlock();
}
}, 1);
evtWE = true;
} catch (ClassNotFoundException ex) {
Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0");
}
}
getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + (evtWE ? "1 event, " : "") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!"));
} else {
getLogger().info("Unable to find Skript, disabling SkStuff...");
Bukkit.getPluginManager().disablePlugin(this);;

View File

@ -1,4 +1,4 @@
package me.TheBukor.conditions;
package me.TheBukor.SkStuff.conditions;
import org.bukkit.Bukkit;
import org.bukkit.Location;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import java.util.HashSet;
import java.util.Set;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.effects;
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;

View File

@ -0,0 +1,40 @@
package me.TheBukor.SkStuff.events;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class EvtWorldEditChange extends Event {
static Player player;
static Block block;
static Block futureBlock;
public EvtWorldEditChange(Player player, Block block, Block futureBlock) {
EvtWorldEditChange.player = player;
EvtWorldEditChange.block = block;
EvtWorldEditChange.futureBlock = futureBlock;
}
public static Player getPlayer() {
return player;
}
public static Block getBlock() {
return block;
}
public static Block getFutureBlock() {
return futureBlock;
}
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -0,0 +1,24 @@
package me.TheBukor.SkStuff.events;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
public class WorldEditChangeHandler {
public WorldEditChangeHandler() {
WorldEdit.getInstance().getEventBus().register(this);
}
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
Actor actor = event.getActor();
World world = event.getWorld();
if (world instanceof BukkitWorld) {
event.setExtent(new WorldEditExtent(actor, world, event.getExtent()));
}
}
}

View File

@ -0,0 +1,41 @@
package me.TheBukor.SkStuff.events;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
import me.TheBukor.SkStuff.SkStuff;
public class WorldEditExtent extends AbstractLoggingExtent {
private final Actor actor;
private final World world;
public WorldEditExtent(Actor actor, com.sk89q.worldedit.world.World weWorld, Extent extent) {
super(extent);
this.actor = actor;
this.world = ((BukkitWorld) weWorld).getWorld();
}
@Override
protected void onBlockChange(final Vector vec, BaseBlock baseBlock) {
final Block b = BukkitUtil.toLocation(world, vec).getBlock();
final Player p = Bukkit.getPlayerExact(actor.getName());
Bukkit.getScheduler().scheduleSyncDelayedTask(new SkStuff(), new Runnable() {
@Override
public void run() {
Block futureB = BukkitUtil.toLocation(world, vec).getBlock();
Bukkit.getPluginManager().callEvent(new EvtWorldEditChange(p, b, futureB));
}
}, 1L);
}
}

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.EOFException;
import java.io.File;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.EOFException;
import java.io.File;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.EOFException;
import java.io.File;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.TheBukor.expressions;
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;