Updated WorldEdit and WorldGuard to 7.0.0

It doesn't work without them atm because it tries to load a class from them
This commit is contained in:
Norbi Peti 2019-08-28 23:29:40 +02:00
parent 24ed3393d3
commit 14bdf0ebe0
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 1093 additions and 1089 deletions

542
pom.xml
View file

@ -1,268 +1,274 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.jaschastarke</groupId>
<artifactId>LimitedCreative</artifactId>
<name>LimitedCreative</name>
<version>2.3-SNAPSHOT</version>
<url>https://github.com/possi/LimitedCreative</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plib.version>1.4-SNAPSHOT</plib.version>
<bukkit.version>1.12.2-R0.1-SNAPSHOT</bukkit.version>
</properties>
<scm>
<connection>scm:git:git://github.com/possi/LimitedCreative.git</connection>
<developerConnection>scm:git:git@github.com:possi/LimitedCreative.git</developerConnection>
<url>https://github.com/possi/LimitedCreative/tree/plib</url>
</scm>
<distributionManagement>
<repository>
<id>de-jas-repo</id>
<url>scp://repo@ja-s.de/var/customers/webs/repo/mvn</url>
</repository>
</distributionManagement>
<ciManagement>
<system>jenkins</system>
<url>http://ci.ja-s.de:8080/</url>
</ciManagement>
<issueManagement>
<system>BukkitDev</system>
<url>http://dev.bukkit.org/server-mods/limited-creative/tickets/</url>
</issueManagement>
<repositories>
<!-- Possible public Maven Repository, containing LimitedCreative builds and other dependencies without own rep.
like AuthMe, etc.
Supports http only -->
<repository>
<id>de-jas-rep</id>
<url>http://repo.ja-s.de/mvn</url>
</repository>
<!-- Official (Craft-)Bukkit repository -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- Official WorldGuard and WorldEdit repository -->
<repository>
<id>sk89q-mvn2</id>
<url>http://maven.sk89q.com/repo</url>
</repository>
<!-- Official Multiverse repository -->
<repository>
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public</url>
</repository>
<!-- Official xAuth repository; it is no good! we keep our own dep-files of it - ->
<repository>
<id>luricos.de-repo</id>
<url>http://repo.luricos.de/bukkit-plugins/</url>
</repository><!- - -->
<!-- Official LogBlock repository -->
<repository>
<id>md5</id>
<url>http://repo.md-5.net/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>de-jas-rep</id>
<url>http://repo.ja-s.de/mvn</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>de.jaschastarke</groupId>
<artifactId>plib</artifactId>
<version>${plib.version}</version>
</dependency>
<dependency>
<!-- http://dl.bukkit.org/ -->
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>6.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
<groupId>uk.org.whoami</groupId>
<artifactId>authme</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/multiverse-core/ -->
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/multiworld-v-2-0/ -->
<groupId>multiworld</groupId>
<artifactId>multiworld</artifactId>
<version>4.7.2</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/xauth/ -->
<groupId>com.cypherx</groupId>
<artifactId>xauth</artifactId>
<version>2.0.26</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/coreprotect/ -->
<groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId>
<version>2.0.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.avaje/ebean -->
<dependency>
<groupId>org.avaje</groupId>
<artifactId>ebean</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<annotationProcessors>
<!-- Needed to fetch DocComments from Source -->
<annotationProcessor>de.jaschastarke.maven.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>de.jaschastarke</groupId>
<artifactId>plib</artifactId>
<version>${plib.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>pluginyaml</goal>
</goals>
<configuration>
<!-- plugin.yml -->
<mainClass>de.jaschastarke.minecraft.limitedcreative.LimitedCreative</mainClass>
<softdepend>
<param>WorldGuard</param>
<param>WorldEdit</param>
<param>Multiverse-Core</param>
<param>Multiworld</param>
<param>xAuth</param>
<param>AuthMe</param>
<param>MultiInv</param>
<param>Multiverse-Inventories</param>
<param>Vault</param>
<param>CoreProtect</param>
</softdepend>
<custom>
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
</custom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>de.jaschastarke:plib</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>de.jaschastarke:plib</artifact>
<excludes>
<exclude>de/jaschastarke/maven/**</exclude>
<exclude>de/jaschastarke/bukkit/maven/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>de.jaschastarke</groupId>
<artifactId>plib</artifactId>
<versionRange>
[0.1-SNAPSHOT,)
</versionRange>
<goals>
<goal>pluginyaml</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<extensions>
<!-- Enabling the use of SCP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.1</version>
</extension>
</extensions>
</build>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.jaschastarke</groupId>
<artifactId>LimitedCreative</artifactId>
<name>LimitedCreative</name>
<version>2.3-SNAPSHOT</version>
<url>https://github.com/possi/LimitedCreative</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plib.version>1.4-SNAPSHOT</plib.version>
<bukkit.version>1.12.2-R0.1-SNAPSHOT</bukkit.version>
</properties>
<scm>
<connection>scm:git:git://github.com/possi/LimitedCreative.git</connection>
<developerConnection>scm:git:git@github.com:possi/LimitedCreative.git</developerConnection>
<url>https://github.com/possi/LimitedCreative/tree/plib</url>
</scm>
<distributionManagement>
<repository>
<id>de-jas-repo</id>
<url>scp://repo@ja-s.de/var/customers/webs/repo/mvn</url>
</repository>
</distributionManagement>
<ciManagement>
<system>jenkins</system>
<url>http://ci.ja-s.de:8080/</url>
</ciManagement>
<issueManagement>
<system>BukkitDev</system>
<url>http://dev.bukkit.org/server-mods/limited-creative/tickets/</url>
</issueManagement>
<repositories>
<!-- Possible public Maven Repository, containing LimitedCreative builds and other dependencies without own rep.
like AuthMe, etc.
Supports http only -->
<repository>
<id>de-jas-rep</id>
<url>http://repo.ja-s.de/mvn</url>
</repository>
<!-- Official (Craft-)Bukkit repository -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- Official WorldGuard and WorldEdit repository -->
<repository>
<id>sk89q-mvn2</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<!-- Official Multiverse repository -->
<repository>
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public</url>
</repository>
<!-- Official xAuth repository; it is no good! we keep our own dep-files of it - ->
<repository>
<id>luricos.de-repo</id>
<url>http://repo.luricos.de/bukkit-plugins/</url>
</repository><!- - -->
<!-- Official LogBlock repository -->
<repository>
<id>md5</id>
<url>http://repo.md-5.net/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>de-jas-rep</id>
<url>http://repo.ja-s.de/mvn</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>de.jaschastarke</groupId>
<artifactId>plib</artifactId>
<version>${plib.version}</version>
</dependency>
<dependency>
<!-- http://dl.bukkit.org/ -->
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
</dependency>
<dependency>
<!-- http://dl.bukkit.org/ -->
<groupId>org.bukkit.</groupId> <!-- Needed for WE integration -->
<artifactId>bukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
<groupId>uk.org.whoami</groupId>
<artifactId>authme</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/multiverse-core/ -->
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/multiworld-v-2-0/ -->
<groupId>multiworld</groupId>
<artifactId>multiworld</artifactId>
<version>4.7.2</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/xauth/ -->
<groupId>com.cypherx</groupId>
<artifactId>xauth</artifactId>
<version>2.0.26</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/coreprotect/ -->
<groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId>
<version>2.0.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.avaje/ebean -->
<dependency>
<groupId>org.avaje</groupId>
<artifactId>ebean</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<annotationProcessors>
<!-- Needed to fetch DocComments from Source -->
<annotationProcessor>de.jaschastarke.maven.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>de.jaschastarke</groupId>
<artifactId>plib</artifactId>
<version>${plib.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>pluginyaml</goal>
</goals>
<configuration>
<!-- plugin.yml -->
<mainClass>de.jaschastarke.minecraft.limitedcreative.LimitedCreative</mainClass>
<softdepend>
<param>WorldGuard</param>
<param>WorldEdit</param>
<param>Multiverse-Core</param>
<param>Multiworld</param>
<param>xAuth</param>
<param>AuthMe</param>
<param>MultiInv</param>
<param>Multiverse-Inventories</param>
<param>Vault</param>
<param>CoreProtect</param>
</softdepend>
<custom>
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
</custom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>de.jaschastarke:plib</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>de.jaschastarke:plib</artifact>
<excludes>
<exclude>de/jaschastarke/maven/**</exclude>
<exclude>de/jaschastarke/bukkit/maven/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>de.jaschastarke</groupId>
<artifactId>plib</artifactId>
<versionRange>
[0.1-SNAPSHOT,)
</versionRange>
<goals>
<goal>pluginyaml</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<extensions>
<!-- Enabling the use of SCP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.1</version>
</extension>
</extensions>
</build>
</project>

View file

@ -1,285 +1,288 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate;
import java.util.Date;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection;
import de.jaschastarke.LocaleString;
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
import de.jaschastarke.bukkit.lib.commands.BukkitCommand;
import de.jaschastarke.bukkit.lib.commands.CommandContext;
import de.jaschastarke.bukkit.lib.commands.CommandException;
import de.jaschastarke.bukkit.lib.commands.HelpCommand;
import de.jaschastarke.bukkit.lib.commands.IHelpDescribed;
import de.jaschastarke.bukkit.lib.commands.MissingPermissionCommandException;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
import de.jaschastarke.bukkit.lib.commands.parser.DefinedParameterParser;
import de.jaschastarke.bukkit.lib.database.DBHelper;
import de.jaschastarke.database.DatabaseConfigurationException;
import de.jaschastarke.database.db.Database;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginCommand;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/**
* LimitedCreative-BlockState-Command: modify blockstate database to prevent drops of selected blocks (requires WorldEdit)
* @usage /<command> - displays Regions-Command-Help
* @permission limitedcreative.blockstate.command
*/
@ArchiveDocComments
@PluginCommand
public class BlockStateCommand extends BukkitCommand implements IHelpDescribed {
private ModBlockStates mod;
private HelpCommand help;
public BlockStateCommand() {
this.help = this.getDefaultHelpCommand();
}
public BlockStateCommand(ModBlockStates mod) {
super(mod.getPlugin());
this.help = this.getDefaultHelpCommand();
this.mod = mod;
}
@Override
public String getName() {
return "lcbs";
}
@Override
public String[] getAliases() {
return new String[]{};
}
/**
* @internal has no effect, as not tested by any command handler
* @see IHelpDescribed
*/
@Override
public IAbstractPermission[] getRequiredPermissions() {
return new IAbstractPermission[]{BlockStatePermissions.COMMAND};
}
@Override
public CharSequence[] getUsages() {
return new String[]{"..."};
}
@Override
public CharSequence getDescription() {
return new LocaleString("command.blockstate");
}
@Override
public CharSequence getPackageName() {
return mod.getPlugin().getName() + " - " + mod.getName();
}
public boolean execute(final CommandContext context, final String[] args) throws MissingPermissionCommandException, CommandException {
if (mod.getModuleEntry().getState() != ModuleState.ENABLED)
throw new CommandException("Module " + mod.getName() + " is disabled");
return super.execute(context, args);
}
/**
* Deletes no longer used data from the BlockState-Database. Currently it only removes non-creative entries
* from the database, if you changed to "logSurvival"-config from true to false.
*/
@IsCommand("cleanup")
@Usages("")
public boolean cleanupDatabase(final CommandContext context, String... args) throws CommandException {
if (mod.getConfig().getLogSurvival()) {
context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup"));
} else {
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() {
@Override
public void run() {
int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL);
if (countDeleted < 0)
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.cleanup_error"));
else
context.responseFormatted(ChatFormattings.SUCCESS, L("command.blockstate.cleanup_success", countDeleted));
}
});
}
return true;
}
/**
* Modifies the BlockState-Database and sets all blocks in the selection to the provided gamemode. Set it
* to "creative" to disable drop of this block on destroying. Set it to "survival" to allow it.
* WorldEdit is required, because the selection Region is used.
* gamemode can be: survival / creative / adventure / s / c / a / 0 / 1 / 2
* @throws MissingPermissionCommandException
*/
@IsCommand("set")
@Usages("<gamemode>")
public boolean setGameMode(final CommandContext context, String... args) throws CommandException, MissingPermissionCommandException {
if (!mod.getPlugin().getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
help.execute(context, new String[]{"set"});
context.response(L("command.blockstate.requires_worldedit"));
return true;
}
if (!context.isPlayer()) {
context.response(L("cmdblock.blocked.not_console"));
return true;
}
if (args.length < 1) {// doesn't count parameters
return false;
}
if (mod.getConfig().getIgnoredWorlds().contains(context.getPlayer().getWorld().getName())) {
context.response(L("command.blockstate.world_ignored", context.getPlayer().getWorld().getName()));
return true;
}
String gm = args[0].toLowerCase();
final GameMode tgm;
if (gm.equals("0") || gm.equals("s") || gm.equals("survival"))
tgm = GameMode.SURVIVAL;
else if (gm.equals("1") || gm.equals("c") || gm.equals("creative"))
tgm = GameMode.CREATIVE;
else if (gm.equals("2") || gm.equals("a") || gm.equals("adventure"))
tgm = GameMode.ADVENTURE;
else {
return false;
}
WorldEditPlugin we = (WorldEditPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin("WorldEdit");
final Selection selection = we.getSelection(context.getPlayer());
if (selection == null) {
context.response(L("command.blockstate.worledit_selection_empty"));
return true;
}
final Location min = selection.getMinimumPoint();
final Location max = selection.getMaximumPoint();
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() {
@Override
public void run() {
if (mod.isDebug())
mod.getLog().debug("Scheduler: Asynchronous Task run");
DBTransaction update = mod.getModel().groupUpdate();
int count = 0;
World w = selection.getWorld();
Cuboid c = new Cuboid();
c.add(min);
c.add(max);
mod.getModel().cacheStates(c);
BlockState seed = new BlockState();
seed.setPlayer(context.getPlayer());
seed.setGameMode(tgm);
seed.setSource(Source.COMMAND);
seed.setDate(new Date());
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
Location loc = new Location(w, x, y, z);
if (w.getBlockAt(loc).getType() != Material.AIR && selection.contains(loc)) {
seed.setLocation(loc);
update.setState(new BlockState(seed));
count++;
}
}
}
}
update.finish();
context.response(L("command.blockstate.command_updated", count));
}
});
return true;
}
/**
* Imports BlockState Data from a given Database to the current active Database.
* A Server-Restart is needed after migration!
* Parameters:
* -u --update Don't delete existing records / only overwrite if newer
* --import=<type> Import from other Plugins. Supported Types:
* cc CreativeControl
*/
@IsCommand("migrate")
@Usages("-u --import=cc <dsn> [username] [password]")
public boolean migrateDatabase(final CommandContext context, String... args) throws CommandException, MissingPermissionCommandException {
DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"debug", "d", "update", "u", "confirm"});
if (params.getArgumentCount() < 1) {// doesn't count parameters
return false;
}
if (Bukkit.getServer().getOnlinePlayers().size() > (context.isPlayer() ? 1 : 0)) {
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_useronline_error"));
return true;
}
Database source;
Database target;
try {
if (params.getArgumentCount() < 2)
source = DBHelper.createConnection(params.getArgument(0));
else if (params.getArgumentCount() < 3)
source = DBHelper.createConnection(params.getArgument(0), params.getArgument(1), null);
else
source = DBHelper.createConnection(params.getArgument(0), params.getArgument(1), params.getArgument(2));
target = mod.getPlugin().getDatabaseConnection();
} catch (DatabaseConfigurationException e) {
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_connect_error", e.getMessage()));
return true;
}
DatabaseMigrationThread thread;
if (params.getParameter("import") != null) {
if (params.getParameter("import").equals("cc")) {
thread = new CreativeControlImportThread(mod, context, source, target);
} else {
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_importtype_error", params.getParameter("import")));
return false;
}
} else {
thread = new DatabaseMigrationThread(mod, context, source, target);
}
if (params.getFlags().contains("update") || params.getFlags().contains("u")) {
thread.setMode(DatabaseMigrationThread.Mode.UPDATE);
}
if (params.getFlags().contains("debug") || params.getFlags().contains("d")) {
thread.setDebug(true);
}
if (!params.getFlags().contains("confirm")) {
context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.migrate_confirm", "--confirm"));
return true;
}
mod.getModuleEntry().disable();
thread.start();
String sourceType = source.getType().toString();
if (params.getParameter("import") != null) {
if (params.getParameter("import").equals("cc")) {
sourceType = "CreativeControl-" + sourceType;
}
}
context.response(L("command.blockstate.migrate_started", sourceType, target.getType()));
return true;
}
private String L(String msg, Object... args) {
return mod.getPlugin().getLocale().trans(msg, args);
}
}
package de.jaschastarke.minecraft.limitedcreative.blockstate;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import de.jaschastarke.LocaleString;
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
import de.jaschastarke.bukkit.lib.commands.*;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
import de.jaschastarke.bukkit.lib.commands.parser.DefinedParameterParser;
import de.jaschastarke.bukkit.lib.database.DBHelper;
import de.jaschastarke.database.DatabaseConfigurationException;
import de.jaschastarke.database.db.Database;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginCommand;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import java.util.Date;
/**
* LimitedCreative-BlockState-Command: modify blockstate database to prevent drops of selected blocks (requires WorldEdit)
* @usage /<command> - displays Regions-Command-Help
* @permission limitedcreative.blockstate.command
*/
@ArchiveDocComments
@PluginCommand
public class BlockStateCommand extends BukkitCommand implements IHelpDescribed {
private ModBlockStates mod;
private HelpCommand help;
public BlockStateCommand() {
this.help = this.getDefaultHelpCommand();
}
public BlockStateCommand(ModBlockStates mod) {
super(mod.getPlugin());
this.help = this.getDefaultHelpCommand();
this.mod = mod;
}
@Override
public String getName() {
return "lcbs";
}
@Override
public String[] getAliases() {
return new String[]{};
}
/**
* @internal has no effect, as not tested by any command handler
* @see IHelpDescribed
*/
@Override
public IAbstractPermission[] getRequiredPermissions() {
return new IAbstractPermission[]{BlockStatePermissions.COMMAND};
}
@Override
public CharSequence[] getUsages() {
return new String[]{"..."};
}
@Override
public CharSequence getDescription() {
return new LocaleString("command.blockstate");
}
@Override
public CharSequence getPackageName() {
return mod.getPlugin().getName() + " - " + mod.getName();
}
public boolean execute(final CommandContext context, final String[] args) throws MissingPermissionCommandException, CommandException {
if (mod.getModuleEntry().getState() != ModuleState.ENABLED)
throw new CommandException("Module " + mod.getName() + " is disabled");
return super.execute(context, args);
}
/**
* Deletes no longer used data from the BlockState-Database. Currently it only removes non-creative entries
* from the database, if you changed to "logSurvival"-config from true to false.
*/
@IsCommand("cleanup")
@Usages("")
public boolean cleanupDatabase(final CommandContext context, String... args) throws CommandException {
if (mod.getConfig().getLogSurvival()) {
context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup"));
} else {
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() {
@Override
public void run() {
int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL);
if (countDeleted < 0)
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.cleanup_error"));
else
context.responseFormatted(ChatFormattings.SUCCESS, L("command.blockstate.cleanup_success", countDeleted));
}
});
}
return true;
}
/**
* Modifies the BlockState-Database and sets all blocks in the selection to the provided gamemode. Set it
* to "creative" to disable drop of this block on destroying. Set it to "survival" to allow it.
* WorldEdit is required, because the selection Region is used.
* gamemode can be: survival / creative / adventure / s / c / a / 0 / 1 / 2
* @throws MissingPermissionCommandException
*/
@IsCommand("set")
@Usages("<gamemode>")
public boolean setGameMode(final CommandContext context, String... args) throws CommandException, MissingPermissionCommandException {
if (!mod.getPlugin().getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
help.execute(context, new String[]{"set"});
context.response(L("command.blockstate.requires_worldedit"));
return true;
}
if (!context.isPlayer()) {
context.response(L("cmdblock.blocked.not_console"));
return true;
}
if (args.length < 1) {// doesn't count parameters
return false;
}
if (mod.getConfig().getIgnoredWorlds().contains(context.getPlayer().getWorld().getName())) {
context.response(L("command.blockstate.world_ignored", context.getPlayer().getWorld().getName()));
return true;
}
String gm = args[0].toLowerCase();
final GameMode tgm;
if (gm.equals("0") || gm.equals("s") || gm.equals("survival"))
tgm = GameMode.SURVIVAL;
else if (gm.equals("1") || gm.equals("c") || gm.equals("creative"))
tgm = GameMode.CREATIVE;
else if (gm.equals("2") || gm.equals("a") || gm.equals("adventure"))
tgm = GameMode.ADVENTURE;
else {
return false;
}
BukkitPlayer bp = BukkitAdapter.adapt(context.getPlayer());
Region region = null;
try {
region = WorldEdit.getInstance().getSessionManager().get(bp).getSelection(bp.getWorld());
} catch (Exception ignored) { //IncompleteRegionException
}
final Region selection = region;
if (selection == null) {
context.response(L("command.blockstate.worledit_selection_empty"));
return true;
}
final BlockVector3 min = selection.getMinimumPoint();
final BlockVector3 max = selection.getMaximumPoint();
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() {
@Override
public void run() {
if (mod.isDebug())
mod.getLog().debug("Scheduler: Asynchronous Task run");
DBTransaction update = mod.getModel().groupUpdate();
int count = 0;
World w = selection.getWorld();
assert w != null;
org.bukkit.World bw = BukkitAdapter.adapt(w);
Cuboid c = new Cuboid();
c.add(new Location(bw, min.getBlockX(), min.getBlockY(), min.getBlockZ()));
c.add(new Location(bw, max.getBlockX(), max.getBlockY(), max.getBlockZ()));
mod.getModel().cacheStates(c);
BlockState seed = new BlockState();
seed.setPlayer(context.getPlayer());
seed.setGameMode(tgm);
seed.setSource(Source.COMMAND);
seed.setDate(new Date());
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
BlockVector3 loc = BlockVector3.at(x, y, z);
if (!w.getBlock(loc).getBlockType().getMaterial().isAir() && selection.contains(loc)) {
seed.setLocation(new Location(bw, x, y, z));
update.setState(new BlockState(seed));
count++;
}
}
}
}
update.finish();
context.response(L("command.blockstate.command_updated", count));
}
});
return true;
}
/**
* Imports BlockState Data from a given Database to the current active Database.
* A Server-Restart is needed after migration!
* Parameters:
* -u --update Don't delete existing records / only overwrite if newer
* --import=<type> Import from other Plugins. Supported Types:
* cc CreativeControl
*/
@IsCommand("migrate")
@Usages("-u --import=cc <dsn> [username] [password]")
public boolean migrateDatabase(final CommandContext context, String... args) throws CommandException, MissingPermissionCommandException {
DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"debug", "d", "update", "u", "confirm"});
if (params.getArgumentCount() < 1) {// doesn't count parameters
return false;
}
if (Bukkit.getServer().getOnlinePlayers().size() > (context.isPlayer() ? 1 : 0)) {
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_useronline_error"));
return true;
}
Database source;
Database target;
try {
if (params.getArgumentCount() < 2)
source = DBHelper.createConnection(params.getArgument(0));
else if (params.getArgumentCount() < 3)
source = DBHelper.createConnection(params.getArgument(0), params.getArgument(1), null);
else
source = DBHelper.createConnection(params.getArgument(0), params.getArgument(1), params.getArgument(2));
target = mod.getPlugin().getDatabaseConnection();
} catch (DatabaseConfigurationException e) {
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_connect_error", e.getMessage()));
return true;
}
DatabaseMigrationThread thread;
if (params.getParameter("import") != null) {
if (params.getParameter("import").equals("cc")) {
thread = new CreativeControlImportThread(mod, context, source, target);
} else {
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_importtype_error", params.getParameter("import")));
return false;
}
} else {
thread = new DatabaseMigrationThread(mod, context, source, target);
}
if (params.getFlags().contains("update") || params.getFlags().contains("u")) {
thread.setMode(DatabaseMigrationThread.Mode.UPDATE);
}
if (params.getFlags().contains("debug") || params.getFlags().contains("d")) {
thread.setDebug(true);
}
if (!params.getFlags().contains("confirm")) {
context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.migrate_confirm", "--confirm"));
return true;
}
mod.getModuleEntry().disable();
thread.start();
String sourceType = source.getType().toString();
if (params.getParameter("import") != null) {
if (params.getParameter("import").equals("cc")) {
sourceType = "CreativeControl-" + sourceType;
}
}
context.response(L("command.blockstate.migrate_started", sourceType, target.getType()));
return true;
}
private String L(String msg, Object... args) {
return mod.getPlugin().getLocale().trans(msg, args);
}
}

