use of com.sk89q.worldguard.bukkit.RegionContainer in project Plot-System by AlpsBTE.
the class RawPlotGenerator method createProtection.
@Override
protected void createProtection() {
RegionContainer container = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
RegionManager regionManager = container.get(getPlot().getWorld().getBukkitWorld());
if (regionManager != null) {
for (String regionID : regionManager.getRegions().keySet()) {
regionManager.removeRegion(regionID);
}
} else {
throw new RuntimeException("Region Manager is null");
}
super.createProtection();
}
use of com.sk89q.worldguard.bukkit.RegionContainer in project Plot-System by AlpsBTE.
the class AbstractPlotGenerator method createProtection.
/**
* Creates plot protection
*/
protected void createProtection() {
BlockVector min = BlockVector.toBlockPoint(0, 1, 0);
BlockVector max = BlockVector.toBlockPoint(PlotManager.PLOT_SIZE, 256, PlotManager.PLOT_SIZE);
RegionContainer container = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
RegionManager regionManager = container.get(plot.getWorld().getBukkitWorld());
// Create protected region for world
GlobalProtectedRegion globalRegion = new GlobalProtectedRegion("__global__");
globalRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
globalRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.ALL);
// Create protected region for plot
ProtectedRegion protectedPlotRegion = new ProtectedCuboidRegion(plot.getWorld().getWorldName(), min, max);
protectedPlotRegion.setPriority(100);
// Add and save regions
try {
if (regionManager != null) {
regionManager.addRegion(globalRegion);
regionManager.addRegion(protectedPlotRegion);
regionManager.saveChanges();
} else {
throw new RuntimeException("Region Manager is null");
}
} catch (StorageException ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while saving plot protection!", ex);
throw new RuntimeException("Plot protection creation completed exceptionally");
}
// Add plot owner
DefaultDomain owner = protectedPlotRegion.getOwners();
owner.addPlayer(builder.getUUID());
protectedPlotRegion.setOwners(owner);
// Set permissions
protectedPlotRegion.setFlag(DefaultFlag.PASSTHROUGH, StateFlag.State.ALLOW);
protectedPlotRegion.setFlag(DefaultFlag.PASSTHROUGH.getRegionGroupFlag(), RegionGroup.OWNERS);
protectedPlotRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.ALLOW);
protectedPlotRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.ALL);
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getCommandsConfig();
List<String> allowedCommandsNonBuilder = config.getStringList(ConfigPaths.ALLOWED_COMMANDS_NON_BUILDERS);
allowedCommandsNonBuilder.removeIf(c -> c.equals("/cmd1"));
for (BaseCommand baseCommand : PlotSystem.getPlugin().getCommandManager().getBaseCommands()) {
allowedCommandsNonBuilder.addAll(Arrays.asList(baseCommand.getNames()));
for (String command : baseCommand.getNames()) {
allowedCommandsNonBuilder.add("/" + command);
}
}
List<String> blockedCommandsBuilders = config.getStringList(ConfigPaths.BLOCKED_COMMANDS_BUILDERS);
blockedCommandsBuilders.removeIf(c -> c.equals("/cmd1"));
protectedPlotRegion.setFlag(DefaultFlag.BLOCKED_CMDS, new HashSet<>(blockedCommandsBuilders));
protectedPlotRegion.setFlag(DefaultFlag.BLOCKED_CMDS.getRegionGroupFlag(), RegionGroup.OWNERS);
protectedPlotRegion.setFlag(DefaultFlag.ALLOWED_CMDS, new HashSet<>(allowedCommandsNonBuilder));
protectedPlotRegion.setFlag(DefaultFlag.ALLOWED_CMDS.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
}
use of com.sk89q.worldguard.bukkit.RegionContainer in project Plot-System by AlpsBTE.
the class EventListener method onPlayerInteractEvent.
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
if (event.getItem() != null && event.getItem().equals(CompanionMenu.getMenuItem(event.getPlayer()))) {
event.getPlayer().performCommand("companion");
} else if (event.getItem() != null && event.getItem().equals(ReviewMenu.getMenuItem(event.getPlayer()))) {
event.getPlayer().performCommand("review");
}
}
// Open/Close iron trap door when right-clicking
if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (event.getHand() != EquipmentSlot.OFF_HAND) {
if (!event.getPlayer().isSneaking()) {
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.IRON_TRAPDOOR) {
RegionContainer regionContainer = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
RegionQuery query = regionContainer.createQuery();
if (query.testBuild(event.getPlayer().getLocation(), PlotSystem.DependencyManager.getWorldGuard().wrapPlayer(event.getPlayer()), DefaultFlag.INTERACT)) {
BlockState state = event.getClickedBlock().getState();
TrapDoor tp = (TrapDoor) state.getData();
if (!tp.isOpen()) {
tp.setOpen(true);
event.getPlayer().playSound(event.getClickedBlock().getLocation(), "block.iron_trapdoor.open", 1f, 1f);
} else {
tp.setOpen(false);
event.getPlayer().playSound(event.getClickedBlock().getLocation(), "block.iron_trapdoor.close", 1f, 1f);
}
state.update();
}
}
}
}
}
}
use of com.sk89q.worldguard.bukkit.RegionContainer in project Storage by D-x-Z.
the class BlockBreak method onBreaking.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBreaking(@NotNull BlockBreakEvent e) {
Player p = e.getPlayer();
String blocks = e.getBlock().getType().toString();
String items = null;
NMSAssistant nms = new NMSAssistant();
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(p);
Location loc = new Location(p.getWorld(), e.getBlock().getLocation().getBlockX(), e.getBlock().getLocation().getBlockY(), e.getBlock().getLocation().getBlockZ());
RegionContainer container = WorldGuardPlugin.inst().getRegionContainer();
RegionQuery query = container.createQuery();
if (!query.testState(loc, localPlayer, DefaultFlag.BLOCK_BREAK) && !p.hasPermission("Storage.admin")) {
e.setCancelled(true);
return;
}
e.getBlock().getDrops().clear();
if (nms.isVersion(12)) {
e.setDropItems(false);
}
List<String> w = getconfigfile().getStringList("Blacklist-World");
if (!w.contains(p.getWorld().getName())) {
if (autoPick(p)) {
for (String getBlockType : Objects.requireNonNull(getconfigfile().getConfigurationSection("Blocks.")).getKeys(false)) {
if (blocks.equalsIgnoreCase(getBlockType)) {
items = getconfigfile().getString("Blocks." + blocks + ".Name");
break;
}
}
if (items == null) {
return;
}
if (getMaxStorage(p, blocks) == 0) {
setMaxStorage(p, blocks, getconfigfile().getInt("Default_Max_Storage"));
}
if (p.getItemInHand() != null && p.getItemInHand().getItemMeta().hasEnchant(Enchantment.LOOT_BONUS_BLOCKS)) {
if (getRandomInt(getconfigfile().getInt("Fortune.Chance.System.Min"), getconfigfile().getInt("Fortune.Chance.System.Max")) <= (p.getItemInHand().getItemMeta().getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS) * getconfigfile().getInt("Fortune.Chance.Player"))) {
int fortune = getRandomInt(getconfigfile().getInt("Fortune.Drop.Min"), getconfigfile().getInt("Fortune.Drop.Max"));
addStorage(p, blocks, 1 + fortune);
} else {
addStorage(p, blocks, 1);
}
} else {
addStorage(p, blocks, 1);
}
}
}
}
use of com.sk89q.worldguard.bukkit.RegionContainer in project UltraCosmetics by iSach.
the class FlagManager method categoryFlagCheck.
@Override
protected Set<Category> categoryFlagCheck(Player bukkitPlayer) {
RegionContainer rc = WGBukkit.getPlugin().getRegionContainer();
RegionQuery query = rc.createQuery();
return query.queryValue(bukkitPlayer.getLocation(), bukkitPlayer, CATEGORY_FLAG);
}
Aggregations