WorldEdit block change event, still in test. Also fixed package names.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package me.TheBukor.SkStuff.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
|
||||
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 EffDrawLineWE extends Effect {
|
||||
private Expression<Location> location1;
|
||||
private Expression<Location> location2;
|
||||
private Expression<EditSession> editSession;
|
||||
private Expression<ItemStack> blockList;
|
||||
private Expression<Double> thickness;
|
||||
private boolean filled = true;
|
||||
|
||||
@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];
|
||||
blockList = (Expression<ItemStack>) expr[3];
|
||||
thickness = (Expression<Double>) expr[4];
|
||||
if (result.mark == 1) filled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
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
|
||||
protected void execute(Event e) {
|
||||
Location pos1 = location1.getSingle(e);
|
||||
Location pos2 = location2.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList.getAll(e);
|
||||
Double thick = thickness.getSingle(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.drawLine(Patterns.wrap(random), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled);
|
||||
session.flushQueue();
|
||||
} catch (MaxChangedBlocksException ex) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
|
||||
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 EffMakeCylinder extends Effect {
|
||||
private Expression<Location> location;
|
||||
private Expression<Double> radius1;
|
||||
private Expression<Double> radius2;
|
||||
private Expression<Integer> height;
|
||||
private Expression<EditSession> editSession;
|
||||
private Expression<ItemStack> blockList;
|
||||
private boolean filled = true;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
location = (Expression<Location>) expr[0];
|
||||
radius1 = (Expression<Double>) expr[1];
|
||||
height = (Expression<Integer>) expr[2];
|
||||
radius2 = (Expression<Double>) expr[3];
|
||||
editSession = (Expression<EditSession>) expr[4];
|
||||
blockList = (Expression<ItemStack>) expr[5];
|
||||
if (result.mark == 1) filled = false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "create a cylinder at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + height.toString(e, false) + " " + radius2.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void execute(Event e) {
|
||||
Location loc = location.getSingle(e);
|
||||
Double rad1 = radius1.getSingle(e);
|
||||
Integer h = height.getSingle(e);
|
||||
Double rad2 = radius2.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList.getAll(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.makeCylinder(BukkitUtil.toVector(loc), Patterns.wrap(random), rad1, rad2, h, filled);
|
||||
session.flushQueue();
|
||||
} catch (WorldEditException ex) {
|
||||
if (ex instanceof MaxChangedBlocksException)
|
||||
return;
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
|
||||
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 EffMakePyramid extends Effect {
|
||||
private Expression<Location> location;
|
||||
private Expression<Integer> radius;
|
||||
private Expression<EditSession> editSession;
|
||||
private Expression<ItemStack> blockList;
|
||||
private boolean filled = true;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
location = (Expression<Location>) expr[0];
|
||||
radius = (Expression<Integer>) expr[1];
|
||||
editSession = (Expression<EditSession>) expr[2];
|
||||
blockList = (Expression<ItemStack>) expr[3];
|
||||
if (result.mark == 1) filled = false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
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
|
||||
protected void execute(Event e) {
|
||||
Location loc = location.getSingle(e);
|
||||
Integer rad = radius.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList.getAll(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.makePyramid(BukkitUtil.toVector(loc), Patterns.wrap(random), rad, filled);
|
||||
session.flushQueue();
|
||||
} catch (WorldEditException ex) {
|
||||
if (ex instanceof MaxChangedBlocksException)
|
||||
return;
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
|
||||
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 EffMakeSphere extends Effect {
|
||||
private Expression<Location> location;
|
||||
private Expression<Double> radius1;
|
||||
private Expression<Double> radius2;
|
||||
private Expression<Double> radius3;
|
||||
private Expression<EditSession> editSession;
|
||||
private Expression<ItemStack> blockList;
|
||||
private boolean filled = true;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
location = (Expression<Location>) expr[0];
|
||||
radius1 = (Expression<Double>) expr[1];
|
||||
radius2 = (Expression<Double>) expr[2];
|
||||
radius3 = (Expression<Double>) expr[3];
|
||||
editSession = (Expression<EditSession>) expr[4];
|
||||
blockList = (Expression<ItemStack>) expr[5];
|
||||
if (result.mark == 1) filled = false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
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
|
||||
protected void execute(Event e) {
|
||||
Location loc = location.getSingle(e);
|
||||
Double rad1 = radius1.getSingle(e);
|
||||
Double rad2 = radius2.getSingle(e);
|
||||
Double rad3 = radius3.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList.getAll(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.makeSphere(BukkitUtil.toVector(loc), Patterns.wrap(random), rad1, rad2, rad3, filled);
|
||||
session.flushQueue();
|
||||
} catch (WorldEditException ex) {
|
||||
if (ex instanceof MaxChangedBlocksException)
|
||||
return;
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
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 EffMakeWalls extends Effect {
|
||||
private Expression<Location> location1;
|
||||
private Expression<Location> location2;
|
||||
private Expression<EditSession> editSession;
|
||||
private Expression<ItemStack> blockList;
|
||||
|
||||
@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];
|
||||
blockList = (Expression<ItemStack>) expr[3];
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "make walls from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void execute(Event e) {
|
||||
Location pos1 = location1.getSingle(e);
|
||||
Location pos2 = location2.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList.getAll(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.makeWalls(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), Patterns.wrap(random));
|
||||
session.flushQueue();
|
||||
} catch (WorldEditException ex) {
|
||||
if (ex instanceof MaxChangedBlocksException)
|
||||
return;
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package me.TheBukor.SkStuff.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
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 EffRememberChanges extends Effect {
|
||||
private Expression<Player> player;
|
||||
private Expression<EditSession> editSession;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
editSession = (Expression<EditSession>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "make " + player.toString(e, false) + " remember changes from edit session";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(Event e) {
|
||||
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
Player p = player.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
if (we.getSession(p) == null) return;
|
||||
we.getSession(p).remember(session);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
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 EffReplaceBlocksWE extends Effect {
|
||||
private Expression<ItemStack> blockList1;
|
||||
private Expression<Location> location1;
|
||||
private Expression<Location> location2;
|
||||
private Expression<ItemStack> blockList2;
|
||||
private Expression<EditSession> editSession;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
blockList1 = (Expression<ItemStack>) expr[0];
|
||||
location1 = (Expression<Location>) expr[1];
|
||||
location2 = (Expression<Location>) expr[2];
|
||||
blockList2 = (Expression<ItemStack>) expr[3];
|
||||
editSession = (Expression<EditSession>) expr[4];
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "replace all " + blockList1.toString(e, false) + " from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " with " + blockList1.toString(e, false) + " using an edit session";
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
@Override
|
||||
protected void execute(Event e) {
|
||||
Location pos1 = location1.getSingle(e);
|
||||
Location pos2 = location2.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList1.getAll(e);
|
||||
ItemStack[] blocksToPlace = blockList2.getAll(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
Set<BaseBlock> blocksToReplace = new HashSet<BaseBlock>();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
blocksToReplace.add(new BaseBlock(b.getTypeId(), b.getDurability()));
|
||||
}
|
||||
}
|
||||
for (ItemStack b : blocksToPlace) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.replaceBlocks(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), blocksToReplace, Patterns.wrap(random));
|
||||
session.flushQueue();
|
||||
} catch (WorldEditException ex) {
|
||||
if (ex instanceof MaxChangedBlocksException)
|
||||
return;
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
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 EffSetBlocksWE extends Effect {
|
||||
private Expression<Location> location1;
|
||||
private Expression<Location> location2;
|
||||
private Expression<ItemStack> blockList;
|
||||
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];
|
||||
blockList = (Expression<ItemStack>) expr[2];
|
||||
editSession = (Expression<EditSession>) expr[3];
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "set all blocks from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " to " + blockList.toString(e, false) + " using an edit session";
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void execute(Event e) {
|
||||
Location pos1 = location1.getSingle(e);
|
||||
Location pos2 = location2.getSingle(e);
|
||||
EditSession session = editSession.getSingle(e);
|
||||
ItemStack[] blocks = blockList.getAll(e);
|
||||
RandomPattern random = new RandomPattern();
|
||||
if (session == null) return;
|
||||
for (ItemStack b : blocks) {
|
||||
if (b.getType().isBlock()) {
|
||||
random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
|
||||
}
|
||||
}
|
||||
try {
|
||||
session.setBlocks(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), Patterns.wrap(random));
|
||||
session.flushQueue();
|
||||
} catch (WorldEditException ex) {
|
||||
if (ex instanceof MaxChangedBlocksException)
|
||||
return;
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.TheBukor.SkStuff.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.TheBukor.SkStuff.effects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
|
||||
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 EffUndoRedoSession extends Effect {
|
||||
private Expression<EditSession> editSession;
|
||||
private boolean redo = false;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
editSession = (Expression<EditSession>) expr[0];
|
||||
if (result.mark == 1) redo = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return (redo == true ? "redo " : "undo ") + "changes from edit session";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(Event e) {
|
||||
EditSession session = editSession.getSingle(e);
|
||||
if (session == null) return;
|
||||
if (redo == false) {
|
||||
session.undo(session);
|
||||
} else {
|
||||
session.redo(session);
|
||||
}
|
||||
session.flushQueue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user