use of com.sk89q.worldguard.config.ConfigurationManager in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
handleBlockRightClick(event);
} else if (event.getAction() == Action.PHYSICAL) {
handlePhysicalInteract(event);
}
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(world);
if (wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
int slot = player.getInventory().getHeldItemSlot();
ItemStack heldItem = player.getInventory().getItem(slot);
if (heldItem != null && heldItem.getAmount() < 0) {
player.getInventory().setItem(slot, null);
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
}
}
}
use of com.sk89q.worldguard.config.ConfigurationManager in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerJoin.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(world);
if (cfg.activityHaltToggle) {
player.sendMessage(ChatColor.YELLOW + "Intensive server activity has been HALTED.");
int removed = 0;
for (Entity entity : world.getEntities()) {
if (Entities.isIntensiveEntity(BukkitAdapter.adapt(entity))) {
entity.remove();
removed++;
}
}
if (removed > 10) {
log.info("Halt-Act: " + removed + " entities (>10) auto-removed from " + player.getWorld());
}
}
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW + "Fire spread is currently globally disabled for this world.");
}
Events.fire(new ProcessPlayerEvent(player));
WorldGuard.getInstance().getExecutorService().submit(() -> WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
}
use of com.sk89q.worldguard.config.ConfigurationManager in project WorldGuard by EngineHub.
the class ToggleCommands method stopLag.
@Command(aliases = { "halt-activity", "stoplag", "haltactivity" }, usage = "[confirm]", desc = "Attempts to cease as much activity in order to stop lag", flags = "cis", max = 1)
@CommandPermissions({ "worldguard.halt-activity" })
public void stopLag(CommandContext args, Actor sender) throws CommandException {
ConfigurationManager configManager = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
if (args.hasFlag('i')) {
if (configManager.activityHaltToggle) {
sender.print("ALL intensive server activity is not allowed.");
} else {
sender.print("ALL intensive server activity is allowed.");
}
} else {
boolean activityHaltToggle = !args.hasFlag('c');
if (activityHaltToggle && (args.argsLength() == 0 || !args.getString(0).equalsIgnoreCase("confirm"))) {
String confirmCommand = "/" + args.getCommand() + " confirm";
TextComponent message = TextComponent.builder("").append(ErrorFormat.wrap("This command will ")).append(ErrorFormat.wrap("PERMANENTLY").decoration(TextDecoration.BOLD, TextDecoration.State.TRUE)).append(ErrorFormat.wrap(" erase ALL animals in ALL loaded chunks in ALL loaded worlds. ")).append(TextComponent.newline()).append(TextComponent.of("[Click]", TextColor.GREEN).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, confirmCommand)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to confirm /" + args.getCommand())))).append(ErrorFormat.wrap(" or type ")).append(CodeFormat.wrap(confirmCommand).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, confirmCommand))).append(ErrorFormat.wrap(" to confirm.")).build();
sender.print(message);
return;
}
configManager.activityHaltToggle = activityHaltToggle;
if (activityHaltToggle) {
if (!(sender instanceof LocalPlayer)) {
sender.print("ALL intensive server activity halted.");
}
if (!args.hasFlag('s')) {
worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity halted by " + sender.getDisplayName() + "."));
} else {
sender.print("(Silent) ALL intensive server activity halted by " + sender.getDisplayName() + ".");
}
for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
int removed = 0;
for (Entity entity : world.getEntities()) {
if (Entities.isIntensiveEntity(entity)) {
entity.remove();
removed++;
}
}
if (removed > 10) {
sender.printRaw("" + removed + " entities (>10) auto-removed from " + world.getName());
}
}
} else {
if (!args.hasFlag('s')) {
worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity is now allowed."));
if (!(sender instanceof LocalPlayer)) {
sender.print("ALL intensive server activity is now allowed.");
}
} else {
sender.print("(Silent) ALL intensive server activity is now allowed.");
}
}
}
}
use of com.sk89q.worldguard.config.ConfigurationManager in project WorldGuard by EngineHub.
the class WorldGuardCommands method reload.
@Command(aliases = { "reload" }, desc = "Reload WorldGuard configuration", max = 0)
@CommandPermissions({ "worldguard.reload" })
public void reload(CommandContext args, Actor sender) throws CommandException {
// TODO: This is subject to a race condition, but at least other commands are not being processed concurrently
List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
if (!tasks.isEmpty()) {
throw new CommandException("There are currently pending tasks. Use /wg running to monitor these tasks first.");
}
LoggerToChatHandler handler = null;
Logger minecraftLogger = null;
if (sender instanceof LocalPlayer) {
handler = new LoggerToChatHandler(sender);
handler.setLevel(Level.ALL);
minecraftLogger = Logger.getLogger("com.sk89q.worldguard");
minecraftLogger.addHandler(handler);
}
try {
ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
config.unload();
config.load();
for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
config.get(world);
}
WorldGuard.getInstance().getPlatform().getRegionContainer().reload();
// WGBukkit.cleanCache();
sender.print("WorldGuard configuration reloaded.");
} catch (Throwable t) {
sender.printError("Error while reloading: " + t.getMessage());
} finally {
if (minecraftLogger != null) {
minecraftLogger.removeHandler(handler);
}
}
}
use of com.sk89q.worldguard.config.ConfigurationManager in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerCommandPreprocess.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
Set<String> allowedCommands = set.queryValue(localPlayer, Flags.ALLOWED_CMDS);
Set<String> blockedCommands = set.queryValue(localPlayer, Flags.BLOCKED_CMDS);
CommandFilter test = new CommandFilter(allowedCommands, blockedCommands);
if (!test.apply(event.getMessage())) {
String message = set.queryValue(localPlayer, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("use " + event.getMessage(), localPlayer, message);
event.setCancelled(true);
return;
}
}
if (cfg.blockInGameOp) {
if (opPattern.matcher(event.getMessage()).matches()) {
player.sendMessage(ChatColor.RED + "/op and /deop can only be used in console (as set by a WG setting).");
event.setCancelled(true);
return;
}
}
}
Aggregations