Added new WE effects, fixed NPE when edit session doesn't exist.

This commit is contained in:
Richard 2015-12-13 21:12:13 -02:00
parent c7034ae857
commit dae953dc85
8 changed files with 199 additions and 38 deletions

View File

@ -16,10 +16,13 @@ import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.ParseContext; import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes; import ch.njol.skript.registrations.Classes;
import me.TheBukor.conditions.CondSelectionContains; import me.TheBukor.conditions.CondSelectionContains;
import me.TheBukor.effects.EffDrainLiquid;
import me.TheBukor.effects.EffDrawLineWE; import me.TheBukor.effects.EffDrawLineWE;
import me.TheBukor.effects.EffMakePyramid; import me.TheBukor.effects.EffMakePyramid;
import me.TheBukor.effects.EffMakeSphere; import me.TheBukor.effects.EffMakeSphere;
import me.TheBukor.effects.EffNaturalize;
import me.TheBukor.effects.EffRememberChanges; import me.TheBukor.effects.EffRememberChanges;
import me.TheBukor.effects.EffSimulateSnow;
import me.TheBukor.effects.EffUndoRedoSession; import me.TheBukor.effects.EffUndoRedoSession;
import me.TheBukor.expressions.ExprAreaOfSchematic; import me.TheBukor.expressions.ExprAreaOfSchematic;
import me.TheBukor.expressions.ExprAreaOfSelection; import me.TheBukor.expressions.ExprAreaOfSelection;
@ -378,20 +381,21 @@ public class SkStuff extends JavaPlugin {
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
getLogger().info("WorldEdit found! Registering WorldEdit stuff..."); getLogger().info("WorldEdit found! Registering WorldEdit stuff...");
condAmount += 1; condAmount += 1;
effAmount += 5; effAmount += 8;
exprAmount += 16; exprAmount += 16;
typeAmount += 1; typeAmount += 1;
Skript.registerCondition(CondSelectionContains.class, "[(world[ ]edit|we)] selection of %player% (contains|has) %location%", "%player%'s [(world[ ]edit|we)] selection (contains|has) %location%", "[(world[ ]edit|we)] selection of %player% does(n't| not) (contain|have) %location%", "%player%'s [(world[ ]edit|we)] selection does(n't| not) (contain|have) %location%"); Skript.registerCondition(CondSelectionContains.class, "[(world[ ]edit|we)] selection of %player% (contains|has) %location%", "%player%'s [(world[ ]edit|we)] selection (contains|has) %location%", "[(world[ ]edit|we)] selection of %player% does(n't| not) (contain|have) %location%", "%player%'s [(world[ ]edit|we)] selection does(n't| not) (contain|have) %location%");
// EXPERIMENTAL EFFECTS/EXPRESSIONS Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%");
Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a] (0¦[(no(n|t)(-| )hollow|filled|)]|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstack% [(and|with)] thick[ness] %double%"); Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) (change|edit)s (of|from) [edit[ ]session] %editsession%");
Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%"); Skript.registerEffect(EffRememberChanges.class, "make %player% (remember|be able to undo) changes (of|from) [edit[ ]session] %editsession%");
Skript.registerEffect(EffRememberChanges.class, "make %player% (remember|be able to undo) changes (of|from) [edit [ ]session] %editsession%"); Skript.registerEffect(EffMakeSphere.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %double%, %double%(,| and) %double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
Skript.registerEffect(EffMakeSphere.class, "(create|make) [a] (0¦[(no(n|t)(-| )hollow|filled|)]|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %number%, %number%(,| and) %number% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstack%"); Skript.registerEffect(EffSimulateSnow.class, "(simulate snow at|place snow over) %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%", "make %location% snowy (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffMakePyramid.class, "(create|make) [a] (0¦[(no(n|t)(-| )hollow|filled|)]|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstack%"); Skript.registerEffect(EffMakePyramid.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
Skript.registerEffect(EffDrainLiquid.class, "(drain|remove) [all] liquid[s] at %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffNaturalize.class, "naturalize ([cuboid] region|[all] blocks) (from|between) %location% (to|and) %location% (using|with) [edit[ ]session] %editsession%");
Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%"); Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%");
Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%"); Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%");
Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "new edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%"); Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "new edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%");
// END OF EXPERIMENTAL EFFS/EXPRS
Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection");
Skript.registerExpression(ExprSelectionPos1.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]1 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]1"); Skript.registerExpression(ExprSelectionPos1.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]1 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]1");
Skript.registerExpression(ExprSelectionPos2.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]2 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]2"); Skript.registerExpression(ExprSelectionPos2.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]2 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]2");