View file

@ -1,21 +1,20 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import java.util.Date;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
import java.util.Date;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
public class EditSessionExtent extends AbstractLoggingExtent {
public class EditSessionExtent extends AbstractDelegateExtent {
private ModBlockStates mod;
private Player player = null;
private World world;
@ -30,14 +29,15 @@ public class EditSessionExtent extends AbstractLoggingExtent {
/**
* Called when a block is being changed.
*
* @param position the position
* @param pt the position
* @param newBlock the new block to replace the old one
*/
protected void onBlockChange(Vector pt, BaseBlock newBlock) {
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 pt, T newBlock) throws WorldEditException {
if (mod.isDebug())
mod.getLog().debug("WorldEdit-Integration: BlockChange: "+pt.toString()+" BB: " + newBlock.toString());
Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (newBlock.getType() == 0) {
if (newBlock.getBlockType().getMaterial().isAir()) {
mod.getModel().removeState(loc.getBlock());
} else {
BlockState s = mod.getModel().getState(loc.getBlock());
@ -54,5 +54,6 @@ public class EditSessionExtent extends AbstractLoggingExtent {
mod.getModel().setState(s);
}
return true;
}
}

View file

@ -1,48 +1,47 @@
package de.jaschastarke.minecraft.limitedcreative.regions;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
/**
* Well, that was an interesting idea, but it doesn't work.
*/
public class GameModeFlag extends Flag<GameMode> {
public GameModeFlag(String name, RegionGroup defaultGroup) {
super(name, defaultGroup);
}
@Override
public GameMode parseInput(WorldGuardPlugin plugin, CommandSender sender, String input) throws InvalidFlagFormat {
input = input.trim();
if (input.equalsIgnoreCase("creative")) {
return GameMode.CREATIVE;
} else if (input.equalsIgnoreCase("survival")) {
return GameMode.SURVIVAL;
} else if (input.equalsIgnoreCase("adventure")) {
return GameMode.ADVENTURE;
} else if (input.equalsIgnoreCase("none")) {
return null;
} else {
throw new InvalidFlagFormat("Expected survival/creative/none but got '" + input + "'");
}
}
@Override
public GameMode unmarshal(Object o) {
GameMode gm = null;
if (o != null) {
gm = GameMode.valueOf((String) o);
}
return gm;
}
@Override
public Object marshal(GameMode o) {
return o == null ? null : o.name();
}
}
package de.jaschastarke.minecraft.limitedcreative.regions;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import org.bukkit.GameMode;
/**
* Well, that was an interesting idea, but it doesn't work.
*/
public class GameModeFlag extends Flag<GameMode> {
public GameModeFlag(String name, RegionGroup defaultGroup) {
super(name, defaultGroup);
}
@Override
public GameMode parseInput(FlagContext context) throws InvalidFlagFormat {
String input = context.getUserInput();
input = input.trim();
if (input.equalsIgnoreCase("creative")) {
return GameMode.CREATIVE;
} else if (input.equalsIgnoreCase("survival")) {
return GameMode.SURVIVAL;
} else if (input.equalsIgnoreCase("adventure")) {
return GameMode.ADVENTURE;
} else if (input.equalsIgnoreCase("none")) {
return null;
} else {
throw new InvalidFlagFormat("Expected survival/creative/none but got '" + input + "'");
}
}
@Override
public GameMode unmarshal(Object o) {
GameMode gm = null;
if (o != null) {
gm = GameMode.valueOf((String) o);
}
return gm;
}
@Override
public Object marshal(GameMode o) {
return o == null ? null : o.name();
}
}

View file

@ -1,282 +1,280 @@
package de.jaschastarke.minecraft.limitedcreative.regions;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import de.jaschastarke.LocaleString;
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
import de.jaschastarke.bukkit.lib.commands.BukkitCommand;
import de.jaschastarke.bukkit.lib.commands.CommandContext;
import de.jaschastarke.bukkit.lib.commands.CommandException;
import de.jaschastarke.bukkit.lib.commands.HelpCommand;
import de.jaschastarke.bukkit.lib.commands.ICommand;
import de.jaschastarke.bukkit.lib.commands.IHelpDescribed;
import de.jaschastarke.bukkit.lib.commands.MethodCommand;
import de.jaschastarke.bukkit.lib.commands.MissingPermissionCommandException;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
import de.jaschastarke.bukkit.lib.commands.parser.DefinedParameterParser;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion.Completer;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion.Context;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginCommand;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagList;
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagValue;
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.Region;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/**
* LimitedCreative-Region-Command: configure creative regions
* @usage /<command> - displays Regions-Command-Help
* @permission limitedcreative.region
*/
@ArchiveDocComments
@PluginCommand
public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
private final static String GLOBAL_REGION = "__global__";
private ModRegions mod;
private HelpCommand help;
private WorldGuardPlugin wg;
public RegionsCommand() {
this.help = this.getDefaultHelpCommand();
}
public RegionsCommand(ModRegions mod) {
super(mod.getPlugin());
this.help = this.getDefaultHelpCommand();
this.mod = mod;
this.wg = (WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME);
fullfillTabCompletion();
}
@Override
public String getName() {
return "lcr";
}
@Override
public String[] getAliases() {
return new String[]{"/region"};
}
public boolean execute(final CommandContext context, final String[] args) throws MissingPermissionCommandException, CommandException {
if (mod.getModuleEntry().getState() != ModuleState.ENABLED)
throw new CommandException("Module " + mod.getName() + " is disabled");
return super.execute(context, args);
}
/**
* @internal has no effect, as not tested by any command handler
* @see IHelpDescribed
*/
@Override
public IAbstractPermission[] getRequiredPermissions() {
return new IAbstractPermission[]{RegionPermissions.REGION};
}
@Override
public String[] getUsages() {
return null;
}
@Override
public CharSequence getDescription() {
return new LocaleString("command.regions");
}
@Override
public String getPackageName() {
return mod.getPlugin().getName() + " - " + mod.getName();
}
/*@Override
public IPermission getPermission(String subPerm) {
if (subPerm.equals("region"))
return RegionPermissions.REGION;
else
return RegionPermissions.REGION.getPermission(subPerm);
}*/
protected void fullfillTabCompletion() {
for (ICommand cmd : handler.getCommands()) {
if (cmd instanceof MethodCommand) {
if (cmd.getName().equals("info")) {
((MethodCommand) cmd).getCompleter().add(TabCompletion.forUsageLine("[region]"));
}
for (TabCompletion c : ((MethodCommand) cmd).getCompleter()) {
c.setCompleter("region", new RegionCompleter());
}
}
}
}
private class RegionCompleter implements Completer {
@Override
public List<String> get(Context context, String arg) {
int idx = -1;
String[] args = context.getHelper().getArguments();
for (int i = 0; i < args.length; i++) {
if (args[i].equals("world")) {
idx = i;
break;
}
}
World w = context.getCommandContext().isPlayer() ? context.getCommandContext().getPlayer().getWorld() : null;
if (idx > -1 && context.getArgument(idx) != null)
w = Bukkit.getWorld(context.getArgument(idx));
if (w != null) {
RegionManager mgr = getWorldGuard().getRegionManager(w);
if (mgr != null) {
List<String> hints = new ArrayList<String>();
for (String rId : mgr.getRegions().keySet()) {
if (rId.toLowerCase().startsWith(arg.toLowerCase()))
hints.add(rId);
}
return hints;
}
}
return null;
}
}
/**
* Sets the Flag of a region to a new value. If no value given, the flag is removed.
* -g sets the affected group of the flag, instead the flag (equivalent to using flag-group as flag-name)
* -w world uses a world by name instead the world your in (required from console)
*/
@IsCommand("flag")
//@NeedsPermission("region") // not needed as the whole command requires permissions
@Usages("<region> -g <flag> -w world [value]")
public boolean setFlag(CommandContext context, String... args) throws CommandException, MissingPermissionCommandException {
DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"g"}, 2);
if (params.getArgumentCount() < 2) {// doesn't count parameters
help.execute(context, new String[]{"flag"});
context.response(L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender()));
return true;
}
World w = context.isPlayer() ? context.getPlayer().getWorld() : null;
if (params.getParameter("-w") != null)
w = mod.getPlugin().getServer().getWorld(params.getParameter("-w"));
if (w == null)
throw new CommandException(L("command.worldguard.world_not_found"));
RegionManager mgr = getWorldGuard().getRegionManager(w);
ProtectedRegion region = mgr.getRegion(params.getArgument(0));
if (region == null && params.getArgument(0).equalsIgnoreCase("__global__")) {
region = new GlobalProtectedRegion(params.getArgument(0));
mgr.addRegion(region);
}
if (region == null)
throw new CommandException(L("command.worldguard.region_not_found"));
Region reg = mod.getRegionManager().world(w).region(region);
Flag<?> flag = FlagList.getFlag(params.getArgument(1));
if (flag == null) {
String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "\n"
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
throw new CommandException(msg);
} else if (params.getFlags().contains("g")) {
flag = flag.getRegionGroupFlag();
if (flag == null) {
String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "-group\n"
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
throw new CommandException(msg);
}
}
String value = params.getValue();
try {
if (value != null && value.trim().length() > 0) {
reg.setFlag(flag, flag.parseInput(getWorldGuard(), context.getSender(), value));
} else {
reg.setFlag(flag, null);
}
} catch (InvalidFlagFormat e) {
context.response(context.getFormatter().formatString(ChatFormattings.ERROR, e.getLocalizedMessage()));
return true;
}
context.response(L("command.worldguard.flag_set", flag.getName()));
return true;
}
@IsCommand("info")
//@NeedsPermission("region")
@Usages("[world] [region]")
public boolean getInfo(CommandContext context, String... args) throws CommandException {
DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"s"}, 1);
if (context.isPlayer()) {
/*
* WorldEdits intercepting Servers privates commandMap via Reflections realy sucks!
* Just because they are to lazy to add all the lines commands to plugin.yml
*/
String orgCmd = ("region info " + StringUtils.join(args)).trim();
mod.getPlugin().getServer().dispatchCommand(context.getSender(), orgCmd);
}
World w = context.isPlayer() ? context.getPlayer().getWorld() : null;
if (params.getArgumentCount() > 1)
w = mod.getPlugin().getServer().getWorld(params.getArgument(0));
if (w == null)
throw new CommandException(L("command.worldguard.world_not_found"));
ProtectedRegion region = null;
if (params.getArgumentCount() == 0 && context.isPlayer()) {
RegionManager mgr = getWorldGuard().getRegionManager(context.getPlayer().getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation());
if (set.size() > 0) {
region = set.iterator().next();
} else {
region = getWorldGuard().getRegionManager(w).getRegion(GLOBAL_REGION);
}
} else {
int rpc = params.getArgumentCount() > 1 ? 1 : 0;
RegionManager mgr = getWorldGuard().getRegionManager(w);
region = mgr.getRegion(params.getArgument(rpc));
if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) {
region = new GlobalProtectedRegion(params.getArgument(rpc));
mgr.addRegion(region);
}
}
if (region == null)
throw new CommandException(L("command.worldguard.region_not_found"));
Region reg = mod.getRegionManager().world(w).region(region);
StringBuilder list = new StringBuilder();
for (FlagValue data : reg.getFlags()) {
if (list.length() > 0)
list.append(", ");
list.append(data.getFlag().getName());
list.append(": ");
list.append(data.getValue().toString());
}
context.response(ChatColor.GREEN + L("command.worldguard.additional_flags") + list.toString());
return true;
}
private String L(String msg, Object... args) {
return mod.getPlugin().getLocale().trans(msg, args);
}
private WorldGuardPlugin getWorldGuard() {
return wg;
}
}
package de.jaschastarke.minecraft.limitedcreative.regions;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import de.jaschastarke.LocaleString;
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
import de.jaschastarke.bukkit.lib.commands.*;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
import de.jaschastarke.bukkit.lib.commands.parser.DefinedParameterParser;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion.Completer;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion.Context;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginCommand;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagList;
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagValue;
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.Region;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import java.util.ArrayList;
import java.util.List;
/**
* LimitedCreative-Region-Command: configure creative regions
* @usage /<command> - displays Regions-Command-Help
* @permission limitedcreative.region
*/
@ArchiveDocComments
@PluginCommand
public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
private final static String GLOBAL_REGION = "__global__";
private ModRegions mod;
private HelpCommand help;
private WorldGuardPlugin wg;
public RegionsCommand() {
this.help = this.getDefaultHelpCommand();
}
public RegionsCommand(ModRegions mod) {
super(mod.getPlugin());
this.help = this.getDefaultHelpCommand();
this.mod = mod;
this.wg = (WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME);
fullfillTabCompletion();
}
@Override
public String getName() {
return "lcr";
}
@Override
public String[] getAliases() {
return new String[]{"/region"};
}
public boolean execute(final CommandContext context, final String[] args) throws MissingPermissionCommandException, CommandException {
if (mod.getModuleEntry().getState() != ModuleState.ENABLED)
throw new CommandException("Module " + mod.getName() + " is disabled");
return super.execute(context, args);
}
/**
* @internal has no effect, as not tested by any command handler
* @see IHelpDescribed
*/
@Override
public IAbstractPermission[] getRequiredPermissions() {
return new IAbstractPermission[]{RegionPermissions.REGION};
}
@Override
public String[] getUsages() {
return null;
}
@Override
public CharSequence getDescription() {
return new LocaleString("command.regions");
}
@Override
public String getPackageName() {
return mod.getPlugin().getName() + " - " + mod.getName();
}
/*@Override
public IPermission getPermission(String subPerm) {
if (subPerm.equals("region"))
return RegionPermissions.REGION;
else
return RegionPermissions.REGION.getPermission(subPerm);
}*/
protected void fullfillTabCompletion() {
for (ICommand cmd : handler.getCommands()) {
if (cmd instanceof MethodCommand) {
if (cmd.getName().equals("info")) {
((MethodCommand) cmd).getCompleter().add(TabCompletion.forUsageLine("[region]"));
}
for (TabCompletion c : ((MethodCommand) cmd).getCompleter()) {
c.setCompleter("region", new RegionCompleter());
}
}
}
}
private class RegionCompleter implements Completer {
@Override
public List<String> get(Context context, String arg) {
int idx = -1;
String[] args = context.getHelper().getArguments();
for (int i = 0; i < args.length; i++) {
if (args[i].equals("world")) {
idx = i;
break;
}
}
World w = context.getCommandContext().isPlayer() ? context.getCommandContext().getPlayer().getWorld() : null;
if (idx > -1 && context.getArgument(idx) != null)
w = Bukkit.getWorld(context.getArgument(idx));
if (w != null) {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionManager mgr = container.get(BukkitAdapter.adapt(w));
if (mgr != null) {
List<String> hints = new ArrayList<String>();
for (String rId : mgr.getRegions().keySet()) {
if (rId.toLowerCase().startsWith(arg.toLowerCase()))
hints.add(rId);
}
return hints;
}
}
return null;
}
}
/**
* Sets the Flag of a region to a new value. If no value given, the flag is removed.
* -g sets the affected group of the flag, instead the flag (equivalent to using flag-group as flag-name)
* -w world uses a world by name instead the world your in (required from console)
*/
@IsCommand("flag")
//@NeedsPermission("region") // not needed as the whole command requires permissions
@Usages("<region> -g <flag> -w world [value]")
public boolean setFlag(CommandContext context, String... args) throws CommandException, MissingPermissionCommandException {
DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"g"}, 2);
if (params.getArgumentCount() < 2) {// doesn't count parameters
help.execute(context, new String[]{"flag"});
context.response(L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender()));
return true;
}
World w = context.isPlayer() ? context.getPlayer().getWorld() : null;
if (params.getParameter("-w") != null)
w = mod.getPlugin().getServer().getWorld(params.getParameter("-w"));
if (w == null)
throw new CommandException(L("command.worldguard.world_not_found"));
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionManager mgr = container.get(BukkitAdapter.adapt(w));
ProtectedRegion region = mgr.getRegion(params.getArgument(0));
if (region == null && params.getArgument(0).equalsIgnoreCase("__global__")) {
region = new GlobalProtectedRegion(params.getArgument(0));
mgr.addRegion(region);
}
if (region == null)
throw new CommandException(L("command.worldguard.region_not_found"));
Region reg = mod.getRegionManager().world(w).region(region);
Flag<?> flag = FlagList.getFlag(params.getArgument(1));
if (flag == null) {
String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "\n"
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
throw new CommandException(msg);
} else if (params.getFlags().contains("g")) {
flag = flag.getRegionGroupFlag();
if (flag == null) {
String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "-group\n"
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
throw new CommandException(msg);
}
}
String value = params.getValue();
try {
if (value != null && value.trim().length() > 0) {
reg.setFlag(flag, flag.parseInput(FlagContext.create().setInput(value).build()));
} else {
reg.setFlag(flag, null);
}
} catch (InvalidFlagFormat e) {
context.response(context.getFormatter().formatString(ChatFormattings.ERROR, e.getLocalizedMessage()));
return true;
}
context.response(L("command.worldguard.flag_set", flag.getName()));
return true;
}
@IsCommand("info")
//@NeedsPermission("region")
@Usages("[world] [region]")
public boolean getInfo(CommandContext context, String... args) throws CommandException {
DefinedParameterParser params = new DefinedParameterParser(args, new String[]{"s"}, 1);
if (context.isPlayer()) {
/*
* WorldEdits intercepting Servers privates commandMap via Reflections realy sucks!
* Just because they are to lazy to add all the lines commands to plugin.yml
*/
String orgCmd = ("region info " + StringUtils.join(args)).trim();
mod.getPlugin().getServer().dispatchCommand(context.getSender(), orgCmd);
}
World w = context.isPlayer() ? context.getPlayer().getWorld() : null;
if (params.getArgumentCount() > 1)
w = mod.getPlugin().getServer().getWorld(params.getArgument(0));
if (w == null)
throw new CommandException(L("command.worldguard.world_not_found"));
ProtectedRegion region = null;
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
if (params.getArgumentCount() == 0 && context.isPlayer()) {
RegionManager mgr = container.get(BukkitAdapter.adapt(context.getPlayer().getWorld()));
ApplicableRegionSet set = mgr.getApplicableRegions(BukkitAdapter.asBlockVector(context.getPlayer().getLocation()));
if (set.size() > 0) {
region = set.iterator().next();
} else {
region = container.get(BukkitAdapter.adapt(w)).getRegion(GLOBAL_REGION);
}
} else {
int rpc = params.getArgumentCount() > 1 ? 1 : 0;
RegionManager mgr = container.get(BukkitAdapter.adapt(w));
region = mgr.getRegion(params.getArgument(rpc));
if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) {
region = new GlobalProtectedRegion(params.getArgument(rpc));
mgr.addRegion(region);
}
}
if (region == null)
throw new CommandException(L("command.worldguard.region_not_found"));
Region reg = mod.getRegionManager().world(w).region(region);
StringBuilder list = new StringBuilder();
for (FlagValue data : reg.getFlags()) {
if (list.length() > 0)
list.append(", ");
list.append(data.getFlag().getName());
list.append(": ");
list.append(data.getValue().toString());
}
context.response(ChatColor.GREEN + L("command.worldguard.additional_flags") + list.toString());
return true;
}
private String L(String msg, Object... args) {
return mod.getPlugin().getLocale().trans(msg, args);
}
private WorldGuardPlugin getWorldGuard() {
return wg;
}
}

