Compare commits
No commits in common. "master" and "plib" have entirely different histories.
94 changed files with 1235 additions and 5989 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,13 +1,11 @@
|
|||
/bin
|
||||
|
||||
# IDE stuff
|
||||
# Eclipse stuff
|
||||
/.project
|
||||
/.classpath
|
||||
/.settings
|
||||
/.buildpath
|
||||
/.checkstyle
|
||||
/.idea
|
||||
/LimitedCreative.iml
|
||||
|
||||
# maven
|
||||
/target
|
||||
|
|
27
README.md
27
README.md
|
@ -4,25 +4,22 @@ http://dev.bukkit.org/server-mods/limited-creative/
|
|||
Required dependencies
|
||||
---------------------
|
||||
|
||||
* [plib](https://github.com/possi/plib)
|
||||
* [Bukkit](https://github.com/Bukkit/Bukkit)
|
||||
|
||||
Dependencies for optional integrations
|
||||
--------------------------------------
|
||||
|
||||
* [WorldGuard](http://dev.bukkit.org/bukkit-plugins/worldguard/)
|
||||
* [WorldEdit](http://dev.bukkit.org/bukkit-plugins/worldedit/)
|
||||
* [xAuth](http://dev.bukkit.org/bukkit-plugins/xauth/)
|
||||
* [AuthMe](http://dev.bukkit.org/bukkit-plugins/authme-reloaded/)
|
||||
* [Multiverse-Core](http://dev.bukkit.org/bukkit-plugins/multiverse-core/)
|
||||
* [Vault](http://dev.bukkit.org/bukkit-plugins/vault/)
|
||||
* [Multiworld](http://dev.bukkit.org/bukkit-plugins/multiworld-v-2-0/)
|
||||
* [LogBlock](http://dev.bukkit.org/bukkit-plugins/logblock/)
|
||||
* [WorldGuard](https://github.com/sk89q/worldguard)
|
||||
* [WorldEdit](https://github.com/sk89q/worldedit)
|
||||
* [xAuth](http://dev.bukkit.org/server-mods/xauth/)
|
||||
* [AuthMe](http://dev.bukkit.org/server-mods/authme-reloaded/) ([GitSource](https://github.com/Multiplayer-italia/AuthMe-Reloaded))
|
||||
* [Multiverse-Core](http://dev.bukkit.org/server-mods/multiverse-core/)
|
||||
|
||||
Building
|
||||
--------
|
||||
Download and install xAuth and Multiworld into the local `repo` repository with a command like so:
|
||||
----
|
||||
|
||||
```bash
|
||||
mvn install:install-file -Dfile=xAuth-2.0.26.jar -Dpackaging=jar -DlocalRepositoryPath=repo -DgroupId=de.luricos.bukkit -DartifactId=xAuth -Dversion=2.0.26
|
||||
```
|
||||
To use Maven packaging
|
||||
----------------------
|
||||
|
||||
For required development snapshots, that aren't found by maven, you have to clone the project and do:
|
||||
$ mvn install
|
||||
in the directory of the project
|
||||
|
|
4
TODO.txt
Normal file
4
TODO.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
- cleanup localize-messages
|
||||
- region command descriptions
|
||||
- rework german localization
|
||||
- fix DocComment formatting for config and permissions
|
550
pom.xml
550
pom.xml
|
@ -1,303 +1,247 @@
|
|||
<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.5</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> - offline
|
||||
<id>de-jas-rep</id>
|
||||
<url>http://repo.ja-s.de/mvn</url>
|
||||
</repository> -->
|
||||
<!-- Local repository for plugins without a repo -->
|
||||
<repository>
|
||||
<id>localRepo</id>
|
||||
<url>file://${project.basedir}/repo</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/repository/bukkit-plugins/</url>
|
||||
</repository><!- - It points to dependencies that don't exist anymore -->
|
||||
<!-- Official LogBlock repository -->
|
||||
<repository>
|
||||
<id>md5</id>
|
||||
<url>http://repo.md-5.net/content/groups/public/</url>
|
||||
</repository>
|
||||
<!-- Official AuthMe Reloaded repository -->
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
<!-- Official CoreProtect repository -->
|
||||
<repository>
|
||||
<id>coreprotect-repo</id>
|
||||
<url>http://maven.playpro.com/</url>
|
||||
</repository>
|
||||
<!-- Official PermissionsEx repository -->
|
||||
<repository>
|
||||
<id>pex-repo</id>
|
||||
<url>https://repo.glaremasters.me/repository/permissionsex/</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>fr.xephi</groupId>
|
||||
<artifactId>authme</artifactId>
|
||||
<version>5.6.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</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>5.2.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- http://dev.bukkit.org/server-mods/xauth/ -->
|
||||
<groupId>de.luricos.bukkit</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>19.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.avaje/ebean -->
|
||||
<dependency>
|
||||
<groupId>org.avaje</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>2.7.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</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>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</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>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>de.jaschastarke:plib</include>
|
||||
<include>org.bstats</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>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>de.jaschastarke.minecraft.limitedcreative.bstats</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</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/>
|
||||
</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.0-SNAPSHOT</version>
|
||||
<url>https://github.com/possi/LimitedCreative</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<plib.version>1.0-SNAPSHOT</plib.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>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
<!-- Official WorldGuard and WorldEdit repository -->
|
||||
<repository>
|
||||
<id>sk89q-mvn2</id>
|
||||
<url>http://mvn2.sk89q.com/repo</url>
|
||||
</repository>
|
||||
<!-- Official Multiverse repository -->
|
||||
<repository>
|
||||
<id>onarandombox</id>
|
||||
<url>http://repo.onarandombox.com/content/groups/public</url>
|
||||
</repository>
|
||||
<!-- Official Vault repository -->
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</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><!- - -->
|
||||
</repositories>
|
||||
|
||||
<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>1.5.1-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- http://dev.bukkit.org/server-mods/worldedit/ -->
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>5.5.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>5.7.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
|
||||
<groupId>uk.org.whoami</groupId>
|
||||
<artifactId>authme</artifactId>
|
||||
<version>2.7.12</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/server-mods/xauth/ -->
|
||||
<groupId>com.cypherx</groupId>
|
||||
<artifactId>xauth</artifactId>
|
||||
<version>2.0.26</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>MultiInv</param>
|
||||
<param>xAuth</param>
|
||||
<param>AuthMe</param>
|
||||
<param>MultiInv</param>
|
||||
<param>Multiverse-Inventories</param>
|
||||
<param>Vault</param>
|
||||
</softdepend>
|
||||
<custom>
|
||||
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
|
||||
</custom>
|
||||
<registeredPermissions>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.Permissions:CONTAINER</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.SwitchGameModePermissions:ALL</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.limits.NoLimitPermissions:PARENT</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.cmdblocker.CmdBlockPermissions:CONTAINER</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.regions.RegionPermissions:REGION</param>
|
||||
</registeredPermissions>
|
||||
<registeredCommands>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.MainCommand</param>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.regions.RegionsCommand</param>
|
||||
</registeredCommands>
|
||||
</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>1.0</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
</build>
|
||||
</project>
|
|
@ -1,49 +1,66 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.bukkit.lib.configuration.PluginConfiguration;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
/**
|
||||
* Limited Creative - Configuration
|
||||
*
|
||||
* (YAML-Syntax: http://en.wikipedia.org/wiki/YAML)
|
||||
*
|
||||
* This configuration-file is automatically written when changed via ingame-commands. So any manual added comments are
|
||||
* This configuration-file is automatically written when changed via ingame-commands. So any manual added comments are
|
||||
* removed.
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations
|
||||
public class Config extends PluginConfiguration {
|
||||
public Config(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public Config(Core plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(ConfigurationSection sect) {
|
||||
super.setValues(sect);
|
||||
|
||||
if (plugin.getModules().size() > 0) {
|
||||
setModuleStates();
|
||||
}
|
||||
}
|
||||
|
||||
public void setModuleStates() {
|
||||
ModuleEntry<IModule> metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry();
|
||||
if (metricsEntry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
metricsEntry.initialState = getMetrics() ? ModuleState.ENABLED : ModuleState.DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
|
||||
super.setValue(node, pValue);
|
||||
|
||||
if (node.getName().equals("metrics")) {
|
||||
ModuleEntry<IModule> metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry();
|
||||
metricsEntry.setEnabled(getMetrics());
|
||||
if (getMetrics()) {
|
||||
if (metricsEntry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
metricsEntry.enable();
|
||||
} else {
|
||||
metricsEntry.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Metrics
|
||||
*
|
||||
* This settings allows the Addon-Author to track the Servers using this plugin. It will not track any player
|
||||
* related data like names, ips, online time or such. Please do not disable the option! As more servers are using
|
||||
* This settings allows the Addon-Author to track the Servers using this plugin. It will not track any player
|
||||
* related data like names, ips, online time or such. Please do not disable the option! As more servers are using
|
||||
* the plugin and the author knows, as more he is willing to support the plugin! Its a win-win for both.
|
||||
*
|
||||
* default: true
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
/**
|
||||
* @Todo may be abstract to some per-module-definitions that are checked onEnabled and here automaticly
|
||||
*/
|
||||
public class DependencyListener implements Listener {
|
||||
private LimitedCreative plugin;
|
||||
|
||||
public DependencyListener(LimitedCreative plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginLoaded(PluginEnableEvent event) {
|
||||
ModInventories mod = plugin.getModule(ModInventories.class);
|
||||
if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) {
|
||||
String incomp = Hooks.InventoryIncompatible.test();
|
||||
if (incomp != null) {
|
||||
mod.getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, mod.getName()));
|
||||
mod.getModuleEntry().deactivateUsage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginUnloaded(PluginDisableEvent event) {
|
||||
if (event.getPlugin().getName().equals("Vault")) {
|
||||
ModGameModePerm mod = plugin.getModule(ModGameModePerm.class);
|
||||
if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) {
|
||||
mod.getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", mod.getName()));
|
||||
mod.getModuleEntry().deactivateUsage();
|
||||
}
|
||||
} else if (event.getPlugin().getName().equals("WorldGuard")) {
|
||||
ModRegions mod = plugin.getModule(ModRegions.class);
|
||||
if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) {
|
||||
mod.getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", mod.getName()));
|
||||
mod.getModuleEntry().deactivateUsage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,11 +4,11 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -21,35 +21,27 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
|
|||
public FeatureBlockItemSpawn(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
private CleanUp cleanup = new CleanUp();
|
||||
public final static long TICK_OFFSET = 1;
|
||||
public final static long TIME_OFFSET = 250;
|
||||
|
||||
private List<BlockItemDrop> list = new ArrayList<BlockItemDrop>();
|
||||
|
||||
public boolean isBlocked(Location l, Material type) {
|
||||
if (isDebug())
|
||||
getLog().debug("Checking ItemBlocked: " + l.toString() + " - " + type.toString());
|
||||
cleanup();
|
||||
for (BlockItemDrop block : list) {
|
||||
if (isDebug())
|
||||
getLog().debug(" - " + block.toString());
|
||||
if (block.getLocation().equals(l) && (block.getType() == null || block.getType().equals(type))) {
|
||||
if (isDebug())
|
||||
getLog().debug(" blocked!");
|
||||
if (block.getLocation().equals(l) && (block.getType() == null || block.getType().equals(type)))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isDebug())
|
||||
getLog().debug(" allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
private void scheduleCleanUp() {
|
||||
if (cleanup.maxTime == 0) { // if not scheduled yet
|
||||
cleanup.maxTime = System.currentTimeMillis();
|
||||
Bukkit.getScheduler().runTaskLater(plugin, cleanup, TICK_OFFSET);
|
||||
private void cleanup() {
|
||||
Iterator<BlockItemDrop> i = list.iterator();
|
||||
while (i.hasNext()) {
|
||||
BlockItemDrop block = i.next();
|
||||
if (block.getTimestamp() < System.currentTimeMillis() - TIME_OFFSET)
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class BlockItemDrop {
|
||||
public BlockItemDrop(Location l, Material type) {
|
||||
this.l = l;
|
||||
|
@ -68,74 +60,34 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
|
|||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
public String toString() {
|
||||
return Long.toString(timestamp) + ": " + l.toString() + (type != null ? " - " + type.toString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
public void block(Block block, Player player) {
|
||||
if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
block(block.getLocation(), block.getType());
|
||||
} else {
|
||||
// doesn't include silktouch
|
||||
for (ItemStack i : block.getDrops(player.getInventory().getItemInMainHand())) {
|
||||
for (ItemStack i : block.getDrops(player.getItemInHand())) {
|
||||
block(block.getLocation(), i.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void block(Block block) {
|
||||
block(block.getLocation());
|
||||
}
|
||||
public void block(Location l) {
|
||||
list.add(new BlockItemDrop(l, null));
|
||||
scheduleCleanUp();
|
||||
block(block, null);
|
||||
}
|
||||
public void block(Location l, Material type) {
|
||||
list.add(new BlockItemDrop(l, type));
|
||||
scheduleCleanUp();
|
||||
}
|
||||
public void block(Location l, ItemStack item) {
|
||||
if (item != null)
|
||||
block(l, item.getType());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
if (event.getEntity() != null) {
|
||||
if (this.isBlocked(event.getLocation().getBlock().getLocation(), event.getEntity().getItemStack().getType())) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getEntity() instanceof Item) {
|
||||
if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't default Plugin-debug to this mod. Because it is too spammy.
|
||||
*/
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
private class CleanUp implements Runnable {
|
||||
public long maxTime = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.isDebug())
|
||||
plugin.getLog().debug("Scheduler: Synchronous Task run: Cleanup");
|
||||
Iterator<BlockItemDrop> i = list.iterator();
|
||||
while (i.hasNext()) {
|
||||
BlockItemDrop block = i.next();
|
||||
if (block.getTimestamp() <= maxTime) {
|
||||
if (isDebug())
|
||||
getLog().debug("Removing outdated BlokItemDrop: " + block.toString());
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
maxTime = 0;
|
||||
if (list.size() > 0)
|
||||
scheduleCleanUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +1,34 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.bukkit.tools.stats.IStatistics;
|
||||
import de.jaschastarke.bukkit.tools.stats.PiwikStatistics;
|
||||
|
||||
public class FeatureMetrics extends CoreModule<LimitedCreative> implements Listener {
|
||||
public FeatureMetrics(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
private Metrics bstats = null;
|
||||
|
||||
private IStatistics metric;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
if (bstats == null) {
|
||||
bstats = new Metrics(plugin, 10413);
|
||||
|
||||
bstats.addCustomChart(new AdvancedPie("module_usage", () -> {
|
||||
HashMap<String, Integer> ret = new HashMap<>();
|
||||
for (final ModuleEntry<IModule> mod : plugin.getModules())
|
||||
if (mod.getModule() instanceof CoreModule<?>)
|
||||
ret.put(((CoreModule<?>) mod.getModule()).getName(), mod.getState() == ModuleState.ENABLED ? 1 : 0);
|
||||
return ret;
|
||||
}));
|
||||
bstats.addCustomChart(new AdvancedPie("dependencies", () -> {
|
||||
HashMap<String, Integer> ret = new HashMap<>();
|
||||
for (final String dep : plugin.getDescription().getSoftDepend())
|
||||
ret.put(dep, plugin.getServer().getPluginManager().isPluginEnabled(dep) ? 1 : 0);
|
||||
return ret;
|
||||
}));
|
||||
}
|
||||
metric = new PiwikStatistics(plugin);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
metric.unregister();
|
||||
}
|
||||
|
||||
public void track(String event) throws IOException {
|
||||
if (metric == null)
|
||||
throw new IllegalAccessError("The feature hasn't been enabled");
|
||||
metric.trackEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.IHasName;
|
||||
|
@ -23,10 +22,8 @@ import de.jaschastarke.bukkit.lib.commands.annotations.Description;
|
|||
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
|
||||
import de.jaschastarke.bukkit.lib.commands.annotations.NeedsPermission;
|
||||
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
|
||||
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
|
||||
public FeatureSwitchGameMode(LimitedCreative plugin) {
|
||||
|
@ -69,7 +66,6 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
|
|||
return SwitchGameModePermissions.ALL.getPermission(subPerm);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected boolean changeGameMode(CommandContext context, String player, GameMode tgm, IAbstractPermission permission) throws MissingPermissionCommandException, CommandException {
|
||||
Player target = null;
|
||||
if (player != null && !player.isEmpty()) {
|
||||
|
@ -86,12 +82,10 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
|
|||
if (!target.equals(context.getSender()) && !context.checkPermission(SwitchGameModePermissions.OTHER))
|
||||
throw new MissingPermissionCommandException(SwitchGameModePermissions.OTHER);
|
||||
|
||||
GameMode wgm = this.getDefaultGameMode(target.getWorld());
|
||||
GameMode wgm = Hooks.DefaultWorldGameMode.get(target.getWorld());
|
||||
|
||||
if (!this.regionOptional(target, tgm)) {
|
||||
if (!context.checkPermission(permission) && (wgm != tgm || !context.checkPermission(SwitchGameModePermissions.BACKONLY)))
|
||||
throw new MissingPermissionCommandException(permission);
|
||||
}
|
||||
if (!context.checkPermission(permission) && (wgm != tgm || !context.checkPermission(SwitchGameModePermissions.BACKONLY)))
|
||||
throw new MissingPermissionCommandException(permission);
|
||||
|
||||
if (target.getGameMode() != tgm) {
|
||||
target.setGameMode(tgm);
|
||||
|
@ -103,16 +97,6 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private GameMode getDefaultGameMode(World world) {
|
||||
return Hooks.DefaultWorldGameMode.get(world);
|
||||
}
|
||||
|
||||
private boolean regionOptional(Player player, GameMode tgm) {
|
||||
ModRegions mod = plugin.getModule(ModRegions.class);
|
||||
return mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED
|
||||
&& mod.getWorldGuardIntegration().isRegionOptional(player, tgm);
|
||||
}
|
||||
|
||||
@IsCommand("survival")
|
||||
@Alias("s")
|
||||
|
@ -138,18 +122,5 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
|
|||
public boolean adventure(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
|
||||
return changeGameMode(context, player, GameMode.ADVENTURE, SwitchGameModePermissions.ADVENTURE);
|
||||
}
|
||||
@IsCommand("spectator")
|
||||
@Alias("sp")
|
||||
@Description(value = "command.switch.spectator", translate = true)
|
||||
@NeedsPermission(value={"spectator", "backonly"}, optional = true)
|
||||
@Usages("[player]")
|
||||
public boolean spectator(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
|
||||
return changeGameMode(context, player, GameMode.SPECTATOR, SwitchGameModePermissions.SPECTATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TabCompletion> getTabCompleter(MethodCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import de.jaschastarke.hooking.BooleanHooker;
|
||||
import de.jaschastarke.hooking.GetHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public final class Hooks {
|
||||
public static PlayerCheckHooker IsLoggedIn = new PlayerCheckHooker(true);
|
||||
|
@ -18,24 +20,21 @@ public final class Hooks {
|
|||
return Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void inizializeHooks(LimitedCreative plugin) {
|
||||
IsLoggedIn.clearHooks();
|
||||
DefaultWorldGameMode.clearHooks();
|
||||
IsMultiVerse.clearHooks();
|
||||
InventoryIncompatible.clearHooks();
|
||||
|
||||
if (isAuthMePresent()) {
|
||||
new de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks(plugin);
|
||||
if (isPluginEnabled("AuthMe")) {
|
||||
new AuthMeHooks(plugin);
|
||||
}
|
||||
if (isXAuth20Present()) {
|
||||
if (isPluginEnabled("xAuth")) {
|
||||
new xAuthHooks(plugin);
|
||||
}
|
||||
if (isPluginEnabled("Multiverse-Core")) {
|
||||
new MultiVerseHooks(plugin);
|
||||
}/* else if (isPluginEnabled("MultiWorld")) { // MultiWord suckz, the Creative-World-Setting doesn't affect anything
|
||||
new MultiWorldHooks(plugin);
|
||||
}*/
|
||||
}
|
||||
|
||||
InventoryIncompatible.register(new GetHooker.Check<String>() {
|
||||
@Override
|
||||
|
@ -48,28 +47,4 @@ public final class Hooks {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isAuthMePresent() {
|
||||
if (isPluginEnabled("AuthMe")) {
|
||||
try {
|
||||
Class.forName("uk.org.whoami.authme.api.API");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isXAuth20Present() {
|
||||
if (isPluginEnabled("xAuth")) {
|
||||
try {
|
||||
Class.forName("com.cypherx.xauth.xAuth");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,6 @@ import de.jaschastarke.I18n;
|
|||
import de.jaschastarke.bukkit.lib.Core;
|
||||
import de.jaschastarke.bukkit.lib.PluginLang;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand;
|
||||
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
|
||||
import de.jaschastarke.bukkit.lib.modules.InstantHangingBreak;
|
||||
import de.jaschastarke.utils.ClassDescriptorStorage;
|
||||
|
||||
public class LimitedCreative extends Core {
|
||||
protected Config config = null;
|
||||
|
@ -27,36 +24,17 @@ public class LimitedCreative extends Core {
|
|||
|
||||
Hooks.inizializeHooks(this);
|
||||
|
||||
modules.addSharedModule(new AdditionalBlockBreaks(this));
|
||||
modules.addSharedModule(new InstantHangingBreak(this));
|
||||
modules.addSharedModule(new FeatureBlockItemSpawn(this));
|
||||
addModule(new FeatureSwitchGameMode(this));
|
||||
addModule(new ModInventories(this));
|
||||
addModule(new ModCreativeLimits(this));
|
||||
addModule(new ModRegions(this));
|
||||
addModule(new ModCmdBlocker(this));
|
||||
addModule(new ModGameModePerm(this));
|
||||
addModule(new ModBlockStates(this));
|
||||
addModule(new FeatureMetrics(this)).setDefaultEnabled(config.getMetrics());
|
||||
|
||||
listeners.addListener(new DependencyListener(this));
|
||||
addModule(new FeatureMetrics(this));
|
||||
|
||||
config.setModuleStates();
|
||||
config.saveDefault();
|
||||
|
||||
try {
|
||||
Class.forName("de.jaschastarke.hooking.CaptainHook");
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptorStorage getDocCommentStorage() {
|
||||
if (cds == null) {
|
||||
cds = new ClassDescriptorStorage();
|
||||
cds.getResourceBundle().addResourceBundle("lang.doccomments");
|
||||
}
|
||||
return cds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.getDebug();
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.jaschastarke.LocaleString;
|
||||
import de.jaschastarke.bukkit.lib.commands.BukkitCommand;
|
||||
import de.jaschastarke.bukkit.lib.commands.CommandContext;
|
||||
import de.jaschastarke.bukkit.lib.commands.IHelpDescribed;
|
||||
import de.jaschastarke.bukkit.lib.commands.IMethodCommandContainer;
|
||||
import de.jaschastarke.bukkit.lib.commands.MethodCommand;
|
||||
import de.jaschastarke.bukkit.lib.commands.annotations.Description;
|
||||
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
|
||||
import de.jaschastarke.bukkit.lib.commands.annotations.NeedsPermission;
|
||||
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
|
||||
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginCommand;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
|
||||
|
@ -24,14 +18,12 @@ import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
|||
* @permission limitedcreative.command
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginCommand
|
||||
public class MainCommand extends BukkitCommand implements IHelpDescribed, IMethodCommandContainer {
|
||||
private LimitedCreative plugin;
|
||||
|
||||
public MainCommand() {
|
||||
}
|
||||
public MainCommand(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
@ -71,22 +63,17 @@ public class MainCommand extends BukkitCommand implements IHelpDescribed, IMetho
|
|||
}
|
||||
|
||||
@IsCommand("reload")
|
||||
@Usages("")
|
||||
@Description(value = "command.config.reload", translate = true)
|
||||
@NeedsPermission(value={"config"})
|
||||
public boolean doReload(final CommandContext context) {
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.isDebug())
|
||||
plugin.getLog().debug("Scheduler: Synchronous Task run: Disable");
|
||||
plugin.onDisable();
|
||||
plugin.getPluginConfig().reload();
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.isDebug())
|
||||
plugin.getLog().debug("Scheduler: Synchronous Task run: Enable");
|
||||
plugin.onEnable();
|
||||
context.response(context.getFormatter().getString("command.config.reload.success"));
|
||||
}
|
||||
|
@ -95,9 +82,4 @@ public class MainCommand extends BukkitCommand implements IHelpDescribed, IMetho
|
|||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TabCompletion> getTabCompleter(MethodCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
|
||||
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
|
||||
import de.jaschastarke.bukkit.lib.modules.BlockFall;
|
||||
import de.jaschastarke.bukkit.lib.modules.InstantHangingBreak;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingStandingListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.EditSessionListener;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
|
||||
public class ModBlockStates extends CoreModule<LimitedCreative> {
|
||||
private BlockStateConfig config;
|
||||
private FeatureBlockItemSpawn blockDrops;
|
||||
private BlockStateCommand command;
|
||||
private DBModel model;
|
||||
|
||||
public ModBlockStates(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BlockState";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ModuleEntry<IModule> entry) {
|
||||
super.initialize(entry);
|
||||
|
||||
config = new BlockStateConfig(this, entry);
|
||||
plugin.getPluginConfig().registerSection(config);
|
||||
|
||||
blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
|
||||
modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules());
|
||||
modules.linkSharedModule(InstantHangingBreak.class, plugin.getModules());
|
||||
this.addModule(new BlockFall(plugin));
|
||||
|
||||
listeners.addListener(new BlockListener(this));
|
||||
listeners.addListener(new HangingStandingListener(this));
|
||||
listeners.addListener(new PlayerListener(this));
|
||||
|
||||
command = new BlockStateCommand(this);
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
if (model == null) {
|
||||
if (config.getUseThreading())
|
||||
model = new ThreadedModel(this);
|
||||
else
|
||||
model = new SyncronizedModel(this);
|
||||
}
|
||||
if (model instanceof Listener)
|
||||
listeners.addListener((Listener) model);
|
||||
model.onEnable();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
getLog().warn(plugin.getLocale().trans("block_state.error.sql_connection_failed", getName()));
|
||||
entry.deactivateUsage();
|
||||
return;
|
||||
}
|
||||
super.onEnable();
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("WorldEdit") && config.getWorldeditIntegration()) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
WorldEdit.getInstance().getEventBus().register(new EditSessionListener(ModBlockStates.this));
|
||||
} catch (Exception e) {
|
||||
getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
|
||||
}
|
||||
}
|
||||
}.runTaskLater(plugin, 1L);
|
||||
}
|
||||
|
||||
plugin.getCommandHandler().registerCommand(command);
|
||||
plugin.getMainCommand().registerCommand(new AliasHelpedCommand<BlockStateCommand>(command, "blockstate", new String[]{"bs"}));
|
||||
|
||||
getLog().info(plugin.getLocale().trans("basic.loaded.module"));
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (model != null)
|
||||
model.onDisable();
|
||||
super.onDisable();
|
||||
if (model != null && model instanceof Listener)
|
||||
listeners.removeListener((Listener) model);
|
||||
model = null;
|
||||
|
||||
plugin.getCommandHandler().removeCommand(command);
|
||||
plugin.getMainCommand().removeCommand(command);
|
||||
}
|
||||
|
||||
public BlockStateConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
public FeatureBlockItemSpawn getBlockSpawn() {
|
||||
return blockDrops;
|
||||
}
|
||||
public DBModel getModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
|
@ -1,20 +1,16 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
|
||||
import de.jaschastarke.bukkit.lib.modules.InstantHangingBreak;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.BlockListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.EntityListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.EntityNoDrop;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.PlayerListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.VehicleListener;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
public class ModCreativeLimits extends CoreModule<LimitedCreative> {
|
||||
protected LimitConfig config;
|
||||
private EntityNoDrop noDropsMobs = null;
|
||||
|
||||
public ModCreativeLimits(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
|
@ -33,16 +29,17 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
|
|||
listeners.addListener(new PlayerListener(this));
|
||||
listeners.addListener(new EntityListener(this));
|
||||
listeners.addListener(new BlockListener(this));
|
||||
listeners.addListener(new VehicleListener(this));
|
||||
config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry));
|
||||
|
||||
blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
|
||||
modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules());
|
||||
modules.linkSharedModule(InstantHangingBreak.class, plugin.getModules());
|
||||
}
|
||||
|
||||
public FeatureBlockItemSpawn getBlockSpawn() {
|
||||
return blockDrops;
|
||||
/*blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
|
||||
if (blockDrops == null)
|
||||
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
|
||||
*/
|
||||
|
||||
if (!config.getEnabled()) {
|
||||
entry.initialState = ModuleState.DISABLED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,11 +51,5 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
|
|||
public LimitConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public EntityNoDrop getNoDropMobs() {
|
||||
if (noDropsMobs == null)
|
||||
noDropsMobs = new EntityNoDrop();
|
||||
return noDropsMobs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.minecraft.limitedcreative.gmperm.GMPermConfig;
|
||||
import de.jaschastarke.minecraft.limitedcreative.gmperm.PermissionInterface;
|
||||
import de.jaschastarke.minecraft.limitedcreative.gmperm.PlayerListener;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
|
||||
public class ModGameModePerm extends CoreModule<LimitedCreative> {
|
||||
private GMPermConfig config;
|
||||
private PermissionInterface permission = null;
|
||||
|
||||
public ModGameModePerm(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GameModePerm";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ModuleEntry<IModule> entry) {
|
||||
super.initialize(entry);
|
||||
listeners.addListener(new PlayerListener(this));
|
||||
config = new GMPermConfig(this, entry);
|
||||
plugin.getPluginConfig().registerSection(config);
|
||||
|
||||
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
if (config.getEnabled())
|
||||
getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName()));
|
||||
entry.deactivateUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
permission = new PermissionInterface(this);
|
||||
|
||||
if (config.getEnabled()) {
|
||||
if (!permission.isPresent()) {
|
||||
getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName()));
|
||||
entry.deactivateUsage();
|
||||
return;
|
||||
} /*else if (!getVaultPermission().hasGroupSupport()) {
|
||||
getLog().warn(plugin.getLocale().trans("gmperm.warning.no_group_support", getName()));
|
||||
entry.initialState = ModuleState.NOT_INITIALIZED;
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
getLog().info(plugin.getLocale().trans("basic.loaded.module"));
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
permission.clear();
|
||||
}
|
||||
public GMPermConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
public PermissionInterface getPermissionInterface() {
|
||||
return permission;
|
||||
}
|
||||
}
|
|
@ -1,135 +1,133 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.*;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.store.ReflectionStorage;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class ModInventories extends CoreModule<LimitedCreative> {
|
||||
protected PlayerInventoryStorage storage;
|
||||
protected Map<Player, Inventory> inventories;
|
||||
protected InventoryConfig config;
|
||||
protected ArmoryConfig armor_config;
|
||||
|
||||
public ModInventories(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Inventory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ModuleEntry<IModule> entry) {
|
||||
super.initialize(entry);
|
||||
listeners.addListener(new PlayerListener(this));
|
||||
config = plugin.getPluginConfig().registerSection(new InventoryConfig(this, entry));
|
||||
armor_config = config.registerSection(new ArmoryConfig(this));
|
||||
|
||||
if (Hooks.isAuthMePresent()) {
|
||||
addModule(new de.jaschastarke.minecraft.limitedcreative.inventories.AuthMeInventories(plugin, this));
|
||||
}
|
||||
String incomp = Hooks.InventoryIncompatible.test();
|
||||
if (config.getEnabled() && incomp != null) {
|
||||
getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName()));
|
||||
entry.deactivateUsage();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
String incomp = Hooks.InventoryIncompatible.test();
|
||||
if (incomp != null) {
|
||||
throw new IllegalAccessError(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName()));
|
||||
}
|
||||
super.onEnable();
|
||||
//storage = new InvYamlStorage(this, new File(plugin.getDataFolder(), config.getFolder()));
|
||||
storage = new ReflectionStorage(this, new File(plugin.getDataFolder(), config.getFolder()));
|
||||
inventories = new WeakHashMap<Player, Inventory>();
|
||||
getLog().info(plugin.getLocale().trans("basic.loaded.module"));
|
||||
}
|
||||
public InventoryConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
public ArmoryConfig getArmorConfig() {
|
||||
return armor_config;
|
||||
}
|
||||
|
||||
public PlayerInventoryStorage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public Inventory getInventory(Player player) {
|
||||
if (inventories.containsKey(player)) {
|
||||
return inventories.get(player);
|
||||
} else {
|
||||
Inventory inv = new Inventory(storage, player);
|
||||
inventories.put(player, inv);
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
|
||||
public void onSetGameMode(Player player, GameMode gm) {
|
||||
if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
|
||||
return;
|
||||
player.closeInventory();
|
||||
|
||||
GameMode cgm = player.getGameMode();
|
||||
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||
gm = GameMode.SURVIVAL;
|
||||
else if (gm == GameMode.SPECTATOR)
|
||||
gm = GameMode.CREATIVE;
|
||||
if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||
cgm = GameMode.SURVIVAL;
|
||||
else if (cgm == GameMode.SPECTATOR)
|
||||
cgm = GameMode.CREATIVE;
|
||||
|
||||
if (gm != cgm) {
|
||||
if (gm != GameMode.CREATIVE || config.getStoreCreative()) {
|
||||
getInventory(player).save(cgm);
|
||||
}
|
||||
if (gm == GameMode.CREATIVE) {
|
||||
if (config.getStoreCreative() && getInventory(player).isStored(GameMode.CREATIVE)) {
|
||||
getInventory(player).load(GameMode.CREATIVE);
|
||||
} else {
|
||||
getInventory(player).clear();
|
||||
}
|
||||
setCreativeArmor(player);
|
||||
} else if (gm == GameMode.SURVIVAL) {
|
||||
if (getInventory(player).isStored(GameMode.SURVIVAL))
|
||||
getInventory(player).load(GameMode.SURVIVAL);
|
||||
} else if (gm == GameMode.ADVENTURE) {
|
||||
if (getInventory(player).isStored(GameMode.ADVENTURE))
|
||||
getInventory(player).load(GameMode.ADVENTURE);
|
||||
else
|
||||
getInventory(player).clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreativeArmor(Player player) {
|
||||
if (!getPlugin().getPermManager().hasPermission(player, InventoryPermissions.BYPASS_CREATIVE_ARMOR)) {
|
||||
Map<String, ItemStack> armor = armor_config.getCreativeArmor();
|
||||
if (armor != null) {
|
||||
ItemStack[] is = new ItemStack[4];
|
||||
if (armor.containsKey("feet"))
|
||||
is[0] = armor.get("feet");
|
||||
if (armor.containsKey("legs"))
|
||||
is[1] = armor.get("legs");
|
||||
if (armor.containsKey("chest"))
|
||||
is[2] = armor.get("chest");
|
||||
if (armor.containsKey("head"))
|
||||
is[3] = armor.get("head");
|
||||
player.getInventory().setArmorContents(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.jaschastarke.minecraft.limitedcreative;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.PlayerListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.store.InvYamlStorage;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
public class ModInventories extends CoreModule<LimitedCreative> {
|
||||
protected PlayerInventoryStorage storage;
|
||||
protected Map<Player, Inventory> inventories;
|
||||
protected InventoryConfig config;
|
||||
protected ArmoryConfig armor_config;
|
||||
|
||||
public ModInventories(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Inventory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ModuleEntry<IModule> entry) {
|
||||
super.initialize(entry);
|
||||
listeners.addListener(new PlayerListener(this));
|
||||
config = plugin.getPluginConfig().registerSection(new InventoryConfig(this, entry));
|
||||
armor_config = config.registerSection(new ArmoryConfig(this));
|
||||
|
||||
if (!config.getEnabled()) {
|
||||
entry.initialState = ModuleState.DISABLED;
|
||||
return;
|
||||
}
|
||||
|
||||
String incomp = Hooks.InventoryIncompatible.test();
|
||||
if (incomp != null) {
|
||||
getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName()));
|
||||
entry.initialState = ModuleState.NOT_INITIALIZED;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
String incomp = Hooks.InventoryIncompatible.test();
|
||||
if (incomp != null) {
|
||||
throw new IllegalAccessError(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName()));
|
||||
}
|
||||
super.onEnable();
|
||||
storage = new InvYamlStorage(this, new File(plugin.getDataFolder(), config.getFolder()));
|
||||
inventories = new WeakHashMap<Player, Inventory>();
|
||||
getLog().info(plugin.getLocale().trans("basic.loaded.module"));
|
||||
}
|
||||
public InventoryConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public PlayerInventoryStorage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public Inventory getInventory(Player player) {
|
||||
if (inventories.containsKey(player)) {
|
||||
return inventories.get(player);
|
||||
} else {
|
||||
Inventory inv = new Inventory(storage, player);
|
||||
inventories.put(player, inv);
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
|
||||
public void onSetGameMode(Player player, GameMode gm) {
|
||||
if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
|
||||
return;
|
||||
player.closeInventory();
|
||||
|
||||
GameMode cgm = player.getGameMode();
|
||||
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||
gm = GameMode.SURVIVAL;
|
||||
if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||
cgm = GameMode.SURVIVAL;
|
||||
|
||||
if (gm != cgm) {
|
||||
if (gm != GameMode.CREATIVE || config.getStoreCreative()) {
|
||||
getInventory(player).save(cgm);
|
||||
}
|
||||
if (gm == GameMode.CREATIVE) {
|
||||
if (config.getStoreCreative() && getInventory(player).isStored(GameMode.CREATIVE)) {
|
||||
getInventory(player).load(GameMode.CREATIVE);
|
||||
} else {
|
||||
getInventory(player).clear();
|
||||
}
|
||||
setCreativeArmor(player);
|
||||
} else if (gm == GameMode.SURVIVAL) {
|
||||
if (getInventory(player).isStored(GameMode.SURVIVAL))
|
||||
getInventory(player).load(GameMode.SURVIVAL);
|
||||
} else if (gm == GameMode.ADVENTURE) {
|
||||
if (getInventory(player).isStored(GameMode.ADVENTURE))
|
||||
getInventory(player).load(GameMode.ADVENTURE);
|
||||
else
|
||||
getInventory(player).clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreativeArmor(Player player) {
|
||||
Map<String, ItemStack> armor = armor_config.getCreativeArmor();
|
||||
if (armor != null) {
|
||||
ItemStack[] is = new ItemStack[4];
|
||||
if (armor.containsKey("feet"))
|
||||
is[0] = armor.get("feet");
|
||||
if (armor.containsKey("legs"))
|
||||
is[1] = armor.get("legs");
|
||||
if (armor.containsKey("chest"))
|
||||
is[2] = armor.get("chest");
|
||||
if (armor.containsKey("head"))
|
||||
is[3] = armor.get("head");
|
||||
player.getInventory().setArmorContents(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,24 +4,27 @@ import java.io.File;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.BlockListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.IWorldGuardIntegration;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.Flags;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.PlayerData;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.PlayerListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.RegionConfig;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.RegionListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.RegionsCommand;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagList;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.PlayerRegionListener;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
public class ModRegions extends CoreModule<LimitedCreative> {
|
||||
private CustomRegionManager mgr;
|
||||
private IWorldGuardIntegration wg;
|
||||
private WorldGuardPlugin wg;
|
||||
private PlayerData pdata;
|
||||
private FeatureBlockItemSpawn blockDrops = null;
|
||||
private RegionConfig config;
|
||||
|
@ -30,26 +33,17 @@ public class ModRegions extends CoreModule<LimitedCreative> {
|
|||
public ModRegions(LimitedCreative plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Regions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ModuleEntry<IModule> pEntry) {
|
||||
super.initialize(pEntry);
|
||||
|
||||
blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
|
||||
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
|
||||
if (blockDrops == null)
|
||||
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
|
||||
|
||||
config = plugin.getPluginConfig().registerSection(new RegionConfig(this, entry));
|
||||
|
||||
if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
if (config.getEnabled())
|
||||
getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName()));
|
||||
entry.deactivateUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
command = new RegionsCommand(this);
|
||||
|
||||
listeners.addListener(new PlayerListener(this));
|
||||
|
@ -57,14 +51,12 @@ public class ModRegions extends CoreModule<LimitedCreative> {
|
|||
listeners.addListener(new RegionListener(this));
|
||||
listeners.addListener(new PlayerRegionListener(this)); // Fires Custom-Events listen by RegionListener
|
||||
|
||||
getWorldGuardIntegration().initFlagList();
|
||||
}
|
||||
|
||||
public IWorldGuardIntegration getWorldGuardIntegration() {
|
||||
if (wg == null) {
|
||||
wg = new WorldGuardIntegration(this);
|
||||
FlagList.addFlags(Flags.getList());
|
||||
|
||||
if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName()));
|
||||
entry.initialState = ModuleState.NOT_INITIALIZED;
|
||||
}
|
||||
return wg;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,9 +64,9 @@ public class ModRegions extends CoreModule<LimitedCreative> {
|
|||
super.onEnable();
|
||||
|
||||
mgr = new CustomRegionManager(new File(plugin.getDataFolder(), "regions.yml"), this);
|
||||
/*wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (wg == null)
|
||||
throw new IllegalAccessError("Missing Plugin WorldGuard");*/
|
||||
throw new IllegalAccessError("Missing Plugin WorldGuard");
|
||||
|
||||
plugin.getCommandHandler().registerCommand(command);
|
||||
plugin.getMainCommand().registerCommand(new AliasHelpedCommand<RegionsCommand>(command, "region", new String[]{"r"}));
|
||||
|
@ -95,9 +87,9 @@ public class ModRegions extends CoreModule<LimitedCreative> {
|
|||
return config;
|
||||
}
|
||||
|
||||
/*public WorldGuardPlugin getWorldGuard() {
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
return wg;
|
||||
}*/
|
||||
}
|
||||
public CustomRegionManager getRegionManager() {
|
||||
return mgr;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package de.jaschastarke.minecraft.limitedcreative;
|
|||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainerNode;
|
||||
|
@ -31,7 +30,6 @@ public class Permissions extends SimplePermissionContainerNode {
|
|||
super(name);
|
||||
}
|
||||
|
||||
@PluginPermissions
|
||||
public final static Permissions CONTAINER = new Permissions("limitedcreative");
|
||||
|
||||
/**
|
||||
|
@ -39,9 +37,8 @@ public class Permissions extends SimplePermissionContainerNode {
|
|||
*/
|
||||
public static final IPermission CONFIG = new BasicPermission(CONTAINER, "config", PermissionDefault.OP);
|
||||
/**
|
||||
* Needed for any player that want's to use the /lc or /limitedcreative-command. If not granted, the user shouldn't
|
||||
* see the command in /help, but he also isn't able to use the /lc c-gamemode commands, even if switch_gamemode
|
||||
* is granted.
|
||||
* Gives player access to the general /limitedcreative command. This permission doesn't affect the usability, but
|
||||
* allows to hide the command from /help for users.
|
||||
*/
|
||||
public static final IPermission COMMAND = new BasicPermission(CONTAINER, "command", PermissionDefault.OP);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package de.jaschastarke.minecraft.limitedcreative;
|
|||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IsChildPermission;
|
||||
|
@ -14,7 +13,6 @@ public class SwitchGameModePermissions extends ParentPermissionContainerNode {
|
|||
/**
|
||||
* Allows switching of own game mode to creative/adventure and back
|
||||
*/
|
||||
@PluginPermissions
|
||||
public final static SwitchGameModePermissions ALL = new SwitchGameModePermissions(Permissions.CONTAINER, "switch_gamemode");
|
||||
|
||||
protected SwitchGameModePermissions(IAbstractPermission parent, String name) {
|
||||
|
@ -46,11 +44,6 @@ public class SwitchGameModePermissions extends ParentPermissionContainerNode {
|
|||
*/
|
||||
@IsChildPermission
|
||||
public final static BasicPermission ADVENTURE = new BasicPermission(ALL, "adventure", PermissionDefault.FALSE);
|
||||
/**
|
||||
* Allows switching of own game mode to spectator, but not to creative/survival/adventure
|
||||
*/
|
||||
@IsChildPermission
|
||||
public final static BasicPermission SPECTATOR = new BasicPermission(ALL, "spectator", PermissionDefault.FALSE);
|
||||
|
||||
/**
|
||||
* Allows switching of other users game mode
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class AbstractModel {
|
||||
protected static final String BSMDKEY = "blockstate";
|
||||
protected MetadataValue metadataNull;
|
||||
private Plugin plugin;
|
||||
|
||||
protected AbstractModel(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
metadataNull = new FixedMetadataValue(plugin, new Boolean(null));
|
||||
}
|
||||
|
||||
protected void moveMetaState(Block from, Block to) {
|
||||
HasBlockState metaBlock = getMetaBlock(from);
|
||||
if (metaBlock.isSet() && metaBlock.getState() != null) {
|
||||
BlockState state = metaBlock.state;
|
||||
state.setLocation(to.getLocation());
|
||||
setMetaBlock(to, state);
|
||||
} else {
|
||||
removeMetaBlock(to);
|
||||
}
|
||||
setMetaBlock(from, null);
|
||||
}
|
||||
|
||||
protected boolean hasMetaBlock(Metadatable m) {
|
||||
List<MetadataValue> metadata = m.getMetadata(BSMDKEY);
|
||||
for (MetadataValue v : metadata) {
|
||||
if (v.value() instanceof BlockState)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected void setMetaBlock(Metadatable m, BlockState s) {
|
||||
if (s == null)
|
||||
m.setMetadata(BSMDKEY, metadataNull);
|
||||
else
|
||||
m.setMetadata(BSMDKEY, new FixedMetadataValue(plugin, s));
|
||||
}
|
||||
protected HasBlockState getMetaBlock(Metadatable m) {
|
||||
HasBlockState has = null;
|
||||
List<MetadataValue> metadata = m.getMetadata(BSMDKEY);
|
||||
for (MetadataValue v : metadata) {
|
||||
if (v.value() instanceof BlockState) {
|
||||
has = new HasBlockState((BlockState) v.value());
|
||||
break;
|
||||
} else if (v == metadataNull) {
|
||||
// Metadata Knows, that there is no entry in DB
|
||||
has = new HasBlockState(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (has == null)
|
||||
return new HasBlockState(false);
|
||||
else
|
||||
return has;
|
||||
}
|
||||
protected void removeMetaBlock(Metadatable m) {
|
||||
m.removeMetadata(BSMDKEY, plugin);
|
||||
}
|
||||
|
||||
public static class HasBlockState {
|
||||
private boolean set = false;
|
||||
private BlockState state = null;
|
||||
public HasBlockState(BlockState state) {
|
||||
set = true;
|
||||
this.state = state;
|
||||
}
|
||||
public HasBlockState(boolean isSet) {
|
||||
set = isSet;
|
||||
}
|
||||
public boolean isSet() {
|
||||
return set;
|
||||
}
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.events.BlockDestroyedEvent;
|
||||
import de.jaschastarke.bukkit.lib.events.BlockMovedEvent;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
private final static String FALLING_ENTITY_BSMDKEY = "blockstate";
|
||||
private ModBlockStates mod;
|
||||
private MetadataValue blockAlreadExtended;
|
||||
|
||||
public BlockListener(ModBlockStates mod) {
|
||||
this.mod = mod;
|
||||
blockAlreadExtended = new FixedMetadataValue(mod.getPlugin(), new Boolean(true));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
|
||||
return;
|
||||
if (mod.getModel().isRestricted(event.getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Breaking bad, err.. block: " + event.getBlock().getLocation().toString() + " was placed by creative. Drop prevented");
|
||||
|
||||
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
||||
mod.getBlockSpawn().block(event.getBlock(), event.getPlayer());
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
}
|
||||
mod.getModel().removeState(event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOtherBlockDestroy(BlockDestroyedEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
|
||||
return;
|
||||
if (mod.getModel().isRestricted(event.getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Breaking attached block: " + event.getBlock().getLocation().toString() + " was placed by creative. Drop prevented");
|
||||
|
||||
mod.getBlockSpawn().block(event.getBlock());
|
||||
}
|
||||
mod.getModel().removeState(event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockMoved(BlockMovedEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
|
||||
return;
|
||||
for (MetadataValue md : event.getEntity().getMetadata(FALLING_ENTITY_BSMDKEY)) {
|
||||
if (md.value() instanceof BlockState) {
|
||||
BlockState bs = (BlockState) md.value();
|
||||
// The state of the source block should be always be cached yet, as we either asked it before, or
|
||||
// it was just placed
|
||||
if (bs != mod.getModel().getState(event.getSource())) {
|
||||
bs.setLocation(event.getBlock().getLocation());
|
||||
mod.getModel().setState(bs);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
mod.getModel().moveState(event.getSource(), event.getBlock());
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
|
||||
if (event.getEntityType() == EntityType.FALLING_BLOCK) {
|
||||
if (event.getTo() == Material.AIR) {
|
||||
if (mod.getModel().isRestricted(event.getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Falling block: " + event.getBlock().getLocation().toString() + " was placed by creative (drop prevented)");
|
||||
FallingBlock fe = (FallingBlock) event.getEntity();
|
||||
fe.setDropItem(false);
|
||||
// Using getState to fetch the full state from database synchronous isn't optimal, but either it is
|
||||
// cached, as it was just placed, or it isn't that important, as it is a rare event
|
||||
fe.setMetadata(FALLING_ENTITY_BSMDKEY, new FixedMetadataValue(mod.getPlugin(), mod.getModel().getState(event.getBlock())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlocksBreakByExplosion(EntityExplodeEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getLocation().getWorld().getName()))
|
||||
return;
|
||||
Map<Block, Boolean> states = mod.getModel().getRestrictedStates(event.blockList());
|
||||
DBTransaction update = mod.getModel().groupUpdate();
|
||||
for (Block block : event.blockList()) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Breaking bad, err.. block by explosion: " + block.getLocation().toString());
|
||||
|
||||
if (states.get(block)) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("... was placed by creative. Drop prevented");
|
||||
mod.getBlockSpawn().block(block);
|
||||
}
|
||||
|
||||
update.removeState(block);
|
||||
}
|
||||
update.finish();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
|
||||
return;
|
||||
BlockState s = new BlockState();
|
||||
s.setLocation(event.getBlock().getLocation());
|
||||
s.setPlayer(event.getPlayer());
|
||||
s.setDate(new Date());
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
||||
|
||||
mod.getModel().setState(s);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPistionExtend(BlockPistonExtendEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
|
||||
return;
|
||||
if (event.getBlock().getMetadata("LCBS_pistonIsAlreadyExtended").size() > 0) // Fixes long known Bukkit issue
|
||||
return;
|
||||
event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", blockAlreadExtended);
|
||||
|
||||
/*if (mod.isDebug())
|
||||
mod.getLog().debug("PistonExtend "+source.getType()+" "+source.getLocation()+" "+event.getDirection());*/
|
||||
|
||||
List<Block> movedBlocks = event.getBlocks();
|
||||
|
||||
if (movedBlocks.size() > 0) {
|
||||
DBTransaction update = mod.getModel().groupUpdate();
|
||||
for(int count = movedBlocks.size()-1; count >= 0; count--){
|
||||
Block sblock = movedBlocks.get(count);
|
||||
Block dest = sblock.getRelative(event.getDirection());
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("PistionExtend moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation());
|
||||
|
||||
update.moveState(sblock, dest);
|
||||
}
|
||||
update.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPistionRetract(BlockPistonRetractEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getBlock().getWorld().getName()))
|
||||
return;
|
||||
event.getBlock().removeMetadata("LCBS_pistonIsAlreadyExtended", mod.getPlugin());
|
||||
|
||||
List<Block> movedBlocks = event.getBlocks();
|
||||
if(movedBlocks.size() > 0)
|
||||
{
|
||||
DBTransaction update = mod.getModel().groupUpdate();
|
||||
for(int count = movedBlocks.size()-1; count >= 0; count--){
|
||||
Block sblock = movedBlocks.get(count);
|
||||
Block dest = sblock.getRelative(event.getDirection());
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("PistionRetract moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation());
|
||||
|
||||
update.moveState(sblock, dest);
|
||||
}
|
||||
update.finish();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
//import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
//import javax.persistence.IdClass;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.avaje.ebean.validation.NotNull;
|
||||
|
||||
/**
|
||||
* @TODO: A Database Table-Generation based on Annotations (much work). all those Annotations here have not effect yet
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "block_state")
|
||||
//@IdClass(BlockLocation.class)
|
||||
public class BlockState {
|
||||
public static enum Source {
|
||||
SEED, // There is no way to determine this source, but lets be prepared for miracles ;)
|
||||
PLAYER,
|
||||
EDIT, // WorldEdit or MCEdit or such, we also can't determine that. But I keep believing in miracles
|
||||
COMMAND, // Manual Databse-Change via. BlockState-Command
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private Location location;
|
||||
|
||||
@Column(name = "gm")
|
||||
private GameMode gameMode;
|
||||
|
||||
@Column(name = "player")
|
||||
private UUID uuid;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "cdate")
|
||||
private Date date;
|
||||
|
||||
@NotNull
|
||||
private Source source = Source.UNKNOWN;
|
||||
|
||||
public BlockState() {
|
||||
}
|
||||
public BlockState(BlockState copy) {
|
||||
this.location = copy.location;
|
||||
this.gameMode = copy.gameMode;
|
||||
this.uuid = copy.uuid;
|
||||
this.date = copy.date;
|
||||
this.source = copy.source;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location loc) {
|
||||
location = loc;
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public void setGameMode(GameMode gm) {
|
||||
this.gameMode = gm;
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return Bukkit.getOfflinePlayer(uuid).getName();
|
||||
}
|
||||
|
||||
//TODO Rename
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setPlayerNameOrUUID(String s) {
|
||||
if(s==null)
|
||||
uuid=null;
|
||||
else if(!s.matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"))
|
||||
uuid = Bukkit.getOfflinePlayer(s).getUniqueId(); //If it's a name, get UUID
|
||||
else
|
||||
uuid = UUID.fromString(s);
|
||||
}
|
||||
|
||||
public OfflinePlayer getPlayer() {
|
||||
OfflinePlayer p = Bukkit.getPlayer(uuid);
|
||||
if (p == null)
|
||||
p = Bukkit.getOfflinePlayer(uuid);
|
||||
return p;
|
||||
}
|
||||
|
||||
public void setPlayer(OfflinePlayer player) {
|
||||
setSource(Source.PLAYER);
|
||||
this.uuid = player.getUniqueId();
|
||||
if (player instanceof Player) {
|
||||
setGameMode(((Player) player).getGameMode());
|
||||
}
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Source getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Source source) {
|
||||
if (source != Source.PLAYER && source != Source.EDIT && source != Source.COMMAND)
|
||||
setPlayerNameOrUUID(null);
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public boolean isRestricted() {
|
||||
return this.getGameMode() == GameMode.CREATIVE || this.getSource() == Source.EDIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String playerName = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
//return blockLocation.toString() + " by " +
|
||||
return location.toString() + " by " +
|
||||
(source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) +
|
||||
(gameMode != null ? "" : (" in GM: " + gameMode)) +
|
||||
" at " + date.toString();
|
||||
}
|
||||
}
|
|
@ -1,285 +0,0 @@
|
|||
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(), () -> {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,203 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.bukkit.lib.configuration.StringList;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Config;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
|
||||
/**
|
||||
* BlockState-Feature
|
||||
*
|
||||
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/blockstate/
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = Config.class)
|
||||
public class BlockStateConfig extends Configuration implements IConfigurationSubGroup {
|
||||
protected ModBlockStates mod;
|
||||
protected ModuleEntry<IModule> entry;
|
||||
|
||||
public BlockStateConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public BlockStateConfig(ModBlockStates mod, ModuleEntry<IModule> modEntry) {
|
||||
super(mod.getPlugin().getDocCommentStorage());
|
||||
this.mod = mod;
|
||||
entry = modEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
|
||||
if (node.getName().equals("tool"))
|
||||
setTool(pValue);
|
||||
else
|
||||
super.setValue(node, pValue);
|
||||
if (node.getName().equals("enabled")) {
|
||||
entry.setEnabled(getEnabled());
|
||||
} else if (node.getName().equals("useThreading")) {
|
||||
if (entry.isEnabled()) {
|
||||
entry.disable();
|
||||
entry.enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(ConfigurationSection sect) {
|
||||
ignoredWorlds = null;
|
||||
super.setValues(sect);
|
||||
entry.setDefaultEnabled(getEnabled());
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "blockstate";
|
||||
}
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 700;
|
||||
}
|
||||
|
||||
/**
|
||||
* BlockStateEnabled
|
||||
*
|
||||
* This Feature stores the GameMode a Block was created in, and prevents drops if a Block was created
|
||||
* in creative mode.
|
||||
*
|
||||
* Due to the huge load of this Feature, it isn't enabled by default. It uses the Database-credentials from
|
||||
* bukkit.yml (http://wiki.bukkit.org/Bukkit.yml#database) in the server-directory.
|
||||
*
|
||||
* default: false
|
||||
*/
|
||||
@IsConfigurationNode(order = 100)
|
||||
public boolean getEnabled() {
|
||||
return config.getBoolean("enabled", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* BlockStateThreading
|
||||
*
|
||||
* Uses Threading to minimize lag. This fully relies on Bukkit metadata implementation. You only should need this,
|
||||
* if there are often plays more then 10 players at once on your server, or you're about to use huge WorldEdits often.
|
||||
* Be aware that this requires more memory, to increase the performance
|
||||
*
|
||||
* Without threading, huge WorldEdits becomes much noticeable slower.
|
||||
*
|
||||
* default: true
|
||||
*/
|
||||
@IsConfigurationNode(order = 150)
|
||||
public boolean getUseThreading() {
|
||||
return config.getBoolean("useThreading", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* BlockStateTool
|
||||
*
|
||||
* The id or technical name (http://public.ja-s.de/bukkit/material) of an item that displays information about the
|
||||
* right-clicked block.
|
||||
*
|
||||
* default: WOOD_PICKAXE
|
||||
*/
|
||||
@IsConfigurationNode(order = 200)
|
||||
public Material getTool() {
|
||||
if (config.isString("tool")) {
|
||||
Material v = Material.getMaterial(config.getString("tool"));
|
||||
if (v != null)
|
||||
return v;
|
||||
} else if (config.isInt("tool")) {
|
||||
Material v = Material.getMaterial(config.getInt("tool"));
|
||||
if (v != null)
|
||||
return v;
|
||||
} else {
|
||||
Object v = config.get("tool", Material.WOOD_PICKAXE);
|
||||
if (v instanceof Material)
|
||||
return (Material) v;
|
||||
}
|
||||
mod.getLog().warn("Unknown BlockStateTool: " + config.get("tool"));
|
||||
return Material.WOOD_PICKAXE;
|
||||
}
|
||||
|
||||
/**
|
||||
* BlockStateLogSurvival
|
||||
*
|
||||
* Log all Block-Places to the database. Disable to make the database more slim by not adding blocks placed in
|
||||
* survival-mode.
|
||||
*
|
||||
* default: false
|
||||
*/
|
||||
@IsConfigurationNode(order = 400)
|
||||
public boolean getLogSurvival() {
|
||||
return config.getBoolean("logSurvival", false);
|
||||
}
|
||||
|
||||
private StringList ignoredWorlds = null;
|
||||
|
||||
/**
|
||||
* BlockStateIgnoredWorlds
|
||||
*
|
||||
* While you may use per world permissions to configure limitations fine graded, you may want to disable the
|
||||
* BlockState-Feature for certain worlds (like complete creative worlds) to save cpu and memory.
|
||||
*
|
||||
* default: []
|
||||
*/
|
||||
@IsConfigurationNode(order = 500)
|
||||
public StringList getIgnoredWorlds() {
|
||||
if (ignoredWorlds == null) {
|
||||
ignoredWorlds = new StringList(config.getStringList("ignoredWorlds"));
|
||||
}
|
||||
return ignoredWorlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* BlockStateWorldEditIntegration
|
||||
*
|
||||
* Allows you to disable hook into WorldEdit for better Performance. By default Integration is enable, so it logs
|
||||
* block modifications via worldedit as creative-placed blocks in the database.
|
||||
* A server reload (better restart) is needed to disabled WE-Integration.
|
||||
*
|
||||
* default: true
|
||||
*/
|
||||
@IsConfigurationNode(order = 600)
|
||||
public boolean getWorldeditIntegration() {
|
||||
return config.getBoolean("worldeditIntegration", true);
|
||||
}
|
||||
|
||||
protected void setTool(Object val) throws InvalidValueException {
|
||||
String v = (String) val;
|
||||
Material m = null;
|
||||
try {
|
||||
int i = Integer.parseInt(v);
|
||||
if (i > 0)
|
||||
m = Material.getMaterial(i);
|
||||
} catch (NumberFormatException e) {
|
||||
m = null;
|
||||
}
|
||||
if (m == null)
|
||||
m = Material.getMaterial(v);
|
||||
if (m == null)
|
||||
throw new InvalidValueException("Material '" + v + "' not found");
|
||||
else
|
||||
config.set("tool", m);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getValue(final IConfigurationNode node) {
|
||||
Object val = super.getValue(node);
|
||||
if (node.getName().equals("tool") && val != null) {
|
||||
return val.toString();
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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.blockstate;
|
||||
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermissionContainer;
|
||||
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainerNode;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Permissions;
|
||||
|
||||
@ArchiveDocComments
|
||||
public class BlockStatePermissions extends SimplePermissionContainerNode {
|
||||
public BlockStatePermissions(IAbstractPermission parent, String name) {
|
||||
super(parent, name);
|
||||
}
|
||||
|
||||
@PluginPermissions
|
||||
public static final IPermissionContainer PARENT = new BlockStatePermissions(Permissions.CONTAINER, "blockstate");
|
||||
|
||||
/**
|
||||
* Grants ability to use the configured tool to get info about placed blocks.
|
||||
*/
|
||||
public static final IPermission TOOL = new BasicPermission(PARENT, "tool", PermissionDefault.OP);
|
||||
|
||||
/**
|
||||
* Grants access to the blockstate admin command to modify the database.
|
||||
*/
|
||||
public static final IPermission COMMAND = new BasicPermission(PARENT, "command", PermissionDefault.OP);
|
||||
|
||||
/**
|
||||
* Allows to get drops even if a block was created from a creative player or WorldEdit.
|
||||
*/
|
||||
public static final IPermission BYPASS = new BasicPermission(PARENT, "bypass", PermissionDefault.FALSE);
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
|
||||
import de.jaschastarke.bukkit.lib.commands.CommandContext;
|
||||
import de.jaschastarke.bukkit.lib.database.ResultIterator;
|
||||
import de.jaschastarke.database.db.Database;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
|
||||
|
||||
public class CreativeControlImportThread extends DatabaseMigrationThread {
|
||||
public CreativeControlImportThread(ModBlockStates mod, CommandContext context, Database source, Database target) {
|
||||
super(mod, context, source, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!target.isInTransaction())
|
||||
target.startTransaction();
|
||||
|
||||
int rowCount = 0;
|
||||
Connection sourceConnection = source.getConnection();
|
||||
Connection targetConnection = target.getConnection();
|
||||
|
||||
if (mode == Mode.REPLACE) {
|
||||
targetConnection.createStatement().execute("DELETE FROM lc_block_state");
|
||||
}
|
||||
|
||||
DBQueries targetDB = new DBQueries(this, target);
|
||||
|
||||
List<WorldSize> worldBounds = new ArrayList<WorldSize>();
|
||||
for (World w : mod.getPlugin().getServer().getWorlds()) {
|
||||
try {
|
||||
ResultSet fetchBounds = sourceConnection.createStatement().executeQuery("SELECT MIN(x), MIN(z), MAX(x), MAX(z) FROM crcr_blocks_" + w.getName());
|
||||
while (fetchBounds.next()) {
|
||||
worldBounds.add(new WorldSize(w,
|
||||
fetchBounds.getInt(1),
|
||||
fetchBounds.getInt(2),
|
||||
fetchBounds.getInt(3),
|
||||
fetchBounds.getInt(4)));
|
||||
}
|
||||
fetchBounds.close();
|
||||
} catch (SQLException e) {
|
||||
if (isDebug())
|
||||
mod.getLog().debug("crcr_blocks_" + w.getName() + " not found: " + e.getMessage());
|
||||
mod.getLog().info("CreativeControl has BlockData for World " + w.getName());
|
||||
}
|
||||
}
|
||||
|
||||
for (WorldSize bounds : worldBounds) {
|
||||
World world = mod.getPlugin().getServer().getWorld(bounds.getWorld());
|
||||
if (world != null) {
|
||||
long time = System.currentTimeMillis();
|
||||
int itCount = 0;
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Processing world " + world.getName() + " with bounds: " + bounds);
|
||||
|
||||
for (int x = bounds.getMinX(); x <= bounds.getMaxX(); x += CHUNK_SIZE + 1) {
|
||||
for (int z = bounds.getMinZ(); z <= bounds.getMaxZ(); z += CHUNK_SIZE + 1) {
|
||||
Cuboid c = new Cuboid();
|
||||
c.add(new Location(world, x, 0, z));
|
||||
c.add(new Location(world, x + CHUNK_SIZE, world.getMaxHeight(), z + CHUNK_SIZE));
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Fetching Cuboid: " + c.toString());
|
||||
|
||||
for (BlockState bs : iterateAllIn(c)) {
|
||||
if (mode == Mode.UPDATE) {
|
||||
BlockState xs = targetDB.find(bs.getLocation());
|
||||
if (xs == null) {
|
||||
targetDB.insert(bs);
|
||||
} else if (xs.getDate().before(bs.getDate())) {
|
||||
targetDB.update(bs);
|
||||
}
|
||||
} else {
|
||||
targetDB.insert(bs);
|
||||
}
|
||||
rowCount++;
|
||||
itCount++;
|
||||
}
|
||||
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
String region = "Region{world = " + world.getName() + ", x = [" + bounds.getMinX() + "; " + (bounds.getMinX() + CHUNK_SIZE) + "], z = [" + bounds.getMinZ() + "; " + (bounds.getMinZ() + CHUNK_SIZE) + "]}";
|
||||
mod.getLog().info("Migration processed " + itCount + " BlockStates in " + region + " within " + ((System.currentTimeMillis() - time) / 1000.0) + " seconds");
|
||||
}
|
||||
}
|
||||
|
||||
target.endTransaction();
|
||||
context.responseFormatted(ChatFormattings.SUCCESS, L("command.blockstate.migration_finished", rowCount) + " " +
|
||||
context.getFormatter().formatString(ChatFormattings.ERROR, L("command.blockstate.migration_finished_restart")));
|
||||
} catch (SQLException e) {
|
||||
try {
|
||||
target.revertTransaction();
|
||||
} catch (SQLException e1) {}
|
||||
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migration_error", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement findall = null;
|
||||
private Iterable<BlockState> iterateAllIn(final DBModel.Cuboid c) throws SQLException {
|
||||
if (isDebug())
|
||||
getLog().debug("DBQuery: iterateAllIn: " + c.toString());
|
||||
if (findall == null) {
|
||||
findall = source.prepare("SELECT * FROM crcr_blocks_" + c.getWorld().getName() + " LEFT JOIN crcr_players ON owner = id WHERE x >= ? AND x <= ? AND y >= ? AND y <= ? AND z >= ? AND z <= ?");
|
||||
}
|
||||
findall.setInt(1, c.getMinX());
|
||||
findall.setInt(2, c.getMaxX());
|
||||
findall.setInt(3, c.getMinY());
|
||||
findall.setInt(4, c.getMaxY());
|
||||
findall.setInt(5, c.getMinZ());
|
||||
findall.setInt(6, c.getMaxZ());
|
||||
ResultSet rs = findall.executeQuery();
|
||||
return new ResultIterator<BlockState>(rs) {
|
||||
@Override
|
||||
protected BlockState fetch(ResultSet rs) throws SQLException {
|
||||
BlockState bs = new BlockState();
|
||||
bs.setLocation(new Location(c.getWorld(), rs.getInt("x"), rs.getInt("y"), rs.getInt("z")));
|
||||
bs.setDate(new Date(rs.getLong("time")));
|
||||
bs.setGameMode(GameMode.CREATIVE);
|
||||
bs.setPlayerNameOrUUID(rs.getString("player"));
|
||||
bs.setSource(Source.PLAYER);
|
||||
return bs;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public interface DBModel {
|
||||
public static class Cuboid {
|
||||
private World w = null;
|
||||
private int minx, miny, minz;
|
||||
private int maxx, maxy, maxz;
|
||||
public void add(Location loc) {
|
||||
if (w == null) {
|
||||
w = loc.getWorld();
|
||||
minx = maxx = loc.getBlockX();
|
||||
miny = maxy = loc.getBlockY();
|
||||
minz = maxz = loc.getBlockZ();
|
||||
} else {
|
||||
if (w != loc.getWorld())
|
||||
throw new IllegalArgumentException("Point is from a different world");
|
||||
if (minx > loc.getBlockX())
|
||||
minx = loc.getBlockX();
|
||||
if (maxx < loc.getBlockX())
|
||||
maxx = loc.getBlockX();
|
||||
if (miny > loc.getBlockY())
|
||||
miny = loc.getBlockY();
|
||||
if (maxy < loc.getBlockY())
|
||||
maxy = loc.getBlockY();
|
||||
if (minz > loc.getBlockZ())
|
||||
minz = loc.getBlockZ();
|
||||
if (maxz < loc.getBlockZ())
|
||||
maxz = loc.getBlockZ();
|
||||
}
|
||||
}
|
||||
public int getMinX() {
|
||||
return minx;
|
||||
}
|
||||
public int getMinY() {
|
||||
return miny;
|
||||
}
|
||||
public int getMinZ() {
|
||||
return minz;
|
||||
}
|
||||
public int getMaxX() {
|
||||
return maxx;
|
||||
}
|
||||
public int getMaxY() {
|
||||
return maxy;
|
||||
}
|
||||
public int getMaxZ() {
|
||||
return maxz;
|
||||
}
|
||||
public World getWorld() {
|
||||
return w;
|
||||
}
|
||||
public boolean isEmpty() {
|
||||
return w == null;
|
||||
}
|
||||
public String toString() {
|
||||
return "Cuboid{world="+w.getName()+", min_x="+minx+", max_x="+maxx+", min_y="+miny+", max_y="+maxy+", min_z="+minz+", max_z="+maxz+"}";
|
||||
}
|
||||
}
|
||||
|
||||
public enum Cleanup {
|
||||
SURVIVAL;
|
||||
}
|
||||
|
||||
public void onEnable() throws Exception;
|
||||
public void onDisable();
|
||||
public void moveState(Block from, Block to);
|
||||
public void removeState(BlockState state);
|
||||
public void removeState(Block block);
|
||||
public Map<Block, BlockState> getStates(List<Block> blocks);
|
||||
public Map<Block, Boolean> getRestrictedStates(List<Block> blocks);
|
||||
public void cacheStates(DBModel.Cuboid c);
|
||||
public BlockState getState(Block block);
|
||||
public boolean isRestricted(Block block);
|
||||
public void setState(BlockState state);
|
||||
public DBTransaction groupUpdate();
|
||||
|
||||
public static interface DBTransaction {
|
||||
public void moveState(Block from, Block to);
|
||||
public void setState(BlockState state);
|
||||
public void removeState(Block block);
|
||||
public void finish();
|
||||
}
|
||||
|
||||
public int cleanUp(Cleanup target);
|
||||
}
|
|
@ -1,324 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.database.ResultIterator;
|
||||
import de.jaschastarke.database.Type;
|
||||
import de.jaschastarke.database.db.Database;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cleanup;
|
||||
import de.jaschastarke.utils.IDebugLogHolder;
|
||||
|
||||
public class DBQueries {
|
||||
private Database db;
|
||||
private IDebugLogHolder dbg;
|
||||
public DBQueries(IDebugLogHolder mod, Database db) {
|
||||
this.dbg = mod;
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
private PreparedStatement find = null;
|
||||
public BlockState find(Location loc) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: find: " + loc.toString());
|
||||
if (find == null) {
|
||||
find = db.prepare("SELECT * FROM lc_block_state WHERE x = ? AND y = ? AND z = ? AND world = ?");
|
||||
}
|
||||
find.setInt(1, loc.getBlockX());
|
||||
find.setInt(2, loc.getBlockY());
|
||||
find.setInt(3, loc.getBlockZ());
|
||||
find.setString(4, loc.getWorld().getUID().toString());
|
||||
ResultSet rs = find.executeQuery();
|
||||
if (rs.next()) {
|
||||
BlockState bs = new BlockState();
|
||||
bs.setLocation(loc);
|
||||
bs.setDate(rs.getTimestamp("cdate"));
|
||||
bs.setGameMode(getGameMode(rs));
|
||||
bs.setPlayerNameOrUUID(rs.getString("player"));
|
||||
bs.setSource(getSource(rs));
|
||||
rs.close();
|
||||
return bs;
|
||||
}
|
||||
rs.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
private PreparedStatement findall = null;
|
||||
public List<BlockState> findAllIn(DBModel.Cuboid c) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: findAllIn: " + c.toString());
|
||||
List<BlockState> blocks = new ArrayList<BlockState>();
|
||||
if (findall == null) {
|
||||
findall = db.prepare("SELECT * FROM lc_block_state WHERE x >= ? AND x <= ? AND y >= ? AND y <= ? AND z >= ? AND z <= ? AND world = ?");
|
||||
}
|
||||
findall.setInt(1, c.getMinX());
|
||||
findall.setInt(2, c.getMaxX());
|
||||
findall.setInt(3, c.getMinY());
|
||||
findall.setInt(4, c.getMaxY());
|
||||
findall.setInt(5, c.getMinZ());
|
||||
findall.setInt(6, c.getMaxZ());
|
||||
findall.setString(7, c.getWorld().getUID().toString());
|
||||
ResultSet rs = findall.executeQuery();
|
||||
while (rs.next()) {
|
||||
BlockState bs = new BlockState();
|
||||
bs.setLocation(new Location(c.getWorld(), rs.getInt("x"), rs.getInt("y"), rs.getInt("z")));
|
||||
bs.setDate(rs.getTimestamp("cdate"));
|
||||
bs.setGameMode(getGameMode(rs));
|
||||
bs.setPlayerNameOrUUID(rs.getString("player"));
|
||||
bs.setSource(getSource(rs));
|
||||
blocks.add(bs);
|
||||
}
|
||||
rs.close();
|
||||
return blocks;
|
||||
}
|
||||
public Iterable<BlockState> iterateAllIn(final DBModel.Cuboid c) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: iterateAllIn: " + c.toString());
|
||||
if (findall == null) {
|
||||
findall = db.prepare("SELECT * FROM lc_block_state WHERE x >= ? AND x <= ? AND y >= ? AND y <= ? AND z >= ? AND z <= ? AND world = ?");
|
||||
}
|
||||
findall.setInt(1, c.getMinX());
|
||||
findall.setInt(2, c.getMaxX());
|
||||
findall.setInt(3, c.getMinY());
|
||||
findall.setInt(4, c.getMaxY());
|
||||
findall.setInt(5, c.getMinZ());
|
||||
findall.setInt(6, c.getMaxZ());
|
||||
findall.setString(7, c.getWorld().getUID().toString());
|
||||
ResultSet rs = findall.executeQuery();
|
||||
return new ResultIterator<BlockState>(rs) {
|
||||
@Override
|
||||
protected BlockState fetch(ResultSet rs) throws SQLException {
|
||||
BlockState bs = new BlockState();
|
||||
bs.setLocation(new Location(c.getWorld(), rs.getInt("x"), rs.getInt("y"), rs.getInt("z")));
|
||||
bs.setDate(rs.getTimestamp("cdate"));
|
||||
bs.setGameMode(getGameMode(rs));
|
||||
bs.setPlayerNameOrUUID(rs.getString("player"));
|
||||
bs.setSource(getSource(rs));
|
||||
return bs;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private PreparedStatement delete = null;
|
||||
public boolean delete(BlockState s) throws SQLException {
|
||||
return delete(s.getLocation());
|
||||
}
|
||||
public boolean delete(Location loc) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: delete: " + loc.toString());
|
||||
if (delete == null) {
|
||||
delete = db.prepare("DELETE FROM lc_block_state WHERE x = ? AND y = ? AND z = ? AND world = ?");
|
||||
}
|
||||
delete.setInt(1, loc.getBlockX());
|
||||
delete.setInt(2, loc.getBlockY());
|
||||
delete.setInt(3, loc.getBlockZ());
|
||||
delete.setString(4, loc.getWorld().getUID().toString());
|
||||
return delete.executeUpdate() > 0;
|
||||
}
|
||||
|
||||
private PreparedStatement update = null;
|
||||
public boolean update(BlockState s) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: update: " + s.toString());
|
||||
if (update == null) {
|
||||
update = db.prepare("UPDATE lc_block_state SET gm = ?, player = ?, cdate = ?, source = ?"+
|
||||
"WHERE x = ? AND y = ? AND z = ? AND world = ? ");
|
||||
}
|
||||
if (s.getGameMode() == null)
|
||||
update.setNull(1, Types.INTEGER);
|
||||
else if (db.getType() == Type.MySQL)
|
||||
update.setString(1, s.getGameMode().name());
|
||||
else
|
||||
update.setInt(1, s.getGameMode().getValue());
|
||||
update.setString(2, s.getPlayerUUID().toString());
|
||||
update.setTimestamp(3, new java.sql.Timestamp(s.getDate().getTime()));
|
||||
if (db.getType() == Type.MySQL)
|
||||
update.setString(4, s.getSource().name());
|
||||
else
|
||||
update.setInt(4, s.getSource().ordinal());
|
||||
update.setInt(5, s.getLocation().getBlockX());
|
||||
update.setInt(6, s.getLocation().getBlockY());
|
||||
update.setInt(7, s.getLocation().getBlockZ());
|
||||
update.setString(8, s.getLocation().getWorld().getUID().toString());
|
||||
return update.executeUpdate() > 0;
|
||||
}
|
||||
|
||||
private PreparedStatement move = null;
|
||||
public boolean move(BlockState s, Location newLoc) throws SQLException {
|
||||
boolean r = move(s.getLocation(), newLoc);
|
||||
if (r)
|
||||
s.setLocation(newLoc);
|
||||
return r;
|
||||
}
|
||||
|
||||
public boolean move(Location oldLoc, Location newLoc) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: move: " + oldLoc.toString() + ", " + newLoc.toString());
|
||||
if (move == null) {
|
||||
move = db.prepare("UPDATE lc_block_state SET x = ?, y = ?, z = ? "+
|
||||
"WHERE x = ? AND y = ? AND z = ? AND world = ?");
|
||||
}
|
||||
|
||||
move.setInt(1, newLoc.getBlockX());
|
||||
move.setInt(2, newLoc.getBlockY());
|
||||
move.setInt(3, newLoc.getBlockZ());
|
||||
move.setInt(4, oldLoc.getBlockX());
|
||||
move.setInt(5, oldLoc.getBlockY());
|
||||
move.setInt(6, oldLoc.getBlockZ());
|
||||
move.setString(7, oldLoc.getWorld().getUID().toString());
|
||||
|
||||
return move.executeUpdate() > 0;
|
||||
}
|
||||
|
||||
/*private PreparedStatement replace = null;
|
||||
public boolean replace(BlockState s) throws SQLException {
|
||||
if (replace == null) {
|
||||
replace = db.prepare("INSERT OR REPLACE INTO lc_block_state (x, y, z, world, gm, player, cdate, source)"+
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
}
|
||||
return this._executeInsert(replace, s);
|
||||
}*/
|
||||
private PreparedStatement insert = null;
|
||||
public boolean insert(BlockState s) throws SQLException {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: insert: " + s.toString());
|
||||
if (insert == null) {
|
||||
insert = db.prepare("INSERT INTO lc_block_state (x, y, z, world, gm, player, cdate, source)"+
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
}
|
||||
return this._executeInsert(insert, s);
|
||||
}
|
||||
private boolean _executeInsert(PreparedStatement insert, BlockState s) throws SQLException {
|
||||
insert.setInt(1, s.getLocation().getBlockX());
|
||||
insert.setInt(2, s.getLocation().getBlockY());
|
||||
insert.setInt(3, s.getLocation().getBlockZ());
|
||||
insert.setString(4, s.getLocation().getWorld().getUID().toString());
|
||||
if (s.getGameMode() == null)
|
||||
insert.setNull(5, Types.INTEGER);
|
||||
else if (db.getType() == Type.MySQL)
|
||||
insert.setString(5, s.getGameMode().name());
|
||||
else
|
||||
insert.setInt(5, s.getGameMode().getValue());
|
||||
insert.setString(6, s.getPlayerUUID().toString());
|
||||
insert.setTimestamp(7, new java.sql.Timestamp(s.getDate().getTime()));
|
||||
if (db.getType() == Type.MySQL)
|
||||
insert.setString(8, s.getSource().name());
|
||||
else
|
||||
insert.setInt(8, s.getSource().ordinal());
|
||||
return insert.executeUpdate() > 0;
|
||||
}
|
||||
|
||||
private GameMode getGameMode(ResultSet rs) {
|
||||
try {
|
||||
switch (db.getType()) {
|
||||
case SQLite:
|
||||
int gm = rs.getInt("gm");
|
||||
if (rs.wasNull())
|
||||
return null;
|
||||
return GameMode.getByValue(gm);
|
||||
case MySQL:
|
||||
if (rs.getString("gm") == null)
|
||||
return null;
|
||||
return GameMode.valueOf(rs.getString("gm"));
|
||||
default:
|
||||
throw new RuntimeException("Unsupported Database-Type.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
db.getLogger().warn("Couldn't get GameMode from result-set: "+e.getMessage());
|
||||
return GameMode.SURVIVAL;
|
||||
}
|
||||
}
|
||||
|
||||
private Source getSource(ResultSet rs) {
|
||||
try {
|
||||
switch (db.getType()) {
|
||||
case SQLite:
|
||||
return Source.values()[rs.getInt("source")];
|
||||
case MySQL:
|
||||
return Source.valueOf(rs.getString("source"));
|
||||
default:
|
||||
throw new RuntimeException("Unsupported Database-Type.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
db.getLogger().warn("Couldn't get Source from result-set: "+e.getMessage());
|
||||
return Source.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public void initTable() throws SQLException {
|
||||
switch (db.getType()) {
|
||||
case SQLite:
|
||||
if (!db.getDDL().tableExists("lc_block_state")) {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: initTable SQLite: lc_block_state");
|
||||
db.execute(
|
||||
"CREATE TABLE lc_block_state ("+
|
||||
"x integer,"+
|
||||
"y integer,"+
|
||||
"z integer,"+
|
||||
"world varchar(40),"+
|
||||
"gm integer,"+
|
||||
"player varchar(255),"+
|
||||
"cdate timestamp not null,"+
|
||||
"source integer not null,"+
|
||||
"primary key (x, y, z, world),"+
|
||||
"constraint ck_lc_block_state_gm check (gm in (0,1,2)),"+
|
||||
"constraint ck_lc_block_state_source check (source in (0,1,2,3,4))"+
|
||||
")"
|
||||
).close();
|
||||
db.getLogger().info("Created SQLite-Table: lc_block_state");
|
||||
}
|
||||
break;
|
||||
case MySQL:
|
||||
if (!db.getDDL().tableExists("lc_block_state")) {
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: initTable MySQL: lc_block_state");
|
||||
db.execute(
|
||||
"CREATE TABLE IF NOT EXISTS lc_block_state ("+
|
||||
"x INT NOT NULL,"+
|
||||
"y INT NOT NULL,"+
|
||||
"z INT NOT NULL,"+
|
||||
"world VARCHAR(40) NOT NULL,"+
|
||||
"gm ENUM('CREATIVE', 'SURVIVAL', 'ADVENTURE'),"+
|
||||
"player VARCHAR(255),"+
|
||||
"cdate TIMESTAMP NOT NULL,"+
|
||||
"source ENUM('SEED','PLAYER','EDIT','COMMAND','UNKNOWN') NOT NULL,"+
|
||||
"PRIMARY KEY (x, y, z, world)"+
|
||||
")"
|
||||
).close();
|
||||
db.getLogger().info("Created MySQL-Table: lc_block_state");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Currently only SQLite or MySQL is supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public int cleanup(Cleanup q) throws SQLException {
|
||||
PreparedStatement delete;
|
||||
if (dbg.isDebug())
|
||||
dbg.getLog().debug("DBQuery: cleanup: " + q.toString());
|
||||
if (q == Cleanup.SURVIVAL) {
|
||||
delete = db.prepare("DELETE FROM lc_block_state WHERE gm = ?");
|
||||
if (db.getType() == Type.MySQL)
|
||||
delete.setString(1, GameMode.SURVIVAL.name());
|
||||
else
|
||||
delete.setInt(1, GameMode.SURVIVAL.getValue());
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return delete.executeUpdate();
|
||||
}
|
||||
|
||||
public Database getDB() {
|
||||
return db;
|
||||
}
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
|
||||
import de.jaschastarke.bukkit.lib.commands.CommandContext;
|
||||
import de.jaschastarke.database.db.Database;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
|
||||
import de.jaschastarke.utils.IDebugLogHolder;
|
||||
import de.jaschastarke.utils.ISimpleLogger;
|
||||
|
||||
public class DatabaseMigrationThread extends Thread implements IDebugLogHolder {
|
||||
protected static final int CHUNK_SIZE = 512;
|
||||
protected ModBlockStates mod;
|
||||
protected CommandContext context;
|
||||
protected Database source;
|
||||
protected Database target;
|
||||
protected Mode mode = Mode.REPLACE;
|
||||
private boolean debug = false;
|
||||
|
||||
public static enum Mode {
|
||||
REPLACE,
|
||||
UPDATE
|
||||
}
|
||||
|
||||
public DatabaseMigrationThread(ModBlockStates mod, CommandContext context, Database source, Database target) {
|
||||
this.mod = mod;
|
||||
this.context = context;
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
setName("LC BlockState Database-Migration");
|
||||
setPriority(MIN_PRIORITY);
|
||||
}
|
||||
|
||||
public Mode getMode() {
|
||||
return mode;
|
||||
}
|
||||
public void setMode(Mode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISimpleLogger getLog() {
|
||||
return mod.getLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!target.isInTransaction())
|
||||
target.startTransaction();
|
||||
|
||||
int rowCount = 0;
|
||||
Connection sourceConnection = source.getConnection();
|
||||
Connection targetConnection = target.getConnection();
|
||||
|
||||
if (mode == Mode.REPLACE) {
|
||||
targetConnection.createStatement().execute("DELETE FROM lc_block_state");
|
||||
}
|
||||
|
||||
DBQueries sourceDB = new DBQueries(this, source);
|
||||
DBQueries targetDB = new DBQueries(this, target);
|
||||
|
||||
List<WorldSize> worldBounds = new ArrayList<WorldSize>();
|
||||
ResultSet fetchBounds = sourceConnection.createStatement().executeQuery("SELECT world, MIN(x), MIN(z), MAX(x), MAX(z) FROM lc_block_state GROUP BY world");
|
||||
while (fetchBounds.next()) {
|
||||
worldBounds.add(new WorldSize(fetchBounds.getString("world"),
|
||||
fetchBounds.getInt(2),
|
||||
fetchBounds.getInt(3),
|
||||
fetchBounds.getInt(4),
|
||||
fetchBounds.getInt(5)));
|
||||
}
|
||||
fetchBounds.close();
|
||||
|
||||
for (WorldSize bounds : worldBounds) {
|
||||
World world = mod.getPlugin().getServer().getWorld(bounds.getWorld());
|
||||
if (world != null) {
|
||||
long time = System.currentTimeMillis();
|
||||
int itCount = 0;
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Processing world " + world.getName() + " with bounds: " + bounds);
|
||||
|
||||
for (int x = bounds.getMinX(); x <= bounds.getMaxX(); x += CHUNK_SIZE + 1) {
|
||||
for (int z = bounds.getMinZ(); z <= bounds.getMaxZ(); z += CHUNK_SIZE + 1) {
|
||||
Cuboid c = new Cuboid();
|
||||
c.add(new Location(world, x, 0, z));
|
||||
c.add(new Location(world, x + CHUNK_SIZE, world.getMaxHeight(), z + CHUNK_SIZE));
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Fetching Cuboid: " + c.toString());
|
||||
|
||||
for (BlockState bs : sourceDB.iterateAllIn(c)) {
|
||||
if (mode == Mode.UPDATE) {
|
||||
BlockState xs = targetDB.find(bs.getLocation());
|
||||
if (xs == null) {
|
||||
targetDB.insert(bs);
|
||||
} else if (xs.getDate().before(bs.getDate())) {
|
||||
targetDB.update(bs);
|
||||
}
|
||||
} else {
|
||||
targetDB.insert(bs);
|
||||
}
|
||||
rowCount++;
|
||||
itCount++;
|
||||
}
|
||||
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
String region = "Region{world = " + world.getName() + ", x = [" + bounds.getMinX() + "; " + (bounds.getMinX() + CHUNK_SIZE) + "], z = [" + bounds.getMinZ() + "; " + (bounds.getMinZ() + CHUNK_SIZE) + "]}";
|
||||
mod.getLog().info("Migration processed " + itCount + " BlockStates in " + region + " within " + ((System.currentTimeMillis() - time) / 1000.0) + " seconds");
|
||||
}
|
||||
}
|
||||
|
||||
target.endTransaction();
|
||||
context.responseFormatted(ChatFormattings.SUCCESS, L("command.blockstate.migration_finished", rowCount) + " " +
|
||||
context.getFormatter().formatString(ChatFormattings.ERROR, L("command.blockstate.migration_finished_restart")));
|
||||
} catch (SQLException e) {
|
||||
try {
|
||||
target.revertTransaction();
|
||||
} catch (SQLException e1) {}
|
||||
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migration_error", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
protected String L(String msg, Object... args) {
|
||||
return mod.getPlugin().getLocale().trans(msg, args);
|
||||
}
|
||||
|
||||
protected static class WorldSize {
|
||||
UUID w;
|
||||
int minX, minZ, maxX, maxZ;
|
||||
|
||||
public WorldSize(String w, int minX, int minZ, int maxX, int maxZ) {
|
||||
this.w = UUID.fromString(w);
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
public WorldSize(World w, int minX, int minZ, int maxX, int maxZ) {
|
||||
this.w = w.getUID();
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
this.maxX = maxX;
|
||||
this.maxZ = maxZ;
|
||||
}
|
||||
public String toString() {
|
||||
World world = Bukkit.getServer().getWorld(w);
|
||||
String wn = world == null ? w.toString() : world.getName();
|
||||
return getClass().getSimpleName() + "{world = " + wn + ", minX = " + minX + ", minZ = " + minZ + ", maxX = " + maxX + ", maxZ = " + maxZ + "}";
|
||||
}
|
||||
public UUID getWorld() {
|
||||
return w;
|
||||
}
|
||||
public int getMinX() {
|
||||
return minX;
|
||||
}
|
||||
public int getMinZ() {
|
||||
return minZ;
|
||||
}
|
||||
public int getMaxX() {
|
||||
return maxX;
|
||||
}
|
||||
public int getMaxZ() {
|
||||
return maxZ;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
|
||||
public class HangingStandingListener implements Listener {
|
||||
private ModBlockStates mod;
|
||||
public HangingStandingListener(ModBlockStates mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getRightClicked().getWorld().getName()))
|
||||
return;
|
||||
if (event.getRightClicked() instanceof ItemFrame) {
|
||||
if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Modifying hanging: " + event.getRightClicked().getLocation().toString());
|
||||
|
||||
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("... was placed by creative. Modify prevented");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
BlockState s = new BlockState();
|
||||
s.setLocation(event.getRightClicked().getLocation().getBlock().getLocation());
|
||||
s.setPlayer(event.getPlayer());
|
||||
s.setDate(new Date());
|
||||
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
||||
|
||||
mod.getModel().setState(s);
|
||||
}
|
||||
} else if (event.getRightClicked() instanceof ArmorStand) {
|
||||
if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Modifying standing: " + event.getRightClicked().getLocation().toString());
|
||||
|
||||
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("... was placed by creative. Modify prevented");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
BlockState s = new BlockState();
|
||||
s.setLocation(event.getRightClicked().getLocation().getBlock().getLocation());
|
||||
s.setPlayer(event.getPlayer());
|
||||
s.setDate(new Date());
|
||||
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
||||
|
||||
mod.getModel().setState(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
|
||||
onPlayerInteractEntity(event);
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onArmorStandManipulateEvent(PlayerArmorStandManipulateEvent event) {
|
||||
onPlayerInteractEntity(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
|
||||
return;
|
||||
if (event.getDamager() instanceof Player && event.getEntity() instanceof ItemFrame) {
|
||||
if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Modifying hanging: " + event.getEntity().getLocation().toString());
|
||||
|
||||
if (((Player) event.getDamager()).getGameMode() != GameMode.CREATIVE) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("... was placed by creative. Modify prevented");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
BlockState s = new BlockState();
|
||||
s.setLocation(event.getEntity().getLocation().getBlock().getLocation());
|
||||
s.setPlayer((Player) event.getDamager());
|
||||
s.setDate(new Date());
|
||||
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
||||
|
||||
mod.getModel().setState(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onHangingBreak(HangingBreakEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
|
||||
return;
|
||||
if (event.getEntity() instanceof ItemFrame) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Breaking hanging: " + event.getEntity().getLocation().toString());
|
||||
|
||||
if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("... was placed by creative. Drop prevented");
|
||||
|
||||
mod.getBlockSpawn().block(event.getEntity().getLocation().getBlock().getLocation(), Material.ITEM_FRAME);
|
||||
mod.getBlockSpawn().block(event.getEntity().getLocation().getBlock().getLocation(), ((ItemFrame) event.getEntity()).getItem().getType());
|
||||
}
|
||||
|
||||
mod.getModel().removeState(event.getEntity().getLocation().getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkArmoryDestroy(ArmorStand entity, boolean deRemove) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Breaking standing: " + entity.getLocation().toString());
|
||||
|
||||
if (mod.getModel().isRestricted(entity.getLocation().getBlock())) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("... was placed by creative. Drop prevented");
|
||||
|
||||
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), Material.ARMOR_STAND);
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), Material.ARMOR_STAND);
|
||||
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getHelmet());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getChestplate());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getBoots());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getItemInHand());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getLeggings());
|
||||
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getHelmet());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getChestplate());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getBoots());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getItemInHand());
|
||||
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getLeggings());
|
||||
/*entity.setBoots(null);
|
||||
entity.setChestplate(null);
|
||||
entity.setHelmet(null);
|
||||
entity.setItemInHand(null);
|
||||
entity.setLeggings(null);*/
|
||||
}
|
||||
|
||||
if (deRemove)
|
||||
mod.getModel().removeState(entity.getLocation().getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onStandingBreak(EntityDeathEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
|
||||
return;
|
||||
if (event.getEntity() instanceof ArmorStand) {
|
||||
checkArmoryDestroy((ArmorStand) event.getEntity(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onStandingBreaking(EntityDamageByEntityEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
|
||||
return;
|
||||
if (event.getEntity() instanceof ArmorStand) {
|
||||
// TODO: Bug in Spigot, we can not check for destroying yet. so the block state stays in DB :(
|
||||
//if (event.getEntity().isDead() || ((ArmorStand) event.getEntity()).getHealth() <= event.getFinalDamage()) {
|
||||
checkArmoryDestroy((ArmorStand) event.getEntity(), false);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
|
||||
return;
|
||||
if (event.getEntity() instanceof ItemFrame) {
|
||||
BlockState s = new BlockState();
|
||||
s.setLocation(event.getEntity().getLocation().getBlock().getLocation());
|
||||
s.setPlayer(event.getPlayer());
|
||||
s.setDate(new Date());
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Saving BlockState: " + s.toString());
|
||||
|
||||
mod.getModel().setState(s);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
|
||||
import de.jaschastarke.bukkit.lib.chat.InGameFormatter;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private ModBlockStates mod;
|
||||
public PlayerListener(ModBlockStates mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block b = event.getClickedBlock();
|
||||
if (b != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(event.getClickedBlock().getWorld().getName())) {
|
||||
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", event.getClickedBlock().getWorld().getName()));
|
||||
} else {
|
||||
showInfo(event.getPlayer(), b.getLocation(), b.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInteractEntity(PlayerInteractEntityEvent event) {
|
||||
Entity e = event.getRightClicked();
|
||||
if (e != null && e instanceof ItemFrame && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) {
|
||||
if (mod.getConfig().getIgnoredWorlds().contains(e.getWorld().getName())) {
|
||||
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", e.getWorld().getName()));
|
||||
} else {
|
||||
showInfo(event.getPlayer(), e.getLocation(), Material.ITEM_FRAME);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void showInfo(Player pl, Location loc, Material type) {
|
||||
BlockState s = mod.getModel().getState(loc.getBlock());
|
||||
InGameFormatter f = new InGameFormatter(mod.getPlugin().getLang());
|
||||
String ret = null;
|
||||
if (s == null || s.getSource() == Source.UNKNOWN) {
|
||||
ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown", type.toString()));
|
||||
} else {
|
||||
String k = "block_state.tool_info." + s.getSource().name().toLowerCase();
|
||||
String gm = "";
|
||||
if (s.getGameMode() != null) {
|
||||
switch (s.getGameMode()) {
|
||||
case CREATIVE:
|
||||
gm = ChatColor.GOLD + s.getGameMode().toString().toLowerCase() + ChatColor.RESET;
|
||||
break;
|
||||
case SURVIVAL:
|
||||
gm = ChatColor.GREEN + s.getGameMode().toString().toLowerCase() + ChatColor.RESET;
|
||||
break;
|
||||
case ADVENTURE:
|
||||
gm = ChatColor.DARK_GREEN + s.getGameMode().toString().toLowerCase() + ChatColor.RESET;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = f.formatString(ChatFormattings.INFO, f.getString(k, type.toString(),
|
||||
s.getPlayerName(),
|
||||
gm,
|
||||
s.getDate()));
|
||||
}
|
||||
if (ret != null)
|
||||
pl.sendMessage(ret);
|
||||
}
|
||||
}
|
|
@ -1,212 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.jaschastarke.database.DatabaseConfigurationException;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
|
||||
/**
|
||||
* @internal I'm not happy with the error-handling here, especially in the Transaction, but I'll focus on the asynchronous
|
||||
* variant, where all errors have to be handled in a separate thread.
|
||||
*/
|
||||
public class SyncronizedModel extends AbstractModel implements DBModel {
|
||||
private ModBlockStates mod;
|
||||
private DBQueries q;
|
||||
|
||||
public SyncronizedModel(ModBlockStates mod) throws DatabaseConfigurationException {
|
||||
super(mod.getPlugin());
|
||||
this.mod = mod;
|
||||
this.q = new DBQueries(mod, mod.getPlugin().getDatabaseConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() throws SQLException {
|
||||
this.q.initTable();
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public void moveState(Block from, Block to) {
|
||||
try {
|
||||
q.delete(to.getLocation());
|
||||
q.move(from.getLocation(), to.getLocation());
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to move BlockState in DB from " + from.getLocation().toString() + " to " + to.getLocation().toString());
|
||||
}
|
||||
moveMetaState(from, to);
|
||||
}
|
||||
public void removeState(BlockState state) {
|
||||
removeState(state.getLocation().getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeState(Block block) {
|
||||
setMetaBlock(block, null);
|
||||
try {
|
||||
q.delete(block.getLocation());
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to delete BlockState in DB from " + block.getLocation().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Block, Boolean> getRestrictedStates(List<Block> blocks) {
|
||||
Map<Block, Boolean> ret = new HashMap<Block, Boolean>();
|
||||
for (Map.Entry<Block, BlockState> entry : getStates(blocks).entrySet()) {
|
||||
ret.put(entry.getKey(), entry.getValue() != null && entry.getValue().isRestricted());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public Map<Block, BlockState> getStates(List<Block> blocks) {
|
||||
Map<Block, BlockState> ret = new HashMap<Block, BlockState>();
|
||||
|
||||
Cuboid c = new Cuboid();
|
||||
for (Block block : blocks) {
|
||||
HasBlockState has = getMetaBlock(block);
|
||||
if (has.isSet()) {
|
||||
ret.put(block, has.getState());
|
||||
} else {
|
||||
c.add(block.getLocation());
|
||||
}
|
||||
}
|
||||
if (!c.isEmpty()) {
|
||||
try {
|
||||
List<BlockState> dbb = q.findAllIn(c);
|
||||
for (BlockState bs : dbb) {
|
||||
setMetaBlock(bs.getLocation().getBlock(), bs);
|
||||
if (blocks.contains(bs.getLocation().getBlock()))
|
||||
ret.put(bs.getLocation().getBlock(), bs);
|
||||
}
|
||||
for (Block block : blocks) {
|
||||
if (!ret.containsKey(block)) {
|
||||
ret.put(block, null);
|
||||
setMetaBlock(block, null);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to fetch BlockState from DB in " + c.toString());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public void cacheStates(Cuboid c) {
|
||||
if (!c.isEmpty()) {
|
||||
try {
|
||||
List<BlockState> dbb = q.findAllIn(c);
|
||||
for (BlockState bs : dbb) {
|
||||
setMetaBlock(bs.getLocation().getBlock(), bs);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to fetch BlockState (for caching) from DB in " + c.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRestricted(Block block) {
|
||||
BlockState state = getState(block);
|
||||
return state != null ? state.isRestricted() : false;
|
||||
}
|
||||
|
||||
public BlockState getState(Block block) {
|
||||
HasBlockState has = getMetaBlock(block);
|
||||
if (!has.isSet()) {
|
||||
try {
|
||||
BlockState state = q.find(block.getLocation());
|
||||
setMetaBlock(block, state);
|
||||
return state;
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to fetch BlockState (for caching) from DB at " + block.getLocation().toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return has.getState();
|
||||
}
|
||||
public void setState(BlockState state) {
|
||||
Block block = state.getLocation().getBlock();
|
||||
boolean store = state != null && (state.isRestricted() || mod.getConfig().getLogSurvival());
|
||||
|
||||
setMetaBlock(block, store ? state : null);
|
||||
|
||||
try {
|
||||
if (!store)
|
||||
q.delete(state);
|
||||
else if (!q.update(state))
|
||||
q.insert(state);
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to update BlockState in DB at " + block.getLocation().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBTransaction groupUpdate() {
|
||||
return new Transaction();
|
||||
}
|
||||
|
||||
private class Transaction implements DBTransaction {
|
||||
private boolean finished = false;
|
||||
private Transaction() {
|
||||
try {
|
||||
q.getDB().startTransaction();
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveState(Block from, Block to) {
|
||||
if (finished)
|
||||
throw new IllegalAccessError("Transaction already ended");
|
||||
SyncronizedModel.this.moveState(from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(BlockState state) {
|
||||
if (finished)
|
||||
throw new IllegalAccessError("Transaction already ended");
|
||||
SyncronizedModel.this.setState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeState(Block block) {
|
||||
if (finished)
|
||||
throw new IllegalAccessError("Transaction already ended");
|
||||
SyncronizedModel.this.removeState(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
try {
|
||||
q.getDB().endTransaction();
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
} finally {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cleanUp(Cleanup target) {
|
||||
try {
|
||||
return q.cleanup(target);
|
||||
} catch (SQLException e) {
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to cleanup BlockState-DB");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
|
||||
import de.jaschastarke.database.DatabaseConfigurationException;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.thread.CallableAction;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.thread.ThreadLink;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.thread.Transaction;
|
||||
|
||||
public class ThreadedModel extends AbstractModel implements DBModel, Listener {
|
||||
private ModBlockStates mod;
|
||||
private ThreadLink threads;
|
||||
private MetadataValue metadataSet;
|
||||
private MetadataValue metadataSetRestricted;
|
||||
|
||||
public ThreadedModel(ModBlockStates mod) {
|
||||
super(mod.getPlugin());
|
||||
this.mod = mod;
|
||||
metadataSet = new FixedMetadataValue(mod.getPlugin(), new Boolean(true));
|
||||
metadataSetRestricted = new FixedMetadataValue(mod.getPlugin(), new Object());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() throws SQLException, DatabaseConfigurationException {
|
||||
DBQueries queries = new DBQueries(mod, mod.getPlugin().getDatabaseConnection());
|
||||
queries.initTable();
|
||||
threads = new ThreadLink(this, queries);
|
||||
// We don't keep any reference to queries, because it contains the DB-Connection, which should be only used
|
||||
// from the thread from now on (as SQLite may not threadsafe)
|
||||
for (World w : mod.getPlugin().getServer().getWorlds()) {
|
||||
if (!mod.getConfig().getIgnoredWorlds().containsIgnoreCase(w.getName())) {
|
||||
for (Chunk chunk : w.getLoadedChunks()) {
|
||||
threads.queueChunkLoad(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
threads.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {
|
||||
threads.shutdown();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
mod.getLog().severe("Failed to clean end Database-Thread, maybe BlockStates haven't been saved");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
if (!mod.getConfig().getIgnoredWorlds().containsIgnoreCase(event.getWorld().getName())) {
|
||||
threads.queueChunkLoad(event.getChunk());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveState(Block from, Block to) {
|
||||
threads.queueMetaMove(from.getLocation(), to.getLocation());
|
||||
moveMetaState(from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeState(BlockState state) {
|
||||
removeState(state.getLocation().getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeState(Block block) {
|
||||
setMetaBlock(block, null);
|
||||
threads.queueUpdate(block);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Block, Boolean> getRestrictedStates(List<Block> blocks) {
|
||||
Map<Block, Boolean> ret = new HashMap<Block, Boolean>();
|
||||
for (Block block : blocks) {
|
||||
HasBlockState has = getMetaBlock(block);
|
||||
ret.put(block, has.isRestricted());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Block, BlockState> getStates(List<Block> blocks) {
|
||||
Map<Block, BlockState> ret = new HashMap<Block, BlockState>();
|
||||
Cuboid c;
|
||||
do {
|
||||
c = new Cuboid();
|
||||
for (Block block : blocks) {
|
||||
HasBlockState has = getMetaBlock(block);
|
||||
if (has.getState() != null || has.isNull()) {
|
||||
ret.put(block, has.getState());
|
||||
} else {
|
||||
c.add(block.getLocation());
|
||||
ret.put(block, null);
|
||||
}
|
||||
}
|
||||
if (!c.isEmpty())
|
||||
threads.callUpdate(c);
|
||||
} while(!c.isEmpty());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cacheStates(Cuboid c) {
|
||||
threads.callUpdate(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getState(Block block) {
|
||||
HasBlockState has = getMetaBlock(block);
|
||||
if (has.getState() == null && !has.isNull()) {
|
||||
// The DB-Entry isn't set
|
||||
// and the entry doesn't tell us that it knows that it isn't set
|
||||
// (while using the threaded model, even having no Metadata entry, tells us there is no one in DB)
|
||||
return threads.callUpdate(block);
|
||||
}
|
||||
return has.getState();
|
||||
}
|
||||
@Override
|
||||
public boolean isRestricted(Block block) {
|
||||
return getMetaBlock(block).isRestricted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(BlockState state) {
|
||||
Block block = state.getLocation().getBlock();
|
||||
boolean store = state.isRestricted() || mod.getConfig().getLogSurvival();
|
||||
|
||||
setMetaBlock(block, store ? state : null);
|
||||
|
||||
threads.queueUpdate(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBTransaction groupUpdate() {
|
||||
return new GroupUpdate(threads);
|
||||
}
|
||||
|
||||
private class GroupUpdate extends Transaction {
|
||||
public GroupUpdate(ThreadLink threads) {
|
||||
super(threads);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveState(Block from, Block to) {
|
||||
moveMetaState(from, to);
|
||||
|
||||
super.moveState(from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(BlockState state) {
|
||||
Block block = state.getLocation().getBlock();
|
||||
boolean store = state.isRestricted() || mod.getConfig().getLogSurvival();
|
||||
|
||||
setMetaBlock(block, store ? state : null);
|
||||
|
||||
super.setState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeState(Block block) {
|
||||
setMetaBlock(block, null);
|
||||
|
||||
super.setState(block);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata-Interface for the Thread-Link
|
||||
*/
|
||||
public HasBlockState getMetaState(Block block) {
|
||||
return getMetaBlock(block);
|
||||
}
|
||||
/**
|
||||
* Metadata-Interface for the Thread-Link
|
||||
*/
|
||||
public void setMetaState(Block block, BlockState state) {
|
||||
super.setMetaBlock(block, state);
|
||||
}
|
||||
public void setSimpleMetaDataState(Block block, BlockState state) {
|
||||
if (state == null)
|
||||
super.setMetaBlock(block, null);
|
||||
else if (state.isRestricted())
|
||||
block.setMetadata(BSMDKEY, metadataSetRestricted);
|
||||
else
|
||||
block.setMetadata(BSMDKEY, metadataSet);
|
||||
}
|
||||
protected HasBlockState getMetaBlock(Metadatable m) {
|
||||
HasBlockState has = null;
|
||||
List<MetadataValue> metadata = m.getMetadata(BSMDKEY);
|
||||
for (MetadataValue v : metadata) {
|
||||
if (v.value() instanceof BlockState) {
|
||||
// The actual DB-entry is in Metadata (requires more memory)
|
||||
has = new HasBlockState((BlockState) v.value());
|
||||
break;
|
||||
} else if (v.getOwningPlugin() == mod.getPlugin()) {
|
||||
if (v == metadataNull) {
|
||||
// Metadata knows, that there is no entry in DB
|
||||
has = new HasBlockState(true);
|
||||
break;
|
||||
} else if (v == metadataSet) {
|
||||
// Metadata knows, that there is survival-entry in DB
|
||||
has = new HasBlockState(true, false);
|
||||
break;
|
||||
} else if (v == metadataSetRestricted) {
|
||||
// Metadata knows, that there is creative-entry in DB
|
||||
has = new HasBlockState(true, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (has == null)
|
||||
return new HasBlockState(false);
|
||||
else
|
||||
return has;
|
||||
}
|
||||
public static class HasBlockState extends AbstractModel.HasBlockState {
|
||||
private boolean restricted = false;
|
||||
private boolean isNull = false;
|
||||
|
||||
public HasBlockState(BlockState state) {
|
||||
super(state);
|
||||
restricted = state.isRestricted();
|
||||
}
|
||||
public HasBlockState(boolean isSet) {
|
||||
super(isSet);
|
||||
isNull = true;
|
||||
}
|
||||
public HasBlockState(boolean isSet, boolean isRestricted) {
|
||||
super(isSet);
|
||||
restricted = isRestricted;
|
||||
}
|
||||
public boolean isRestricted() {
|
||||
return restricted;
|
||||
}
|
||||
public boolean isNull() {
|
||||
return isNull;
|
||||
}
|
||||
}
|
||||
|
||||
public ModBlockStates getModel() {
|
||||
return mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cleanUp(final Cleanup target) {
|
||||
return threads.call(new CallableAction<Integer>() {
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
this.returnSet = true;
|
||||
try {
|
||||
this.returnValue = q.cleanup(target);
|
||||
} catch (SQLException e) {
|
||||
this.returnValue = -1;
|
||||
mod.getLog().severe(e.getMessage());
|
||||
mod.getLog().warn("Failed to cleanup BlockState-DB");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
public interface Action {
|
||||
|
||||
/**
|
||||
* @internal Executed from asynchronous Thread. Only Thread-Safe methods should be called.
|
||||
*/
|
||||
void process(ThreadLink link, DBQueries q);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
public class CacheChunkAction implements Action {
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
|
||||
private Chunk chunk;
|
||||
|
||||
public CacheChunkAction(Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
if (!chunk.isLoaded())
|
||||
return;
|
||||
Set<Block> knownBlocks = new HashSet<Block>();
|
||||
try {
|
||||
if (chunk.isLoaded()) {
|
||||
for (BlockState state : q.findAllIn(getBlocks())) {
|
||||
if (chunk.isLoaded()) {
|
||||
Block b = state.getLocation().getBlock();
|
||||
knownBlocks.add(b);
|
||||
link.setSimpleMetaState(b, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*int h = chunk.getWorld().getMaxHeight();
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < CHUNK_SIZE; x++) {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
Block b = chunk.getBlock(x, y, z);
|
||||
if (!knownBlocks.contains(b) && b.getType() != Material.AIR) {
|
||||
link.setSimpleMetaState(b, null);
|
||||
link.blockCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
} catch (SQLException e) {
|
||||
link.getLog().severe(e.getMessage());
|
||||
link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to load BlockStates for Chunk " + chunk.getX() + "/" + chunk.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
protected Cuboid getBlocks() {
|
||||
Cuboid c = new Cuboid();
|
||||
c.add(chunk.getBlock(0, 0, 0).getLocation());
|
||||
|
||||
int h = chunk.getWorld().getMaxHeight();
|
||||
c.add(chunk.getBlock(CHUNK_SIZE - 1, h - 1, CHUNK_SIZE - 1).getLocation());
|
||||
return c;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
public abstract class CallableAction<E> implements Action {
|
||||
protected boolean returnSet = false;
|
||||
protected E returnValue = null;
|
||||
|
||||
public E getValue() {
|
||||
synchronized (this) {
|
||||
try {
|
||||
while (!returnSet)
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
public class FetchBlockStateAction extends CallableAction<BlockState> {
|
||||
private Block block;
|
||||
|
||||
public FetchBlockStateAction(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
BlockState state = null;
|
||||
try {
|
||||
state = q.find(block.getLocation());
|
||||
link.setMetaState(block, state);
|
||||
} catch (SQLException e) {
|
||||
link.getLog().severe(e.getMessage());
|
||||
link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to fetch BlockState from DB: " + block.getLocation());
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
returnValue = state;
|
||||
returnSet = true;
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
public class FetchCuboidAction extends CallableAction<List<BlockState>> {
|
||||
private Cuboid cuboid;
|
||||
|
||||
public FetchCuboidAction(Cuboid cuboid) {
|
||||
this.cuboid = cuboid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
List<BlockState> states = null;
|
||||
try {
|
||||
states = q.findAllIn(cuboid);
|
||||
for (BlockState bs : states) {
|
||||
link.setMetaState(bs.getLocation().getBlock(), bs);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
link.getLog().severe(e.getMessage());
|
||||
link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to fetch BlockState from DB: " + cuboid);
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
returnValue = states;
|
||||
returnSet = true;
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
public class MoveBlockStateAction extends TransactionAction implements Action {
|
||||
private Location from;
|
||||
private Location to;
|
||||
|
||||
public MoveBlockStateAction(Location from, Location to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
try {
|
||||
processInTransaction(link, q);
|
||||
} catch (SQLException e) {
|
||||
link.getLog().severe(e.getMessage());
|
||||
link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to move BlockState in DB from " + from.toString() + " to " + to.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processInTransaction(ThreadLink link, DBQueries q) throws SQLException {
|
||||
q.delete(to);
|
||||
q.move(from, to);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,241 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.AbstractModel.HasBlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class ThreadLink {
|
||||
private static final int BATCH_ACTION_LENGTH = 25;
|
||||
private static final int QUEUE_ACCESS_WARNING_DURATION = 5; // ms
|
||||
private static final int COUNT_WARNING_QUEUE = 5;
|
||||
private static final int COUNT_ERROR_QUEUE = 20;
|
||||
private static final int QUEUE_TIMING_DURATION = 500; // ms
|
||||
private static final int STARTUP_TIMING = 30000; // ms
|
||||
private static final int THREAD_SHUTDOWN_WAIT_MS = 30000;
|
||||
private long lastTimeout;
|
||||
private final Stack<Action> updateQueue = new Stack<Action>();
|
||||
|
||||
private boolean shutdown;
|
||||
private ModuleLogger log;
|
||||
private ThreadedModel model;
|
||||
private Thread thread;
|
||||
|
||||
public ThreadLink(ThreadedModel threadedModel, DBQueries queries) {
|
||||
model = threadedModel;
|
||||
log = threadedModel.getModel().getLog();
|
||||
|
||||
/*
|
||||
* In theory we could add multiple threads, e.g. 1 write and 2 read threads.
|
||||
*/
|
||||
createThread(queries);
|
||||
shutdown = true; //Don't allow the thread to run until it's started
|
||||
}
|
||||
|
||||
private class DBThread extends Thread {
|
||||
private DBQueries q;
|
||||
public DBThread(DBQueries queries) {
|
||||
super();
|
||||
this.q = queries;
|
||||
}
|
||||
public void run() {
|
||||
if (getModule().isDebug())
|
||||
log.debug("DB-Thread '" + Thread.currentThread().getName() + "' started.");
|
||||
lastTimeout = System.currentTimeMillis() + STARTUP_TIMING;
|
||||
while (!shutdown || !updateQueue.isEmpty()) {
|
||||
try {
|
||||
//Thread.sleep(1000);
|
||||
//throw new RuntimeException("Test exception pls ignore");
|
||||
List<Action> acts = new LinkedList<Action>();
|
||||
synchronized (updateQueue) {
|
||||
while (updateQueue.isEmpty() && !shutdown)
|
||||
updateQueue.wait();
|
||||
if (updateQueue.size() > (BATCH_ACTION_LENGTH * COUNT_ERROR_QUEUE)) {
|
||||
if (System.currentTimeMillis() - lastTimeout > QUEUE_TIMING_DURATION) {
|
||||
getLog().warn("Extrem large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size());
|
||||
lastTimeout = System.currentTimeMillis();
|
||||
}
|
||||
} else if (updateQueue.size() > (BATCH_ACTION_LENGTH * COUNT_WARNING_QUEUE)) {
|
||||
if (System.currentTimeMillis() - lastTimeout > QUEUE_TIMING_DURATION) {
|
||||
getLog().info("Large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size());
|
||||
lastTimeout = System.currentTimeMillis();
|
||||
}
|
||||
} else if (updateQueue.size() <= BATCH_ACTION_LENGTH) {
|
||||
lastTimeout = System.currentTimeMillis();
|
||||
}
|
||||
for (int i = 0; i < BATCH_ACTION_LENGTH && !updateQueue.isEmpty(); i++) {
|
||||
acts.add(updateQueue.pop());
|
||||
}
|
||||
}
|
||||
long t = 0;
|
||||
if (getModule().isDebug()) {
|
||||
t = System.currentTimeMillis();
|
||||
log.debug("DB-Thread '" + Thread.currentThread().getName() + "' run: " + acts.size());
|
||||
}
|
||||
for (Action act : acts) {
|
||||
if (!shutdown || !(act instanceof CacheChunkAction)) {
|
||||
if (act instanceof CallableAction) {
|
||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||
synchronized (act) {
|
||||
act.process(ThreadLink.this, this.q);
|
||||
act.notify();
|
||||
}
|
||||
} else {
|
||||
act.process(ThreadLink.this, this.q);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getModule().isDebug())
|
||||
log.debug("DB-Thread '" + Thread.currentThread().getName() + "' execution time: " + (System.currentTimeMillis() - t) + "ms");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
log.severe("DB-Thread '" + Thread.currentThread().getName() + "' was harmfully interupted");
|
||||
}
|
||||
Thread.yield();
|
||||
}
|
||||
if (getModule().isDebug())
|
||||
log.debug("DB-Thread " + Thread.currentThread().getName() + " finished.");
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
shutdown = false;
|
||||
if (!thread.isAlive())
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
public void queueUpdate(Block block) {
|
||||
restartThreadIfNeeded();
|
||||
long l = System.currentTimeMillis();
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.add(new UpdateBlockStateAction(block));
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
long l2 = System.currentTimeMillis();
|
||||
if (l2 - l > QUEUE_ACCESS_WARNING_DURATION) {
|
||||
getLog().warn("queueUpdate-action took too long: " + (l2 - l) + "ms");
|
||||
}
|
||||
}
|
||||
|
||||
public BlockState callUpdate(Block block) {
|
||||
restartThreadIfNeeded();
|
||||
FetchBlockStateAction action = new FetchBlockStateAction(block);
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.push(action);
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
return action.getValue();
|
||||
}
|
||||
|
||||
public void queue(Action act) {
|
||||
restartThreadIfNeeded();
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.add(act);
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
}
|
||||
public <T> T call(CallableAction<T> act) {
|
||||
restartThreadIfNeeded();
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.push(act);
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
return act.getValue();
|
||||
}
|
||||
|
||||
public List<BlockState> callUpdate(Cuboid c) {
|
||||
FetchCuboidAction action = new FetchCuboidAction(c);
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.push(action);
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
return action.getValue();
|
||||
}
|
||||
|
||||
public void queueMetaMove(Location from, Location to) {
|
||||
restartThreadIfNeeded();
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.add(new MoveBlockStateAction(from, to));
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void queueChunkLoad(Chunk chunk) {
|
||||
restartThreadIfNeeded();
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.add(new CacheChunkAction(chunk));
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void queueTransaction(Transaction transaction) {
|
||||
restartThreadIfNeeded();
|
||||
synchronized (updateQueue) {
|
||||
updateQueue.add(transaction);
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() throws InterruptedException {
|
||||
synchronized (updateQueue) {
|
||||
shutdown = true;
|
||||
updateQueue.notifyAll();
|
||||
}
|
||||
thread.join(THREAD_SHUTDOWN_WAIT_MS);
|
||||
if (thread.isAlive())
|
||||
thread.interrupt(); //Wake it up
|
||||
}
|
||||
|
||||
public HasBlockState getMetaState(Block block) {
|
||||
return model.getMetaState(block);
|
||||
}
|
||||
public void setMetaState(Block block, BlockState state) {
|
||||
model.setMetaState(block, state);
|
||||
}
|
||||
public void setSimpleMetaState(Block block, BlockState state) {
|
||||
model.setSimpleMetaDataState(block, state);
|
||||
}
|
||||
|
||||
public ModBlockStates getModule() {
|
||||
return model.getModel();
|
||||
}
|
||||
|
||||
public ModuleLogger getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
private void restartThreadIfNeeded() {
|
||||
if ((thread != null && thread.isAlive()) || shutdown)
|
||||
return;
|
||||
log.warn("Thread is dead, restarting!");
|
||||
new Exception("Thread-restarting update called").printStackTrace();
|
||||
createThread(((DBThread) thread).q);
|
||||
start();
|
||||
}
|
||||
|
||||
private void createThread(DBQueries queries) {
|
||||
if (shutdown)
|
||||
return;
|
||||
thread = new DBThread(queries);
|
||||
thread.setName("LC BlockState DB-Thread");
|
||||
thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable e) {
|
||||
e.printStackTrace();
|
||||
log.severe("Thread " + thread.getName() + " encoutered an uncaught Exception: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
abstract public class Transaction implements DBTransaction, Action {
|
||||
protected boolean finished = false;
|
||||
private List<TransactionAction> actions = new LinkedList<TransactionAction>();
|
||||
private ThreadLink link;
|
||||
|
||||
public Transaction(ThreadLink link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveState(Block from, Block to) {
|
||||
if (finished)
|
||||
throw new IllegalAccessError("Transaction already ended");
|
||||
|
||||
actions.add(new MoveBlockStateAction(from.getLocation(), to.getLocation()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(BlockState state) {
|
||||
if (finished)
|
||||
throw new IllegalAccessError("Transaction already ended");
|
||||
|
||||
Block block = state.getLocation().getBlock();
|
||||
actions.add(new UpdateBlockStateAction(block));
|
||||
}
|
||||
|
||||
public void setState(Block block) {
|
||||
if (finished)
|
||||
throw new IllegalAccessError("Transaction already ended");
|
||||
|
||||
actions.add(new UpdateBlockStateAction(block));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
if (finished)
|
||||
return;
|
||||
link.queueTransaction(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Executed from asynchronous Thread. Only Thread-Safe methods should be called.
|
||||
*/
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
if (actions.isEmpty())
|
||||
return;
|
||||
try {
|
||||
q.getDB().startTransaction();
|
||||
for (TransactionAction act : actions) {
|
||||
act.processInTransaction(link, q);
|
||||
}
|
||||
q.getDB().endTransaction();
|
||||
} catch (SQLException e) {
|
||||
try {
|
||||
q.getDB().revertTransaction();
|
||||
} catch (SQLException e1) {}
|
||||
link.getLog().severe(e.getMessage());
|
||||
link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to write Transaction to the Database");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
abstract public class TransactionAction implements Action {
|
||||
abstract public void processInTransaction(ThreadLink link, DBQueries q) throws SQLException;
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.thread;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.AbstractModel.HasBlockState;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
|
||||
|
||||
public class UpdateBlockStateAction extends TransactionAction implements Action {
|
||||
private Block block;
|
||||
public UpdateBlockStateAction(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ThreadLink link, DBQueries q) {
|
||||
HasBlockState state = link.getMetaState(block);
|
||||
if (state.isSet()) {
|
||||
try {
|
||||
q.delete(block.getLocation());
|
||||
if (state.getState() != null)
|
||||
q.insert(state.getState());
|
||||
} catch (SQLException e) {
|
||||
link.getLog().severe(e.getMessage());
|
||||
link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to save BlockState to DB: " + state.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processInTransaction(ThreadLink link, DBQueries q) throws SQLException {
|
||||
HasBlockState state = link.getMetaState(block);
|
||||
if (state.isSet()) {
|
||||
q.delete(block.getLocation());
|
||||
if (state.getState() != null)
|
||||
q.insert(state.getState());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
||||
|
||||
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 java.util.Date;
|
||||
|
||||
public class EditSessionExtent extends AbstractDelegateExtent {
|
||||
private ModBlockStates mod;
|
||||
private Player player = null;
|
||||
private World world;
|
||||
|
||||
public EditSessionExtent(Extent extent, ModBlockStates mod, Player player, World world) {
|
||||
super(extent);
|
||||
this.mod = mod;
|
||||
this.player = player;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is being changed.
|
||||
*
|
||||
* @param pt the position
|
||||
* @param newBlock the new block to replace the old one
|
||||
*/
|
||||
@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.getBlockType().getMaterial().isAir()) {
|
||||
mod.getModel().removeState(loc.getBlock());
|
||||
} else {
|
||||
BlockState s = mod.getModel().getState(loc.getBlock());
|
||||
if (s == null) {
|
||||
s = new BlockState();
|
||||
s.setLocation(loc);
|
||||
}
|
||||
s.setGameMode(null);
|
||||
s.setPlayerNameOrUUID(player.getUniqueId().toString());
|
||||
s.setDate(new Date());
|
||||
s.setSource(Source.EDIT);
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("WorldEdit-Integration: Saving BlockState: " + s.toString());
|
||||
|
||||
mod.getModel().setState(s);
|
||||
}
|
||||
super.setBlock(pt, newBlock);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.EditSession.Stage;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
|
||||
public class EditSessionListener {
|
||||
private ModBlockStates mod;
|
||||
|
||||
public EditSessionListener(ModBlockStates mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEditSession(EditSessionEvent event) {
|
||||
if (mod.getConfig().getWorldeditIntegration()) {
|
||||
if (event.getStage() == Stage.BEFORE_CHANGE) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("WorldEdit-Integration: New EditSession: "+event.getActor().getName()+" in World "+event.getWorld().getName()); // + " (" + event.getStage() + ")");
|
||||
Actor actor = event.getActor();
|
||||
World world = event.getWorld();
|
||||
if (actor != null && actor.isPlayer() && world != null && world instanceof BukkitWorld) {
|
||||
Player player = Bukkit.getPlayer(actor.getUniqueId());
|
||||
event.setExtent(new EditSessionExtent(event.getExtent(), mod, player, ((BukkitWorld) event.getWorld()).getWorld()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,24 +6,22 @@ import java.util.List;
|
|||
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurableList;
|
||||
import de.jaschastarke.bukkit.lib.configuration.IToGeneric;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ITabComplete;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ListConfigValue;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
|
||||
public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements ConfigurableList<ICmdBlockEntry>, IToGeneric, ITabComplete {
|
||||
public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements ConfigurableList<ICmdBlockEntry>, IToGeneric {
|
||||
private static final long serialVersionUID = -125544131527849084L;
|
||||
|
||||
@Override
|
||||
public boolean addSetting(String cmd) throws InvalidValueException {
|
||||
public void add(String cmd) throws InvalidValueException {
|
||||
if (cmd.startsWith("^")) {
|
||||
return add(new RegexpBlockEntry(cmd));
|
||||
add(new RegexpBlockEntry(cmd));
|
||||
} else {
|
||||
return add(new StringBlockEntry(cmd));
|
||||
add(new StringBlockEntry(cmd));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeSetting(String e) {
|
||||
public boolean remove(String e) {
|
||||
for (Iterator<ICmdBlockEntry> iterator = this.iterator(); iterator.hasNext();) {
|
||||
ICmdBlockEntry entry = iterator.next();
|
||||
if (entry.toString().equalsIgnoreCase(e)) {
|
||||
|
@ -43,22 +41,4 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
|
|||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSettings() {
|
||||
clear();
|
||||
}
|
||||
|
||||
public List<String> tabComplete(String[] args, String[] chain) {
|
||||
if (args.length > 0 && chain.length > 0) {
|
||||
if (chain[chain.length - 1].equalsIgnoreCase(ListConfigValue.REMOVE)) {
|
||||
List<String> hints = new ArrayList<String>();
|
||||
for (ICmdBlockEntry s : this) {
|
||||
if (s.toString().toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
hints.add(s.toString());
|
||||
}
|
||||
return hints;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
|||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.DynamicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
|
@ -20,7 +19,6 @@ public class CmdBlockPermissions extends SimplePermissionContainerNode {
|
|||
super(parent, name);
|
||||
}
|
||||
|
||||
@PluginPermissions
|
||||
public static final SimplePermissionContainerNode CONTAINER = new CmdBlockPermissions(Permissions.CONTAINER, "cmdblock");
|
||||
|
||||
/**
|
||||
|
@ -33,7 +31,7 @@ public class CmdBlockPermissions extends SimplePermissionContainerNode {
|
|||
* Allows to bypass specific blockings of commands as it tests against all partial permissions:
|
||||
*
|
||||
* Example:
|
||||
* A Command "/execute a fuzzy command -n 256" is entered by the player which is blocked by the configuration the
|
||||
* A Command "/execute a fuzzy command -n 256" is entered by the player which is blocked by the configuration the
|
||||
* following permissions are tested, and if one is present for the user, he is allowed to execute the command:
|
||||
* - limitedcreative.cmdblock.*
|
||||
* - limitedcreative.cmdblock.execute
|
||||
|
|
|
@ -3,17 +3,15 @@ package de.jaschastarke.minecraft.limitedcreative.cmdblocker;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Config;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModCmdBlocker;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
/**
|
||||
* CommandBlocker-Feature
|
||||
|
@ -21,34 +19,32 @@ import de.jaschastarke.modularize.ModuleEntry;
|
|||
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/command-blocker/
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = Config.class)
|
||||
public class CmdBlockerConfig extends Configuration implements IConfigurationSubGroup {
|
||||
private CmdBlockList blockList;
|
||||
|
||||
protected ModCmdBlocker mod;
|
||||
protected ModuleEntry<IModule> entry;
|
||||
|
||||
public CmdBlockerConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public CmdBlockerConfig(ModCmdBlocker modCmdBlocker, ModuleEntry<IModule> modEntry) {
|
||||
super(modCmdBlocker.getPlugin().getDocCommentStorage());
|
||||
mod = modCmdBlocker;
|
||||
entry = modEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(ConfigurationSection sect) {
|
||||
blockList = null;
|
||||
super.setValues(sect);
|
||||
entry.setDefaultEnabled(getEnabled());
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
|
||||
super.setValue(node, pValue);
|
||||
if (node.getName().equals("enabled")) {
|
||||
entry.setEnabled(getEnabled());
|
||||
if (getEnabled()) {
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.enable();
|
||||
} else {
|
||||
entry.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,12 +68,14 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub
|
|||
public boolean getEnabled() {
|
||||
return config.getBoolean("enabled", true);
|
||||
}
|
||||
|
||||
private CmdBlockList blockList;
|
||||
|
||||
/**
|
||||
* CmdBlockerList
|
||||
*
|
||||
* Defines the list of commands that are blocked while in creative mode. The leading / isn't included. By default
|
||||
* the list-item is treated as simple string as typed in by the user after the /. All commands starting with
|
||||
* Defines the list of commands that are blocked while in creative mode. The leading / isn't included. By default
|
||||
* the list-item is treated as simple string as typed in by the user after the /. All commands starting with
|
||||
* this string are blocked, even if more parameteres are entered by the user.
|
||||
* If the first character is ^ the entry is interpreted as a regular expression (including the ^ for begin of the string).
|
||||
* Only use regular expressions if you know them!
|
||||
|
@ -98,7 +96,7 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub
|
|||
if (config.contains("commands") && config.isList("commands")) {
|
||||
for (Object e : config.getList("commands")) {
|
||||
try {
|
||||
blockList.addSetting(e.toString());
|
||||
blockList.add(e.toString());
|
||||
} catch (InvalidValueException e1) {
|
||||
mod.getLog().warn(e1.getMessage());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.regex.Pattern;
|
|||
public class RegexpBlockEntry implements ICmdBlockEntry {
|
||||
private Pattern rx;
|
||||
public RegexpBlockEntry(String regex) {
|
||||
rx = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
||||
rx = Pattern.compile(regex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,7 @@ public class StringBlockEntry implements ICmdBlockEntry {
|
|||
|
||||
@Override
|
||||
public boolean test(String cmd) {
|
||||
return cmd.toLowerCase().startsWith(this.str.toLowerCase());
|
||||
return cmd.startsWith(this.str);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.gmperm;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Config;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
|
||||
/**
|
||||
* GameMode-Permissions-Feature
|
||||
*
|
||||
* This Feature requires Vault-Plugin to be active.
|
||||
*
|
||||
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/gmperm/
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = Config.class)
|
||||
public class GMPermConfig extends Configuration implements IConfigurationSubGroup {
|
||||
protected ModGameModePerm mod;
|
||||
protected ModuleEntry<IModule> entry;
|
||||
|
||||
public GMPermConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public GMPermConfig(ModGameModePerm modGameModePerm, ModuleEntry<IModule> modEntry) {
|
||||
super(modGameModePerm.getPlugin().getDocCommentStorage());
|
||||
mod = modGameModePerm;
|
||||
entry = modEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
|
||||
super.setValue(node, pValue);
|
||||
if (node.getName().equals("enabled")) {
|
||||
entry.setEnabled(getEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(ConfigurationSection sect) {
|
||||
super.setValues(sect);
|
||||
entry.setDefaultEnabled(getEnabled());
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "gmperm";
|
||||
}
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 600;
|
||||
}
|
||||
|
||||
/**
|
||||
* GMPermEnabled
|
||||
*
|
||||
* Activates that players are put in a special permission group while in creative mode.
|
||||
*
|
||||
* default: false
|
||||
*/
|
||||
@IsConfigurationNode(order = 100)
|
||||
public boolean getEnabled() {
|
||||
return config.getBoolean("enabled", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* GMPermCreativeGroup
|
||||
*
|
||||
* Defines the Permission-Group which the player gets added to on entering creative-mode. If this value is changed
|
||||
* the old group won't be automatically removed from players already in it. So be sure to delete the old group or
|
||||
* remove all player of it, that they don't get stuck with that permissions.
|
||||
*/
|
||||
@IsConfigurationNode(order = 200)
|
||||
public String getCreativeGroup() {
|
||||
return config.getString("creativeGroup", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* GMPermAdventureGroup
|
||||
*
|
||||
* Like GMPermCreativeGroup but for adventure users. This is optional, so you don't have to set any group.
|
||||
*
|
||||
* default: false
|
||||
*/
|
||||
@IsConfigurationNode(order = 300)
|
||||
public String getAdventureGroup() {
|
||||
if (config.isBoolean("adventureGroup"))
|
||||
return null;
|
||||
return config.getString("adventureGroup", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final IConfigurationNode node) {
|
||||
Object val = super.getValue(node);
|
||||
if (node.getName().equals("adventureGroup") && val == null) {
|
||||
return new Boolean(false);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.gmperm;
|
||||
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
|
||||
public class PermissionInterface {
|
||||
//private CoreModule<?> mod;
|
||||
private Permission permission = null;
|
||||
private RegisteredServiceProvider<Permission> permissionProvider;
|
||||
|
||||
public PermissionInterface(CoreModule<?> mod) {
|
||||
//this.mod = mod;
|
||||
permissionProvider = mod.getPlugin().getServer().getServicesManager().getRegistration(Permission.class);
|
||||
}
|
||||
|
||||
public boolean isPresent() {
|
||||
return permissionProvider != null && permissionProvider.getProvider() != null;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
permission = null;
|
||||
}
|
||||
|
||||
public Permission getPermission() {
|
||||
if (permission == null)
|
||||
permission = permissionProvider.getProvider();
|
||||
return permission;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* 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.gmperm;
|
||||
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private ModGameModePerm mod;
|
||||
public PlayerListener(ModGameModePerm mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
protected Permission v() {
|
||||
return mod.getPermissionInterface().getPermission();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
ensureGroup(event.getPlayer(), event.getNewGameMode());
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if (event.getResult() == Result.ALLOWED)
|
||||
return;
|
||||
|
||||
ensureGroup(event.getPlayer());
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (!event.getFrom().getWorld().equals(event.getTo().getWorld())) {
|
||||
ensureGroup(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
protected void ensureGroup(Player player) {
|
||||
ensureGroup(player, player.getGameMode());
|
||||
}
|
||||
protected void ensureGroup(Player player, GameMode gm) {
|
||||
String cgroup = mod.getConfig().getCreativeGroup();
|
||||
String agroup = mod.getConfig().getAdventureGroup();
|
||||
|
||||
if (gm == GameMode.CREATIVE) {
|
||||
if (!v().playerInGroup(player, cgroup)) {
|
||||
v().playerAddGroup(player, cgroup);
|
||||
}
|
||||
if (agroup != null && v().playerInGroup(player, agroup)) {
|
||||
v().playerRemoveGroup(player, agroup);
|
||||
}
|
||||
} else if (gm == GameMode.ADVENTURE) {
|
||||
if (v().playerInGroup(player, cgroup)) {
|
||||
v().playerRemoveGroup(player, cgroup);
|
||||
}
|
||||
if (agroup != null && !v().playerInGroup(player, agroup)) {
|
||||
v().playerAddGroup(player, agroup);
|
||||
}
|
||||
} else if (gm == GameMode.SURVIVAL) {
|
||||
if (v().playerInGroup(player, cgroup)) {
|
||||
v().playerRemoveGroup(player, cgroup);
|
||||
}
|
||||
if (agroup != null && v().playerInGroup(player, agroup)) {
|
||||
v().playerRemoveGroup(player, agroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.org.whoami.authme.cache.auth.PlayerCache;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
//@Deprecated // AuthMe 3.0 released. Compatibility for older versions will be removed sometime
|
||||
public class AuthMeHooks {
|
||||
public AuthMeHooks(final LimitedCreative plugin) {
|
||||
Hooks.IsLoggedIn.register(new PlayerCheckHooker.Check() {
|
||||
@Override
|
||||
public boolean test(Player player) {
|
||||
boolean li = AuthMeApi.getInstance().isAuthenticated(player);
|
||||
boolean li = PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase());
|
||||
if (plugin.isDebug()) // not nessesary, but so no string concation without debug needed
|
||||
plugin.getLog().debug("AuthMe: "+player.getName()+": logged in: "+li);
|
||||
return li;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
import multiworld.MultiWorldPlugin;
|
||||
import multiworld.api.MultiWorldAPI;
|
||||
|
||||
public class MultiWorldHooks {
|
||||
public MultiWorldHooks(final LimitedCreative plugin) {
|
||||
Hooks.DefaultWorldGameMode.register(new WorldTypeHooker.Check() {
|
||||
@Override
|
||||
public GameMode get(World world) {
|
||||
boolean creative = getMWApi().isCreativeWorld(world.getName());
|
||||
GameMode gm = creative ? GameMode.CREATIVE : GameMode.SURVIVAL;
|
||||
plugin.getLog().debug("MultiWorld: "+world.getName()+": game mode: "+gm);
|
||||
return gm;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static MultiWorldAPI getMWApi() {
|
||||
return ((MultiWorldPlugin) Bukkit.getServer().getPluginManager().getPlugin("MultiWorld")).getApi();
|
||||
}
|
||||
}
|
|
@ -9,16 +9,12 @@ import org.bukkit.material.MaterialData;
|
|||
|
||||
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ICommandConfigCallback;
|
||||
import de.jaschastarke.bukkit.lib.items.MaterialDataNotRecognizedException;
|
||||
import de.jaschastarke.bukkit.lib.items.MaterialNotRecognizedException;
|
||||
import de.jaschastarke.bukkit.lib.items.ItemUtils;
|
||||
import de.jaschastarke.configuration.ConfigurationStyle;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||
|
||||
/**
|
||||
|
@ -27,15 +23,9 @@ import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
|||
* When set, all creative Player automatically wears the given items as Armor. So they are better seen by other Players.
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = InventoryConfig.class)
|
||||
public class ArmoryConfig extends Configuration implements IConfigurationSubGroup, ICommandConfigCallback {
|
||||
public class ArmoryConfig extends Configuration implements IConfigurationSubGroup {
|
||||
protected ModInventories mod;
|
||||
|
||||
public ArmoryConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public ArmoryConfig(ModInventories modInventories) {
|
||||
super(modInventories.getPlugin().getDocCommentStorage());
|
||||
mod = modInventories;
|
||||
}
|
||||
|
||||
|
@ -43,7 +33,7 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
|||
public void setValues(ConfigurationSection sect) {
|
||||
if (sect == null || sect.getValues(false).size() == 0) {
|
||||
ConfigurationSection parent_sect = mod.getConfig().getValues();
|
||||
if (parent_sect.contains("armore") && parent_sect.isConfigurationSection("armor")) {
|
||||
if (parent_sect.contains("armor")) {
|
||||
sect = parent_sect.createSection(this.getName(), parent_sect.getConfigurationSection("armor").getValues(true));
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +63,9 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
|||
if (getEnabled()) {
|
||||
Map<String, ItemStack> armor = new HashMap<String, ItemStack>();
|
||||
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
||||
if (!entry.getKey().equals("enabled") && !entry.getKey().equals("fixed")) {
|
||||
if (entry.getValue() instanceof ItemStack) {
|
||||
armor.put(entry.getKey(), (ItemStack) entry.getValue());
|
||||
if (!entry.getKey().equals("enabled")) {
|
||||
if (entry instanceof ItemStack) {
|
||||
armor.put(entry.getKey(), (ItemStack) entry);
|
||||
} else {
|
||||
MaterialData md = null;
|
||||
try {
|
||||
|
@ -99,40 +89,26 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
|||
/**
|
||||
* InventoryCreativeArmorItems
|
||||
*
|
||||
* Allows changing of the "Creative-Armor" to be wear when in creative mode.
|
||||
* *see Blacklist for details on Item-Types
|
||||
* Allows changing of the "Creative-Armor" to be wear when in creative mode
|
||||
*
|
||||
* When using commands to change this options, use "current" (without quotes) to set it to the currently wearing item.
|
||||
* This way you can easily set it to dyed leather armor.
|
||||
* *see Blacklist for details on Item-Types
|
||||
*/
|
||||
@IsConfigurationNode(order = 500)
|
||||
public Object getHead() {
|
||||
return config.get("head", "CHAINMAIL_HELMET");
|
||||
}
|
||||
@IsConfigurationNode(order = 501, style = ConfigurationStyle.GROUPED_PREVIOUS)
|
||||
@IsConfigurationNode(order = 501)
|
||||
public Object getChest() {
|
||||
return config.get("chest", "CHAINMAIL_CHESTPLATE");
|
||||
}
|
||||
@IsConfigurationNode(order = 502, style = ConfigurationStyle.GROUPED_PREVIOUS)
|
||||
@IsConfigurationNode(order = 502)
|
||||
public Object getLegs() {
|
||||
return config.get("legs", "CHAINMAIL_LEGGINGS");
|
||||
}
|
||||
@IsConfigurationNode(order = 503, style = ConfigurationStyle.GROUPED_PREVIOUS)
|
||||
@IsConfigurationNode(order = 503)
|
||||
public Object getFeet() {
|
||||
return config.get("feet", "CHAINMAIL_BOOTS");
|
||||
}
|
||||
|
||||
/* -- Doesn't work, because of bugged bukkit... the event isn't fired if you try again --*
|
||||
* InventoryCreativeArmorFixed
|
||||
*
|
||||
* Prevent players from changing armor while in creative.
|
||||
*
|
||||
* default: true
|
||||
*//*
|
||||
@IsConfigurationNode(order = 600, name = "fixed")
|
||||
public boolean getFixedArmor() {
|
||||
return config.getBoolean("fixed", true);
|
||||
}*/
|
||||
|
||||
public String L(String msg, Object... objects) {
|
||||
return mod.getPlugin().getLocale().trans(msg, objects);
|
||||
|
@ -140,22 +116,4 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
|
|||
public ModuleLogger getLog() {
|
||||
return mod.getLog();
|
||||
}
|
||||
@Override
|
||||
public void onConfigCommandChange(Callback cb) {
|
||||
String n = cb.getNode().getName();
|
||||
if (n.equals("head") || n.equals("chest") || n.equals("legs") || n.equals("feet")) {
|
||||
if (cb.getValue().equals("current") || cb.getValue().equals("this")) {
|
||||
if (cb.getContext().isPlayer()) {
|
||||
if (n.equals("head"))
|
||||
cb.setValue(cb.getContext().getPlayer().getInventory().getHelmet());
|
||||
if (n.equals("chest"))
|
||||
cb.setValue(cb.getContext().getPlayer().getInventory().getChestplate());
|
||||
if (n.equals("legs"))
|
||||
cb.setValue(cb.getContext().getPlayer().getInventory().getLeggings());
|
||||
if (n.equals("feet"))
|
||||
cb.setValue(cb.getContext().getPlayer().getInventory().getBoots());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.inventories;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.SimpleModule;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||
import fr.xephi.authme.events.ProtectInventoryEvent;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
//@Deprecated // AuthMe 3.0 released. Compatibility for older versions will be removed sometime
|
||||
import uk.org.whoami.authme.events.RestoreInventoryEvent;
|
||||
import uk.org.whoami.authme.events.StoreInventoryEvent;
|
||||
import de.jaschastarke.bukkit.lib.SimpleModule;
|
||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreative;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||
|
||||
public class AuthMeInventories extends SimpleModule<LimitedCreative> implements Listener {
|
||||
ModInventories invmod;
|
||||
public AuthMeInventories(LimitedCreative plugin, ModInventories modInventories) {
|
||||
|
@ -18,16 +18,16 @@ public class AuthMeInventories extends SimpleModule<LimitedCreative> implements
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
public void onStoreInventory(ProtectInventoryEvent event) {
|
||||
public void onStoreInventory(StoreInventoryEvent event) {
|
||||
if (isDebug())
|
||||
getLog().debug("AuthMe Store Event: " + event.getPlayer().getName());
|
||||
|
||||
getLog().debug("AuthMe Store Event: "+event.getPlayer().getName());
|
||||
|
||||
event.getPlayer().closeInventory();
|
||||
GameMode cgm = event.getPlayer().getGameMode();
|
||||
|
||||
|
||||
if (cgm == GameMode.ADVENTURE && !invmod.getConfig().getSeparateAdventure())
|
||||
cgm = GameMode.SURVIVAL;
|
||||
|
||||
|
||||
if (cgm != GameMode.CREATIVE || invmod.getConfig().getStoreCreative()) {
|
||||
invmod.getInventory(event.getPlayer()).save(cgm);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,7 @@ public class Inventory {
|
|||
public enum Target {
|
||||
SURVIVAL,
|
||||
CREATIVE,
|
||||
ADVENTURE,
|
||||
SPECTATOR;
|
||||
ADVENTURE;
|
||||
|
||||
public static Target getTarget(GameMode gm) {
|
||||
return Target.valueOf(gm.name());
|
||||
|
|
|
@ -3,17 +3,15 @@ package de.jaschastarke.minecraft.limitedcreative.inventories;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Config;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModInventories;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
/**
|
||||
* Inventory-Feature
|
||||
|
@ -21,16 +19,12 @@ import de.jaschastarke.modularize.ModuleEntry;
|
|||
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/inventory/
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = Config.class)
|
||||
public class InventoryConfig extends Configuration implements IConfigurationSubGroup {
|
||||
|
||||
protected ModInventories mod;
|
||||
protected ModuleEntry<IModule> entry;
|
||||
|
||||
public InventoryConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public InventoryConfig(ModInventories modInventories, ModuleEntry<IModule> modEntry) {
|
||||
super(modInventories.getPlugin().getDocCommentStorage());
|
||||
mod = modInventories;
|
||||
entry = modEntry;
|
||||
}
|
||||
|
@ -39,7 +33,12 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
|
|||
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
|
||||
super.setValue(node, pValue);
|
||||
if (node.getName().equals("enabled")) {
|
||||
entry.setEnabled(getEnabled());
|
||||
if (getEnabled()) {
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.enable();
|
||||
} else {
|
||||
entry.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +52,8 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
|
|||
}
|
||||
|
||||
super.setValues(sect);
|
||||
entry.setDefaultEnabled(getEnabled());
|
||||
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
|
||||
// Config Upgrade
|
||||
if (!sect.contains("storeCreative") && sect.contains("creative"))
|
||||
sect.set("storeCreative", sect.getBoolean("creative"));
|
||||
|
@ -73,7 +72,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
|
|||
/**
|
||||
* InventoryEnabled
|
||||
*
|
||||
* Use this option to disable the separated inventories feature, for example if you use another Plugin handling
|
||||
* Use this option to disable the separated inventories feature, for example if you use another Plugin handling
|
||||
* the inventories, like Multiverse-Inventories.
|
||||
*
|
||||
* default: true
|
||||
|
@ -99,7 +98,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
|
|||
/**
|
||||
* InventorySeparateAdventure
|
||||
*
|
||||
* When true, your players get a separate inventory when switching to adventure gamemode (2). Otherwise
|
||||
* When true, your players get a separate inventory when switching to adventure gamemode (2). Otherwise
|
||||
* they have the default survival inventory while in adventure gamemode.
|
||||
*
|
||||
* default: false
|
||||
|
|
|
@ -20,7 +20,6 @@ package de.jaschastarke.minecraft.limitedcreative.inventories;
|
|||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainer;
|
||||
|
@ -32,16 +31,10 @@ import de.jaschastarke.minecraft.limitedcreative.Permissions;
|
|||
*
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginPermissions
|
||||
public class InventoryPermissions extends SimplePermissionContainer {
|
||||
|
||||
/**
|
||||
* Allows bypassing the inventory separation
|
||||
*/
|
||||
public static final IPermission KEEP_INVENTORY = new BasicPermission(Permissions.CONTAINER, "keepinventory", PermissionDefault.FALSE);
|
||||
|
||||
/**
|
||||
* Allows bypassing creative armor settings. No armor is changed on going to creative.
|
||||
*/
|
||||
public static final IPermission BYPASS_CREATIVE_ARMOR = new BasicPermission(Permissions.CONTAINER, "bypass_creativearmor", PermissionDefault.FALSE);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package de.jaschastarke.minecraft.limitedcreative.inventories;
|
|||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
@ -33,7 +32,7 @@ public class PlayerListener implements Listener {
|
|||
this.mod = mod;
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
boolean isLoggedIn = Hooks.IsLoggedIn.test(event.getPlayer());
|
||||
if (mod.isDebug()) {
|
||||
|
@ -49,22 +48,10 @@ public class PlayerListener implements Listener {
|
|||
mod.onSetGameMode(event.getPlayer(), event.getNewGameMode());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
mod.setCreativeArmor(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
/*@EventHandler(ignoreCancelled = true)
|
||||
public void onCreativeInventory(InventoryCreativeEvent event) {
|
||||
if (event.getWhoClicked() instanceof Player) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (event.getSlotType() == SlotType.ARMOR && mod.getArmorConfig().getFixedArmor()) {
|
||||
if (!mod.getPlugin().getPermManager().hasPermission(player, InventoryPermissions.BYPASS_CREATIVE_ARMOR)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class Fallback {
|
|||
@Override
|
||||
public void store(ConfigurationSection section) {
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR))
|
||||
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0)
|
||||
sectionSetItem(section, String.valueOf(i), inv.getItem(i));
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class Fallback {
|
|||
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
|
||||
Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR)) {
|
||||
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) {
|
||||
map.put(i, inv.getItem(i));
|
||||
}
|
||||
}
|
||||
|
@ -133,13 +133,13 @@ public class Fallback {
|
|||
|
||||
@Override
|
||||
public void store(ConfigurationSection section) {
|
||||
if (inv.getHelmet() != null && !inv.getHelmet().getType().equals(Material.AIR))
|
||||
if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "helmet", inv.getHelmet());
|
||||
if (inv.getChestplate() != null && !inv.getChestplate().getType().equals(Material.AIR))
|
||||
if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "chestplate", inv.getChestplate());
|
||||
if (inv.getLeggings() != null && !inv.getLeggings().getType().equals(Material.AIR))
|
||||
if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "leggins", inv.getLeggings());
|
||||
if (inv.getBoots() != null && !inv.getBoots().getType().equals(Material.AIR))
|
||||
if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0)
|
||||
Items.sectionSetItem(section, "boots", inv.getBoots());
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public class InvYamlStorage extends InvConfStorage {
|
|||
|
||||
@Override
|
||||
public void load(Inventory pinv, Target target) {
|
||||
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target, false)));
|
||||
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,11 +52,7 @@ public class InvYamlStorage extends InvConfStorage {
|
|||
yml.options().header("DO NOT MODIFY THIS FILE");
|
||||
store(pinv, yml);
|
||||
try {
|
||||
File nameFile=getFile(pinv, target, false);
|
||||
File uuidFile=getFile(pinv, target, true);
|
||||
if(!nameFile.equals(uuidFile)) //It'd be recreated right after, still, don't remove if the same
|
||||
nameFile.delete(); //Delete file with name so it doesn't get loaded again
|
||||
yml.save(uuidFile);
|
||||
yml.save(getFile(pinv, target));
|
||||
} catch (IOException e) {
|
||||
mod.getLog().warn("Failed to save Inventory for Player " + pinv.getPlayer().getName());
|
||||
e.printStackTrace();
|
||||
|
@ -65,28 +61,19 @@ public class InvYamlStorage extends InvConfStorage {
|
|||
|
||||
@Override
|
||||
public void remove(Inventory pinv, Target target) {
|
||||
getFile(pinv, target, true).delete();
|
||||
getFile(pinv, target).delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Inventory pinv, Target target) {
|
||||
return getFile(pinv, target, false).exists();
|
||||
return getFile(pinv, target).exists();
|
||||
}
|
||||
|
||||
protected File getFile(Inventory pinv, Target target, boolean uuidonly) {
|
||||
File file;
|
||||
String player;
|
||||
do {
|
||||
player = uuidonly ? pinv.getPlayer().getUniqueId().toString() : pinv.getPlayer().getName();
|
||||
if (target != default_target) {
|
||||
file = new File(dir, player + "_" + target.toString().toLowerCase() + SUFFIX);
|
||||
} else {
|
||||
file = new File(dir, player + SUFFIX);
|
||||
}
|
||||
if(uuidonly)
|
||||
return file; //Use file with UUID, even if doesn't exist
|
||||
uuidonly = true; //Run again with UUID, then return...
|
||||
} while(!file.exists()); //...if the file with name is not found
|
||||
return file; //Found file with player name
|
||||
protected File getFile(Inventory pinv, Target target) {
|
||||
if (target != default_target) {
|
||||
return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX);
|
||||
} else {
|
||||
return new File(dir, pinv.getPlayer().getName() + SUFFIX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,217 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.inventories.store;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
import de.jaschastarke.bukkit.lib.ModuleLogger;
|
||||
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class ReflectionStorage extends PlayerInventoryStorage {
|
||||
private CoreModule<?> mod;
|
||||
private File dir;
|
||||
private String nms;
|
||||
private InvYamlStorage yamlStorage;
|
||||
|
||||
public ReflectionStorage(CoreModule<?> mod, File file) {
|
||||
this.mod = mod;
|
||||
dir = file;
|
||||
yamlStorage = new InvYamlStorage(mod, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLogger getLog() {
|
||||
return mod.getLog();
|
||||
}
|
||||
|
||||
private File getFile(UUID uuid) {
|
||||
return new File(dir, uuid.toString() + "_ref.yml");
|
||||
}
|
||||
|
||||
private Object getInventory(Player player) throws Exception {
|
||||
org.bukkit.inventory.Inventory inv = player.getInventory();
|
||||
if (getInventory == null)
|
||||
getInventory = inv.getClass().getMethod("getInventory");
|
||||
Object handle = getInventory.invoke(inv);
|
||||
if (nms == null)
|
||||
nms = handle.getClass().getPackage().getName();
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Inventory pinv, Inventory.Target target) {
|
||||
try {
|
||||
File f = getFile(pinv.getPlayer().getUniqueId());
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
|
||||
config.set(target.name(), serialize(getInventory(pinv.getPlayer())));
|
||||
config.save(f);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Method getInventory;
|
||||
|
||||
@Override
|
||||
public void load(Inventory pinv, Inventory.Target target) {
|
||||
Player player = pinv.getPlayer();
|
||||
try {
|
||||
File f = getFile(player.getUniqueId());
|
||||
if (!f.exists()) { //If not found use the older file(s)
|
||||
yamlStorage.load(pinv, target);
|
||||
return;
|
||||
}
|
||||
//String content = new String(Files.readAllBytes(f.toPath()));
|
||||
Configuration config = YamlConfiguration.loadConfiguration(f);
|
||||
String content = config.getString(target.name());
|
||||
if (content == null) {
|
||||
yamlStorage.load(pinv, target);
|
||||
return;
|
||||
}
|
||||
setFromSerialized(getInventory(player), content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Inventory pinv, Inventory.Target target) {
|
||||
File f = getFile(pinv.getPlayer().getUniqueId());
|
||||
if (!f.exists()) return;
|
||||
Configuration config = YamlConfiguration.loadConfiguration(f);
|
||||
config.set(target.name(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Inventory pinv, Inventory.Target target) {
|
||||
File f = getFile(pinv.getPlayer().getUniqueId());
|
||||
if (!f.exists()) return yamlStorage.contains(pinv, target);
|
||||
Configuration config = YamlConfiguration.loadConfiguration(f);
|
||||
return config.contains(target.name()) || yamlStorage.contains(pinv, target);
|
||||
}
|
||||
|
||||
//Based on iie's per-world inventory
|
||||
//https://github.com/TBMCPlugins/iiePerWorldInventory/blob/master/src/buttondevteam/perworld/serializers/inventory.java
|
||||
|
||||
private Method save;
|
||||
private Class<?> nbtcl;
|
||||
private Method nbtcsta;
|
||||
private Class<?> nbtcstcl;
|
||||
|
||||
//SERIALIZE ITEMSTACK
|
||||
private String serializeItemStack(Object itemStack) throws Exception {
|
||||
if (nbtcl == null)
|
||||
nbtcl = Class.forName(nms + ".NBTTagCompound");
|
||||
if (save == null)
|
||||
save = itemStack.getClass().getMethod("save", nbtcl);
|
||||
if (nbtcstcl == null)
|
||||
nbtcstcl = Class.forName(nms + ".NBTCompressedStreamTools");
|
||||
if (nbtcsta == null)
|
||||
nbtcsta = nbtcstcl.getMethod("a", nbtcl, OutputStream.class);
|
||||
Object tag = save.invoke(itemStack, nbtcl.newInstance());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
nbtcsta.invoke(null, tag, outputStream);
|
||||
|
||||
return Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||
}
|
||||
|
||||
|
||||
private Method nbtcstaa;
|
||||
private Function<Object, Object> createStack;
|
||||
|
||||
//DESERIALIZE ITEMSTACK
|
||||
private Object deserializeItemStack(String itemStackString) throws Exception {
|
||||
if (nbtcstcl == null)
|
||||
nbtcstcl = Class.forName(nms + ".NBTCompressedStreamTools");
|
||||
if (nbtcstaa == null)
|
||||
nbtcstaa = nbtcstcl.getMethod("a", InputStream.class);
|
||||
if (nbtcl == null)
|
||||
nbtcl = Class.forName(nms + ".NBTTagCompound");
|
||||
try {
|
||||
if (createStack == null) {
|
||||
final Method a = iscl.getMethod("a", nbtcl);
|
||||
createStack = nbt -> {
|
||||
try {
|
||||
return a.invoke(null, nbt);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (NoSuchMethodException ex) { //It can only get here inside the if
|
||||
final Constructor<?> constructor = iscl.getConstructor(nbtcl);
|
||||
createStack = nbt -> {
|
||||
try {
|
||||
return constructor.newInstance(nbt);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64.getDecoder().decode(itemStackString));
|
||||
|
||||
Object nbtTagCompound = nbtcstaa.invoke(null, inputStream);
|
||||
return createStack.apply(nbtTagCompound);
|
||||
}
|
||||
|
||||
private Method getSize;
|
||||
private Method getItem;
|
||||
|
||||
//SERIALIZE INVENTORY
|
||||
private String serialize(Object invInventory) throws Exception {
|
||||
if (getSize == null)
|
||||
getSize = invInventory.getClass().getMethod("getSize");
|
||||
if (getItem == null)
|
||||
getItem = invInventory.getClass().getMethod("getItem", int.class);
|
||||
return IntStream.range(0, (int) getSize.invoke(invInventory))
|
||||
.mapToObj(s -> {
|
||||
try {
|
||||
//nms ItemStack
|
||||
Object i = getItem.invoke(invInventory, s);
|
||||
return Objects.isNull(i) ? null : s + "#" + serializeItemStack(i);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(";"));
|
||||
}
|
||||
|
||||
private Method clear;
|
||||
private Method setItem;
|
||||
private Class<?> iscl;
|
||||
|
||||
//SET INVENTORY FROM SERIALIZED
|
||||
private void setFromSerialized(Object invInventory, String invString) throws Exception {
|
||||
if (clear == null)
|
||||
clear = invInventory.getClass().getMethod("clear");
|
||||
if (iscl == null)
|
||||
iscl = Class.forName(nms + ".ItemStack");
|
||||
if (setItem == null)
|
||||
setItem = invInventory.getClass().getMethod("setItem", int.class, iscl);
|
||||
clear.invoke(invInventory); //clear inventory
|
||||
if (invString != null && !invString.isEmpty())
|
||||
Arrays.asList(invString.split(";"))
|
||||
.parallelStream()
|
||||
.forEach(s -> {
|
||||
String[] e = s.split("#");
|
||||
try {
|
||||
setItem.invoke(invInventory, Integer.parseInt(e[0]), deserializeItemStack(e[1]));
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -11,14 +11,12 @@ import org.bukkit.material.MaterialData;
|
|||
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurableList;
|
||||
import de.jaschastarke.bukkit.lib.configuration.IToGeneric;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ITabComplete;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ListConfigValue;
|
||||
import de.jaschastarke.bukkit.lib.items.ItemUtils;
|
||||
import de.jaschastarke.bukkit.lib.items.MaterialDataNotRecognizedException;
|
||||
import de.jaschastarke.bukkit.lib.items.MaterialNotRecognizedException;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
|
||||
public class BlackList extends ArrayList<BlackList.Blacklisted> implements ConfigurableList<BlackList.Blacklisted>, IToGeneric, ITabComplete {
|
||||
public class BlackList extends ArrayList<BlackList.Blacklisted> implements ConfigurableList<BlackList.Blacklisted>, IToGeneric {
|
||||
private static final long serialVersionUID = -3701659163474405152L;
|
||||
|
||||
public static class Blacklisted {
|
||||
|
@ -32,9 +30,9 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
md = ItemUtils.parseMaterial(rep);
|
||||
hasData = rep.contains(ItemUtils.MATERIAL_DATA_SEP);
|
||||
} catch (MaterialNotRecognizedException e) {
|
||||
throw new InvalidValueException("Invalid Material: " + rep, e);
|
||||
throw new InvalidValueException(e);
|
||||
} catch (MaterialDataNotRecognizedException e) {
|
||||
throw new InvalidValueException("Invalid Material with Data: " + rep, e);
|
||||
throw new InvalidValueException(e);
|
||||
}
|
||||
}
|
||||
public Blacklisted(Material m) {
|
||||
|
@ -55,7 +53,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
}
|
||||
public boolean matches(Block block) {
|
||||
if (hasData) {
|
||||
return md.equals(block.getState().getData());
|
||||
return md.equals(new MaterialData(block.getType(), block.getData()));
|
||||
} else {
|
||||
return block.getType().equals(md.getItemType());
|
||||
}
|
||||
|
@ -76,8 +74,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
add((Blacklisted) el);
|
||||
} else {
|
||||
try {
|
||||
if (el != null)
|
||||
addSetting(el.toString());
|
||||
add(el.toString());
|
||||
} catch (InvalidValueException e) {
|
||||
System.err.println(e.getCause().getMessage());
|
||||
}
|
||||
|
@ -110,15 +107,14 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean addSetting(String e) throws InvalidValueException {
|
||||
public void add(String e) throws InvalidValueException {
|
||||
if (!contains(e)) {
|
||||
return add(new Blacklisted(e));
|
||||
add(new Blacklisted(e));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean removeSetting(String e) {
|
||||
public boolean remove(String e) {
|
||||
Iterator<Blacklisted> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().toString().equalsIgnoreCase(e)) {
|
||||
|
@ -141,32 +137,4 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
public List<String> toGeneric() {
|
||||
return toStringList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSettings() {
|
||||
clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(String[] args, String[] chain) {
|
||||
if (args.length > 0 && chain.length > 0) {
|
||||
List<String> hints = new ArrayList<String>();
|
||||
String action = chain[chain.length - 1];
|
||||
if (action.equalsIgnoreCase(ListConfigValue.ADD)) {
|
||||
for (Material m : Material.values()) {
|
||||
if (m.name().toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||
hints.add(m.name());
|
||||
}
|
||||
}
|
||||
} else if (action.equalsIgnoreCase(ListConfigValue.REMOVE)) {
|
||||
for (Blacklisted bl : this) {
|
||||
if (bl.toString().toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||
hints.add(bl.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return hints;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ITabComplete;
|
||||
import de.jaschastarke.bukkit.lib.configuration.command.ListConfigValue;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
@ -13,32 +11,9 @@ import de.jaschastarke.bukkit.lib.configuration.ConfigurableList;
|
|||
import de.jaschastarke.bukkit.lib.configuration.IToGeneric;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
|
||||
public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> implements ConfigurableList<BlackListEntity.Blacklisted>, IToGeneric, ITabComplete {
|
||||
public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> implements ConfigurableList<BlackListEntity.Blacklisted>, IToGeneric {
|
||||
private static final long serialVersionUID = 6150727863411513873L;
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(String[] args, String[] chain) {
|
||||
if (args.length > 0 && chain.length > 0) {
|
||||
List<String> hints = new ArrayList<String>();
|
||||
String action = chain[chain.length - 1];
|
||||
if (action.equalsIgnoreCase(ListConfigValue.ADD)) {
|
||||
for (EntityType m : EntityType.values()) {
|
||||
if (m.name().toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||
hints.add(m.name());
|
||||
}
|
||||
}
|
||||
} else if (action.equalsIgnoreCase(ListConfigValue.REMOVE)) {
|
||||
for (Blacklisted bl : this) {
|
||||
if (bl.toString().toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||
hints.add(bl.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return hints;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Blacklisted {
|
||||
private String stringRep;
|
||||
private EntityType type;
|
||||
|
@ -52,7 +27,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
type = null;
|
||||
}
|
||||
if (type == null)
|
||||
type = EntityType.valueOf(rep);
|
||||
type = EntityType.fromName(rep);
|
||||
try {
|
||||
if (type == null)
|
||||
type = EntityType.valueOf(rep);
|
||||
|
@ -61,7 +36,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
}
|
||||
|
||||
if (type == null)
|
||||
throw new InvalidValueException("Entity '" + rep + "' not found");
|
||||
throw new InvalidValueException("Entity '" + stringRep + "' not found");
|
||||
stringRep = rep;
|
||||
}
|
||||
public Blacklisted(EntityType et) {
|
||||
|
@ -91,8 +66,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
add((Blacklisted) el);
|
||||
} else {
|
||||
try {
|
||||
if (el != null)
|
||||
addSetting(el.toString());
|
||||
add(el.toString());
|
||||
} catch (InvalidValueException e) {
|
||||
System.err.println((e.getCause() != null ? e.getCause() : e).getMessage());
|
||||
}
|
||||
|
@ -125,15 +99,14 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean addSetting(String e) throws InvalidValueException {
|
||||
public void add(String e) throws InvalidValueException {
|
||||
if (!contains(e)) {
|
||||
return add(new Blacklisted(e));
|
||||
add(new Blacklisted(e));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean removeSetting(String e) {
|
||||
public boolean remove(String e) {
|
||||
Iterator<Blacklisted> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().toString().equalsIgnoreCase(e)) {
|
||||
|
@ -156,9 +129,4 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
public List<String> toGeneric() {
|
||||
return toStringList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSettings() {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,6 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.events.AttachedBlockDestroyedByPlayerEvent;
|
||||
import de.jaschastarke.bukkit.lib.events.HangingBreakByPlayerBlockEvent;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IDynamicPermission;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits;
|
||||
|
||||
|
@ -36,9 +33,9 @@ public class BlockListener implements Listener {
|
|||
this.mod = mod;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (mod.getConfig().getBlockBreak().isListed(event.getBlock())) {
|
||||
if (!checkPermission(event.getPlayer(), NoLimitPermissions.BREAK(event.getBlock()))) {
|
||||
event.setCancelled(true);
|
||||
|
@ -47,9 +44,9 @@ public class BlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (mod.getConfig().getBlockUse().isListed(event.getBlock())) {
|
||||
if (!checkPermission(event.getPlayer(), NoLimitPermissions.USE(event.getBlock()))) {
|
||||
event.setCancelled(true);
|
||||
|
@ -58,29 +55,8 @@ public class BlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onAttachedBlockBreak(AttachedBlockDestroyedByPlayerEvent event) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Attached Block " + event.getBlock().getType() + " initial destroyed by player: " + event.getPlayer().getName() + " in GM " + event.getPlayer().getGameMode().toString());
|
||||
if (event.getPlayer() != null && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!checkPermission(event.getPlayer(), NoLimitPermissions.DROP)) {
|
||||
mod.getBlockSpawn().block(event.getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onHangingBreakByPlayer(HangingBreakByPlayerBlockEvent event) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("Attached Hanging " + event.getEntity().getType() + " destroyed by player block place/break: " + event.getPlayer().getName() + " in GM " + event.getPlayer().getGameMode().toString());
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
event.getDrops().clear();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player, IDynamicPermission perm) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||
}
|
||||
private boolean checkPermission(Player player, IAbstractPermission perm) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.bukkit.entity.Creature;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
|
@ -50,20 +49,6 @@ public class EntityListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
if (event.getEntity() != null && event.getDroppedExp() > 0) {
|
||||
if (mod.getNoDropMobs().isXPPrevented(event.getEntity())) {
|
||||
event.setDroppedExp(0);
|
||||
event.getDrops().clear();
|
||||
}
|
||||
}
|
||||
if (event.getDrops().size() > 0 && mod.getNoDropMobs().isDropPrevented(event.getEntity())) {
|
||||
event.getDrops().clear();
|
||||
}
|
||||
mod.getNoDropMobs().remove(event.getEntity());
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player, IAbstractPermission perm) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.limits;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class EntityNoDrop {
|
||||
private Map<Entity, Prevent> nodrop = new WeakHashMap<Entity, Prevent>();
|
||||
|
||||
private Prevent get(Entity entity) {
|
||||
if (!nodrop.containsKey(entity))
|
||||
nodrop.put(entity, new Prevent());
|
||||
return nodrop.get(entity);
|
||||
}
|
||||
|
||||
public void preventXP(Entity entity) {
|
||||
get(entity).xp = true;
|
||||
}
|
||||
public void preventDrop(Entity entity) {
|
||||
get(entity).drops = true;
|
||||
}
|
||||
public boolean isXPPrevented(Entity entity) {
|
||||
return nodrop.containsKey(entity) && nodrop.get(entity).xp;
|
||||
}
|
||||
public boolean isDropPrevented(Entity entity) {
|
||||
return nodrop.containsKey(entity) && nodrop.get(entity).drops;
|
||||
}
|
||||
public void remove(Entity entity) {
|
||||
nodrop.remove(entity);
|
||||
}
|
||||
|
||||
private class Prevent {
|
||||
boolean xp = false;
|
||||
boolean drops = false;
|
||||
}
|
||||
}
|
|
@ -5,18 +5,16 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.bukkit.lib.configuration.IToGeneric;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Config;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
/**
|
||||
* Creative Limits-Feature
|
||||
|
@ -24,22 +22,13 @@ import de.jaschastarke.modularize.ModuleEntry;
|
|||
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/limit/
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = Config.class)
|
||||
public class LimitConfig extends Configuration implements IConfigurationSubGroup {
|
||||
private BlackList breakList;
|
||||
private BlackListEntity interactEntityList;
|
||||
private BlackList interactList;
|
||||
private BlackList useList;
|
||||
|
||||
|
||||
protected ModCreativeLimits mod;
|
||||
protected ModuleEntry<IModule> entry;
|
||||
|
||||
public LimitConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public LimitConfig(ModCreativeLimits modCreativeLimits, ModuleEntry<IModule> modEntry) {
|
||||
super(modCreativeLimits.getPlugin().getDocCommentStorage());
|
||||
mod = modCreativeLimits;
|
||||
public LimitConfig(ModCreativeLimits modInventories, ModuleEntry<IModule> modEntry) {
|
||||
mod = modInventories;
|
||||
entry = modEntry;
|
||||
}
|
||||
|
||||
|
@ -48,18 +37,20 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
if (!(pValue instanceof BlackList))
|
||||
super.setValue(node, pValue);
|
||||
if (node.getName().equals("enabled")) {
|
||||
entry.setEnabled(getEnabled());
|
||||
if (getEnabled()) {
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.enable();
|
||||
} else {
|
||||
entry.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(ConfigurationSection sect) {
|
||||
breakList = null;
|
||||
interactEntityList = null;
|
||||
interactList = null;
|
||||
useList = null;
|
||||
super.setValues(sect);
|
||||
entry.setDefaultEnabled(getEnabled());
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
|
||||
|
||||
// Config Upgrade
|
||||
if (!sect.contains("interact") && sect.contains("sign")) {
|
||||
|
@ -101,7 +92,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
* - dropping items from "inventory" to the ground
|
||||
* - doing PvP (wouldn't be fair, would it?)
|
||||
*
|
||||
* Also if this option is disabled all other Limit-Options below are disabled too. To just disable some of these
|
||||
* Also if this option is disabled all other Limit-Options below are disabled too. To just disable some of these
|
||||
* limitations, use the "nolimit"-permissions.
|
||||
*
|
||||
* default: true
|
||||
|
@ -114,18 +105,18 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
/**
|
||||
* LimitDropsInsteadPrevent
|
||||
*
|
||||
* When enabled items that are dropped by creative players are removed (burning in the hellfire or such, they just
|
||||
* When enabled items that are dropped by creative players are removed (burning in the hellfire or so, they just
|
||||
* disappear). When disabled the items stay in the inventory of the player.
|
||||
*
|
||||
* default: true
|
||||
* default: false
|
||||
*/
|
||||
@IsConfigurationNode(order = 200)
|
||||
public boolean getRemoveDrops() {
|
||||
return config.getBoolean("removeDrops", true);
|
||||
return config.getBoolean("removeDrops", false);
|
||||
}
|
||||
|
||||
|
||||
public enum BlockPickup implements IToGeneric {
|
||||
public static enum BlockPickup implements IToGeneric {
|
||||
PREVENT,
|
||||
REMOVE;
|
||||
|
||||
|
@ -138,7 +129,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
/**
|
||||
* LimitDamageToMobs
|
||||
*
|
||||
* Prevents dealing damage to all creatures when the player is in creative (friendly sheeps as well as hostile
|
||||
* Prevents dealing damage to all creatures when the player is in creative (friendly sheeps as well as hostile
|
||||
* creepers).
|
||||
*
|
||||
* default: false
|
||||
|
@ -152,11 +143,12 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
/**
|
||||
* LimitPickup
|
||||
*
|
||||
* Prevents the pickup of items while in creative mode. Either the items are just stay on ground and ignore that a
|
||||
* creative player walks over it ("prevent"), or the are "remove"d when a creative player walks over it.
|
||||
* Prevents the pickup of items while in creative mode. Either the items are just stay on ground and ignore that a
|
||||
* creative player walks over it ("prevent"), or the are "remove"d when a creative player walks over it. This is
|
||||
* helpful e.g. when the creative player destroys a long line of rails.
|
||||
*
|
||||
* valid options: remove / prevent / false
|
||||
* default: prevent
|
||||
* default: remove
|
||||
*/
|
||||
@IsConfigurationNode(name = "pickup", order = 300)
|
||||
public BlockPickup getBlockPickup() {
|
||||
|
@ -168,21 +160,28 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
return getEnum(BlockPickup.class, "pickup", BlockPickup.PREVENT);
|
||||
}
|
||||
|
||||
|
||||
private BlackList interactList;
|
||||
/**
|
||||
* LimitInteraction
|
||||
*
|
||||
* Prevents players of interacting with specific blocks as addition to chests in creative mode (and only in
|
||||
* Prevents players of interacting with specific blocks as addition to chests in creative mode (and only in
|
||||
* creative).
|
||||
*
|
||||
* You can use the technical name (http://public.ja-s.de/bukkit/material) or
|
||||
* the id of the block/item (better use the id, if you're not sure). You may add the data separated with a colon
|
||||
* e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to not break yml-configuration! Named data
|
||||
* You can use the technical name (http://tinyurl.com/bukkit-material) or
|
||||
* the id of the block/item (better use the id, if you're not sure). You may add the data separated with a colon
|
||||
* e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to not break yml-configuration! Named data
|
||||
* values aren't supported yet. If you don't add a data-value, all blocks of this material are blocked.
|
||||
*
|
||||
* default:
|
||||
* - WALL_SIGN
|
||||
* - SIGN
|
||||
* - SIGN_POST
|
||||
* - JUKEBOX
|
||||
* - LEVER
|
||||
* - STONE_BUTTON
|
||||
* - WOOD_BUTTON
|
||||
* - WORKBENCH
|
||||
* - ANVIL
|
||||
* - ENCHANTMENT_TABLE
|
||||
*/
|
||||
@IsConfigurationNode(name = "interact", order = 600)
|
||||
public BlackList getBlockInteraction() {
|
||||
|
@ -191,21 +190,30 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
if (!config.contains("interact")) {
|
||||
interactList.add(new BlackList.Blacklisted(Material.WALL_SIGN));
|
||||
interactList.add(new BlackList.Blacklisted(Material.SIGN_POST));
|
||||
interactList.add(new BlackList.Blacklisted(Material.JUKEBOX));
|
||||
interactList.add(new BlackList.Blacklisted(Material.LEVER));
|
||||
interactList.add(new BlackList.Blacklisted(Material.STONE_BUTTON));
|
||||
interactList.add(new BlackList.Blacklisted(Material.WOOD_BUTTON));
|
||||
interactList.add(new BlackList.Blacklisted(Material.WORKBENCH));
|
||||
interactList.add(new BlackList.Blacklisted(Material.ANVIL));
|
||||
interactList.add(new BlackList.Blacklisted(Material.ENCHANTMENT_TABLE));
|
||||
}
|
||||
}
|
||||
return interactList;
|
||||
}
|
||||
|
||||
private BlackListEntity interactEntityList;
|
||||
/**
|
||||
* LimitEntityInteraction
|
||||
*
|
||||
* Prevents players of interacting with specific entities in creative mode (and only in creative).
|
||||
*
|
||||
* You can use the technical name (see http://tinyurl.com/bukkit-entity) or the id of the entity (better use the id,
|
||||
* You can use the technical name (see http://tinyurl.com/bukkit-entity) or the id of the entity (better use the id,
|
||||
* if you're not sure).
|
||||
*
|
||||
* default:
|
||||
* - MINECART_CHEST
|
||||
* - MINECART_FURNACE
|
||||
* - MINECART_HOPPER
|
||||
* - ITEM_FRAME
|
||||
* - VILLAGER
|
||||
*/
|
||||
@IsConfigurationNode(name = "entityInteract", order = 650)
|
||||
|
@ -213,25 +221,29 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
if (interactEntityList == null) {
|
||||
interactEntityList = new BlackListEntity(config.getList("entityInteract"));
|
||||
if (!config.contains("entityInteract")) {
|
||||
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.MINECART_CHEST));
|
||||
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.MINECART_FURNACE));
|
||||
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.MINECART_HOPPER));
|
||||
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.ITEM_FRAME));
|
||||
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.VILLAGER));
|
||||
}
|
||||
}
|
||||
return interactEntityList;
|
||||
}
|
||||
|
||||
private BlackList useList;
|
||||
/**
|
||||
* LimitUse
|
||||
*
|
||||
* Prevents players of using or placing specific items/blocks in creative mode (and only in creative).
|
||||
*
|
||||
* You can use the technical name (see http://public.ja-s.de/bukkit/material) or
|
||||
* the id of the block/item (better use the id, if you're not sure). You may add the data separated with a colon
|
||||
* e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to not break yml-configuration! Named data
|
||||
* You can use the technical name (see http://jd.bukkit.org/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html) or
|
||||
* the id of the block/item (better use the id, if you're not sure). You may add the data separated with a colon
|
||||
* e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to not break yml-configuration! Named data
|
||||
* values aren't supported yet. If you don't add a data-value, all blocks of this material are blocked.
|
||||
*
|
||||
* default:
|
||||
* - EXP_BOTTLE
|
||||
* - EYE_OF_ENDER
|
||||
* - BEDROCK
|
||||
*/
|
||||
@IsConfigurationNode(name = "use", order = 700)
|
||||
|
@ -240,21 +252,21 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
useList = new BlackList(config.getList("use"));
|
||||
if (!config.contains("use")) {
|
||||
useList.add(new BlackList.Blacklisted(Material.EXP_BOTTLE));
|
||||
useList.add(new BlackList.Blacklisted(Material.EYE_OF_ENDER));
|
||||
useList.add(new BlackList.Blacklisted(Material.BEDROCK));
|
||||
}
|
||||
}
|
||||
return useList;
|
||||
}
|
||||
|
||||
private BlackList breakList;
|
||||
/**
|
||||
* LimitBreak
|
||||
*
|
||||
* Prevents players of destroying specific blocks in creative mode (and only in creative).
|
||||
*
|
||||
* You can use the technical name (see http://public.ja-s.de/bukkit/material) or
|
||||
* the id of the block/item (better use the id, if you're not sure). You may add the data separated with a colon
|
||||
* e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to not break yml-configuration! Named data
|
||||
* You can use the technical name (see http://jd.bukkit.org/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html) or
|
||||
* the id of the block/item (better use the id, if you're not sure). You may add the data separated with a colon
|
||||
* e.g.: "WOOL:11" blocks blue wool. But be sure to put it in quotes, to not break yml-configuration! Named data
|
||||
* values aren't supported yet. If you don't add a data-value, all blocks of this material are blocked.
|
||||
*
|
||||
* default:
|
||||
|
@ -270,26 +282,13 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
|||
}
|
||||
return breakList;
|
||||
}
|
||||
|
||||
/**
|
||||
* LimitChestOpen
|
||||
*
|
||||
* Enable this to prevents the ChestOpening-Animination when blocking interaction with a chest. But therefore
|
||||
* you're no longer able to place blocks on chest and such while crouching.
|
||||
*
|
||||
* default: false
|
||||
*/
|
||||
@IsConfigurationNode(name = "chestOpen", order = 900)
|
||||
public boolean getBlockChestInteraction() {
|
||||
return config.getBoolean("chestOpen", false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getValue(final IConfigurationNode node) {
|
||||
Object val = super.getValue(node);
|
||||
if (node.getName().equals("pickup") && val == null) {
|
||||
return false;
|
||||
return new Boolean(false);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -20,13 +20,10 @@ package de.jaschastarke.minecraft.limitedcreative.limits;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.DynamicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
|
@ -44,7 +41,7 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
|
|||
super(parent, name);
|
||||
}
|
||||
|
||||
@PluginPermissions
|
||||
|
||||
public static final IPermissionContainer PARENT = new NoLimitPermissions(Permissions.CONTAINER, "nolimit");
|
||||
|
||||
/**
|
||||
|
@ -53,7 +50,7 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
|
|||
public static final IPermission ALL = new ParentPermissionContainerNode(PARENT, "*", PermissionDefault.OP, PARENT);
|
||||
|
||||
/**
|
||||
* Allows bypassing the "do not open a chest" and "do not open inventory"-limitation
|
||||
* Allows bypassing the "do not open a chest"-limitation
|
||||
*/
|
||||
@IsChildPermission
|
||||
public static final IPermission CHEST = new BasicPermission(PARENT, "chest", PermissionDefault.FALSE);
|
||||
|
@ -93,56 +90,19 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
|
|||
@IsChildPermission
|
||||
public static final IPermission BASE_BREAK = new BasicPermission(PARENT, "break", PermissionDefault.FALSE);
|
||||
|
||||
/**
|
||||
* Allows bypassing the "don't change heal/food-state"-limitation
|
||||
*/
|
||||
@IsChildPermission
|
||||
public static final IPermission STATS_HEALTH = new BasicPermission(PARENT, "health", PermissionDefault.FALSE);
|
||||
|
||||
/**
|
||||
* Allows bypassing the "don't get xp/level"-limitation
|
||||
*/
|
||||
@IsChildPermission
|
||||
public static final IPermission STATS_XP = new BasicPermission(PARENT, "xp", PermissionDefault.FALSE);
|
||||
|
||||
/**
|
||||
* Allows bypassing the "remove all effects on leaving creative"-limitation
|
||||
*/
|
||||
@IsChildPermission
|
||||
public static final IPermission STATS_POTION = new BasicPermission(PARENT, "potion", PermissionDefault.FALSE);
|
||||
|
||||
public static IDynamicPermission INVENTORY(Inventory inv) {
|
||||
return new InventoryPermission(CHEST, inv.getType());
|
||||
}
|
||||
public static IDynamicPermission INVENTORY(InventoryType invtype) {
|
||||
return new InventoryPermission(CHEST, invtype);
|
||||
}
|
||||
public static IDynamicPermission INTERACT(Block block) {
|
||||
return new MaterialPermission(BASE_INTERACT, block.getState().getData());
|
||||
return new MaterialPermission(BASE_INTERACT, new MaterialData(block.getType(), block.getData()));
|
||||
}
|
||||
public static IDynamicPermission USE(Block block) {
|
||||
return new MaterialPermission(BASE_USE, block.getState().getData());
|
||||
return new MaterialPermission(BASE_USE, new MaterialData(block.getType(), block.getData()));
|
||||
}
|
||||
public static IDynamicPermission USE(MaterialData m) {
|
||||
return new MaterialPermission(BASE_USE, m);
|
||||
}
|
||||
public static IDynamicPermission BREAK(Block block) {
|
||||
return new MaterialPermission(BASE_BREAK, block.getState().getData());
|
||||
return new MaterialPermission(BASE_BREAK, new MaterialData(block.getType(), block.getData()));
|
||||
}
|
||||
|
||||
|
||||
public static class InventoryPermission extends DynamicPermission {
|
||||
private InventoryType it;
|
||||
public InventoryPermission(IAbstractPermission parent, InventoryType t) {
|
||||
super(parent);
|
||||
it = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPermissionsToCheck(Collection<IAbstractPermission> perms) {
|
||||
perms.add(new BasicPermission(parent, it.toString()));
|
||||
}
|
||||
}
|
||||
public static class MaterialPermission extends DynamicPermission {
|
||||
private MaterialData md;
|
||||
public MaterialPermission(IAbstractPermission parent, MaterialData m) {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.limits;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
@ -26,19 +25,19 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.BeaconInventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.material.DirectionalContainer;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IDynamicPermission;
|
||||
|
@ -58,7 +57,7 @@ public class PlayerListener implements Listener {
|
|||
* @return The relevant "isCancelled"
|
||||
*/
|
||||
public static boolean isCancelled(PlayerInteractEvent event) {
|
||||
return (event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY);
|
||||
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -67,24 +66,8 @@ public class PlayerListener implements Listener {
|
|||
if (checkPermission(event, NoLimitPermissions.DROP))
|
||||
return;
|
||||
|
||||
if (mod.getConfig().getRemoveDrops())
|
||||
event.getItemDrop().remove();
|
||||
else
|
||||
event.setCancelled(true); // doesn't make much sense
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (event.getPlayer() instanceof Player) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (!mod.getConfig().getBlockChestInteraction()) {
|
||||
if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory())))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory"));
|
||||
}
|
||||
}
|
||||
event.getItemDrop().remove();
|
||||
//event.setCancelled(true); // doesn't make much sense
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +88,7 @@ public class PlayerListener implements Listener {
|
|||
if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
LimitConfig.BlockPickup pickup = mod.getConfig().getBlockPickup();
|
||||
if (pickup != null) {
|
||||
if (checkPermission(event, NoLimitPermissions.PICKUP))
|
||||
if (checkPermission(event, NoLimitPermissions.DROP))
|
||||
return;
|
||||
|
||||
if (pickup == BlockPickup.REMOVE) {
|
||||
|
@ -117,48 +100,6 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangeExp(PlayerExpChangeEvent event) {
|
||||
if (event.getAmount() > 0 && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (checkPermission(event, NoLimitPermissions.STATS_XP))
|
||||
return;
|
||||
event.setAmount(0);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
if (!event.isCancelled() && ((Player) event.getEntity()).getGameMode() == GameMode.CREATIVE) {
|
||||
if (checkPermission((Player) event.getEntity(), NoLimitPermissions.STATS_HEALTH))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
if (!event.isCancelled() && ((Player) event.getEntity()).getGameMode() == GameMode.CREATIVE) {
|
||||
if (checkPermission((Player) event.getEntity(), NoLimitPermissions.STATS_HEALTH))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onGameMode(PlayerGameModeChangeEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if ((event.getPlayer().getGameMode() == GameMode.CREATIVE) && (event.getNewGameMode() != GameMode.CREATIVE)) {
|
||||
if (checkPermission(event, NoLimitPermissions.STATS_POTION))
|
||||
return;
|
||||
for (PotionEffect effect : event.getPlayer().getActivePotionEffects()) {
|
||||
event.getPlayer().removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler // Do not use ignoreCancelled here, as some AIR-Interacts are interpreted as isCancelled by default
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!isCancelled(event) && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (event.getItem() != null && mod.getConfig().getBlockUse().isListed(event.getItem())) {
|
||||
|
@ -176,15 +117,17 @@ public class PlayerListener implements Listener {
|
|||
// when crouching.
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (mod.getConfig().getBlockChestInteraction() && isChest(block)) {
|
||||
if (isChest(block)) {
|
||||
if (!checkPermission(event, NoLimitPermissions.CHEST)) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.chest"));
|
||||
return;
|
||||
}
|
||||
} else if (mod.getConfig().getBlockInteraction().isListed(block)) {
|
||||
if (!checkPermission(event, NoLimitPermissions.INTERACT(block))) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.interact"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,8 +137,8 @@ public class PlayerListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||
if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getInventory().getItemInMainHand().getData()))) {
|
||||
if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getItemInHand())) {
|
||||
if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getItemInHand().getData()))) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.use"));
|
||||
return;
|
||||
|
@ -206,24 +149,20 @@ public class PlayerListener implements Listener {
|
|||
if (!checkPermission(event, NoLimitPermissions.BASE_INTERACT)) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.entity"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
|
||||
onPlayerInteractEntity(event);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityDamageByEntity(EntityDamageEvent rawevent) {
|
||||
if (rawevent instanceof EntityDamageByEntityEvent && !rawevent.isCancelled()) {
|
||||
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) rawevent;
|
||||
|
||||
Entity source = event.getDamager();
|
||||
if (source instanceof Projectile && ((Projectile) source).getShooter() instanceof Entity)
|
||||
source = (Entity) ((Projectile) source).getShooter();
|
||||
if (source instanceof Projectile)
|
||||
source = ((Projectile) source).getShooter();
|
||||
|
||||
if (source instanceof Player) {
|
||||
Player player = (Player) source;
|
||||
|
@ -236,15 +175,6 @@ public class PlayerListener implements Listener {
|
|||
if (!checkPermission(player, NoLimitPermissions.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getEntity() instanceof LivingEntity) {
|
||||
if (!checkPermission(player, NoLimitPermissions.STATS_XP)) {
|
||||
mod.getNoDropMobs().preventXP(event.getEntity());
|
||||
}
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
if (!checkPermission(player, NoLimitPermissions.DROP)) {
|
||||
mod.getNoDropMobs().preventDrop(event.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,9 +186,8 @@ public class PlayerListener implements Listener {
|
|||
*/
|
||||
private boolean isChest(Block block) {
|
||||
return block.getState() instanceof InventoryHolder ||
|
||||
block.getState().getData() instanceof DirectionalContainer ||
|
||||
block.getType().equals(Material.ENDER_CHEST) ||
|
||||
block.getType().equals(Material.BEACON);
|
||||
block.getState() instanceof DirectionalContainer ||
|
||||
block.getState() instanceof BeaconInventory;
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player, IAbstractPermission perm) {
|
||||
|
@ -270,7 +199,4 @@ public class PlayerListener implements Listener {
|
|||
private boolean checkPermission(PlayerEvent event, IDynamicPermission perm) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), perm);
|
||||
}
|
||||
private boolean checkPermission(Player player, IDynamicPermission perm) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.limits;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits;
|
||||
|
||||
public class VehicleListener implements Listener {
|
||||
private ModCreativeLimits mod;
|
||||
public VehicleListener(ModCreativeLimits mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
if (event.getAttacker() instanceof Player) {
|
||||
Player player = (Player) event.getAttacker();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !mod.getPlugin().getPermManager().hasPermission(player, NoLimitPermissions.DROP)) {
|
||||
switch (event.getVehicle().getType()) {
|
||||
case MINECART:
|
||||
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.MINECART);
|
||||
break;
|
||||
case MINECART_CHEST:
|
||||
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.STORAGE_MINECART);
|
||||
break;
|
||||
case MINECART_FURNACE:
|
||||
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.POWERED_MINECART);
|
||||
break;
|
||||
case MINECART_HOPPER:
|
||||
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.HOPPER_MINECART);
|
||||
break;
|
||||
case MINECART_TNT:
|
||||
mod.getBlockSpawn().block(event.getVehicle().getLocation().getBlock().getLocation(), Material.EXPLOSIVE_MINECART);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,6 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
|
|||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.Utils;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
|
||||
|
@ -51,7 +50,7 @@ public class BlockListener extends Listener {
|
|||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not break inside of "survial-region in creative world" when outside
|
||||
if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, player) != player.getGameMode()) {
|
||||
if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) != null) {
|
||||
player.sendMessage(L("blocked.inside_break"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -60,8 +59,6 @@ public class BlockListener extends Listener {
|
|||
// prevent any drops for survival players in creative regions
|
||||
if (player.getGameMode() != GameMode.CREATIVE && getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
|
||||
mod.getBlockSpawn().block(block, player);
|
||||
if (event instanceof BlockBreakEvent)
|
||||
((BlockBreakEvent) event).setExpToDrop(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,27 +79,7 @@ public class BlockListener extends Listener {
|
|||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not build inside of "survial-region in creative world" when outside
|
||||
if (/*getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && */getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
|
||||
event.getPlayer().sendMessage(L("blocked.inside_place"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
PlayerMeta pdata = new PlayerMeta(event.getPlayer());
|
||||
boolean diffrent_region = getRM().isDiffrentRegion(event.getPlayer(), event.getEntity().getLocation());
|
||||
|
||||
if (pdata.isActiveRegionGameMode() && diffrent_region) {
|
||||
// do not build outside of "gamemod-change-region" when in the region
|
||||
if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != pdata.getActiveRegionGameMode()) {
|
||||
event.getPlayer().sendMessage(L("blocked.outside_place"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not build inside of "survial-region in creative world" when outside
|
||||
if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
|
||||
if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null) {
|
||||
event.getPlayer().sendMessage(L("blocked.inside_place"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -143,7 +120,7 @@ public class BlockListener extends Listener {
|
|||
Block dest = source.getRelative(event.getDirection().getOppositeFace());
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky());
|
||||
if (event.isSticky() && source.getType() != Material.AIR) {
|
||||
if (event.isSticky() && source.getType() != Material.AIR) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug("dest "+dest.getType());
|
||||
if (regionSet(source).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) {
|
||||
|
|
|
@ -1,47 +1,48 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IWorldGuardIntegration {
|
||||
public void initFlagList();
|
||||
public boolean isRegionOptional(Player player, GameMode tgm);
|
||||
}
|
|
@ -84,25 +84,22 @@ public class PlayerData {
|
|||
return getGameMode("region_gamemode");
|
||||
}
|
||||
public void storeActiveRegionGameMode(GameMode regionGameMode) {
|
||||
getSect(n()).set("region_gamemode", regionGameMode != null ? regionGameMode.toString() : null);
|
||||
getSect(n()).set("region_gamemode", regionGameMode);
|
||||
cleanUp();
|
||||
save();
|
||||
}
|
||||
public GameMode getPermanentRegionGameMode() {
|
||||
return getGameMode("permanent_gamemode");
|
||||
}
|
||||
public void storePermanentGameMode(GameMode currentGameMode) {
|
||||
getSect(n()).set("permanent_gamemode", currentGameMode != null ? currentGameMode.toString() : null);
|
||||
getSect(n()).set("permanent_gamemode", currentGameMode);
|
||||
cleanUp();
|
||||
save();
|
||||
}
|
||||
public GameMode getOptionalRegionGameMode(String regionHash) {
|
||||
return getGameMode("optional_gamemode." + regionHash);
|
||||
}
|
||||
public void setOptionalRegionGameMode(String regionHash, GameMode currentGameMode) {
|
||||
getSect(n()+".optional_gamemode").set(regionHash, currentGameMode != null ? currentGameMode.toString() : null);
|
||||
getSect(n()+".optional_gamemode").set(regionHash, currentGameMode);
|
||||
cleanUp();
|
||||
save();
|
||||
}
|
||||
|
||||
private GameMode getGameMode(String path) {
|
||||
|
|
|
@ -2,7 +2,6 @@ package de.jaschastarke.minecraft.limitedcreative.regions;
|
|||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
|
@ -10,10 +9,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.material.Button;
|
||||
|
@ -27,8 +23,11 @@ public class PlayerListener extends Listener {
|
|||
super(mod);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (isCancelled(event))
|
||||
return;
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
|
@ -50,74 +49,26 @@ public class PlayerListener extends Listener {
|
|||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not break inside of "survial-region in creative world" when outside
|
||||
if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
|
||||
if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) != null) {
|
||||
event.getPlayer().sendMessage(L("blocked.inside_interact"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
PlayerMeta pmeta = new PlayerMeta(event.getPlayer());
|
||||
Location loc = event.getRightClicked().getLocation();
|
||||
boolean diffrent_region = getRM().isDiffrentRegion(event.getPlayer(), loc);
|
||||
|
||||
if (pmeta.isActiveRegionGameMode() && diffrent_region) {
|
||||
// do not break outside of "gamemod-change-region" when in the region
|
||||
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != pmeta.getActiveRegionGameMode()) {
|
||||
event.getPlayer().sendMessage(L("blocked.outside_interact_entity"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not break inside of "survial-region in creative world" when outside
|
||||
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
|
||||
event.getPlayer().sendMessage(L("blocked.inside_interact_entity"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerDamange(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Player) {
|
||||
PlayerMeta pmeta = new PlayerMeta((Player) event.getDamager());
|
||||
Location loc = event.getEntity().getLocation();
|
||||
boolean diffrent_region = getRM().isDiffrentRegion((Player) event.getDamager(), loc);
|
||||
|
||||
if (pmeta.isActiveRegionGameMode() && diffrent_region) {
|
||||
// do not break outside of "gamemod-change-region" when in the region
|
||||
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != pmeta.getActiveRegionGameMode()) {
|
||||
event.getDamager().sendMessage(L("blocked.outside_interact_entity"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (diffrent_region) {
|
||||
// do not break inside of "survial-region in creative world" when outside
|
||||
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != ((Player) event.getDamager()).getGameMode()) {
|
||||
event.getDamager().sendMessage(L("blocked.inside_interact_entity"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
|
||||
onPlayerInteractEntity(event);
|
||||
}
|
||||
|
||||
private boolean isRegionOptional(Player player) {
|
||||
return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL);
|
||||
return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL, player);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlayerMeta pmeta = new PlayerMeta(player);
|
||||
GameMode gm = event.getNewGameMode();
|
||||
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug(player.getName() + " is changing to GameMode " + gm);
|
||||
mod.getLog().debug(player.getName() + " is changing to GameMode " + gm);;
|
||||
if (Hooks.IsLoggedIn.test(player)) { // if authme is changing GameMode before going to teleport, this should be remembered
|
||||
if (pmeta.isActiveRegionGameMode()) { // change to the other gamemode as the area defines
|
||||
if (!pmeta.isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
|
||||
|
|
|
@ -3,18 +3,16 @@ package de.jaschastarke.minecraft.limitedcreative.regions;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.configuration.Configuration;
|
||||
import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer;
|
||||
import de.jaschastarke.configuration.IConfigurationNode;
|
||||
import de.jaschastarke.configuration.IConfigurationSubGroup;
|
||||
import de.jaschastarke.configuration.InvalidValueException;
|
||||
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginConfigurations;
|
||||
import de.jaschastarke.minecraft.limitedcreative.Config;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.BlackList;
|
||||
import de.jaschastarke.modularize.IModule;
|
||||
import de.jaschastarke.modularize.ModuleEntry;
|
||||
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
||||
|
||||
/**
|
||||
* Region GameModes-Feature
|
||||
|
@ -22,16 +20,11 @@ import de.jaschastarke.modularize.ModuleEntry;
|
|||
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/region/
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
@PluginConfigurations(parent = Config.class)
|
||||
public class RegionConfig extends Configuration implements IConfigurationSubGroup {
|
||||
protected ModRegions mod;
|
||||
protected ModuleEntry<IModule> entry;
|
||||
|
||||
public RegionConfig(ConfigurationContainer container) {
|
||||
super(container);
|
||||
}
|
||||
public RegionConfig(ModRegions modRegions, ModuleEntry<IModule> modEntry) {
|
||||
super(modRegions.getPlugin().getDocCommentStorage());
|
||||
mod = modRegions;
|
||||
entry = modEntry;
|
||||
}
|
||||
|
@ -41,13 +34,19 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
|
|||
if (!(pValue instanceof BlackList))
|
||||
super.setValue(node, pValue);
|
||||
if (node.getName().equals("enabled")) {
|
||||
entry.setEnabled(getEnabled());
|
||||
if (getEnabled()) {
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.enable();
|
||||
} else {
|
||||
entry.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setValues(ConfigurationSection sect) {
|
||||
super.setValues(sect);
|
||||
entry.setDefaultEnabled(getEnabled());
|
||||
if (entry.initialState != ModuleState.NOT_INITIALIZED)
|
||||
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
|
||||
|
||||
// Config Upgrade
|
||||
if (!sect.contains("rememberOptional") && sect.contains("remember"))
|
||||
|
@ -67,7 +66,7 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
|
|||
/**
|
||||
* RegionEnabled
|
||||
*
|
||||
* Enables the feature for "creative-regions". This Feature is automatically disabled, if the required plugin
|
||||
* Enables the feature for "creative-regions". This Feature is automatically disabled, if the required plugin
|
||||
* "WorldGuard" (http://dev.bukkit.org/server-mods/worldguard/) isn't found.
|
||||
*
|
||||
* default: true
|
||||
|
@ -80,9 +79,9 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
|
|||
/**
|
||||
* RegionRememberOptional
|
||||
*
|
||||
* Remembers if players disables the Region-GameMode (by switching in an optional region to World-Default-GameMode
|
||||
* Remembers if players disables the Region-GameMode (by switching in an optional region to World-Default-GameMode
|
||||
* with /lc creative|survival). So when the player re-enters the region, he keep his GameMode which he left it in.
|
||||
* Hint: This is very confusing, if MultiVerse "enforce gamemode" swaps your state (default). So better don't use
|
||||
* Hint: This is very confusing, if MultiVerse "enforce gamemode" swaps your state (default). So better don't use
|
||||
* with Multiverse.
|
||||
*
|
||||
* default: false
|
||||
|
@ -95,9 +94,9 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
|
|||
/**
|
||||
* RegionSafeMode
|
||||
*
|
||||
* When a player leaves a region he always will get back to the World-GameMode, even if he entered the region already
|
||||
* When a player leaves a region he always will get back to the World-GameMode, even if he entered the region already
|
||||
* in the Region-GameMode. So its the opposite analog to RegionRememberOptional.
|
||||
* That means: If a GM in creative-mode walks/flies through a creative-region in a survival world, he will get back
|
||||
* That means: If a GM in creative-mode walks/flies through a creative-region in a survival world, he will get back
|
||||
* to survival on leaving the region.
|
||||
*
|
||||
* default: false
|
||||
|
@ -111,15 +110,13 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
|
|||
/**
|
||||
* RegionMaximumFallingHeight
|
||||
*
|
||||
* When the player is more than this count of blocks above the ground, he is prevented from changing the region that
|
||||
* When the player is more than this count of blocks above the ground, he is prevented from changing the region that
|
||||
* sets him survival which would cause him falling and hurting.
|
||||
*
|
||||
* Set to -1 to disable
|
||||
*
|
||||
* default: 3
|
||||
*/
|
||||
@IsConfigurationNode(order = 500)
|
||||
public int getMaxFallingHeight() {
|
||||
public int getMaximumFloatingHeight() {
|
||||
return config.getInt("maxFallingHeight", 3);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,16 +25,11 @@ public class RegionListener extends Listener {
|
|||
super(mod);
|
||||
}
|
||||
|
||||
private boolean checkFloatingToHigh(int max, Location loc) {
|
||||
if (max < 0)
|
||||
return false;
|
||||
return getFloatingHeight(loc) > max;
|
||||
}
|
||||
public int getFloatingHeight(Player player) {
|
||||
return getFloatingHeight(player.getLocation());
|
||||
}
|
||||
public int getFloatingHeight(Location loc) {
|
||||
Block b = loc.getBlock().getRelative(BlockFace.DOWN);
|
||||
Block b = loc.getBlock();
|
||||
int steps = 0;
|
||||
while (b.getType() == Material.AIR) {
|
||||
steps++;
|
||||
|
@ -44,7 +39,7 @@ public class RegionListener extends Listener {
|
|||
}
|
||||
|
||||
private boolean checkSwitchFlight(PlayerMoveEvent event) {
|
||||
if (event != null && event.getPlayer().getGameMode() == GameMode.CREATIVE && checkFloatingToHigh(mod.getConfig().getMaxFallingHeight(), event.getTo())) {
|
||||
if (event != null && event.getPlayer().getGameMode() == GameMode.CREATIVE && getFloatingHeight(event.getTo()) > mod.getConfig().getMaximumFloatingHeight()) {
|
||||
// but not if he is too high
|
||||
Utils.sendTimeoutMessage(event.getPlayer(), L("blocked.survival_flying"));
|
||||
|
||||
|
@ -73,14 +68,11 @@ public class RegionListener extends Listener {
|
|||
if (mod.isDebug())
|
||||
mod.getLog().debug(player.getName()+": changed region: "+regionGameMode+": " + areaEvent);
|
||||
|
||||
GameMode defaultGameMode;
|
||||
PlayerMoveEvent moveEvent = null;
|
||||
if (areaEvent instanceof PlayerChangedAreaEvent)
|
||||
defaultGameMode = Hooks.DefaultWorldGameMode.get(((PlayerChangedAreaEvent) areaEvent).getMoveEvent().getTo().getWorld());
|
||||
else if (areaEvent instanceof PlayerNewLocationAreaEvent)
|
||||
defaultGameMode = Hooks.DefaultWorldGameMode.get(((PlayerNewLocationAreaEvent) areaEvent).getNewLocation().getWorld());
|
||||
else
|
||||
defaultGameMode = Hooks.DefaultWorldGameMode.get(player.getWorld());
|
||||
moveEvent = ((PlayerChangedAreaEvent) areaEvent).getMoveEvent();
|
||||
GameMode currentGameMode = player.getGameMode();
|
||||
GameMode defaultGameMode = Hooks.DefaultWorldGameMode.get(moveEvent != null ? moveEvent.getTo().getWorld() : player.getWorld());
|
||||
|
||||
if (regionGameMode != null && currentGameMode != regionGameMode && !pmeta.isActiveRegionGameMode(regionGameMode)) {
|
||||
if (mod.isDebug())
|
||||
|
@ -96,9 +88,7 @@ public class RegionListener extends Listener {
|
|||
pmeta.storeActiveRegionGameMode(regionGameMode); // have to be set, before setGameMode
|
||||
|
||||
if (!isOptional) {
|
||||
if (Hooks.IsLoggedIn.test(player)) { // don't change gamemode on login
|
||||
player.setGameMode(regionGameMode);
|
||||
}
|
||||
player.setGameMode(regionGameMode);
|
||||
}
|
||||
}
|
||||
} else if (regionGameMode == null && player.getGameMode() != defaultGameMode && !pmeta.isInPermanentGameMode(currentGameMode) && pmeta.getActiveRegionGameMode() != null) {
|
||||
|
@ -111,9 +101,7 @@ public class RegionListener extends Listener {
|
|||
// result: change him back to default mode
|
||||
if (checkSwitchFlight(areaEvent)) {
|
||||
pmeta.storeActiveRegionGameMode(null);
|
||||
if (Hooks.IsLoggedIn.test(player)) { // don't change gamemode on login
|
||||
player.setGameMode(defaultGameMode);
|
||||
}
|
||||
player.setGameMode(defaultGameMode);
|
||||
}
|
||||
} else if (regionGameMode == null && pmeta.isActiveRegionGameMode()) {
|
||||
if (mod.isDebug())
|
||||
|
|
|
@ -3,7 +3,6 @@ package de.jaschastarke.minecraft.limitedcreative.regions;
|
|||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import de.jaschastarke.maven.ArchiveDocComments;
|
||||
import de.jaschastarke.maven.PluginPermissions;
|
||||
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
|
||||
import de.jaschastarke.minecraft.lib.permissions.IPermission;
|
||||
|
@ -27,7 +26,6 @@ final public class RegionPermissions extends SimplePermissionContainerNode imple
|
|||
/**
|
||||
* Grants access to the /lcr command, which allows to define Limited Creatives region-flags
|
||||
*/
|
||||
@PluginPermissions
|
||||
public static final RegionPermissions REGION = new RegionPermissions(Permissions.CONTAINER, "region");
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,280 +1,203 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
|
||||
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.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.maven.ArchiveDocComments;
|
||||
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;
|
||||
|
||||
/**
|
||||
* LimitedCreative-Region-Command: configure creative regions
|
||||
* @usage /<command> - displays Regions-Command-Help
|
||||
* @permission limitedcreative.region
|
||||
*/
|
||||
@ArchiveDocComments
|
||||
public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
|
||||
private ModRegions mod;
|
||||
private HelpCommand help;
|
||||
|
||||
public RegionsCommand() {
|
||||
this.help = this.getDefaultHelpCommand();
|
||||
}
|
||||
public RegionsCommand(ModRegions mod) {
|
||||
this.mod = mod;
|
||||
this.help = this.getDefaultHelpCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "lcr";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[]{"/region"};
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 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 = mod.getWorldGuard().getGlobalRegionManager().get(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);
|
||||
}
|
||||
|
||||
String value = params.getValue();
|
||||
try {
|
||||
if (value != null) {
|
||||
reg.setFlag(flag, flag.parseInput(mod.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] [id]")
|
||||
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 = mod.getWorldGuard().getGlobalRegionManager().get(context.getPlayer().getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation());
|
||||
if (set.size() > 0) {
|
||||
region = set.iterator().next();
|
||||
}
|
||||
} else {
|
||||
int rpc = params.getArgumentCount() > 1 ? 1 : 0;
|
||||
RegionManager mgr = mod.getWorldGuard().getGlobalRegionManager().get(w);
|
||||
region = mgr.getRegion(params.getArgument(rpc));
|
||||
if (region == null && params.getArgument(rpc).equalsIgnoreCase("__global__")) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package de.jaschastarke.minecraft.limitedcreative.regions;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.jaschastarke.minecraft.limitedcreative.Hooks;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModRegions;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.ApplicableRegions;
|
||||
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagList;
|
||||
|
||||
public class WorldGuardIntegration implements IWorldGuardIntegration {
|
||||
public static final String PLUGIN_NAME = "WorldGuard";
|
||||
private ModRegions mod;
|
||||
|
||||
public WorldGuardIntegration(ModRegions mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initFlagList() {
|
||||
FlagList.addFlags(Flags.getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public boolean isRegionOptional(Player player, GameMode tgm) {
|
||||
ApplicableRegions rs = mod.getRegionManager().getRegionSet(player.getLocation());
|
||||
if (rs.allows(Flags.GAMEMODE_OPTIONAL)) {
|
||||
if ((tgm == rs.getFlag(Flags.GAMEMODE, player)) || (tgm == Hooks.DefaultWorldGameMode.get(player.getWorld())))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,6 @@ import org.bukkit.entity.Player;
|
|||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class ApplicableRegions {
|
||||
|
@ -37,28 +36,28 @@ public class ApplicableRegions {
|
|||
|
||||
public boolean allows(StateFlag flag) {
|
||||
extendRegionFlags();
|
||||
boolean r = regions.queryState(null, flag).equals(State.ALLOW);
|
||||
boolean r = regions.allows(flag);
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
public boolean allows(StateFlag flag, Player player) {
|
||||
extendRegionFlags();
|
||||
boolean r = regions.queryState(mgr.getWorldGuard().wrapPlayer(player), flag).equals(State.ALLOW);
|
||||
boolean r = regions.allows(flag, mgr.getWorldGuard().wrapPlayer(player));
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
public <T extends Flag<V>, V> V getFlag(T flag) {
|
||||
extendRegionFlags();
|
||||
V r = regions.queryValue(null, flag);
|
||||
V r = regions.getFlag(flag);
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
||||
public <T extends Flag<V>, V> V getFlag(T flag, Player player) {
|
||||
extendRegionFlags();
|
||||
V r = regions.queryValue(mgr.getWorldGuard().wrapPlayer(player), flag);
|
||||
V r = regions.getFlag(flag, mgr.getWorldGuard().wrapPlayer(player));
|
||||
contractRegionFlags();
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -1,189 +1,187 @@
|
|||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.GlobalRegionManager;
|
||||
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.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");
|
||||
|
||||
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 mod.getWorldGuard();
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalRegionManager getWGGlobalManager() {
|
||||
return mod.getWorldGuard().getGlobalRegionManager();
|
||||
}
|
||||
public RegionManager getWGManager(World world) {
|
||||
return mod.getWorldGuard().getRegionManager(world);
|
||||
}
|
||||
|
||||
public String getRegionsHash(Location loc) {
|
||||
StringBuilder hash = new StringBuilder(loc.getWorld().getName());
|
||||
List<String> idlist = getWGGlobalManager().get(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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,10 +49,13 @@ public class Region {
|
|||
}
|
||||
|
||||
public void setFlag(Flag<?> flag, Object value) {
|
||||
removeFlag(flag);
|
||||
if (flags != null && value != null)
|
||||
flags.add(new FlagValue(flag, value));
|
||||
mgr.storeFlag(this, flag, value);
|
||||
if (value == null) {
|
||||
removeFlag(flag);
|
||||
} else {
|
||||
if (flags != null)
|
||||
flags.add(new FlagValue(flag, value));
|
||||
mgr.storeFlag(this, flag, value);
|
||||
}
|
||||
}
|
||||
public ProtectedRegion getProtectedRegion() {
|
||||
return region;
|
||||
|
|
|
@ -69,7 +69,4 @@ public class PlayerNewLocationAreaEvent extends PlayerAreaEvent {
|
|||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
public Location getNewLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
@ -24,11 +25,11 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.ApplicableRe
|
|||
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager;
|
||||
|
||||
public class PlayerUpdateAreaEvent extends PlayerAreaEvent {
|
||||
private Player player;
|
||||
private String player;
|
||||
private String hash;
|
||||
protected CustomRegionManager mgr;
|
||||
|
||||
public PlayerUpdateAreaEvent(CustomRegionManager mgr, Player player, String hash) {
|
||||
public PlayerUpdateAreaEvent(CustomRegionManager mgr, String player, String hash) {
|
||||
this.mgr = mgr;
|
||||
this.player = player;
|
||||
this.hash = hash;
|
||||
|
@ -45,7 +46,7 @@ public class PlayerUpdateAreaEvent extends PlayerAreaEvent {
|
|||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
return Bukkit.getServer().getPlayerExact(player);
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
|
55
src/main/resources/lang/disabled.messages_de.properties
Normal file
55
src/main/resources/lang/disabled.messages_de.properties
Normal file
|
@ -0,0 +1,55 @@
|
|||
basic.loaded.worldguard: Erfolgreich mit WorldGuard-Integration geladen
|
||||
basic.loaded.no_worldguard: Erfolgreich geladen (ohne WorldGuard)
|
||||
basic.loaded.module: Modul geladen.
|
||||
basic.feature.store: Getrennte Inventare
|
||||
basic.feature.limit: Kreativ-Einschränkungen
|
||||
basic.feature.region: Kreativ-Regionen
|
||||
basic.conflict: Wegen eines Konfliktes mit {0} ist die Funktion {1} deaktiviert
|
||||
basic.warning.worldguard_not_found: WorldGuard wurd enicht gefunde, dahier ist die Funktion {0} deaktiviert
|
||||
|
||||
command.player: Spieler
|
||||
command.switch.survival: Ändert den Spiel-Modus des Charakters zu überleben
|
||||
command.switch.creative: Ändert den Spiel-Modus des Charakters zu Kreativ
|
||||
command.switch.adventure: Ändert den Spiel-Modus des Charakters zu Abenteuer
|
||||
command.switch.config.overview: "[Einstellung] - liste durch weglassen"
|
||||
command.switch.config.settings: "Verfügbare Einstellungen: "
|
||||
command.switch.config.reload: Lädt das Plugin neu (funktioniert nur teilweise)
|
||||
command.gamemode.changed: "{0}'s Spiel-Modus wurde geändert"
|
||||
command.gamemode.no_change: Bereits in diesem Spiel-Modus
|
||||
command.option.done: Option geändert.
|
||||
command.worldguard.alias: Alias für den //region-Befehl
|
||||
command.worldguard.unknown_flag: Unbekanntes Attribut
|
||||
command.worldguard.available_flags: Verfügbare Attribute
|
||||
command.worldguard.region_not_found: Keine Region mit dieser ID gefunden
|
||||
command.worldguard.world_not_found: Es konnte keine Welt mit diesem Namen gefunden werden
|
||||
command.worldguard.no_flag_given: Es muss ein Attribut angegeben werden, dass gesetzt werden soll
|
||||
command.worldguard.no_integration: Der worldguard-Befehl ist nicht verfügbar, da WorldGuard nicht gefunden wurde
|
||||
command.worldguard.flag_set: "Das Attribut {0} wurde gesetzt"
|
||||
command.worldguard.additional_flags: Zusätzliche Attribute
|
||||
|
||||
cmdblock.blocked: Dieser Befehl ist im Kreativ-Modus blockiert.
|
||||
|
||||
exception.command.lackingpermission: Kein Zugriff auf diesen Befehl
|
||||
exception.command.toomuchparameter: Zuviele Argumente angegeben
|
||||
exception.command.missingparameter: Nicht genügen Argumente angegeben
|
||||
exception.command.playernotfound: Spieler nicht gefunden
|
||||
exception.command.invalidoption: Unbkeannte Option
|
||||
exception.config.savefail: Die Konfiguration konnte nicht gespeichert werden
|
||||
exception.config.material_not_found: (Konfiguration) Material mit Name/ID "{0}" wurde nicht gefunden.
|
||||
exception.storage.load: Fehler beim Laden des Inventars. Bitte einen Admin die Option "UnsafeStorege" in LimitedCreative zu aktivieren um ungültig verzauberte Gegenstände zu erlauben
|
||||
exception.region.not_optional: "In dieser Region kannst du nicht im folgenden Modus sein: {0}"
|
||||
|
||||
blocked.chest: Zugriff auf Truhen ist im Kreativ-Modus nicht erlaubt
|
||||
blocked.sign: Im Kreativ-Modus kann nicht mit Schildern interagiert werden
|
||||
blocked.button: Im Kreativ-Modus kann nicht mit Buttons interagiert werden
|
||||
blocked.lever: Im Kreativ-Modus kann nicht mit Schaltern interagiert werden
|
||||
blocked.survival_flying: Du solltest auf dem Boden stehen wenn du Kreativ-Regionen verlässt
|
||||
blocked.outside_place: Du kannst keine Blöcke auÿerhalb von Spiel-Modus-Regionen setzen
|
||||
blocked.outside_break: Du kannst keine Blöcke auÿerhalb von Spiel-Modus-Regionen zerstören
|
||||
blocked.inside_place: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen setzen
|
||||
blocked.inside_break: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen zerstören
|
||||
blocked.use: Du darfst diese Art von Gegenständen im Kreativ-Modus verwenden
|
||||
blocked.place: Du darfst diese Art von Blöcken im Kreativ-Modus nicht setzen
|
||||
blocked.break: Du darfst diese Art von Blöcken im Kreativ-Modus nicht zerstören
|
||||
blocked.piston: Verschieben von Block {0} aus einer Spiel-Modus-Region bei {1} wurde blockiert
|
||||
blocked.piston_in: Verschieben von Block {0} in eine Spiel-Modus-Region bei {1} wurde blockiert
|
|
@ -1,2 +0,0 @@
|
|||
# This file is empty for purpose, it is only there to prevent ResourceBundle-load-error
|
||||
# The strings are generated from DocComments to META-INF/doccomments.properties
|
|
@ -1,20 +1,16 @@
|
|||
basic.loaded.module: Module loaded.
|
||||
basic.feature.gamemodecommands: GameMode-Commands
|
||||
|
||||
inventory.warning.conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
|
||||
region.warning.worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled
|
||||
gmperm.warning.vault_not_found: Vault isn''t found, the feature {0} is disabled
|
||||
gmperm.warning.no_group_support: "Your Permission-Plugin doesn''t support groups, the feature {0} is disabled"
|
||||
region.warning.worldguard_not_found: WorldGuard isn't found, the feature {0} is disabled
|
||||
|
||||
command.general: LimitedCreative: GameMode-Switch, Creative-Regions, Config and more
|
||||
command.regions: LimitedCreative-Region-Command: configure creative regions
|
||||
command.switch.survival: Changes the game mode of a player to survival
|
||||
command.switch.creative: Changes the game mode of a player to creative
|
||||
command.switch.adventure: Changes the game mode of a player to adventure
|
||||
command.switch.spectator: Changes the game mode of a player to spectator
|
||||
command.config.reload: Reloads configuration and re-initializes all active modules.
|
||||
command.config.reload.success: The plugin was successfully reloaded.
|
||||
command.gamemode.changed: {0}''s game mode has been changed
|
||||
command.gamemode.changed: {0}'s game mode has been changed
|
||||
command.gamemode.no_change: Already in that game mode.
|
||||
|
||||
command.worldguard.alias: Alias for //region-command
|
||||
|
@ -23,44 +19,21 @@ command.worldguard.available_flags: Available flags:
|
|||
command.worldguard.region_not_found: Could not find a region by that ID
|
||||
command.worldguard.world_not_found: Could not find a world by that name
|
||||
command.worldguard.flag_set: "The flag {0} was set"
|
||||
command.worldguard.additional_flags: Additional flags:
|
||||
|
||||
command.blockstate: LimitedCreative-BlockState-Command: modify blockstate database to prevent drops of selected blocks (requires WorldEdit)
|
||||
command.blockstate.world_ignored: The BlockState-Feature is disabled for this World ({0})
|
||||
command.blockstate.requires_worldedit: This command requires WorldEdit-Plugin
|
||||
command.blockstate.worledit_selection_empty: Select a region with WorldEdit first
|
||||
command.blockstate.command_updated: Successfully updated {0} blocks.
|
||||
command.blockstate.command_failed: Failed to update blocks. See server.log for details.
|
||||
command.blockstate.migrate_started: Database migration from {0} to {1} started...
|
||||
command.blockstate.migrate_connect_error: Connection to database failed with error: {0}
|
||||
command.blockstate.migrate_importtype_error: Unknown --import-type: {0}
|
||||
command.blockstate.migration_finished: Database migration of {0} records successful.
|
||||
command.blockstate.migration_finished_restart: A Server-Restart is required!
|
||||
command.blockstate.migration_error: Migration failed with error: {0}
|
||||
command.blockstate.migrate_useronline_error: There are players on the Server. The migration shouldn't be run with active players.
|
||||
command.blockstate.migrate_confirm: Are you sure you want to start the migration? It may take a very long time and much CPU. To confirm execution run the command with the following added: {0}
|
||||
command.blockstate.nothing_to_cleanup: Nothing to cleanup
|
||||
command.blockstate.cleanup_success: Successfully removed {0} entries from database
|
||||
command.blockstate.cleanup_error: Error while cleaning database. Check server.log
|
||||
command.worldguard.additional_flags: Additional flags:
|
||||
|
||||
cmdblock.blocked: This command is blocked while in creative mode.
|
||||
cmdblock.blocked.requires_worldedit: WorlEdit is required to use this command
|
||||
cmdblock.blocked.not_console: This command can not be used from console
|
||||
|
||||
exception.config.material_not_found: (Config) Material with name/id "{0}" was not found.
|
||||
exception.region.not_optional: You can not be {0} in that area
|
||||
|
||||
blocked.inventory: Opening inventories is not allowed in creative mode
|
||||
blocked.chest: Access to chests is not allowed in creative mode
|
||||
blocked.survival_flying: You should stay on ground, when leaving a creative-area
|
||||
blocked.outside_place: You can not place blocks outside of the gamemode-area
|
||||
blocked.outside_break: You can not destroy blocks outside of the gamemode-area
|
||||
blocked.outside_interact: You can not interact with those blocks outside of the gamemode-area
|
||||
blocked.outside_interact_entity: You can not interact with out of the gamemode-area
|
||||
blocked.inside_place: You can not place blocks inside of the gamemode-area
|
||||
blocked.inside_break: You can not destroy blocks inside of the gamemode-area
|
||||
blocked.inside_interact: You can not interact with those blocks inside of the gamemode-area
|
||||
blocked.inside_interact_entity: You can not interact with this into gamemode-area
|
||||
blocked.interact: You are not allowed to interact with this type of blocks
|
||||
blocked.entity: You are not allowed to interact with this type of entity
|
||||
blocked.use: You are not allowed to use this type of item
|
||||
|
@ -69,11 +42,3 @@ blocked.break: You are not allowed to break this type of block
|
|||
|
||||
blocked.region.piston: Moving {0} block out of creative area was blocked at {1}
|
||||
blocked.region.piston_in: Moving {0} block into creative area was blocked at {1}
|
||||
|
||||
block_state.warning.worldedit_sessionfactory_failed: Failed to hook into WorldEdit. WorldEdit-actions can''t be traced. Error: {0}
|
||||
block_state.tool_info.seed: This {0}-Block is generated by the god who created this world
|
||||
block_state.tool_info.player: This {0}-Block was created by ''{1}'' in {2}-mode on {3}
|
||||
block_state.tool_info.edit: This {0}-Block was modified with WorldEdit by ''{1}'' on {3}
|
||||
block_state.tool_info.command: This {0}-Block was manually set to {2}-mode via command by ''{1}'' on {3}
|
||||
block_state.tool_info.unknown: The origin of this {0}-Block is unknown
|
||||
block_state.error.sql_connection_failed: Failed to connect to Database. Check bukkit.yml
|
|
@ -1,79 +0,0 @@
|
|||
basic.loaded.module: Modul geladen.
|
||||
basic.feature.gamemodecommands: Spielmodus-Befehle
|
||||
|
||||
inventory.warning.conflict: Wegen eines Konfliktes mit dem Plugin {0} wurde das Feature {1} deaktiviert
|
||||
region.warning.worldguard_not_found: WorldGuard wurde nicht gefunden. Das Feature {0} wurde deaktiviert.
|
||||
gmperm.warning.vault_not_found: Vault wurde nicht gefunden. Das Feature {0} wurde deaktiviert.
|
||||
gmperm.warning.no_group_support: Das verwendete Permission-Plugin unterstüzzt keine Gruppen. Das Feature {0} wurde deaktiviert
|
||||
|
||||
command.general: LimitedCreative: GameMode-Wechsel, Kreativ-Regionen, Konfiguration und mehr
|
||||
command.regions: LimitedCreative-Region-Kommando: Kreativ-Regionen konfigurieren
|
||||
command.switch.survival: Ändert den Spielmodus des Spielers zu Überleben
|
||||
command.switch.creative: Ändert den Spielmodus des Spielers zu Kreativ
|
||||
command.switch.adventure: Ändert den Spielmodus des Spielers zu Abenteuer
|
||||
command.switch.spectator: Ändert den Spielmodus des Spielers zu Beobachter
|
||||
command.config.reload: Lädt die Konfiguration neu und initialisiert alle Module neu
|
||||
command.config.reload.success: Das Plugin wurde erfolgreich neu geladen
|
||||
command.gamemode.changed: {0}''s GameMode wurde geändert
|
||||
command.gamemode.no_change: Ist bereits in diesem Modus
|
||||
|
||||
command.worldguard.alias: Alias für den //region-Befehl
|
||||
command.worldguard.unknown_flag: Unbekanntes Attribut angegeben
|
||||
command.worldguard.available_flags: Verfügbare Attribute:
|
||||
command.worldguard.region_not_found: Konnte keine Region mit dieser ID finden
|
||||
command.worldguard.world_not_found: Konnte keine Welt mit diesem namen finden
|
||||
command.worldguard.flag_set: Das Attribut {0} wurde gesetzt
|
||||
command.worldguard.additional_flags: Zusätzliche Attribute:
|
||||
|
||||
command.blockstate: LimitedCreative-BlockStatus-Kommando: Ändern der BlockStatus Datenbank um Beute aus den ausgewählten Blöcken zu verhindern (benötigt WorldEdit)
|
||||
command.blockstate.world_ignored: Das BlockStatus-Modul ist für diese Welt deaktiviert ({0})
|
||||
command.blockstate.requires_worldedit: Dieser Befehl benötigt WorldEdit
|
||||
command.blockstate.worledit_selection_empty: Zuerst eine Region mit WorldEdit auswählen
|
||||
command.blockstate.command_updated: Erfolgreich {0} Blöcke aktuallisiert
|
||||
command.blockstate.command_failed: Fehler beim aktualisieren der Blöcke. Siehe server.log für Details
|
||||
command.blockstate.migrate_started: Datenbank-Migration von {0} nach {1} gestartet...
|
||||
command.blockstate.migrate_connect_error: Verbindung zur Datenbank mit folgendem Fehler fehlgeschlafen: {0}
|
||||
command.blockstate.migrate_importtype_error: Unbekannter --import-Typ: {0}
|
||||
command.blockstate.migration_finished: Datenbank-Migration von {0} Datensätzen erfolgreich
|
||||
command.blockstate.migration_finished_restart: Server-Neustart notwendig!
|
||||
command.blockstate.migration_error: Migration mit folgendem Fehler fehlgeschlagen: {0}
|
||||
command.blockstate.migrate_useronline_error: Es sind Spieler auf dem Server. Die Migration sollte nicht mit aktiven Spielern ausgeführt werden.
|
||||
command.blockstate.migrate_confirm: Bist du sicher. dass du die Migration starten willst? Dies dauert vermutlich sehr lange und benötigt viel Prozessor-Leistung. Um die Ausführung zu bestätigen führe den Befehl erneut mit folgendem Parameter aus: {0}
|
||||
command.blockstate.nothing_to_cleanup: Nichts aufzuräumen
|
||||
command.blockstate.cleanup_success: Erfolgreich {0} Datensätze aus der Datenbank gelöscht
|
||||
command.blockstate.cleanup_error: Fehler beim Aufräumen der Datenbank. server.log prüfen
|
||||
|
||||
cmdblock.blocked: Dieses Kommando ist im Kreativ-Modus blockiert
|
||||
cmdblock.blocked.requires_worldedit: WorldEdit wird für diesen Befehl benötigt
|
||||
cmdblock.blocked.not_console: Dieser Befehl kann nicht in der Konsole ausgeführt werden
|
||||
|
||||
exception.config.material_not_found: (Konfiguration) Material mit dem Namen/der ID "{0}" wurde nicht gefunden
|
||||
exception.region.not_optional: Du kannst in diesem Bereich nicht in den {0}-Modus
|
||||
|
||||
blocked.inventory: Inventar öffnen ist im Kreativ-Modus nicht gestattet
|
||||
blocked.chest: Der Zugriff auf Truhen ist im Kreativ-Modus nicht gestattet.
|
||||
blocked.survival_flying: Du solltest auf dem Boden stehen um einen Kreativ-Bereich zu verlassen
|
||||
blocked.outside_place: Du kannst keine Blöcke aus einem GameMode-Bereich heraus bauen
|
||||
blocked.outside_break: Du kannst keine Blöcke aus einem GameMode-Bereich heraus zerstören
|
||||
blocked.outside_interact: Du kannst nicht mit Blöcken außerhalb eines GameMode-Bereichs interagieren
|
||||
blocked.outside_interact_entity: Du kannst damit nicht aus einem GameMode-Bereich heraus interagieren
|
||||
blocked.inside_place: Du kannst keine Blöcke in einen GameMode-Bereich herein bauen
|
||||
blocked.inside_break: Du kannst von außerhalb keine Blöcke in einem GameMode-Bereich zerstören
|
||||
blocked.inside_interact: Du kannst von außerhalb nicht mit Blöcken in einem GameMode-Bereich interagieren
|
||||
blocked.inside_interact_entity: Du kannst damit nicht von außerhalb eines GameMode-Bereich interagieren
|
||||
blocked.interact: Du darfst mit dieser Art Block nicht interagieren
|
||||
blocked.entity: Du darfst nicht mit diesen Kreaturen interagieren
|
||||
blocked.use: Du darfst diese Art Gegenstand nicht verwenden
|
||||
blocked.place: Du darfst diese Art Block nicht platzieren
|
||||
blocked.break: Du darfst diesen Block nicht zerstören
|
||||
|
||||
blocked.region.piston: Verschieben eines {0} Blocks aus einem GameMode-Bereich wurde bei {1} verhindet
|
||||
blocked.region.piston_in: Verschieben eines {0} Blocks in einen GameMode-Bereich wurde bei {1} verhindet
|
||||
|
||||
block_state.warning.worldedit_sessionfactory_failed: Fehler beim Einhängen in WorldEdit. WorldEdit-Aktionen können nicht nachvollzogen werden. Fehler: {0}
|
||||
block_state.tool_info.seed: Dieser {0}-Block wurde von dem Gott generiert der diese Welt erschuf
|
||||
block_state.tool_info.player: Dieser {0}-Block wurde am {3} von ''{1}'' im {2}-Modus gebaut
|
||||
block_state.tool_info.edit: Der {0}-Block wurde am {3} von ''{1}'' mit WorldEdit gesetzt
|
||||
block_state.tool_info.command: Dieser {0}-Block wurde am {3} von ''{1}'' mittels Befehl manuell auf den {2}-Modus gesetzt
|
||||
block_state.tool_info.unknown: Der Ursprung dieses {0}-Blocks ist unbekannt
|
||||
block_state.error.sql_connection_failed: Verbindung zur Datenbank fehlgeschlagen.
|
2
src/main/resources/settings.properties
Normal file
2
src/main/resources/settings.properties
Normal file
|
@ -0,0 +1,2 @@
|
|||
piwik_url = http://stats.ja-s.de/piwikProxy.php
|
||||
piwik_site_id = 2
|
Loading…
Reference in a new issue