Compare commits

...
59 Commits
Author SHA1 Message Date
Andrew Wong 9f04efb3e8 Add a sign error logger 2021-06-03 11:58:55 +02:00
Andrew Wong 5872af7466 Improve performance of tab completions 2020-10-15 18:36:11 +02:00
Andrew Wong a8315e627b Remove debug message 2020-10-15 12:59:18 +02:00
Andrew Wong 35361308a8 Add a teleportation progress notifier, changeup interal structure of the TeleportFeature 2020-10-15 12:57:19 +02:00
Andrew Wong 0c359cdfdf Make TeleportFeature#teleport perform location finding async 2020-10-14 22:11:12 +02:00
Andrew Wong 2a03e7612a Improve the performance for FileManager region getters at the expense of technical debt 2020-10-08 22:13:23 +02:00
Andrew Wong aaf4e07053 Try to save and restore regions async where possible 2020-10-07 20:50:19 +02:00
Andrew Wong fa91016613 Add experimental support for async fawe operations... 2020-10-07 20:39:25 +02:00
Andrew Wong f4bd4ee6c6 Improve performance of block scanning in TeleportFeature 2020-10-07 19:00:40 +02:00
Andrew Wong 44fd7deea5 Keep chunks loaded until the teleport passes 2020-10-07 18:56:36 +02:00
Andrew Wong 2c2f40b0ea Fix merge conflict 2020-09-25 16:55:13 +02:00
Andrew Wong 07406c3987 Improve the performance of TeleportFeature#teleportPlayer
Split chunk loading accross multiple ticks, delay 3 ticks before executing teleport logic
2020-09-25 13:01:09 +02:00
Andrew Wong 82a90b350d Minor bug fixes 2020-08-22 01:37:33 +02:00
Andrew Wong 151fbe8000 Move away from using BukkitDo; Add TaskChain as a dependency 2020-08-17 21:47:44 +02:00
Andrew Wong f2a4dd71e3 Update README.md 2020-08-16 23:44:06 +02:00
Andrew Wong d4cc70f954 Rename version 2020-08-16 23:41:56 +02:00
Andrew Wong 8001047480 Add in the spigot repo 2020-08-16 23:31:29 +02:00
Andrew Wong af1486a6fa Create maven.yml 2020-08-16 23:27:40 +02:00
Andrew Wong 36a2d054d6 Bump maven plugin versions 2020-08-16 23:24:37 +02:00
Andrew Wong 7429b0a206 Remove system dependencies. Utilise PaperLib when teleporting. Remove support for pre-1.13. Added support for 1.16.1 2020-08-16 23:17:08 +02:00
dependabot[bot] 557d11dfb4 Bump checkstyle from 8.21 to 8.29
Bumps [checkstyle](https://github.com/checkstyle/checkstyle) from 8.21 to 8.29.
- [Release notes](https://github.com/checkstyle/checkstyle/releases)
- [Commits](https://github.com/checkstyle/checkstyle/compare/checkstyle-8.21...checkstyle-8.29)

Signed-off-by: dependabot[bot] <support@github.com>
2020-02-26 11:02:43 +01:00
Thijs Wiefferink b9547e2c67 Remove github action experiment 2019-08-16 18:22:19 +02:00
Thijs Wiefferink 221785ae55 Add test workflow maven build 2019-08-16 17:42:22 +02:00
Thijs Wiefferink 0d04676bce Fix including bukkit into the AreaShop jar 2019-06-23 22:27:35 +02:00
Thijs Wiefferink c8cd68c17b Fixup javadoc build 2019-06-23 22:07:34 +02:00
Thijs Wiefferink 539887449c pom.xml: build with craftbukkit 1.13 2019-06-23 21:59:04 +02:00
Thijs Wiefferink 4cda8a9292 Fix sign handling for 1.14
- Setup modules to load different classes for different Bukkit/Spigot versions
- Create BukkitHandler to get/set the sign facing and get the block it is attached to
- Fix `/as addsign` to use new sign methods
- Fix sign updates to use new sign methods
- Implement full forwards and backwards compatibility of the saved sign material type
    - On Bukkit 1.12 and lower all special wood types are translated to the standard sign
    - On Bukkit 1.13 the internal sign name is translated (and special wood types to the standard one)
    - On Bukkit 1.14 the signs of 1.13- are translated to the OAK variants
- Cleanup the .gitignore files inside of the module folders
2019-06-23 21:53:48 +02:00
Thijs Wiefferink fe131dc157 BuyRegion/RentRegion: fix %player% placeholders for selling/unrenting confirmation messages 2019-06-16 21:40:58 +02:00
Thijs Wiefferink 41ced9ee6c Update checkstyle from 7.6 to 8.21 2019-06-01 17:08:30 +02:00
Thijs Wiefferink 03de0ff252 default.yml: fix spelling mistake 2019-06-01 16:24:15 +02:00
Thijs Wiefferink b057271394 Fix permission check of /as rent, fix 'already bought' check of /as buy 2019-02-20 19:33:37 +01:00
Thijs Wiefferink d7cdff0b22 /as setteleport: fix check that hides it from /as help 2019-02-08 22:29:57 +01:00
Thijs Wiefferink 1035b6b41b Move event commands to a feature class, add two events
- Move eventCommandProfile code to a separate class
- Add AddingRegionEvent
- Add DeletingRegionEvent
- Cleanup a couple of duplicate code paths (merge RentRegion/BuyRegion branches)
2019-01-28 23:37:43 +01:00
Thijs Wiefferink e0bad7397c Refactoring based on SonarLint and Intellij IDEA inspections 2019-01-26 21:23:49 +01:00
Thijs Wiefferink b7124e8cdd Remove mcstats.org metrics class, I don't believe they will be online again 2019-01-26 20:11:26 +01:00
Thijs Wiefferink f0952c32c9 Update issue templates
Add 'NEW' label to issues created using the template
2019-01-13 22:26:54 +01:00
Thijs Wiefferink d3dfa86a65 Set version to 2.6.0 2019-01-13 17:34:50 +01:00
Thijs Wiefferink 8f73b8af3c documentation/release.md: add instructions for releasing a new version 2019-01-13 17:34:37 +01:00
Thijs Wiefferink 51b24c74b4 langHeader.yml: add the template used to generate the language file headers to the repository 2019-01-13 17:33:54 +01:00
Thijs Wiefferink 9beb1eb61b Move the changelog from the wiki to the repository 2019-01-13 17:33:09 +01:00
Thijs Wiefferink de5fdafca0 Pull translations from Transifex 2019-01-08 21:18:19 +01:00
Thijs Wiefferink 0aea914d20 Add FastAsyncWorldEdit support on Spigot 1.13
- FastAsyncWorldEdit now supported on Spigot 1.13
- Improved support for the beta-01 versions of WorldGuard and WorldEdit
- Resolves #436
2019-01-08 00:19:48 +01:00
Thijs Wiefferink b4efe7d5bf Add default labels to issue templates 2019-01-05 16:27:05 +01:00
Thijs Wiefferink ec7983e126 Fix handling of sign updates at places where they will pop off immediately
1. When placing back a missing sign it could be placed in the middle of the air
2. BlockPhysicsEvent would fire immediately (synchronously) breaking the sign
3. Sign update would break because the sign has not actually been placed
2019-01-01 19:32:34 +01:00
Thijs Wiefferink e45c353030 Fix detecting region by location when using WorldEdit 7 beta-2 or later
- The WorldEdit 7 beta-2 handler was inheriting a function from the handler of older version that uses the old Vector class
- Fixes #466
- Fixes #467
2019-01-01 19:30:16 +01:00
Thijs Wiefferink 44b1cb0fc8 /as add: fix setting player as landlord when he is an owner of the region
- Fixes #427
- Adds a debug message to check the behavior easily in the future
2018-12-28 17:11:48 +01:00
Thijs Wiefferink c7299fa56c Update Discord image to a widget image 2018-12-27 23:14:56 +01:00
pmme 12bf467714 Simplify WorldEdit 7 flushQueue vs. flushSession 2018-12-27 22:47:14 +01:00
Thijs Wiefferink 5b327db316 signs: instead of cancelling indirect break, remove the sign to prevent lagg 2018-12-27 19:44:30 +01:00
Thijs Wiefferink b4f33589a1 Cleanup old directory 2018-12-27 17:45:19 +01:00
Thijs Wiefferink 530c74ccd2 Add support for the WorldEdit vector refactor update
- Add WorldEdit and WorldGuard module that supports the new vector system
- WorldGuard/WordEdit dependencies are in the repository itself to make builds more reliable
- Change code that uses WorldEdit vectors to use Spigot vectors
- Rename all modules to areashop-[worldguard|worldedit]-<version>
- Change maven versions of internal modules to 'latest' to be less confusing
2018-12-27 17:42:24 +01:00
Thijs Wiefferink fa4857cbce Simplify code in the handler for WorldEdit 7 2018-12-27 15:00:53 +01:00
Thijs Wiefferink 93fd4e96cb Fix restoring schematics for the latest WorldEdit dev builds
- Fixes #447
- Thanks pmme and x1p for reporting the issue!
2018-10-28 17:58:09 +01:00
Thijs Wiefferink a6863ae782 Also put the Vault dependency into /dependencies
- Now it should be easy again to built AreaShop yourself, only need to run BuildTools for 1.13.0 and it should work
2018-10-28 01:15:12 +02:00
Thijs Wiefferink e5e2c4ca08 Fixup dependencies, use Bukkit/CraftBukkit 1.7.9 instead of 1.8
- 1.7.9 is the lowest supported version, so it is good to use that as base
2018-10-28 00:53:30 +02:00
Thijs Wiefferink b0341e2a3e Fix compatibility with 1.13 Material class
- Fixes sign handling to properly detect and store signs, fixes #440
- Fixes safe teleporting (also improves block detection, making it even safer)
2018-10-28 00:12:24 +02:00
Thijs Wiefferink c8e1ebb068 Change WorldGuard/WorldEdit/Bukkit dependencies to file links
- Fixes the issue that olders WorldEdit and Bukkit versions are not available on Maven anymore
- This speeds up the build a lot
2018-10-28 00:00:41 +02:00
Thijs Wiefferink 39c8eb5f73 Fix tab complete types for /as setduration 2018-10-22 23:44:31 +02:00
Thijs Wiefferink 2483cf1614 Try to add compatibility with the FAWE schematic format 2018-10-21 21:59:45 +02:00
99 changed files with 7607 additions and 7010 deletions

No files matched your search

+3
View File
@@ -1,6 +1,9 @@
---
name: Bug report
about: Report a problem in the plugin
title: ''
labels: 'NEW, Type: Bug'
assignees: ''
---
@@ -1,6 +1,9 @@
---
name: Feature request
about: Suggest an idea
title: ''
labels: 'NEW, Type: Feature'
assignees: ''
---
@@ -1,6 +1,9 @@
---
name: Support question
about: Ask help with the setup or usage of the plugin
title: ''
labels: 'NEW, Type: Support'
assignees: ''
---
+32
View File
@@ -0,0 +1,32 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn -B package --file pom.xml
+1 -1
View File
@@ -1,5 +1,5 @@
# Maven stuff
/target
target
.project
.metadata
-1
View File
@@ -1 +0,0 @@
/target
+285 -280
View File
@@ -1,280 +1,285 @@
<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>
<artifactId>areashop</artifactId>
<packaging>jar</packaging>
<name>AreaShop</name>
<version>2.5.0</version> <!-- Main plugin version -->
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
</parent>
<dependencies>
<!-- Bukkit, AreaShop aims to support 1.7.9+, but this is the lowest Bukkit version available from the Spigot repo, Bukkit repository is gone -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<type>jar</type>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- InteractiveMessenger library -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>interactivemessenger</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
<!-- BukkitDo library -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>bukkitdo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-5</artifactId>
<version>WorldGuard-5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-6</artifactId>
<version>WorldGuard-6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-6_1_3</artifactId>
<version>WorldGuard-6_1_3</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-7</artifactId>
<version>WorldGuard-7</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldedit-5</artifactId>
<version>WorldEdit-5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldedit-6</artifactId>
<version>WorldEdit-6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldedit-7</artifactId>
<version>WorldEdit-7</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<scope>system</scope>
<version>any</version>
<systemPath>${project.basedir}/../dependencies/worldedit-bukkit-7.0.0-beta-01.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<scope>system</scope>
<version>any</version>
<systemPath>${project.basedir}/../dependencies/worldguard-legacy-7.0.0-beta01.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<profiles>
<!-- Copy the jar file to a test server, activate by using -DcopyResult="/path/to/test/server" -->
<profile>
<id>test-locally</id>
<activation>
<property>
<name>copyResult</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<configuration>
<target>
<copy file="./target/${project.build.finalName}.jar"
tofile="${copyResult}\${project.build.finalName}.jar"/>
</target>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Package the source files in a jar, activate by using -Dsources -->
<profile>
<id>package-sources</id>
<activation>
<property>
<name>sources</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Produce javadoc files, activate by using -Djavadoc -->
<profile>
<id>generate-javadoc</id>
<activation>
<property>
<name>javadoc</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<phase>package</phase>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludePackageNames>me.wiefferink.areashop.lib</excludePackageNames>
<destDir>${javadoc}</destDir>
<links>
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
<link>http://docs.sk89q.com/worldedit/apidocs/</link>
<link>http://docs.sk89q.com/worldguard/apidocs/</link>
</links>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<directory>target</directory>
<finalName>AreaShop</finalName>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>hiddenConfig.yml</include>
<include>default.yml</include>
<include>README.md</include>
<include>lang/*.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<!-- Relocate messaging framework -->
<relocation>
<pattern>me.wiefferink.interactivemessenger</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.interactivemessenger</shadedPattern>
</relocation>
<!-- Relocate BukkitDo -->
<relocation>
<pattern>me.wiefferink.bukkitdo</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.bukkitdo</shadedPattern>
</relocation>
<!-- Relocate bstats -->
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
</plugins>
</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>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>areashop</artifactId>
<packaging>jar</packaging>
<name>AreaShop</name>
<version>2.7</version> <!-- Main plugin version -->
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
</repositories>
<dependencies>
<!-- Bukkit, AreaShop aims to support 1.16.5+ -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- InteractiveMessenger library -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>interactivemessenger</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
<!-- TaskChain library -->
<dependency>
<groupId>co.aikar</groupId>
<artifactId>taskchain-bukkit</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.4</version>
</dependency>
<!-- WorldEdit/WorldGuard -->
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.3</version>
<scope>provided</scope>
</dependency>
<!-- Interfaces that specific WorldGuard and WorldEdit versions are built against -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>latest</version>
<scope>compile</scope>
</dependency>
<!-- WorldGuard implementations -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-7</artifactId>
<version>latest</version>
<scope>compile</scope>
</dependency>
<!-- WorldEdit implementations -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldedit-7</artifactId>
<version>latest</version>
<scope>compile</scope>
</dependency>
<!-- FAWE compat -->
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-fawe-1-15</artifactId>
<version>latest</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- Vault -->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<!-- bStats -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<profiles>
<!-- Copy the jar file to a test server, activate by using -DcopyResult="/path/to/test/server" -->
<profile>
<id>test-locally</id>
<activation>
<property>
<name>copyResult</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<configuration>
<target>
<copy file="./target/${project.build.finalName}.jar"
tofile="${copyResult}\${project.build.finalName}.jar"/>
</target>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Package the source files in a jar, activate by using -Dsources -->
<profile>
<id>package-sources</id>
<activation>
<property>
<name>sources</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Produce javadoc files, activate by using -Djavadoc -->
<profile>
<id>generate-javadoc</id>
<activation>
<property>
<name>javadoc</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludePackageNames>me.wiefferink.areashop.lib</excludePackageNames>
<destDir>${javadoc}</destDir>
<links>
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
<link>http://docs.sk89q.com/worldedit/apidocs/</link>
<link>http://docs.sk89q.com/worldguard/apidocs/</link>
</links>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<directory>target</directory>
<finalName>AreaShop</finalName>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>hiddenConfig.yml</include>
<include>default.yml</include>
<include>README.md</include>
<include>lang/*.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<!-- Relocate TaskChain -->
<relocation>
<pattern>co.aikar.taskchain</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.taskchain</shadedPattern>
</relocation>
<!-- Relocate messaging framework -->
<relocation>
<pattern>me.wiefferink.interactivemessenger</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.interactivemessenger</shadedPattern>
</relocation>
<!-- Relocate bstats -->
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>io.papermc</pattern>
<shadedPattern>me.wiefferink.areashop.shaded.paperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
File diff suppressed because it is too large. Load diff
@@ -2,25 +2,24 @@ package me.wiefferink.areashop.commands;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
import me.wiefferink.areashop.events.notify.BoughtRegionEvent;
import me.wiefferink.areashop.events.notify.RentedRegionEvent;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import me.wiefferink.areashop.managers.FileManager;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.bukkitdo.Do;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
public class AddCommand extends CommandAreaShop {
@@ -57,7 +56,7 @@ public class AddCommand extends CommandAreaShop {
return;
}
if(args.length < 2 || args[1] == null || (!"rent".equals(args[1].toLowerCase()) && !"buy".equals(args[1].toLowerCase()))) {
if(args.length < 2 || args[1] == null || (!"rent".equalsIgnoreCase(args[1]) && !"buy".equalsIgnoreCase(args[1]))) {
plugin.message(sender, "add-help");
return;
}
@@ -79,7 +78,7 @@ public class AddCommand extends CommandAreaShop {
}
world = selection.getWorld();
regions = Utils.getWorldEditRegionsInSelection(selection).stream().collect(Collectors.toMap(ProtectedRegion::getId, region -> region));
if(regions.size() == 0) {
if(regions.isEmpty()) {
plugin.message(player, "cmd-noWERegionsFound");
return;
}
@@ -113,24 +112,26 @@ public class AddCommand extends CommandAreaShop {
}
regions.put(args[2], region);
}
final boolean isRent = "rent".equals(args[1].toLowerCase());
final boolean isRent = "rent".equalsIgnoreCase(args[1]);
final Player finalPlayer = player;
AreaShop.debug("Starting add task with " + regions.size() + " regions");
TreeSet<GeneralRegion> regionsSuccess = new TreeSet<>();
TreeSet<GeneralRegion> regionsAlready = new TreeSet<>();
TreeSet<GeneralRegion> regionsAlreadyOtherWorld = new TreeSet<>();
TreeSet<GeneralRegion> regionsRentCancelled = new TreeSet<>(); // Denied by an event listener
TreeSet<GeneralRegion> regionsBuyCancelled = new TreeSet<>(); // Denied by an event listener
TreeSet<String> namesBlacklisted = new TreeSet<>();
TreeSet<String> namesNoPermission = new TreeSet<>();
Do.forAll(
TreeSet<String> namesAddCancelled = new TreeSet<>(); // Denied by an event listener
Utils.runAsBatches(regions.entrySet(),
plugin.getConfig().getInt("adding.regionsPerTick"),
regions.entrySet(),
regionEntry -> {
(regionEntry) -> {
String regionName = regionEntry.getKey();
ProtectedRegion region = regionEntry.getValue();
// Determine if the player is an owner or member of the region
boolean isMember = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
boolean isOwner = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
boolean isOwner = finalPlayer != null && plugin.getWorldGuardHandler().containsOwner(region, finalPlayer.getUniqueId());
String type;
if(isRent) {
type = "rent";
@@ -154,46 +155,56 @@ public class AddCommand extends CommandAreaShop {
List<UUID> existing = new ArrayList<>();
existing.addAll(plugin.getWorldGuardHandler().getOwners(region).asUniqueIdList());
existing.addAll(plugin.getWorldGuardHandler().getMembers(region).asUniqueIdList());
AreaShop.debug("regionAddLandlordStatus:", regionName,
"landlord:", landlord,
"existing:", existing,
"isMember:", isMember,
"isOwner:", isOwner,
"createPermission:", sender.hasPermission("areashop.create" + type),
"ownerPermission:", sender.hasPermission("areashop.create" + type + ".owner"),
"memberPermission:", sender.hasPermission("areashop.create" + type + ".member"));
if(isRent) {
RentRegion rent = new RentRegion(regionName, world);
// Set landlord
if(landlord) {
rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
}
// Run commands
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addRent(rent);
AddingRegionEvent event = plugin.getFileManager().addRegion(rent);
if (event.isCancelled()) {
namesAddCancelled.add(rent.getName());
return;
}
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
rent.update();
// Run commands
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
// Add existing owners/members if any
if(!landlord && !existing.isEmpty()) {
// TODO also execute rent events to notify other plugins?
UUID rentBy = existing.remove(0);
OfflinePlayer rentByPlayer = Bukkit.getOfflinePlayer(rentBy);
// Run commands
rent.runEventCommands(GeneralRegion.RegionEvent.RENTED, true);
RentingRegionEvent rentingRegionEvent = new RentingRegionEvent(rent, rentByPlayer, false);
Bukkit.getPluginManager().callEvent(rentingRegionEvent);
if(rentingRegionEvent.isCancelled()) {
regionsRentCancelled.add(rent);
} else {
// Add values to the rent and send it to FileManager
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
rent.setRenter(rentBy);
rent.updateLastActiveTime();
// Add values to the rent and send it to FileManager
rent.setRentedUntil(Calendar.getInstance().getTimeInMillis() + rent.getDuration());
rent.setRenter(existing.remove(0));
rent.updateLastActiveTime();
// Fire schematic event and updated times extended
rent.handleSchematicEvent(GeneralRegion.RegionEvent.RENTED);
// Add others as friends
for(UUID friend : existing) {
rent.getFriendsFeature().addFriend(friend, null);
// Add others as friends
for(UUID friend : existing) {
rent.getFriendsFeature().addFriend(friend, null);
}
rent.notifyAndUpdate(new RentedRegionEvent(rent, false));
}
// Fire schematic event and updated times extended
rent.handleSchematicEvent(GeneralRegion.RegionEvent.RENTED);
// Notify about updates
rent.update();
rent.runEventCommands(GeneralRegion.RegionEvent.RENTED, false);
}
regionsSuccess.add(rent);
@@ -203,47 +214,47 @@ public class AddCommand extends CommandAreaShop {
if(landlord) {
buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName());
}
// Run commands
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addBuy(buy);
AddingRegionEvent event = plugin.getFileManager().addRegion(buy);
if (event.isCancelled()) {
namesAddCancelled.add(buy.getName());
return;
}
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
buy.update();
// Run commands
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
// Add existing owners/members if any
if(!landlord && !existing.isEmpty()) {
// TODO also execute buy events to notify for other plugins?
UUID buyBy = existing.remove(0);
OfflinePlayer buyByPlayer = Bukkit.getOfflinePlayer(buyBy);
// Run commands
buy.runEventCommands(GeneralRegion.RegionEvent.BOUGHT, true);
BuyingRegionEvent buyingRegionEvent = new BuyingRegionEvent(buy, buyByPlayer);
Bukkit.getPluginManager().callEvent(buyingRegionEvent);
if(buyingRegionEvent.isCancelled()) {
regionsBuyCancelled.add(buy);
} else {
// Set the owner
buy.setBuyer(buyBy);
buy.updateLastActiveTime();
// Set the owner
buy.setBuyer(existing.remove(0));
buy.updateLastActiveTime();
// Add others as friends
for(UUID friend : existing) {
buy.getFriendsFeature().addFriend(friend, null);
// Update everything
buy.handleSchematicEvent(GeneralRegion.RegionEvent.BOUGHT);
// Add others as friends
for (UUID friend : existing) {
buy.getFriendsFeature().addFriend(friend, null);
}
buy.notifyAndUpdate(new BoughtRegionEvent(buy));
}
// Notify about updates
buy.update();
// Update everything
buy.handleSchematicEvent(GeneralRegion.RegionEvent.BOUGHT);
// Run commands
buy.runEventCommands(GeneralRegion.RegionEvent.BOUGHT, false);
}
regionsSuccess.add(buy);
}
}
},
() -> {
}, false).thenAccept(
(success) -> {
if(!regionsSuccess.isEmpty()) {
plugin.message(sender, "add-success", args[1], Utils.combinedMessage(regionsSuccess, "region"));
}
@@ -253,6 +264,12 @@ public class AddCommand extends CommandAreaShop {
if(!regionsAlreadyOtherWorld.isEmpty()) {
plugin.message(sender, "add-failedOtherWorld", Utils.combinedMessage(regionsAlreadyOtherWorld, "region"));
}
if(!regionsRentCancelled.isEmpty()) {
plugin.message(sender, "add-rentCancelled", Utils.combinedMessage(regionsRentCancelled, "region"));
}
if(!regionsBuyCancelled.isEmpty()) {
plugin.message(sender, "add-buyCancelled", Utils.combinedMessage(regionsBuyCancelled, "region"));
}
if(!namesBlacklisted.isEmpty()) {
plugin.message(sender, "add-blacklisted", Utils.createCommaSeparatedList(namesBlacklisted));
}
@@ -260,13 +277,15 @@ public class AddCommand extends CommandAreaShop {
plugin.message(sender, "add-noPermissionRegions", Utils.createCommaSeparatedList(namesNoPermission));
plugin.message(sender, "add-noPermissionOwnerMember");
}
}
);
if(!namesAddCancelled.isEmpty()) {
plugin.message(sender, "add-rentCancelled", Utils.createCommaSeparatedList(namesAddCancelled));
}
});
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
List<String> result = new LinkedList<>();
if(toComplete == 2) {
if(sender.hasPermission("areashop.createrent")) {
result.add("rent");
@@ -3,12 +3,16 @@ package me.wiefferink.areashop.commands;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.material.Sign;
import org.bukkit.util.BlockIterator;
import java.util.ArrayList;
@@ -17,100 +21,108 @@ import java.util.Set;
public class AddsignCommand extends CommandAreaShop {
@Override
public String getCommandStart() {
return "areashop addsign";
}
@Override
public String getCommandStart() {
return "areashop addsign";
}
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.addsign")) {
return "help-addsign";
}
return null;
}
@Override
public String getHelp(CommandSender target) {
if (target.hasPermission("areashop.addsign")) {
return "help-addsign";
}
return null;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.addsign")) {
plugin.message(sender, "addsign-noPermission");
return;
}
if(!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
Player player = (Player)sender;
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.addsign")) {
plugin.message(sender, "addsign-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
Player player = (Player) sender;
// Get the sign
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
while(blockIterator.hasNext() && block == null) {
Block next = blockIterator.next();
if(next.getType() != Material.AIR) {
block = next;
}
}
if(block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
plugin.message(sender, "addsign-noSign");
return;
}
// Get the sign
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
while (blockIterator.hasNext() && block == null) {
Block next = blockIterator.next();
if (next.getType() != Material.AIR) {
block = next;
}
}
if (block == null || !Materials.isSign(block.getType())) {
plugin.message(sender, "addsign-noSign");
return;
}
GeneralRegion region;
if(args.length > 1) {
// Get region by argument
region = plugin.getFileManager().getRegion(args[1]);
if(region == null) {
plugin.message(sender, "cmd-notRegistered", args[1]);
return;
}
} else {
// Get region by sign position
List<GeneralRegion> regions = Utils.getImportantRegions(block.getLocation());
if(regions.isEmpty()) {
plugin.message(sender, "addsign-noRegions");
return;
} else if(regions.size() > 1) {
plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
return;
}
region = regions.get(0);
}
Sign sign = (Sign)block.getState().getData();
String profile = null;
if(args.length > 2) {
profile = args[2];
Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
if(!profiles.contains(profile)) {
plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
return;
}
}
RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
if(regionSign != null) {
plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
return;
}
GeneralRegion region;
if (args.length > 1) {
// Get region by argument
region = plugin.getFileManager().getRegion(args[1]);
if (region == null) {
plugin.message(sender, "cmd-notRegistered", args[1]);
return;
}
} else {
// Get region by sign position
List<GeneralRegion> regions = Utils.getImportantRegions(block.getLocation());
if (regions.isEmpty()) {
plugin.message(sender, "addsign-noRegions");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
return;
}
region = regions.get(0);
}
String profile = null;
if (args.length > 2) {
profile = args[2];
Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
if (!profiles.contains(profile)) {
plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
return;
}
}
RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
if (regionSign != null) {
plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
return;
}
region.getSignsFeature().addSign(block.getLocation(), block.getType(), sign.getFacing(), profile);
if(profile == null) {
plugin.message(sender, "addsign-success", region);
} else {
plugin.message(sender, "addsign-successProfile", profile, region);
}
region.update();
}
final BlockData data = block.getBlockData();
final BlockFace rotation;
if (data instanceof Sign) {
rotation = ((Sign) data).getRotation();
} else if (data instanceof WallSign) {
rotation = ((WallSign) data).getFacing();
} else {
rotation = null;
}
region.getSignsFeature().addSign(block.getLocation(), block.getType(), rotation, profile);
if (profile == null) {
plugin.message(sender, "addsign-success", region);
} else {
plugin.message(sender, "addsign-successProfile", profile, region);
}
region.update();
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {
result.addAll(plugin.getConfig().getStringList("signProfiles"));
}
return result;
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
if (toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if (toComplete == 3) {
result.addAll(plugin.getConfig().getStringList("signProfiles"));
}
return result;
}
}
@@ -6,10 +6,7 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Abstract class for generalising command classes.
@@ -31,11 +28,12 @@ public abstract class CommandAreaShop {
* @return true if it can execute the command, false otherwise
*/
public boolean canExecute(Command command, String[] args) {
String commandString = command.getName() + " " + StringUtils.join(args, " ");
if(commandString.length() > getCommandStart().length()) {
return commandString.toLowerCase().startsWith(getCommandStart().toLowerCase() + " ");
String commandString = command.getName() + " " + StringUtils.join(args, " ").toLowerCase();
final String start = getCommandStart().toLowerCase();
if(commandString.length() > start.length()) {
return commandString.startsWith(start + " ");
}
return commandString.toLowerCase().startsWith(getCommandStart().toLowerCase());
return commandString.startsWith(start);
}
/**
@@ -46,7 +44,7 @@ public abstract class CommandAreaShop {
* @return A collection with all the possibilities for argument to complete
*/
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
return new ArrayList<>();
return Collections.emptyList();
}
/**
@@ -89,9 +87,9 @@ public abstract class CommandAreaShop {
return false;
}
private class CommandTime {
public String command;
public long time;
private static class CommandTime {
public final String command;
public final long time;
CommandTime(String command, long time) {
this.command = command;
@@ -1,5 +1,6 @@
package me.wiefferink.areashop.commands;
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -50,37 +51,45 @@ public class DelCommand extends CommandAreaShop {
return;
}
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
if(regions == null || regions.size() == 0) {
if(regions == null || regions.isEmpty()) {
plugin.message(player, "cmd-noRegionsFound");
return;
}
// Start removing the regions that he has permission for
ArrayList<String> namesSuccess = new ArrayList<>();
TreeSet<GeneralRegion> namesFailed = new TreeSet<>();
TreeSet<GeneralRegion> regionsFailed = new TreeSet<>();
TreeSet<GeneralRegion> regionsCancelled = new TreeSet<>();
for(GeneralRegion region : regions) {
boolean isLandlord = region.isLandlord(((Player)sender).getUniqueId());
if(region instanceof RentRegion) {
if(!sender.hasPermission("areashop.destroyrent") && !(isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
namesFailed.add(region);
} else {
plugin.getFileManager().removeRent((RentRegion)region, true);
namesSuccess.add(region.getName());
regionsFailed.add(region);
continue;
}
} else if(region instanceof BuyRegion) {
if(!sender.hasPermission("areashop.destroybuy") && !(isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
namesFailed.add(region);
} else {
plugin.getFileManager().removeBuy((BuyRegion)region, true);
namesSuccess.add(region.getName());
regionsFailed.add(region);
continue;
}
}
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
if (event.isCancelled()) {
regionsCancelled.add(region);
} else {
namesSuccess.add(region.getName());
}
}
// send messages
if(namesSuccess.size() != 0) {
// Send messages
if(!namesSuccess.isEmpty()) {
plugin.message(sender, "del-success", Utils.createCommaSeparatedList(namesSuccess));
}
if(namesFailed.size() != 0) {
plugin.message(sender, "del-failed", Utils.combinedMessage(namesFailed, "region"));
if(!regionsFailed.isEmpty()) {
plugin.message(sender, "del-failed", Utils.combinedMessage(regionsFailed, "region"));
}
if(!regionsCancelled.isEmpty()) {
plugin.message(sender, "del-cancelled", Utils.combinedMessage(regionsCancelled, "region"));
}
} else {
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
@@ -92,16 +101,24 @@ public class DelCommand extends CommandAreaShop {
if(region instanceof RentRegion) {
// Remove the rent if the player has permission
if(sender.hasPermission("areashop.destroyrent") || (isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
plugin.getFileManager().removeRent((RentRegion)region, true);
plugin.message(sender, "destroy-successRent", region);
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
if (event.isCancelled()) {
plugin.message(sender, "general-cancelled", event.getReason());
} else {
plugin.message(sender, "destroy-successRent", region);
}
} else {
plugin.message(sender, "destroy-noPermissionRent", region);
}
} else if(region instanceof BuyRegion) {
// Remove the buy if the player has permission
if(sender.hasPermission("areashop.destroybuy") || (isLandlord && sender.hasPermission("areashop.destroybuy.landlord"))) {
plugin.getFileManager().removeBuy((BuyRegion)region, true);
plugin.message(sender, "destroy-successBuy", region);
DeletingRegionEvent event = plugin.getFileManager().deleteRegion(region, true);
if (event.isCancelled()) {
plugin.message(sender, "general-cancelled", event.getReason());
} else {
plugin.message(sender, "destroy-successBuy", region);
}
} else {
plugin.message(sender, "destroy-noPermissionBuy", region);
}
@@ -2,6 +2,7 @@ package me.wiefferink.areashop.commands;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.tools.Materials;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
@@ -47,7 +48,7 @@ public class DelsignCommand extends CommandAreaShop {
block = next;
}
}
if(block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
if(block == null || !Materials.isSign(block.getType())) {
plugin.message(sender, "delsign-noSign");
return;
}
@@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class FindCommand extends CommandAreaShop {
@@ -82,7 +83,7 @@ public class FindCommand extends CommandAreaShop {
}
if(!results.isEmpty()) {
// Draw a random one
BuyRegion region = results.get(new Random().nextInt(results.size()));
BuyRegion region = results.get(ThreadLocalRandom.current().nextInt(results.size()));
Message onlyInGroup = Message.empty();
if(group != null) {
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(args[3]);
@@ -122,7 +123,7 @@ public class FindCommand extends CommandAreaShop {
}
if(!results.isEmpty()) {
// Draw a random one
RentRegion region = results.get(new Random().nextInt(results.size()));
RentRegion region = results.get(ThreadLocalRandom.current().nextInt(results.size()));
Message onlyInGroup = Message.empty();
if(group != null) {
onlyInGroup = Message.fromKey("find-onlyInGroup").replacements(args[3]);
@@ -53,7 +53,7 @@ public class GroupaddCommand extends CommandAreaShop {
return;
}
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
if(regions.size() == 0) {
if(regions.isEmpty()) {
plugin.message(player, "cmd-noRegionsFound");
return;
}
@@ -66,10 +66,10 @@ public class GroupaddCommand extends CommandAreaShop {
regionsFailed.add(region);
}
}
if(regionsSuccess.size() != 0) {
if(!regionsSuccess.isEmpty()) {
plugin.message(player, "groupadd-weSuccess", group.getName(), Utils.combinedMessage(regionsSuccess, "region"));
}
if(regionsFailed.size() != 0) {
if(!regionsFailed.isEmpty()) {
plugin.message(player, "groupadd-weFailed", group.getName(), Utils.combinedMessage(regionsFailed, "region"));
}
// Update all regions, this does it in a task, updating them without lag
@@ -54,7 +54,7 @@ public class GroupdelCommand extends CommandAreaShop {
return;
}
List<GeneralRegion> regions = Utils.getRegionsInSelection(selection);
if(regions.size() == 0) {
if(regions.isEmpty()) {
plugin.message(player, "cmd-noRegionsFound");
return;
}
@@ -67,10 +67,10 @@ public class GroupdelCommand extends CommandAreaShop {
regionsFailed.add(region);
}
}
if(regionsSuccess.size() != 0) {
if(!regionsSuccess.isEmpty()) {
plugin.message(player, "groupdel-weSuccess", group.getName(), Utils.combinedMessage(regionsSuccess, "region"));
}
if(regionsFailed.size() != 0) {
if(!regionsFailed.isEmpty()) {
plugin.message(player, "groupdel-weFailed", group.getName(), Utils.combinedMessage(regionsFailed, "region"));
}
// Update all regions, this does it in a task, updating them without lag
@@ -40,7 +40,7 @@ public class GroupinfoCommand extends CommandAreaShop {
return;
}
Set<String> members = group.getMembers();
if(members.size() == 0) {
if(members.isEmpty()) {
plugin.message(sender, "groupinfo-noMembers", group.getName());
} else {
plugin.message(sender, "groupinfo-members", group.getName(), Utils.createCommaSeparatedList(members));
@@ -28,7 +28,7 @@ public class GrouplistCommand extends CommandAreaShop {
return;
}
List<String> groups = plugin.getFileManager().getGroupNames();
if(groups.size() == 0) {
if(groups.isEmpty()) {
plugin.message(sender, "grouplist-noGroups");
} else {
plugin.message(sender, "grouplist-success", Utils.createCommaSeparatedList(groups));
@@ -27,11 +27,11 @@ public class ImportCommand extends CommandAreaShop {
return null;
}
// TODO
// - Landlord?
// - Friends
// - Region flags?
// - Settings from the 'permissions' section in RegionForSale/config.yml?
// TODO:
// - Landlord?
// - Friends
// - Region flags?
// - Settings from the 'permissions' section in RegionForSale/config.yml?
@Override
public void execute(CommandSender sender, String[] args) {
@@ -54,7 +54,7 @@ public class ImportCommand extends CommandAreaShop {
return;
}
ImportJob importJob = new ImportJob(sender);
new ImportJob(sender);
}
@Override
@@ -4,6 +4,7 @@ import com.google.common.base.Charsets;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.regions.BuyRegion;
@@ -240,10 +241,13 @@ public class ImportJob {
GeneralRegion region;
if(rentable || (owner != null && !isBought)) {
region = new RentRegion(regionKey, world);
plugin.getFileManager().addRent((RentRegion)region);
} else {
region = new BuyRegion(regionKey, world);
plugin.getFileManager().addBuy((BuyRegion)region);
}
AddingRegionEvent event = plugin.getFileManager().addRegion(region);
if (event.isCancelled()) {
messageNoPrefix("general-cancelled", event.getReason());
continue;
}
// Import settings
@@ -330,7 +334,7 @@ public class ImportJob {
String buyPrice = from.getString("economic-settings.cost-per-unit.buy");
String sellPrice = from.getString("economic-settings.cost-per-unit.selling-price");
// TODO: There is no easy way to import this, setup eventCommandsProfile?
String taxes = from.getString("economic-settings.cost-per-unit.taxes");
// String taxes = from.getString("economic-settings.cost-per-unit.taxes");
// Determine unit and add that to the price
String unitSuffix = "";
@@ -411,8 +415,8 @@ public class ImportJob {
}
private static class TimeUnit {
public long minutes;
public String identifier;
public final long minutes;
public final String identifier;
TimeUnit(long minutes, String identifier) {
this.minutes = minutes;
@@ -113,9 +113,9 @@ public class InfoCommand extends CommandAreaShop {
}
// Page status
if(totalPages > 1) {
String pageString = "" + page;
StringBuilder pageString = new StringBuilder("" + page);
for(int i = pageString.length(); i < (totalPages + "").length(); i++) {
pageString = "0" + pageString;
pageString.insert(0, "0");
}
footer.append(Message.fromKey("info-pageStatus").replacements(page, totalPages));
if(page < totalPages) {
@@ -19,9 +19,7 @@ public class MessageCommand extends CommandAreaShop {
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.message")) {
return null; // Internal command, no need to show in the help list
}
// Internal command, no need to show in the help list
return null;
}
@@ -90,14 +90,14 @@ public class SetdurationCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getRentNames();
} else if(toComplete == 4) {
if(toComplete == 3) {
result.addAll(plugin.getConfig().getStringList("minutes"));
result.addAll(plugin.getConfig().getStringList("hours"));
result.addAll(plugin.getConfig().getStringList("days"));
result.addAll(plugin.getConfig().getStringList("months"));
result.addAll(plugin.getConfig().getStringList("years"));
} else if(toComplete == 4) {
result = plugin.getFileManager().getRentNames();
}
return result;
}
@@ -20,7 +20,7 @@ public class SetteleportCommand extends CommandAreaShop {
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
if(target.hasPermission("areashop.setteleportall") || target.hasPermission("areashop.setteleport")) {
return "help-setteleport";
}
return null;
@@ -1,10 +1,9 @@
package me.wiefferink.areashop.commands;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -17,6 +16,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
@@ -104,7 +104,7 @@ public class StackCommand extends CommandAreaShop {
plugin.message(player, "stack-unclearDirection", facing.toString().toLowerCase().replace('_', '-'));
return;
}
Vector shift = new BlockVector(0, 0, 0);
Vector shift = new Vector(0, 0, 0);
if(facing == BlockFace.SOUTH) {
shift = shift.setZ(-selection.getLength() - gap);
} else if(facing == BlockFace.WEST) {
@@ -158,33 +158,16 @@ public class StackCommand extends CommandAreaShop {
current++;
if(current < amount) {
// Create the region name
String counterName = counter + "";
int minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
while(counterName.length() < minimumLength) {
counterName = "0" + counterName;
}
String regionName;
if(nameTemplate.contains("#")) {
regionName = nameTemplate.replace("#", counterName);
} else {
regionName = nameTemplate + counterName;
}
String regionName = countToName(nameTemplate, counter);
while(manager.getRegion(regionName) != null || AreaShop.getInstance().getFileManager().getRegion(regionName) != null) {
counter++;
counterName = counter + "";
minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
while(counterName.length() < minimumLength) {
counterName = "0" + counterName;
}
if(nameTemplate.contains("#")) {
regionName = nameTemplate.replace("#", counterName);
} else {
regionName = nameTemplate + counterName;
}
regionName = countToName(nameTemplate, counter);
}
// Add the region to WorldGuard (at startposition shifted by the number of this region times the blocks it should shift)
BlockVector minimum = new BlockVector(minimumVector.add(finalShift.multiply(current)));
BlockVector maximum = new BlockVector(maximumVector.add(finalShift.multiply(current)));
Vector minimum = minimumVector.clone().add(finalShift.clone().multiply(current));
Vector maximum = maximumVector.clone().add(finalShift.clone().multiply(current));
// Check for out of bounds
if(minimum.getBlockY() < 0) {
tooLow++;
@@ -193,30 +176,28 @@ public class StackCommand extends CommandAreaShop {
tooHigh++;
continue;
}
ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, minimum, maximum);
ProtectedCuboidRegion region = plugin.getWorldGuardHandler().createCuboidRegion(regionName, minimum,maximum);
manager.addRegion(region);
// Add the region to AreaShop
GeneralRegion newRegion;
if(rentRegions) {
RentRegion rent = new RentRegion(regionName, selection.getWorld());
if(finalGroup != null) {
finalGroup.addMember(rent);
}
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addRent(rent);
rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
rent.update();
newRegion = new RentRegion(regionName, selection.getWorld());
} else {
BuyRegion buy = new BuyRegion(regionName, selection.getWorld());
if(finalGroup != null) {
finalGroup.addMember(buy);
}
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
plugin.getFileManager().addBuy(buy);
buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
buy.update();
newRegion = new BuyRegion(regionName, selection.getWorld());
}
if(finalGroup != null) {
finalGroup.addMember(newRegion);
}
AddingRegionEvent event = plugin.getFileManager().addRegion(newRegion);
if (event.isCancelled()) {
plugin.message(player, "general-cancelled", event.getReason());
continue;
}
newRegion.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
newRegion.update();
}
}
if(current >= amount) {
@@ -237,6 +218,26 @@ public class StackCommand extends CommandAreaShop {
}.runTaskTimer(plugin, 1, 1);
}
/**
* Build a name from a count, with the right length.
* @param template Template to put the name in (# to put the count there, otherwise count is appended)
* @param count Number to use
* @return name with prepended 0's
*/
private String countToName(String template, int count) {
StringBuilder counterName = new StringBuilder().append(count);
int minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
while(counterName.length() < minimumLength) {
counterName.insert(0, "0");
}
if(template.contains("#")) {
return template.replace("#", counterName);
} else {
return template + counterName;
}
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<>();
@@ -5,77 +5,79 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TeleportCommand extends CommandAreaShop {
@Override
public String getCommandStart() {
return "areashop tp";
}
/**
* Check if a person can teleport to the region (assuming he is not teleporting to a sign).
*
* @param person The person to check
* @param region The region to check for
* @return true if the person can teleport to it, otherwise false
*/
public static boolean canUse(CommandSender person, GeneralRegion region) {
if (!(person instanceof Player)) {
return false;
}
Player player = (Player) person;
return player.hasPermission("areashop.teleportall")
|| region.isOwner(player) && player.hasPermission("areashop.teleport")
|| region.isAvailable() && player.hasPermission("areashop.teleportavailable")
|| region.getFriendsFeature().getFriends().contains(player.getUniqueId()) && player.hasPermission("areashop.teleportfriend");
}
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
return "help-teleport";
}
return null;
}
@Override
public String getCommandStart() {
return "areashop tp";
}
/**
* Check if a person can teleport to the region (assuming he is not teleporting to a sign).
* @param person The person to check
* @param region The region to check for
* @return true if the person can teleport to it, otherwise false
*/
public static boolean canUse(CommandSender person, GeneralRegion region) {
if(!(person instanceof Player)) {
return false;
}
Player player = (Player)person;
return player.hasPermission("areashop.teleportall")
|| region.isOwner(player) && player.hasPermission("areashop.teleport")
|| region.isAvailable() && player.hasPermission("areashop.teleportavailable")
|| region.getFriendsFeature().getFriends().contains(player.getUniqueId()) && player.hasPermission("areashop.teleportfriend");
}
@Override
public String getHelp(CommandSender target) {
if (target.hasPermission("areashop.teleportall") || target.hasPermission("areashop.teleport")) {
return "help-teleport";
}
return null;
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportavailable") && !sender.hasPermission("areashop.teleportavailablesign") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
plugin.message(sender, "teleport-noPermission");
return;
}
if(!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
if(args.length <= 1 || args[1] == null) {
plugin.message(sender, "teleport-help");
return;
}
Player player = (Player)sender;
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
if(region == null) {
plugin.message(player, "teleport-noRentOrBuy", args[1]);
return;
}
if(args.length >= 3 && (args[2].equalsIgnoreCase("sign") || args[2].equalsIgnoreCase("yes") || args[2].equalsIgnoreCase("true"))) {
region.getTeleportFeature().teleportPlayer(player, true);
} else {
region.getTeleportFeature().teleportPlayer(player, false);
}
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportavailable") && !sender.hasPermission("areashop.teleportavailablesign") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
plugin.message(sender, "teleport-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
if (args.length <= 1 || args[1] == null) {
plugin.message(sender, "teleport-help");
return;
}
Player player = (Player) sender;
GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
if (region == null) {
plugin.message(player, "teleport-noRentOrBuy", args[1]);
return;
}
}
boolean toSign = args.length >= 3 && (
args[2].equalsIgnoreCase("sign")
|| args[2].equalsIgnoreCase("yes")
|| args[2].equalsIgnoreCase("true")
);
region.getTeleportFeature().teleportPlayer(player, toSign, true);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {
result.add("sign");
}
return result;
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
if (toComplete == 2) {
return plugin.getFileManager().getRegionNames();
} else if (toComplete == 3) {
return Collections.singletonList("sign");
}
return Collections.emptyList();
}
}
@@ -16,6 +16,7 @@ public class RegionEvent<T> extends Event {
return handlers;
}
// Required by Bukkit/Spigot
public static HandlerList getHandlerList() {
return handlers;
}
@@ -0,0 +1,19 @@
package me.wiefferink.areashop.events.ask;
import me.wiefferink.areashop.events.CancellableRegionEvent;
import me.wiefferink.areashop.regions.GeneralRegion;
/**
* Broadcasted when a region has been added to AreaShop.
*/
public class AddingRegionEvent extends CancellableRegionEvent<GeneralRegion> {
/**
* Constructor.
* @param region The region that has been added
*/
public AddingRegionEvent(GeneralRegion region) {
super(region);
}
}
@@ -0,0 +1,19 @@
package me.wiefferink.areashop.events.ask;
import me.wiefferink.areashop.events.CancellableRegionEvent;
import me.wiefferink.areashop.regions.GeneralRegion;
/**
* Broadcasted when a region has been added to AreaShop.
*/
public class DeletingRegionEvent extends CancellableRegionEvent<GeneralRegion> {
/**
* Constructor.
* @param region The region that has been added
*/
public DeletingRegionEvent(GeneralRegion region) {
super(region);
}
}
@@ -0,0 +1,118 @@
package me.wiefferink.areashop.features;
import me.wiefferink.areashop.events.ask.AddingRegionEvent;
import me.wiefferink.areashop.events.ask.BuyingRegionEvent;
import me.wiefferink.areashop.events.ask.DeletingRegionEvent;
import me.wiefferink.areashop.events.ask.RentingRegionEvent;
import me.wiefferink.areashop.events.ask.ResellingRegionEvent;
import me.wiefferink.areashop.events.ask.SellingRegionEvent;
import me.wiefferink.areashop.events.ask.UnrentingRegionEvent;
import me.wiefferink.areashop.events.notify.AddedRegionEvent;
import me.wiefferink.areashop.events.notify.BoughtRegionEvent;
import me.wiefferink.areashop.events.notify.DeletedRegionEvent;
import me.wiefferink.areashop.events.notify.RentedRegionEvent;
import me.wiefferink.areashop.events.notify.ResoldRegionEvent;
import me.wiefferink.areashop.events.notify.SoldRegionEvent;
import me.wiefferink.areashop.events.notify.UnrentedRegionEvent;
import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import java.util.List;
public class CommandsFeature extends RegionFeature {
/**
* Run command for a certain event.
* @param region Region to execute the events for
* @param event The event
* @param before The 'before' or 'after' commands
*/
public void runEventCommands(GeneralRegion region, GeneralRegion.RegionEvent event, boolean before) {
ConfigurationSection eventCommandProfileSection = region.getConfigurationSectionSetting("general.eventCommandProfile", "eventCommandProfiles");
if(eventCommandProfileSection == null) {
return;
}
List<String> commands = eventCommandProfileSection.getStringList(event.getValue() + "." + (before ? "before" : "after"));
if(commands == null || commands.isEmpty()) {
return;
}
region.runCommands(Bukkit.getConsoleSender(), commands);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void addingRegion(AddingRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.CREATED, true);
}
@EventHandler
public void addedRegion(AddedRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.CREATED, false);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void deletingRegion(DeletingRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.DELETED, true);
}
@EventHandler
public void deletedRegion(DeletedRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.DELETED, false);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void rentingRegion(RentingRegionEvent event) {
// Technically the rent can still be cancelled if the payment fails...
runEventCommands(event.getRegion(), event.isExtending() ? GeneralRegion.RegionEvent.EXTENDED : GeneralRegion.RegionEvent.RENTED, true);
}
@EventHandler
public void rentedRegion(RentedRegionEvent event) {
runEventCommands(event.getRegion(), event.hasExtended() ? GeneralRegion.RegionEvent.EXTENDED : GeneralRegion.RegionEvent.RENTED, false);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void buyingRegion(BuyingRegionEvent event) {
// Technically the buy can still be cancelled if the payment fails...
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.BOUGHT, true);
}
@EventHandler
public void boughtRegion(BoughtRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.BOUGHT, false);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void resellingRegion(ResellingRegionEvent event) {
// Technically the resell can still be cancelled if the payment fails...
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.RESELL, true);
}
@EventHandler
public void resoldRegion(ResoldRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.RESELL, false);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void sellingRegion(SellingRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.SOLD, true);
}
@EventHandler
public void soldRegion(SoldRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.SOLD, false);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void unrentingRegion(UnrentingRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.UNRENTED, true);
}
@EventHandler
public void unrentedRegion(UnrentedRegionEvent event) {
runEventCommands(event.getRegion(), GeneralRegion.RegionEvent.UNRENTED, false);
}
}
@@ -6,10 +6,31 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
/*
Possible future feature classes:
- RestrictedToRegion feature
- rent/buy restricted to the region itself
- RestrictedToWorld feature
- rent/buy restricted to the world of the region
- CountLimitsFeature:
- Check region limits
- TimeLimitsFeatures:
- maxExtends
- maxRentTime
- SchematicFeature
- save/load schematics
- CommandsFeature
- execute commands after extend/rent/etc
- LandlordFeature
- manage landlords
- ExpirationWarningsFeature
- sending rental expiration warnings
*/
public abstract class RegionFeature implements Listener {
public static final AreaShop plugin = AreaShop.getInstance();
public YamlConfiguration config = plugin.getConfig();
protected YamlConfiguration config = plugin.getConfig();
private GeneralRegion region;
/**
@@ -1,520 +0,0 @@
package me.wiefferink.areashop.features;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.areashop.tools.Value;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TeleportFeature extends RegionFeature {
private static final ArrayList<Material> canSpawnIn = new ArrayList<>(Arrays.asList(Material.WOOD_DOOR, Material.WOODEN_DOOR, Material.SIGN_POST, Material.WALL_SIGN, Material.STONE_PLATE, Material.IRON_DOOR_BLOCK, Material.WOOD_PLATE, Material.TRAP_DOOR, Material.REDSTONE_LAMP_OFF, Material.REDSTONE_LAMP_ON, Material.DRAGON_EGG, Material.GOLD_PLATE, Material.IRON_PLATE));
private static final ArrayList<Material> cannotSpawnOn = new ArrayList<>(Arrays.asList(Material.PISTON_EXTENSION, Material.PISTON_MOVING_PIECE, Material.SIGN_POST, Material.WALL_SIGN, Material.STONE_PLATE, Material.IRON_DOOR_BLOCK, Material.WOOD_PLATE, Material.TRAP_DOOR, Material.REDSTONE_LAMP_OFF, Material.REDSTONE_LAMP_ON, Material.CACTUS, Material.IRON_FENCE, Material.FENCE_GATE, Material.THIN_GLASS, Material.NETHER_FENCE, Material.DRAGON_EGG, Material.GOLD_PLATE, Material.IRON_PLATE, Material.STAINED_GLASS_PANE));
private static final ArrayList<Material> cannotSpawnBeside = new ArrayList<>(Arrays.asList(Material.LAVA, Material.STATIONARY_LAVA, Material.CACTUS));
public TeleportFeature() {
}
public TeleportFeature(GeneralRegion region) {
setRegion(region);
}
/**
* Get the teleportlocation set for this region.
* @return The teleport location, or null if not set
*/
public Location getTeleportLocation() {
return Utils.configToLocation(getRegion().getConfigurationSectionSetting("general.teleportLocation"));
}
/**
* Check if the region has a teleportLocation specified.
* @return true if the region has a teleportlocation, false otherwise
*/
public boolean hasTeleportLocation() {
return getRegion().getConfigurationSectionSetting("general.teleportLocation") != null;
}
/**
* Set the teleport location of this region.
* @param location The location to set as teleport location
*/
public void setTeleport(Location location) {
if(location == null) {
getRegion().setSetting("general.teleportLocation", null);
} else {
getRegion().setSetting("general.teleportLocation", Utils.locationToConfig(location, true));
}
}
/**
* Teleport a player to the region or sign.
* @param player Player that should be teleported
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
* @param checkRestrictions Set to true if teleport permissions should be checked, false otherwise, also toggles cross-world check
* @return true if the teleport succeeded, otherwise false
*/
public boolean teleportPlayer(Player player, boolean toSign, boolean checkRestrictions) {
// Check basics
if(getRegion().getWorld() == null) {
getRegion().message(player, "general-noWorld");
return false;
}
if(getRegion().getRegion() == null) {
getRegion().message(player, "general-noRegion");
return false;
}
if(checkRestrictions) {
// Check correct world
if(!getRegion().getBooleanSetting("general.teleportCrossWorld") && !player.getWorld().equals(getRegion().getWorld())) {
getRegion().message(player, "teleport-wrongWorld", player.getWorld().getName());
return false;
}
boolean owner = player.getUniqueId().equals(getRegion().getOwner());
boolean friend = getRegion().getFriendsFeature().getFriends().contains(player.getUniqueId());
boolean available = getRegion().isAvailable();
// Teleport to sign instead if they dont have permission for teleporting to region
if((!toSign && owner && !player.hasPermission("areashop.teleport") && player.hasPermission("areashop.teleportsign")
|| !toSign && !owner && !friend && !player.hasPermission("areashop.teleportall") && player.hasPermission("areashop.teleportsignall")
|| !toSign && !owner && friend && !player.hasPermission("areashop.teleportfriend") && player.hasPermission("areashop.teleportfriendsign")
|| !toSign && !owner && !friend && available && !player.hasPermission("areashop.teleportavailable") && player.hasPermission("areashop.teleportavailablesign"))) {
getRegion().message(player, "teleport-changedToSign");
toSign = true;
}
// Check permissions
if(owner && !available && !player.hasPermission("areashop.teleport") && !toSign) {
getRegion().message(player, "teleport-noPermission");
return false;
} else if(!owner && !available && !player.hasPermission("areashop.teleportall") && !toSign && !friend) {
getRegion().message(player, "teleport-noPermissionOther");
return false;
} else if(!owner && !available && !player.hasPermission("areashop.teleportfriend") && !toSign && friend) {
getRegion().message(player, "teleport-noPermissionFriend");
return false;
} else if(available && !player.hasPermission("areashop.teleportavailable") && !toSign) {
getRegion().message(player, "teleport-noPermissionAvailable");
return false;
} else if(owner && !available && !player.hasPermission("areashop.teleportsign") && toSign) {
getRegion().message(player, "teleport-noPermissionSign");
return false;
} else if(!owner && !available && !player.hasPermission("areashop.teleportsignall") && toSign && !friend) {
getRegion().message(player, "teleport-noPermissionOtherSign");
return false;
} else if(!owner && !available && !player.hasPermission("areashop.teleportfriendsign") && toSign && friend) {
getRegion().message(player, "teleport-noPermissionFriendSign");
return false;
} else if(available && !player.hasPermission("areashop.teleportavailablesign") && toSign) {
getRegion().message(player, "teleport-noPermissionAvailableSign");
return false;
}
}
// Get the starting location
Value<Boolean> toSignRef = new Value<>(toSign);
Location startLocation = getStartLocation(player, toSignRef);
toSign = toSignRef.get();
boolean insideRegion;
if(toSign) {
insideRegion = getRegion().getBooleanSetting("general.teleportToSignIntoRegion");
} else {
insideRegion = getRegion().getBooleanSetting("general.teleportIntoRegion");
}
// Check locations starting from startLocation and then a cube that increases
// radius around that (until no block in the region is found at all cube sides)
Location safeLocation = startLocation;
ProtectedRegion worldguardRegion = getRegion().getRegion();
boolean blocksInRegion = worldguardRegion.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ());
if(!blocksInRegion && insideRegion) {
getRegion().message(player, "teleport-blocked");
return false;
}
// Tries limit tracking
int radius = 1;
int checked = 1;
int maxTries = plugin.getConfig().getInt("maximumTries");
// Tracking of which sides to continue the search
boolean done = isSafe(safeLocation) && (blocksInRegion || !insideRegion);
boolean northDone = false, eastDone = false, southDone = false, westDone = false, topDone = false, bottomDone = false;
boolean continueThisDirection;
while((blocksInRegion || !insideRegion) && !done) {
blocksInRegion = false;
// North side
continueThisDirection = false;
for(int x = -radius + 1; x <= radius && !done && !northDone; x++) {
for(int y = -radius + 1; y < radius && !done; y++) {
safeLocation = startLocation.clone().add(x, y, -radius);
if(safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
continue;
}
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
}
northDone = northDone || !continueThisDirection;
// East side
continueThisDirection = false;
for(int z = -radius + 1; z <= radius && !done && !eastDone; z++) {
for(int y = -radius + 1; y < radius && !done; y++) {
safeLocation = startLocation.clone().add(radius, y, z);
if(safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
continue;
}
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
}
eastDone = eastDone || !continueThisDirection;
// South side
continueThisDirection = false;
for(int x = radius - 1; x >= -radius && !done && !southDone; x--) {
for(int y = -radius + 1; y < radius && !done; y++) {
safeLocation = startLocation.clone().add(x, y, radius);
if(safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
continue;
}
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
}
southDone = southDone || !continueThisDirection;
// West side
continueThisDirection = false;
for(int z = radius - 1; z >= -radius && !done && !westDone; z--) {
for(int y = -radius + 1; y < radius && !done; y++) {
safeLocation = startLocation.clone().add(-radius, y, z);
if(safeLocation.getBlockY() > 256 || safeLocation.getBlockY() < 0) {
continue;
}
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
}
westDone = westDone || !continueThisDirection;
// Top side
continueThisDirection = false;
// Middle block of the top
if((startLocation.getBlockY() + radius) > 256) {
topDone = true;
}
if(!done && !topDone) {
safeLocation = startLocation.clone().add(0, radius, 0);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
for(int r = 1; r <= radius && !done && !topDone; r++) {
// North
for(int x = -r + 1; x <= r && !done; x++) {
safeLocation = startLocation.clone().add(x, radius, -r);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
// East
for(int z = -r + 1; z <= r && !done; z++) {
safeLocation = startLocation.clone().add(r, radius, z);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
// South side
for(int x = r - 1; x >= -r && !done; x--) {
safeLocation = startLocation.clone().add(x, radius, r);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
// West side
for(int z = r - 1; z >= -r && !done; z--) {
safeLocation = startLocation.clone().add(-r, radius, z);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
}
topDone = topDone || !continueThisDirection;
// Bottom side
continueThisDirection = false;
// Middle block of the bottom
if(startLocation.getBlockY() - radius < 0) {
bottomDone = true;
}
if(!done && !bottomDone) {
safeLocation = startLocation.clone().add(0, -radius, 0);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
for(int r = 1; r <= radius && !done && !bottomDone; r++) {
// North
for(int x = -r + 1; x <= r && !done; x++) {
safeLocation = startLocation.clone().add(x, -radius, -r);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
// East
for(int z = -r + 1; z <= r && !done; z++) {
safeLocation = startLocation.clone().add(r, -radius, z);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
// South side
for(int x = r - 1; x >= -r && !done; x--) {
safeLocation = startLocation.clone().add(x, -radius, r);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
// West side
for(int z = r - 1; z >= -r && !done; z--) {
safeLocation = startLocation.clone().add(-r, -radius, z);
if(worldguardRegion.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ()) || !insideRegion) {
checked++;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
continueThisDirection = true;
}
}
}
bottomDone = bottomDone || !continueThisDirection;
// Increase cube radius
radius++;
}
if(done && isSafe(safeLocation)) {
if(toSign) {
getRegion().message(player, "teleport-successSign");
// Let the player look at the sign
Vector playerVector = safeLocation.toVector();
playerVector.setY(playerVector.getY() + player.getEyeHeight(true));
Vector signVector = getRegion().getSignsFeature().getSigns().get(0).getLocation().toVector().add(new Vector(0.5, 0.5, 0.5));
Vector direction = playerVector.clone().subtract(signVector).normalize();
safeLocation.setYaw(180 - (float)Math.toDegrees(Math.atan2(direction.getX(), direction.getZ())));
safeLocation.setPitch(90 - (float)Math.toDegrees(Math.acos(direction.getY())));
} else {
getRegion().message(player, "teleport-success");
}
player.teleport(safeLocation);
AreaShop.debug("Found location: " + safeLocation.toString() + " Tries: " + (checked - 1));
return true;
} else {
getRegion().message(player, "teleport-noSafe", checked - 1, maxTries);
AreaShop.debug("No location found, checked " + (checked - 1) + " spots of max " + maxTries);
return false;
}
}
/**
* Teleport a player to the region or sign when he has permissions for it.
* @param player Player that should be teleported
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
* @return true if the teleport succeeded, otherwise false
*/
public boolean teleportPlayer(Player player, boolean toSign) {
return teleportPlayer(player, toSign, true);
}
/**
* Teleport a player to the region when he has permissions for it.
* @param player Player that should be teleported
* @return true if the teleport succeeded, otherwise false
*/
public boolean teleportPlayer(Player player) {
return teleportPlayer(player, false, true);
}
/**
* Checks if a certain location is safe to teleport to.
* @param location The location to check
* @return true if it is safe, otherwise false
*/
private boolean isSafe(Location location) {
Block feet = location.getBlock();
Block head = feet.getRelative(BlockFace.UP);
Block below = feet.getRelative(BlockFace.DOWN);
Block above = head.getRelative(BlockFace.UP);
// Check the block at the feet and head of the player
if((feet.getType().isSolid() && !canSpawnIn.contains(feet.getType())) || feet.isLiquid()) {
return false;
} else if((head.getType().isSolid() && !canSpawnIn.contains(head.getType())) || head.isLiquid()) {
return false;
} else if(!below.getType().isSolid() || cannotSpawnOn.contains(below.getType()) || below.isLiquid()) {
return false;
} else if(above.isLiquid() || cannotSpawnBeside.contains(above.getType())) {
return false;
}
// Get all blocks around the player (below foot level, foot level, head level and above head level)
Set<Material> around = new HashSet<>();
for(int y = 0; y <= 3; y++) {
for(int x = -1; x <= 1; x++) {
for(int z = -1; z <= 1; z++) {
// Skip blocks in the column of the player
if(x == 0 && z == 0) {
continue;
}
around.add(below.getRelative(x, y, z).getType());
}
}
}
// Check the blocks around the player
for(Material material : around) {
if(cannotSpawnBeside.contains(material)) {
return false;
}
}
return true;
}
/**
* Get the start location of a safe teleport search.
* @param player The player to get it for
* @param toSign true to try teleporting to the first sign, false for teleporting to the region
* @return The start location
*/
private Location getStartLocation(Player player, Value<Boolean> toSign) {
Location startLocation = null;
ProtectedRegion worldguardRegion = getRegion().getRegion();
// Try to get sign location
List<RegionSign> signs = getRegion().getSignsFeature().getSigns();
boolean signAvailable = !signs.isEmpty();
if(toSign.get()) {
if(signAvailable) {
// Use the location 1 below the sign to prevent weird spawing above the sign
startLocation = signs.get(0).getLocation(); //.subtract(0.0, 1.0, 0.0);
startLocation.setPitch(player.getLocation().getPitch());
startLocation.setYaw(player.getLocation().getYaw());
// Move player x blocks away from the sign
double distance = getRegion().getDoubleSetting("general.teleportSignDistance");
if(distance > 0) {
BlockFace facing = getRegion().getSignsFeature().getSigns().get(0).getFacing();
Vector facingVector = new Vector(facing.getModX(), facing.getModY(), facing.getModZ())
.normalize()
.multiply(distance);
startLocation.setX(startLocation.getBlockX() + 0.5);
startLocation.setZ(startLocation.getBlockZ() + 0.5);
startLocation.add(facingVector);
}
} else {
// No sign available
getRegion().message(player, "teleport-changedToNoSign");
toSign.set(false);
}
}
// Use teleportation location that is set for the region
if(startLocation == null && hasTeleportLocation()) {
startLocation = getTeleportLocation();
}
// Calculate a default location
if(startLocation == null) {
// Set to block in the middle, y configured in the config
com.sk89q.worldedit.Vector middle = com.sk89q.worldedit.Vector.getMidpoint(worldguardRegion.getMaximumPoint(), worldguardRegion.getMinimumPoint());
String configSetting = getRegion().getStringSetting("general.teleportLocationY");
if("bottom".equalsIgnoreCase(configSetting)) {
middle = middle.setY(worldguardRegion.getMinimumPoint().getBlockY());
} else if("top".equalsIgnoreCase(configSetting)) {
middle = middle.setY(worldguardRegion.getMaximumPoint().getBlockY());
} else if("middle".equalsIgnoreCase(configSetting)) {
middle = middle.setY(middle.getBlockY());
} else {
try {
int vertical = Integer.parseInt(configSetting);
middle = middle.setY(vertical);
} catch(NumberFormatException e) {
AreaShop.warn("Could not parse general.teleportLocationY: '" + configSetting + "'");
}
}
startLocation = new Location(getRegion().getWorld(), middle.getX(), middle.getY(), middle.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch());
}
// Set location in the center of the block
startLocation.setX(startLocation.getBlockX() + 0.5);
startLocation.setZ(startLocation.getBlockZ() + 0.5);
return startLocation;
}
}
@@ -42,7 +42,7 @@ public class WorldGuardRegionFlagsFeature extends RegionFeature {
// Region flags for all states
ConfigurationSection allFlags = flagProfileSection.getConfigurationSection("ALL");
if(allFlags != null) {
result = result && updateRegionFlags(region, allFlags);
result = updateRegionFlags(region, allFlags);
}
// Region flags for the current state
@@ -52,9 +52,8 @@ public class WorldGuardRegionFlagsFeature extends RegionFeature {
if(stateFlags == null && region.getState() == GeneralRegion.RegionState.RESELL) {
stateFlags = flagProfileSection.getConfigurationSection("resale");
}
if(stateFlags != null) {
result = result && updateRegionFlags(region, stateFlags);
result &= updateRegionFlags(region, stateFlags);
}
return result;
@@ -1,16 +1,24 @@
package me.wiefferink.areashop.features.signs;
import com.google.common.base.Objects;
import io.papermc.lib.PaperLib;
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.managers.SignErrorLogger;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.interactivemessenger.processing.Message;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@@ -23,230 +31,267 @@ import java.util.List;
*/
public class RegionSign {
private final SignsFeature signsFeature;
private final String key;
private final SignsFeature signsFeature;
private final String key;
public RegionSign(SignsFeature signsFeature, String key) {
this.signsFeature = signsFeature;
this.key = key;
}
public RegionSign(SignsFeature signsFeature, String key) {
this.signsFeature = signsFeature;
this.key = key;
}
/**
* Get the location of this sign.
* @return The location of this sign
*/
public Location getLocation() {
return Utils.configToLocation(getRegion().getConfig().getConfigurationSection("general.signs." + key + ".location"));
}
/**
* Get the location of this sign.
*
* @return The location of this sign
*/
public Location getLocation() {
return Utils.configToLocation(getRegion().getConfig().getConfigurationSection("general.signs." + key + ".location"));
}
/**
* Location string to be used as key in maps.
* @return Location string
*/
public String getStringLocation() {
return SignsFeature.locationToString(getLocation());
}
/**
* Location string to be used as key in maps.
*
* @return Location string
*/
public String getStringLocation() {
return SignsFeature.locationToString(getLocation());
}
/**
* Chunk string to be used as key in maps.
* @return Chunk string
*/
public String getStringChunk() {
return SignsFeature.chunkToString(getLocation());
}
/**
* Chunk string to be used as key in maps.
*
* @return Chunk string
*/
public String getStringChunk() {
return SignsFeature.chunkToString(getLocation());
}
/**
* Get the region this sign is linked to.
* @return The region this sign is linked to
*/
public GeneralRegion getRegion() {
return signsFeature.getRegion();
}
/**
* Get the region this sign is linked to.
*
* @return The region this sign is linked to
*/
public GeneralRegion getRegion() {
return signsFeature.getRegion();
}
/**
* Remove this sign from the region.
*/
public void remove() {
getLocation().getBlock().setType(Material.AIR);
signsFeature.getSignsRef().remove(getStringLocation());
SignsFeature.getAllSigns().remove(getStringLocation());
SignsFeature.getSignsByChunk().get(getStringChunk()).remove(this);
getRegion().setSetting("general.signs." + key, null);
}
/**
* Remove this sign from the region.
*/
public void remove() {
getLocation().getBlock().setType(Material.AIR);
signsFeature.getSignsRef().remove(getStringLocation());
SignsFeature.getAllSigns().remove(getStringLocation());
SignsFeature.getSignsByChunk().get(getStringChunk()).remove(this);
getRegion().setSetting("general.signs." + key, null);
}
/**
* Get the ConfigurationSection defining the sign layout.
* @return The sign layout config
*/
public ConfigurationSection getProfile() {
return getRegion().getConfigurationSectionSetting("general.signProfile", "signProfiles", getRegion().getConfig().get("general.signs." + key + ".profile"));
}
/**
* Get the ConfigurationSection defining the sign layout.
*
* @return The sign layout config
*/
public ConfigurationSection getProfile() {
return getRegion().getConfigurationSectionSetting("general.signProfile", "signProfiles", getRegion().getConfig().get("general.signs." + key + ".profile"));
}
/**
* Get the facing of the sign.
* @return BlockFace the sign faces, or null if unknown
*/
public BlockFace getFacing() {
try {
return BlockFace.valueOf(getRegion().getConfig().getString("general.signs." + key + ".facing"));
} catch(NullPointerException | IllegalArgumentException e) {
return null;
}
}
/**
* Get the facing of the sign as saved in the config.
*
* @return BlockFace the sign faces, or null if unknown
*/
public BlockFace getFacing() {
try {
return BlockFace.valueOf(getRegion().getConfig().getString("general.signs." + key + ".facing"));
} catch (NullPointerException | IllegalArgumentException e) {
return null;
}
}
/**
* Get the material of the sign
* @return Material of the sign, normally {@link Material#WALL_SIGN} or {@link Material#SIGN_POST}, but could be something else or null.
*/
public Material getMaterial() {
try {
return Material.valueOf(getRegion().getConfig().getString("general.signs." + key + ".signType"));
} catch(NullPointerException | IllegalArgumentException e) {
return null;
}
}
/**
* Get the material of the sign as saved in the config.
*
* @return Material of the sign, usually or one of the other wood types (different result for 1.13-), Material.AIR if none.
*/
public Material getMaterial() {
String name = getRegion().getConfig().getString("general.signs." + key + ".signType");
Material result = Materials.signNameToMaterial(name);
return result == null ? Material.AIR : result;
}
/**
* Update this sign.
* @return true if the update was successful, otherwise false
*/
public boolean update() {
// Ignore updates of signs in chunks that are not loaded
Location signLocation = getLocation();
if(signLocation == null
|| signLocation.getWorld() == null
|| !signLocation.getWorld().isChunkLoaded(signLocation.getBlockX() >> 4, signLocation.getBlockZ() >> 4)) {
return false;
}
/**
* Update this sign.
*
* @return true if the update was successful, otherwise false
*/
public boolean update() {
if(getRegion().isDeleted()) {
return false;
}
// Ignore updates of signs in chunks that are not loaded
Location signLocation = getLocation();
if (signLocation == null
|| signLocation.getWorld() == null
|| !signLocation.getWorld().isChunkLoaded(signLocation.getBlockX() >> 4, signLocation.getBlockZ() >> 4)) {
return false;
}
YamlConfiguration regionConfig = getRegion().getConfig();
ConfigurationSection signConfig = getProfile();
Block block = signLocation.getBlock();
if(signConfig == null || !signConfig.isSet(getRegion().getState().getValue())) {
block.setType(Material.AIR);
return true;
}
final GeneralRegion region = getRegion();
ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue());
if (region.isDeleted()) {
return false;
}
// Get the lines
String[] signLines = new String[4];
boolean signEmpty = true;
for(int i = 0; i < 4; i++) {
signLines[i] = stateConfig.getString("line" + (i + 1));
signEmpty &= (signLines[i] == null || signLines[i].isEmpty());
}
if(signEmpty) {
block.setType(Material.AIR);
return true;
}
YamlConfiguration regionConfig = region.getConfig();
ConfigurationSection signConfig = getProfile();
Block block = signLocation.getBlock();
final String value = region.getState().getValue();
if (signConfig == null || !signConfig.isSet(value)) {
block.setType(Material.AIR);
return true;
}
Sign signState = null;
// Place the sign back (with proper rotation and type) after it has been hidden or (indirectly) destroyed
if(block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST) {
Material signType = getMaterial();
if(signType != Material.WALL_SIGN && signType != Material.SIGN_POST) {
AreaShop.debug("Setting sign", key, "of region", getRegion().getName(), "failed, could not set sign block back");
return false;
}
block.setType(signType);
signState = (Sign)block.getState();
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)signState.getData();
BlockFace signFace = getFacing();
if(signFace != null) {
signData.setFacingDirection(signFace);
signState.setData(signData);
}
}
if(signState == null) {
signState = (Sign)block.getState();
}
ConfigurationSection stateConfig = signConfig.getConfigurationSection(value);
// Save current rotation and type
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)signState.getData();
if(!regionConfig.isString("general.signs." + key + ".signType")) {
getRegion().setSetting("general.signs." + key + ".signType", signState.getType().toString());
}
if(!regionConfig.isString("general.signs." + key + ".facing")) {
getRegion().setSetting("general.signs." + key + ".facing", signData.getFacing().toString());
}
// Get the lines
String[] signLines = new String[4];
boolean signEmpty = true;
for (int i = 0; i < 4; i++) {
signLines[i] = stateConfig.getString("line" + (i + 1));
signEmpty &= (signLines[i] == null || signLines[i].isEmpty());
}
if (signEmpty) {
block.setType(Material.AIR);
return true;
}
// Apply replacements and color and then set it on the sign
for(int i = 0; i < signLines.length; i++) {
if(signLines[i] == null) {
signState.setLine(i, "");
continue;
}
signLines[i] = Message.fromString(signLines[i]).replacements(getRegion()).getSingle();
signLines[i] = Utils.applyColors(signLines[i]);
signState.setLine(i, signLines[i]);
}
signState.update();
return true;
}
final BlockStateSnapshotResult snapshot = PaperLib.getBlockState(block, false);
final BlockState blockState = snapshot.getState();
final BlockData blockData = blockState.getBlockData();
final SignErrorLogger errorLogger = AreaShop.getInstance().getSignErrorLogger();
Material signType = getMaterial();
// Place the sign back (with proper rotation and type) after it has been hidden or (indirectly) destroyed
if (!Tag.SIGNS.isTagged(blockState.getType())) {
// Don't do physics here, we first need to update the direction
blockState.setType(signType);
if (blockData instanceof WallSign) {
((WallSign) blockData).setFacing(getFacing());
} else if (blockData instanceof Sign) {
((org.bukkit.block.data.type.Sign) blockData).setRotation(getFacing());
}
blockState.setBlockData(blockData);
blockState.update(false, true);
// Check if the sign has popped
if (!Materials.isSign(block.getType())) {
final String message = String.format("Setting sign of $1%s of region $2%s failed, could not set sign block back", key, region.getName());
errorLogger.submitWarning(message);
return false;
}
} else {
final String message = "Setting sign $1%s of region $2%s failed, RegionSign material was: $3%s";
errorLogger.submitWarning(String.format(message, key, region.getName(), signType.name()));
}
/**
* Check if the sign needs to update periodically.
* @return true if it needs periodic updates, otherwise false
*/
public boolean needsPeriodicUpdate() {
ConfigurationSection signConfig = getProfile();
if(signConfig == null || !signConfig.isSet(getRegion().getState().getValue().toLowerCase())) {
return false;
}
ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue().toLowerCase());
// Check the lines for the timeleft tag
for(int i = 1; i <= 4; i++) {
String line = stateConfig.getString("line" + i);
if(line != null && !line.isEmpty() && line.contains(Message.VARIABLE_START + AreaShop.tagTimeLeft + Message.VARIABLE_END)) {
return true;
}
}
return false;
}
// Save current rotation and type
if (!regionConfig.isString("general.signs." + key + ".signType")) {
region.setSetting("general.signs." + key + ".signType", blockState.getType().name());
}
if (!regionConfig.isString("general.signs." + key + ".facing")) {
final BlockFace rotation;
if (Materials.isSign(block.getType())) {
if (blockData instanceof org.bukkit.block.data.type.Sign) {
rotation = ((org.bukkit.block.data.type.Sign) blockData).getRotation();
} else if (blockData instanceof WallSign) {
rotation = ((WallSign) blockData).getFacing();
} else {
rotation = null;
}
} else {
rotation = null;
}
region.setSetting("general.signs." + key + ".facing", rotation == null ? null : rotation.toString());
}
/**
* Run commands when a player clicks a sign.
* @param clicker The player that clicked the sign
* @param clickType The type of clicking
* @return true if the commands ran successfully, false if any of them failed
*/
public boolean runSignCommands(Player clicker, GeneralRegion.ClickType clickType) {
ConfigurationSection signConfig = getProfile();
if(signConfig == null) {
return false;
}
ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue().toLowerCase());
// Apply replacements and color and then set it on the sign
Sign signState = (Sign) blockState;
for (int i = 0; i < signLines.length; i++) {
if (signLines[i] == null) {
signState.setLine(i, "");
continue;
}
signLines[i] = Message.fromString(signLines[i]).replacements(getRegion()).getSingle();
signLines[i] = Utils.applyColors(signLines[i]);
signState.setLine(i, signLines[i]);
}
// BlockState#update *should* return true here.
blockState.update(false, false);
return true;
}
// Run player commands if specified
List<String> playerCommands = new ArrayList<>();
for(String command : stateConfig.getStringList(clickType.getValue() + "Player")) {
// TODO move variable checking code to InteractiveMessenger?
playerCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
}
getRegion().runCommands(clicker, playerCommands);
/**
* Check if the sign needs to update periodically.
*
* @return true if it needs periodic updates, otherwise false
*/
public boolean needsPeriodicUpdate() {
ConfigurationSection signConfig = getProfile();
if (signConfig == null || !signConfig.isSet(getRegion().getState().getValue().toLowerCase())) {
return false;
}
// Run console commands if specified
List<String> consoleCommands = new ArrayList<>();
for(String command : stateConfig.getStringList(clickType.getValue() + "Console")) {
consoleCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
}
getRegion().runCommands(Bukkit.getConsoleSender(), consoleCommands);
ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue().toLowerCase());
if (stateConfig == null) {
return false;
}
return !playerCommands.isEmpty() || !consoleCommands.isEmpty();
}
// Check the lines for the timeleft tag
for (int i = 1; i <= 4; i++) {
String line = stateConfig.getString("line" + i);
if (line != null && !line.isEmpty() && line.contains(Message.VARIABLE_START + AreaShop.tagTimeLeft + Message.VARIABLE_END)) {
return true;
}
}
return false;
}
@Override
public boolean equals(Object object) {
return object instanceof RegionSign && ((RegionSign)object).getRegion().equals(this.getRegion()) && ((RegionSign)object).key.equals(this.key);
}
/**
* Run commands when a player clicks a sign.
*
* @param clicker The player that clicked the sign
* @param clickType The type of clicking
* @return true if the commands ran successfully, false if any of them failed
*/
public boolean runSignCommands(Player clicker, GeneralRegion.ClickType clickType) {
ConfigurationSection signConfig = getProfile();
if (signConfig == null) {
return false;
}
final GeneralRegion region = getRegion();
ConfigurationSection stateConfig = signConfig.getConfigurationSection(region.getState().getValue().toLowerCase());
@Override
public int hashCode() {
return Objects.hashCode(key, getRegion().getName());
}
// Run player commands if specified
List<String> playerCommands = new ArrayList<>();
for (String command : stateConfig.getStringList(clickType.getValue() + "Player")) {
// TODO move variable checking code to InteractiveMessenger?
playerCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
}
region.runCommands(clicker, playerCommands);
// Run console commands if specified
List<String> consoleCommands = new ArrayList<>();
for (String command : stateConfig.getStringList(clickType.getValue() + "Console")) {
consoleCommands.add(command.replace(Message.VARIABLE_START + AreaShop.tagClicker + Message.VARIABLE_END, clicker.getName()));
}
region.runCommands(Bukkit.getConsoleSender(), consoleCommands);
return !playerCommands.isEmpty() || !consoleCommands.isEmpty();
}
@Override
public boolean equals(Object object) {
return object instanceof RegionSign && ((RegionSign) object).getRegion().equals(this.getRegion()) && ((RegionSign) object).key.equals(this.key);
}
@Override
public int hashCode() {
return Objects.hashCode(key, getRegion().getName());
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,269 @@
package me.wiefferink.areashop.features.teleport;
import co.aikar.taskchain.TaskChain;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import io.papermc.lib.PaperLib;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.features.RegionFeature;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.areashop.tools.Value;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
public class TeleportFeature extends RegionFeature {
public TeleportFeature() {
}
public TeleportFeature(GeneralRegion region) {
setRegion(region);
}
/**
* Checks if a certain location is safe to teleport to.
*
* @param location The location to check
* @return true if it is safe, otherwise false
*/
static boolean isSafe(Location location) {
Block feet = location.getBlock();
Block head = feet.getRelative(BlockFace.UP);
Block below = feet.getRelative(BlockFace.DOWN);
Block above = head.getRelative(BlockFace.UP);
// Check the block at the feet and head of the player
if ((feet.getType().isSolid() && !canSpawnIn(feet.getType())) || feet.isLiquid()) {
return false;
} else if ((head.getType().isSolid() && !canSpawnIn(head.getType())) || head.isLiquid()) {
return false;
} else if (!below.getType().isSolid() || cannotSpawnOn(below.getType()) || below.isLiquid()) {
return false;
} else if (above.isLiquid() || cannotSpawnBeside(above.getType())) {
return false;
}
// Get all blocks around the player (below foot level, foot level, head level and above head level)
Set<Material> around = new HashSet<>();
for (int y = 0; y <= 3; y++) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
// Skip blocks in the column of the player
if (x == 0 && z == 0) {
continue;
}
around.add(below.getRelative(x, y, z).getType());
}
}
}
// Check the blocks around the player
for (Material material : around) {
if (cannotSpawnBeside(material)) {
return false;
}
}
return true;
}
/**
* Check if a player can spawn in here.
*
* @param material Material to check (assumed that this is at the feet or head level)
* @return true when it is safe to spawn inside, otherwise false
*/
private static boolean canSpawnIn(Material material) {
String name = material.name();
return name.contains("DOOR")
|| name.contains("SIGN")
|| name.contains("PLATE") // Redstone plates
|| name.equals("DRAGON_EGG");
}
/**
* Check if a player can spawn on here.
*
* @param material Material to check (assumed that this is below the feet)
* @return true when it is safe to spawn on top of, otherwise false
*/
private static boolean cannotSpawnOn(Material material) {
String name = material.name();
return name.equals("CACTUS")
|| name.contains("PISTON")
|| name.contains("SIGN")
|| name.contains("DOOR")
|| name.contains("PLATE")
|| name.contains("REDSTONE_LAMP")
|| name.contains("FENCE")
|| name.contains("GLASS_PANE") || name.contains("THIN_GLASS")
|| name.equals("DRAGON_EGG")
|| name.contains("MAGMA");
}
/**
* Check if a player can spawn next to it.
*
* @param material Material to check (assumed that this is somewhere around the player)
* @return true when it is safe to spawn next to, otherwise false
*/
private static boolean cannotSpawnBeside(Material material) {
String name = material.name();
return name.contains("LAVA")
|| name.contains("CACTUS")
|| name.equals("FIRE")
|| name.contains("MAGMA");
}
/**
* Get the teleportlocation set for this region.
*
* @return The teleport location, or null if not set
*/
public Location getTeleportLocation() {
return Utils.configToLocation(getRegion().getConfigurationSectionSetting("general.teleportLocation"));
}
/**
* Check if the region has a teleportLocation specified.
*
* @return true if the region has a teleportlocation, false otherwise
*/
public boolean hasTeleportLocation() {
return getRegion().getConfigurationSectionSetting("general.teleportLocation") != null;
}
/**
* Set the teleport location of this region.
*
* @param location The location to set as teleport location
*/
public void setTeleport(Location location) {
if (location == null) {
getRegion().setSetting("general.teleportLocation", null);
} else {
getRegion().setSetting("general.teleportLocation", Utils.locationToConfig(location, true));
}
}
/**
* Teleport a player to the region or sign.
*
* @param player Player that should be teleported
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
* @param checkRestrictions Set to true if teleport permissions should be checked, false otherwise, also toggles cross-world check
* @return true if the teleport succeeded, otherwise false
*/
public CompletableFuture<Boolean> teleportPlayer(Player player, boolean toSign, boolean checkRestrictions) {
return new TeleportJob(this, plugin).executeTeleport(player, toSign, checkRestrictions);
}
/**
* Teleport a player to the region or sign when he has permissions for it.
*
* @param player Player that should be teleported
* @param toSign true to teleport to the first sign of the region, false for teleporting to the region itself
* @return true if the teleport succeeded, otherwise false
*/
public CompletableFuture<Boolean> teleportPlayer(Player player, boolean toSign) {
return teleportPlayer(player, toSign, true);
}
/**
* Teleport a player to the region when he has permissions for it.
*
* @param player Player that should be teleported
* @return true if the teleport succeeded, otherwise false
*/
public CompletableFuture<Boolean> teleportPlayer(Player player) {
return teleportPlayer(player, false, true);
}
/**
* Get the start location of a safe teleport search.
*
* @param player The player to get it for
* @param toSign true to try teleporting to the first sign, false for teleporting to the region
* @return The start location
*/
Location getStartLocation(Player player, Value<Boolean> toSign) {
Location startLocation = null;
ProtectedRegion worldguardRegion = getRegion().getRegion();
// Try to get sign location
List<RegionSign> signs = getRegion().getSignsFeature().getSigns();
boolean signAvailable = !signs.isEmpty();
if (toSign.get()) {
if (signAvailable) {
// Use the location 1 below the sign to prevent weird spawing above the sign
startLocation = signs.get(0).getLocation(); //.subtract(0.0, 1.0, 0.0);
startLocation.setPitch(player.getLocation().getPitch());
startLocation.setYaw(player.getLocation().getYaw());
// Move player x blocks away from the sign
double distance = getRegion().getDoubleSetting("general.teleportSignDistance");
if (distance > 0) {
BlockFace facing = getRegion().getSignsFeature().getSigns().get(0).getFacing();
Vector facingVector = new Vector(facing.getModX(), facing.getModY(), facing.getModZ())
.normalize()
.multiply(distance);
startLocation.setX(startLocation.getBlockX() + 0.5);
startLocation.setZ(startLocation.getBlockZ() + 0.5);
startLocation.add(facingVector);
}
} else {
// No sign available
getRegion().message(player, "teleport-changedToNoSign");
toSign.set(false);
}
}
// Use teleportation location that is set for the region
if (startLocation == null && hasTeleportLocation()) {
startLocation = getTeleportLocation();
}
// Calculate a default location
if (startLocation == null) {
// Set to block in the middle, y configured in the config
Vector regionMin = AreaShop.getInstance().getWorldGuardHandler().getMinimumPoint(worldguardRegion);
Vector regionMax = AreaShop.getInstance().getWorldGuardHandler().getMaximumPoint(worldguardRegion);
Vector middle = regionMin.clone().midpoint(regionMax);
String configSetting = getRegion().getStringSetting("general.teleportLocationY");
if ("bottom".equalsIgnoreCase(configSetting)) {
middle = middle.setY(regionMin.getBlockY());
} else if ("top".equalsIgnoreCase(configSetting)) {
middle = middle.setY(regionMax.getBlockY());
} else if ("middle".equalsIgnoreCase(configSetting)) {
middle = middle.setY(middle.getBlockY());
} else {
try {
int vertical = Integer.parseInt(configSetting);
middle = middle.setY(vertical);
} catch (NumberFormatException e) {
AreaShop.warn("Could not parse general.teleportLocationY: '" + configSetting + "'");
}
}
startLocation = new Location(getRegion().getWorld(), middle.getX(), middle.getY(), middle.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch());
}
// Set location in the center of the block
startLocation.setX(startLocation.getBlockX() + 0.5);
startLocation.setZ(startLocation.getBlockZ() + 0.5);
return startLocation;
}
}
@@ -0,0 +1,639 @@
package me.wiefferink.areashop.features.teleport;
import co.aikar.taskchain.TaskChain;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import io.papermc.lib.PaperLib;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.areashop.tools.Value;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
class TeleportJob {
private final AreaShop plugin;
private final GeneralRegion region;
private final TeleportFeature feature;
private BukkitTask notifierTask;
private boolean running;
private int checked;
private boolean done;
private boolean blocksInRegionCopy;
private boolean northDone = false, eastDone = false, southDone = false, westDone = false, topDone = false, bottomDone = false;
private boolean continueThisDirection;
private int radius = 1;
public TeleportJob(final TeleportFeature region, final AreaShop plugin) {
this.feature = region;
this.region = region.getRegion();
this.plugin = plugin;
}
private static Function<double[], Boolean> generateContainsFunction(final ProtectedRegion worldguardRegion) {
final BlockVector3 min = worldguardRegion.getMinimumPoint(), max = worldguardRegion.getMaximumPoint();
if (worldguardRegion instanceof GlobalProtectedRegion) {
return (unused) -> true;
} else if (worldguardRegion instanceof ProtectedCuboidRegion) {
return coords -> {
final double x = coords[0];
final double y = coords[1];
final double z = coords[2];
return x >= min.getBlockX() && x < max.getBlockX() + 1
&& y >= min.getBlockY() && y < max.getBlockY() + 1
&& z >= min.getBlockZ() && z < max.getBlockZ() + 1;
};
} else if (worldguardRegion instanceof ProtectedPolygonalRegion) {
final int minY = min.getY(), maxY = max.getY();
final List<BlockVector2> points = worldguardRegion.getPoints();
return coords -> {
int targetX = (int) Math.round(coords[0]); // Width
int targetY = (int) Math.round(coords[1]); // Height
int targetZ = (int) Math.round(coords[2]); // Depth
if (targetY < minY || targetY > maxY) {
return false;
}
//Quick and dirty check.
if (targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()) {
return false;
}
boolean inside = false;
int npoints = points.size();
int xNew, zNew;
int xOld, zOld;
int x1, z1;
int x2, z2;
long crossproduct;
int i;
xOld = points.get(npoints - 1).getBlockX();
zOld = points.get(npoints - 1).getBlockZ();
for (i = 0; i < npoints; i++) {
xNew = points.get(i).getBlockX();
zNew = points.get(i).getBlockZ();
//Check for corner
if (xNew == targetX && zNew == targetZ) {
return true;
}
if (xNew > xOld) {
x1 = xOld;
x2 = xNew;
z1 = zOld;
z2 = zNew;
} else {
x1 = xNew;
x2 = xOld;
z1 = zNew;
z2 = zOld;
}
if (x1 <= targetX && targetX <= x2) {
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
- ((long) z2 - (long) z1) * (long) (targetX - x1);
if (crossproduct == 0) {
if ((z1 <= targetZ) == (targetZ <= z2)) return true; // on edge
} else if (crossproduct < 0 && (x1 != targetX)) {
inside = !inside;
}
}
xOld = xNew;
zOld = zNew;
}
return inside;
};
} else {
throw new UnsupportedOperationException("Unknown region type: " + worldguardRegion.getClass().getCanonicalName());
}
}
public boolean isRunning() {
return running;
}
public CompletableFuture<Boolean> executeTeleport(final Player player, boolean toSign, boolean checkRestrictions) {
if (running) {
throw new IllegalStateException("Task is already running!");
}
running = true;
// Check basics
if (feature == null) {
region.message(player, "general-noRegion");
return CompletableFuture.completedFuture(false);
}
if (region.getWorld() == null) {
region.message(player, "general-noWorld");
return CompletableFuture.completedFuture(false);
}
if (checkRestrictions) {
// Check correct world
if (!region.getBooleanSetting("general.teleportCrossWorld") && !player.getWorld().equals(region.getWorld())) {
region.message(player, "teleport-wrongWorld", player.getWorld().getName());
return CompletableFuture.completedFuture(false);
}
boolean owner = player.getUniqueId().equals(region.getOwner());
boolean friend = region.getFriendsFeature().getFriends().contains(player.getUniqueId());
boolean available = region.isAvailable();
// Teleport to sign instead if they dont have permission for teleporting to region
if ((!toSign && owner && !player.hasPermission("areashop.teleport") && player.hasPermission("areashop.teleportsign")
|| !toSign && !owner && !friend && !player.hasPermission("areashop.teleportall") && player.hasPermission("areashop.teleportsignall")
|| !toSign && !owner && friend && !player.hasPermission("areashop.teleportfriend") && player.hasPermission("areashop.teleportfriendsign")
|| !toSign && !owner && !friend && available && !player.hasPermission("areashop.teleportavailable") && player.hasPermission("areashop.teleportavailablesign"))) {
region.message(player, "teleport-changedToSign");
toSign = true;
}
// Check permissions
if (owner && !available && !player.hasPermission("areashop.teleport") && !toSign) {
region.message(player, "teleport-noPermission");
return CompletableFuture.completedFuture(false);
} else if (!owner && !available && !player.hasPermission("areashop.teleportall") && !toSign && !friend) {
region.message(player, "teleport-noPermissionOther");
return CompletableFuture.completedFuture(false);
} else if (!owner && !available && !player.hasPermission("areashop.teleportfriend") && !toSign && friend) {
region.message(player, "teleport-noPermissionFriend");
return CompletableFuture.completedFuture(false);
} else if (available && !player.hasPermission("areashop.teleportavailable") && !toSign) {
region.message(player, "teleport-noPermissionAvailable");
return CompletableFuture.completedFuture(false);
} else if (owner && !available && !player.hasPermission("areashop.teleportsign") && toSign) {
region.message(player, "teleport-noPermissionSign");
return CompletableFuture.completedFuture(false);
} else if (!owner && !available && !player.hasPermission("areashop.teleportsignall") && toSign && !friend) {
region.message(player, "teleport-noPermissionOtherSign");
return CompletableFuture.completedFuture(false);
} else if (!owner && !available && !player.hasPermission("areashop.teleportfriendsign") && toSign && friend) {
region.message(player, "teleport-noPermissionFriendSign");
return CompletableFuture.completedFuture(false);
} else if (available && !player.hasPermission("areashop.teleportavailablesign") && toSign) {
region.message(player, "teleport-noPermissionAvailableSign");
return CompletableFuture.completedFuture(false);
}
}
// Get the starting location
Value<Boolean> toSignRef = new Value<>(toSign);
Location startLocation = feature.getStartLocation(player, toSignRef);
toSign = toSignRef.get();
boolean insideRegion;
if (toSign) {
insideRegion = region.getBooleanSetting("general.teleportToSignIntoRegion");
} else {
insideRegion = region.getBooleanSetting("general.teleportIntoRegion");
}
// Check locations starting from startLocation and then a cube that increases
// radius around that (until no block in the region is found at all cube sides)
ProtectedRegion worldguardRegion = region.getRegion();
final Function<double[], Boolean> regionContains = generateContainsFunction(worldguardRegion);
boolean blocksInRegion = worldguardRegion.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ());
if (!blocksInRegion && insideRegion) {
region.message(player, "teleport-blocked");
return CompletableFuture.completedFuture(false);
}
// Tracking of which sides to continue the search
final World world = region.getWorld();
BlockVector3 min = worldguardRegion.getMinimumPoint();
BlockVector3 max = worldguardRegion.getMaximumPoint();
final Collection<Chunk> collection = ConcurrentHashMap.newKeySet();
final List<CompletableFuture<Object>> futures = new ArrayList<>();
final Collection<int[]> coords = new HashSet<>();
for (int x = min.getX(); x < max.getX(); x += 16) {
for (int z = min.getZ(); z < max.getZ(); z += 16) {
coords.add(new int[]{x, z});
}
}
final CompletableFuture<?> schedulingFuture;
if (coords.size() < 128) {
schedulingFuture = Utils.runAsBatches(coords, 32,
coord -> futures.add(PaperLib.getChunkAtAsync(world, coord[0], coord[1]).thenApply(chunk -> {
chunk.setForceLoaded(true);
collection.add(chunk);
return chunk;
})), false);
} else {
schedulingFuture = null;
}
final CompletableFuture<Boolean> future = new CompletableFuture<>();
final boolean finalToSign = toSign;
final Runnable task = () -> {
blocksInRegionCopy = blocksInRegion;
int safeY = startLocation.getBlockY();
int safeX = startLocation.getBlockX();
int safeZ = startLocation.getBlockZ();
final Location temp = new Location(world, 0, 0, 0);
// Tries limit tracking
int maxTries = plugin.getConfig().getInt("maximumTries");
// Tracking of which sides to continue the search
try {
this.done = Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(startLocation)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
Utils.newChain().async(() -> {
while ((blocksInRegionCopy || !insideRegion) && !done) {
blocksInRegionCopy = false;
// North side
continueThisDirection = false;
temp.setX(-radius + 1);
temp.setY(-radius + 1);
temp.setZ(-radius);
for (int x = -radius + 1; x <= radius && !done && !northDone; x++) {
for (int y = -radius + 1; y < radius && !done; y++) {
if (y + safeY > 256 || y + safeY < 0) {
continue;
}
if (!insideRegion || regionContains.apply(new double[]{x + safeX, y + safeY, safeZ - radius})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 1, 0);
}
temp.add(1, 0, 0);
}
northDone = northDone || !continueThisDirection;
}
}).abortIf((var0) -> done).async(() -> {
// South side
continueThisDirection = false;
temp.setX(radius - 1);
temp.setY(-radius + 1);
temp.setZ(-radius);
for (int x = radius - 1; x >= -radius && !done && !southDone; x--) {
for (int y = -radius + 1; y < radius && !done; y++) {
if (y + safeY > 256 || y + safeY < 0) {
continue;
}
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY + y, safeZ - radius})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 1, 0);
}
temp.add(-1, 0, 0);
}
southDone = southDone || !continueThisDirection;
}).abortIf((var0) -> done).async(() -> {
// East side
continueThisDirection = false;
temp.setX(-radius + 1);
temp.setY(-radius + 1);
temp.setZ(0);
for (int z = -radius + 1; z <= radius && !done && !eastDone; z++) {
for (int y = -radius + 1; y < radius && !done; y++) {
if (y + safeY > 256 || y + safeY < 0) {
continue;
}
if (!insideRegion || regionContains.apply(new double[]{safeX + radius, y + safeY, z + safeZ})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 1, 0);
}
temp.add(0, 0, 1);
}
eastDone = eastDone || !continueThisDirection;
}).abortIf((var0) -> done).async(() -> {
// West side
continueThisDirection = false;
temp.setX(-radius);
temp.setY(-radius);
temp.setZ(radius - 1);
for (int z = radius - 1; z >= -radius && !done && !westDone; z--) {
for (int y = -radius + 1; y < radius && !done; y++) {
if (y + safeY > 256 || y + safeY < 0) {
continue;
}
if (!insideRegion || regionContains.apply(new double[]{safeX - radius, safeY + y, safeZ + z})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 1, 0);
}
temp.add(0, 0, -1);
}
westDone = westDone || !continueThisDirection;
}).abortIf((var0) -> done).async(() -> {
// Top side
continueThisDirection = false;
// Middle block of the top
if ((safeY + radius) > 256) {
topDone = true;
}
if (!done && !topDone) {
temp.setX(0);
temp.setY(radius);
temp.setZ(0);
if (!insideRegion || regionContains.apply(new double[]{safeX, safeY + radius, safeZ})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
}
temp.setY(radius);
for (int r = 1; r <= radius && !done && !topDone; r++) {
temp.setX(-r + 1);
temp.setZ(-r);
for (int x = -r + 1; x <= r && !done; x++) {
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY + radius, safeZ - r})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(1, 0, 0);
}
// East
temp.setX(r);
temp.setZ(-r + 1);
for (int z = -r + 1; z <= r && !done; z++) {
if (!insideRegion || regionContains.apply(new double[]{safeX + r, safeY + radius, safeZ + z})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 0, z);
}
// South side
temp.setX(r - 1);
temp.setZ(r);
for (int x = r - 1; x >= -r && !done; x--) {
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY + radius, safeZ + r})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(-1, 0, 0);
}
// West side
temp.setX(-r);
temp.setZ(r - 1);
for (int z = r - 1; z >= -r && !done; z--) {
if (!insideRegion || regionContains.apply(new double[]{safeX - r, safeY + radius, safeZ + z})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 0, -1);
}
}
topDone = topDone || !continueThisDirection;
}).abortIf(var0 -> done).async(() -> {
// Bottom side
continueThisDirection = false;
// Middle block of the bottom
if (safeY - radius < 0) {
bottomDone = true;
}
if (!done && !bottomDone) {
temp.setX(0);
temp.setY(-radius);
temp.setZ(0);
if (!insideRegion || regionContains.apply(new double[]{safeX, safeY - radius, safeZ})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
}
temp.setY(-radius);
for (int r = 1; r <= radius && !done && !bottomDone; r++) {
// North
temp.setX(-r + 1);
temp.setZ(-r);
for (int x = -r + 1; x <= r && !done; x++) {
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY - radius, safeZ - r})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(1, 0, 0);
}
// East
temp.setX(0);
temp.setZ(-r + 1);
for (int z = -r + 1; z <= r && !done; z++) {
if (!insideRegion || regionContains.apply(new double[]{safeX + r, safeY - radius, safeZ + z})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 0, 1);
}
// South side
temp.setX(r - 1);
temp.setZ(r);
for (int x = r - 1; x >= -r && !done; x--) {
if (!insideRegion || regionContains.apply(new double[]{safeX + x, safeY - radius, safeZ + r})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(-1, 0, 0);
}
// West side
temp.setX(-r);
temp.setZ(r - 1);
for (int z = r - 1; z >= -r && !done; z--) {
if (!insideRegion || regionContains.apply(new double[]{safeX - r, safeY - radius, safeZ + z})) {
checked++;
try {
this.done = checked > maxTries || Bukkit.getScheduler().callSyncMethod(plugin, () -> TeleportFeature.isSafe(temp)).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException ex) {
ex.printStackTrace();
this.done = false;
}
blocksInRegionCopy = true;
continueThisDirection = true;
}
temp.add(0, 0, -1);
}
}
bottomDone = bottomDone || !continueThisDirection;
// Increase cube radius
radius++;
startLocation.add(temp);
}).execute(() -> Bukkit.getScheduler().runTask(plugin, () -> {
if (done && TeleportFeature.isSafe(startLocation)) {
if (finalToSign) {
region.message(player, "teleport-successSign");
// Let the player look at the sign
Vector playerVector = startLocation.toVector();
playerVector.setY(playerVector.getY() + player.getEyeHeight(true));
Vector signVector = region.getSignsFeature().getSigns().get(0).getLocation().toVector().add(new Vector(0.5, 0.5, 0.5));
Vector direction = playerVector.clone().subtract(signVector).normalize();
startLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ())));
startLocation.setPitch(90 - (float) Math.toDegrees(Math.acos(direction.getY())));
} else {
region.message(player, "teleport-success");
}
AreaShop.debug("Found location: " + startLocation.toString() + " Tries: " + checked);
PaperLib.teleportAsync(player, startLocation).thenAccept(future::complete);
} else {
region.message(player, "teleport-noSafe", checked, maxTries);
AreaShop.debug("No location found, checked " + checked + " spots of max " + maxTries);
future.complete(false);
}
}));
};
// Start notifying the player, the one issue is that checked/max is 0 is if chunk loading takes up >= ~3s
doNotifications(player.getUniqueId());
TaskChain<?> chain = Utils.newChain();
if (schedulingFuture != null) {
// If there aren't too many chunks, pre-load them. Max will take 10 ticks ~ 500-600ms
chain = chain.asyncFirstFuture(() -> schedulingFuture).asyncFutures((unused) -> futures);
}
// Run the calculation task async
chain.async(task::run).execute();
// Don't keep chunks force-loaded once the teleportation has been completed.
return future.thenApply((unused0) -> {
for (Chunk chunk : collection) {
chunk.setForceLoaded(false); // Should be fine to call async(?)
}
running = false;
return unused0;
});
}
/**
* Get the task which notifies player of teleport progress.
*
* @return Returns the task, may be null.
*/
public BukkitTask getNotifierTask() {
return notifierTask;
}
private void doNotifications(final UUID player0) {
final int maxTries = plugin.getConfig().getInt("maximumTries");
this.notifierTask = new BukkitRunnable() {
@Override
public void run() {
final Player player = Bukkit.getPlayer(player0);
if (TeleportJob.this.done || player == null) {
this.cancel();
TeleportJob.this.notifierTask = null;
return;
}
region.message(player, "teleport-calculation-progress", "%done%", String.valueOf(checked), "%max%", String.valueOf(maxTries));
}
}.runTaskTimer(plugin, Utils.millisToTicks(3000), Utils.millisToTicks(3000));
}
}
@@ -1,769 +0,0 @@
/*
* Copyright 2011-2013 Tyler Blair. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and contributors and should not be interpreted as representing official policies,
* either expressed or implied, of anybody else.
*/
package me.wiefferink.areashop.lib;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
public class Metrics {
/**
* The current revision number.
*/
private static final int REVISION = 7;
/**
* The base url of the metrics domain.
*/
private static final String BASE_URL = "http://report.mcstats.org";
/**
* The url used to report a server's status.
*/
private static final String REPORT_URL = "/plugin/%s";
/**
* Interval of time to ping (in minutes).
*/
private static final int PING_INTERVAL = 15;
/**
* The plugin this metrics submits for.
*/
private final Plugin plugin;
/**
* All of the custom graphs to submit to metrics.
*/
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/**
* The plugin configuration file.
*/
private final YamlConfiguration configuration;
/**
* The plugin configuration file.
*/
private final File configurationFile;
/**
* Unique server id.
*/
private final String guid;
/**
* Debug mode.
*/
private final boolean debug;
/**
* Lock for synchronization.
*/
private final Object optOutLock = new Object();
/**
* The scheduled task.
*/
private volatile BukkitTask task = null;
/**
* Constructor.
* @param plugin The plugin to report stats for
* @throws IOException When the plugin or configuration is wrong
*/
public Metrics(final Plugin plugin) throws IOException {
if(plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
this.plugin = plugin;
// load the config
configurationFile = getConfigFile();
configuration = YamlConfiguration.loadConfiguration(configurationFile);
// add some defaults
configuration.addDefault("opt-out", false);
configuration.addDefault("guid", UUID.randomUUID().toString());
configuration.addDefault("debug", false);
// Do we need to create the file?
if(configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org").copyDefaults(true);
configuration.save(configurationFile);
}
// Load the guid then
guid = configuration.getString("guid");
debug = configuration.getBoolean("debug", false);
}
/**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* website. Plotters can be added to the graph object returned.
* @param name The name of the graph
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(final String name) {
if(name == null) {
throw new IllegalArgumentException("Graph name cannot be null");
}
// Construct the graph object
final Graph graph = new Graph(name);
// Now we can add our graph
graphs.add(graph);
// and return back
return graph;
}
/**
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend.
* @param graph The name of the graph
*/
public void addGraph(final Graph graph) {
if(graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
graphs.add(graph);
}
/**
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
* ticks.
* @return True if statistics measuring is running, otherwise false.
*/
public boolean start() {
synchronized(optOutLock) {
// Did we opt out?
if(isOptOut()) {
return false;
}
// Is metrics already running?
if(task != null) {
return true;
}
// Begin hitting the server with glorious data
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
private boolean firstPost = true;
public void run() {
try {
// This has to be synchronized or it can collide with the disable method.
synchronized(optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out
if(isOptOut() && task != null) {
task.cancel();
task = null;
// Tell all plotters to stop gathering information.
for(Graph graph : graphs) {
graph.onOptOut();
}
}
}
// We use the inverse of firstPost because if it is the first time we are posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e PING!
postPlugin(!firstPost);
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch(IOException e) {
if(debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}
}, 0, PING_INTERVAL * 1200);
return true;
}
}
/**
* If the server owner denied plugin metrics.
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized(optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch(IOException ex) {
if(debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true;
} catch(InvalidConfigurationException ex) {
if(debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true;
}
return configuration.getBoolean("opt-out", false);
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
* @throws IOException when saving the config file fails
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized(optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if(isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if(task == null) {
start();
}
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
* @throws IOException when saving the config file fails
*/
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
synchronized(optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if(!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
}
// Disable Task, if it is running
if(task != null) {
task.cancel();
task = null;
}
}
}
/**
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status.
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory.
File pluginsFolder = plugin.getDataFolder().getParentFile();
// return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
/**
* Gets the online player (backwards compatibility).
* @return online player amount
*/
private int getOnlinePlayers() {
try {
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
} else {
return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
}
} catch(Exception ex) {
if(debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
}
return 0;
}
/**
* Generic method that posts a plugin to the metrics website.
*/
private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section
PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName();
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = this.getOnlinePlayers();
// END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data
StringBuilder json = new StringBuilder(1024);
json.append('{');
// The plugin's description file containg all of the plugin data such as name, version, author, etc
appendJsonPair(json, "guid", guid);
appendJsonPair(json, "plugin_version", pluginVersion);
appendJsonPair(json, "server_version", serverVersion);
appendJsonPair(json, "players_online", Integer.toString(playersOnline));
// New data as of R6
String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version");
String javaVersion = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64
if(osarch.equals("amd64")) {
osarch = "x86_64";
}
appendJsonPair(json, "osname", osname);
appendJsonPair(json, "osarch", osarch);
appendJsonPair(json, "osversion", osversion);
appendJsonPair(json, "cores", Integer.toString(coreCount));
appendJsonPair(json, "auth_mode", onlineMode ? "1" : "0");
appendJsonPair(json, "java_version", javaVersion);
// If we're pinging, append it
if(isPing) {
appendJsonPair(json, "ping", "1");
}
if(graphs.size() > 0) {
synchronized(graphs) {
json.append(',');
json.append('"');
json.append("graphs");
json.append('"');
json.append(':');
json.append('{');
boolean firstGraph = true;
final Iterator<Graph> iter = graphs.iterator();
while(iter.hasNext()) {
Graph graph = iter.next();
StringBuilder graphJson = new StringBuilder();
graphJson.append('{');
for(Plotter plotter : graph.getPlotters()) {
appendJsonPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
}
graphJson.append('}');
if(!firstGraph) {
json.append(',');
}
json.append(escapeJson(graph.getName()));
json.append(':');
json.append(graphJson);
firstGraph = false;
}
json.append('}');
}
}
// close json
json.append('}');
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website
URLConnection connection;
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if(isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
byte[] uncompressed = json.toString().getBytes();
byte[] compressed = gzip(json.toString());
// Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if(debug) {
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
// Write the data
OutputStream os = connection.getOutputStream();
os.write(compressed);
os.flush();
// Now read the response
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = reader.readLine();
// close resources
os.close();
reader.close();
if(response == null || response.startsWith("ERR") || response.startsWith("7")) {
if(response == null) {
response = "null";
} else if(response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1);
}
throw new IOException(response);
} else {
// Is this the first update this hour?
if(response.equals("1") || response.contains("This is your first update this hour")) {
synchronized(graphs) {
final Iterator<Graph> iter = graphs.iterator();
while(iter.hasNext()) {
final Graph graph = iter.next();
for(Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
}
}
}
}
}
/**
* GZip compress a string of bytes.
* @param input Content to gzip
* @return byte[] of the gzipped input
*/
public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes(StandardCharsets.UTF_8));
} catch(IOException e) {
e.printStackTrace();
} finally {
if(gzos != null) {
try {
gzos.close();
} catch(IOException ignore) {
// ignore
}
}
}
return baos.toByteArray();
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch(Exception e) {
return false;
}
}
/**
* Appends a json encoded key/value pair to the given string builder.
*/
private static void appendJsonPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false;
try {
if(value.equals("0") || !value.endsWith("0")) {
Double.parseDouble(value);
isValueNumeric = true;
}
} catch(NumberFormatException e) {
isValueNumeric = false;
}
if(json.charAt(json.length() - 1) != '{') {
json.append(',');
}
json.append(escapeJson(key));
json.append(':');
if(isValueNumeric) {
json.append(value);
} else {
json.append(escapeJson(value));
}
}
/**
* Escape a string to create a valid JSON string.
*/
private static String escapeJson(String text) {
StringBuilder builder = new StringBuilder();
builder.append('"');
for(int index = 0; index < text.length(); index++) {
char chr = text.charAt(index);
switch(chr) {
case '"':
case '\\':
builder.append('\\');
builder.append(chr);
break;
case '\b':
builder.append("\\b");
break;
case '\t':
builder.append("\\t");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
default:
if(chr < ' ') {
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
} else {
builder.append(chr);
}
break;
}
}
builder.append('"');
return builder.toString();
}
/**
* Encode text as UTF-8.
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/**
* Represents a custom graph on the website.
*/
public static class Graph {
/**
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
* rejected.
*/
private final String name;
/**
* The set of plotters that are contained within this graph.
*/
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
private Graph(final String name) {
this.name = name;
}
/**
* Gets the graph's name.
* @return the Graph's name
*/
public String getName() {
return name;
}
/**
* Add a plotter to the graph, which will be used to plot entries.
* @param plotter the plotter to add to the graph
*/
public void addPlotter(final Plotter plotter) {
plotters.add(plotter);
}
/**
* Remove a plotter from the graph.
* @param plotter the plotter to remove from the graph
*/
public void removePlotter(final Plotter plotter) {
plotters.remove(plotter);
}
/**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph.
* @return an unmodifiable {@link java.util.Set} of the plotter objects
*/
public Set<Plotter> getPlotters() {
return Collections.unmodifiableSet(plotters);
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public boolean equals(final Object object) {
if(!(object instanceof Graph)) {
return false;
}
final Graph graph = (Graph)object;
return graph.name.equals(name);
}
/**
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
*/
protected void onOptOut() {
}
}
/**
* Interface used to collect custom data for a plugin.
*/
public abstract static class Plotter {
/**
* The plot's name.
*/
private final String name;
/**
* Construct a plotter with the default plot name.
*/
public Plotter() {
this("Default");
}
/**
* Construct a plotter with a specific plot name.
* @param name the name of the plotter to use, which will show up on the website
*/
public Plotter(final String name) {
this.name = name;
}
/**
* Get the current value for the plotted point. Since this function defers to an external function it may or may
* not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
* from any thread so care should be taken when accessing resources that need to be synchronized.
* @return the current value for the point to be plotted.
*/
public abstract int getValue();
/**
* Get the column name for the plotted point.
* @return the plotted point's column name
*/
public String getColumnName() {
return name;
}
/**
* Called after the website graphs have been updated.
*/
public void reset() {
}
@Override
public int hashCode() {
return getColumnName().hashCode();
}
@Override
public boolean equals(final Object object) {
if(!(object instanceof Plotter)) {
return false;
}
final Plotter plotter = (Plotter)object;
return plotter.name.equals(name) && plotter.getValue() == getValue();
}
}
}
@@ -5,7 +5,6 @@ import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.bukkitdo.Do;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -22,112 +21,109 @@ import java.util.List;
* Notify region expiry and track activity time.
*/
public final class PlayerLoginLogoutListener implements Listener {
private final AreaShop plugin;
private final AreaShop plugin;
/**
* Constructor.
* @param plugin The AreaShop plugin
*/
public PlayerLoginLogoutListener(AreaShop plugin) {
this.plugin = plugin;
}
/**
* Constructor.
*
* @param plugin The AreaShop plugin
*/
public PlayerLoginLogoutListener(AreaShop plugin) {
this.plugin = plugin;
}
/**
* Called when a sign is changed.
* @param event The event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
if(event.getResult() != Result.ALLOWED) {
return;
}
final Player player = event.getPlayer();
/**
* Called when a sign is changed.
*
* @param event The event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
if (event.getResult() != Result.ALLOWED) {
return;
}
final Player player = event.getPlayer();
// Schedule task to check for notifications, prevents a lag spike at login
Do.syncTimerLater(25, 25, () -> {
// Delay until all regions are loaded
if(!plugin.isReady()) {
return true;
}
if(!player.isOnline()) {
return false;
}
// Notify for rents that almost run out
for(RentRegion region : plugin.getFileManager().getRents()) {
if(region.isRenter(player)) {
String warningSetting = region.getStringSetting("rent.warningOnLoginTime");
if(warningSetting == null || warningSetting.isEmpty()) {
continue;
}
long warningTime = Utils.durationStringToLong(warningSetting);
if(region.getTimeLeft() < warningTime) {
// Send the warning message later to let it appear after general MOTD messages
AreaShop.getInstance().message(player, "rent-expireWarning", region);
}
}
}
// Schedule task to check for notifications, prevents a lag spike at login
Utils.runCancellingTaskTimer(() -> {
// Delay until all regions are loaded
if (!plugin.isReady()) {
return true;
}
if (!player.isOnline()) {
return false;
}
// Notify for rents that almost run out
for (RentRegion region : plugin.getFileManager().getRents()) {
if (region.isRenter(player)) {
String warningSetting = region.getStringSetting("rent.warningOnLoginTime");
if (warningSetting == null || warningSetting.isEmpty()) {
continue;
}
long warningTime = Utils.durationStringToLong(warningSetting);
if (region.getTimeLeft() < warningTime) {
// Send the warning message later to let it appear after general MOTD messages
AreaShop.getInstance().message(player, "rent-expireWarning", region);
}
}
}
// Notify admins for plugin updates
AreaShop.getInstance().notifyUpdate(player);
return false;
});
// Notify admins for plugin updates
AreaShop.getInstance().notifyUpdate(player);
return false;
}, 25, 25, false);
// Check if the player has regions that use an old name of him and update them
Do.syncTimerLater(22, 10, () -> {
if(!plugin.isReady()) {
return true;
}
// Check if the player has regions that use an old name of him and update them
Utils.runCancellingTaskTimer(() -> {
if (!plugin.isReady()) {
return true;
}
List<GeneralRegion> regions = new ArrayList<>();
for(GeneralRegion region : plugin.getFileManager().getRegions()) {
if(region.isOwner(player)) {
regions.add(region);
}
}
List<GeneralRegion> regions = new ArrayList<>();
for (GeneralRegion region : plugin.getFileManager().getRegions()) {
if (region.isOwner(player)) {
regions.add(region);
}
}
final String name = player.getName();
Utils.runAsBatches(regions,
plugin.getConfig().getInt("nameupdate.regionsPerTick"),
(region) -> {
if (region instanceof BuyRegion || region instanceof RentRegion) {
String key = region instanceof BuyRegion ? "buy.buyerName" : "rent.renterName";
if (!name.equals(region.getStringSetting("buy.buyerName"))) {
region.setSetting(key, player.getName());
region.update();
}
}
}, false);
return false;
}, 22, 10, false);
}
Do.forAll(
plugin.getConfig().getInt("nameupdate.regionsPerTick"),
regions,
region -> {
if(region instanceof BuyRegion) {
if(!player.getName().equals(region.getStringSetting("buy.buyerName"))) {
region.setSetting("buy.buyerName", player.getName());
region.update();
}
} else if(region instanceof RentRegion) {
if(!player.getName().equals(region.getStringSetting("rent.renterName"))) {
region.setSetting("rent.renterName", player.getName());
region.update();
}
}
}
);
return false;
});
}
// Active time updates
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogout(PlayerQuitEvent event) {
updateLastActive(event.getPlayer());
}
// Active time updates
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogout(PlayerQuitEvent event) {
updateLastActive(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
updateLastActive(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
updateLastActive(event.getPlayer());
}
/**
* Update the last active time for all regions the player is owner off.
* @param player The player to update the active times for
*/
private void updateLastActive(Player player) {
for(GeneralRegion region : plugin.getFileManager().getRegions()) {
if(region.isOwner(player)) {
region.updateLastActiveTime();
}
}
}
/**
* Update the last active time for all regions the player is owner off.
*
* @param player The player to update the active times for
*/
private void updateLastActive(Player player) {
for (GeneralRegion region : plugin.getFileManager().getRegions()) {
if (region.isOwner(player)) {
region.updateLastActiveTime();
}
}
}
}
@@ -39,19 +39,15 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.*;
public class CommandManager extends Manager implements CommandExecutor, TabCompleter {
private final ArrayList<CommandAreaShop> commands;
private final List<CommandAreaShop> commands = new ArrayList<>();
/**
* Constructor.
*/
public CommandManager() {
commands = new ArrayList<>();
commands.add(new HelpCommand());
commands.add(new RentCommand());
commands.add(new UnrentCommand());
@@ -95,8 +91,9 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
* Get the list with AreaShop commands.
* @return The list with AreaShop commands
*/
public ArrayList<CommandAreaShop> getCommands() {
return commands;
public List<CommandAreaShop> getCommands() {
// Return a cloned array
return new ArrayList<>(commands);
}
/**
@@ -109,12 +106,12 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
return;
}
// Add all messages to a list
ArrayList<String> messages = new ArrayList<>();
List<String> messages = new ArrayList<>(commands.size());
plugin.message(target, "help-header");
plugin.message(target, "help-alias");
for(CommandAreaShop command : commands) {
String help = command.getHelp(target);
if(help != null && help.length() != 0) {
if(help != null && !help.isEmpty()) {
messages.add(help);
}
}
@@ -130,38 +127,48 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
plugin.message(sender, "general-notReady");
return true;
}
// Redirect `/as info player <player>` to `/as me <player>`
if(args.length == 3 && "info".equals(args[0]) && "player".equals(args[1])) {
if(args.length == 3 && "info".equalsIgnoreCase(args[0]) && "player".equalsIgnoreCase(args[1])) {
args[0] = "me";
args[1] = args[2];
}
// Execute command
boolean executed = false;
for(int i = 0; i < commands.size() && !executed; i++) {
if(commands.get(i).canExecute(command, args)) {
commands.get(i).execute(sender, args);
for (final CommandAreaShop cmd : commands) {
if (cmd.canExecute(command, args)) {
cmd.execute(sender, args);
executed = true;
// Can't have two commands with same label
break;
}
}
if(!executed && args.length == 0) {
this.showHelp(sender);
} else if(!executed && args.length > 0) {
// Indicate that the '/as updaterents' and '/as updatebuys' commands are removed
if("updaterents".equalsIgnoreCase(args[0]) || "updatebuys".equalsIgnoreCase(args[0])) {
plugin.message(sender, "reload-updateCommandChanged");
// Show help
if (!executed) {
if (args.length == 0) {
this.showHelp(sender);
} else {
plugin.message(sender, "cmd-notValid");
// Indicate that the '/as updaterents' and '/as updatebuys' commands are removed
if("updaterents".equalsIgnoreCase(args[0]) || "updatebuys".equalsIgnoreCase(args[0])) {
plugin.message(sender, "reload-updateCommandChanged");
} else {
plugin.message(sender, "cmd-notValid");
}
}
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> result = new ArrayList<>();
if(!sender.hasPermission("areashop.tabcomplete")) {
return result;
return Collections.emptyList();
}
List<String> result = new ArrayList<>();
int toCompleteNumber = args.length;
String toCompletePrefix = args[args.length - 1].toLowerCase();
//AreaShop.debug("toCompleteNumber=" + toCompleteNumber + ", toCompletePrefix=" + toCompletePrefix + ", length=" + toCompletePrefix.length());
@@ -177,19 +184,19 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
for(CommandAreaShop c : commands) {
if(c.canExecute(command, args)) {
result = c.getTabCompleteList(toCompleteNumber, start, sender);
break;
}
}
}
// Filter and sort the results
if(result.size() > 0) {
if(!result.isEmpty()) {
SortedSet<String> set = new TreeSet<>();
for(String suggestion : result) {
if(suggestion.toLowerCase().startsWith(toCompletePrefix)) {
set.add(suggestion);
}
}
result.clear();
result.addAll(set);
return new ArrayList<>(set);
}
//AreaShop.debug("Tabcomplete #" + toCompleteNumber + ", prefix="+ toCompletePrefix + ", result=" + result.toString());
return result;
@@ -1,10 +1,11 @@
package me.wiefferink.areashop.managers;
import me.wiefferink.areashop.AreaShop;
import me.wiefferink.areashop.features.CommandsFeature;
import me.wiefferink.areashop.features.DebugFeature;
import me.wiefferink.areashop.features.FriendsFeature;
import me.wiefferink.areashop.features.RegionFeature;
import me.wiefferink.areashop.features.TeleportFeature;
import me.wiefferink.areashop.features.teleport.TeleportFeature;
import me.wiefferink.areashop.features.WorldGuardRegionFlagsFeature;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.regions.GeneralRegion;
@@ -25,7 +26,8 @@ public class FeatureManager extends Manager {
SignsFeature.class,
FriendsFeature.class,
WorldGuardRegionFlagsFeature.class,
TeleportFeature.class
TeleportFeature.class,
CommandsFeature.class
));
// One instance of each feature, registered for event handling
private final Set<RegionFeature> globalFeatures;
@@ -40,13 +42,11 @@ public class FeatureManager extends Manager {
for(Class<? extends RegionFeature> clazz : featureClasses) {
try {
Constructor<? extends RegionFeature> constructor = clazz.getConstructor();
try {
RegionFeature feature = constructor.newInstance();
feature.listen();
globalFeatures.add(feature);
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
AreaShop.error("Failed to instantiate global feature:", clazz, e);
}
RegionFeature feature = constructor.newInstance();
feature.listen();
globalFeatures.add(feature);
} catch(InstantiationException | IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
AreaShop.error("Failed to instantiate global feature:", clazz, e);
} catch(NoSuchMethodException e) {
// Feature does not have a global part
}
@@ -57,7 +57,7 @@ public class FeatureManager extends Manager {
for(Class<? extends RegionFeature> clazz : featureClasses) {
try {
regionFeatureConstructors.put(clazz, clazz.getConstructor(GeneralRegion.class));
} catch(NoSuchMethodException | IllegalArgumentException e) {
} catch(NoSuchMethodException | IllegalArgumentException ignored) {
// The feature does not have a region specific part
}
}
@@ -71,7 +71,7 @@ public class FeatureManager extends Manager {
}
/**
* Instanciate a feature for a certain region.
* Instantiate a feature for a certain region.
* @param region The region to create a feature for
* @param featureClazz The class of the feature to create
* @return The feature class
@@ -80,7 +80,7 @@ public class FeatureManager extends Manager {
try {
return regionFeatureConstructors.get(featureClazz).newInstance(region);
} catch(InstantiationException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
AreaShop.error("Failed to instanciate feature", featureClazz, "for region", region, e, e.getCause());
AreaShop.error("Failed to instantiate feature", featureClazz, "for region", region, e, e.getCause());
}
return null;
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,79 @@
package me.wiefferink.areashop.managers;
import me.wiefferink.areashop.AreaShop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicBoolean;
public class SignErrorLogger {
public static final String PREFIX_WARN = "[Warning] [Sign Feature] ";
public static final DateFormat FORMAT = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
private final List<String> cache = new LinkedList<>();
private final AtomicBoolean needsSaving = new AtomicBoolean(false);
private final File file;
public SignErrorLogger(File file) {
this.file = Objects.requireNonNull(file);
}
public void clearCache() {
synchronized (this.cache) {
this.cache.clear();
}
}
public SignErrorLogger submitWarning(String message) {
final String actual = FORMAT.format(Date.from(Instant.now())) + PREFIX_WARN + message;
synchronized (this.cache) {
this.cache.add(actual);
}
return this;
}
public void queueSave() {
this.needsSaving.set(true);
}
public void saveIfDirty() {
if (this.needsSaving.get()) {
save();
}
}
public synchronized void save() {
AreaShop.debugTask("[Sign Feature] Dumping sign errors to disk...");
final String[] copy;
synchronized (this.cache) {
copy = cache.toArray(new String[0]);
}
final StringJoiner joiner = new StringJoiner(System.lineSeparator());
for (String s : copy) {
joiner.add(s);
}
try (OutputStream os = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
writer.write(joiner.toString());
} catch (IOException ex) {
ex.printStackTrace();
AreaShop.error("Failed to update the sign error log!");
} finally {
AreaShop.debugTask("[Sign Feature] Error dump complete.");
}
}
}
@@ -3,12 +3,16 @@ package me.wiefferink.areashop.managers;
import me.wiefferink.areashop.features.signs.RegionSign;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.Materials;
import me.wiefferink.areashop.tools.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -17,7 +21,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.material.Sign;
import org.bukkit.util.BlockIterator;
import java.util.HashMap;
@@ -39,7 +42,7 @@ public class SignLinkerManager extends Manager implements Listener {
@Override
public void shutdown() {
for(UUID uuid : signLinkers.keySet()) {
exitSignLinkMode(Bukkit.getPlayer(uuid));
exitSignLinkMode(uuid);
}
}
@@ -71,6 +74,18 @@ public class SignLinkerManager extends Manager implements Listener {
plugin.message(player, "linksigns-stopped");
}
private void exitSignLinkMode(UUID player) {
signLinkers.remove(player);
if(eventsRegistered && signLinkers.isEmpty()) {
eventsRegistered = false;
HandlerList.unregisterAll(this);
}
final Player online = Bukkit.getPlayer(player);
if (online != null) {
plugin.message(player, "linksigns-stopped");
}
}
/**
* Check if the player is in sign linking mode.
* @param player The player to check
@@ -120,7 +135,7 @@ public class SignLinkerManager extends Manager implements Listener {
block = next;
}
}
if(block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
if(block == null || !Materials.isSign(block.getType())) {
plugin.message(player, "linksigns-noSign");
return;
}
@@ -130,8 +145,16 @@ public class SignLinkerManager extends Manager implements Listener {
plugin.message(player, "linksigns-alreadyRegistered", regionSign.getRegion());
return;
}
Sign sign = (Sign)block.getState().getData();
linker.setSign(block.getLocation(), block.getType(), sign.getFacing());
final BlockData blockData = block.getBlockData();
final BlockFace rotation;
if (blockData instanceof Sign) {
rotation = ((Sign) blockData).getRotation();
} else if (blockData instanceof WallSign) {
rotation = ((WallSign) blockData).getFacing();
} else {
rotation = null;
}
linker.setSign(block.getLocation(), block.getType(), rotation);
}
}
}
@@ -259,189 +259,187 @@ public class BuyRegion extends GeneralRegion {
@SuppressWarnings("deprecation")
public boolean buy(OfflinePlayer offlinePlayer) {
// Check if the player has permission
if(plugin.hasPermission(offlinePlayer, "areashop.buy")) {
if(plugin.getEconomy() == null) {
message(offlinePlayer, "general-noEconomy");
if(!plugin.hasPermission(offlinePlayer, "areashop.buy")) {
message(offlinePlayer, "buy-noPermission");
return false;
}
if(plugin.getEconomy() == null) {
message(offlinePlayer, "general-noEconomy");
return false;
}
if(isInResellingMode()) {
if(!plugin.hasPermission(offlinePlayer, "areashop.buyresell")) {
message(offlinePlayer, "buy-noPermissionResell");
return false;
}
if(isInResellingMode()) {
if(!plugin.hasPermission(offlinePlayer, "areashop.buyresell")) {
message(offlinePlayer, "buy-noPermissionResell");
return false;
}
} else {
if(!plugin.hasPermission(offlinePlayer, "areashop.buynormal")) {
message(offlinePlayer, "buy-noPermissionNoResell");
return false;
}
}
if(getWorld() == null) {
message(offlinePlayer, "general-noWorld");
return false;
}
if(getRegion() == null) {
message(offlinePlayer, "general-noRegion");
return false;
}
if(!isSold() || (isInResellingMode() && !isBuyer(offlinePlayer))) {
boolean isResell = isInResellingMode();
// Only relevant if the player is online
Player player = offlinePlayer.getPlayer();
if(player != null) {
// Check if the players needs to be in the region for buying
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
message(offlinePlayer, "buy-restrictedToRegion");
return false;
}
// Check if the players needs to be in the world for buying
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
message(offlinePlayer, "buy-restrictedToWorld", player.getWorld().getName());
return false;
}
}
// Check region limits
LimitResult limitResult = this.limitsAllow(RegionType.BUY, offlinePlayer);
AreaShop.debug("LimitResult: " + limitResult.toString());
if(!limitResult.actionAllowed()) {
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
if(limitResult.getLimitingFactor() == LimitType.BUYS) {
message(offlinePlayer, "buy-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
// Should not be reached, but is safe like this
return false;
}
// Check if the player has enough money
if((!isResell && plugin.getEconomy().has(offlinePlayer, getWorldName(), getPrice())) || (isResell && plugin.getEconomy().has(offlinePlayer, getWorldName(), getResellPrice()))) {
UUID oldOwner = getBuyer();
if(isResell && oldOwner != null) {
// Broadcast and check event
ResellingRegionEvent event = new ResellingRegionEvent(this, offlinePlayer);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(offlinePlayer, "general-cancelled", event.getReason());
return false;
}
getFriendsFeature().clearFriends();
double resellPrice = getResellPrice();
// Transfer the money to the previous owner
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getResellPrice());
if(!r.transactionSuccess()) {
message(offlinePlayer, "buy-payError");
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while buying " + getName() + ": " + r.errorMessage);
return false;
}
r = null;
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
String oldOwnerName = getPlayerName();
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
oldOwnerName = oldOwnerPlayer.getName();
} else if(oldOwnerName != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerName, getWorldName(), getResellPrice());
}
if(r == null || !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + oldOwnerName + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + offlinePlayer.getName());
}
// Resell is done, disable that now
disableReselling();
// Run commands
this.runEventCommands(RegionEvent.RESELL, true);
// Set the owner
setBuyer(offlinePlayer.getUniqueId());
updateLastActiveTime();
// Update everything
handleSchematicEvent(RegionEvent.RESELL);
// Notify about updates
this.notifyAndUpdate(new ResoldRegionEvent(this, oldOwner));
// Send message to the player
message(offlinePlayer, "buy-successResale", oldOwnerName);
Player seller = Bukkit.getPlayer(oldOwner);
if(seller != null) {
message(seller, "buy-successSeller", resellPrice);
}
// Run commands
this.runEventCommands(RegionEvent.RESELL, false);
} else {
// Broadcast and check event
BuyingRegionEvent event = new BuyingRegionEvent(this, offlinePlayer);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(offlinePlayer, "general-cancelled", event.getReason());
return false;
}
// Substract the money from the players balance
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getPrice());
if(!r.transactionSuccess()) {
message(offlinePlayer, "buy-payError");
return false;
}
// Optionally give money to the landlord
OfflinePlayer landlordPlayer = null;
if(getLandlord() != null) {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
} else {
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), getPrice());
}
if(r != null && !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + getFormattedPrice() + " for his sell of region " + getName() + " to " + offlinePlayer.getName());
}
}
// Run commands
this.runEventCommands(RegionEvent.BOUGHT, true);
// Set the owner
setBuyer(offlinePlayer.getUniqueId());
updateLastActiveTime();
// Notify about updates
this.notifyAndUpdate(new BoughtRegionEvent(this));
// Update everything
handleSchematicEvent(RegionEvent.BOUGHT);
// Send message to the player
message(offlinePlayer, "buy-succes");
// Run commands
this.runEventCommands(RegionEvent.BOUGHT, false);
}
return true;
} else {
// Player has not enough money
if(isResell) {
message(offlinePlayer, "buy-lowMoneyResell", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
} else {
message(offlinePlayer, "buy-lowMoney", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
}
}
} else {
if(isBuyer(offlinePlayer)) {
message(offlinePlayer, "buy-yours");
} else {
message(offlinePlayer, "buy-someoneElse");
}
}
} else {
message(offlinePlayer, "buy-noPermission");
if(!plugin.hasPermission(offlinePlayer, "areashop.buynormal")) {
message(offlinePlayer, "buy-noPermissionNoResell");
return false;
}
}
return false;
if(getWorld() == null) {
message(offlinePlayer, "general-noWorld");
return false;
}
if(getRegion() == null) {
message(offlinePlayer, "general-noRegion");
return false;
}
if (isSold() && !(isInResellingMode() && !isBuyer(offlinePlayer))) {
if(isBuyer(offlinePlayer)) {
message(offlinePlayer, "buy-yours");
} else {
message(offlinePlayer, "buy-someoneElse");
}
return false;
}
boolean isResell = isInResellingMode();
// Only relevant if the player is online
Player player = offlinePlayer.getPlayer();
if(player != null) {
// Check if the players needs to be in the region for buying
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
message(offlinePlayer, "buy-restrictedToRegion");
return false;
}
// Check if the players needs to be in the world for buying
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
message(offlinePlayer, "buy-restrictedToWorld", player.getWorld().getName());
return false;
}
}
// Check region limits
LimitResult limitResult = this.limitsAllow(RegionType.BUY, offlinePlayer);
AreaShop.debug("LimitResult: " + limitResult.toString());
if(!limitResult.actionAllowed()) {
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
if(limitResult.getLimitingFactor() == LimitType.BUYS) {
message(offlinePlayer, "buy-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
// Should not be reached, but is safe like this
return false;
}
// Check if the player has enough money
if (isResell && !plugin.getEconomy().has(offlinePlayer, getWorldName(), getResellPrice())) {
message(offlinePlayer, "buy-lowMoneyResell", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
return false;
}
if (!isResell && !plugin.getEconomy().has(offlinePlayer, getWorldName(), getPrice())) {
message(offlinePlayer, "buy-lowMoney", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
return false;
}
UUID oldOwner = getBuyer();
if(isResell && oldOwner != null) {
// Broadcast and check event
ResellingRegionEvent event = new ResellingRegionEvent(this, offlinePlayer);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(offlinePlayer, "general-cancelled", event.getReason());
return false;
}
getFriendsFeature().clearFriends();
double resellPrice = getResellPrice();
// Transfer the money to the previous owner
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getResellPrice());
if(!r.transactionSuccess()) {
message(offlinePlayer, "buy-payError");
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while buying " + getName() + ": " + r.errorMessage);
return false;
}
r = null;
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
String oldOwnerName = getPlayerName();
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
oldOwnerName = oldOwnerPlayer.getName();
} else if(oldOwnerName != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerName, getWorldName(), getResellPrice());
}
if(r == null || !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + oldOwnerName + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + offlinePlayer.getName());
}
// Resell is done, disable that now
disableReselling();
// Set the owner
setBuyer(offlinePlayer.getUniqueId());
updateLastActiveTime();
// Update everything
handleSchematicEvent(RegionEvent.RESELL);
// Notify about updates
this.notifyAndUpdate(new ResoldRegionEvent(this, oldOwner));
// Send message to the player
message(offlinePlayer, "buy-successResale", oldOwnerName);
Player seller = Bukkit.getPlayer(oldOwner);
if(seller != null) {
message(seller, "buy-successSeller", resellPrice);
}
} else {
// Broadcast and check event
BuyingRegionEvent event = new BuyingRegionEvent(this, offlinePlayer);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(offlinePlayer, "general-cancelled", event.getReason());
return false;
}
// Substract the money from the players balance
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), getPrice());
if(!r.transactionSuccess()) {
message(offlinePlayer, "buy-payError");
return false;
}
// Optionally give money to the landlord
OfflinePlayer landlordPlayer = null;
if(getLandlord() != null) {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
} else {
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), getPrice());
}
if(r != null && !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + getFormattedPrice() + " for his sell of region " + getName() + " to " + offlinePlayer.getName());
}
}
// Set the owner
setBuyer(offlinePlayer.getUniqueId());
updateLastActiveTime();
// Send message to the player
message(offlinePlayer, "buy-succes");
// Update everything
handleSchematicEvent(RegionEvent.BOUGHT);
// Notify about updates
this.notifyAndUpdate(new BoughtRegionEvent(this));
}
return true;
}
/**
@@ -483,9 +481,6 @@ public class BuyRegion extends GeneralRegion {
return false;
}
// Run commands
this.runEventCommands(RegionEvent.SOLD, true);
disableReselling();
// Give part of the buying price back
double moneyBack = getMoneyBackAmount();
@@ -528,11 +523,12 @@ public class BuyRegion extends GeneralRegion {
}
}
message(executor, "sell-sold");
// Handle schematic save/restore (while %uuid% is still available)
handleSchematicEvent(RegionEvent.SOLD);
// Send message: before actual removal of the buyer so that it is still available for variables
message(executor, "sell-sold");
// Remove friends and the owner
getFriendsFeature().clearFriends();
UUID oldBuyer = getBuyer();
@@ -541,9 +537,6 @@ public class BuyRegion extends GeneralRegion {
// Notify about updates
this.notifyAndUpdate(new SoldRegionEvent(this, oldBuyer, Math.max(moneyBack, 0)));
// Run commands
this.runEventCommands(RegionEvent.SOLD, false);
return true;
}
@@ -558,10 +551,11 @@ public class BuyRegion extends GeneralRegion {
return false;
}
long lastPlayed = getLastActiveTime();
long now = System.currentTimeMillis();
//AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
if(Calendar.getInstance().getTimeInMillis() > (lastPlayed + inactiveSetting)) {
if(now > (lastPlayed + inactiveSetting)) {
AreaShop.info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName());
AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
AreaShop.debug("currentTime=" + now + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (now - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
return this.sell(true, null);
}
return false;
@@ -1,7 +1,6 @@
package me.wiefferink.areashop.regions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import co.aikar.taskchain.TaskChain;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.AreaShop;
@@ -9,12 +8,11 @@ import me.wiefferink.areashop.events.NotifyRegionEvent;
import me.wiefferink.areashop.events.notify.UpdateRegionEvent;
import me.wiefferink.areashop.features.FriendsFeature;
import me.wiefferink.areashop.features.RegionFeature;
import me.wiefferink.areashop.features.TeleportFeature;
import me.wiefferink.areashop.features.teleport.TeleportFeature;
import me.wiefferink.areashop.features.signs.SignsFeature;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.managers.FileManager;
import me.wiefferink.areashop.tools.Utils;
import me.wiefferink.bukkitdo.Do;
import me.wiefferink.interactivemessenger.processing.Message;
import me.wiefferink.interactivemessenger.processing.ReplacementProvider;
import org.apache.commons.lang.exception.ExceptionUtils;
@@ -25,8 +23,10 @@ import org.bukkit.World;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.io.File;
import java.io.IOException;
@@ -39,6 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public abstract class GeneralRegion implements GeneralRegionInterface, Comparable<GeneralRegion>, ReplacementProvider {
static final AreaShop plugin = AreaShop.getInstance();
@@ -184,15 +185,11 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Get a feature of this region.
* @param clazz The class of the feature to get
* @return The feature (either just instanciated or cached)
* @param <T> The feature to get
* @return The feature (either just instantiated or cached)
*/
public RegionFeature getFeature(Class<? extends RegionFeature> clazz) {
RegionFeature result = features.get(clazz);
if(result == null) {
result = plugin.getFeatureManager().getRegionFeature(this, clazz);
features.put(clazz, result);
}
return result;
public <T extends RegionFeature> T getFeature(Class<T> clazz) {
return clazz.cast(features.computeIfAbsent(clazz, (unused) -> plugin.getFeatureManager().getRegionFeature(this, clazz)));
}
/**
@@ -200,7 +197,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return The FriendsFeature of this region
*/
public FriendsFeature getFriendsFeature() {
return (FriendsFeature)getFeature(FriendsFeature.class);
return getFeature(FriendsFeature.class);
}
/**
@@ -208,7 +205,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return The SignsFeature of this region
*/
public SignsFeature getSignsFeature() {
return (SignsFeature)getFeature(SignsFeature.class);
return getFeature(SignsFeature.class);
}
/**
@@ -216,7 +213,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return The TeleportFeature
*/
public TeleportFeature getTeleportFeature() {
return (TeleportFeature)getFeature(TeleportFeature.class);
return getFeature(TeleportFeature.class);
}
// ABSTRACT
@@ -312,6 +309,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* Get the name of the region.
* @return The region name
*/
@Override
public String getName() {
return config.getString("general.name");
}
@@ -366,6 +364,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* Get the World of the region.
* @return The World where the region is located
*/
@Override
public World getWorld() {
return Bukkit.getWorld(getWorldName());
}
@@ -374,6 +373,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* Get the name of the world where the region is located.
* @return The name of the world of the region
*/
@Override
public String getWorldName() {
return getStringSetting("general.world");
}
@@ -445,7 +445,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(landlordName != null && !landlordName.isEmpty()) {
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(landlordName);
if(offlinePlayer != null) {
if(offlinePlayer.hasPlayedBefore()) {
return offlinePlayer.getUniqueId();
}
}
@@ -458,7 +458,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
*/
public String getLandlordName() {
String result = Utils.toName(getLandlord());
if(result == null || result.isEmpty()) {
if(result.isEmpty()) {
result = config.getString("general.landlordName");
if(result == null || result.isEmpty()) {
result = null;
@@ -477,7 +477,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
setSetting("general.landlord", landlord.toString());
}
String properName = Utils.toName(landlord);
if(properName == null) {
if(properName.isEmpty()) {
properName = name;
}
setSetting("general.landlordName", properName);
@@ -504,6 +504,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* Get the WorldGuard region associated with this AreaShop region.
* @return The ProtectedRegion of WorldGuard or null if the region does not exist anymore
*/
@Override
public ProtectedRegion getRegion() {
if(getWorld() == null
|| plugin.getWorldGuard() == null
@@ -514,37 +515,56 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
return plugin.getRegionManager(getWorld()).getRegion(getName());
}
/**
* Get the minimum corner of the region.
* @return Vector
*/
public Vector getMinimumPoint() {
return plugin.getWorldGuardHandler().getMinimumPoint(getRegion());
}
/**
* Get the maximum corner of the region.
* @return Vector
*/
public Vector getMaximumPoint() {
return plugin.getWorldGuardHandler().getMaximumPoint(getRegion());
}
/**
* Get the width of the region (x-axis).
* @return The width of the region (x-axis)
*/
@Override
public int getWidth() {
if(getRegion() == null) {
return 0;
}
return getRegion().getMaximumPoint().getBlockX() - getRegion().getMinimumPoint().getBlockX() + 1;
return getMaximumPoint().getBlockX() - getMinimumPoint().getBlockX() + 1;
}
/**
* Get the depth of the region (z-axis).
* @return The depth of the region (z-axis)
*/
@Override
public int getDepth() {
if(getRegion() == null) {
return 0;
}
return getRegion().getMaximumPoint().getBlockZ() - getRegion().getMinimumPoint().getBlockZ() + 1;
return getMaximumPoint().getBlockZ() - getMinimumPoint().getBlockZ() + 1;
}
/**
* Get the height of the region (y-axis).
* @return The height of the region (y-axis)
*/
@Override
public int getHeight() {
if(getRegion() == null) {
return 0;
}
return getRegion().getMaximumPoint().getBlockY() - getRegion().getMinimumPoint().getBlockY() + 1;
return getMaximumPoint().getBlockY() - getMinimumPoint().getBlockY() + 1;
}
/**
@@ -567,8 +587,11 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
*/
public List<String> getGroupNames() {
List<String> result = new ArrayList<>();
for(RegionGroup group : getGroups()) {
result.add(group.getName());
// Inline #getGroups
for(RegionGroup group : plugin.getFileManager().getGroups()) {
if(group.isMember(this)) {
result.add(group.getName());
}
}
return result;
}
@@ -756,6 +779,36 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
return true;
}
/**
* Save all blocks in a region for restoring later.
* @param fileName The name of the file to save to (extension and folder will be added)
* @return true if the region has been saved properly, otherwise false
*/
public CompletableFuture<Boolean> saveRegionBlocksAsync(String fileName) {
// Check if the region is correct
ProtectedRegion region = getRegion();
if(region == null) {
AreaShop.debug("Region '" + getName() + "' does not exist in WorldGuard, save failed");
return CompletableFuture.completedFuture(false);
}
// The path to save the schematic
File saveFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
// Create parent directories
File parent = saveFile.getParentFile();
if(parent != null && !parent.exists()) {
if(!parent.mkdirs()) {
AreaShop.warn("Did not save region " + getName() + ", schematic directory could not be created: " + saveFile.getAbsolutePath());
return CompletableFuture.completedFuture(false);
}
}
return plugin.getWorldEditHandler().saveRegionBlocksAsync(saveFile, this).thenApply(result -> {
if(result) {
AreaShop.debug("Saved schematic for region " + getName());
}
return result;
});
}
/**
* Restore all blocks in a region for restoring later.
* @param fileName The name of the file to save to (extension and folder will be added)
@@ -773,11 +826,34 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
AreaShop.debug("Restored schematic for region " + getName());
// Workaround for signs inside the region in combination with async restore of plugins like AsyncWorldEdit and FastAsyncWorldEdit
Do.syncLater(10, getSignsFeature()::update);
Bukkit.getScheduler().runTaskLater(plugin, getSignsFeature()::update, 10);
}
return result;
}
/**
* Restore all blocks in a region for restoring later.
* @param fileName The name of the file to save to (extension and folder will be added)
* @return true if the region has been restored properly, otherwise false
*/
public CompletableFuture<Boolean> restoreRegionBlocksAsync(String fileName) {
if(getRegion() == null) {
AreaShop.debug("Region '" + getName() + "' does not exist in WorldGuard, restore failed");
return CompletableFuture.completedFuture(false);
}
// The path to save the schematic
File restoreFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName);
return plugin.getWorldEditHandler().restoreRegionBlocksAsync(restoreFile, this).thenApply(result -> {
if(result) {
AreaShop.debug("Restored schematic for region " + getName());
// Workaround for signs inside the region in combination with async restore of plugins like AsyncWorldEdit and FastAsyncWorldEdit
Bukkit.getScheduler().runTaskLater(plugin, getSignsFeature()::update, 10);
}
return result;
});
}
/**
* Reset all flags of the region.
*/
@@ -822,6 +898,48 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
}
public CompletableFuture<Boolean> saveNowAsync() {
final YamlConfiguration clone = new YamlConfiguration();
final String fileName = plugin.getFileManager().getRegionFolder() + File.separator + getName().toLowerCase() + ".yml";
try {
clone.loadFromString(config.saveToString());
} catch (InvalidConfigurationException ex) {
ex.printStackTrace();
return CompletableFuture.completedFuture(false);
}
final CompletableFuture<Boolean> future = new CompletableFuture<>();
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
clone.save(new File(fileName));
future.complete(true);
} catch (IOException ex) {
ex.printStackTrace();
future.complete(false);
}
});
return future;
}
public TaskChain<Boolean> saveNowAsync(final TaskChain<?> chain) {
final YamlConfiguration clone = new YamlConfiguration();
final String fileName = plugin.getFileManager().getRegionFolder() + File.separator + getName().toLowerCase() + ".yml";
try {
clone.loadFromString(config.saveToString());
} catch (InvalidConfigurationException ex) {
ex.printStackTrace();
return chain.sync((unused) -> false);
}
return chain.async((unused) -> {
try {
clone.save(new File(fileName));
return true;
} catch (IOException ex) {
ex.printStackTrace();
return false;
}
});
}
// CONFIG
@@ -1251,7 +1369,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Class to store the result of a limits check.
*/
public class LimitResult {
public static class LimitResult {
private final boolean actionAllowed;
private final LimitType limitingFactor;
private final int maximum;
@@ -1366,8 +1484,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
public boolean matchesLimitGroup(String group) {
List<String> worlds = plugin.getConfig().getStringList("limitGroups." + group + ".worlds");
List<String> groups = plugin.getConfig().getStringList("limitGroups." + group + ".groups");
if((worlds == null || worlds.isEmpty() || worlds.contains(getWorldName()))) {
if(groups == null || groups.isEmpty()) {
if(worlds.isEmpty() || worlds.contains(getWorldName())) {
if(groups.isEmpty()) {
return true;
} else {
boolean inGroups = false;
@@ -1399,14 +1517,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
String save = profileSection.getString(type.getValue() + ".save");
String restore = profileSection.getString(type.getValue() + ".restore");
// Save the region if needed
if(save != null && save.length() != 0) {
if(save != null && !save.isEmpty()) {
save = Message.fromString(save).replacements(this).getSingle();
saveRegionBlocks(save);
saveRegionBlocksAsync(save);
}
// Restore the region if needed
if(restore != null && restore.length() != 0) {
if(restore != null && !restore.isEmpty()) {
restore = Message.fromString(restore).replacements(this).getSingle();
restoreRegionBlocks(restore);
restoreRegionBlocksAsync(restore);
}
}
@@ -1423,7 +1541,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
for(String command : commands) {
if(command == null || command.length() == 0) {
if(command == null || command.isEmpty()) {
continue;
}
// It is not ideal we have to disable language replacements here, but otherwise giving language variables
@@ -1457,23 +1575,6 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
}
/**
* Run command for a certain event.
* @param event The event
* @param before The 'before' or 'after' commands
*/
public void runEventCommands(RegionEvent event, boolean before) {
ConfigurationSection eventCommandProfileSection = getConfigurationSectionSetting("general.eventCommandProfile", "eventCommandProfiles");
if(eventCommandProfileSection == null) {
return;
}
List<String> commands = eventCommandProfileSection.getStringList(event.getValue() + "." + (before ? "before" : "after"));
if(commands == null || commands.isEmpty()) {
return;
}
runCommands(Bukkit.getConsoleSender(), commands);
}
/**
* Get the volume of the region (number of blocks inside it).
* @return Number of blocks in the region
@@ -1495,8 +1596,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
// Use own calculation for polygon regions, as WorldGuard does not implement it and returns 0
ProtectedRegion region = getRegion();
if(region instanceof ProtectedPolygonalRegion) {
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
Vector min = getMinimumPoint();
Vector max = getMaximumPoint();
// Exact, but slow algorithm
if(getWidth() * getDepth() < 100) {
@@ -1512,7 +1613,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
// Estimate, but quick algorithm
else {
List<BlockVector2D> points = region.getPoints();
List<Vector> points = plugin.getWorldGuardHandler().getRegionPoints(region);
int numPoints = points.size();
if(numPoints < 3) {
return 0;
@@ -1527,7 +1628,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
x2 = points.get(i + 1).getBlockX();
z2 = points.get(i + 1).getBlockZ();
area = area + ((z1 + z2) * (x1 - x2));
area += ((z1 + z2) * (x1 - x2));
}
x1 = points.get(numPoints - 1).getBlockX();
@@ -1535,7 +1636,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
x2 = points.get(0).getBlockX();
z2 = points.get(0).getBlockZ();
area = area + ((z1 + z2) * (x1 - x2));
area += ((z1 + z2) * (x1 - x2));
area = Math.ceil(Math.abs(area) / 2);
return (long)(area * getHeight());
}
@@ -148,8 +148,8 @@ public class RegionGroup {
*/
public Set<GeneralRegion> getMemberRegions() {
Set<GeneralRegion> result = new HashSet<>();
for(String name : getMembers()) {
result.add(plugin.getFileManager().getRegion(name));
for(String playerName : getMembers()) {
result.add(plugin.getFileManager().getRegion(playerName));
}
return result;
}
@@ -316,7 +316,7 @@ public class RentRegion extends GeneralRegion {
*/
public double getMoneyBackAmount() {
Long currentTime = Calendar.getInstance().getTimeInMillis();
Double timeLeft = (double)((getRentedUntil() - currentTime));
Double timeLeft = (double)(getRentedUntil() - currentTime);
double percentage = (getMoneyBackPercentage()) / 100.0;
Double timePeriod = (double)(getDuration());
double periods = timeLeft / timePeriod;
@@ -347,10 +347,8 @@ public class RentRegion extends GeneralRegion {
long now = Calendar.getInstance().getTimeInMillis();
if(!isDeleted() && isRented() && now > getRentedUntil()) {
// Extend rent if configured for that
if(getBooleanSetting("rent.autoExtend")) {
if(extend()) {
return false;
}
if(getBooleanSetting("rent.autoExtend") && extend()) {
return false;
}
// Send message to the player if online
@@ -434,200 +432,190 @@ public class RentRegion extends GeneralRegion {
message(offlinePlayer, "general-noEconomy");
return false;
}
//Check if the player has permission
if(plugin.hasPermission(offlinePlayer, "areashop.rent")) {
if(getWorld() == null) {
message(offlinePlayer, "general-noWorld");
// Check if the player has permission
if(!plugin.hasPermission(offlinePlayer, "areashop.rent")) {
message(offlinePlayer, "rent-noPermission");
return false;
}
// Check location restrictions
if(getWorld() == null) {
message(offlinePlayer, "general-noWorld");
return false;
}
if(getRegion() == null) {
message(offlinePlayer, "general-noRegion");
return false;
}
boolean extend = false;
if(getRenter() != null && offlinePlayer.getUniqueId().equals(getRenter())) {
extend = true;
}
// Check if available or extending
if (isRented() && !extend) {
message(offlinePlayer, "rent-someoneElse");
return false;
}
// These checks are only relevant for online players doing the renting/buying themselves
Player player = offlinePlayer.getPlayer();
if(player != null) {
// Check if the players needs to be in the region for renting
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
message(offlinePlayer, "rent-restrictedToRegion");
return false;
}
if(getRegion() == null) {
message(offlinePlayer, "general-noRegion");
// Check if the players needs to be in the world for renting
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
message(offlinePlayer, "rent-restrictedToWorld", player.getWorld().getName());
return false;
}
boolean extend = false;
if(getRenter() != null && offlinePlayer.getUniqueId().equals(getRenter())) {
extend = true;
}
// Check region limits if this is not extending
if(!(extend && config.getBoolean("allowRegionExtendsWhenAboveLimits"))) {
LimitResult limitResult;
if(extend) {
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer, true);
} else {
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer);
}
// Check if the region is available for renting or if the player wants to extend the rent
if(!isRented() || extend) {
// These checks are only relevant for online players doing the renting/buying themselves
Player player = offlinePlayer.getPlayer();
if(player != null) {
// Check if the players needs to be in the region for renting
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
message(offlinePlayer, "rent-restrictedToRegion");
return false;
}
// Check if the players needs to be in the world for renting
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
message(offlinePlayer, "rent-restrictedToWorld", player.getWorld().getName());
return false;
}
AreaShop.debug("LimitResult: " + limitResult.toString());
if(!limitResult.actionAllowed()) {
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
// Check region limits if this is not extending
if(!(extend && config.getBoolean("allowRegionExtendsWhenAboveLimits"))) {
LimitResult limitResult;
if(extend) {
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer, true);
} else {
limitResult = this.limitsAllow(RegionType.RENT, offlinePlayer);
}
AreaShop.debug("LimitResult: " + limitResult.toString());
if(!limitResult.actionAllowed()) {
if(limitResult.getLimitingFactor() == LimitType.TOTAL) {
message(offlinePlayer, "total-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
if(limitResult.getLimitingFactor() == LimitType.RENTS) {
message(offlinePlayer, "rent-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
if(limitResult.getLimitingFactor() == LimitType.EXTEND) {
message(offlinePlayer, "rent-maximumExtend", limitResult.getMaximum(), limitResult.getCurrent() + 1, limitResult.getLimitingGroup());
return false;
}
return false;
}
if(limitResult.getLimitingFactor() == LimitType.RENTS) {
message(offlinePlayer, "rent-maximum", limitResult.getMaximum(), limitResult.getCurrent(), limitResult.getLimitingGroup());
return false;
}
// Check if the player can still extend this rent
if(extend && !plugin.hasPermission(offlinePlayer, "areashop.rentextendbypass")) {
if(getMaxExtends() >= 0 && getTimesExtended() >= getMaxExtends()) {
message(offlinePlayer, "rent-maxExtends");
return false;
}
if(limitResult.getLimitingFactor() == LimitType.EXTEND) {
message(offlinePlayer, "rent-maximumExtend", limitResult.getMaximum(), limitResult.getCurrent() + 1, limitResult.getLimitingGroup());
return false;
}
return false;
}
}
// Check if there is enough time left before hitting maxRentTime
boolean extendToMax = false;
double price = getPrice();
long timeNow = Calendar.getInstance().getTimeInMillis();
long timeRented = 0;
long maxRentTime = getMaxRentTime();
if(isRented()) {
timeRented = getRentedUntil() - timeNow;
}
if((timeRented + getDuration()) > (maxRentTime)
&& !plugin.hasPermission(offlinePlayer, "areashop.renttimebypass")
&& maxRentTime != -1) {
// Extend to the maximum instead of adding a full period
if(getBooleanSetting("rent.extendToFullWhenAboveMaxRentTime")) {
if(timeRented >= maxRentTime) {
message(offlinePlayer, "rent-alreadyAtFull");
return false;
} else {
long toRentPart = maxRentTime - timeRented;
extendToMax = true;
price = ((double)toRentPart) / getDuration() * price;
}
} else {
message(offlinePlayer, "rent-maxRentTime");
return false;
}
}
// Check if the player can still extend this rent
if(extend && !plugin.hasPermission(offlinePlayer, "areashop.rentextendbypass")) {
if(getMaxExtends() >= 0 && getTimesExtended() >= getMaxExtends()) {
message(offlinePlayer, "rent-maxExtends");
return false;
}
}
if(plugin.getEconomy().has(offlinePlayer, getWorldName(), price)) {
// Broadcast and check event
RentingRegionEvent event = new RentingRegionEvent(this, offlinePlayer, extend);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(offlinePlayer, "general-cancelled", event.getReason());
return false;
}
// Substract the money from the players balance
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), price);
if(!r.transactionSuccess()) {
message(offlinePlayer, "rent-payError");
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while renting " + getName() + ": " + r.errorMessage);
return false;
}
// Optionally give money to the landlord
OfflinePlayer landlordPlayer = null;
if(getLandlord() != null) {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), price);
} else {
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), price);
}
if(r == null || !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + Utils.formatCurrency(price) + " for his rent of region " + getName() + " to " + offlinePlayer.getName());
}
}
if(!extend) {
// Run commands
runEventCommands(RegionEvent.RENTED, true);
} else {
// Run commands
runEventCommands(RegionEvent.EXTENDED, true);
}
// Get the time until the region will be rented
Calendar calendar = Calendar.getInstance();
if(extendToMax) {
calendar.setTimeInMillis(calendar.getTimeInMillis() + getMaxRentTime());
} else if(extend) {
calendar.setTimeInMillis(getRentedUntil() + getDuration());
} else {
calendar.setTimeInMillis(calendar.getTimeInMillis() + getDuration());
}
// Add values to the rent and send it to FileManager
setRentedUntil(calendar.getTimeInMillis());
setRenter(offlinePlayer.getUniqueId());
updateLastActiveTime();
// Fire schematic event and updated times extended
if(!extend) {
this.handleSchematicEvent(RegionEvent.RENTED);
setTimesExtended(0);
} else {
setTimesExtended(getTimesExtended() + 1);
}
// Notify about updates
this.notifyAndUpdate(new RentedRegionEvent(this, extend));
// Send message to the player
if(extendToMax) {
message(offlinePlayer, "rent-extendedToMax");
} else if(extend) {
message(offlinePlayer, "rent-extended");
} else {
message(offlinePlayer, "rent-rented");
}
if(!extend) {
// Run commands
this.runEventCommands(RegionEvent.RENTED, false);
} else {
// Run commands
this.runEventCommands(RegionEvent.EXTENDED, false);
}
return true;
// Check if there is enough time left before hitting maxRentTime
boolean extendToMax = false;
double price = getPrice();
long timeNow = Calendar.getInstance().getTimeInMillis();
long timeRented = 0;
long maxRentTime = getMaxRentTime();
if(isRented()) {
timeRented = getRentedUntil() - timeNow;
}
if((timeRented + getDuration()) > (maxRentTime)
&& !plugin.hasPermission(offlinePlayer, "areashop.renttimebypass")
&& maxRentTime != -1) {
// Extend to the maximum instead of adding a full period
if(getBooleanSetting("rent.extendToFullWhenAboveMaxRentTime")) {
if(timeRented >= maxRentTime) {
message(offlinePlayer, "rent-alreadyAtFull");
return false;
} else {
// Player has not enough money
if(extend) {
message(offlinePlayer, "rent-lowMoneyExtend", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
} else {
message(offlinePlayer, "rent-lowMoneyRent", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
}
long toRentPart = maxRentTime - timeRented;
extendToMax = true;
price = ((double)toRentPart) / getDuration() * price;
}
} else {
message(offlinePlayer, "rent-someoneElse");
message(offlinePlayer, "rent-maxRentTime");
return false;
}
} else {
message(offlinePlayer, "rent-noPermission");
}
return false;
// Check if the player has enough money
if(!plugin.getEconomy().has(offlinePlayer, getWorldName(), price)) {
if(extend) {
message(offlinePlayer, "rent-lowMoneyExtend", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
} else {
message(offlinePlayer, "rent-lowMoneyRent", Utils.formatCurrency(plugin.getEconomy().getBalance(offlinePlayer, getWorldName())));
}
return false;
}
// Broadcast and check event
RentingRegionEvent event = new RentingRegionEvent(this, offlinePlayer, extend);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
message(offlinePlayer, "general-cancelled", event.getReason());
return false;
}
// Substract the money from the players balance
EconomyResponse r = plugin.getEconomy().withdrawPlayer(offlinePlayer, getWorldName(), price);
if(!r.transactionSuccess()) {
message(offlinePlayer, "rent-payError");
AreaShop.debug("Something went wrong with getting money from " + offlinePlayer.getName() + " while renting " + getName() + ": " + r.errorMessage);
return false;
}
// Optionally give money to the landlord
OfflinePlayer landlordPlayer = null;
if(getLandlord() != null) {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), price);
} else {
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), price);
}
if(r == null || !r.transactionSuccess()) {
AreaShop.warn("Something went wrong with paying '" + landlordName + "' " + Utils.formatCurrency(price) + " for his rent of region " + getName() + " to " + offlinePlayer.getName());
}
}
// Get the time until the region will be rented
Calendar calendar = Calendar.getInstance();
if(extendToMax) {
calendar.setTimeInMillis(calendar.getTimeInMillis() + getMaxRentTime());
} else if(extend) {
calendar.setTimeInMillis(getRentedUntil() + getDuration());
} else {
calendar.setTimeInMillis(calendar.getTimeInMillis() + getDuration());
}
// Add values to the rent and send it to FileManager
setRentedUntil(calendar.getTimeInMillis());
setRenter(offlinePlayer.getUniqueId());
updateLastActiveTime();
// Fire schematic event and updated times extended
if(!extend) {
this.handleSchematicEvent(RegionEvent.RENTED);
setTimesExtended(0);
} else {
setTimesExtended(getTimesExtended() + 1);
}
// Send message to the player
if(extendToMax) {
message(offlinePlayer, "rent-extendedToMax");
} else if(extend) {
message(offlinePlayer, "rent-extended");
} else {
message(offlinePlayer, "rent-rented");
}
// Notify about updates
this.notifyAndUpdate(new RentedRegionEvent(this, extend));
return true;
}
/**
@@ -662,8 +650,7 @@ public class RentRegion extends GeneralRegion {
return false;
}
// Run commands
this.runEventCommands(RegionEvent.UNRENTED, true);
// Do a payback
double moneyBack = getMoneyBackAmount();
if(moneyBack > 0 && giveMoneyBack) {
boolean noPayBack = false;
@@ -704,12 +691,12 @@ public class RentRegion extends GeneralRegion {
}
}
// Send messages
message(executor, "unrent-unrented");
// Handle schematic save/restore (while %uuid% is still available)
handleSchematicEvent(RegionEvent.UNRENTED);
// Send message: before actual removal of the renter so that it is still available for variables
message(executor, "unrent-unrented");
// Remove friends, the owner and renteduntil values
getFriendsFeature().clearFriends();
UUID oldRenter = getRenter();
@@ -720,9 +707,6 @@ public class RentRegion extends GeneralRegion {
// Notify about updates
this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
// Run commands
this.runEventCommands(RegionEvent.UNRENTED, false);
return true;
}
@@ -737,10 +721,11 @@ public class RentRegion extends GeneralRegion {
return false;
}
long lastPlayed = getLastActiveTime();
final long now = System.currentTimeMillis();
//AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
if(Calendar.getInstance().getTimeInMillis() > (lastPlayed + inactiveSetting)) {
if(now > (lastPlayed + inactiveSetting)) {
AreaShop.info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName());
AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
AreaShop.debug("currentTime=" + now + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (now - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting);
return this.unRent(true, null);
}
return false;
@@ -10,18 +10,14 @@ import java.util.HashMap;
public class Analytics {
private Analytics() {
}
/**
* Start analytics tracking.
*/
public static void start() {
// Legacy MCstats statistics (remove at some point)
try {
new me.wiefferink.areashop.lib.Metrics(AreaShop.getInstance()).start();
AreaShop.debug("Started mcstats.org statistics service");
} catch(Exception e) {
AreaShop.debug("Could not start mcstats.org statistics service");
}
// bStats statistics
try {
Metrics metrics = new Metrics(AreaShop.getInstance());
@@ -49,8 +49,8 @@ public class GithubUpdateCheck {
this.author = author;
this.repository = repository;
this.currentVersion = plugin.getDescription().getVersion();
this.versionComparator = (latestVersion, currentVersion) ->
!latestVersion.equalsIgnoreCase(currentVersion);
this.versionComparator = (latest, current) ->
!latest.equalsIgnoreCase(current);
this.checking = false;
this.error = false;
@@ -0,0 +1,132 @@
package me.wiefferink.areashop.tools;
import me.wiefferink.areashop.AreaShop;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
public class Materials {
private Materials() {
}
private static final HashSet<String> WALL_SIGN_TYPES = new HashSet<>(Arrays.asList(
// 1.14+ types
"ACACIA_WALL_SIGN",
"BIRCH_WALL_SIGN",
"DARK_OAK_WALL_SIGN",
"JUNGLE_WALL_SIGN",
"OAK_WALL_SIGN",
"SPRUCE_WALL_SIGN",
// Legacy types
"LEGACY_WALL_SIGN",
"WALL_SIGN"
));
private static final HashSet<String> FLOOR_SIGN_TYPES = new HashSet<>(Arrays.asList(
// 1.14+ types
"ACACIA_SIGN",
"BIRCH_SIGN",
"DARK_OAK_SIGN",
"JUNGLE_SIGN",
"OAK_SIGN",
"SPRUCE_SIGN",
// Legacy types
"LEGACY_SIGN",
"LEGACY_SIGN_POST",
"SIGN",
"SIGN_POST"
));
private static boolean legacyMaterials = false;
static {
List<String> legacyMaterialVersions = Arrays.asList("1.7", "1.8", "1.9", "1.10", "1.11", "1.12");
for(String legacyMaterialVersion : legacyMaterialVersions) {
String version = Bukkit.getBukkitVersion();
// Detects '1.8', '1.8.3', '1.8-pre1' style versions
if(version.equals(legacyMaterialVersion)
|| version.startsWith(legacyMaterialVersion + ".")
|| version.startsWith(legacyMaterialVersion + "-")) {
legacyMaterials = true;
break;
}
}
}
/**
* Get material based on a sign material name.
* @param name Name of the sign material
* @return null if not a sign, otherwise the material matching the name (when the material is not available on the current minecraft version, it returns the base type)
*/
public static Material signNameToMaterial(String name) {
// Expected null case
if (!isSign(name)) {
return null;
}
Material result = null;
if (legacyMaterials) {
// 1.12 and lower just know SIGN_POST, WALL_SIGN and SIGN
if (FLOOR_SIGN_TYPES.contains(name)) {
result = Material.getMaterial("SIGN_POST");
} else if (WALL_SIGN_TYPES.contains(name)) {
result = Material.getMaterial("WALL_SIGN");
if (result == null) {
result = Material.getMaterial("SIGN");
}
}
} else {
// Try saved name (works for wood types on 1.14, regular types for below)
result = Material.getMaterial(name);
if (result == null) {
// Cases for 1.13, which don't know wood types, but need new materials
if (FLOOR_SIGN_TYPES.contains(name)) {
// SIGN -> OAK_SIGN for 1.14
result = Material.getMaterial("OAK_SIGN");
// Fallback for 1.13
if (result == null) {
result = Material.getMaterial("SIGN");
}
} else if (WALL_SIGN_TYPES.contains(name)) {
// WALL_SIGN -> OAK_WALL_SIGN for 1.14
result = Material.getMaterial("OAK_WALL_SIGN");
// Fallback for 1.13
if (result == null) {
result = Material.getMaterial("WALL_SIGN");
}
}
}
}
if (result == null) {
AreaShop.debug("Materials.get() null result:", name, "legacyMaterials:", legacyMaterials);
}
return result;
}
/**
* Check if a Material is a sign (of either the wall or floor type).
* @param material Material to check
* @return true if the given material is a sign
*/
public static boolean isSign(Material material) {
return isSign(material.name());
}
/**
* Check if a Material is a sign (of either the wall or floor type).
* @param name String to check
* @return true if the given material is a sign
*/
public static boolean isSign(String name) {
return name != null && (FLOOR_SIGN_TYPES.contains(name) || WALL_SIGN_TYPES.contains(name));
}
}
File diff suppressed because it is too large. Load diff
@@ -2,29 +2,29 @@ package me.wiefferink.areashop.tools;
public class Value<T> {
private T value;
private T content;
/**
* Create a container with a default value.
* @param value The value to set
* Create a container with a default content.
* @param content The content to set
*/
public Value(T value) {
this.value = value;
public Value(T content) {
this.content = content;
}
/**
* Get the stored value.
* @return The stored value
* Get the stored content.
* @return The stored content
*/
public T get() {
return value;
return content;
}
/**
* Set the value.
* @param value The new value
* Set the content.
* @param value The new content
*/
public void set(T value) {
this.value = value;
this.content = value;
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ general:
# The y location within the region to start searching for safe teleport locations (x and z are in the middle of the region).
# Possible values: 'bottom', 'middle', 'top' or a number indicating an exact y coordinate.
teleportLocationY: bottom
# If true the teleportation algorithm only allows telportation to inside the region, otherwise it will expand
# If true the teleportation algorithm only allows teleportation to inside the region, otherwise it will expand
# a cube from the starting point to check for safe spots (then it could end outside of the region).
teleportIntoRegion: true
# Same as above, but then for when you teleport to the sign of a region instead of the region itself.
+5
View File
@@ -343,6 +343,7 @@ destroy-successRent: "%lang:region% successfully deregistered as rental region."
destroy-successBuy: "%lang:region% successfully deregistered as buy region."
teleport-help: "/as tp <region> [sign]."
teleport-calculation-progress: "Teleport in progress, finding safe location %done%/%max% scans complete."
teleport-noRentOrBuy: "The specified region is not registered: %0%."
teleport-noPermission: "You don't have permission to teleport to your region."
teleport-noPermissionOther: "You don't have permission to teleport to regions you do not own."
@@ -414,6 +415,9 @@ add-success: "Added as %0%: [gray]%1%."
add-failed: "Already registered: [gray]%0%."
add-failedOtherWorld: "Already registered from another world: [gray]%0%."
add-blacklisted: "On the blacklist: [gray]%0%."
add-rentCancelled: "Rent cancelled: [gray]%0%."
add-buyCancelled: "Buy cancelled: [gray]%0%."
add-addCancelled: "Add cancelled: [gray]%0%."
add-specifyWorld: "Specify the world of the region when using from console."
add-incorrectWorld: "World '%0%' not found, try again (case-sensitive)."
add-noPermissionRegions: "No permission to add: [gray]%0%."
@@ -422,6 +426,7 @@ add-noPermissionOwnerMember: "[gray]You either are not a member/owner of these r
del-noPermission: "You don't have permission to remove regions."
del-success: "Removed regions: [gray]%0%."
del-failed: "No permission to remove or not registered: [gray]%0%."
del-cancelled: "Delete cancelled: [gray]%0%."
addsign-help: "/as addsign [region] [profile]."
addsign-noSign: "You are not looking at a sign."
+3 -1
View File
@@ -1,6 +1,6 @@
# ╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
# ║ Language file of the AreaShop plugin created by NLThijs48, Github can be found at https://github.com/NLthijs48/AreaShop
# ║ Spanish language file, plugin version 2.5.0, 424/428 messages are translated (99%)
# ║ Spanish language file, plugin version 2.5.0, 426/428 messages are translated (100%)
# ║
# ║ This file will be overwritten at each startup/reload of the plugin, if you want to change anything then do the following:
# ║ 1: Make a copy of this file
@@ -138,6 +138,7 @@
"sell-sold": "La región %lang:region%, de %lang:player%, ha sido vendida."
"sell-noPermission": "No tienes permiso para vender regiones."
"sell-noPermissionOther": "No tienes permiso para vender regiones ajenas."
"sell-disabled": "La venta fue desactivada para esta región."
"reload-reloading": "Todos los archivos han sido recargados, comprobando alquileres y actualizando regiones..."
"reload-noPermission": "No tienes permiso para recargar los archivos de configuración."
"reload-updateCommandChanged": "Los comandos '/as updaterents' y '/as updatebuys' han sido borrados, '/as reload' actualizará las regiones. Puedes usar este comando en vez de los 2 primeros."
@@ -432,6 +433,7 @@
"resell-success": "%lang:region% está en modo reventa por %resellprice%."
"resell-noPermission": "No tienes permiso para cambiar tu región a modo reventa."
"resell-noPermissionOther": "No tienes permiso para cambiar las regiones a modo reventa."
"resell-disabled": "La reventa fue deshabilitada para esta región."
"stopresell-help": "/as stopresell [región], la región en la que estás se usará si no se especifican nombres."
"stopresell-notRegistered": "La región especificada no es válida: %0%."
"stopresell-notResell": "No puedes parar la reventa de %lang:region% porque no está en modo reventa."
+33 -1
View File
@@ -1,6 +1,6 @@
# ╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
# ║ Language file of the AreaShop plugin created by NLThijs48, Github can be found at https://github.com/NLthijs48/AreaShop
# ║ French language file, plugin version 2.5.0, 399/428 messages are translated (93%)
# ║ French language file, plugin version 2.5.0, 428/428 messages are translated (100%)
# ║
# ║ This file will be overwritten at each startup/reload of the plugin, if you want to change anything then do the following:
# ║ 1: Make a copy of this file
@@ -178,6 +178,10 @@
"info-pageNoPrevious":
- " [darkgray][bold]◄Précédent[/bold] "
- " hover: C'est déjà la premier page"
"info-pageNext":
- "[gold][bold]Suivant►[/bold]"
- "hover: %lang:action|Page suivante|%"
- "commande: /areashop "
"info-pageNoNext":
- " [darkgray][bold]Suivaznt►[/bold]"
- " hover: C'est déjà la dernière page"
@@ -290,6 +294,7 @@
"setduration-successRemoved": "La durée de location de %lang:region% a été supprimé, maintenant celle-ci utilisera le durée de location du group ou du fichier default.yml, nouvelle durée de location : %duration%."
"setup-noRegion": "Vous n'avez pas spécifié de région à la seconde ligne."
"setup-alreadyRentSign": "La région que vous avez spécifiée a déjà été ajoutée à AreaShop en tant qu'une région louable, ajoutez un panneau avec [as] sur le première ligne ou tapez '/as addsign'."
"setup-alreadyOtherWorld": "La région que vous avez spécifiée est déjà ajoutée à AreaShop dans un autre monde. Les régions de différents mondes ont toujours besoin de noms différents."
"setup-alreadyBuySign": "La région que vous avez spécifiée a déjà été ajoutée à AreaShop en tant qu'une région achetable, ajoutez un panneau avec [as] sur le première ligne ou tapez '/as addsign'."
"setup-noDuration": "A la troisième ligne, vous n'avez pas spécifié la durée de location de la région."
"setup-wrongDuration": "Le temps spécifié n'est pas au bon format. Exemple : 1 day."
@@ -368,6 +373,7 @@
"add-noPermission": "Vous n'avez pas la permission d'ajouter une région à AreaShop."
"add-success": "Ajoutée comme %0% : [gray]%1%."
"add-failed": "Déjà enregistré: [gray]%0%."
"add-failedOtherWorld": "Déjà inscrit d'un autre monde: [gray]%0%."
"add-blacklisted": "Dans la liste noir: [gray]%0%."
"add-specifyWorld": "Spécifiez le monde de la région lors de l'utilisation de la console."
"add-incorrectWorld": "Le monde '%0%' est introuvable, essayez de nouveau (attention à la casse)."
@@ -379,6 +385,7 @@
"addsign-help": "/as addsign [region] [profile]"
"addsign-noSign": "Vous ne regardez pas de panneau."
"addsign-noRegions": "Aucune région trouvée autour du panneau."
"addSign-notRegistered": "La région spécifiée n'est pas enregistrée dans AreaShop: %0% (elle doit d'abord être ajoutée à AreaShop avant qu'un signe puisse être ajouté)."
"addsign-couldNotDetect": "Plusieurs régions ont été trouvées à proximité du panneau. Spécifiez la région en argument supplémentaire (2 des régions trouvées: %lang:tRegion|%0%|% et %lang:tRegion|%1%|%)."
"addsign-couldNotDetectSign": "Plusieurs régions ont été trouvées à proximité du panneau. Spécifiez la région à la deuxième ligne (2 des régions trouvées: %lang:tRegion|%0%|% et %lang:tRegion|%1%|%)."
"addsign-wrongProfile": "Le profil spécifié n'existe pas, utilisez l'un de la liste suivante (Vérifiez la config): [gray]%0%."
@@ -428,6 +435,7 @@
"resell-success": "%lang:region% a été mise en revente avec succès pour un prix de %resellprice%."
"resell-noPermission": "Vous n'avez pas la permission de mettre votre région en revente."
"resell-noPermissionOther": "Vous n'avez pas la permission de mettre des régions en revente."
"resell-disabled": "La revente a été désactivée pour cette région."
"stopresell-help": "/as stropresell [région], la région où vous vous trouvez sera utilisée si vous ne spécifiez pas de région."
"stopresell-notRegistered": "La région spécifiée n'est pas enregistrée : %0%."
"stopresell-notResell": "Vous ne pouvez pas stopper la revente %lang:region% car elle n'est pas en mode revente."
@@ -486,6 +494,30 @@
"message-help": "/as message <joueur> <message...>"
"message-noPermission": "Vous n'avez pas la permission d'envoyer des messages AreaShop."
"message-notOnline": "%0% n'est pas connecté."
"import-help": "/as import RegionAVendre"
"import-wrongSource": "Spécifiez d'où vous voulez importer les données, les options: RegionAVendre"
"import-noPluginFolder": "Impossible de trouver le dossier %0%, êtes-vous sûr que vous importez de la bonne source?"
"import-noWorldsFolder": "Il n'y a pas de dossier 'plugins/RegionForSale/worlds' donc rien ne peut être importé."
"import-confirm": "Êtes-vous sûr de vouloir importer toutes les régions de RegionAVendre?"
"import-start": "Début de l'importation des données RegionAVendre :"
"import-doWorld": "[darkgreen][bold]► Monde %0% :"
"import-noBukkitWorld": "[red]Impossible de trouver le monde dans Bukkit."
"import-noRegionManager": "[red]Impossible d’obtenir RegionManager de WorldGuard, les régions sont-elles activées dans ce monde?"
"import-noRegions": "[red]Pas de fichier regions.yml trouvé."
"import-loadRegionsFailed": "[red]Impossible de charger regions.yml de : %0%"
"import-invalidRegionSection": "[red]Mauvaise section dans regions.yml : %0%."
"import-noWorldGuardRegion": "[red]La région de WorldGuard n'a pas été trouvée :%0%."
"import-noWorldGuardRegionParent": "[red]La région de WorldGuard pour la région parent n'a pas été trouvé : %0%"
"import-buyAndRent": "[gold] %0% peuvent être achetés et loués, seulement en ajoutant comme achat dans AreaShop (ne peuvent pas être les deux)."
"import-noBuyAndNoRent": "[red]%0% ne peut pas être acheté ni être loué sans importer."
"import-imported": "[green]%lang:tRegion|%0% importé."
"import-loadWorldConfigFailed": "[red} Chargement de world-specific config.yml échoué : %0%."
"import-improperParentRegion": "[red]Region parent %0% n'a pas de réglages lisible."
"import-alreadyAdded": "[red]Region '%0%' a déjà été ajoutée."
"import-alreadyAddedOtherWorld": "[red]Region '%0%' a déjà été ajoutée dans le monde %1%, les régions de différents mondes ne peuvent pas avoir le même nom dans AreaShop."
"import-invalidSignLocation": "[red]Echec d'importation de la pancarte de la région '%0%', location invalide '%1%'."
"import-signAlreadyAdded": "[red] Ignoré l'ajout de la pancarte à la location '%1%' de la région '%0%', il est déjà ajouté à la région '%2%'."
"import-moneyBackFailed": "[red] Échec de l'analyse du prix d'achat '%0%' et du prix de vente '%1%' pour définir le pourcentage de remboursement."
"confirm-rent":
- "%lang:prefix%Êtes-vous sur de vouloir louer %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Cliquez ici pour louer %0%|%"
+9 -1
View File
@@ -1,6 +1,6 @@
# ╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
# ║ Language file of the AreaShop plugin created by NLThijs48, Github can be found at https://github.com/NLthijs48/AreaShop
# ║ Russian language file, plugin version 2.5.0, 395/428 messages are translated (92%)
# ║ Russian language file, plugin version 2.5.0, 403/428 messages are translated (94%)
# ║
# ║ This file will be overwritten at each startup/reload of the plugin, if you want to change anything then do the following:
# ║ 1: Make a copy of this file
@@ -136,6 +136,7 @@
"sell-sold": "%lang:region% был продан %lang:player%."
"sell-noPermission": "У Вас нет прав для продажи региона."
"sell-noPermissionOther": "У Вас нет прав для продажи другого региона."
"sell-disabled": "Продажа была отключена для этого региона"
"reload-reloading": "Перезагружены все конфигурации и файлы регионов."
"reload-noPermission": "Недостаточно полномочий для того, чтобы перезагрузить конфиги плагина."
"reload-updateCommandChanged": "'/as updaterents' и '/as updatebuys' были удалены, '/as reload' теперь будет также обновлять регионы, используйте взамен эту команду."
@@ -283,6 +284,7 @@
"setduration-successRemoved": "Длительность аренды в %lang:region% было удалено, использование новой длительности аренды из группы или файла default.yml, новая длительность: %duration%."
"setup-noRegion": "Вы не указали регион на второй строке."
"setup-alreadyRentSign": "Регион уже добавлен в AreaShop в виде аренды региона, добавьте табличку с [as] на первой строке, или '/as addsign'."
"setup-alreadyOtherWorld": "Регион который ты выбрал уже добавлен в AreaShop в другом мире, регионы из разных миров должы иметь разные названия"
"setup-alreadyBuySign": "Регион уже добавлен в AreaShop в виде покупного региона, добавьте табличку с [as] на первой строке, или '/as addsign'."
"setup-noDuration": "Вы не указали, на сколько времени этот регион можно арендовать, сделайте это на третьей строчке."
"setup-wrongDuration": "Время указано не в правильном формате, например: 1 day."
@@ -361,6 +363,7 @@
"add-noPermission": "У вас нет разрешения добавлять регионы в AreaShop."
"add-success": "Добавлен в %0%: [gray]%1%."
"add-failed": "Уже зарегистрирован: [gray]%0%."
"add-failedOtherWorld": "Уже зарегистрирован в другом мире: [gray]"
"add-blacklisted": "Включен в черный список : [gray]%0%."
"add-specifyWorld": "Укажите мир региона при использовании из консоли."
"add-incorrectWorld": "Мир '%0%' не найден, попробуйте еще раз (с учетом регистра)."
@@ -372,6 +375,7 @@
"addsign-help": "/as addsign [регион] [профиль]."
"addsign-noSign": "Вы не смотрите на табличку."
"addsign-noRegions": "Не найдено регионов вокруг таблички."
"addSign-notRegistered": "Данный регион не зарегистрирован в AreaShop%0% (сначало нужно добавить регион в AreaShop прежде чем создавать табичку)"
"addsign-couldNotDetect": "Найдено несколько регионов вокруг таблички, укажите регион в качестве дополнительного аргумента (2 из регионов, которые были найдены: %lang:tRegion|%0%|% и %lang:tRegion|%1%|%)."
"addsign-couldNotDetectSign": "Найдено несколько регионов вокруг таблички, укажите регион на второй строке (2 из регионов, которые были найдены: %lang:tRegion|%0%|% и %lang:tRegion|%1%|%)."
"addsign-wrongProfile": "Указанный профиль не существует, используйте одно из следующих действий (проверьте конфиг.): [gray]%0%."
@@ -421,6 +425,7 @@
"resell-success": "%lang:region% был успешно выставлен в режим перепродажи за %resellprice%."
"resell-noPermission": "У Вас нет прав что бы установить ваш регион в режим перепродажи."
"resell-noPermissionOther": "У Вас нет прав что бы установить регион в режим перепродажи."
"resell-disabled": "Перепродажа была отключенна для этого региона"
"stopresell-help": "/as stopresell [имярегиона], если не указано имя, будет выбран регион в котором вы находитесь."
"stopresell-notRegistered": "Указанный регион не зарегистрирован: %0%."
"stopresell-notResell": "Вы не можете остановить перепродажу %lang:region% потому что регион не в режиме перепродажи."
@@ -479,6 +484,9 @@
"message-help": "/as message <игрок> <сообщение...>"
"message-noPermission": "У вас нет разрешения на отправку AreaShop сообщений."
"message-notOnline": "%0% не в сети."
"import-help": "/as import RegionForSale"
"import-confirm": "Вы действительно хотите импортировать все регионы из RegionForSale?"
"import-noWorldGuardRegion": "[red]WorldGuard регион не найден:"
"confirm-rent":
- "%lang:prefix%Вы уверены, что вы хотите арендовать %lang:tRegion|%0%|%?[break]"
- "[darkgreen][bold]►[reset] %lang:button|Нажмите, чтобы арендовать %0%|%"
+3 -2
View File
@@ -1,9 +1,9 @@
name: AreaShop
main: me.wiefferink.areashop.AreaShop
version: "${project.version}${build.number}"
version: "${project.version}"
description: "Selling and renting WorldGuard regions to your players, highly configurable."
depend: [Vault, WorldGuard, WorldEdit]
softdepend: [Multiverse-Core]
softdepend: [Multiverse-Core, FastAsyncWorldEdit]
author: NLThijs48
website: https://github.com/NLthijs48/AreaShop
commands:
@@ -13,6 +13,7 @@ commands:
aliases: [as]
awareness:
- !@UTF8
api-version: 1.13
permissions:
areashop.*:
description: Give access to all commands of AreaShop
-1
View File
@@ -1 +0,0 @@
/target
@@ -1,22 +0,0 @@
package me.wiefferink.areashop.interfaces;
import org.bukkit.entity.Player;
import java.io.File;
public abstract class WorldEditInterface {
protected final AreaShopInterface pluginInterface;
public WorldEditInterface(AreaShopInterface pluginInterface) {
this.pluginInterface = pluginInterface;
}
// Different way to restore blocks per implementation, newer ones support entities as well
public abstract boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface);
// Different way to save blocks per implementation, newer ones support entities as well
public abstract boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface);
public abstract WorldEditSelection getPlayerSelection(Player player);
}
+7 -7
View File
@@ -17,7 +17,7 @@
[►Request a feature, report a bug or ask support](https://github.com/NLthijs48/AreaShop/issues/new/choose)&nbsp;&nbsp;
[►Open issues](https://github.com/NLthijs48/AreaShop/issues)<br/>
**Development:**
[►Changelog](https://github.com/NLthijs48/AreaShop/wiki/Changelog)&nbsp;&nbsp;
[►Changelog](https://github.com/NLthijs48/AreaShop/blob/master/changelog.md)&nbsp;&nbsp;
[►Compiling](https://github.com/NLthijs48/AreaShop/wiki/Compiling-AreaShop)&nbsp;&nbsp;
[►Modules/classes overview](https://github.com/NLthijs48/AreaShop/wiki/Modules,-packages-and-classes-overview)
[►Javadocs](https://wiefferink.me/AreaShop/javadocs/)
@@ -64,11 +64,11 @@ For a preview join 'mc.go-craft.com' and go to the Survival server, the shops ar
Old video for AreaShop v1.0: [Tutorial by VariationVault](https://www.youtube.com/watch?v=k2HMCxCCOYo)
### Required dependencies
* Java 7 or higher (latest recommended)
* Bukkit/Spigot 1.7.9 or higher (modded servers often include Bukkit/Spigot support, so it should also work on that, but it is not specifically tested for it)
* [WorldGuard](http://dev.bukkit.org/bukkit-plugins/worldguard/): 5.9 or higher (6.0+ recommended)
* [WorldEdit](http://dev.bukkit.org/bukkit-plugins/worldedit/): 5.6.3 or higher (6.0+ recommended)
* [Vault](http://dev.bukkit.org/bukkit-plugins/vault/): 1.4.1 or higher
* Java 8 or higher (latest recommended)
* Bukkit/Spigot 1.13.2 or higher (modded servers often include Bukkit/Spigot support, so it should also work on that, but it is not specifically tested for it)
* [WorldGuard](http://dev.bukkit.org/bukkit-plugins/worldguard/): 7.0.3 or higher
* [WorldEdit](http://dev.bukkit.org/bukkit-plugins/worldedit/): 7.0.1 or higher
* [Vault](http://dev.bukkit.org/bukkit-plugins/vault/): 1.7 or higher
* An economy plugin supported by Vault (check the [Vault page](http://dev.bukkit.org/bukkit-plugins/vault/) for a list of these)
### Metrics
@@ -83,6 +83,6 @@ Help translating the plugin into different languages and to keep the translation
![Transifex-translation-progress](https://transifex.com/projects/p/areashop/resource/enyml/chart/image_png)
[![Discord-support-chat](https://user-images.githubusercontent.com/6951068/47256403-31ba5e80-d480-11e8-8ca7-d788a7e7ee29.png)](https://discord.gg/84kGMCQ)
[![Discord-support-chat](https://discordapp.com/api/v6/guilds/342592311122853893/widget.png?style=banner3)](https://discord.gg/84kGMCQ)
[![Donate through PayPal to support development](https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VEECV88NG3L5C)
-1
View File
@@ -1 +0,0 @@
/target
-44
View File
@@ -1,44 +0,0 @@
<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>
<artifactId>areashop-worldedit-5</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldEdit 5</name>
<version>WorldEdit-5</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.7-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
</dependencies>
</project>
@@ -1,108 +0,0 @@
package me.wiefferink.areashop.handlers;
import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.schematic.SchematicFormat;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
public class WorldEditHandler5 extends WorldEditInterface {
public WorldEditHandler5(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public WorldEditSelection getPlayerSelection(Player player) {
Selection selection = pluginInterface.getWorldEdit().getSelection(player);
if (selection == null) {
return null;
}
return new WorldEditSelection(
player.getWorld(),
selection.getMinimumPoint(),
selection.getMaximumPoint()
);
}
@Override
public boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface) {
file = new File(file.getAbsolutePath() + ".schematic");
if(!file.exists() || !file.isFile()) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", schematic file does not exist: " + file.getAbsolutePath());
return false;
}
boolean result = true;
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
// Get the origin and size of the region
Vector origin = new Vector(regionInterface.getRegion().getMinimumPoint().getBlockX(), regionInterface.getRegion().getMinimumPoint().getBlockY(), regionInterface.getRegion().getMinimumPoint().getBlockZ());
editSession.enableQueue();
Exception otherException = null;
try {
CuboidClipboard clipBoard = SchematicFormat.MCEDIT.load(file);
if(clipBoard.getHeight() != regionInterface.getHeight()
|| clipBoard.getWidth() != regionInterface.getWidth()
|| clipBoard.getLength() != regionInterface.getDepth()) {
pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
pluginInterface.debugI("schematic|region, x:" + clipBoard.getWidth() + "|" + regionInterface.getWidth() + ", y:" + clipBoard.getHeight() + "|" + regionInterface.getHeight() + ", z:" + clipBoard.getLength() + "|" + regionInterface.getDepth());
}
clipBoard.place(editSession, origin, false);
} catch(MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("exceeded the block limit while restoring schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
result = false;
} catch(DataException | IOException e) {
otherException = e;
}
if(otherException != null) {
pluginInterface.getLogger().warning("Failed to restore schematic for region " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
result = false;
}
editSession.flushQueue();
return result;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
file = new File(file.getAbsolutePath() + ".schematic");
boolean result = true;
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
Vector size = (new Vector(region.getMaximumPoint().getBlockX(), region.getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockZ()).subtract(origin)).add(new Vector(1, 1, 1));
EditSession editSession = new EditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
// Save the schematic
editSession.enableQueue();
CuboidClipboard clipboard = new CuboidClipboard(size, origin);
clipboard.copy(editSession);
Exception otherException = null;
try {
SchematicFormat.MCEDIT.save(clipboard, file);
} catch(DataException | IOException e) {
otherException = e;
}
if(otherException != null) {
pluginInterface.getLogger().warning("Failed to save schematic for region " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
result = false;
}
editSession.flushQueue();
return result;
}
}
-1
View File
@@ -1 +0,0 @@
/target
-44
View File
@@ -1,44 +0,0 @@
<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>
<artifactId>areashop-worldedit-6</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldEdit 6</name>
<version>WorldEdit-6</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
</dependencies>
</project>
@@ -1,191 +0,0 @@
package me.wiefferink.areashop.handlers;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.io.Closer;
import com.sk89q.worldedit.world.registry.WorldData;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionType;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.entity.Player;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class WorldEditHandler6 extends WorldEditInterface {
public WorldEditHandler6(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public WorldEditSelection getPlayerSelection(Player player) {
Selection selection = pluginInterface.getWorldEdit().getSelection(player);
if (selection == null) {
return null;
}
return new WorldEditSelection(
player.getWorld(),
selection.getMinimumPoint(),
selection.getMaximumPoint()
);
}
@Override
public boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface) {
file = new File(file.getAbsolutePath() + ".schematic");
if(!file.exists() || !file.isFile()) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", schematic file does not exist: " + file.getAbsolutePath());
return false;
}
com.sk89q.worldedit.world.World world = null;
if(regionInterface.getName() != null) {
world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
}
if(world == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
return false;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
editSession.enableQueue();
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
// Read the schematic and paste it into the world
try(Closer closer = Closer.create()) {
FileInputStream fis = closer.register(new FileInputStream(file));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(bis);
WorldData worldData = world.getWorldData();
LocalSession session = new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
Clipboard clipboard = reader.read(worldData);
if(clipboard.getDimensions().getY() != regionInterface.getHeight()
|| clipboard.getDimensions().getX() != regionInterface.getWidth()
|| clipboard.getDimensions().getZ() != regionInterface.getDepth()) {
pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
pluginInterface.debugI("schematic|region, x:" + clipboard.getDimensions().getX() + "|" + regionInterface.getWidth() + ", y:" + clipboard.getDimensions().getY() + "|" + regionInterface.getHeight() + ", z:" + clipboard.getDimensions().getZ() + "|" + regionInterface.getDepth());
}
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, worldData);
session.setBlockChangeLimit(pluginInterface.getConfig().getInt("maximumBlocks"));
session.setClipboard(clipboardHolder);
// Build operation
BlockTransformExtent extent = new BlockTransformExtent(clipboardHolder.getClipboard(), clipboardHolder.getTransform(), editSession.getWorld().getWorldData().getBlockRegistry());
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), editSession, origin);
copy.setRemovingEntities(true);
copy.setTransform(clipboardHolder.getTransform());
// Mask to region (for polygon and other weird shaped regions)
// TODO make this more efficient (especially for polygon regions)
if(region.getType() != RegionType.CUBOID) {
copy.setSourceMask(new Mask() {
@Override
public boolean test(Vector vector) {
return region.contains(vector);
}
@Override
public Mask2D toMask2D() {
return null;
}
});
}
Operations.completeLegacy(copy);
} catch(MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("exceeded the block limit while restoring schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
} catch(IOException e) {
pluginInterface.getLogger().warning("An error occured while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
editSession.flushQueue();
return true;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
file = new File(file.getAbsolutePath() + ".schematic");
com.sk89q.worldedit.world.World world = null;
if(regionInterface.getWorld() != null) {
world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
}
if(world == null) {
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
return false;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
// Create a clipboard
CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
clipboard.setOrigin(regionInterface.getRegion().getMinimumPoint());
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint()), clipboard, regionInterface.getRegion().getMinimumPoint());
try {
Operations.completeLegacy(copy);
} catch(MaxChangedBlocksException e) {
pluginInterface.getLogger().warning("exceeded the block limit while saving schematic of " + regionInterface.getName() + ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: " + pluginInterface.getConfig().getInt("maximumBlocks"));
return false;
}
try(Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(file));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(ClipboardFormat.SCHEMATIC.getWriter(bos));
writer.write(clipboard, world.getWorldData());
} catch(IOException e) {
pluginInterface.getLogger().warning("An error occured while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
return true;
}
}
-1
View File
@@ -1 +0,0 @@
/target
-1
View File
@@ -1 +0,0 @@
/target
-37
View File
@@ -1,37 +0,0 @@
<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>
<artifactId>areashop-worldguard-5</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldGuard 5</name>
<version>WorldGuard-5</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>5.9.1-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
</dependencies>
</project>
@@ -1,141 +0,0 @@
package me.wiefferink.areashop.handlers;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.RegionAccessSet;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class WorldGuardHandler5 extends WorldGuardInterface {
public WorldGuardHandler5(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public RegionManager getRegionManager(World world) {
return WorldGuardPlugin.inst().getRegionManager(world);
}
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
Set<ProtectedRegion> result = new HashSet<>();
Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
for(ProtectedRegion region : pluginInterface.getWorldGuard().getRegionManager(location.getWorld()).getRegions().values()) {
if(region.contains(vector)) {
result.add(region);
}
}
return result;
}
@Override
public void setOwners(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getOwners().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setOwners(defaultDomain);
}
}
@Override
public void setMembers(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getMembers().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setMembers(defaultDomain);
}
}
@Override
public RegionAccessSet getMembers(ProtectedRegion region) {
RegionAccessSet result = new RegionAccessSet();
result.getGroupNames().addAll(region.getMembers().getGroups());
result.getPlayerNames().addAll(region.getMembers().getPlayers());
return result;
}
@Override
public RegionAccessSet getOwners(ProtectedRegion region) {
RegionAccessSet result = new RegionAccessSet();
result.getGroupNames().addAll(region.getOwners().getGroups());
result.getPlayerNames().addAll(region.getOwners().getPlayers());
return result;
}
/**
* Build a DefaultDomain from a RegionAccessSet.
* @param regionAccessSet RegionAccessSet to read
* @return DefaultDomain containing the entities from the RegionAccessSet
*/
private DefaultDomain buildDomain(RegionAccessSet regionAccessSet) {
DefaultDomain owners = new DefaultDomain();
for(String playerName : regionAccessSet.getPlayerNames()) {
owners.addPlayer(playerName);
}
// Add by name since UUIDs were not yet supported
for(UUID uuid : regionAccessSet.getPlayerUniqueIds()) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if(offlinePlayer != null && offlinePlayer.getName() != null) {
owners.addPlayer(offlinePlayer.getName());
}
}
for(String group : regionAccessSet.getGroupNames()) {
owners.addGroup(group);
}
return owners;
}
@Override
public boolean containsMember(ProtectedRegion region, UUID player) {
if(player == null) {
return false;
} else {
String name = Bukkit.getOfflinePlayer(player).getName();
return name != null && region.getMembers().contains(name);
}
}
@Override
public boolean containsOwner(ProtectedRegion region, UUID player) {
if(player == null) {
return false;
} else {
String name = Bukkit.getOfflinePlayer(player).getName();
return name != null && region.getOwners().contains(name);
}
}
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
return DefaultFlag.fuzzyMatchFlag(flagName);
}
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
return flag.parseInput(WorldGuardPlugin.inst(), null, input);
}
@Override
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
return flag.parseInput(WorldGuardPlugin.inst(), null, input);
}
}
-1
View File
@@ -1 +0,0 @@
/target
-37
View File
@@ -1,37 +0,0 @@
<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>
<artifactId>areashop-worldguard-6</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldGuard 6</name>
<version>WorldGuard-6</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
</dependencies>
</project>
-1
View File
@@ -1 +0,0 @@
/target
@@ -1,32 +0,0 @@
package me.wiefferink.areashop.handlers;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
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 com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
public class WorldGuardHandler6_1_3 extends WorldGuardHandler6 {
public WorldGuardHandler6_1_3(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
return DefaultFlag.fuzzyMatchFlag(WorldGuardPlugin.inst().getFlagRegistry(), flagName);
}
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
return flag.parseInput(FlagContext.create().setInput(input).build());
}
@Override
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
return flag.parseInput(FlagContext.create().setInput(input).build());
}
}
-1
View File
@@ -1 +0,0 @@
/target
-58
View File
@@ -1,58 +0,0 @@
<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>
<artifactId>areashop-worldguard-7</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldGuard 7</name>
<version>WorldGuard-7</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<scope>system</scope>
<version>any</version>
<systemPath>${project.basedir}/../dependencies/worldedit-bukkit-7.0.0-beta-01.jar</systemPath>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-6</artifactId>
<version>WorldGuard-6</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-6_1_3</artifactId>
<version>WorldGuard-6_1_3</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<scope>system</scope>
<version>any</version>
<systemPath>${project.basedir}/../dependencies/worldguard-legacy-7.0.0-beta01.jar</systemPath>
</dependency>
</dependencies>
</project>
@@ -1,40 +0,0 @@
package me.wiefferink.areashop.handlers;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import org.bukkit.World;
public class WorldGuardHandler7 extends WorldGuardHandler6_1_3 {
public WorldGuardHandler7(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public RegionManager getRegionManager(World world) {
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
}
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
return flag.parseInput(FlagContext.create().setInput(input).build());
}
@Override
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
return flag.parseInput(FlagContext.create().setInput(input).build());
}
}
+426
View File
@@ -0,0 +1,426 @@
## AreaShop NEXT
[**Planned features**](https://github.com/NLthijs48/AreaShop/milestone/5)
## AreaShop 2.6.0
**Features:**
* Add 1.13 FastAsyncWorldEdit support (note: FastAsyncWorldEdit does seem to work correctly for 1.13.0, but not yet on 1.13.2)
* Add support for the latest WorldEdit/WorldGuard 7 versions (which have refactored the vector classes)
* Improve adding back signs after they have been removed by players or schematic restore
* Improve performance of the BlockPhysicsEvent (allow signs to get removed to prevent loops, while not dropping an item)
* Updated all translations, pulled from Transifex
**Fixed:**
* Fixed `/as setduration` tab completion
* Fixed 1.13 Material handling, especially dealing with signs and the checks by the safe teleport function
* `/as add`: properly set the landlord when the player is an owner of the region (it was only working for members)
**Technical:**
* Change Maven dependencies to use `.jar` files in the `dependencies/` folder to ensure the build keeps working even though maven repositories have disappeared
## AreaShop 2.5.0
**Features:**
* Minecraft 1.13 and 1.13.1 support.
* WorldGuard 7 support.
* WorldEdit 7 support.
* Update all translations (pulled from Transifex).
* Add import for RegionForSale regions:
* `/as import RegionForSale`
* Imports all regions from RegionForSale
* Converts almost all settings to their AreaShop equivalent
* Handles parent regions
* Add setting to automatically extends a rent when the time is up: `rent.autoExtend` in `default.yml`.
* Added options to disable players selling/reselling regions: `buy.sellDisabled`, `buy.resellDisabled`.
* Add setting to disable cross-world teleports for the `/as tp` command: `teleportCrossWorld` in the `general` section of `default.yml`.
* Add setting to disable cross-world teleports for the `/as find` command: `findCrossWorld` in the `general` section of `default.yml`.
* Allow `price` and `moneyBack` values to be calculated dynamically:
* All region variables can be used: `price: "5*%volume%"` would be `$5` per cubic meter (block in the region).
* Full JavaScript expressions and code can be used, the last statement will be the resulting price.
* Add `%volume%` variable for the number of blocks in a region, which supports polygon regions correctly.
* `/as stack` now allows the usage of `#` to choose the position of the number in the region name.
* Add customizable metric suffixes, now you can decide when to shorten a number and how, see `metricSymbols` in `config.yml`.
* Add support for automatically adding all AreaShop regions of a certain world to a RegionGroup
**Technical:**
* BREAKING: `BuyingRegionEvent`, `RentingRegionEvent` and `ResellingRegionEvent` now use `OfflinePlayer` instead of `Player`, because renting/buying/reselling is now also possible while the player is offline.
* Improved file loading mechanics
* Improve sign update performance, AreaShop will never load chunks anymore, and will simply update signs when players load chunks.
* Moved the messaging library to its own project: [InteractiveMessenger](https://github.com/NLthijs48/InteractiveMessenger)
* Added a lot of automated tests to ensure all functionality keeps working
* Fixed bugs with formatting codes, line endings and hover messages
* All user input that is inserted into messages is now escaped properly (using variables does not break the message anyore)
* Add [bStats.org](https://bstats.org/plugin/bukkit/AreaShop) analytics. Since mcstats.org is really unstable and offline half of the time I added bStats (which tracks the same information, plus the number of regions and their state), MCStats tracking will be removed in a future version.
* Groups are never removed from `groups.yml` anymore, previously they were removed when they had zero regions, which wipe settings.
* Github update checker has been added as replacement for the BukkitDev updater (it will never download anything, it just notifies about updates).
* Only update WorldGuard region settings if they are different, this should prevent unnecessary saving by WorldGuard.
* When new code is pushed to Github the translations on Transifex get updated automatically, so that translations can begin immediately.
**Fixed:**
* Security issues caused by saving/restoring entities in schematics
* Prevent missing `schematicProfile` causing an exception.
* Setting `schematicProfile` in a region file.
* Players could resell their region with a negative price.
* Using `landlordName` without `landlord` (UUID) setting works correctly now.
* Using `/as addfriend` with a player that is online for the first time.
* Removing the English time modifiers from the config.yml file would cause all tasks to be broken, because their schedule time is defined with strings like `1 minute`. The English modifiers from the config.yml inside the .jar file are always added now.
* `/as setowner` for regions that are not yet rented has been fixed.
* Restoring polygon regions will now only touch blocks that are actually inside the region.
***
## AreaShop V2.4.0
* Change the `config.yml` and `default.yml` files to be easier to understand:
* The profiles previously listed in the `config.yml` are now directly assigned to the profile settings in `default.yml`
* When you give a profile setting in `default.yml` a string it will still look up the profile in `config.yml`, which ensures your old config still works.
* Add permissions `areashop.teleportavailable` and `areashop.teleportavailablesign`, with which you can give players permission to teleport to all forsale/forrent regions (thanks jewome62 for the [pull request](https://github.com/NLthijs48/AreaShop/pull/241)!).
* Support for stacking up and down with `/as stack`.
* Fix clicking signs while confirmations are enabled trying to execute commands as players by default (causing that the player does not get a confirmation message).
* Fix a line break problem in the message parser and fix line breaks on 1.7 servers.
* Fix some color parsing issues in the message parser (it would not detect a color if you directly used the section sign).
* Add tab completion for `/as me`.
* Fix a bug that caused `/as setowner` extending the rent, even though the owner is different as the previous one.
* Rename the events AreaShop emits for integration with other plugins (**this breaks existing plugins that use these events!**).
* Fix WorldGuard version detection.
***
## AreaShop V2.3.2
* Added Russian translation (86% complete, so if you know Russian please [help translating](https://github.com/NLthijs48/AreaShop/wiki/Language-support))
* Fixed server crash bug caused by the new messages system (#205)
* Improve stability of the messages system (all reflection removed, using /tellraw in the background now)
* Fix Vault API repo link, thanks Androkai (#206)
***
## AreaShop V2.3.1
* Added German, French and Norwegian translations, thanks to all the translators!
* Added automatic conversion for language files downloaded from Transifex (this means you can download the latest version from Transifex and AreaShop will correctly read it).
***
## AreaShop V2.3.0
**Additions:**
- Add hover/click support for all messages of AreaShop:
- If a region name is in a message then you can click the region name to see all information about the region.
- Player names can be clicked to see which regions they own.
- For long lists like `/as info all` AreaShop will use pages, with buttons you can click to go to the next/previous page.
- A lot of buttons on the region info page, to rent/unrent, remove friends or teleport to the region
- All these messages are defined in the messages file (EN.yml), so you can also edit and [use these yourself](https://github.com/NLthijs48/AreaShop/wiki/Language-support#message-format-specifications).
- Got any suggestions for adding more buttons like these? Please let me know.
- Can be turned off by `useFancyMessages` in `config.yml` (no idea why you would want to do that though).
- Improvements to inserting messages into other messages, for example passing along variables: `%lang:action|My action text|%`.
- `/as help` now respects the `areashop.help` permission.
- Add an `ALL` state for flagProfiles to set flags for all states (like `priority`).
- By default players need to confirm selling/unrenting when using signs, to prevent accidentely losing your region and possibly the contents of it (you can also easily turn it on for renting/buying in the `signProfiles` section in `config.yml`).
- Add compatibility for the upcoming WorldGuard version (setting flags of regions changed).
**Technical:**
- Add redunded money to the `UnrentedRegionEvent` and `SoldRegionEvent`.
- Add events for adding/removing friends: `AddFriendEvent` and `DeleteFriendEvent`, both can be cancelled.
- Move all code to the `me.wiefferink` package, since I intent on keeping this domain, and will not have `nl.evolutioncoding` for long anymore.
- Add an issue template to the repository so that creating Github issues has placeholder text and directions on what information to provide.
- Cleanup the config file by making all timing settings hidden.
- Improve the Maven setup by adding options to move plugin output to a directory, produce a jar with sources and produce Javadoc
- Add a [build server](http://wiefferink.me:8080/job/AreaShop/) where you can find the latest **in development** AreaShop version.
- Setup a Javadoc site: [https://wiefferink.me/AreaShop/javadocs/](https://wiefferink.me/AreaShop/javadocs/), automatically updated by the Jenkins build server.
**Fixes:**
- Fix problems with detecting most important region when placing a sign (problem showed up when using child/parent system of WorldGuard)
***
## AreaShop V2.2.2
**Additions:**
* Add full 1.9 compatibility (only stats reporting and some tab completions were broken, all other functionality was functional already).
* Add feature that lets players rent a region at least to the maximum rental time (before they could not extend before the region had `max-duration` time left). Can be turned off in the `default.yml` file with `extendToFullWhenAboveMaxRentTime`.
* Add event system:
- 'ask' type events that can be cancelled, broadcasted before the action happens.
- 'notify' type events that cannot be cancelled, but only let you know that it has happened.
- Events for renting (with extending flag), unrenting, buying, selling, reselling, adding and removing.
- General 'RegionUpdateEvent' to listen to as display service (update signs, update regions flags, etc).
- Can be used to write addons for AreaShop.
- Is currently only used for updating signs and regions, but other parts of AreaShop will also be using it soon.
* Add `areashop.linksigns` permissions to the `areashop.*` permissions group.
* Add priority, interact and build flag to the default `config.yml` file, helps to reduce support for issues with this.
* Add `middle` and number options to the `teleportLocationY` setting in `default.yml`.
* Add variable support for all language messages that can support it, which means where a region is known.
* Add Czech language, translated by Fractival.
**Fixes:**
* Fix last active time of players sometimes not updating correctly, influences inactive unrent/sell feature.
* Fix message variables for `/as info player <player>`.
* Fix the `n:<name>` option for member/owner region flags (the `n:` was not stripped away before adding them).
***
## AreaShop V2.2.1
* Added a setting to deny extending rental regions when the player is above his limits (if the player cannot rent the region back when he unrents it then it he is considered to be above his limits). Setting `allowRegionExtendsWhenAboveLimits` can be found in `config.yml` and is by default set at `false`, this modifies the behaviour of AreaShop compared to the previous version, but this is probably something that users already expect to happen.
* Fixed a bug with `/as tp` sometimes teleporting to the region instead of a the sign when a player has certain permissions.
* Moved all documentation to GitHub, as you probably have already seen.
* Added permission `areashop.buyresell` and `areashop.buynormal` to be able to prevent players from buying regions that are in reselling mode, or regions that are not in reselling mode.
* Fixed `/as find` without balance argument using a maximum of zero instead of the balance of the player + formatting of the price will now use the proper currency formatting instead of a plain number.
* Fixed `/as info` trying to filter by group for a couple of sub commands when it should not.
* Fixed `/as info region <region>` always showing a line specifying the landlord, even when there is not one (it would show `<UNKNOWN>`).
* Added Vault jar file to the repository to make compiling easier, only cloning + running with Maven is enough now.
* Improved handling of failed file loading for all config and region files, better messages in console for when it happens.
* Remove `lastActive` line from region files when unrented/sold, nothing serious, just cleanup.
* Fixed sign click actions still executing even when the Bukkit event is cancelled.
* Breaking signs that are connected to regions will not longer disconnect it, but instead make it float.
* Made removing regions from AreaShop less destructible for region flags, only greeting and farewell are removed to avoid confusion (this helps when you accidentally add wrong regions).
* Fixed support for the seconds modifiers when using `/as setduration`.
* Added support for weeks modifiers for specifying time durations.
* Cleaned old Dutch time modifiers from `config.yml`, **Warning: This will break existing signs with these modifiers if not re-added in the config**. Regions using incorrect time specifiers will be listed in the console/log at startup.
* Unrenting/selling a region that has a landlord will now get the money from the landlord instead of introducing new money. If the landlord does not have enough money then the user will get nothing back.
* Change the default sign tags to `[asrent]` and `[asbuy]`, this prevents clashes with for example Essentials. This will not impact already linked signs, only creating new signs and the tags can still be easily changed in the config.
***
## AreaShop V2.2.0
* Change to a module based Maven project to support dependencies with multiple versions:
* 1 .jar file for AreaShop, no different files for certain dependencies anymore.
* Support for WorldGuard 5 and WorldGuard 6.
* Support for WorldEdit 5 and WorldEdit 6.
* Setup to easily add support for more version if breaking changes in dependencies happen.
* Add support for the new schematic save/restore classes of WorldEdit (supports entities).
* Added the `/as stack` command to easily create and register a lot of regions, syntax:
* /as stack <amount> <gap> <name> <rent|buy> [group]
* `<amount>` Number of regions that will be created
* `<gap>` Blocks distance between the regions
* `<name>` Name of the regions (number will be behind it)
* `<rent|buy>` The type of the region
* `[group]` A group to add the created regions to
* The regions will be created in the direction you are facing
* Don't be afraid to create 100+ regions with this command, it will do a certain number per tick, and therefore not lag/crash the server.
* Setting `stackRegionNumberLength` to config.yml to indicate how long the numbers appended to the base region name should at least be (generate names like this: `region-001`, `region-014`, `region-4567`).
* Make region loading non-descructive:
Regions will never be removed again by AreaShop itself. If the world or WorldGuard region is missing that is required for the functions of the region then it will simply say so in the console. This will make sure that regions are not removed when you have trouble loading your world or your WorldGuard regions.
* Make the update checker async, also when it cannot reach BukkitDev to check for updates it does not slow down the start of the server.
* Fix `/as setowner` not saving the region file, and therefore losing changes when restarting the server.
* Change Vault integration to support custom (not build into Vault) economies. This also enables support to change economies while the server is running.
* Fix a bug with teleporting to regions, and add a message when the teleport changes from sign to region or the other way around (this happens when the user does not have permission for one of them, but has for the other).
* Remove the `enableSchematics` setting from the config file, this setting is already in default.yml and only caused confusion.
* Added landlord functionality:
* Set the landlord of a region with `/as setlandlord <player>`.
* Set the landlord in default.yml or groups by UUID or name.
* All revenue of a region (buy/rental) will go to the landlord.
* Permissions `areashop.createrent.owner`, `areashop.createrent.member`, `areashop.createbuy.owner` and `areashop.createbuy.member` to enable users to add existing WorldGuard regions to AreaShop if they are already owner/member (they are automatically assigned as landlord when they add regions).
* Permissions `areashop.destroybuy.landlord` and `areashop.destroyrent.landlord` to give landlords the permission to remove their region from AreaShop.
* Permission `areashop.setprice.landlord` to let landlords change the price of their region.
* Permission `areashop.setduration.landlord` to let landlords change the duration of their region.
* Permission `areashop.landlord.*` to give all landlord permissions to a player (all permissions above).
* Added arguments `default` and `reset` to `/as setprice` and `/as setduration` to remove the setting from the region file (then it inherits it again from the groups or default.yml).
* Support Metric prefixes (https://en.wikipedia.org/wiki/Metric_prefix) to display large numbers nicely. This means you can display numbers like `1000000` as `1.00G` instead. Has options to indicate from which number prefixes should be used.
* Added a decimalMark setting to config.yml to change the character used to indicate the fractional part of numbers (change from dot to comma for example).
* Changed all time period settings in config files to a readable format like the rental times. Old values will still be read correctly, and should work exactly like in the old version.
* Make sure regions are not unnecessary saved directly after loading them at server startup.
* Fixed an issue with `/as addfriend` denying you to add players that just joined for the first time.
* Fix a problem with depositing money to players that never joined the server (or for which there is no player.dat file anymore).
* Add date and time variables for all config settings (can be used to save schematics as backup, creating a new one each time instead of overwriting).
* Add fallback system for owners and landlords, if the UUID has no correct name within the Bukkit API it will use the cached name. This makes sure that these people can still be paid through Vault.
***
## AreaShop V2.1.5
* Changed all translations to have a period at the end of sentences.
* Added a Chinese (Taiwan) language file
* Added a blacklist option in the config to block certain regions from being added to AreaShop (you can provide a list of region names with regular expressions) by default only `_global_` is on the list. Regular expressions make it possible to for example block all regions with a certain pattern.
* Added a setting `findTeleportToSign` to change if `/as find` should teleport you to the first sign of the region or to the `/as settp` spot (with fallback to the middle of the region).
* Fixed a small bug that would cause you to get teleported to the fallback spot instead of the `/as settp` one when you try to teleport to a sign but don't have permission for it (AreaShop changes your request to a non-sign teleport if you do have permission for that in that case)
* Added an extra option to `/as info` to list all regions that do not have a group, use `/as info nogroup`.
* Added name change detection on login of the player (checks if the players name matches the saved name for the regions that are owned by the players, works because getting regions happens with the UUID) and if it changed it will update the region flags and signs.
* Changed that now all region flags and signs will be updated when starting the server, that way users don't think that something does not work simply because the region is not updated. This can be turned off by setting `updateRegionsOnStartup` to false in the config (updating the region happens slowly so it should not cause any noticeable lag).
* Removed the `/as updaterents` and `/as updatebuys` commands, became redundant because `/as reload` also updates all regions now so that can be used instead.
* Fixed translation of color codes for greeting/farewell messages for WorldGuard 6.0+ users (this problem was caused by an unintended breaking change by WorldGuard, check [this ticket](http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/tickets/26-color-issue/) for details).
***
## AreaShop V2.1.4
* Fixed a bug with regions that are in reselling mode, they will now correctly check if you have enough money to pay the resell price instead of checking if you have enough money for the normal price.
* Added a line to the `/as info region` output for regions that are in resell mode which displays the resell price.
* Changed `/as find` to first search all matching regions (rent/buy, maxprice and group) and after that select a random region from that list.
***
## AreaShop V2.1.3
* Splitted into 2 versions now, 1 for WorldGuard 5.9 and 1 for WorldGuard 6.x+ Use the correct version that matches the WorldGuard version you have installed.
***
## AreaShop V2.1.2
* Fixed a bug with the `/as settp` command not accepting arguments, it would always try to find regions at your location instead of first checking if you give it a region name.
* Fixed a bug with inactive player unrent/sell settings. If the `inactiveTimeUntilUnrent` or `inactiveTimeUntilSell` settings would be set to a value above 35000 it would cause an integer overflow, resulting in a 50% chance that all regions will be unrentend/sold (and if that does not happen it will still sell/unrent them too early).
* Fixed a bug with periodic sign updating crashing when a region has 0 signs.
* Add an update checker, will check BukkitDev for the latest file and print a message in console if an update has been found. Also notifies OPs + players with the `areashop.notifyupdate` permission. It will never download the latest version, because those might require a backup or manual changes to run properly.
* Fixed some possible bugs with getting the list of players that are added as friend to a region.
* --Restored compatibility with WorldGuard 5.9 (WorldGuard 6.0+ is still recommended because that one properly supports UUID's, so 5.9 would cause problems with name changing) and WorldEdit 5.6.3 (could probably already be used with previous AreaShop versions)-- Broken in this version, fixed in V2.1.3 by releasing 2 jar files.
* The French language file has been corrected at some points.
* The German language file has been completed and corrected at some points
* The Polish language file has been improved slightly, but is not 100% complete yet (can you help translating? Check [this page](http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/pages/schematics-languages/#w-option-2))
***
## AreaShop V2.1.1
* Fixed a bug with setting the `owners` flag through the flagProfiles section. (previously it would split the list behind owners into different entries using ` ` as separator, but that should be `, ` this has been fixed now)
* Fixed a bug that cause the "conversion to a new version of the file format starts, could take some time" message to always appear after reload/restart of the server. It would not actually do anything to the files, but would print the message.
* Fixed the unnecessary saving of the groups.yml file, if loaded from disk it would automatically mark the file as changed, causing it to save at the next iteration of the save task.
* Fixed a bug that caused the region flags and signs to update for each member that is added (this is unnecessary when loading the groups from disk, commands still update signs etc properly). Now it will update after all the members of a group are added, and this update is spread over multiple ticks like the `/as updaterents` command
* Updated the French language file to the latest version that is made at [Transifex](https://www.transifex.com/projects/p/areashop/), it has been fully updated by Yaelknown.
***
## AreaShop V2.1.0
#### Features added/changed
* Changed the `/as info region` command to show more relevant information:
![New /as info layout](https://camo.githubusercontent.com/955823568bd47790d56f50ed0c24af8f65640356/687474703a2f2f6465762e62756b6b69742e6f72672f6d656469612f696d616765732f37392f3534372f53637265656e73686f745f312e706e67)
These are almost all things that could show there, some lines will not show up when based on config options (extending, in advance renting, restoring), some don't show up if empty (friends, signs) and some don't show up based on permissions (groups, teleport location, restoring).
* Adding friends to your region is now possible with `/as addfriend <player> [region]` (delete with `/as delfriend <player> [region]`), by default these players will also be added as member of the region, this can however be changed in the `flagProfiles` section of config.yml. By default friends can also teleport to the regions they are added to, deny permission `areashop.teleportfriend` to stop this.
* Automatic unrenting for players that are inactive for a certain period of time (`inactiveTimeUntilUnrent` and `inactiveTimeUntilSell` in default.yml, so this can also be changed for groups of regions or individual ones) OPs are excluded by default, those regions will not be unrented/sold.
* Added a argument to `/as find` to specify a group, it will only search for regions in that group if specified. Could be useful to create command signs and let players automatically get a region that is at a certain place.
* Added a command `/as me`, which lists all your rent and buy regions, plus regions you are added as friend.
* Added a `/as setowner <player> [region]` command to change the owner of a region without triggering events for commands, schematics or money transactions (using this command on a rent region with the player that already rents it will extend the region by 1 time period).
* Added a `/as resell <price> [region]` command to let players put their bought region into resell mode. If they do that the sign will indicate you can buy the region (shows [Resale] at the top), but the owner can still do anything like normal. When another player buys the region then the money will get transferred to the original owner and the new player will be owner (then the sign shows [Sold] again). If a player changed his mind and does not want to resell his region anymore he can use `/as resell`.
* Added a tag `%timeleft%` for signs to show the time that a rent has left instead of the end date, AreaShop will update signs that have this every minute by default (check the values in the `signs` section at the bottom of the config to change this)
* All files (config.yml, default.yml, groups.yml, <region>.yml and <lang>.yml) are now loaded in UTF-8 mode, so now they support all fancy characters like € or ê.
* Limitgroups for limiting how much regions a player can buy/rent have changed to be more flexible. Now a `worlds` and `groups` section can be added to a group to let the limits only count for regions in these worlds and groups. This allows for different limits for regions in different world (let players have max 2 plots in creative, while limiting the number of shops in survival to 1) the groups allow you to limit certain type of regions that are in the same world.
* The limitgroup `unlimited` that was normally in the config by default has been removed and now the permission `areashop.limitbypass` allows you to ignore the limits (default to OPs)
* The `areashop.setteleportoutsideregion` permission now works correctly
* Added a setting to specify the maximum time a rent region can be rented in advance: `maxRentTime` in default.yml. This prevents players from renting a region a year in advance, instead they have to extend their rent every now and then.
* Added `areashop.teleportsignall` permission to teleport to signs of region you do not own (default for OPs)
* If a language string contains tags other then `%0%`, `%1%`, `%2%` etc, then all tags for regions can be used (check the config.yml file on the [Config System](http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/pages/the-config-system/) page to see all available tags)
* All places where tags can be used, now also language strings can be inserted. Use `%lang:<key>%`, where <key> is the part before the colon in the language file. All tags that are available in the original string will be available in the inserted language string.
* The default commands that are executed by clicking on signs now use the full `/areashop` instead of `/as` to prevent collisions with commands of other plugins.
* The number of digits behind the decimal point of prices can be changed with the `fractionalNumbers` setting in config.yml, the setting `hideEmptyFractionalPart` determines if the `.0` part of a number should be hidden or not. Default settings produce numbers like this: `$10`, `$5,50`, `$3.45`.
* Fixed a bug with with money withdrawal: If a player is in world A and buys a region in world B the plugin now correctly withdraws money from world B.
* Added a setting to force a user to be in the correct world before he can buy/rent a region: `restrictedToWorld` in default.yml
* Added a setting to force a user to be inside the region before he can buy/rent it: `restrictedToRegion` in default.yml
* Added a warning system for players to indicate their rent is running out, `expirationWarningProfiles` section in the config. Different times can be specifed when a message should be sent and a custom list of commands can be executed (all region tags can be used)
* Added a settting `warningOnLoginTime` to default.yml, when a rent region has less then this time left when the owner of it logs in it will send a warning message to the owner.
* The command `/as rentduration` is renamed to `/as setduration` to be consistent with the other commands
* The flagprofiles changed, owners and members now take a list of UUID's, when setting to a region only these will be set (others are cleared). It is now possible to add groups to owners/members by using `g:<group>` in the list, this does the same as `/region addmember <region> g:<group>`. It is now possible to specify the group a flag is about, use `g:<members|non_members|owners|non_owners|all>`, can for example be used to only let members of a region walk into it.
* If a schematic is wrongly sized compared to the region size AreaShop will print a warning in the console (but it will still restore it)
#### Performance improvements
* Operations that change/check multiple regions have been changed to do this spread over multiple ticks (now it does a certain number of regions per second instead of all at once, prevents lag spikes for if you have a lot of regions). At the bottom of the config is a section `Limits and Timings` where the speed of these tasks can be changed. The following actions have been changed to this new system (NEW indicates that this is added for a new feature of this update):
* Checking expiration of rent regions
* Updating of regions when using `/as updaterents` or `/as updatebuys`
* Checking of regions for players that are inactive for too long (NEW)
* Periodic sign updates of regions for when it has tags like `%timeleft%` (NEW)
* Saving region files, now regions only get saved every 10 minutes now by default. Only regions that actually changed will be saved, when shutting down the server it will also safe the regions to prevent data loss. This task also handles saving the groups.yml file (also only saved when necessary) and saving of WorldGuard regions (uses the saveChanged() method of WorldGuard to only save regions that require it).
* Checking for when to send warning about rent expiration to players (NEW)
***
## AreaShop V2.0.2
* Adds compatibility with WorldGuard 6, but does not work with WorldGuard 5 anymore
* Fixes a bug with upgrading from a lower version. With V2.0.0 and V2.0.1 it could happen that the plugin does not update correctly from a lower version, the config.yml would not be moved to the `#old` folder preventing AreaShop to generate a new config. Then the plugin would load the old config and deny users to rent/buy regions because the limits are set incorrectly.
* Fixes the incompatibility of UTF-8 characters with the language files, now characters like é, ê, etc. will show up correctly in-game.
* Adds a fully updated French language file to the plugin, thanks BlaZingHope for translating, check [the ticket](http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/tickets/5-language-add-a-language/).
***
## AreaShop V2.0.1
* Moves setting to determine y location of teleport position to default.yml/groups/region files
* Adds setting to specify if teleporting should be inside the region or not (default.yml/groups/region files)
* Adds a setting to the config.yml to specify the maximum number of tries the safe teleport function can do (default 50000)
* The teleport function now functions properly with locations close to build limit or below 0 (no more falling from the sky).
***
## AreaShop V2.0.0
#### WARNING
Before updating to this version of the plugin make a backup of all worlds that contain regions registered in this plugin!
After updating from a previous version the old config.yml will be placed in the folder `#old` because the config changed
a lot, you can copy the old settings to the new config, just put them in the right position. In the `#old` folder are also
the necessary files to revert back to version 1.X of AreaShop.
#### Feature changes
Note: sections in the config ending with `Profile` can be assigned to region with the inheritance system. You can create new profiles by copying an existing one and changing the values.
Parts you don't need can usually be left out.
* Adds a permission to set the teleport location outside the WorldGuard region: areashop.setteleportoutsideregion (given to OPs by default)
* If you remove a rent or buy region all the flags of the WorldGuard region will be reset
* Adds extra checks for teleportation, now also check blocks around you so now a 3x3x4 shape will be checked for danger
* Adds a setting in the config to specify what the default y coordinate should be for teleporting, setting `teleportLocationY`, values: bottom, middle, top
* You can specify in the config if AreaShop messages in the console should be in color or not
* Adds support for different limits for players by using permissions, declare limit groups in the section `limitGroups` and then give players the permission
`areashop.limits.<group>`, replacing <group> with the name of the group (if a player has multiple groups then highest limit will be used, by default they have group `default` and OPs have `unlimited`)
* Adds full customization of signs, in the section `signProfiles` all lines of a sign can be changed and also the commands to execute when a players right/left clicks a sign (multiple commands can be used, it is a list). Tags are provided to insert region all region data (check config)
* Adds support for multiple signs for one region, for every sign you can set the profile (profiles specified in the config), if not set the profile will be inherited from the region/groups/default.yml
signs can be added by `as addsign` or placing a sign with the first line `[as]`, second line the region (optional if sign is inside region) and third line the profile (optional)
* Adds support to execute commands at certain events (created, deleted, rented, extended, unrented, bought, sold) check config section `eventCommandProfiles`
* Flag settings are now by profile (check `flagProfiles`), so regions can have different flags set (for example a different greeting)
* Adds a setting to limit the maximum number of times a rent can be extended (check default.yml/groups/region files)
#### Command changes
* Adds tab completion for all commands if you are OP or have the permission areashop.tabcomplete
* Adds color and format support to greeting and farewell messages (use the normal bukkit formatting codes)
* Adds a command to find an available rent/buy with an optional maximumprice (with no maxprice your balance will be used as max), /as find <buy|rent> [maxprice]
* Adds extra optional parameter `sign` to `as tp`, with that parameter you will teleport to the (first) sign instead of the region
* With a lot of player command you don't have to specify a region anymore, just stand in the region and the plugin will detect it
* Merges commands `as rentrestore` and `as buyrestore` into `as setrestore`
* Merges commands `as buyprice` and `as rentprice` into `as setprice`
* Adds `as groupadd` command to add regions to groups. Rents and buys can be mixed, region can be specified or taken from your WorldEdit selection (adds them all), group will be created if it has no members yet
* Adds `as groupdel` command to delete regions from groups, region can be specified or taken from your WorldEdit selection (removes them all), if a groups is empty it will be removed
* Adds `as grouplist` command that lists all groups registered
* Adds `as groupinfo` command that displays members of the specified group
* Adds `as add` command to add a region or all regions inside your WorldEdit selection (no signs will be added)
* Adds `as del` command to delete a region from AreaShop or all inside your WorldEdit selection (signs will be removed)
* Adds `as addsign` command to add the sign you are looking at (max 100 blocks away) to the specified region (with optionally a profile)
* Adds `as delsign` command to delete the sign you are looking at from the region it belongs to
* Adds `as schemevent` command to manually trigger a schematic event
#### The new config system
The config system has drastically changed and an inheritance system has been added to support global, group and individual settings.
Now the config only contains global settings and profiles, these profiles can be assigned with the inheritance system.
A file called `default.yml` will appear, this file contains all settings that can be changed globally, in a group or in a individual region.
When you create a group with the build-in commands a file `groups.yml` will appear, this contains the groups and members of the groups.
Each region has its own file inside the folder `/regions` located inside the AreaShop folder, this file contains the individual settings.
When checking a setting, for example `price`, the plugin first checks if it has been set in the region file, then it checks
all groups assigned to the region for the setting (the one with highest priority will apply, or otherwise the first one with the setting).
If it still did not find the setting it gets it from `default.yml`. All settings in `default.yml` can be used in group files and region files,
just add them to the file, to for example set the price for a group with buy regions you add the setting `price` inside the section `buy`.
***
## AreaShop V1.3.0
* Adds support for name changing, all files will be converted to UUID's on startup. It will create files `rents.old` and `buys.old` as backup for if the conversion goes wrong, you can delete these after you are sure everything works
* Adds version system for all files, this is for converting to next version and is just a `behind the scenes` thing, a `versions` file will appear in the datafolder of the plugin
* Adds a command to teleport to regions, normal players can only teleport to their bought/rented regions (can be changed with permissions) ops can teleport to all rent/buy regions. Teleportation is safe, the plugin tries to find a safe spot within the region.
* Adds a command to set the teleport location, normal players can only set it for their bought/rented regions (can be changed with permissions) ops can change it for all regions. If no location is set the teleport command will try to teleport to the bottom middle of the region (and then checking a cube of increasing size around that while it is not safe).
* Fixes problem with Multiverse-Core, if Multiverse would load after AreaShop then all rents/buys in other worlds then `world`, `world_nether` and `world_the_end` will deregister. Now AreaShop softdepends on Multiverse-Core so if Multiverse is on the server it should load before AreaShop.
* Fixes problem with the flags sections in the config, it was not possible to reset flag with the previous way of handling the flags. If you put no value behind a flag or `none` it will now reset.
* Fixes bug with percentage of money back after buying/renting not working, only 100% and 0% were possible before, now it works normally.
* Refactored the commands system, adding commands and maintenance should be easier now. Also tab completion would be possible now, leave a comment if you would like to have that.
***
## AreaShop V1.2.1
* Fixes bugs with deleting regions and worlds (plugin would not start correctly)
* Adds support for automatically using the region you place the sign in when you leave the second line empty (looks at priority and parent/child relations)
***
## AreaShop V1.2.0
* Fixed a bug with accessing the Vault api to early (plugin does not load in rare cases)
* Added option to set `moneyCharacterAfter`, instead of $10 you can create something like `10 gold` now.
* Added statistics, using Metrics, can be disabled in the config (check http://mcstats.org/|http://mcstats.org/)
* Added commands to change the price of buy and rent regions. `/as rentprice` and `/as buyprice`
* Added command to change the duration of a rent region. `/as rentduration`
* Added config option to change the timeformat that is used on the signs and in the chat
* Added config options to change the identifiers used for rent regions (minutes, hours, days, months, years) This also fixes that `M` did not work as month, but as minute.
***
## AreaShop V1.1.2
* Small bugfix for restoring, the `rented` restore event was also firing when you extended your rent, possibly removing all your items within the region.
* The included language file for Dutch (NL.yml) should work now.
***
## AreaShop V1.1
* This release adds a very configurable saving and restoring of regions. You can let the plugin save and restore the region from/to a .schematic file on certain events. Commands are added to change the restoring profile for a rent/buy and the state (true, false, general) which are respectively enabled, disabled and `as general config option`. Check the [[http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/pages/default-config/|Config page]] for which options you are missing or let the plugin generate a new one for you. Also some commands are merged to make it simpler.
***
## AreaShop V1.0
* First public release of the plugin, contains language support, commands, sign interaction and a config.
+3 -5
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Based on the Google Java Style Guide: https://google.github.io/styleguide/javaguide.html
@@ -42,9 +42,7 @@
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces"/>
<module name="LeftCurly">
<property name="maxLineLength" value="100"/>
</module>
<module name="LeftCurly" />
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_DO"/>
Binary file not shown.
Binary file not shown.
+45
View File
@@ -0,0 +1,45 @@
# How to release a version of AreaShop
Below the steps to follow for releasing a version of AreaShop are listed.
## Pull the latest translations from Transifex
**Setup:**
1. Clone the [InteractiveMessengerTransifex](https://github.com/NLthijs48/InteractiveMessengerTransifex) repository
2. Run `mvn package`
- The `target\InteractiveMessengerTransifex.jar` file should now be present
**Pull translations:**
1. Run `target/InteractiveMessengerTransifex.jar` using Java with the following arguments:
- **`download`**
- **<transifex api key>**, get from Transifex
- **`areashop`**, project name
- **`enyml`**, name of the file to download, this is the name AreaShop uses on Transifex
- **`./AreaShop/src/main/resources/lang`**, path to the `lang` directory in your clone of the AreaShop repository
- **`70`**, meaning only languages translated for at least 70% will get downloaded
- **`true`**, reformat the files to be suitable for using in the plugin
- **`./langHeader.yml`**, header to add to language file, this file is in the AreaShop repository
- **`<version>`**, release version to put in the header
2. Commit the changed files in the AreaShop repository
3. Push the commit to Github
## Update the version number
1. In `./AreaShop/pom.xml` update the `<version>` tag with the new version (following semantic versioning)
2. In `./changelog.md` add notes about the features/fixes of this new version
3. Commit the updated files
4. Push the commit to Github
5. Jenkins will build a new version and make it available on Maven
## Uploading to distribution platforms
The order is important, uploading to Github will trigger the update notification, but points people to Spigot
1. Post a [resource update on Spigot](https://www.spigotmc.org/resources/areashop.2991/add-version)
- Use the changelog in the update message
- Indicate major features in the update title
- Update the supported Spigot versions if necessary
2. Upload a [new file on Bukkit](https://dev.bukkit.org/projects/regionbuyandrent/files/upload)
- Use the changelog in the update message
- The file needs to be approved before it will be available for everyone
3. Add a [new release on Github](https://github.com/NLthijs48/AreaShop/releases/new)
- Enter a tag like `v2.6.0`
- Enter a title like `AreaShop 2.6.0`
- Add the changelog
- Add the .jar file as `AreaShop.jar`
+53
View File
@@ -0,0 +1,53 @@
<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>
<artifactId>areashop-fawe-1-15</artifactId>
<packaging>jar</packaging>
<name>AreaShop FastAsyncWorldEdit 1.14+</name>
<version>latest</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<repositories>
<repository>
<id>IS-Repo</id>
<url>https://mvn.intellectualsites.com/content/repositories/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.intellectualsites.fawe</groupId>
<artifactId>FAWE-Bukkit</artifactId>
<version>1.16-380</version> <!-- Equivalent to WE 7.0.2? -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>latest</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,283 @@
package me.wiefferink.areashop.handlers.fawe.v1_15;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.RelightMode;
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
import com.google.common.annotations.Beta;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.*;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.io.Closer;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionType;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.GeneralRegionInterface;
import me.wiefferink.areashop.interfaces.WorldEditInterface;
import me.wiefferink.areashop.interfaces.WorldEditSelection;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.entity.Player;
import org.bukkit.util.BoundingBox;
import java.io.*;
import java.util.concurrent.CompletableFuture;
import java.util.zip.GZIPInputStream;
// Future: this class could use the schematic save/paste api of FAWE: https://github.com/boy0001/FastAsyncWorldedit/wiki/Pasting-a-schematic
// This would not allow for shaping the schematic to a polygon region though
public class FastAsyncWorldEditHandler extends WorldEditInterface {
public FastAsyncWorldEditHandler(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
private static class RegionBoundMask implements Mask {
private final BoundingBox boundingBox;
public RegionBoundMask(final ProtectedRegion region) {
final BlockVector3 min = region.getMinimumPoint(), max = region.getMaximumPoint();
this.boundingBox = new BoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ());
}
public RegionBoundMask(final BoundingBox boundingBox) {
this.boundingBox = boundingBox.clone();
}
@Override
public boolean test(BlockVector3 vector) {
return boundingBox.contains(vector.getX(), vector.getY(), vector.getZ());
}
@Override
public Mask2D toMask2D() {
return null;
}
@Override
public Mask copy() {
return new RegionBoundMask(boundingBox);
}
}
@Override
@Beta
public CompletableFuture<Boolean> restoreRegionBlocksAsync(File rawFile, GeneralRegionInterface regionInterface) {
File file = null;
ClipboardFormat format = null;
for (ClipboardFormat formatOption : BuiltInClipboardFormat.values()) {
if (new File(rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension())
.exists()) {
file = new File(
rawFile.getAbsolutePath() + "." + formatOption.getPrimaryFileExtension());
format = formatOption;
break;
}
}
if (file == null) {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName()
+ ", schematic file does not exist: " + rawFile.getAbsolutePath());
return CompletableFuture.completedFuture(false);
}
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), " from file",
file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getName() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if (world == null) {
pluginInterface.getLogger().info(
"Did not restore region " + regionInterface.getName() + ", world not found: "
+ regionInterface.getWorldName());
return CompletableFuture.completedFuture(false);
}
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
final FaweLimit limit = new FaweLimit();
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
EditSession editSession = FaweAPI.getEditSessionBuilder(world).limit(limit).relightMode(RelightMode.OPTIMAL).build();
editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE);
ProtectedRegion region = regionInterface.getRegion();
final RegionType regionType = region.getType();
// Get the origin and size of the region
final BlockVector3 origin = BlockVector3
.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(),
region.getMinimumPoint().getBlockZ());
final RegionBoundMask mask = new RegionBoundMask(region);
final File finalFile = file;
final String regionName = regionInterface.getName();
final double regionWidth = regionInterface.getWidth(), regionHeight = regionInterface.getHeight(), regionDepth = regionInterface.getDepth();
final LocalSession session =
new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
FaweAPI.getTaskManager().async(() -> {
// Read the schematic and paste it into the world
try (Closer closer = Closer.create()) {
FileInputStream fis = closer.register(new FileInputStream(finalFile));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(bis));
ClipboardReader reader = new FastSchematicReader(nbtStream);
Clipboard clipboard = reader.read();
if (clipboard.getDimensions().getY() != regionHeight
|| clipboard.getDimensions().getX() != regionWidth
|| clipboard.getDimensions().getZ() != regionDepth) {
pluginInterface.getLogger().warning(
"Size of the region " + regionName
+ " is not the same as the schematic to restore!");
pluginInterface.debugI(
"schematic|region, x:" + clipboard.getDimensions().getX() + "|"
+ regionWidth + ", y:" + clipboard.getDimensions().getY()
+ "|" + regionHeight + ", z:" + clipboard.getDimensions()
.getZ() + "|" + regionDepth);
}
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
session.setBlockChangeLimit(limit.MAX_CHANGES);
session.setClipboard(clipboardHolder);
// Build operation
BlockTransformExtent extent = new BlockTransformExtent(clipboard);
ForwardExtentCopy copy =
new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(),
editSession, origin);
copy.setTransform(clipboardHolder.getTransform());
// Mask to region (for polygon and other weird shaped regions)
// TODO make this more efficient (especially for polygon regions)
if (regionType != RegionType.CUBOID) {
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning(
"exceeded the block limit while restoring schematic of " + regionInterface.getName()
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumBlocks"));
CompletableFuture.completedFuture(false);
} catch (IOException e) {
pluginInterface.getLogger().warning(
"An error occured while restoring schematic of " + regionInterface.getName()
+ ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
CompletableFuture.completedFuture(false);
} catch (Exception e) {
pluginInterface.getLogger()
.warning("crashed during restore of " + regionInterface.getName());
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
CompletableFuture.completedFuture(false);
}
editSession.flushQueue();
CompletableFuture.completedFuture(true);
});
return completableFuture;
}
@Override
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
return restoreRegionBlocksAsync(rawFile, regionInterface).join();
}
@Override
@Beta
public CompletableFuture<Boolean> saveRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
// TODO implement using the FastAsyncWorldEdit api to save async
ClipboardFormat format = BuiltInClipboardFormat.MINECRAFT_STRUCTURE;
// TODO allow selecting FAWE format in the config? (when enabled you cannot go back to vanilla WorldEdit easily)
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file",
file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if (regionInterface.getWorld() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
}
if (world == null) {
pluginInterface.getLogger().warning(
"Did not save region " + regionInterface.getName() + ", world not found: "
+ regionInterface.getWorldName());
return CompletableFuture.completedFuture(false);
}
final FaweLimit limit = new FaweLimit();
limit.MAX_CHANGES = pluginInterface.getConfig().getInt("maximumBlocks");
EditSession editSession = FaweAPI.getEditSessionBuilder(world).relightMode(RelightMode.OPTIMAL).limit(limit).build();
final ProtectedRegion region = regionInterface.getRegion();
final BlockVector3 min = region.getMinimumPoint(), max = region.getMaximumPoint();
final String regionName = regionInterface.getName();
final World finalWorld = world;
final CompletableFuture<Boolean> completableFuture = new CompletableFuture<>();
final File finalFile = file;
FaweAPI.getTaskManager().async(() -> {
// Create a clipboard
CuboidRegion selection =
new CuboidRegion(finalWorld, min, max);
Clipboard clipboard = new MemoryOptimizedClipboard(selection);
clipboard.setOrigin(min);
ForwardExtentCopy copy = new ForwardExtentCopy(editSession,
selection.clone(), clipboard,
min);
try {
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
pluginInterface.getLogger().warning(
"Exceeded the block limit while saving schematic of " + regionName
+ ", limit in exception: " + e.getBlockLimit() + ", limit passed by AreaShop: "
+ pluginInterface.getConfig().getInt("maximumBlocks"));
completableFuture.complete(false);
}
try (Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(finalFile));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(format.getWriter(bos));
writer.write(clipboard);
} catch (IOException e) {
pluginInterface.getLogger().warning(
"An error occured while saving schematic of " + regionName
+ ", enable debug to see the complete stacktrace");
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
completableFuture.complete(false);
} catch (Exception e) {
pluginInterface.getLogger()
.warning("Crashed during save of " + regionName);
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
completableFuture.complete(false);
}
completableFuture.complete(true);
});
return completableFuture;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
return saveRegionBlocksAsync(file, regionInterface).join();
}
@Override
public WorldEditSelection getPlayerSelection(Player player) {
try {
Region region = pluginInterface.getWorldEdit().getSession(player)
.getSelection(BukkitAdapter.adapt(player.getWorld()));
return new WorldEditSelection(player.getWorld(),
BukkitAdapter.adapt(player.getWorld(), region.getMinimumPoint()),
BukkitAdapter.adapt(player.getWorld(), region.getMaximumPoint()));
} catch (IncompleteRegionException e) {
return null;
}
}
}
@@ -4,34 +4,34 @@
<artifactId>areashop-interface</artifactId>
<packaging>jar</packaging>
<name>AreaShop Interface</name>
<version>AreaShopInterface</version>
<version>latest</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<type>jar</type>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>6.0.0-SNAPSHOT</version>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.3</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
</dependencies>
@@ -3,10 +3,11 @@ package me.wiefferink.areashop.interfaces;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.util.logging.Logger;
public interface AreaShopInterface {
public interface AreaShopInterface extends Plugin {
void debugI(Object... message);
YamlConfiguration getConfig();
@@ -56,7 +56,7 @@ public class RegionAccessSet {
result.addAll(playerUniqueIds);
for(String playerName : playerNames) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
if(offlinePlayer != null && offlinePlayer.getUniqueId() != null) {
if (offlinePlayer.hasPlayedBefore()) {
result.add(offlinePlayer.getUniqueId());
}
}
@@ -0,0 +1,49 @@
package me.wiefferink.areashop.interfaces;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.concurrent.CompletableFuture;
public abstract class WorldEditInterface {
protected final AreaShopInterface pluginInterface;
public WorldEditInterface(AreaShopInterface pluginInterface) {
this.pluginInterface = pluginInterface;
}
/**
* Different way to restore blocks per implementation, newer ones support entities as well.
* Why: the schematic api has changed between WorldEdit 5 and 6, and the schematic format changed between 6 and 7
* @param file File to try restoring from to the location of the region
* @param regionInterface Region to restore from
* @return true when successful, otherwise false
*/
public abstract boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface);
public CompletableFuture<Boolean> restoreRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
return CompletableFuture.completedFuture(restoreRegionBlocks(file, regionInterface));
}
/**
* Different way to save blocks per implementation, newer ones support entities as well.
* Why: the schematic api has changed between WorldEdit 5 and 6, and the schematic format changed between 6 and 7
* @param file File to try saving the region to
* @param regionInterface Region to restore from
* @return true when successful, otherwise false
*/
public abstract boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface);
public CompletableFuture<Boolean> saveRegionBlocksAsync(File file, GeneralRegionInterface regionInterface) {
return CompletableFuture.completedFuture(saveRegionBlocks(file, regionInterface));
}
/**
* Get the selection of the player.
* Why: the underlying WorldEdit selection class has changed from interface <-> class
* @param player Player to get the selection for
* @return WorldEditSelection if the player has selected something, otherwise null
*/
public abstract WorldEditSelection getPlayerSelection(Player player);
}
@@ -4,9 +4,9 @@ import org.bukkit.Location;
import org.bukkit.World;
public class WorldEditSelection {
private World world;
private Location minimum;
private Location maximum;
private final World world;
private final Location minimum;
private final Location maximum;
/**
* Craete a WorldEditSelection.
@@ -5,10 +5,13 @@ import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -78,7 +81,7 @@ public abstract class WorldGuardInterface {
*/
public abstract RegionAccessSet getOwners(ProtectedRegion region);
// New flag system was introcuded in version 6.1.3, requiring different flag parsing
// New flag system was introduced in version 6.1.3, requiring different flag parsing
/**
* Get a flag from the name of a flag.
* @param flagName The name of the flag to get
@@ -104,4 +107,35 @@ public abstract class WorldGuardInterface {
* @throws InvalidFlagFormat When the input for the flag is incorrect
*/
public abstract RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat;
// WorldEdit Vector -> BlockVector3 refactor in WorldEdit 7 beta-2
/**
* Get the minimum point of a region.
* @param region The region to get it for
* @return Minimum point represented as vector
*/
public abstract Vector getMinimumPoint(ProtectedRegion region);
/**
* Get the maximum point of a region.
* @param region The region to get it for
* @return Maximum point represented as vector
*/
public abstract Vector getMaximumPoint(ProtectedRegion region);
/**
* Get the edges of a region (meant for polygon regions).
* @param region The region to get it for
* @return Points around the edge as vector array
*/
public abstract List<Vector> getRegionPoints(ProtectedRegion region);
/**
* Create a CuboidRegion.
* @param name Name to use in WorldEdit
* @param min Minimum point
* @param max Maximum point
* @return CuboidRegion
*/
public abstract ProtectedCuboidRegion createCuboidRegion(String name, Vector min, Vector max);
}
@@ -4,41 +4,49 @@
<artifactId>areashop-worldedit-7</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldEdit 7</name>
<version>WorldEdit-7</version>
<version>latest</version>
<description>
World Edit compatibility handler
- Deprecated usages on 7.2.0
- Compiles against 7.0.1, 7.1.0-SNAPSHOT, 7.2.0-SNAPSHOT
</description>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<version>latest</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<scope>system</scope>
<version>any</version>
<systemPath>${project.basedir}/../dependencies/worldedit-bukkit-7.0.0-beta-01.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<scope>system</scope>
<version>any</version>
<systemPath>${project.basedir}/../dependencies/worldguard-legacy-7.0.0-beta01.jar</systemPath>
</dependency>
</dependencies>
</project>
@@ -1,14 +1,12 @@
package me.wiefferink.areashop.handlers;
package me.wiefferink.areashop.handlers.worldedit.v7;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
@@ -18,9 +16,9 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.io.Closer;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@@ -39,15 +37,14 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class WorldEditHandler7 extends WorldEditInterface {
public class WorldEditHandler extends WorldEditInterface {
public WorldEditHandler7(AreaShopInterface pluginInterface) {
public WorldEditHandler(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public WorldEditSelection getPlayerSelection(Player player) {
CuboidRegionSelector s;
try {
Region region = pluginInterface.getWorldEdit().getSession(player).getSelection(BukkitAdapter.adapt(player.getWorld()));
return new WorldEditSelection(
@@ -63,10 +60,13 @@ public class WorldEditHandler7 extends WorldEditInterface {
@Override
public boolean restoreRegionBlocks(File rawFile, GeneralRegionInterface regionInterface) {
File file = null;
for (ClipboardFormat format : ClipboardFormats.getAll()) {
for (String extension : format.getFileExtensions()) {
if (new File(rawFile.getAbsolutePath() + "." + extension).exists()) {
file = new File(rawFile.getAbsolutePath() + "." + extension);
ClipboardFormat format = null;
for (ClipboardFormat formatOption : ClipboardFormats.getAll()) {
for (String extension : formatOption.getFileExtensions()) {
File fileOption = new File(rawFile.getAbsolutePath() + "." + extension);
if (fileOption.exists()) {
file = fileOption;
format = formatOption;
}
}
}
@@ -74,6 +74,7 @@ public class WorldEditHandler7 extends WorldEditInterface {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", schematic file does not exist: " + rawFile.getAbsolutePath());
return false;
}
pluginInterface.debugI("Trying to restore region", regionInterface.getName(), "from file", file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if(regionInterface.getName() != null) {
@@ -83,22 +84,18 @@ public class WorldEditHandler7 extends WorldEditInterface {
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
return false;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
editSession.enableQueue();
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit() // WARNING Deprecated in 7.2.0!
.getEditSessionFactory()
.getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
ProtectedRegion region = regionInterface.getRegion();
// Get the origin and size of the region
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
BlockVector3 origin = BlockVector3.at(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
// Read the schematic and paste it into the world
try(Closer closer = Closer.create()) {
FileInputStream fis = closer.register(new FileInputStream(file));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(file);
if (clipboardFormat == null) {
pluginInterface.getLogger().warning("WorldEdit could not detect format type of the schematic file:" + file.getAbsolutePath() + ", try updating WorldEdit");
return false;
}
ClipboardReader reader = clipboardFormat.getReader(bis);
ClipboardReader reader = format.getReader(bis);
//WorldData worldData = world.getWorldData();
LocalSession session = new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
@@ -124,7 +121,7 @@ public class WorldEditHandler7 extends WorldEditInterface {
if(region.getType() != RegionType.CUBOID) {
copy.setSourceMask(new Mask() {
@Override
public boolean test(Vector vector) {
public boolean test(BlockVector3 vector) {
return region.contains(vector);
}
@@ -147,13 +144,26 @@ public class WorldEditHandler7 extends WorldEditInterface {
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
return false;
}
editSession.flushQueue();
editSession.close();
return true;
}
@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
file = new File(file.getAbsolutePath() + "." + BuiltInClipboardFormat.SPONGE_SCHEMATIC.getPrimaryFileExtension());
ClipboardFormat format = ClipboardFormats.findByAlias("sponge");
if(format == null) {
// Sponge format does not exist, try to select another one
for(ClipboardFormat otherFormat : ClipboardFormats.getAll()) {
format = otherFormat;
}
if(format == null) {
pluginInterface.getLogger().warning("Cannot find a format to save a schematic in, no available formats!");
return false;
}
}
file = new File(file.getAbsolutePath() + "." + format.getPrimaryFileExtension());
pluginInterface.debugI("Trying to save region", regionInterface.getName(), " to file", file.getAbsolutePath(), "with format", format.getName());
com.sk89q.worldedit.world.World world = null;
if(regionInterface.getWorld() != null) {
world = BukkitAdapter.adapt(regionInterface.getWorld());
@@ -162,7 +172,10 @@ public class WorldEditHandler7 extends WorldEditInterface {
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
return false;
}
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit() // WARNING Deprecated in 7.2.0!
.getEditSessionFactory()
.getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
// Create a clipboard
CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
@@ -178,7 +191,7 @@ public class WorldEditHandler7 extends WorldEditInterface {
try(Closer closer = Closer.create()) {
FileOutputStream fos = closer.register(new FileOutputStream(file));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(bos));
ClipboardWriter writer = closer.register(format.getWriter(bos));
writer.write(clipboard);
} catch(IOException e) {
pluginInterface.getLogger().warning("An error occured while saving schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
@@ -1,44 +1,47 @@
<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>
<artifactId>areashop-worldguard-6_1_3</artifactId>
<artifactId>areashop-worldguard-7</artifactId>
<packaging>jar</packaging>
<name>AreaShop WorldGuard 6_1_3</name>
<version>WorldGuard-6_1_3</version>
<name>AreaShop WorldGuard 7</name>
<version>latest</version>
<parent>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<version>parent</version>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>AreaShopInterface</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-worldguard-6</artifactId>
<version>WorldGuard-6</version>
<type>jar</type>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<scope>provided</scope>
<version>7.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>6.1.3-SNAPSHOT</version>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.wiefferink</groupId>
<artifactId>areashop-interface</artifactId>
<version>latest</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
</project>
@@ -1,40 +1,47 @@
package me.wiefferink.areashop.handlers;
package me.wiefferink.areashop.handlers.worldguard.v7;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.wiefferink.areashop.interfaces.AreaShopInterface;
import me.wiefferink.areashop.interfaces.RegionAccessSet;
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class WorldGuardHandler6 extends WorldGuardInterface {
public class WorldGuardHandler extends WorldGuardInterface {
public WorldGuardHandler6(AreaShopInterface pluginInterface) {
public WorldGuardHandler(AreaShopInterface pluginInterface) {
super(pluginInterface);
}
@Override
public RegionManager getRegionManager(World world) {
return WorldGuardPlugin.inst().getRegionManager(world);
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
}
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
Set<ProtectedRegion> result = new HashSet<>();
Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
BlockVector3 vector = BlockVector3.at(location.getX(), location.getY(), location.getZ());
for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
if(region.contains(vector)) {
result.add(region);
@@ -43,40 +50,6 @@ public class WorldGuardHandler6 extends WorldGuardInterface {
return result;
}
@Override
public void setOwners(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getOwners().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setOwners(defaultDomain);
}
}
@Override
public void setMembers(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getMembers().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setMembers(defaultDomain);
}
}
@Override
public RegionAccessSet getMembers(ProtectedRegion region) {
RegionAccessSet result = new RegionAccessSet();
result.getGroupNames().addAll(region.getMembers().getGroups());
result.getPlayerNames().addAll(region.getMembers().getPlayers());
result.getPlayerUniqueIds().addAll(region.getMembers().getUniqueIds());
return result;
}
@Override
public RegionAccessSet getOwners(ProtectedRegion region) {
RegionAccessSet result = new RegionAccessSet();
result.getGroupNames().addAll(region.getOwners().getGroups());
result.getPlayerNames().addAll(region.getOwners().getPlayers());
result.getPlayerUniqueIds().addAll(region.getOwners().getUniqueIds());
return result;
}
/**
* Build a DefaultDomain from a RegionAccessSet.
* @param regionAccessSet RegionAccessSet to read
@@ -100,6 +73,22 @@ public class WorldGuardHandler6 extends WorldGuardInterface {
return owners;
}
@Override
public void setOwners(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getOwners().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setOwners(defaultDomain);
}
}
@Override
public void setMembers(ProtectedRegion region, RegionAccessSet regionAccessSet) {
DefaultDomain defaultDomain = buildDomain(regionAccessSet);
if(!region.getMembers().toUserFriendlyString().equals(defaultDomain.toUserFriendlyString())) {
region.setMembers(defaultDomain);
}
}
@Override
public boolean containsMember(ProtectedRegion region, UUID player) {
return region.getMembers().contains(player);
@@ -110,18 +99,62 @@ public class WorldGuardHandler6 extends WorldGuardInterface {
return region.getOwners().contains(player);
}
@Override
public RegionAccessSet getMembers(ProtectedRegion region) {
RegionAccessSet result = new RegionAccessSet();
result.getGroupNames().addAll(region.getMembers().getGroups());
result.getPlayerNames().addAll(region.getMembers().getPlayers());
result.getPlayerUniqueIds().addAll(region.getMembers().getUniqueIds());
return result;
}
@Override
public RegionAccessSet getOwners(ProtectedRegion region) {
RegionAccessSet result = new RegionAccessSet();
result.getGroupNames().addAll(region.getOwners().getGroups());
result.getPlayerNames().addAll(region.getOwners().getPlayers());
result.getPlayerUniqueIds().addAll(region.getOwners().getUniqueIds());
return result;
}
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
return DefaultFlag.fuzzyMatchFlag(flagName);
return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
return flag.parseInput(WorldGuardPlugin.inst(), null, input);
return flag.parseInput(FlagContext.create().setInput(input).build());
}
@Override
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
return flag.parseInput(WorldGuardPlugin.inst(), null, input);
return flag.parseInput(FlagContext.create().setInput(input).build());
}
@Override
public Vector getMinimumPoint(ProtectedRegion region) {
BlockVector3 min = region.getMinimumPoint();
return new Vector(min.getX(), min.getY(), min.getZ());
}
@Override
public Vector getMaximumPoint(ProtectedRegion region) {
BlockVector3 min = region.getMaximumPoint();
return new Vector(min.getX(), min.getY(), min.getZ());
}
@Override
public List<Vector> getRegionPoints(ProtectedRegion region) {
List<Vector> result = new ArrayList<>();
for (BlockVector2 point : region.getPoints()) {
result.add(new Vector(point.getX(), 0,point.getZ()));
}
return result;
}
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, Vector corner1, Vector corner2) {
return new ProtectedCuboidRegion(name, BlockVector3.at(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), BlockVector3.at(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
}
+12
View File
@@ -0,0 +1,12 @@
# ╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
# ║ Language file of the AreaShop plugin created by NLThijs48, Github can be found at https://github.com/NLthijs48/AreaShop
# ║ {language} language file, plugin version {version}, {translated}/{messages} messages are translated ({translatedPercent}%){source}
# ║
# ║ This file will be overwritten at each startup/reload of the plugin, if you want to change anything then do the following:
# ║ 1: Make a copy of this file
# ║ 2: Rename it to `servername.yml`
# ║ 3: Change the `language` setting in config.yml to `servername`, do not include `.yml`
# ║ 4: Change the messages in the new file to your liking
# ║ 5: Use `/as reload`or reload/restart your server to see the changes
# ╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
+33 -24
View File
@@ -4,7 +4,7 @@
<groupId>me.wiefferink</groupId>
<artifactId>areashop-parent</artifactId>
<packaging>pom</packaging>
<version>parent</version>
<version>1.0</version>
<name>AreaShop Parent</name>
<url>https://github.com/NLthijs48/AreaShop</url>
@@ -27,14 +27,6 @@
</ciManagement>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo-wg</id>
<url>http://maven.sk89q.com/artifactory/repo/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
@@ -47,39 +39,55 @@
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
</repository>
<repository>
<id>mvn-repo</id>
<url>https://mvnrepository.com/artifact/org.bstats/bstats-bukkit</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<build.number>#CUSTOM</build.number>
<bukkit.version>1.8-R0.1-SNAPSHOT</bukkit.version>
<!--build.number>#CUSTOM</build.number-->
</properties>
<modules>
<module>WorldGuard 5</module>
<module>WorldGuard 6</module>
<module>WorldGuard 6_1_3</module>
<module>WorldGuard 7</module>
<module>Interfaces</module>
<module>WorldEdit 5</module>
<module>WorldEdit 6</module>
<module>WorldEdit 7</module>
<module>hooks/areashop-interface</module>
<!-- FAWE Compat -->
<module>hooks/areashop-fawe-1-15</module>
<!-- World Edit Compat -->
<module>hooks/areashop-worldedit-7</module>
<!-- World Guard Compat -->
<module>hooks/areashop-worldguard-7</module>
<module>AreaShop</module>
</modules>
<build>
<plugins>
<defaultGoal>clean package</defaultGoal>
<!--plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<version>3.1.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.6</version>
<version>8.29</version>
</dependency>
</dependencies>
<executions>
@@ -89,7 +97,8 @@
<configuration>
<configLocation>config/checkstyle.xml</configLocation>
<suppressionsLocation>config/checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>config/checkstyle.suppressions.file</suppressionsFileExpression>
<suppressionsFileExpression>config/checkstyle.suppressions.file
</suppressionsFileExpression>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
@@ -101,7 +110,7 @@
</execution>
</executions>
</plugin>
</plugins>
</plugins-->
</build>
</project>