use of com.sk89q.worldedit.IncompleteRegionException in project Prism-Bukkit by prism.
the class WorldEditBridge method getSelectedArea.
/**
* Worldedit bridge.
*
* @param plugin Prism
* @param player Player
* @param parameters {@link QueryParameters}
* @return boolean.
*/
public static boolean getSelectedArea(Plugin plugin, Player player, QueryParameters parameters) {
// Get selected area
Region region = null;
try {
final BukkitPlayer lp = BukkitAdapter.adapt(player);
final World lw = lp.getWorld();
LocalSession session = WorldEdit.getInstance().getSessionManager().getIfPresent(lp);
if (session != null) {
region = session.getSelection(lw);
}
if (region == null) {
return false;
}
final Vector minLoc = new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
final Vector maxLoc = new Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
final Region sel = session.getRegionSelector(lw).getRegion();
final double lRadius = ((float) sel.getLength() + 1) / 2;
final double wRadius = ((float) sel.getWidth() + 1) / 2;
final double hRadius = ((float) sel.getHeight() + 1) / 2;
String procType = "applier";
if (parameters.getProcessType().equals(PrismProcessType.LOOKUP)) {
procType = "lookup";
}
final int maxRadius = plugin.getConfig().getInt("prism.queries.max-" + procType + "-radius");
if (maxRadius != 0 && (lRadius > maxRadius || wRadius > maxRadius || hRadius > maxRadius) && !player.hasPermission("prism.override-max-" + procType + "-radius")) {
return false;
} else {
parameters.setWorld(region.getWorld().getName());
parameters.setMinLocation(minLoc);
parameters.setMaxLocation(maxLoc);
}
} catch (final IncompleteRegionException e) {
return false;
}
return true;
}
use of com.sk89q.worldedit.IncompleteRegionException in project RedProtect by FabioZumbi12.
the class AWEListener method regenRegion.
public static void regenRegion(final br.net.fabiozumbi12.RedProtect.Bukkit.Region r, final World w, final Location p1, final Location p2, final int delay, final CommandSender sender, final boolean remove) {
Bukkit.getScheduler().scheduleSyncDelayedTask(RedProtect.get(), () -> {
if (RPUtil.stopRegen) {
return;
}
CuboidSelection csel = new CuboidSelection(w, p1, p2);
Region wreg;
try {
wreg = csel.getRegionSelector().getRegion();
} catch (IncompleteRegionException e1) {
e1.printStackTrace();
return;
}
AsyncWorldEditBukkit aweMain = (AsyncWorldEditBukkit) Bukkit.getPluginManager().getPlugin("AsyncWorldEdit");
IBlockPlacer bPlacer = aweMain.getBlockPlacer();
final IBlockPlacerListener listener = new IBlockPlacerListener() {
@Override
public void jobAdded(IJobEntry job) {
/*if (job.getPlayer().getName().equals("redprotect")){
String name = job.getName();
//job.addStateChangedListener(stateListener);
RedProtect.get().logger.warning("JobAdded: " + name + " of region " + r.getName() + " - " + job.getStatus() + ": " + job.isTaskDone());
}*/
}
@Override
public void jobRemoved(IJobEntry job) {
if (job.getPlayer().getName().equals("redprotect")) {
String name = job.getName();
// job.addStateChangedListener(stateListener);
if (RPConfig.getBool("purge.regen.awe-logs") && job.isTaskDone()) {
RedProtect.get().logger.sucess("JobDone: " + name + " of region " + r.getName() + " - " + job.getStatus() + ": " + job.getStatusString());
}
}
}
};
bPlacer.addListener(listener);
AsyncEditSessionFactory factory = (AsyncEditSessionFactory) WorldEdit.getInstance().getEditSessionFactory();
EditSession ess = factory.getEditSession(wreg.getWorld(), -1);
eSessions.put(r.getID(), ess);
int delayCount = 1 + delay / 10;
if (sender != null) {
if (AsyncWorld.wrap(wreg.getWorld(), new PlayerManager(aweMain).createFakePlayer("redprotect", UUID.randomUUID())).regenerate(wreg, ess)) {
RPLang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
} else {
RPLang.sendMessage(sender, "[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
}
} else {
if (AsyncWorld.wrap(wreg.getWorld(), new PlayerManager(aweMain).createFakePlayer("redprotect", UUID.randomUUID())).regenerate(wreg, ess)) {
RedProtect.get().logger.warning("[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
} else {
RedProtect.get().logger.warning("[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
}
}
if (remove) {
RedProtect.get().rm.remove(r, RedProtect.get().serv.getWorld(r.getWorld()));
}
if (RPConfig.getInt("purge.regen.stop-server-every") > 0 && delayCount > RPConfig.getInt("purge.regen.stop-server-every")) {
Bukkit.getScheduler().cancelTasks(RedProtect.get());
RedProtect.get().rm.saveAll();
Bukkit.getServer().shutdown();
}
}, delay);
}
use of com.sk89q.worldedit.IncompleteRegionException in project HawkEye by oliverwoodings.
the class WorldEditRollbackCommand method execute.
@Override
public boolean execute() {
// Check if player already has a rollback processing
if (session.doingRollback()) {
Util.sendMessage(sender, "&cYou already have a rollback command processing!");
return true;
}
// Check if WorldEdit is enabled
if (HawkEye.worldEdit == null) {
Util.sendMessage(sender, "&7WorldEdit&c is not enabled, unable to perform rollbacks in selected region");
return true;
}
// Check if the WorldEdit selection is complete
Region region = null;
try {
LocalPlayer lp = new BukkitPlayer(HawkEye.worldEdit, HawkEye.worldEdit.getWorldEdit().getServer(), player);
LocalWorld lw = lp.getWorld();
region = HawkEye.worldEdit.getWorldEdit().getSession(lp).getSelection(lw);
} catch (IncompleteRegionException e) {
Util.sendMessage(sender, "&cPlease complete your selection before doing a &7WorldEdit&c rollback!");
return true;
}
// Parse arguments
SearchParser parser = null;
try {
parser = new SearchParser(player, args);
// Check that supplied actions can rollback
if (parser.actions.size() > 0) {
for (DataType type : parser.actions) if (!type.canRollback())
throw new IllegalArgumentException("You cannot rollback that action type: &7" + type.getConfigName());
} else // If none supplied, add in all rollback types
{
for (DataType type : DataType.values()) if (type.canRollback())
parser.actions.add(type);
}
} catch (IllegalArgumentException e) {
Util.sendMessage(sender, "&c" + e.getMessage());
return true;
}
// Set WorldEdit locations
parser.minLoc = new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
parser.maxLoc = new Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
// Create new SearchQuery with data
new SearchQuery(new RollbackCallback(session, RollbackType.GLOBAL), parser, SearchDir.DESC);
return true;
}
Aggregations