WorldEdit restored to soft dependency instead of dependency

This commit is contained in:
Ammar Askar
2013-01-12 16:00:22 +05:00
parent 83de6fc329
commit 5d0c3216c2
6 changed files with 100 additions and 64 deletions

View File

@@ -338,7 +338,7 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.RED + "You are not allowed to rollback more than " + rollbackMaxTime + " minutes");
return false;
}
if (rollbackMaxArea > 0 && (params.sel == null && params.loc == null || params.radius > rollbackMaxArea || params.sel != null && (params.sel.getLength() > rollbackMaxArea || params.sel.getWidth() > rollbackMaxArea))) {
if (rollbackMaxArea > 0 && (params.sel == null && params.loc == null || params.radius > rollbackMaxArea || params.sel != null && (params.sel.getSelection().getLength() > rollbackMaxArea || params.sel.getSelection().getWidth() > rollbackMaxArea))) {
sender.sendMessage(ChatColor.RED + "You are not allowed to rollback an area larger than " + rollbackMaxArea + " blocks");
return false;
}

View File

@@ -88,11 +88,7 @@ public class LogBlock extends JavaPlugin
}
if (noDb)
return;
if (pm.getPlugin("WorldEdit") == null) {
new Exception("WorldEdit is not installed please download and install").printStackTrace();
pm.disablePlugin(this);
return;
} else {
if (pm.getPlugin("WorldEdit") != null) {
LogBlockEditSessionFactory.initialize();
}
commandsHandler = new CommandsHandler(this);

View File

@@ -1,26 +1,7 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.config.Config.defaultDist;
import static de.diddiz.LogBlock.config.Config.defaultTime;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.BukkitUtils.getBlockEquivalents;
import static de.diddiz.util.MaterialName.materialName;
import static de.diddiz.util.Utils.isInt;
import static de.diddiz.util.Utils.join;
import static de.diddiz.util.Utils.listing;
import static de.diddiz.util.Utils.parseTimeSpec;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import de.diddiz.util.Block;
import de.diddiz.worldedit.RegionContainer;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -28,8 +9,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.util.Block;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.config.Config.*;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.BukkitUtils.getBlockEquivalents;
import static de.diddiz.util.MaterialName.materialName;
import static de.diddiz.util.Utils.*;
public final class QueryParams implements Cloneable
{
@@ -42,7 +33,7 @@ public final class QueryParams implements Cloneable
public List<String> killers = new ArrayList<String>();
public List<String> victims = new ArrayList<String>();
public boolean excludePlayersMode = false, excludeKillersMode = false, excludeVictimsMode = false, prepareToolQuery = false, silent = false;
public Selection sel = null;
public RegionContainer sel = null;
public SummarizationMode sum = SummarizationMode.NONE;
public List<Block> types = new ArrayList<Block>();
public World world = null;
@@ -285,7 +276,9 @@ public final class QueryParams implements Cloneable
else if (radius > 0)
where.append("x > '").append(loc.getBlockX() - radius).append("' AND x < '").append(loc.getBlockX() + radius).append("' AND y > '").append(loc.getBlockY() - radius).append("' AND y < '").append(loc.getBlockY() + radius).append("' AND z > '").append(loc.getBlockZ() - radius).append("' AND z < '").append(loc.getBlockZ() + radius).append("' AND ");
} else if (sel != null)
where.append("x >= '").append(sel.getMinimumPoint().getBlockX()).append("' AND x <= '").append(sel.getMaximumPoint().getBlockX()).append("' AND y >= '").append(sel.getMinimumPoint().getBlockY()).append("' AND y <= '").append(sel.getMaximumPoint().getBlockY()).append("' AND z >= '").append(sel.getMinimumPoint().getBlockZ()).append("' AND z <= '").append(sel.getMaximumPoint().getBlockZ()).append("' AND ");
where.append("x >= '").append(sel.getSelection().getMinimumPoint().getBlockX()).append("' AND x <= '").append(sel.getSelection().getMaximumPoint().getBlockX())
.append("' AND y >= '").append(sel.getSelection().getMinimumPoint().getBlockY()).append("' AND y <= '").append(sel.getSelection().getMaximumPoint().getBlockY())
.append("' AND z >= '").append(sel.getSelection().getMinimumPoint().getBlockZ()).append("' AND z <= '").append(sel.getSelection().getMaximumPoint().getBlockZ()).append("' AND ");
} else {
switch (blockChangeType) {
case ALL:
@@ -381,7 +374,9 @@ public final class QueryParams implements Cloneable
else if (radius > 0)
where.append("x > '").append(loc.getBlockX() - radius).append("' AND x < '").append(loc.getBlockX() + radius).append("' AND y > '").append(loc.getBlockY() - radius).append("' AND y < '").append(loc.getBlockY() + radius).append("' AND z > '").append(loc.getBlockZ() - radius).append("' AND z < '").append(loc.getBlockZ() + radius).append("' AND ");
} else if (sel != null)
where.append("x >= '").append(sel.getMinimumPoint().getBlockX()).append("' AND x <= '").append(sel.getMaximumPoint().getBlockX()).append("' AND y >= '").append(sel.getMinimumPoint().getBlockY()).append("' AND y <= '").append(sel.getMaximumPoint().getBlockY()).append("' AND z >= '").append(sel.getMinimumPoint().getBlockZ()).append("' AND z <= '").append(sel.getMaximumPoint().getBlockZ()).append("' AND ");
where.append("x >= '").append(sel.getSelection().getMinimumPoint().getBlockX()).append("' AND x <= '").append(sel.getSelection().getMaximumPoint().getBlockX())
.append("' AND y >= '").append(sel.getSelection().getMinimumPoint().getBlockY()).append("' AND y <= '").append(sel.getSelection().getMaximumPoint().getBlockY()).
append("' AND z >= '").append(sel.getSelection().getMinimumPoint().getBlockZ()).append("' AND z <= '").append(sel.getSelection().getMaximumPoint().getBlockZ()).append("' AND ");
}
if (!players.isEmpty() && sum != SummarizationMode.PLAYERS && blockChangeType != BlockChangeType.KILLS)
if (!excludePlayersMode) {
@@ -526,14 +521,11 @@ public final class QueryParams implements Cloneable
if (player == null)
throw new IllegalArgumentException("You have to ba a player to use selection");
final Plugin we = player.getServer().getPluginManager().getPlugin("WorldEdit");
if (we == null)
throw new IllegalArgumentException("WorldEdit plugin not found");
final Selection selection = ((WorldEditPlugin)we).getSelection(player);
if (selection == null)
throw new IllegalArgumentException("No selection defined");
if (!(selection instanceof CuboidSelection))
throw new IllegalArgumentException("You have to define a cuboid selection");
setSelection(selection);
if (we != null) {
setSelection(RegionContainer.fromPlayerSelection(player, we));
} else {
throw new IllegalArgumentException("WorldEdit not found!");
}
} else if (param.equals("time") || param.equals("since")) {
since = values.length > 0 ? parseTimeSpec(values) : defaultTime;
if (since == -1)
@@ -634,9 +626,9 @@ public final class QueryParams implements Cloneable
world = loc.getWorld();
}
public void setSelection(Selection sel) {
this.sel = sel;
world = sel.getWorld();
public void setSelection(RegionContainer container) {
this.sel = container;
world = sel.getSelection().getWorld();
}
public void setPlayer(String playerName) {

View File

@@ -1,11 +1,14 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.Session.hasSession;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static de.diddiz.LogBlock.config.Config.toolsByType;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import java.util.Map.Entry;
import de.diddiz.LogBlock.CommandsHandler;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.QueryParams;
import de.diddiz.LogBlock.Session;
import de.diddiz.LogBlock.Tool;
import de.diddiz.LogBlock.ToolBehavior;
import de.diddiz.LogBlock.ToolData;
import de.diddiz.LogBlock.ToolMode;
import de.diddiz.worldedit.RegionContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -17,14 +20,13 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import de.diddiz.LogBlock.CommandsHandler;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.QueryParams;
import de.diddiz.LogBlock.Session;
import de.diddiz.LogBlock.Tool;
import de.diddiz.LogBlock.ToolBehavior;
import de.diddiz.LogBlock.ToolData;
import de.diddiz.LogBlock.ToolMode;
import java.util.Map.Entry;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.Session.hasSession;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static de.diddiz.LogBlock.config.Config.toolsByType;
public class ToolListener implements Listener
{
@@ -56,11 +58,17 @@ public class ToolListener implements Listener
else if (block.getTypeId() != 54 || tool.params.radius != 0)
params.setLocation(block.getLocation());
else {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST})
if (block.getRelative(face).getTypeId() == 54)
params.setSelection(new CuboidSelection(event.getPlayer().getWorld(), block.getLocation(), block.getRelative(face).getLocation()));
if (params.sel == null)
params.setLocation(block.getLocation());
if (logblock.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
if (block.getRelative(face).getTypeId() == 54) {
params.setSelection(RegionContainer.fromCorners(event.getPlayer().getWorld(),
block.getLocation(), block.getRelative(face).getLocation()));
}
}
if (params.sel == null) {
params.setLocation(block.getLocation());
}
}
}
try {
if (toolData.mode == ToolMode.ROLLBACK)

View File

@@ -0,0 +1,41 @@
package de.diddiz.worldedit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class RegionContainer {
private Selection selection;
public RegionContainer(Selection sel) {
this.selection = sel;
}
public static RegionContainer fromPlayerSelection(Player player, Plugin plugin) {
final Selection selection = ((WorldEditPlugin) plugin).getSelection(player);
if (selection == null) {
throw new IllegalArgumentException("No selection defined");
}
if (!(selection instanceof CuboidSelection)) {
throw new IllegalArgumentException("You have to define a cuboid selection");
}
return new RegionContainer(selection);
}
public static RegionContainer fromCorners(World world, Location first, Location second) {
return new RegionContainer(new CuboidSelection(world, first, second));
}
public Selection getSelection() {
return selection;
}
public void setSelection(Selection selection) {
this.selection = selection;
}
}

View File

@@ -5,8 +5,7 @@ authors: [md_5, ammar2]
website: http://dev.bukkit.org/server-mods/logblock/
main: de.diddiz.LogBlock.LogBlock
description: ${project.description}
softdepend: [LogBlockQuestioner]
depend: [WorldEdit]
softdepend: [LogBlockQuestioner, WorldEdit]
commands:
lb:
description: 'LogBlock plugin commands'