View File

@ -0,0 +1,52 @@
package me.TheBukor.effects;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.event.Event;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
public class EffDrainLiquid extends Effect {
private Expression<Location> location;
private Expression<Double> radius;
private Expression<EditSession> editSession;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
location = (Expression<Location>) expr[0];
radius = (Expression<Double>) expr[1];
editSession = (Expression<EditSession>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "drain liquids at " + location.toString(e, false) + " in a radius of " + radius.toString(e, false);
}
@Override
protected void execute(Event e) {
Location loc = location.getSingle(e);
Double rad = radius.getSingle(e);
EditSession session = editSession.getSingle(e);
if (session == null) return;
try {
session.drainArea(BukkitUtil.toVector(loc), rad);
session.flushQueue();
} catch (WorldEditException ex) {
if (ex instanceof MaxChangedBlocksException)
return;
else
ex.printStackTrace();
}
}
}

View File

@ -8,18 +8,17 @@ import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Patterns;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.patterns.Pattern;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
@SuppressWarnings("deprecation")
public class EffDrawLineWE extends Effect { public class EffDrawLineWE extends Effect {
private Expression<Location> location1; private Expression<Location> location1;
private Expression<Location> location2; private Expression<Location> location2;
@ -45,6 +44,7 @@ public class EffDrawLineWE extends Effect {
return "draw a line from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false) + " and thickness " + thickness.toString(e, false); return "draw a line from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false) + " and thickness " + thickness.toString(e, false);
} }
@SuppressWarnings("deprecation")
@Override @Override
protected void execute(Event e) { protected void execute(Event e) {
Location pos1 = location1.getSingle(e); Location pos1 = location1.getSingle(e);
@ -53,17 +53,14 @@ public class EffDrawLineWE extends Effect {
ItemStack[] blocks = blockList.getAll(e); ItemStack[] blocks = blockList.getAll(e);
Double thick = thickness.getSingle(e); Double thick = thickness.getSingle(e);
RandomPattern random = new RandomPattern(); RandomPattern random = new RandomPattern();
if (session == null) return;
for (ItemStack b : blocks) { for (ItemStack b : blocks) {
if (b.getType().isBlock()) { if (b.getType().isBlock()) {
try { random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(pos1.getWorld()), b)), 50);
} catch (WorldEditException ex) {
ex.printStackTrace();
}
} }
} }
try { try {
session.drawLine((Pattern) random, BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled); session.drawLine(Patterns.wrap(random), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled);
session.flushQueue(); session.flushQueue();
} catch (MaxChangedBlocksException ex) { } catch (MaxChangedBlocksException ex) {
return; return;

View File

@ -9,17 +9,17 @@ import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Patterns;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.patterns.Pattern;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
@SuppressWarnings("deprecation")
public class EffMakePyramid extends Effect { public class EffMakePyramid extends Effect {
private Expression<Location> location; private Expression<Location> location;
private Expression<Integer> radius; private Expression<Integer> radius;
@ -42,6 +42,7 @@ public class EffMakePyramid extends Effect {
return "create a pyramid at " + location.toString(e, false) + " with a radius of " + radius.toString(e, false) + " using an edit session with " + blockList.toString(e, false); return "create a pyramid at " + location.toString(e, false) + " with a radius of " + radius.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
} }
@SuppressWarnings("deprecation")
@Override @Override
protected void execute(Event e) { protected void execute(Event e) {
Location loc = location.getSingle(e); Location loc = location.getSingle(e);
@ -49,20 +50,20 @@ public class EffMakePyramid extends Effect {
EditSession session = editSession.getSingle(e); EditSession session = editSession.getSingle(e);
ItemStack[] blocks = blockList.getAll(e); ItemStack[] blocks = blockList.getAll(e);
RandomPattern random = new RandomPattern(); RandomPattern random = new RandomPattern();
if (session == null) return;
for (ItemStack b : blocks) { for (ItemStack b : blocks) {
if (b.getType().isBlock()) { if (b.getType().isBlock()) {
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
}
}
try { try {
random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(loc.getWorld()), b)), 50); session.makePyramid(BukkitUtil.toVector(loc), Patterns.wrap(random), rad, filled);
session.flushQueue();
} catch (WorldEditException ex) { } catch (WorldEditException ex) {
if (ex instanceof MaxChangedBlocksException)
return;
else
ex.printStackTrace(); ex.printStackTrace();
} }
} }
}
try {
session.makePyramid(BukkitUtil.toVector(loc), (Pattern) random, rad, filled);
session.flushQueue();
} catch (MaxChangedBlocksException ex) {
return;
}
}
} }