View file

@ -1,192 +1,189 @@
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.limitedcreative.regions.worldguard;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
import de.jaschastarke.utils.StringUtil;
public class CustomRegionManager {
protected YamlConfiguration c;
protected File file;
private Map<World, CWorld> worlds = new HashMap<World, CWorld>();
private ModRegions mod;
public CustomRegionManager(File file, ModRegions mod) {
this.file = file;
this.mod = mod;
c = YamlConfiguration.loadConfiguration(file);
}
public CWorld world(World w) {
if (worlds.containsKey(w)) {
return worlds.get(w);
} else {
CWorld r = new CWorld(w);
worlds.put(w, r);
return r;
}
}
public class CWorld {
private World world;
private ConfigurationSection wc = null;
public CWorld(World w) {
world = w;
}
public CustomRegionManager getManager() {
return CustomRegionManager.this;
}
private Map<ProtectedRegion, Region> regions = new HashMap<ProtectedRegion, Region>();
public Region region(ProtectedRegion pr) {
if (regions.containsKey(pr)) {
return regions.get(pr);
} else {
Region r = new Region(this, pr);
regions.put(pr, r);
return r;
}
}
public World getWorld() {
return world;
}
public ProtectedRegion getGlobalRegion() {
return getWGManager(world).getRegion("__global__");
}
@SuppressWarnings("unchecked")
public <V> void storeFlag(Region region, Flag<V> flag, Object value) {
if (wc == null) {
if (c.contains(world.getName().toLowerCase()))
wc = c.getConfigurationSection(world.getName().toLowerCase());
else
wc = c.createSection(world.getName().toLowerCase());
}
ConfigurationSection rs;
if (wc.contains(region.getProtectedRegion().getId()))
rs = wc.getConfigurationSection(region.getProtectedRegion().getId());
else
rs = wc.createSection(region.getProtectedRegion().getId());
ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags");
if (value == null) {
fs.set(flag.getName(), null);
} else {
fs.set(flag.getName(), flag.marshal((V) value));
}
try {
c.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public List<FlagValue> getFlags(Region region) {
List<FlagValue> list = new ArrayList<FlagValue>();
if (c.contains(world.getName().toLowerCase())) {
ConfigurationSection wc = c.getConfigurationSection(world.getName().toLowerCase());
if (wc.contains(region.getProtectedRegion().getId())) {
ConfigurationSection rs = wc.getConfigurationSection(region.getProtectedRegion().getId());
if (rs.contains("flags")) {
ConfigurationSection fs = rs.getConfigurationSection("flags");
for (Map.Entry<String, Object> data : fs.getValues(false).entrySet()) {
Flag<?> flag = null;
if (data.getKey().endsWith("-group")) {
flag = FlagList.getFlag(data.getKey().substring(0, data.getKey().length() - 6));
if (flag != null)
flag = flag.getRegionGroupFlag();
} else {
flag = FlagList.getFlag(data.getKey());
}
if (flag != null) { // the flag doesn't exists anymore. just ignore it without error
Object value = flag.unmarshal(data.getValue());
list.add(new FlagValue(flag, value));
} else {
if (mod.isDebug())
mod.getLog().debug("Couldn't load unknown Flag: "+data.getKey());
}
}
}
}
}
return list;
}
public WorldGuardPlugin getWorldGuard() {
return CustomRegionManager.this.getWorldGuard();
}
}
private WorldGuardPlugin getWorldGuard() {
return ((WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME));
}
public RegionManager getWGManager(World world) {
return getWorldGuard().getRegionManager(world);
}
public String getRegionsHash(Location loc) {
StringBuilder hash = new StringBuilder(loc.getWorld().getName());
List<String> idlist = getWGManager(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc));
if (idlist.size() > 0) {
hash.append("#");
String[] ids = idlist.toArray(new String[idlist.size()]);
if (ids.length > 1) {
Arrays.sort(ids);
}
hash.append(StringUtil.join(ids, ","));
}
return hash.toString();
}
public ApplicableRegions getRegionSet(Location loc) {
return new ApplicableRegions(getWGManager(loc.getWorld()).getApplicableRegions(loc), this.world(loc.getWorld()));
}
public ApplicableRegions getRegionSet(Block block) {
return getRegionSet(block.getLocation());
}
public boolean isDiffrentRegion(Player player, Location loc) {
return !getRegionsHash(loc).equals(mod.getPlayerData(player).getHash());
}
}
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.limitedcreative.regions.worldguard;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
import de.jaschastarke.utils.StringUtil;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class CustomRegionManager {
protected YamlConfiguration c;
protected File file;
private Map<World, CWorld> worlds = new HashMap<World, CWorld>();
private ModRegions mod;
public CustomRegionManager(File file, ModRegions mod) {
this.file = file;
this.mod = mod;
c = YamlConfiguration.loadConfiguration(file);
}
public CWorld world(World w) {
if (worlds.containsKey(w)) {
return worlds.get(w);
} else {
CWorld r = new CWorld(w);
worlds.put(w, r);
return r;
}
}
public class CWorld {
private World world;
private ConfigurationSection wc = null;
public CWorld(World w) {
world = w;
}
public CustomRegionManager getManager() {
return CustomRegionManager.this;
}
private Map<ProtectedRegion, Region> regions = new HashMap<ProtectedRegion, Region>();
public Region region(ProtectedRegion pr) {
if (regions.containsKey(pr)) {
return regions.get(pr);
} else {
Region r = new Region(this, pr);
regions.put(pr, r);
return r;
}
}
public World getWorld() {
return world;
}
public ProtectedRegion getGlobalRegion() {
return getWGManager(world).getRegion("__global__");
}
@SuppressWarnings("unchecked")
public <V> void storeFlag(Region region, Flag<V> flag, Object value) {
if (wc == null) {
if (c.contains(world.getName().toLowerCase()))
wc = c.getConfigurationSection(world.getName().toLowerCase());
else
wc = c.createSection(world.getName().toLowerCase());
}
ConfigurationSection rs;
if (wc.contains(region.getProtectedRegion().getId()))
rs = wc.getConfigurationSection(region.getProtectedRegion().getId());
else
rs = wc.createSection(region.getProtectedRegion().getId());
ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags");
if (value == null) {
fs.set(flag.getName(), null);
} else {
fs.set(flag.getName(), flag.marshal((V) value));
}
try {
c.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public List<FlagValue> getFlags(Region region) {
List<FlagValue> list = new ArrayList<FlagValue>();
if (c.contains(world.getName().toLowerCase())) {
ConfigurationSection wc = c.getConfigurationSection(world.getName().toLowerCase());
if (wc.contains(region.getProtectedRegion().getId())) {
ConfigurationSection rs = wc.getConfigurationSection(region.getProtectedRegion().getId());
if (rs.contains("flags")) {
ConfigurationSection fs = rs.getConfigurationSection("flags");
for (Map.Entry<String, Object> data : fs.getValues(false).entrySet()) {
Flag<?> flag = null;
if (data.getKey().endsWith("-group")) {
flag = FlagList.getFlag(data.getKey().substring(0, data.getKey().length() - 6));
if (flag != null)
flag = flag.getRegionGroupFlag();
} else {
flag = FlagList.getFlag(data.getKey());
}
if (flag != null) { // the flag doesn't exists anymore. just ignore it without error
Object value = flag.unmarshal(data.getValue());
list.add(new FlagValue(flag, value));
} else {
if (mod.isDebug())
mod.getLog().debug("Couldn't load unknown Flag: "+data.getKey());
}
}
}
}
}
return list;
}
public WorldGuardPlugin getWorldGuard() {
return CustomRegionManager.this.getWorldGuard();
}
}
private WorldGuardPlugin getWorldGuard() {
return ((WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME));
}
public RegionManager getWGManager(World world) {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
return container.get(BukkitAdapter.adapt(world));
}
public String getRegionsHash(Location loc) {
StringBuilder hash = new StringBuilder(loc.getWorld().getName());
List<String> idlist = getWGManager(loc.getWorld()).getApplicableRegionsIDs(BukkitAdapter.asBlockVector(loc));
if (idlist.size() > 0) {
hash.append("#");
String[] ids = idlist.toArray(new String[idlist.size()]);
if (ids.length > 1) {
Arrays.sort(ids);
}
hash.append(StringUtil.join(ids, ","));
}
return hash.toString();
}
public ApplicableRegions getRegionSet(Location loc) {
return new ApplicableRegions(getWGManager(loc.getWorld()).getApplicableRegions(BukkitAdapter.asBlockVector(loc)), this.world(loc.getWorld()));
}
public ApplicableRegions getRegionSet(Block block) {
return getRegionSet(block.getLocation());
}
public boolean isDiffrentRegion(Player player, Location loc) {
return !getRegionsHash(loc).equals(mod.getPlayerData(player).getHash());
}
}