use of br.net.fabiozumbi12.RedProtect.Sponge.region.RegionBuilder in project RedProtect by FabioZumbi12.
the class WEHook method pasteWithWE.
public static Region pasteWithWE(Player p, File file) {
World world = p.getWorld();
Location loc = p.getLocation();
final Region[] r = { null };
if (!p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().isSolid()) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.needground");
return null;
}
Clipboard clipboard = null;
ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format == null) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.copyfail");
return null;
}
try (ClipboardReader reader = format.getReader(new FileInputStream(file))) {
clipboard = reader.read();
} catch (IOException e) {
CoreUtil.printJarVersion();
e.printStackTrace();
}
if (clipboard != null) {
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1)) {
BlockVector3 to = BlockVector3.at(loc.getX(), loc.getY(), loc.getZ());
// Rotate to player looking direction
float yaw = loc.getYaw();
if (yaw < 0) {
yaw += 360;
}
int rotate = 0;
if (yaw >= 315 || yaw < 45) {
rotate = 180;
} else if (yaw < 135) {
rotate = 270;
} else if (yaw < 225) {
rotate = 0;
} else if (yaw < 315) {
rotate = 90;
}
ClipboardHolder holder = new ClipboardHolder(clipboard);
AffineTransform transform = new AffineTransform();
transform = transform.rotateY(-rotate);
holder.setTransform(holder.getTransform().combine(transform));
Operation operation = holder.createPaste(editSession).to(to).ignoreAirBlocks(false).build();
Operations.complete(operation);
// Select the region min and max
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
Vector3 locMax = realTo.add(holder.getTransform().apply(clipboard.getRegion().getMaximumPoint().subtract(clipboard.getRegion().getMinimumPoint()).toVector3()));
Location min = new Location(world, realTo.getX(), realTo.getY(), realTo.getZ());
Location max = new Location(world, locMax.getX(), locMax.getY(), locMax.getZ());
if (RedProtect.get().getConfigManager().configRoot().region_settings.autoexpandvert_ondefine) {
min.setY(p.getWorld().getMinHeight());
max.setY(p.getWorld().getMaxHeight());
if (RedProtect.get().getConfigManager().configRoot().region_settings.claim.miny != -1)
min.setY(RedProtect.get().getConfigManager().configRoot().region_settings.claim.miny);
if (RedProtect.get().getConfigManager().configRoot().region_settings.claim.maxy != -1)
max.setY(RedProtect.get().getConfigManager().configRoot().region_settings.claim.maxy);
}
RedProtect.get().getLanguageManager().sendMessage(p, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(p, min, max, "", new PlayerRegion(p.getUniqueId().toString(), p.getName()), new HashSet<>(), false);
if (rb2.ready()) {
r[0] = rb2.build();
}
});
} catch (WorldEditException e) {
CoreUtil.printJarVersion();
e.printStackTrace();
r[0] = null;
}
}
return r[0];
}
use of br.net.fabiozumbi12.RedProtect.Sponge.region.RegionBuilder in project RedProtect by FabioZumbi12.
the class WEHook method pasteWithWE.
public static Region pasteWithWE(Player p, File file) {
Location<World> loc = p.getLocation();
Region r = null;
if (p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.WATER) || p.getLocation().getBlockRelative(Direction.DOWN).getBlock().getType().equals(BlockTypes.FLOWING_WATER)) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.needground");
return null;
}
SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());
LocalSession session = SpongeWorldEdit.inst().getSession(p);
Closer closer = Closer.create();
try {
ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
FileInputStream fis = closer.register(new FileInputStream(file));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardReader reader = format.getReader(bis);
WorldData worldData = ws.getWorldData();
Clipboard clipboard = reader.read(ws.getWorldData());
session.setClipboard(new ClipboardHolder(clipboard, worldData));
Vector bmin = clipboard.getMinimumPoint();
Vector bmax = clipboard.getMaximumPoint();
Location<World> min = loc.add(bmin.getX(), bmin.getY(), bmin.getZ());
Location<World> max = loc.add(bmax.getX(), bmax.getY(), bmax.getZ());
PlayerRegion leader = new PlayerRegion(p.getUniqueId().toString(), p.getName());
RegionBuilder rb2 = new DefineRegionBuilder(p, min, max, "", leader, new HashSet<>(), false);
if (rb2.ready()) {
r = rb2.build();
}
ClipboardHolder holder = session.getClipboard();
Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
Operations.completeLegacy(op);
} catch (IOException | EmptyClipboardException | IncompleteRegionException | MaxChangedBlocksException e) {
CoreUtil.printJarVersion();
e.printStackTrace();
}
return r;
}
use of br.net.fabiozumbi12.RedProtect.Sponge.region.RegionBuilder in project RedProtect by FabioZumbi12.
the class RPBlockListener method onSignPlace.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onSignPlace(ChangeSignEvent e, @First Player p) {
RedProtect.get().logger.debug("blocks", "BlockListener - Is SignChangeEvent event! Cancelled? " + e.isCancelled());
Sign s = e.getTargetTile();
List<Text> lines = e.getText().asList();
Location<World> loc = s.getLocation();
World w = p.getWorld();
BlockSnapshot b = w.createSnapshot(loc.getBlockPosition());
if (b == null) {
this.setErrorSign(e, p, RPLang.get("blocklistener.block.null"));
return;
}
Region signr = RedProtect.get().rm.getTopRegion(loc);
if (signr != null && !signr.canSign(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
e.setCancelled(true);
return;
}
Text line1 = lines.get(0);
if (lines.size() != 4) {
this.setErrorSign(e, p, RPLang.get("blocklistener.sign.wronglines"));
return;
}
if (RedProtect.get().cfgs.getBool("server-protection.sign-spy.enabled")) {
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
if (!RedProtect.get().cfgs.getBool("server-protection.sign-spy.only-console")) {
for (Player play : Sponge.getServer().getOnlinePlayers()) {
if (RedProtect.get().ph.hasGenPerm(play, "redprotect.signspy")) /* && !play.equals(p)*/
{
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
}
}
}
}
if ((RedProtect.get().cfgs.getBool("private.use") && s.getType().equals(TileEntityTypes.SIGN)) && (line1.toPlain().equalsIgnoreCase("private") || line1.toPlain().equalsIgnoreCase("[private]") || line1.toPlain().equalsIgnoreCase(RPLang.get("blocklistener.container.signline")) || line1.toPlain().equalsIgnoreCase("[" + RPLang.get("blocklistener.container.signline") + "]"))) {
Region r = RedProtect.get().rm.getTopRegion(loc);
Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
if (out || r != null) {
if (cont.isContainer(b)) {
int length = p.getName().length();
if (length > 16) {
length = 16;
}
lines.set(1, RPUtil.toText(p.getName().substring(0, length)));
e.getText().setElements(lines);
RPLang.sendMessage(p, "blocklistener.container.protected");
return;
} else {
RPLang.sendMessage(p, "blocklistener.container.notprotected");
// w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
return;
}
} else {
RPLang.sendMessage(p, "blocklistener.container.notregion");
// w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
return;
}
}
if (line1.toPlain().equalsIgnoreCase("[rp]")) {
String claimmode = RedProtect.get().cfgs.getWorldClaimType(p.getWorld().getName());
if ((!claimmode.equalsIgnoreCase("BLOCK") && !claimmode.equalsIgnoreCase("BOTH")) && !RedProtect.get().ph.hasPerm(p, "redprotect.admin.create")) {
this.setErrorSign(e, p, RPLang.get("blocklistener.region.claimmode"));
return;
}
RegionBuilder rb = new EncompassRegionBuilder(e);
if (rb.ready()) {
Region r = rb.build();
lines.set(0, RPUtil.toText(RPLang.get("blocklistener.region.signcreated")));
lines.set(1, RPUtil.toText(r.getName()));
e.getText().setElements(lines);
// RPLang.sendMessage(p, RPLang.get("blocklistener.region.created").replace("{region}", r.getName()));
RedProtect.get().rm.add(r, RedProtect.get().serv.getWorld(r.getWorld()).get());
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.region.RegionBuilder in project RedProtect by FabioZumbi12.
the class ClaimCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
HandleHelpPage(sender, 1);
return true;
}
Player player = (Player) sender;
String claimmode = RedProtect.get().getConfigManager().getWorldClaimType(player.getWorld().getName());
if (!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH") && !RedProtect.get().getPermissionHandler().hasCommandPerm(player, "claim")) {
RedProtect.get().getLanguageManager().sendMessage(player, "blocklistener.region.blockmode");
return true;
}
if (args.length == 0) {
String name = RedProtect.get().getUtil().nameGen(player.getName(), player.getWorld().getName());
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, new PlayerRegion(player.getUniqueId().toString(), player.getName()), new HashSet<>(), false);
if (rb2.ready()) {
Region r2 = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().getRegionManager().add(r2, player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
});
return true;
}
if (args.length == 1) {
String name = args[0];
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, new PlayerRegion(player.getUniqueId().toString(), player.getName()), new HashSet<>(), false);
if (rb2.ready()) {
Region r2 = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().getRegionManager().add(r2, player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
});
return true;
}
if (args.length == 2) {
String name = args[0];
Set<PlayerRegion> addedAdmins = new HashSet<>();
addedAdmins.add(new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(args[1]), args[1]));
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, new PlayerRegion(player.getUniqueId().toString(), player.getName()), addedAdmins, false);
if (rb2.ready()) {
Region r2 = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().getRegionManager().add(r2, player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
});
return true;
}
RedProtect.get().getLanguageManager().sendCommandHelp(sender, "claim", true);
return true;
}
use of br.net.fabiozumbi12.RedProtect.Sponge.region.RegionBuilder in project RedProtect by FabioZumbi12.
the class CreatePortalCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
HandleHelpPage(sender, 1);
return true;
}
Player player = (Player) sender;
// rp createportal <regionName> <regionTo> <world>
if (args.length == 3) {
World w = RedProtect.get().getServer().getWorld(args[2]);
if (w == null) {
sender.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.region.invalidworld"));
return true;
}
Region r = RedProtect.get().getRegionManager().getRegion(args[1], w.getName());
if (r == null) {
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.createportal.warning").replace("{region}", args[1]));
}
PlayerRegion serverName = new PlayerRegion(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader, RedProtect.get().getConfigManager().configRoot().region_settings.default_leader);
String name = Normalizer.normalize(args[0].replace(" ", "_"), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").replaceAll("[^\\p{L}0-9 ]", "");
final Region[] r2 = { RedProtect.get().getRegionManager().getRegion(name, w.getName()) };
if (r == r2[0]) {
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.createportal.equals"));
return true;
}
if (r2[0] != null) {
if ((!r2[0].isLeader(player) || !r2[0].isAdmin(player)) && !r2[0].canBuild(player)) {
RedProtect.get().getLanguageManager().sendMessage(player, "no.permission");
return true;
}
RedProtect.get().getLanguageManager().sendMessage(player, String.format(RedProtect.get().getLanguageManager().get("cmdmanager.region.portalcreated"), name, args[1], w.getName()));
RedProtect.get().getLanguageManager().sendMessage(player, "cmdmanager.region.portalhint");
r2[0].setFlag(sender, "set-portal", args[1] + " " + w.getName());
RedProtect.get().logger.addLog("(World " + r2[0].getWorld() + ") Player " + player.getName() + " CREATED A PORTAL " + r2[0].getName() + " to " + args[1] + " database " + w.getName());
} else {
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new HashSet<>(), true);
if (rb2.ready()) {
r2[0] = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, String.format(RedProtect.get().getLanguageManager().get("cmdmanager.region.portalcreated"), name, args[1], w.getName()));
RedProtect.get().getLanguageManager().sendMessage(player, "cmdmanager.region.portalhint");
r2[0].setFlag(sender, "set-portal", args[1] + " " + w.getName());
RedProtect.get().getRegionManager().add(r2[0], player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2[0].getWorld() + ") Player " + player.getName() + " CREATED A PORTAL " + r2[0].getName() + " to " + args[1] + " database " + w.getName());
}
});
}
return true;
}
RedProtect.get().getLanguageManager().sendCommandHelp(sender, "createportal", true);
return true;
}
Aggregations