View File

@ -9,17 +9,17 @@ import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Patterns;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.patterns.Pattern;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
@SuppressWarnings("deprecation")
public class EffMakeSphere extends Effect { public class EffMakeSphere extends Effect {
private Expression<Location> location; private Expression<Location> location;
private Expression<Double> radius1; private Expression<Double> radius1;
@ -46,6 +46,7 @@ public class EffMakeSphere extends Effect {
return "create a sphere centered at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + radius2.toString(e, false) + " " + radius3.toString(e, false) + " using an edit session with " + blockList.toString(e, false); return "create a sphere centered at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + radius2.toString(e, false) + " " + radius3.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
} }
@SuppressWarnings("deprecation")
@Override @Override
protected void execute(Event e) { protected void execute(Event e) {
Location loc = location.getSingle(e); Location loc = location.getSingle(e);
@ -55,20 +56,20 @@ public class EffMakeSphere extends Effect {
EditSession session = editSession.getSingle(e); EditSession session = editSession.getSingle(e);
ItemStack[] blocks = blockList.getAll(e); ItemStack[] blocks = blockList.getAll(e);
RandomPattern random = new RandomPattern(); RandomPattern random = new RandomPattern();
if (session == null) return;
for (ItemStack b : blocks) { for (ItemStack b : blocks) {
if (b.getType().isBlock()) { if (b.getType().isBlock()) {
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
}
}
try { try {
random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(loc.getWorld()), b)), 50); session.makeSphere(BukkitUtil.toVector(loc), Patterns.wrap(random), rad1, rad2, rad3, filled);
session.flushQueue();
} catch (WorldEditException ex) { } catch (WorldEditException ex) {
if (ex instanceof MaxChangedBlocksException)
return;
else
ex.printStackTrace(); ex.printStackTrace();
} }
} }
}
try {
session.makeSphere(BukkitUtil.toVector(loc), (Pattern) random, rad1, rad2, rad3, filled);
session.flushQueue();
} catch (MaxChangedBlocksException ex) {
return;
}
}
} }

View File

@ -0,0 +1,54 @@
package me.TheBukor.effects;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.event.Event;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
public class EffNaturalize extends Effect {
private Expression<Location> location1;
private Expression<Location> location2;
private Expression<EditSession> editSession;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
location1 = (Expression<Location>) expr[0];
location2 = (Expression<Location>) expr[1];
editSession = (Expression<EditSession>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "naturalize all blocks from " + location1.toString(e, false) + " to " + location2.toString(e, false);
}
@Override
protected void execute(Event e) {
Location pos1 = location1.getSingle(e);
Location pos2 = location2.getSingle(e);
EditSession session = editSession.getSingle(e);
if (session == null) return;
CuboidRegion region = new CuboidRegion(BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2));
try {
session.naturalizeCuboidBlocks(region);
session.flushQueue();
} catch (WorldEditException ex) {
if (ex instanceof MaxChangedBlocksException)
return;
else
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,52 @@
package me.TheBukor.effects;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.event.Event;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
public class EffSimulateSnow extends Effect {
private Expression<Location> location;
private Expression<Double> radius;
private Expression<EditSession> editSession;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
location = (Expression<Location>) expr[0];
radius = (Expression<Double>) expr[1];
editSession = (Expression<EditSession>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "make " + location.toString(e, false) + " snowy in a radius of " + radius.toString(e, false);
}
@Override
protected void execute(Event e) {
Location loc = location.getSingle(e);
Double rad = radius.getSingle(e);
EditSession session = editSession.getSingle(e);
if (session == null) return;
try {
session.simulateSnow(BukkitUtil.toVector(loc), rad);
session.flushQueue();
} catch (WorldEditException ex) {
if (ex instanceof MaxChangedBlocksException)
return;
else
ex.printStackTrace();
}
}
}

View File

@ -25,7 +25,7 @@ public class EffUndoRedoSession extends Effect {
@Override @Override
public String toString(@Nullable Event e, boolean arg1) { public String toString(@Nullable Event e, boolean arg1) {
return "undo last change of edit session"; return (redo == true ? "redo " : "undo ") + "changes from edit session";
} }
@Override @Override