Compare commits

...

205 Commits
v3.4.5 ... dev

Author SHA1 Message Date
ac9042bbe4 Various minor
New plugin updater and versioning
In game changelog
fix login teleporting
2017-08-09 15:05:13 +10:00
b280644661 Delete build 2017-08-09 15:01:16 +10:00
b924809c91 Fixes #1608 2017-08-03 23:13:04 +10:00
a913983d99 Add plot leave 2017-07-25 06:39:59 +10:00
3633576e03 Fix teleport for single plot worlds 2017-07-08 23:22:05 +10:00
73318f23a1 Fixes #1660 2017-07-08 21:56:15 +10:00
248751378b Fixes #1661 2017-07-08 21:50:47 +10:00
1918000668 Merge pull request #1645 from dordsor21/master
Lower TPS threshold please
2017-07-07 16:12:26 +10:00
9037b74720 Closes #1659 2017-07-07 16:11:46 +10:00
f6540bbfcb bypass owner check for download 2017-06-29 15:38:37 +10:00
507d0f19e4 Lower TPS threshold please 2017-06-24 16:11:52 +01:00
355e16fe92 Ignore searching top block for teleportation 2017-06-09 17:43:46 +10:00
2b1905889c Minor sponge fix 2017-05-16 13:20:28 +10:00
7ee67c8b41 Merge pull request #1599 from Gabscap/fix-min_height
Fix world.min_height setting
2017-05-03 14:58:16 +10:00
f8ab36b67c Fix world.min_height setting 2017-05-01 21:23:21 +02:00
b5ef5df20d * 2017-04-28 01:47:05 +10:00
509b1f1c3d Fixes #1593 2017-04-28 00:59:59 +10:00
bfe98f3285 Some claiming fixes 2017-04-20 14:12:40 +10:00
47915b8b86 Read sign on main thread 2017-04-20 01:09:52 +10:00
3c110bb125 Fixes #1585 2017-04-18 22:55:04 +10:00
a87fee1224 Merge pull request #1583 from manuelgu/patch-3
Added useSSL=false to JDBC connection URL
2017-04-17 22:28:20 +10:00
757b9c695f Fix compile 2017-04-17 19:11:55 +10:00
193948d4fd Fix claim 2017-04-17 11:56:10 +10:00
b616951e23 Added useSSL=false to JDBC connection URL
This is required according to MySQL 5.5.45+, 5.6.26+ and 5.7.6+.
2017-04-16 22:17:17 +02:00
37977f1da4 Check database before claiming plot 2017-04-15 12:40:23 +10:00
7eb7cd9b53 Ensure world loading occurs on the main thread 2017-04-11 01:49:01 +10:00
ddfcc5b077 Player login tweaks 2017-04-10 09:06:44 +10:00
9f6bf14649 Log when a plot is created/deleted 2017-04-09 17:10:23 +10:00
f99994737c Print error when failing to close database 2017-04-09 17:09:06 +10:00
6e0ade4f63 Some sponge fixes 2017-04-07 08:25:08 +10:00
c1a6c75ebe * 2017-04-04 08:07:54 +10:00
022372e9b7 Fixes #1534 + various
Auto world loading/unloading
Auto player teleporting on login
2017-04-04 07:59:36 +10:00
3f54ba23c2 Fix world delete 2017-04-01 04:36:45 +11:00
e8672df760 Add Gitter badge (#1565) 2017-03-27 12:03:33 -04:00
5d6f4c6668 Some plot area restructuring 2017-03-23 11:10:29 +11:00
a07ed4eafd * 2017-03-18 00:50:43 +11:00
5262ff665a Fix door break 2017-03-18 00:49:41 +11:00
1129a80329 Fixes #1510 2017-03-17 17:41:58 +11:00
a628c5927f Fixes #1560 2017-03-17 16:40:29 +11:00
478ad9670b Fixes #1476 2017-03-16 14:15:00 +11:00
8e3407505a Recover on database error
Might resolve #1476
2017-03-15 02:10:57 +11:00
e208d7f72a Fix mass purge 2017-03-15 01:28:02 +11:00
b0df79bb80 Break up purge task 2017-03-15 00:16:27 +11:00
411c75b219 Fixes #1556 Close #1555 2017-03-14 01:56:14 +11:00
491cc50440 Fixes #1528 2017-03-13 18:45:37 +11:00
e9723f5be1 Fixes #1532 2017-03-13 18:38:58 +11:00
a015039dad Fixes #1535
Set `misc_spawn_unowned`
2017-03-13 18:36:40 +11:00
a0640a1e66 Fixes #1536 2017-03-13 18:12:38 +11:00
0b6d2d3dd6 Fixes #1538 2017-03-13 18:07:48 +11:00
ad11ad3472 Fixes #1517 2017-03-13 18:02:05 +11:00
93717e670c Use InteractBlockEvent
For some reason sponge was calling the event twice, the second with a
relative location, which makes no sense. Switching to a different event
works.
2017-03-13 17:34:44 +11:00
38a33248e7 Send message on perm check 2017-03-13 09:04:40 +11:00
52496af9a1 Fix road interact on sponge 2017-03-13 07:16:16 +11:00
4d4950090d Fix 1.7 block placer 2017-03-10 07:07:50 +11:00
c8c144b6da Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2017-03-08 16:51:29 +11:00
e94adb04ea Add maven repo
closes #1394
2017-03-08 16:51:01 +11:00
395c1c743f Merge pull request #1537 from HexagonMC/master
Fix plot teleport.
2017-03-06 15:40:28 +11:00
b1fb01303d Fix plot teleport.
Fixes https://github.com/IntellectualSites/PlotSquared/issues/1302
2017-02-20 20:29:43 +01:00
aa7b770c03 tweak highest block check 2017-01-31 16:45:02 +11:00
e7990a06e2 Check player name for invalid character first 2017-01-30 19:42:16 +11:00
88f5e5b0bc Sort player names 2017-01-15 22:51:54 +11:00
47db330764 Fix title global flag 2017-01-13 08:05:13 +11:00
35ebc8c830 Permission check fix 2017-01-13 07:22:28 +11:00
686a6c499f Fixes #1502 2017-01-11 07:53:53 +11:00
cb6d839214 Possible fix for #1476
Changes database load to prefer the latest entry over older ones.

Some previous changes may fix connections dropping, which resulted in
(incorrect) fixes being attempted by the plugin.
2017-01-11 07:21:36 +11:00
6af96f43d4 Optimize schematic paste 2016-12-31 17:23:46 +11:00
e3eccfd476 Fix debugpaste 2016-12-31 17:23:38 +11:00
15d4b6d34b Bump spigot version 2016-12-29 07:23:51 +11:00
c3e2421d51 Merge pull request #1492 from c7w/master
Update s_chinese.yml
2016-12-25 17:32:36 +11:00
c7w
f7793f027c Update s_chinese.yml 2016-12-25 14:30:32 +08:00
6ec96870c0 Fix SO 2016-12-23 15:33:19 +11:00
a843203ca3 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java
2016-12-15 17:42:51 +11:00
3240fc9559 Exit plot on unclaim
Fixes #1471
2016-12-15 17:37:26 +11:00
5fd1486cec Merge pull request #1478 from EvilOlaf/patch-2
Update ISSUE_TEMPLATE.md
2016-12-13 01:44:37 +11:00
d648148f51 Update ISSUE_TEMPLATE.md 2016-12-12 15:42:00 +01:00
d554dab8c8 Fix potential NPE with claiming 2016-12-10 14:33:48 -05:00
9ad45750ee Unclaiming a plot should call plotExit() 2016-12-09 20:58:05 -05:00
a554ae5633 Potential fix for commands 2016-12-09 16:58:32 -05:00
7b1c4a5042 Check border when claiming a plot
Also fixes #1467
2016-12-10 01:09:07 +11:00
9fc464e896 Shorter border teleportation 2016-12-10 00:44:42 +11:00
bec11b244e Use the correct plot id 2016-12-10 00:26:40 +11:00
dc94418b51 Only expand border to current plot. 2016-12-09 23:52:48 +11:00
72ab10c079 remove debug 2016-12-03 23:08:10 +11:00
f50d32f06b * 2016-12-02 17:17:16 +11:00
6cc744a2e6 Fixes #1444 2016-12-02 17:16:19 +11:00
e40dc37f89 Fix versioning messup. 2016-12-01 21:56:19 -05:00
7e34d9e20a Fix title logic 2016-11-30 21:26:52 +11:00
c891abce09 Allow added players to use frost walker
Properly fixes #1438
2016-11-30 20:46:48 +11:00
2b561f2efa Rename to ice-form 2016-11-30 19:06:03 +11:00
dea0a452df Add fading 1.11 titles 2016-11-30 16:28:50 +11:00
81418b07a8 Fixes #1438 (unless other things call this event) 2016-11-30 16:15:20 +11:00
a3c1ad3ec8 Fixes #1449 2016-11-30 16:10:08 +11:00
7c6c19ba63 Fixes #740 2016-11-30 16:07:16 +11:00
2e23ae0811 Fixes #1243 2016-11-30 16:00:47 +11:00
28e7f5bc08 Fixes #1349
Non standard plot managers/areas not supported
2016-11-30 15:57:24 +11:00
7a1417dc56 Fixes #1415 2016-11-30 15:45:28 +11:00
e7fa9e01be Fixes #1419 2016-11-30 15:43:23 +11:00
93414d54c1 Fixes #1453 2016-11-30 15:41:08 +11:00
5642fd3899 Fixes #1359
plots.chat.color
and
PLOT_CHAT_SPY_FORMAT
2016-11-30 15:36:13 +11:00
f3d950f6e1 Fix flame enchant damaging entities 2016-11-30 15:03:48 +11:00
95f8aaa2fe this could be here? 2016-11-30 13:10:36 +11:00
878010255c Java 9 2016-11-28 18:02:03 +11:00
8edc357d01 Fixed #1448 2016-11-27 01:26:06 -05:00
588639d9c2 3.5.1 Start 2016-11-27 01:08:35 -05:00
ff401b65c4 3.5.0 Release 2016-11-26 18:02:39 -05:00
11913bfbe5 Fix compile issue 2016-11-26 17:53:44 -05:00
62b353f82d Various Sponge changes
- many improvements
- inventory utilities broke when updating to Sponge API 6.0.0
2016-11-26 16:49:13 -05:00
8d442f58d4 Fixes #1445 2016-11-26 12:05:08 -05:00
5cbd2f44bd Update Sponge Gradle 2016-11-26 11:55:59 -05:00
dc673f9715 Fixed #1440 , Fixed #1446 2016-11-26 11:55:38 -05:00
deb5441bcf *Fix compile error 2016-11-24 11:05:28 +11:00
8ebf71c87f DB fix 2016-11-24 10:19:00 +11:00
9fd53af483 Add world argument 2016-11-23 15:47:18 +11:00
fb729df59e Setting to sort plots by area 2016-11-23 15:36:25 +11:00
ce6e1be13e Fix maven dependencies (#1439)
* Fixes

* Fix wrong version
2016-11-21 09:59:11 -05:00
e126054053 Fixes #1429 Removes duplicate aliases. 2016-11-20 22:29:14 -05:00
77281017d4 Fixes #1428 , Fixes #1431 2016-11-20 22:24:27 -05:00
e0208aa369 Fix plot help category pagination 2016-11-18 10:49:03 +11:00
fdc42a3d5c Seems the new spigot 1.11 sqlite driver has issues parsing timestamps, no idea why. 2016-11-18 09:08:41 +11:00
3070557a3a Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-11-13 22:18:11 +11:00
2ec0b55482 Fix database lock error 2016-11-13 22:17:17 +11:00
10dd9b6371 Merge pull request #1424 from c7w/master
translation
2016-11-13 06:41:25 +11:00
c7w
1ac0a7dad0 translation
translation of chinese
2016-11-12 12:52:43 +08:00
f8b1fcffa1 Fix worldedit mask area 2016-11-12 00:14:12 +11:00
17762f5ae7 Tweak delete message 2016-11-09 00:13:46 +11:00
1d7cdde84a Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-11-02 04:28:11 +11:00
c950b0021f Notify inbox permission 2016-11-02 04:27:52 +11:00
e4bc2b30b1 Update ISSUE_TEMPLATE.md (#1409) 2016-10-28 10:15:38 -04:00
e0c4c944bb Merge remote-tracking branch 'origin/master' 2016-10-26 23:01:01 -04:00
dd09ef18e6 Add missing gradle batch
Signed-off-by: MattBDev <mattbdev@outlook.com>
2016-10-26 23:00:43 -04:00
68011f43cd Fixes #1390 2016-10-21 03:51:27 +11:00
93c4854454 Add misc-interact flag 2016-10-18 05:03:14 +11:00
e594227d95 Fix some height issues 2016-10-14 16:56:28 +11:00
d6be5703ae Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-10-14 15:14:35 +11:00
c97544d083 Minor fixes 2016-10-14 15:14:08 +11:00
a05fd2dd11 Fix #1386
Signed-off-by: MattBDev <mattbdev@outlook.com>
2016-10-10 00:18:35 -04:00
5978c9c3c0 Fix center 2016-10-03 00:56:27 +11:00
5d3e096501 *Fix the toggle 2016-10-03 00:56:26 +11:00
39e99c0593 Merge pull request #1381 from filoghost/patch-1
Fix permission checks being ignored
2016-10-02 14:08:22 +11:00
cd33aaa1b6 Fix permission checks being ignored 2016-10-01 21:35:57 +02:00
0244c0241c Trim deletes expired plots 2016-10-01 20:17:50 +10:00
5ed2190cb3 Fixes #1369 2016-09-30 23:32:49 +10:00
c533f0bae9 Fix area removal 2016-09-30 17:05:18 +10:00
cd2b6c8ccc Fixes #1379 2016-09-30 17:04:06 +10:00
6f2c7de0ff Minor fix to conversion 2016-09-30 16:46:10 +10:00
62373c0737 * 2016-09-30 16:15:15 +10:00
499120963a Streamline PlotMe conversion
Use reflection to disable PlotMe and forward DefaultGenerator to
PlotSquared
Fix border material copying from plotme config
You no longer need to delete the PlotMe jar for conversion
Fix some outdated messages
2016-09-30 16:14:35 +10:00
f1d581a8d8 Fixes #1377 2016-09-30 15:29:50 +10:00
6074fc8033 Nukkit generator fixes 2016-09-30 14:26:20 +10:00
e4d7270c28 Fix some merged plot events 2016-09-30 03:30:34 +10:00
b6df07f723 Add snow-form flag 2016-09-27 01:38:59 +10:00
177b33154f Multiple
Fixes #1362
Fixes border id for PlotMe converter
2016-09-27 00:56:39 +10:00
6bf2fbcfcf Command tweaks 2016-09-26 18:33:27 +10:00
12f8861d07 Various
externalize strings
plotme conversion fixes
2016-09-26 18:31:08 +10:00
c99e23bd3c Fixes #1367 2016-09-25 18:48:38 +10:00
1b6d08b3fe Fixes #1365 2016-09-25 18:43:53 +10:00
3b4490c1c6 Fixes #1366 2016-09-25 18:42:05 +10:00
04c011164a Add near cmd 2016-09-25 18:06:20 +10:00
86b776f742 Nukkit perms 2016-09-25 16:49:51 +10:00
61022b717a Fixes #1360 2016-09-21 13:42:59 +10:00
9e5af7a642 Possible fix for redstone in merged plots 2016-09-20 23:49:22 +10:00
364b4347d1 Fix area id parsing 2016-09-19 14:18:47 +10:00
d89274ce09 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
2016-09-17 16:03:57 +10:00
264114332b Let generator be up to the implementation 2016-09-17 16:02:05 +10:00
a4363bdb27 Fix #1355
There is the possibility this will cause issues with sponge

Signed-off-by: MattBDev <mattbdev@outlook.com>
2016-09-14 19:27:30 -04:00
8e7e5dcb25 Cleanup
Signed-off-by: MattBDev <mattbdev@outlook.com>
2016-09-14 12:16:22 -04:00
56227a6d7d Fixes #1351 2016-09-14 10:21:14 +10:00
63259ec269 Merge pull request #1352 from MisterErwin/master
A (possible) fix to #1351
2016-09-14 10:17:11 +10:00
0286a7b046 Fixes #1131 2016-09-14 10:12:53 +10:00
b6dac54677 Code cleaning and Gradle Update
Updated gradle wrapper to 3.0
Updated Gradle files for Nukkit
Added/cleaned minor Nukkit code
Removed duplicate TitleManagement code

Signed-off-by: MattBDev <mattbdev@outlook.com>
2016-09-13 18:10:01 -04:00
bf1d487508 A (possible) fix to #1351 2016-09-12 17:05:13 +02:00
a95b68b73c Add villager-interact flag 2016-09-09 15:17:37 +10:00
85ff8bf639 Minor tweaks 2016-09-07 00:28:01 +10:00
0557671b80 Recover from third party generator error 2016-09-04 14:22:01 +10:00
d75ab130da Sponge fixes 2016-09-02 15:58:24 +10:00
6a12a6ba64 print chat to console
Fixes #1339
2016-09-02 15:47:19 +10:00
22901bf9f2 Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-09-01 16:57:52 +10:00
07ee19b4bb Fixes #1337 2016-08-31 19:09:17 +10:00
27c21b9ab6 Fix #1321 2016-08-30 21:50:52 -04:00
da7a12bc00 Fixes #1234 2016-08-29 16:21:14 +10:00
3b73b2e9d8 Fix grant check 2016-08-29 15:33:26 +10:00
970c80cb15 Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-08-29 15:01:27 +10:00
dd665ed9ce Fence rotation 2016-08-29 15:01:19 +10:00
572da7d436 Merge pull request #1332 from manuelgu/patch-2
Might resolve #1331
2016-08-29 14:41:48 +10:00
ab05b026e9 Merge pull request #1335 from Herocraft/fix/vault-repo
Switch Vault repository to the real one
2016-08-29 12:19:48 +10:00
2fcb59f8cf Switch Vault repository to the real one 2016-08-28 18:26:11 -07:00
20250bc989 Might resolve #1331
Wasn't able to reproduce the issue
2016-08-28 20:14:58 +02:00
5e4798165b Merge pull request #1330 from MinelinkNetwork/fix-pom
Fix Spigot artifact in POM
2016-08-28 18:26:57 +10:00
7fc3fb097e Fix Spigot artifact in POM
Use the correct groupId, artifactId and version of Spigot dependency
installed by BuildTools
2016-08-28 01:13:21 -07:00
3a08e5c091 Merge pull request #1326 from SupremeMortal/SupremeMortal-patch-1
Update Non-existent Repo
2016-08-28 00:52:04 +10:00
50770a78d7 Fixed mistake 2016-08-27 14:09:03 +01:00
1266eed86a Add Replacement Repo For Vault 2016-08-27 14:08:35 +01:00
c0996299b4 Remove non-existent Repo
"nexus.theyeticave.net" does not exist anymore.
2016-08-27 14:03:41 +01:00
90d48b2cd0 Fixes #1289 2016-08-26 13:54:22 +10:00
a95d18499e Fixes #1285 2016-08-26 13:19:42 +10:00
61d00e51ef Fixes #1303 2016-08-26 03:02:50 +10:00
b5349e16f0 Fixes #1305
Just teleports the player further back
Combine move/tp since tp extends move
2016-08-26 02:31:50 +10:00
a801127036 Merge pull request #1301 from MisterErwin/master
Calling events when players are removed from plots & correct calling of Member & Trusted events
2016-08-26 02:02:40 +10:00
2806f8b20c Fixes #1307 2016-08-26 01:36:35 +10:00
7d11147836 Add Lazzy "Offline -> Offline Lowercase" conversion 2016-08-20 21:40:54 +10:00
74a6df1fa7 Update README.md 2016-08-20 00:26:53 -04:00
bc0c0abe7e Fix NPE 2016-08-19 12:16:13 +10:00
56907e4580 Version Bump
3.4.6-SNAPSHOT
2016-08-18 10:38:06 -04:00
634802ef98 Got rid of that auto-optimize-imports option 2016-08-08 23:20:31 +02:00
37e4a652dd Now calling the respective events when a user is removed from a plot.
And switched the event calling of adding Helpers and Trusted players. (Correct me if that was wrong)
2016-08-08 22:45:08 +02:00
245 changed files with 12937 additions and 4210 deletions

View File

@ -1,12 +1,22 @@
# Bug report template (Follow this template unless you are making a feature request.)
**Debug paste link**:
# Bug report template
<!--- In order to create a valid issue report you have to follow this template. -->
<!--- Incomplete reports might be marked as invalid. -->
<!--- You may remove it if you are posting a feature request. -->
**Debug paste link:**
<!--- Enter /plot debugpaste in game or in your console and copy the output here -->
**Description of the problem:**
**How to replicate:**
<!--- If you can reproduce the issue please tell us as detailed as possible step by step how to do that -->
**Checklist**:
<!-- Make sure you have completed the following steps (put an "X" between of brackets): -->
- [] I included a `/plot debugpaste` link
- [] I made sure there are no duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues?utf8=%E2%9C%93&q=is%3Aissue)
- [] I made sure I am using an up-to-date version of PlotSquared
- [] I Made sure the bug/error is not caused by any other plugin
**Description of the problem:**
**How to replicate**:
Make sure you've completed the following steps (put an X between of brackets):
- [] Include `/plot debugpaste`
- [] Made sure there aren't duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues?utf8=%E2%9C%93&q=is%3Aissue)
- [] Made sure you're using an updated version of PlotSquared
- [] Made sure the bug/error isn't caused by any other plugin

12
.gitignore vendored
View File

@ -1,13 +1,14 @@
### Others ###
*.bat
*.cmd
*.sh
*.prefs
Sponge/build
Core/build
Bukkit/build
Nukkit/build
### Maven ###
/mvn
/target/lib
/target/maven-archiver
/target/classes
@ -131,4 +132,11 @@ local.properties
# STS (Spring Tool Suite)
.springBeans
/target/
/target/
Nukkit/build/classes/
Nukkit/build/dependency-cache/
checkstyle.xml
classes/
p2error.txt
*.bat
Nukkit/build/resources/main/plugin.yml

View File

@ -2,12 +2,15 @@ repositories {
maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"}
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/"}
maven {url "http://nexus.hc.to/content/repositories/pub_releases"}
mavenLocal()
}
dependencies {
compile project(':Core')
compile 'org.spigotmc:spigot-api:1.10.2-R0.1-SNAPSHOT'
compile 'net.milkbowl.vault:VaultAPI:1.6'
compile 'org.spigotmc:spigot-api:1.11.2-R0.1-SNAPSHOT'
compile("net.milkbowl.vault:VaultAPI:1.6") {
exclude module: 'bukkit'
}
}
sourceCompatibility = 1.7

View File

@ -12,10 +12,15 @@ import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager;
@ -45,7 +50,7 @@ import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
import com.plotsquared.bukkit.listeners.PlayerEvents_1_9;
import com.plotsquared.bukkit.listeners.PlotPlusListener;
import com.plotsquared.bukkit.listeners.WorldEvents;
import com.plotsquared.bukkit.titles.DefaultTitle_19;
import com.plotsquared.bukkit.titles.DefaultTitle_111;
import com.plotsquared.bukkit.util.BukkitChatManager;
import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitCommand;
@ -57,6 +62,7 @@ import com.plotsquared.bukkit.util.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitVersion;
import com.plotsquared.bukkit.util.Metrics;
import com.plotsquared.bukkit.util.SendChunk;
import com.plotsquared.bukkit.util.SetGenCB;
@ -71,8 +77,18 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.sk89q.worldedit.WorldEdit;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
@ -84,20 +100,62 @@ import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
private static ConcurrentHashMap<String, Plugin> pluginMap;
static {
// Disable AWE as otherwise both fail to load
PluginManager manager = Bukkit.getPluginManager();
try {
Settings.load(new File("plugins/PlotSquared/config/settings.yml"));
if (Settings.Enabled_Components.PLOTME_CONVERTER) { // Only disable PlotMe if conversion is enabled
Field pluginsField = manager.getClass().getDeclaredField("plugins");
Field lookupNamesField = manager.getClass().getDeclaredField("lookupNames");
pluginsField.setAccessible(true);
lookupNamesField.setAccessible(true);
List<Plugin> plugins = (List<Plugin>) pluginsField.get(manager);
Iterator<Plugin> iter = plugins.iterator();
while (iter.hasNext()) {
if (iter.next().getName().startsWith("PlotMe")) {
iter.remove();
}
}
Map<String, Plugin> lookupNames = (Map<String, Plugin>) lookupNamesField.get(manager);
lookupNames.remove("PlotMe");
lookupNames.remove("PlotMe-DefaultGenerator");
pluginsField.set(manager, new ArrayList<Plugin>(plugins) {
@Override
public boolean add(Plugin plugin) {
if (plugin.getName().startsWith("PlotMe")) {
System.out.print("Disabling `" + plugin.getName() + "` for PlotMe conversion (configure in PlotSquared settings.yml)");
} else {
return super.add(plugin);
}
return false;
}
});
pluginMap = new ConcurrentHashMap<String, Plugin>(lookupNames) {
@Override
public Plugin put(String key, Plugin plugin) {
if (!plugin.getName().startsWith("PlotMe")) {
return super.put(key, plugin);
}
return null;
}
};
lookupNamesField.set(manager, pluginMap);
}
} catch (Throwable ignore) {}
}
public static WorldEdit worldEdit;
private int[] version;
private String name;
@Override
public int[] getServerVersion() {
@ -122,13 +180,52 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public void onEnable() {
if (pluginMap != null) {
pluginMap.put("PlotMe-DefaultGenerator", this);
}
this.name = getDescription().getName();
getServer().getName();
new PS(this, "Bukkit");
if (Settings.Enabled_Components.METRICS) {
new Metrics(this).start();
PS.log(C.PREFIX + "&6Metrics enabled.");
} else {
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS);
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName()));
}
if (Settings.Enabled_Components.WORLDS) {
TaskManager.IMP.taskRepeat(new Runnable() {
@Override
public void run() {
unload();
}
}, 20);
}
}
public void unload() {
PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
for (World world : Bukkit.getWorlds()) {
String name = world.getName();
PlotId id = PlotId.fromString(name);
if (id != null) {
Plot plot = area.getOwnedPlot(id);
if (plot != null) {
List<PlotPlayer> players = plot.getPlayersInPlot();
if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) {
for (Chunk chunk : world.getLoadedChunks()) {
chunk.unload(true, false);
if (System.currentTimeMillis() - start > 20) {
return;
}
}
Bukkit.unloadWorld(world, false);
}
}
}
}
}
}
@ -170,6 +267,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return getDescription().getVersion();
}
@Override
public String getPluginName() {
return name;
}
@Override
public void registerCommands() {
BukkitCommand bukkitCommand = new BukkitCommand();
@ -237,6 +339,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
case TIPPED_ARROW:
case ENDER_PEARL:
case ARROW:
case LLAMA_SPIT:
// managed elsewhere | projectile
continue;
case ITEM_FRAME:
@ -253,7 +356,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
case MINECART_MOB_SPAWNER:
case ENDER_CRYSTAL:
case MINECART_TNT:
case BOAT: {
case BOAT:
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
com.intellectualcrafters.plot.object.Location location = BukkitUtil.getLocation(entity.getLocation());
Plot plot = location.getPlot();
@ -277,7 +380,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} else {
continue;
}
}
case SMALL_FIREBALL:
case FIREBALL:
case DRAGON_FIREBALL:
@ -288,6 +390,20 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
case FALLING_BLOCK:
// managed elsewhere
continue;
case LLAMA:
case DONKEY:
case MULE:
case ZOMBIE_HORSE:
case SKELETON_HORSE:
case HUSK:
case ELDER_GUARDIAN:
case WITHER_SKELETON:
case STRAY:
case ZOMBIE_VILLAGER:
case EVOKER:
case EVOKER_FANGS:
case VEX:
case VINDICATOR:
case POLAR_BEAR:
case BAT:
case BLAZE:
@ -357,11 +473,20 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
HybridGen result = new HybridGen();
if (!PS.get().setupPlotWorld(world, id, result)) {
return null;
if (Settings.Enabled_Components.PLOTME_CONVERTER) {
initPlotMeConverter();
Settings.Enabled_Components.PLOTME_CONVERTER = false;
}
return (ChunkGenerator) result.specify();
IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) {
result = new SingleWorldGenerator();
} else {
result = PS.get().IMP.getDefaultGenerator();
if (!PS.get().setupPlotWorld(world, id, result)) {
return null;
}
}
return (ChunkGenerator) result.specify(world);
}
@Override
@ -370,25 +495,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
getServer().getPluginManager().registerEvents(main, this);
try {
getServer().getClass().getMethod("spigot");
Class.forName("org.bukkit.event.entity.EntitySpawnEvent");
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
} catch (NoSuchMethodException ignored) {
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
PS.debug("Not running Spigot. Skipping EntitySpawnListener event.");
}
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
} catch (Throwable e) {
e.printStackTrace();
}
}
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) {
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
try {
getServer().getPluginManager().registerEvents(new PlayerEvents183(), this);
} catch (Throwable e) {
e.printStackTrace();
}
}
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) {
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this);
} catch (Throwable e) {
@ -443,13 +569,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
PS.debug(SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
MainUtil.canSendChunk = false;
}
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) {
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
return QueueProvider.of(BukkitLocalQueue_1_9.class, BukkitLocalQueue.class);
}
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) {
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
return QueueProvider.of(BukkitLocalQueue_1_8_3.class, BukkitLocalQueue.class);
}
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
return QueueProvider.of(BukkitLocalQueue_1_8.class, BukkitLocalQueue.class);
}
return QueueProvider.of(BukkitLocalQueue_1_7.class, BukkitLocalQueue.class);
@ -462,18 +588,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public boolean initPlotMeConverter() {
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
return;
}
if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
return;
}
}
}, 20);
return Bukkit.getPluginManager().getPlugin("PlotMe") != null;
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
return true;
} else if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
return true;
}
return false;
}
@Override
@ -489,7 +609,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
return new BukkitPlotGenerator(world, gen);
} else {
return new BukkitPlotGenerator(new HybridGen());
return new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator());
}
}
@ -505,7 +625,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public UUIDHandlerImplementation initUUIDHandler() {
boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6);
boolean checkVersion = PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_7_6);
UUIDWrapper wrapper;
if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE) {
@ -529,17 +649,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
PS.log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
Settings.TITLES = false;
} else {
AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
AbstractTitle.TITLE_CLASS = new DefaultTitle_111();
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
Settings.UUID.NATIVE_UUID_PROVIDER = true;
}
}
if (Settings.UUID.OFFLINE) {
PS.log(C.PREFIX
+ " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
+ " &6" + getPluginName() + " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
+ "Bukkit");
} else {
PS.log(C.PREFIX + " &6PlotSquared is using online UUIDs");
PS.log(C.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
}
if (Settings.UUID.USE_SQLUUIDHANDLER) {
return new SQLUUIDHandler(wrapper);
@ -573,6 +693,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
}
@Override
public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen();
}
@Override
public InventoryUtil initInventoryUtil() {
return new BukkitInventoryUtil();
@ -590,7 +715,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
if (world == null) {
// create world
ConfigurationSection worldConfig = PS.get().worlds.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", "PlotSquared");
String manager = worldConfig.getString("generator.plugin", getPluginName());
SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = worldConfig.getString("generator.init", manager);
@ -599,17 +724,18 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
setup.step = new ConfigurationNode[0];
setup.world = worldName;
SetupUtils.manager.setupWorld(setup);
world = Bukkit.getWorld(worldName);
} else {
try {
if (!PS.get().hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
} catch (Exception ignored) {
PS.log("Failed to reload world: " + world);
PS.log("Failed to reload world: " + world + " | " + ignored.getMessage());
Bukkit.getServer().unloadWorld(world, false);
return;
}
}
world = Bukkit.getWorld(worldName);
ChunkGenerator gen = world.getGenerator();
if (gen instanceof BukkitPlotGenerator) {
PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
@ -664,7 +790,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
@Override
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
public GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(generator);
}

View File

@ -19,93 +19,93 @@ import java.util.Collection;
*/
public final class ArrayWrapper<E> {
/**
* Creates an array wrapper with some elements.
*
* @param elements The elements of the array.
*/
public ArrayWrapper(E... elements) {
setArray(elements);
}
/**
* Creates an array wrapper with some elements.
*
* @param elements The elements of the array.
*/
public ArrayWrapper(E... elements) {
setArray(elements);
}
private E[] _array;
private E[] _array;
/**
* Retrieves a reference to the wrapped array instance.
*
* @return The array wrapped by this instance.
*/
public E[] getArray() {
return _array;
}
/**
* Retrieves a reference to the wrapped array instance.
*
* @return The array wrapped by this instance.
*/
public E[] getArray() {
return _array;
}
/**
* Set this wrapper to wrap a new array instance.
*
* @param array The new wrapped array.
*/
public void setArray(E[] array) {
Validate.notNull(array, "The array must not be null.");
_array = array;
}
/**
* Set this wrapper to wrap a new array instance.
*
* @param array The new wrapped array.
*/
public void setArray(E[] array) {
Validate.notNull(array, "The array must not be null.");
_array = array;
}
/**
* Determines if this object has a value equivalent to another object.
*
* @see Arrays#equals(Object[], Object[])
*/
@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object other) {
if (!(other instanceof ArrayWrapper)) {
return false;
}
return Arrays.equals(_array, ((ArrayWrapper) other)._array);
}
/**
* Determines if this object has a value equivalent to another object.
*
* @see Arrays#equals(Object[], Object[])
*/
@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object other) {
if (!(other instanceof ArrayWrapper)) {
return false;
}
return Arrays.equals(_array, ((ArrayWrapper) other)._array);
}
/**
* Gets the hash code represented by this objects value.
*
* @return This object's hash code.
* @see Arrays#hashCode(Object[])
*/
@Override
public int hashCode() {
return Arrays.hashCode(_array);
}
/**
* Gets the hash code represented by this objects value.
*
* @return This object's hash code.
* @see Arrays#hashCode(Object[])
*/
@Override
public int hashCode() {
return Arrays.hashCode(_array);
}
/**
* Converts an iterable element collection to an array of elements.
* The iteration order of the specified object will be used as the array element order.
*
* @param list The iterable of objects which will be converted to an array.
* @param c The type of the elements of the array.
* @return An array of elements in the specified iterable.
*/
@SuppressWarnings("unchecked")
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
int size = -1;
if (list instanceof Collection<?>) {
@SuppressWarnings("rawtypes")
Collection coll = (Collection) list;
size = coll.size();
}
/**
* Converts an iterable element collection to an array of elements.
* The iteration order of the specified object will be used as the array element order.
*
* @param list The iterable of objects which will be converted to an array.
* @param c The type of the elements of the array.
* @return An array of elements in the specified iterable.
*/
@SuppressWarnings("unchecked")
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
int size = -1;
if (list instanceof Collection<?>) {
@SuppressWarnings("rawtypes")
Collection coll = (Collection) list;
size = coll.size();
}
if (size < 0) {
size = 0;
// Ugly hack: Count it ourselves
for (@SuppressWarnings("unused") T element : list) {
size++;
}
}
if (size < 0) {
size = 0;
// Ugly hack: Count it ourselves
for (@SuppressWarnings("unused") T element : list) {
size++;
}
}
T[] result = (T[]) Array.newInstance(c, size);
int i = 0;
for (T element : list) { // Assumes iteration order is consistent
result[i++] = element; // Assign array element at index THEN increment counter
}
return result;
}
T[] result = (T[]) Array.newInstance(c, size);
int i = 0;
for (T element : list) { // Assumes iteration order is consistent
result[i++] = element; // Assign array element at index THEN increment counter
}
return result;
}
}

View File

@ -9,11 +9,11 @@ import java.io.IOException;
*/
interface JsonRepresentedObject {
/**
* Writes the JSON representation of this object to the specified writer.
* @param writer The JSON writer which will receive the object.
* @throws IOException If an error occurs writing to the stream.
*/
public void writeJson(JsonWriter writer) throws IOException;
/**
* Writes the JSON representation of this object to the specified writer.
* @param writer The JSON writer which will receive the object.
* @throws IOException If an error occurs writing to the stream.
*/
public void writeJson(JsonWriter writer) throws IOException;
}

View File

@ -1,12 +1,12 @@
package com.plotsquared.bukkit.chat;
import com.google.gson.stream.JsonWriter;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.stream.JsonWriter;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
/**
* Represents a JSON string value.
* Writes by this object will not write name values nor begin/end objects in the JSON stream.
@ -14,34 +14,34 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
*/
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
private String _value;
private String _value;
public JsonString(CharSequence value) {
_value = value == null ? null : value.toString();
}
public JsonString(CharSequence value) {
_value = value == null ? null : value.toString();
}
@Override
public void writeJson(JsonWriter writer) throws IOException {
writer.value(getValue());
}
@Override
public void writeJson(JsonWriter writer) throws IOException {
writer.value(getValue());
}
public String getValue() {
return _value;
}
public String getValue() {
return _value;
}
public Map<String, Object> serialize() {
HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
theSingleValue.put("stringValue", _value);
return theSingleValue;
}
public Map<String, Object> serialize() {
HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
theSingleValue.put("stringValue", _value);
return theSingleValue;
}
public static JsonString deserialize(Map<String, Object> map) {
return new JsonString(map.get("stringValue").toString());
}
public static JsonString deserialize(Map<String, Object> map) {
return new JsonString(map.get("stringValue").toString());
}
@Override
public String toString() {
return _value;
}
@Override
public String toString() {
return _value;
}
}

View File

@ -15,134 +15,134 @@ import java.util.Map;
*/
public final class Reflection {
/**
* Stores loaded classes from the {@code net.minecraft.server} package.
*/
private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<>();
/**
* Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages).
*/
private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<>();
private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<>();
/**
* Contains loaded methods in a cache.
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
*/
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
private static String _versionString;
/**
* Stores loaded classes from the {@code net.minecraft.server} package.
*/
private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<>();
/**
* Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages).
*/
private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<>();
private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<>();
/**
* Contains loaded methods in a cache.
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
*/
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
private static String _versionString;
private Reflection() { }
private Reflection() { }
/**
* Gets the version string from the package name of the CraftBukkit server implementation.
* This is needed to bypass the JAR package name changing on each update.
*
* @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
*/
public synchronized static String getVersion() {
if (_versionString == null) {
if (Bukkit.getServer() == null) {
// The server hasn't started, static initializer call?
return null;
}
String name = Bukkit.getServer().getClass().getPackage().getName();
_versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
}
/**
* Gets the version string from the package name of the CraftBukkit server implementation.
* This is needed to bypass the JAR package name changing on each update.
*
* @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
*/
public synchronized static String getVersion() {
if (_versionString == null) {
if (Bukkit.getServer() == null) {
// The server hasn't started, static initializer call?
return null;
}
String name = Bukkit.getServer().getClass().getPackage().getName();
_versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
}
return _versionString;
}
return _versionString;
}
/**
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
*
* @param className The name of the class, excluding the package, within NMS.
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
*/
public synchronized static Class<?> getNMSClass(String className) {
if (_loadedNMSClasses.containsKey(className)) {
return _loadedNMSClasses.get(className);
}
/**
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
*
* @param className The name of the class, excluding the package, within NMS.
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
*/
public synchronized static Class<?> getNMSClass(String className) {
if (_loadedNMSClasses.containsKey(className)) {
return _loadedNMSClasses.get(className);
}
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
} catch (ClassNotFoundException e) {
_loadedNMSClasses.put(className, null);
throw new RuntimeException(e);
}
_loadedNMSClasses.put(className, clazz);
return clazz;
}
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
} catch (ClassNotFoundException e) {
_loadedNMSClasses.put(className, null);
throw new RuntimeException(e);
}
_loadedNMSClasses.put(className, clazz);
return clazz;
}
/**
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
*
* @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}.
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
*/
public synchronized static Class<?> getOBCClass(String className) {
if (_loadedOBCClasses.containsKey(className)) {
return _loadedOBCClasses.get(className);
}
/**
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
*
* @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}.
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
*/
public synchronized static Class<?> getOBCClass(String className) {
if (_loadedOBCClasses.containsKey(className)) {
return _loadedOBCClasses.get(className);
}
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
} catch (ClassNotFoundException e) {
_loadedOBCClasses.put(className, null);
throw new RuntimeException(e);
}
_loadedOBCClasses.put(className, clazz);
return clazz;
}
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
} catch (ClassNotFoundException e) {
_loadedOBCClasses.put(className, null);
throw new RuntimeException(e);
}
_loadedOBCClasses.put(className, clazz);
return clazz;
}
/**
* Attempts to get the NMS handle of a CraftBukkit object.
* <p>
* The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the runtime type of the specified object.
* </p>
*
* @param obj The object for which to retrieve an NMS handle.
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
*/
public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
return getMethod(obj.getClass(), "getHandle").invoke(obj);
}
/**
* Attempts to get the NMS handle of a CraftBukkit object.
* <p>
* The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the runtime type of the specified object.
* </p>
*
* @param obj The object for which to retrieve an NMS handle.
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
*/
public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
return getMethod(obj.getClass(), "getHandle").invoke(obj);
}
/**
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
* returned will be an instance or static field.
* <p>
* A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that
* no field will be reflectively looked up twice.
* </p>
* <p>
* If a field is deemed suitable for return, {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
* </p>
*
* @param clazz The class which contains the field to retrieve.
* @param name The declared name of the field in the class.
* @return A field object with the specified name declared by the specified class.
* @see Class#getDeclaredField(String)
*/
public synchronized static Field getField(Class<?> clazz, String name) {
Map<String, Field> loaded;
if (!_loadedFields.containsKey(clazz)) {
loaded = new HashMap<>();
_loadedFields.put(clazz, loaded);
} else {
loaded = _loadedFields.get(clazz);
}
if (loaded.containsKey(name)) {
// If the field is loaded (or cached as not existing), return the relevant value, which might be null
return loaded.get(name);
}
/**
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
* returned will be an instance or static field.
* <p>
* A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that
* no field will be reflectively looked up twice.
* </p>
* <p>
* If a field is deemed suitable for return, {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
* </p>
*
* @param clazz The class which contains the field to retrieve.
* @param name The declared name of the field in the class.
* @return A field object with the specified name declared by the specified class.
* @see Class#getDeclaredField(String)
*/
public synchronized static Field getField(Class<?> clazz, String name) {
Map<String, Field> loaded;
if (!_loadedFields.containsKey(clazz)) {
loaded = new HashMap<>();
_loadedFields.put(clazz, loaded);
} else {
loaded = _loadedFields.get(clazz);
}
if (loaded.containsKey(name)) {
// If the field is loaded (or cached as not existing), return the relevant value, which might be null
return loaded.get(name);
}
try {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
@ -157,50 +157,50 @@ public final class Reflection {
}
}
/**
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
* returned will be an instance or static field.
* <p>
* A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that
* no method will be reflectively looked up twice.
* <p>
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
* <p>
* This method does <em>not</em> search superclasses of the specified type for methods with the specified signature.
* Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}.
*
* @param clazz The class which contains the method to retrieve.
* @param name The declared name of the method in the class.
* @param args The formal argument types of the method.
* @return A method object with the specified name declared by the specified class.
*/
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
if (!_loadedMethods.containsKey(clazz)) {
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
}
/**
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
* returned will be an instance or static field.
* <p>
* A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that
* no method will be reflectively looked up twice.
* <p>
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
* <p>
* This method does <em>not</em> search superclasses of the specified type for methods with the specified signature.
* Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}.
*
* @param clazz The class which contains the method to retrieve.
* @param name The declared name of the method in the class.
* @param args The formal argument types of the method.
* @return A method object with the specified name declared by the specified class.
*/
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
if (!_loadedMethods.containsKey(clazz)) {
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
}
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
if (!loadedMethodNames.containsKey(name)) {
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
}
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
if (!loadedMethodNames.containsKey(name)) {
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
}
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
if (loadedSignatures.containsKey(wrappedArg)) {
return loadedSignatures.get(wrappedArg);
}
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
if (loadedSignatures.containsKey(wrappedArg)) {
return loadedSignatures.get(wrappedArg);
}
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
m.setAccessible(true);
loadedSignatures.put(wrappedArg, m);
return m;
}
}
loadedSignatures.put(wrappedArg, null);
return null;
}
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
m.setAccessible(true);
loadedSignatures.put(wrappedArg, m);
return m;
}
}
loadedSignatures.put(wrappedArg, null);
return null;
}
}

View File

@ -91,7 +91,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
MainUtil.sendMessage(player, "&7 - Disconnecting players");
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
entry.getValue().kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
entry.getValue().kick("UUID conversion has been initiated. You may reconnect when finished.");
}
MainUtil.sendMessage(player, "&7 - Initializing map");
@ -155,7 +155,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&c - Error! Attempting to repopulate");
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
if (op.getLastPlayed() != 0) {
// String name = op.getName();
// String name = op.getPluginName();
// StringWrapper wrap = new StringWrapper(name);
UUID uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);

View File

@ -1,22 +1,17 @@
package com.plotsquared.bukkit.database.plotme;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.MemorySection;
import com.intellectualcrafters.configuration.file.FileConfiguration;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.CommandException;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -28,9 +23,14 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.CommandException;
public class LikePlotMeConverter {
@ -50,7 +50,7 @@ public class LikePlotMeConverter {
}
private void sendMessage(String message) {
PS.debug("&3PlotMe&8->&3PlotSquared&8: &7" + message);
PS.debug("&3PlotMe&8->&3" + PS.imp().getPluginName() + "&8: &7" + message);
}
public String getPlotMePath() {
@ -97,14 +97,42 @@ public class LikePlotMeConverter {
return;
}
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
content = content.replace("PlotMe-DefaultGenerator", "PlotSquared");
content = content.replace("PlotMe", "PlotSquared");
content = content.replace("AthionPlots", "PlotSquared");
content = content.replace("PlotZWorld", "PlotSquared");
String pluginName = PS.imp().getPluginName();
content = content.replace("PlotMe-DefaultGenerator", pluginName);
content = content.replace("PlotMe", pluginName);
content = content.replace("AthionPlots", pluginName);
content = content.replace("PlotZWorld", pluginName);
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
} catch (IOException ignored) {}
}
private void copyConfig(ConfigurationSection plotmeDgYml, String world) throws IOException {
String actualWorldName = getWorld(world);
String plotMeWorldName = world.toLowerCase();
Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
PS.get().worlds.set("worlds." + world + ".road.width", pathWidth);
int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight", plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight", 64)); //
PS.get().worlds.set("worlds." + world + ".road.height", height);
PS.get().worlds.set("worlds." + world + ".wall.height", height);
PS.get().worlds.set("worlds." + world + ".plot.height", height);
int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); //
PS.get().worlds.set("worlds." + world + ".plot.size", plotSize);
String wallblock = plotmeDgYml.getString("worlds." + plotMeWorldName + ".UnclaimedBorder", plotmeDgYml.getString("worlds." + plotMeWorldName + ".WallBlock", "44")); //
PS.get().worlds.set("worlds." + world + ".wall.block", wallblock);
String claimed = plotmeDgYml.getString("worlds." + plotMeWorldName + ".ProtectedWallBlock", "44:1"); //
PS.get().worlds.set("worlds." + world + ".wall.block_claimed", claimed);
String floor = plotmeDgYml.getString("worlds." + plotMeWorldName + ".PlotFloorBlock", "2"); //
PS.get().worlds.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
String filling = plotmeDgYml.getString("worlds." + plotMeWorldName + ".FillBlock", "3"); //
PS.get().worlds.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5");
PS.get().worlds.set("worlds." + world + ".road.block", road);
PS.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
PS.get().worlds.set("worlds." + actualWorldName + ".plot.height", height);
PS.get().worlds.set("worlds." + actualWorldName + ".wall.height", height);
PS.get().worlds.save(PS.get().worldsFile);
}
public boolean run(APlotMeConnector connector) {
try {
String dataFolder = getPlotMePath();
@ -130,7 +158,7 @@ public class LikePlotMeConverter {
return false;
}
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
sendMessage("PlotMe conversion has started. To disable this, please set 'enabled-components -> plotme-converter' to false in the 'settings.yml'");
mergeWorldYml(plotConfig);
@ -177,36 +205,14 @@ public class LikePlotMeConverter {
if (plotmeDgFile.exists()) {
YamlConfiguration plotmeDgYml = YamlConfiguration.loadConfiguration(plotmeDgFile);
try {
for (String world : plots.keySet()) {
String actualWorldName = getWorld(world);
String plotMeWorldName = world.toLowerCase();
Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
PS.get().worlds.set("worlds." + world + ".road.width", pathWidth);
int pathHeight = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight", 64); //
PS.get().worlds.set("worlds." + world + ".road.height", pathHeight);
PS.get().worlds.set("worlds." + world + ".wall.height", pathHeight);
PS.get().worlds.set("worlds." + world + ".plot.height", pathHeight);
int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); //
PS.get().worlds.set("worlds." + world + ".plot.size", plotSize);
String wallblock = plotmeDgYml.getString("worlds." + plotMeWorldName + ".WallBlock", "44"); //
PS.get().worlds.set("worlds." + world + ".wall.block", wallblock);
String floor = plotmeDgYml.getString("worlds." + plotMeWorldName + ".PlotFloorBlock", "2"); //
PS.get().worlds.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
String filling = plotmeDgYml.getString("worlds." + plotMeWorldName + ".FillBlock", "3"); //
PS.get().worlds.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5");
PS.get().worlds.set("worlds." + world + ".road.block", road);
int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
if (height == 0) {
height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight", 64); //
}
PS.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
PS.get().worlds.set("worlds." + actualWorldName + ".plot.height", height);
PS.get().worlds.set("worlds." + actualWorldName + ".wall.height", height);
PS.get().worlds.save(PS.get().worldsFile);
HashSet<String> allWorlds = new HashSet<>(plots.keySet());
allWorlds.addAll(worlds);
for (String world : allWorlds) {
copyConfig(plotmeDgYml, world);
}
} catch (IOException ignored) {}
} catch (IOException ignored) {
ignored.printStackTrace();
}
}
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
String world = entry.getKey();
@ -255,7 +261,7 @@ public class LikePlotMeConverter {
done();
sendMessage("&aDatabase conversion is now complete!");
PS.debug("&c - Stop the server");
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
PS.debug("&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
PS.debug("&c - Start the server");
PS.get().setPlots(DBFunc.getPlots());
@ -288,38 +294,43 @@ public class LikePlotMeConverter {
World world = Bukkit.getWorld(getWorld(worldName));
if (world == null) {
sendMessage("&cInvalid world in PlotMe configuration: " + worldName);
continue;
}
String actualWorldName = world.getName();
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
PS.get().removePlotAreas(actualWorldName);
if (mv) {
// unload world with MV
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// load world with MV
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv import " + actualWorldName + " normal -g PlotSquared");
} else if (mw) {
// unload world with MW
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// load world with MW
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mw create " + actualWorldName + " plugin:PlotSquared");
if (!Bukkit.getWorlds().isEmpty() && Bukkit.getWorlds().get(0).getName().equals(worldName)) {
sendMessage("&cYou need to stop the server to reload this world properly");
} else {
// Load using Bukkit API
// - User must set generator manually
Bukkit.getServer().unloadWorld(world, true);
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
myWorld.save();
PS.get().removePlotAreas(actualWorldName);
if (mv) {
// unload world with MV
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// load world with MV
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv import " + actualWorldName + " normal -g " + PS.imp().getPluginName());
} else if (mw) {
// unload world with MW
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// load world with MW
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mw create " + actualWorldName + " plugin:" + PS.imp().getPluginName());
} else {
// Load using Bukkit API
// - User must set generator manually
Bukkit.getServer().unloadWorld(world, true);
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator())).createWorld();
myWorld.save();
}
}
}
} catch (CommandException e) {
@ -329,7 +340,7 @@ public class LikePlotMeConverter {
done();
sendMessage("&aDatabase conversion is now complete!");
PS.debug("&c - Stop the server");
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
PS.debug("&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
PS.debug("&c - Start the server");
} else {

View File

@ -67,7 +67,7 @@ public class PlotMeConnector_017 extends APlotMeConnector {
return null;
}
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerID");
boolean merge = !this.plugin.equals("plotme") && Settings.Enabled_Components.PLOTME_CONVERTER;
boolean merge = !"plotme".equals(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
while (resultSet.next()) {
int key = resultSet.getInt("plot_id");
PlotId id = new PlotId(resultSet.getInt("plotX"), resultSet.getInt("plotZ"));
@ -126,7 +126,7 @@ public class PlotMeConnector_017 extends APlotMeConnector {
plots.put(key, plot);
}
for (Plot plot : plots.values()) {
HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.getArea().worldname);
HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.getWorldName());
if (mergeMap != null) {
if (mergeMap.containsKey(plot.getId())) {
plot.setMerged(mergeMap.get(plot.getId()));
@ -174,10 +174,10 @@ public class PlotMeConnector_017 extends APlotMeConnector {
HashMap<String, HashMap<PlotId, Plot>> processed = new HashMap<>();
for (Plot plot : plots.values()) {
HashMap<PlotId, Plot> map = processed.get(plot.getArea().worldname);
HashMap<PlotId, Plot> map = processed.get(plot.getWorldName());
if (map == null) {
map = new HashMap<>();
processed.put(plot.getArea().worldname, map);
processed.put(plot.getWorldName(), map);
}
map.put(plot.getId(), plot);
}

View File

@ -36,7 +36,7 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
* @return String
*/
public String getWorld() {
return getPlot().getArea().worldname;
return getPlot().getWorldName();
}
@Override

View File

@ -37,7 +37,7 @@ public class PlotComponentSetEvent extends PlotEvent {
* @return String
*/
public String getWorld() {
return getPlot().getArea().worldname;
return getPlot().getWorldName();
}
/**

View File

@ -35,7 +35,7 @@ public class PlotDeleteEvent extends PlotEvent {
* @return String
*/
public String getWorld() {
return getPlot().getArea().worldname;
return getPlot().getWorldName();
}
@Override

View File

@ -2,7 +2,6 @@ package com.plotsquared.bukkit.generator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ChunkWrapper;
@ -20,24 +19,23 @@ import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.block.GenChunk;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Set;
public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper<ChunkGenerator> {
private final GenChunk chunkSetter;
private final PseudoRandom random = new PseudoRandom();
private final IndependentPlotGenerator plotGenerator;
private final List<BlockPopulator> populators = new ArrayList<>();
private List<BlockPopulator> populators;
private final ChunkGenerator platformGenerator;
private final boolean full;
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
@ -49,6 +47,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
}
this.plotGenerator = generator;
this.platformGenerator = this;
populators = new ArrayList<>();
this.populators.add(new BlockPopulator() {
private LocalBlockQueue queue;
@ -119,7 +118,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override
public PlotManager getNewPlotManager() {
return new HybridGen().getNewPlotManager();
return PS.get().IMP.getDefaultGenerator().getNewPlotManager();
}
@Override
@ -129,7 +128,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
return new HybridGen().getNewPlotArea(world, id, min, max);
return PS.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
}
@Override
@ -188,9 +187,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
}
};
this.chunkSetter = new GenChunk(null, new ChunkWrapper(world, 0, 0));
if (cg != null) {
this.populators.addAll(cg.getDefaultPopulators(BukkitUtil.getWorld(world)));
}
MainUtil.initCache();
}
@ -246,6 +242,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
}
ArrayList<BlockPopulator> toAdd = new ArrayList<>();
List<BlockPopulator> existing = world.getPopulators();
if (populators == null && platformGenerator != null) {
populators = new ArrayList<>(platformGenerator.getDefaultPopulators(world));
}
for (BlockPopulator populator : this.populators) {
if (!existing.contains(populator)) {
toAdd.add(populator);

View File

@ -1,6 +1,7 @@
package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@ -46,7 +47,7 @@ public class ChunkListener implements Listener {
this.mustSave = classChunk.getField("mustSave");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
} catch (Throwable ignored) {
PS.debug("PlotSquared/Server not compatible for chunk processor trim/gc");
PS.debug(PS.imp().getPluginName() + "/Server not compatible for chunk processor trim/gc");
Settings.Chunk_Processor.AUTO_TRIM = false;
}
}
@ -228,7 +229,7 @@ public class ChunkListener implements Listener {
if (!chunk.isLoaded()) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
PS.debug("[PlotSquared] &aSuccessfully processed and unloaded chunk!");
PS.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true);
return;
}
@ -236,7 +237,7 @@ public class ChunkListener implements Listener {
if (tiles.length == 0) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
PS.debug("[PlotSquared] &aSuccessfully processed and unloaded chunk!");
PS.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true);
return;
}
@ -246,7 +247,7 @@ public class ChunkListener implements Listener {
if (i >= tiles.length) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
PS.debug("[PlotSquared] &aSuccessfully processed and unloaded chunk!");
PS.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true);
return;
}
@ -270,11 +271,11 @@ public class ChunkListener implements Listener {
ent.remove();
}
}
PS.debug("[PlotSquared] &a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
PS.debug(C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
}
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
if (unload) {
PS.debug("[PlotSquared] &c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
PS.debug(C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
cleanChunk(chunk);
return true;
}

View File

@ -22,17 +22,19 @@ public class EntitySpawnListener implements Listener {
return;
}
Plot plot = area.getOwnedPlotAbs(location);
if (plot == null) {
if (!area.MOB_SPAWNING) {
if (event.getEntityType().isAlive() || !area.MISC_SPAWN_UNOWNED) {
event.setCancelled(true);
}
}
return;
}
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
event.setCancelled(true);
}
switch (entity.getType()) {
case ENDER_CRYSTAL:
if (plot == null) {
if (!area.MOB_SPAWNING) {
event.setCancelled(true);
}
return;
}
if (PlayerEvents.checkEntity(entity, plot)) {
event.setCancelled(true);
}

View File

@ -1,18 +1,19 @@
package com.plotsquared.bukkit.listeners;
import com.google.common.collect.Iterables;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class ForceFieldListener {
@ -79,14 +80,18 @@ public class ForceFieldListener {
if (plot.isAdded(uuid)) {
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
for (PlotPlayer oPlayer : players) {
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(plotPlayer, oPlayer));
if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(plotPlayer, oPlayer));
}
}
} else {
PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
if (oPlayer == null) {
return;
}
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
}
}
}
}

View File

@ -20,14 +20,26 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.RegExUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.bukkit.object.BukkitLazyBlock;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitVersion;
import com.plotsquared.listener.PlayerBlockEventType;
import com.plotsquared.listener.PlotListener;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -55,6 +67,7 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -64,6 +77,7 @@ import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
@ -113,17 +127,6 @@ import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
/**
* Player Events involving plots.
*
@ -161,6 +164,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onRedstoneEvent(BlockRedstoneEvent event) {
Block block = event.getBlock();
switch (block.getType()) {
case OBSERVER:
case REDSTONE_LAMP_OFF:
case REDSTONE_WIRE:
case REDSTONE_LAMP_ON:
@ -195,7 +199,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return;
}
Plot plot = area.getOwnedPlotAbs(loc);
Plot plot = area.getOwnedPlot(loc);
if (plot == null) {
return;
}
@ -204,8 +208,19 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
if (Settings.Redstone.DISABLE_OFFLINE) {
if (UUIDHandler.getPlayer(plot.owner) == null) {
boolean disable = true;
boolean disable;
if (plot.isMerged()) {
disable = true;
for (UUID owner : plot.getOwners()) {
if (UUIDHandler.getPlayer(owner) != null) {
disable = false;
break;
}
}
} else {
disable = UUIDHandler.getPlayer(plot.owner) == null;
}
if (disable) {
for (UUID trusted : plot.getTrusted()) {
if (UUIDHandler.getPlayer(trusted) != null) {
disable = false;
@ -305,7 +320,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return true;
}
Plot plot = area.getPlotAbs(loc);
Plot plot = area.getPlot(loc);
ProjectileSource shooter = entity.getShooter();
if (shooter instanceof Player) {
PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
@ -347,30 +362,33 @@ public class PlayerEvents extends PlotListener implements Listener {
if (msg.isEmpty()) {
return;
}
String[] split = msg.split(" ");
PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
if (cmd == null) {
if (split[0].equals("plotme") || split[0].equals("ap")) {
Player player = event.getPlayer();
if (Settings.PlotMe.ALIAS) {
player.performCommand("plots " + StringMan.join(Arrays.copyOfRange(split, 1, split.length), " "));
} else {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
}
event.setCancelled(true);
return;
}
}
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Location loc = pp.getLocation();
PlotArea area = loc.getPlotArea();
if (area == null) {
return;
}
String[] parts = msg.split(" ");
Plot plot = pp.getCurrentPlot();
if (BukkitMain.worldEdit != null) { // Check WorldEdit
switch (parts[0].toLowerCase()) {
case "up":
case "/up":
case "worldedit:up":
case "worldedit:/up":
if (plot == null || (!plot.isAdded(pp.getUUID()) && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER, true))) {
event.setCancelled(true);
return;
}
}
}
if (plot == null) {
return;
}
Optional<List<String>> flag = plot.getFlag(Flags.BLOCKED_CMDS);
if (flag.isPresent() && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
List<String> blocked_cmds = flag.get();
String[] parts = msg.split(" ");
String c = parts[0];
if (parts[0].contains(":")) {
c = parts[0].split(":")[1];
@ -428,10 +446,11 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onConnect(PlayerJoinEvent event) {
final Player player = event.getPlayer();
BukkitUtil.getPlayer(event.getPlayer()).unregister();
UUIDHandler.getPlayers().remove(player.getName());
BukkitUtil.removePlayer(player.getName());
final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Now
String name = pp.getName();
@ -468,6 +487,30 @@ public class PlayerEvents extends PlotListener implements Listener {
EventUtil.manager.doRespawnTask(pp);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
if (event.getTo() == null || event.getFrom() == null || !event.getFrom().getWorld().equals(event.getTo().getWorld())) {
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("location");
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("lastplot");
org.bukkit.Location to = event.getTo();
if (to != null) {
Player player = event.getPlayer();
PlotPlayer pp = PlotPlayer.wrap(player);
Location loc = BukkitUtil.getLocation(to);
PlotArea area = PS.get().getPlotAreaAbs(loc);
if (area == null) {
return;
}
Plot plot = area.getPlot(loc);
if (plot != null) {
plotEntry(pp, plot);
}
}
return;
}
playerMove(event);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void playerMove(PlayerMoveEvent event) {
org.bukkit.Location from = event.getFrom();
@ -489,35 +532,45 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot now = area.getPlot(loc);
Plot lastPlot = pp.getMeta("lastplot");
if (now == null) {
if (lastPlot != null && !plotExit(pp, lastPlot)) {
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
this.tmpTeleport = false;
if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
player.teleport(from);
} else {
player.teleport(player.getWorld().getSpawnLocation());
}
this.tmpTeleport = true;
event.setCancelled(true);
return;
}
} else if (now.equals(lastPlot)) {
ForceFieldListener.handleForcefield(player, pp, now);
return;
} else if (!plotEntry(pp, now)) {
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
player.teleport(from);
event.setCancelled(true);
this.tmpTeleport = false;
to.setX(from.getBlockX());
to.setY(from.getBlockY());
to.setZ(from.getBlockZ());
player.teleport(event.getTo());
this.tmpTeleport = true;
return;
}
Integer border = area.getBorder();
if (x2 > border) {
to.setX(border - 4);
if (x2 > border && this.tmpTeleport) {
to.setX(x2 - 1);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
return;
}
if (x2 < -border) {
to.setX(-border + 4);
if (x2 < -border && this.tmpTeleport) {
to.setX(x2 + 1);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
return;
}
@ -540,33 +593,44 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot now = area.getPlot(loc);
Plot lastPlot = pp.getMeta("lastplot");
if (now == null) {
if (lastPlot != null && !plotExit(pp, lastPlot)) {
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
this.tmpTeleport = false;
if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
player.teleport(from);
} else {
player.teleport(player.getWorld().getSpawnLocation());
}
this.tmpTeleport = true;
event.setCancelled(true);
return;
}
} else if (now.equals(lastPlot)) {
ForceFieldListener.handleForcefield(player, pp, now);
return;
} else if (!plotEntry(pp, now)) {
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
this.tmpTeleport = false;
player.teleport(from);
event.setCancelled(true);
to.setX(from.getBlockX());
to.setY(from.getBlockY());
to.setZ(from.getBlockZ());
player.teleport(event.getTo());
this.tmpTeleport = true;
return;
}
Integer border = area.getBorder();
if (z2 > border) {
to.setZ(border - 4);
if (z2 > border && this.tmpTeleport) {
to.setZ(z2 - 1);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
} else if (z2 < -border) {
to.setZ(-border + 4);
} else if (z2 < -border && this.tmpTeleport) {
to.setZ(z2 + 1);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
}
}
@ -577,7 +641,7 @@ public class PlayerEvents extends PlotListener implements Listener {
PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
Location location = plotPlayer.getLocation();
PlotArea area = location.getPlotArea();
if (area == null || (!area.PLOT_CHAT && !plotPlayer.getAttribute("chat"))) {
if (area == null || (area.PLOT_CHAT == plotPlayer.getAttribute("chat"))) {
return;
}
Plot plot = area.getPlot(location);
@ -590,13 +654,12 @@ public class PlayerEvents extends PlotListener implements Listener {
String sender = event.getPlayer().getDisplayName();
PlotId id = plot.getId();
Set<Player> recipients = event.getRecipients();
Set<Player> spies = new HashSet<>();
recipients.clear();
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue();
if (pp.getAttribute("chatspy")) {
String spy = event.getFormat();
spy = String.format(spy, sender, message);
pp.sendMessage(spy);
spies.add(((BukkitPlayer) pp).player);
} else {
Plot current = pp.getCurrentPlot();
if (current != null && current.getBasePlot(false).equals(plot)) {
@ -605,10 +668,20 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
String partial = ChatColor.translateAlternateColorCodes('&',format.replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender));
if (plotPlayer.hasPermission("plots.chat.color")) {
message = C.color(message);
}
String full = partial.replace("%msg%", message);
for (Player receiver : recipients) {
receiver.sendMessage(full);
}
if (!spies.isEmpty()) {
String spyMessage = C.PLOT_CHAT_SPY_FORMAT.s().replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender).replace("%msg%", message);
for (Player player : spies) {
player.sendMessage(spyMessage);
}
}
PS.debug(full);
}
@EventHandler(priority = EventPriority.LOWEST)
@ -619,7 +692,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return;
}
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot != null) {
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (event.getBlock().getY() == 0) {
@ -727,15 +800,12 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onWorldChanged(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
// Delete last location
pp.deleteMeta("location");
Plot plot = (Plot) pp.deleteMeta("lastplot");
if (plot != null) {
plotExit(pp, plot);
}
if (PS.get().worldedit != null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
if (pp.getAttribute("worldedit")) {
@ -746,6 +816,15 @@ public class PlayerEvents extends PlotListener implements Listener {
if (Settings.Enabled_Components.PERMISSION_CACHE) {
pp.deleteMeta("perm");
}
Location loc = pp.getLocation();
PlotArea area = PS.get().getPlotAreaAbs(loc);
if (area == null) {
return;
}
plot = area.getPlot(loc);
if (plot != null) {
plotEntry(pp, plot);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -766,7 +845,38 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!PS.get().hasPlotArea(world)) {
return;
}
if (BukkitUtil.getLocation(event.getBlock().getLocation()).getPlotArea() != null) {
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getOwnedPlot(location);
if (plot == null) {
event.setCancelled(true);
return;
}
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player player = (Player) entity;
if (!plot.hasOwner()) {
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (Flags.ICE_FORM.isTrue(plot)) {
return;
}
event.setCancelled(true);
return;
}
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (!plot.isAdded(plotPlayer.getUUID())) {
if (Flags.ICE_FORM.isTrue(plot)) {
return;
}
event.setCancelled(true);
return;
}
return;
}
if (!Flags.ICE_FORM.isTrue(plot)) {
event.setCancelled(true);
}
}
@ -806,6 +916,27 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockSpread(BlockFormEvent event) {
Block block = event.getBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
if (location.isPlotRoad()) {
event.setCancelled(true);
return;
}
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getOwnedPlot(location);
if (plot == null) {
return;
}
if (Flags.SNOW_FORM.isFalse(plot)) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer();
@ -820,7 +951,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return;
}
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot != null) {
if (location.getY() == 0) {
event.setCancelled(true);
@ -1080,7 +1211,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
}
Plot origin = area.getPlotAbs(location);
Plot origin = area.getPlot(location);
if (origin == null) {
event.setCancelled(true);
return;
@ -1174,6 +1305,25 @@ public class PlayerEvents extends PlotListener implements Listener {
case NOTE_BLOCK:
case JUKEBOX:
case WORKBENCH:
case SILVER_SHULKER_BOX:
case BLACK_SHULKER_BOX:
case BLUE_SHULKER_BOX:
case RED_SHULKER_BOX:
case PINK_SHULKER_BOX:
case ORANGE_SHULKER_BOX:
case WHITE_SHULKER_BOX:
case YELLOW_SHULKER_BOX:
case BROWN_SHULKER_BOX:
case CYAN_SHULKER_BOX:
case GREEN_SHULKER_BOX:
case PURPLE_SHULKER_BOX:
case GRAY_SHULKER_BOX:
case LIME_SHULKER_BOX:
case LIGHT_BLUE_SHULKER_BOX:
case MAGENTA_SHULKER_BOX:
case COMMAND_REPEATING:
case COMMAND_CHAIN:
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
case DRAGON_EGG:
@ -1192,7 +1342,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Material type = (hand == null) ? null : hand.getType();
int id = (type == null) ? 0 : type.getId();
if (id == 0) {
if (type == Material.AIR) {
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
}
@ -1209,18 +1359,15 @@ public class PlayerEvents extends PlotListener implements Listener {
case MONSTER_EGGS:
eventType = PlayerBlockEventType.SPAWN_MOB;
break;
case ARMOR_STAND:
location = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_MISC;
break;
case WRITTEN_BOOK:
case BOOK_AND_QUILL:
case BOOK:
eventType = PlayerBlockEventType.READ;
break;
case APPLE:
case BAKED_POTATO:
case MUSHROOM_SOUP:
@ -1461,6 +1608,7 @@ public class PlayerEvents extends PlotListener implements Listener {
switch (entity.getType()) {
case PLAYER:
return false;
case LLAMA_SPIT:
case SMALL_FIREBALL:
case FIREBALL:
case DROPPED_ITEM:
@ -1490,6 +1638,7 @@ public class PlayerEvents extends PlotListener implements Listener {
case AREA_EFFECT_CLOUD:
case LIGHTNING:
case WITHER_SKULL:
case EVOKER_FANGS:
case UNKNOWN:
// non moving / unmovable
return checkEntity(plot, Flags.ENTITY_CAP);
@ -1522,6 +1671,11 @@ public class PlayerEvents extends PlotListener implements Listener {
case SNOWMAN:
case BAT:
case HORSE:
case DONKEY:
case LLAMA:
case MULE:
case ZOMBIE_HORSE:
case SKELETON_HORSE:
// animal
return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
case BLAZE:
@ -1543,6 +1697,14 @@ public class PlayerEvents extends PlotListener implements Listener {
case WITHER:
case ZOMBIE:
case SHULKER:
case HUSK:
case STRAY:
case ELDER_GUARDIAN:
case WITHER_SKELETON:
case VINDICATOR:
case EVOKER:
case VEX:
case ZOMBIE_VILLAGER:
// monster
return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
default:
@ -1669,159 +1831,6 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
if (event.getTo() == null || event.getFrom() == null) {
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("location");
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("lastplot");
return;
}
org.bukkit.Location from = event.getFrom();
org.bukkit.Location to = event.getTo();
int x2;
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc);
PlotArea area = loc.getPlotArea();
if (area == null) {
return;
}
Plot now = area.getPlot(loc);
Plot lastPlot = pp.getMeta("lastplot");
if (now == null) {
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
this.tmpTeleport = false;
player.teleport(from);
this.tmpTeleport = true;
} else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
this.tmpTeleport = false;
player.teleport(player.getWorld().getSpawnLocation());
this.tmpTeleport = true;
}
}
event.setCancelled(true);
return;
}
} else if (lastPlot != null && now.equals(lastPlot)) {
if (!Flags.DENY_TELEPORT.allowsTeleport(pp, lastPlot)) {
event.setTo(BukkitUtil.getLocation(lastPlot.getSide()));
}
return;
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
this.tmpTeleport = false;
player.teleport(from);
this.tmpTeleport = true;
} else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
this.tmpTeleport = false;
player.teleport(player.getWorld().getSpawnLocation());
this.tmpTeleport = true;
}
}
event.setCancelled(true);
return;
}
Integer border = area.getBorder();
if (this.tmpTeleport) {
if (x2 > border) {
to.setX(border - 4);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
return;
} else if (x2 < -border) {
to.setX(-border + 4);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
return;
}
}
return;
}
int z2;
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
// Set last location
Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc);
PlotArea area = loc.getPlotArea();
if (area == null) {
return;
}
Plot now = area.getPlot(loc);
Plot lastPlot = pp.getMeta("lastplot");
if (now == null) {
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
this.tmpTeleport = false;
player.teleport(from);
this.tmpTeleport = true;
} else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
this.tmpTeleport = false;
player.teleport(player.getWorld().getSpawnLocation());
this.tmpTeleport = true;
}
}
event.setCancelled(true);
return;
}
} else if (lastPlot != null && now.equals(lastPlot)) {
if (!Flags.DENY_TELEPORT.allowsTeleport(pp, lastPlot)) {
event.setTo(BukkitUtil.getLocation(lastPlot.getSide()));
}
return;
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) {
this.tmpTeleport = false;
player.teleport(from);
this.tmpTeleport = true;
} else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
this.tmpTeleport = false;
player.teleport(player.getWorld().getSpawnLocation());
this.tmpTeleport = true;
}
}
event.setCancelled(true);
return;
}
Integer border = area.getBorder();
if (this.tmpTeleport) {
if (z2 > border) {
to.setZ(border - 4);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
} else if (z2 < -border) {
to.setZ(-border + 4);
this.tmpTeleport = false;
player.teleport(event.getTo());
this.tmpTeleport = true;
MainUtil.sendMessage(pp, C.BORDER);
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
BlockFace bf = event.getBlockFace();
@ -1832,7 +1841,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot == null) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
return;
@ -1903,7 +1912,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Player player = event.getPlayer();
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot == null) {
if (Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_BUILD_ROAD)) {
return;
@ -1958,7 +1967,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Player p = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
@ -1999,7 +2008,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD);
@ -2029,7 +2038,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
PlotPlayer player = BukkitUtil.getPlayer(shooter);
Plot plot = area.getPlotAbs(BukkitUtil.getLocation(event.getEntity()));
Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity()));
if (plot != null) {
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
@ -2060,7 +2069,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Player p = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_ROAD);
@ -2088,6 +2097,9 @@ public class PlayerEvents extends PlotListener implements Listener {
if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT, false)) {
return;
}
if (entity instanceof Villager && plot.getFlag(Flags.VILLAGER_INTERACT, false)) {
return;
}
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
event.setCancelled(true);
@ -2106,7 +2118,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (d instanceof Player) {
Player p = (Player) d;
PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlotAbs(l);
Plot plot = area.getPlot(l);
if (plot == null) {
if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.road");
@ -2156,8 +2168,27 @@ public class PlayerEvents extends PlotListener implements Listener {
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
EntityDamageByEntityEvent eventChange = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
EntityDamageByEntityEvent eventChange = null;
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_11_0)) {
eventChange = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
EntityDamageEvent.DamageCause.FIRE_TICK, (double)event.getDuration());
} else {
try {
Constructor<EntityDamageByEntityEvent> constructor = EntityDamageByEntityEvent.class.getConstructor(Entity.class,
Entity.class, EntityDamageEvent.DamageCause.class, Integer.TYPE);
eventChange = constructor.newInstance(event.getCombuster(), event.getEntity(),
EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace();
}
}
if (eventChange == null) {
return;
}
onEntityDamageByEntityEvent(eventChange);
if (eventChange.isCancelled()) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -2357,7 +2388,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = area.getPlotAbs(location);
Plot plot = area.getPlot(location);
if (plot != null) {
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
@ -2396,7 +2427,7 @@ public class PlayerEvents extends PlotListener implements Listener {
event.setCancelled(true);
MainUtil.sendMessage(pp, C.HEIGHT_LIMIT.s().replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
}
} else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
} else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
event.setCancelled(true);
}

View File

@ -2,6 +2,7 @@ package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
@ -66,7 +67,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
oldLore = lore.toString();
}
}
if (!newLore.equals("[(+NBT)]") || (current.equals(newItem) && newLore.equals(oldLore))) {
if (!"[(+NBT)]".equals(newLore) || (current.equals(newItem) && newLore.equals(oldLore))) {
return;
}
HashSet<Byte> blocks = null;
@ -141,6 +142,9 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
} else {
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (Flags.MISC_INTERACT.isTrue(plot)) {
return;
}
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
e.setCancelled(true);

View File

@ -2,6 +2,8 @@ package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
@ -16,6 +18,14 @@ public class WorldEvents implements Listener {
public void onWorldInit(WorldInitEvent event) {
World world = event.getWorld();
String name = world.getName();
PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
if (single.isWorld(name)) {
world.setKeepSpawnInMemory(false);
return;
}
}
ChunkGenerator gen = world.getGenerator();
if (gen instanceof GeneratorWrapper) {
PS.get().loadWorld(name, (GeneratorWrapper<?>) gen);

View File

@ -1,5 +1,6 @@
package com.plotsquared.bukkit.object;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
@ -67,7 +68,7 @@ public class BukkitPlayer extends PlotPlayer {
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
for (RegisteredListener listener : listeners) {
if (listener.getPlugin().getName().equals("PlotSquared")) {
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
continue;
}
try {
@ -81,7 +82,7 @@ public class BukkitPlayer extends PlotPlayer {
}
event = new PlayerTeleportEvent(player, to, from);
for (RegisteredListener listener : listeners) {
if (listener.getPlugin().getName().equals("PlotSquared")) {
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
continue;
}
try {
@ -101,6 +102,11 @@ public class BukkitPlayer extends PlotPlayer {
return this.player.hasPermission(permission);
}
@Override
public boolean isPermissionSet(String permission) {
return this.player.isPermissionSet(permission);
}
@Override
public void sendMessage(String message) {
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {

View File

@ -1,6 +1,7 @@
package com.plotsquared.bukkit.object.entity;
import com.intellectualcrafters.plot.PS;
import com.plotsquared.bukkit.util.BukkitVersion;
import org.bukkit.Art;
import org.bukkit.DyeColor;
import org.bukkit.Location;
@ -86,7 +87,7 @@ public class EntityWrapper {
if (depth == 1) {
return;
}
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 10, 0) || entity instanceof ArmorStand) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
if (!entity.hasGravity()) {
this.noGravity = true;
}
@ -94,7 +95,7 @@ public class EntityWrapper {
switch (entity.getType()) {
case ARROW:
case BOAT:
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
Boat boat = (Boat) entity;
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
}
@ -353,7 +354,7 @@ public class EntityWrapper {
void restoreEquipment(LivingEntity entity) {
EntityEquipment equipment = entity.getEquipment();
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
equipment.setItemInMainHand(this.lived.mainHand);
equipment.setItemInOffHand(this.lived.offHand);
} else {
@ -397,7 +398,7 @@ public class EntityWrapper {
}
void storeEquipment(EntityEquipment equipment) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
this.lived.mainHand = equipment.getItemInMainHand().clone();
this.lived.offHand = equipment.getItemInOffHand().clone();
} else {
@ -487,7 +488,7 @@ public class EntityWrapper {
if (this.depth == 1) {
return entity;
}
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 10, 0) || entity instanceof ArmorStand) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
if (this.noGravity) {
entity.setGravity(false);
}
@ -495,7 +496,7 @@ public class EntityWrapper {
switch (entity.getType()) {
case ARROW:
case BOAT:
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
Boat boat = (Boat) entity;
boat.setWoodType(TreeSpecies.values()[dataByte]);
}

View File

@ -18,7 +18,7 @@ public class DefaultTitleManager extends TitleManager {
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
*/
public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
}
@ -106,9 +106,9 @@ public class DefaultTitleManager extends TitleManager {
}
}
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) {
if (m.getName().equals(name) && (args.length == 0 || classListEqual(args, m.getParameterTypes()))) {
m.setAccessible(true);
return m;
}
@ -116,17 +116,4 @@ public class DefaultTitleManager extends TitleManager {
return null;
}
boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
if (l1.length != l2.length) {
return false;
}
boolean equal = true;
for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) {
equal = false;
break;
}
}
return equal;
}
}

View File

@ -17,7 +17,7 @@ public class DefaultTitleManager_183 extends DefaultTitleManager {
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
*/
public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
}
@ -67,15 +67,4 @@ public class DefaultTitleManager_183 extends DefaultTitleManager {
}
}
}
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) {
m.setAccessible(true);
return m;
}
}
return null;
}
}

View File

@ -0,0 +1,32 @@
package com.plotsquared.bukkit.titles;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitVersion;
import org.bukkit.entity.Player;
@SuppressWarnings("deprecation")
public class DefaultTitle_111 extends AbstractTitle {
private final boolean valid;
public DefaultTitle_111() {
this.valid = PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_11_0);
}
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
if (valid) {
try {
final Player playerObj = ((BukkitPlayer) player).player;
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
title.send(playerObj);
return;
} catch (Throwable ignored) {}
}
AbstractTitle.TITLE_CLASS = new DefaultTitle_180();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}

View File

@ -4,7 +4,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.plotsquared.bukkit.object.BukkitPlayer;
public class DefaultTitle extends AbstractTitle {
public class DefaultTitle_180 extends AbstractTitle {
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
@ -12,7 +12,7 @@ public class DefaultTitle extends AbstractTitle {
DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out);
title.send(((BukkitPlayer) player).player);
} catch (Exception ignored) {
AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}

View File

@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.object.BukkitPlayer;
import org.bukkit.entity.Player;
@SuppressWarnings("deprecation")
public class DefaultTitle_19 extends AbstractTitle {
@Override
@ -20,7 +21,7 @@ public class DefaultTitle_19 extends AbstractTitle {
}
}, delay * 20);
} catch (Throwable ignored) {
AbstractTitle.TITLE_CLASS = new DefaultTitle();
AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}

View File

@ -19,7 +19,7 @@ public class HackTitleManager extends TitleManager {
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
*/
public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
}
@ -162,18 +162,4 @@ public class HackTitleManager extends TitleManager {
return null;
}
private boolean classListEqual(Class<?>[] l1, Class<?>[] l2) {
if (l1.length != l2.length) {
return false;
}
boolean equal = true;
for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) {
equal = false;
break;
}
}
return equal;
}
}

View File

@ -241,4 +241,17 @@ public abstract class TitleManager {
return true;
}
boolean classListEqual(Class<?>[] l1, Class<?>[] l2) {
if (l1.length != l2.length) {
return false;
}
boolean equal = true;
for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) {
equal = false;
break;
}
}
return equal;
}
}

View File

@ -0,0 +1,526 @@
package com.plotsquared.bukkit.titles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/**
* Minecraft 1.8 Title
* For 1.11
*
* @author Maxim Van de Wynckel
* @version 1.1.0
*/
public class TitleManager_1_11 {
/* Title packet */
private static Class<?> packetTitle;
/* Title packet actions ENUM */
private static Class<?> packetActions;
/* Chat serializer */
private static Class<?> nmsChatSerializer;
private static Class<?> chatBaseComponent;
/* NMS player and connection */
private static Class<?> nmsPlayer;
private static Class<?> nmsPlayerConnection;
private static Field playerConnection;
private static Method sendPacket;
private static Class<?> obcPlayer;
private static Method methodPlayerGetHandle;
/* Title text and color */
private String title = "";
private ChatColor titleColor = ChatColor.WHITE;
/* Subtitle text and color */
private String subtitle = "";
private ChatColor subtitleColor = ChatColor.WHITE;
/* Title timings */
private int fadeInTime = -1;
private int stayTime = -1;
private int fadeOutTime = -1;
private boolean ticks = false;
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<Class<?>, Class<?>>();
public TitleManager_1_11() {
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title Title
*/
public TitleManager_1_11(String title) {
this.title = title;
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title Title text
* @param subtitle Subtitle text
*/
public TitleManager_1_11(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
loadClasses();
}
/**
* Copy 1.8 title
*
* @param title Title
*/
public TitleManager_1_11(TitleManager_1_11 title) {
// Copy title
this.title = title.getTitle();
this.subtitle = title.getSubtitle();
this.titleColor = title.getTitleColor();
this.subtitleColor = title.getSubtitleColor();
this.fadeInTime = title.getFadeInTime();
this.fadeOutTime = title.getFadeOutTime();
this.stayTime = title.getStayTime();
this.ticks = title.isTicks();
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title Title text
* @param subtitle Subtitle text
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
*/
public TitleManager_1_11(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
this.title = title;
this.subtitle = subtitle;
this.fadeInTime = fadeInTime;
this.stayTime = stayTime;
this.fadeOutTime = fadeOutTime;
loadClasses();
}
/**
* Load spigot and NMS classes
*/
private void loadClasses() {
if (packetTitle == null) {
packetTitle = getNMSClass("PacketPlayOutTitle");
packetActions = getNMSClass("PacketPlayOutTitle$EnumTitleAction");
chatBaseComponent = getNMSClass("IChatBaseComponent");
nmsChatSerializer = getNMSClass("ChatComponentText");
nmsPlayer = getNMSClass("EntityPlayer");
nmsPlayerConnection = getNMSClass("PlayerConnection");
playerConnection = getField(nmsPlayer,
"playerConnection");
sendPacket = getMethod(nmsPlayerConnection, "sendPacket");
obcPlayer = getOBCClass("entity.CraftPlayer");
methodPlayerGetHandle = getMethod("getHandle", obcPlayer);
}
}
/**
* Set title text
*
* @param title Title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Get title text
*
* @return Title text
*/
public String getTitle() {
return this.title;
}
/**
* Set subtitle text
*
* @param subtitle Subtitle text
*/
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
/**
* Get subtitle text
*
* @return Subtitle text
*/
public String getSubtitle() {
return this.subtitle;
}
/**
* Set the title color
*
* @param color Chat color
*/
public void setTitleColor(ChatColor color) {
this.titleColor = color;
}
/**
* Set the subtitle color
*
* @param color Chat color
*/
public void setSubtitleColor(ChatColor color) {
this.subtitleColor = color;
}
/**
* Set title fade in time
*
* @param time Time
*/
public void setFadeInTime(int time) {
this.fadeInTime = time;
}
/**
* Set title fade out time
*
* @param time Time
*/
public void setFadeOutTime(int time) {
this.fadeOutTime = time;
}
/**
* Set title stay time
*
* @param time Time
*/
public void setStayTime(int time) {
this.stayTime = time;
}
/**
* Set timings to ticks
*/
public void setTimingsToTicks() {
ticks = true;
}
/**
* Set timings to seconds
*/
public void setTimingsToSeconds() {
ticks = false;
}
/**
* Send the title to a player
*
* @param player Player
*/
public void send(Player player) {
if (packetTitle != null) {
// First reset previous settings
resetTitle(player);
try {
// Send timings first
Object handle = getHandle(player);
Object connection = playerConnection.get(handle);
Object[] actions = packetActions.getEnumConstants();
Object packet = packetTitle.getConstructor(packetActions,
chatBaseComponent, Integer.TYPE, Integer.TYPE,
Integer.TYPE).newInstance(actions[3], null,
fadeInTime * (ticks ? 1 : 20),
stayTime * (ticks ? 1 : 20),
fadeOutTime * (ticks ? 1 : 20));
// Send if set
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
sendPacket.invoke(connection, packet);
Object serialized;
if (!subtitle.equals("")) {
// Send subtitle if present
serialized = nmsChatSerializer.getConstructor(String.class)
.newInstance(subtitleColor +
ChatColor.translateAlternateColorCodes('&',
subtitle));
packet = packetTitle.getConstructor(packetActions,
chatBaseComponent).newInstance(actions[1],
serialized);
sendPacket.invoke(connection, packet);
}
// Send title
serialized = nmsChatSerializer.getConstructor(
String.class).newInstance(titleColor +
ChatColor.translateAlternateColorCodes('&', title));
packet = packetTitle.getConstructor(packetActions,
chatBaseComponent).newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void updateTimes(Player player) {
if (TitleManager_1_11.packetTitle != null) {
try {
Object handle = getHandle(player);
Object connection = playerConnection.get(handle);
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
Object packet = TitleManager_1_11.packetTitle.getConstructor(
new Class[]{TitleManager_1_11.packetActions, chatBaseComponent,
Integer.TYPE, Integer.TYPE, Integer.TYPE})
.newInstance(
actions[3],
null,
this.fadeInTime
* (this.ticks ? 1 : 20),
this.stayTime
* (this.ticks ? 1 : 20),
this.fadeOutTime
* (this.ticks ? 1 : 20));
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1)
&& (this.stayTime != -1)) {
sendPacket.invoke(connection, packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void updateTitle(Player player) {
if (TitleManager_1_11.packetTitle != null) {
try {
Object handle = getHandle(player);
Object connection = getField(handle.getClass(),
"playerConnection").get(handle);
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(),
"sendPacket");
Object serialized = nmsChatSerializer.getConstructor(
String.class)
.newInstance(titleColor +
ChatColor.translateAlternateColorCodes('&',
this.title));
Object packet = TitleManager_1_11.packetTitle
.getConstructor(
new Class[]{TitleManager_1_11.packetActions,
chatBaseComponent}).newInstance(
actions[0], serialized);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void updateSubtitle(Player player) {
if (TitleManager_1_11.packetTitle != null) {
try {
Object handle = getHandle(player);
Object connection = playerConnection.get(handle);
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
Object serialized = nmsChatSerializer.getConstructor(
String.class)
.newInstance(subtitleColor +
ChatColor.translateAlternateColorCodes('&',
this.subtitle));
Object packet = TitleManager_1_11.packetTitle
.getConstructor(
new Class[]{TitleManager_1_11.packetActions,
chatBaseComponent}).newInstance(
actions[1], serialized);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Broadcast the title to all players
*/
public void broadcast() {
for (Player p : Bukkit.getOnlinePlayers()) {
send(p);
}
}
/**
* Clear the title
*
* @param player Player
*/
public void clearTitle(Player player) {
try {
// Send timings first
Object handle = getHandle(player);
Object connection = playerConnection.get(handle);
Object[] actions = packetActions.getEnumConstants();
Object packet = packetTitle.getConstructor(packetActions,
chatBaseComponent).newInstance(actions[4], null);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Reset the title settings
*
* @param player Player
*/
public void resetTitle(Player player) {
try {
// Send timings first
Object handle = getHandle(player);
Object connection = playerConnection.get(handle);
Object[] actions = packetActions.getEnumConstants();
Object packet = packetTitle.getConstructor(packetActions,
chatBaseComponent).newInstance(actions[5], null);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
private Class<?> getPrimitiveType(Class<?> clazz) {
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES
.get(clazz) : clazz;
}
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
int a = classes != null ? classes.length : 0;
Class<?>[] types = new Class<?>[a];
for (int i = 0; i < a; i++)
types[i] = getPrimitiveType(classes[i]);
return types;
}
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length)
return false;
for (int i = 0; i < a.length; i++)
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
return false;
return true;
}
private Object getHandle(Player player) {
try {
return methodPlayerGetHandle.invoke(player);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(String name, Class<?> clazz,
Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t))
return m;
}
return null;
}
private String getVersion() {
String name = Bukkit.getServer().getClass().getPackage().getName();
String version = name.substring(name.lastIndexOf('.') + 1) + ".";
return version;
}
private Class<?> getNMSClass(String className) {
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = null;
try {
clazz = Class.forName(fullName);
} catch (Exception e) {
e.printStackTrace();
}
return clazz;
}
private Class<?> getOBCClass(String className) {
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz = null;
try {
clazz = Class.forName(fullName);
} catch (Exception e) {
e.printStackTrace();
}
return clazz;
}
private Field getField(Class<?> clazz, String name) {
try {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods())
if (m.getName().equals(name)
&& (args.length == 0 || ClassListEqual(args,
m.getParameterTypes()))) {
m.setAccessible(true);
return m;
}
return null;
}
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
boolean equal = true;
if (l1.length != l2.length)
return false;
for (int i = 0; i < l1.length; i++)
if (l1[i] != l2[i]) {
equal = false;
break;
}
return equal;
}
public ChatColor getTitleColor() {
return titleColor;
}
public ChatColor getSubtitleColor() {
return subtitleColor;
}
public int getFadeInTime() {
return fadeInTime;
}
public int getFadeOutTime() {
return fadeOutTime;
}
public int getStayTime() {
return stayTime;
}
public boolean isTicks() {
return ticks;
}
}

View File

@ -516,6 +516,7 @@ public class BukkitChunkManager extends ChunkManager {
case SHULKER_BULLET:
case SPECTRAL_ARROW:
case DRAGON_FIREBALL:
case LLAMA_SPIT:
// projectile
case PRIMED_TNT:
case FALLING_BLOCK:
@ -533,6 +534,7 @@ public class BukkitChunkManager extends ChunkManager {
case UNKNOWN:
case AREA_EFFECT_CLOUD:
case LINGERING_POTION:
case EVOKER_FANGS:
// non moving / unremovable
break;
case ITEM_FRAME:
@ -566,6 +568,11 @@ public class BukkitChunkManager extends ChunkManager {
case COW:
case SNOWMAN:
case BAT:
case DONKEY:
case LLAMA:
case SKELETON_HORSE:
case ZOMBIE_HORSE:
case MULE:
// animal
count[3]++;
count[1]++;
@ -589,6 +596,14 @@ public class BukkitChunkManager extends ChunkManager {
case WITHER:
case ZOMBIE:
case SHULKER:
case ELDER_GUARDIAN:
case STRAY:
case HUSK:
case EVOKER:
case VEX:
case WITHER_SKELETON:
case ZOMBIE_VILLAGER:
case VINDICATOR:
// monster
count[3]++;
count[2]++;
@ -610,27 +625,27 @@ public class BukkitChunkManager extends ChunkManager {
public static class ContentMap {
public final Map<BlockLoc, ItemStack[]> chestContents;
public final Map<BlockLoc, ItemStack[]> furnaceContents;
public final Map<BlockLoc, ItemStack[]> dispenserContents;
public final Map<BlockLoc, ItemStack[]> dropperContents;
public final Map<BlockLoc, ItemStack[]> brewingStandContents;
public final Map<BlockLoc, ItemStack[]> beaconContents;
public final Map<BlockLoc, ItemStack[]> hopperContents;
public final Map<BlockLoc, Short[]> furnaceTime;
public final Map<BlockLoc, Object[]> skullData;
public final Map<BlockLoc, Material> jukeboxDisc;
public final Map<BlockLoc, Short> brewTime;
public final Map<BlockLoc, EntityType> spawnerData;
public final Map<BlockLoc, String> cmdData;
public final Map<BlockLoc, String[]> signContents;
public final Map<BlockLoc, Note> noteBlockContents;
public final Map<BlockLoc, List<Pattern>> bannerPatterns;
public final Map<BlockLoc, DyeColor> bannerBase;
public final Set<EntityWrapper> entities;
public final Map<PlotLoc, PlotBlock[]> allBlocks;
final Map<BlockLoc, ItemStack[]> chestContents;
final Map<BlockLoc, ItemStack[]> furnaceContents;
final Map<BlockLoc, ItemStack[]> dispenserContents;
final Map<BlockLoc, ItemStack[]> dropperContents;
final Map<BlockLoc, ItemStack[]> brewingStandContents;
final Map<BlockLoc, ItemStack[]> beaconContents;
final Map<BlockLoc, ItemStack[]> hopperContents;
final Map<BlockLoc, Short[]> furnaceTime;
final Map<BlockLoc, Object[]> skullData;
final Map<BlockLoc, Material> jukeboxDisc;
final Map<BlockLoc, Short> brewTime;
final Map<BlockLoc, EntityType> spawnerData;
final Map<BlockLoc, String> cmdData;
final Map<BlockLoc, String[]> signContents;
final Map<BlockLoc, Note> noteBlockContents;
final Map<BlockLoc, List<Pattern>> bannerPatterns;
final Map<BlockLoc, DyeColor> bannerBase;
final Set<EntityWrapper> entities;
final Map<PlotLoc, PlotBlock[]> allBlocks;
public ContentMap() {
ContentMap() {
this.chestContents = new HashMap<>();
this.furnaceContents = new HashMap<>();
this.dispenserContents = new HashMap<>();

View File

@ -85,7 +85,7 @@ public class BukkitEventUtil extends EventUtil {
@Override
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getArea().worldname), plot, plots));
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
}
@Override
@ -110,12 +110,12 @@ public class BukkitEventUtil extends EventUtil {
@Override
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
}
@Override
public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
}
@Override

View File

@ -12,8 +12,6 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
import java.util.HashSet;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@ -23,6 +21,9 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData;
import java.util.HashSet;
import java.util.Random;
public class BukkitHybridUtils extends HybridUtils {
@Override
@ -50,7 +51,8 @@ public class BukkitHybridUtils extends HybridUtils {
}
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
@Override
public void setBiome(int a, int b, Biome c) {}
public void setBiome(int a, int b, Biome c) {
}
@Override
public Biome getBiome(int a, int b) {
@ -171,11 +173,13 @@ public class BukkitHybridUtils extends HybridUtils {
}
Material material = Material.getMaterial(now);
Class<? extends MaterialData> md = material.getData();
if (md.equals(Directional.class)) {
data[i] += 8;
} else if (!md.equals(MaterialData.class)) {
data[i]++;
if (material != null) {
Class<? extends MaterialData> md = material.getData();
if (md.equals(Directional.class)) {
data[i] += 8;
} else if (!md.equals(MaterialData.class)) {
data[i]++;
}
}
types.add(now);
}

View File

@ -9,18 +9,20 @@ import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
public class BukkitSetupUtils extends SetupUtils {
@ -31,23 +33,49 @@ public class BukkitSetupUtils extends SetupUtils {
}
String testWorld = "CheckingPlotSquaredGenerator";
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin.isEnabled()) {
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
if (generator != null) {
PS.get().removePlotAreas(testWorld);
String name = plugin.getDescription().getName();
GeneratorWrapper<?> wrapped;
if (generator instanceof GeneratorWrapper<?>) {
wrapped = (GeneratorWrapper<?>) generator;
} else {
wrapped = new BukkitPlotGenerator(testWorld, generator);
try {
if (plugin.isEnabled()) {
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
if (generator != null) {
PS.get().removePlotAreas(testWorld);
String name = plugin.getDescription().getName();
GeneratorWrapper<?> wrapped;
if (generator instanceof GeneratorWrapper<?>) {
wrapped = (GeneratorWrapper<?>) generator;
} else {
wrapped = new BukkitPlotGenerator(testWorld, generator);
}
SetupUtils.generators.put(name, wrapped);
}
SetupUtils.generators.put(name, wrapped);
}
} catch (Throwable e) { // Recover from third party generator error
e.printStackTrace();
}
}
}
@Override
public void unload(String worldName, boolean save) {
World world = Bukkit.getWorld(worldName);
if (world == null) {
return;
}
World dw = Bukkit.getWorlds().get(0);
for (Player player : world.getPlayers()) {
player.teleport(dw.getSpawnLocation());
}
if (save) {
for (Chunk chunk : world.getLoadedChunks()) {
chunk.unload(true, false);
}
} else {
for (Chunk chunk : world.getLoadedChunks()) {
chunk.unload(false, false);
}
}
Bukkit.unloadWorld(world, false);
}
@Override
public String setupWorld(SetupObject object) {
SetupUtils.manager.updateGenerators();
@ -55,13 +83,13 @@ public class BukkitSetupUtils extends SetupUtils {
String world = object.world;
int type = object.type;
String worldPath = "worlds." + object.world;
if (!PS.get().worlds.contains(worldPath)) {
PS.get().worlds.createSection(worldPath);
}
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
switch (type) {
case 2: {
if (object.id != null) {
if (!PS.get().worlds.contains(worldPath)) {
PS.get().worlds.createSection(worldPath);
}
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
String areaName = object.id + "-" + object.min + "-" + object.max;
String areaPath = "areas." + areaName;
if (!worldSection.contains(areaPath)) {
@ -97,7 +125,11 @@ public class BukkitSetupUtils extends SetupUtils {
}
break;
}
case 1:
case 1: {
if (!PS.get().worlds.contains(worldPath)) {
PS.get().worlds.createSection(worldPath);
}
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue());
}
@ -112,11 +144,19 @@ public class BukkitSetupUtils extends SetupUtils {
object.setupGenerator = null;
}
break;
case 0:
for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue());
}
case 0: {
if (steps.length != 0) {
if (!PS.get().worlds.contains(worldPath)) {
PS.get().worlds.createSection(worldPath);
}
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue());
}
}
break;
}
}
try {
PS.get().worlds.save(PS.get().worldsFile);
@ -143,6 +183,7 @@ public class BukkitSetupUtils extends SetupUtils {
WorldCreator wc = new WorldCreator(object.world);
wc.generator(object.setupGenerator);
wc.environment(Environment.NORMAL);
wc.type(WorldType.FLAT);
Bukkit.createWorld(wc);
setGenerator(world, object.setupGenerator);
} else {
@ -159,7 +200,7 @@ public class BukkitSetupUtils extends SetupUtils {
return world;
}
}
Bukkit.createWorld(new WorldCreator(object.world).environment(World.Environment.NORMAL));
World bw = Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL));
}
return object.world;
}

View File

@ -7,10 +7,10 @@ import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.bukkit.object.BukkitPlayer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
@ -80,15 +80,7 @@ public class BukkitUtil extends WorldUtil {
}
public static World getWorld(String string) {
if (StringMan.isEqual(string, lastString)) {
if (lastWorld != null) {
return lastWorld;
}
}
World world = Bukkit.getWorld(string);
lastString = string;
lastWorld = world;
return world;
return Bukkit.getWorld(string);
}
public static String getWorld(Entity entity) {
@ -96,7 +88,8 @@ public class BukkitUtil extends WorldUtil {
}
public static List<Entity> getEntities(String worldName) {
return getWorld(worldName).getEntities();
World world = getWorld(worldName);
return world != null ? world.getEntities() : new ArrayList<Entity>();
}
public static Location getLocation(Entity entity) {
@ -178,7 +171,26 @@ public class BukkitUtil extends WorldUtil {
@Override
public int getHighestBlock(String world, int x, int z) {
return getWorld(world).getHighestBlockAt(x, z).getY();
World bukkitWorld = getWorld(world);
// Skip top and bottom block
for (int y = bukkitWorld.getMaxHeight() - 2; y > 0; y--) {
Block block = bukkitWorld.getBlockAt(x, y, z);
if (block != null) {
Material type = block.getType();
if (type.isSolid()) {
return y + 1;
} else {
switch (type) {
case WATER:
case LAVA:
case STATIONARY_LAVA:
case STATIONARY_WATER:
return y;
}
}
}
}
return bukkitWorld.getMaxHeight();
}
@Override

View File

@ -0,0 +1,14 @@
package com.plotsquared.bukkit.util;
public class BukkitVersion {
public static int[] v1_11_0 = {1, 11, 0};
public static int[] v1_10_2 = {1, 10, 2};
public static int[] v1_10_0 = {1, 10, 0};
public static int[] v1_9_4 = {1, 9, 4};
public static int[] v1_9_0 = {1, 9, 0};
public static int[] v1_8_3 = {1, 8, 3};
public static int[] v1_8_0 = {1, 8, 0};
public static int[] v1_7_6 = {1, 7, 6};
public static int[] v1_7_0 = {1, 7, 0};
public static int[] v1_6_0 = {1, 6, 0};
}

View File

@ -6,21 +6,14 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import com.google.common.io.ByteSink;
import com.google.common.io.ByteSource;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.primitives.Primitives;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.io.BufferedInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -41,6 +34,10 @@ import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
public class NbtFactory {
@ -161,19 +158,16 @@ public class NbtFactory {
/**
* Load the content of a file from a stream.
*
* Use {@link Files#newInputStreamSupplier(File)} to provide a stream from a file.
* @param stream - the stream supplier.
* @param option - whether or not to decompress the input stream.
* @return The decoded NBT compound.
* @throws IOException If anything went wrong.
*/
public static NbtCompound fromStream(ByteSource stream, StreamOptions option) throws IOException {
InputStream input = null;
public static NbtCompound fromStream(InputStream input, StreamOptions option) throws IOException {
DataInputStream data = null;
boolean suppress = true;
try {
input = stream.openStream();
if (option == StreamOptions.GZIP_COMPRESSION) {
data = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input)));
} else {
@ -196,7 +190,6 @@ public class NbtFactory {
/**
* Save the content of a NBT compound to a stream.
*
* Use {@link Files#newOutputStreamSupplier(File)} to provide a stream supplier to a file.
* @param source - the NBT compound to save.
* @param stream - the stream.
* @param option - whether or not to compress the output.
@ -445,8 +438,7 @@ public class NbtFactory {
/**
* Convert a given NBT element to a primitive wrapper or List/Map equivalent.
* <p>
* All changes to any mutable objects will be reflected in the underlying NBT element(s).
* <p> All changes to any mutable objects will be reflected in the underlying NBT element(s).
* @param nms - the NBT element.
* @return The wrapper equivalent.
*/
@ -605,7 +597,7 @@ public class NbtFactory {
*/
private static class LoadMethodWorldUpdate extends LoadCompoundMethod {
public LoadMethodWorldUpdate(Class<?> streamClass) {
LoadMethodWorldUpdate(Class<?> streamClass) {
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
}
@ -622,7 +614,7 @@ public class NbtFactory {
private Object readLimiter;
public LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass));
// Find the unlimited read limiter
@ -645,8 +637,7 @@ public class NbtFactory {
/**
* Represents a root NBT compound.
* <p>
* All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
* <p> All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
* <ul>
* <li>Primitive types</li>
* <li>{@link String String}</li>
@ -769,8 +760,6 @@ public class NbtFactory {
/**
* Save the content of a NBT compound to a stream.
* <p>
* Use {@link Files#newOutputStreamSupplier(File)} to provide a stream supplier to a file.
* @param stream - the output stream.
* @param option - whether or not to compress the output.
* @throws IOException If anything went wrong.

View File

@ -50,7 +50,7 @@ public class SendChunk {
RefClass classChunk = getRefClass("{nms}.Chunk");
this.methodInitLighting = classChunk.getMethod("initLighting");
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
//this works for 1.9.4 and 1.10
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),int.class);
} else {
@ -89,7 +89,7 @@ public class SendChunk {
Location location = null;
String world;
if (plot != null) {
world = plot.getArea().worldname;
world = plot.getWorldName();
} else {
location = pp.getLocation();
world = location.getWorld();
@ -116,7 +116,7 @@ public class SendChunk {
chunks.remove(chunk);
Object con = this.connection.of(entity).get();
Object packet = null;
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
try {
packet = this.mapChunk.create(c,65535);
} catch (Exception ignored) {}

View File

@ -4,6 +4,8 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
@ -126,4 +128,60 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
}
}
}
private Field fieldNeighbors;
private Method chunkGetHandle;
/**
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
* - Could have been achieved without reflection by force unloading specific chunks
* - Much faster just setting the variable manually though
* @param chunk
* @return
*/
protected Object[] disableLighting(Chunk chunk) {
try {
if (chunkGetHandle == null) {
chunkGetHandle = chunk.getClass().getDeclaredMethod("getHandle");
chunkGetHandle.setAccessible(true);
}
Object nmsChunk = chunkGetHandle.invoke(chunk);
if (fieldNeighbors == null) {
fieldNeighbors = nmsChunk.getClass().getDeclaredField("neighbors");
fieldNeighbors.setAccessible(true);
}
Object value = fieldNeighbors.get(nmsChunk);
fieldNeighbors.set(nmsChunk, 0);
return new Object[] {nmsChunk, value};
} catch (Throwable ignore) {}
return null;
}
protected void disableLighting(Object[] disableResult) {
if (disableResult != null) {
try {
fieldNeighbors.set(disableResult[0], 0);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
protected void resetLighting(Object[] disableResult) {
if (disableResult != null) {
try {
fieldNeighbors.set(disableResult[0], disableResult[1]);
} catch (Throwable ignore) {
ignore.printStackTrace();
}
}
}
protected void enableLighting(Object[] disableResult) {
if (disableResult != null) {
try {
fieldNeighbors.set(disableResult[0], 0x739C0);
} catch (Throwable ignore) {}
}
}
}

View File

@ -25,7 +25,9 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
private final ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
private final ReflectionUtils.RefClass classWorld = getRefClass("{nms}.World");
private final ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
private final ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
private final ReflectionUtils.RefMethod methodGetHandle;
private final ReflectionUtils.RefMethod methodGetHandleChunk;
private final ReflectionUtils.RefMethod methodGetChunkAt;
private final ReflectionUtils.RefMethod methodA;
private final ReflectionUtils.RefMethod methodGetById;
@ -40,6 +42,7 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
this.methodA = this.classChunk.getMethod("a", int.class, int.class, int.class, this.classBlock, int.class);
this.methodGetById = this.classBlock.getMethod("getById", int.class);
this.methodGetHandleChunk = this.classCraftChunk.getMethod("getHandle");
this.methodInitLighting = this.classChunk.getMethod("initLighting");
this.sendChunk = new SendChunk();
TaskManager.runTaskRepeat(new Runnable() {
@ -87,7 +90,7 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
@Override
public void fixChunkLighting(int x, int z) {
Object c = this.methodGetHandle.of(getChunk(x, z)).call();
Object c = this.methodGetHandleChunk.of(getChunk(x, z)).call();
this.methodInitLighting.of(c).call();
}
@ -112,12 +115,14 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
int y = MainUtil.y_loc[i][j];
int z = MainUtil.z_loc[i][j];
PlotBlock newBlock = result2[j];
if (newBlock.id == -1) {
chunk.getBlock(x, y, z).setData(newBlock.data, false);
continue;
if (newBlock != null) {
if (newBlock.id == -1) {
chunk.getBlock(x, y, z).setData(newBlock.data, false);
continue;
}
Object block = this.methodGetById.call(newBlock.id);
this.methodA.of(c).call(x, y, z, block, newBlock.data);
}
Object block = this.methodGetById.call(newBlock.id);
this.methodA.of(c).call(x, y, z, block, newBlock.data);
}
}
fixChunkLighting(lc.getX(), lc.getZ());

View File

@ -276,7 +276,7 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
Field tileEntities = clazz.getDeclaredField("tileEntities");
Field entitySlices = clazz.getDeclaredField("entitySlices");
Object[] sections = (Object[]) sections1.get(c);
HashMap<?, ?> tiles = (HashMap<?, ?>) tileEntities.get(c);
Map<?, ?> tiles = (Map<?, ?>) tileEntities.get(c);
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
Method getX = null;
@ -403,11 +403,11 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
}
}
}
/*
/*
if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
return false;
}
*/
*/
}
this.methodInitLighting.of(c).call();

View File

@ -1,9 +1,7 @@
package com.plotsquared.bukkit.util.block;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ChunkWrapper;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
@ -11,7 +9,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ -256,14 +253,14 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
Field tf = clazz.getDeclaredField("tileEntities");
Field entitySlices = clazz.getDeclaredField("entitySlices");
Object[] sections = (Object[]) sf.get(c);
HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
Map<?, ?> tiles = (Map<?, ?>) tf.get(c);
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
Method xm = null;
Method ym = null;
Method zm = null;
// Trim tiles
boolean removed = false;
Collection tickList = ((Collection) this.tileEntityListTick.of(w).get());
Set<Map.Entry<?, ?>> entrySet = (Set<Map.Entry<?, ?>>) (Set<?>) tiles.entrySet();
Iterator<Map.Entry<?, ?>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
@ -285,13 +282,10 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
continue;
}
if (array[k] != 0) {
removed = true;
tickList.remove(tile.getValue());
iterator.remove();
}
}
if (removed) {
((Collection) this.tileEntityListTick.of(w).get()).clear();
}
// Trim entities
for (int i = 0; i < 16; i++) {
@ -380,87 +374,73 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
Object c = this.methodGetHandleChunk.of(chunk).call();
ChunkWrapper wrapper = new ChunkWrapper(getWorld(), bc.getX(), bc.getZ());
if (fixAll && !(boolean) this.methodAreNeighborsLoaded.of(c).call(1)) {
World world = chunk.getWorld();
for (int x = wrapper.x - 1; x <= wrapper.x + 1; x++) {
for (int z = wrapper.z - 1; z <= wrapper.z + 1; z++) {
if (x != 0 && z != 0) {
Chunk other = world.getChunkAt(x, z);
while (!other.isLoaded()) {
other.load(true);
}
ChunkManager.manager.loadChunk(getWorld(), new ChunkLoc(x, z), true);
}
}
}
}
Object[] result = disableLighting(chunk);
enableLighting(result);
this.methodInitLighting.of(c).call();
if (bc.getTotalRelight() == 0 && !fixAll) {
return true;
}
if (bc.getTotalRelight() != 0 || fixAll) {
Object[] sections = (Object[]) this.fieldSections.of(c).get();
Object w = this.fieldWorld.of(c).get();
Object[] sections = (Object[]) this.fieldSections.of(c).get();
Object w = this.fieldWorld.of(c).get();
int X = chunk.getX() << 4;
int Z = chunk.getZ() << 4;
ReflectionUtils.RefMethod.RefExecutor relight = this.methodW.of(w);
for (int j = 0; j < sections.length; j++) {
Object section = sections[j];
if (section == null) {
continue;
}
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0 || bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
continue;
}
char[] array = bc.getIdArray(j);
if (array != null) {
int l = PseudoRandom.random.random(2);
for (int k = 0; k < array.length; k++) {
int i = array[k];
if (i < 16) {
continue;
}
short id = (short) (i >> 4);
switch (id) { // Lighting
default:
if (!fixAll) {
continue;
}
if ((k & 1) == l) {
l = 1 - l;
continue;
}
case 10:
case 11:
case 39:
case 40:
case 50:
case 51:
case 62:
case 74:
case 76:
case 89:
case 122:
case 124:
case 130:
case 138:
case 169:
int x = MainUtil.x_loc[j][k];
int y = MainUtil.y_loc[j][k];
int z = MainUtil.z_loc[j][k];
if (isSurrounded(bc.blocks, x, y, z)) {
continue;
}
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
relight.call(pos);
int X = chunk.getX() << 4;
int Z = chunk.getZ() << 4;
ReflectionUtils.RefMethod.RefExecutor relight = this.methodW.of(w);
for (int j = 0; j < sections.length; j++) {
Object section = sections[j];
if (section == null) {
continue;
}
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0 || bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
continue;
}
char[] array = bc.getIdArray(j);
if (array != null) {
int l = PseudoRandom.random.random(2);
for (int k = 0; k < array.length; k++) {
int i = array[k];
if (i < 16) {
continue;
}
short id = (short) (i >> 4);
switch (id) { // Lighting
default:
if (!fixAll) {
continue;
}
if ((k & 1) == l) {
l = 1 - l;
continue;
}
case 10:
case 11:
case 39:
case 40:
case 50:
case 51:
case 62:
case 74:
case 76:
case 89:
case 122:
case 124:
case 130:
case 138:
case 169:
int x = MainUtil.x_loc[j][k];
int y = MainUtil.y_loc[j][k];
int z = MainUtil.z_loc[j][k];
if (isSurrounded(bc.blocks, x, y, z)) {
continue;
}
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
relight.call(pos);
}
}
}
}
}
resetLighting(result);
return true;
} catch (Throwable e) {
e.printStackTrace();

View File

@ -28,12 +28,6 @@ public class GenChunk extends ScopedLocalBlockQueue {
public GenChunk(Chunk chunk, ChunkWrapper wrap) {
super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15));
if ((this.chunk = chunk) == null && (wrap) != null) {
World world = BukkitUtil.getWorld(wrap.world);
if (world != null) {
this.chunk = world.getChunkAt(wrap.x, wrap.z);
}
}
this.biomes = Biome.values();
}
@ -168,8 +162,6 @@ public class GenChunk extends ScopedLocalBlockQueue {
return new Location(getWorld(), getX() << 4, 0, getZ() << 4);
}
public GenChunk clone() {
GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
if (this.result != null) {
@ -193,7 +185,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
}
public GenChunk shallowClone() {
GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), getX(), getZ()));
toReturn.result = this.result;
toReturn.result_data = this.result_data;
toReturn.cd = this.cd;

View File

@ -2,7 +2,6 @@ package com.plotsquared.bukkit.uuid;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Sets;
import com.google.common.io.ByteSource;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
@ -17,6 +16,7 @@ import com.intellectualcrafters.plot.util.expiry.ExpireManager;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.util.NbtFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -94,8 +94,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
UUID uuid = UUID.fromString(s);
if (check || all.remove(uuid)) {
File file = new File(playerDataFolder, current);
ByteSource is = com.google.common.io.Files.asByteSource(file);
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
NbtFactory.NbtCompound compound = NbtFactory.fromStream(new FileInputStream(file), NbtFactory.StreamOptions.GZIP_COMPRESSION);
if (!compound.containsKey("bukkit")) {
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
} else {
@ -160,8 +159,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
if (!file.exists()) {
continue;
}
ByteSource is = com.google.common.io.Files.asByteSource(file);
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
NbtFactory.NbtCompound compound = NbtFactory.fromStream(new FileInputStream(file), NbtFactory.StreamOptions.GZIP_COMPRESSION);
if (!compound.containsKey("bukkit")) {
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
} else {

View File

@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
@ -123,15 +124,17 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
HttpURLConnection connection =
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
.openConnection();
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
String name = (String) response.get("name");
if (name != null) {
add(new StringWrapper(name), uuid);
try (InputStream con = connection.getInputStream()) {
InputStreamReader reader = new InputStreamReader(con);
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
String name = (String) response.get("name");
if (name != null) {
add(new StringWrapper(name), uuid);
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
PS.debug("Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
}
TaskManager.runTaskLaterAsync(this, SQLUUIDHandler.this.INTERVAL);
}

View File

@ -10,8 +10,8 @@ loadbefore: [MultiWorld, Multiverse-Core]
database: false
commands:
plots:
description: PlotSquared PlotSquared command.
aliases: [p,plot,ps,plotsquared,p2,2]
description: Plot command.
aliases: [p,plot,ps,plotsquared,p2,2,plotme]
permission: plots.use
permission-message: "You are lacking the permission node 'plots.use'"
permissions:
@ -104,6 +104,7 @@ permissions:
plots.home: true
plots.clear: true
plots.delete: true
plots.music: true
plots.list: true
plots.list.mine: true
plots.list.shared: true
@ -130,6 +131,10 @@ permissions:
plots.toggle.chat: true
plots.set.biome: true
plots.set.home: true
plots.set.alias: true
plots.set.description: true
plots.description: true
plots.alias: true
plots.merge: true
plots.merge.other: true
plots.merge.4: true
@ -153,3 +158,156 @@ permissions:
default: op
plots.confirm.bypass:
default: false
plotme.use:
description: Gives default user commands
children:
plots.permpack.basic: true
plots.plot.1: true
plotme.admin:
description: Gives default administrator commands
children:
plots.admin: true
plotme.use.middle:
children:
plots.middle: true
plotme.use.buy:
children:
plots.buy: true
plotme.use.sell:
children:
plots.set: true
plots.flag: true
plots.set.flag: true
plots.set.price.*: true
plotme.use.dispose:
children:
plots.delete: true
plotme.use.done:
children:
plots.done: true
plotme.use.claim:
children:
plots.claim: true
plotme.use.auto:
children:
plots.auto: true
plotme.use.reset:
children:
plots.delete: true
plotme.use.home:
children:
plots.home: true
plotme.use.info:
children:
plots.info: true
plotme.use.biome:
children:
plots.set: true
plots.set.biome: true
plotme.use.clear:
children:
plots.clear: true
plotme.use.list:
children:
plots.list: true
plots.list.forsale: true
plots.list.mine: true
plots.list.shared: true
plotme.use.add:
children:
plots.add: true
plots.trust: true
plots.add.everyone: true
plots.trust.everyone: true
plotme.use.deny:
children:
plots.deny: true
plots.deny.everyone: true
plotme.use.remove:
children:
plots.remove: true
plotme.use.undeny:
children:
plots.remove: true
plotme.use.protect:
children:
plots.set: true
plots.flag: true
plots.set.flag: true
plots.set.keep.*: true
plotme.use.nameplot:
children:
plots.set.alias: true
plotme.limit.*:
children:
plots.plot.*: true
plotme.limit.1:
children:
plots.plot.1: true
plotme.limit.5:
children:
plots.plot.5: true
plotme.limit.10:
children:
plots.plot.10: true
plotme.admin.home.other:
children:
plots.plot.: true
plotme.admin.clear:
children:
plots.admin.command.clear: true
plotme.admin.reset:
children:
plots.admin.command.delete: true
plotme.admin.add:
children:
plots.admin.command.add: true
plotme.admin.deny:
children:
plots.admin.command.deny: true
plotme.admin.remove:
children:
plots.admin.command.remove: true
plotme.admin.undeny:
children:
plots.admin.command.remove: true
plotme.admin.bypassdeny:
children:
plots.admin.entry.denied: true
plotme.admin.setowner:
children:
plots.admin.command.setowner: true
plotme.admin.move:
children:
plots.admin.command.move: true
plotme.admin.weanywhere:
children:
plots.worldedit.bypass: true
plotme.admin.list:
children:
plots.list.world: true
plots.list.world.*: true
plots.list.top: true
plots.list.all: true
plots.list.unowned: true
plots.list.unknown: true
plots.list.player: true
plots.list.done: true
plots.list.expired: true
plots.list.fuzzy: true
plots.list.area: true
plotme.admin.dispose:
children:
plots.admin.command.delete: true
plotme.admin.done:
children:
plots.admin.command.done: true
plotme.admin.expired:
children:
plots.list.expired: true
plotme.admin.buildanywhere:
children:
plots.admin.vehicle.*: true
plots.admin.interact.*: true
plots.admin.build.*: true
plots.admin.destroy.*: true

View File

@ -7,5 +7,46 @@ dependencies {
sourceCompatibility = 1.7
targetCompatibility = 1.7
jar.archiveName = "PlotSquared-Core-${parent.version}.jar"
jar.destinationDir = file '../target'
processResources {
from('src/main/resources') {
include 'plugin.properties'
expand(
version: "${project.parent.version}",
name: project.parent.name,
)
}
}
jar.archiveName="plotsquared-api-${project.parent.version}.jar"
jar.destinationDir = file '../mvn/com/plotsquared/plotsquared-api/' + project.parent.version
task createPom << {
pom {
project {
groupId 'com.plotsquared'
artifactId 'plotsquared-api'
version project.parent.version
}
}.writeTo("../mvn/com/plotsquared/plotsquared-api/${project.parent.version}/plotsquared-api-${project.parent.version}.pom")
pom {
project {
groupId 'com.plotsquared'
artifactId 'plotsquared-api'
version 'latest'
}
}.writeTo("../mvn/com/plotsquared/plotsquared-api/latest/plotsquared-api-latest.pom")
}
task copyFiles {
doLast {
copy {
from "../mvn/com/plotsquared/plotsquared-api/${project.parent.version}/"
into '../mvn/com/plotsquared/plotsquared-api/latest/'
include('*.jar')
rename ("plotsquared-api-${project.parent.version}.jar", 'plotsquared-api-latest.jar')
}
}
}
build.finalizedBy(copyFiles)
copyFiles.dependsOn(createPom)

View File

@ -29,9 +29,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
@Override
public void addDefault(String path, Object value) {
if (path == null) {
throw new NullPointerException("Path may not be null");
}
if (this.defaults == null) {
this.defaults = new MemoryConfiguration();
}
@ -41,10 +38,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
@Override
public void addDefaults(Map<String, Object> defaults) {
if (defaults == null) {
throw new NullPointerException("Defaults may not be null");
}
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
addDefault(entry.getKey(), entry.getValue());
}
@ -52,10 +45,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
@Override
public void addDefaults(Configuration defaults) {
if (defaults == null) {
throw new NullPointerException("Defaults may not be null");
}
addDefaults(defaults.getValues(true));
}

View File

@ -49,13 +49,6 @@ public class MemorySection implements ConfigurationSection {
* if parent contains no root Configuration.
*/
protected MemorySection(ConfigurationSection parent, String path) {
if (parent == null) {
throw new NullPointerException("Parent may not be null");
}
if (path == null) {
throw new NullPointerException("Path may not be null");
}
this.path = path;
this.parent = parent;
this.root = parent.getRoot();
@ -133,7 +126,7 @@ public class MemorySection implements ConfigurationSection {
* @return Full path of the section from its root.
*/
public static String createPath(ConfigurationSection section, String key) {
return createPath(section, key, (section == null) ? null : section.getRoot());
return createPath(section, key, section.getRoot());
}
/**
@ -149,9 +142,6 @@ public class MemorySection implements ConfigurationSection {
* @return Full path of the section from its root.
*/
public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) {
if (section == null) {
throw new NullPointerException("Cannot create path without a section");
}
Configuration root = section.getRoot();
if (root == null) {
throw new IllegalStateException("Cannot create path without a root");
@ -253,10 +243,6 @@ public class MemorySection implements ConfigurationSection {
@Override
public void addDefault(String path, Object value) {
if (path == null) {
throw new NullPointerException("Path cannot be null");
}
Configuration root = getRoot();
if (root == null) {
throw new IllegalStateException("Cannot add default without root");
@ -283,10 +269,6 @@ public class MemorySection implements ConfigurationSection {
@Override
public void set(String path, Object value) {
if (path == null) {
throw new NullPointerException("Cannot set to an empty path");
}
Configuration root = getRoot();
if (root == null) {
throw new IllegalStateException("Cannot use section without a root");
@ -367,9 +349,6 @@ public class MemorySection implements ConfigurationSection {
@Override
public ConfigurationSection createSection(String path) {
if (path == null) {
throw new NullPointerException("Cannot create section at empty path");
}
Configuration root = getRoot();
if (root == null) {
throw new IllegalStateException("Cannot create section without a root");
@ -787,10 +766,6 @@ public class MemorySection implements ConfigurationSection {
}
protected Object getDefault(String path) {
if (path == null) {
throw new NullPointerException("Path may not be null");
}
Configuration root = getRoot();
Configuration defaults = root == null ? null : root.getDefaults();
return (defaults == null) ? null : defaults.get(createPath(this, path));

View File

@ -52,7 +52,10 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* any reason.
*/
public void save(File file) throws IOException {
file.getParentFile().mkdirs();
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
String data = saveToString();
@ -87,9 +90,6 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(File file) throws IOException, InvalidConfigurationException {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
FileInputStream stream = new FileInputStream(file);
@ -123,33 +123,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
loadFromString(builder.toString());
}
/**
* Loads this {@link FileConfiguration} from the specified location.
*
* <p>All the values contained within this configuration will be removed,
* leaving only settings and defaults, and the new values will be loaded
* from the given file.
*
* <p>If the file cannot be loaded for any reason, an exception will be
* thrown.
*
* @param file File to load from.
* @throws FileNotFoundException Thrown when the given file cannot be
* opened.
* @throws IOException Thrown when the given file cannot be read.
* @throws InvalidConfigurationException Thrown when the given file is not
* a valid Configuration.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(String file) throws IOException, InvalidConfigurationException {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
load(new File(file));
}
/**
* Loads this {@link FileConfiguration} from the specified string, as
* opposed to from file.

View File

@ -11,7 +11,6 @@ import org.yaml.snakeyaml.representer.Representer;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;
@ -38,13 +37,8 @@ public class YamlConfiguration extends FileConfiguration {
*
* @param file Input file
* @return Resulting configuration
* @throws IllegalArgumentException Thrown if file is null
*/
public static YamlConfiguration loadConfiguration(File file) {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
YamlConfiguration config = new YamlConfiguration();
try {
@ -70,34 +64,6 @@ public class YamlConfiguration extends FileConfiguration {
return config;
}
/**
* Creates a new {@link YamlConfiguration}, loading from the given reader.
*
* <p>Any errors loading the Configuration will be logged and then ignored.
* If the specified input is not a valid config, a blank config will be
* returned.
*
* @param reader input
* @return resulting configuration
* @throws IllegalArgumentException Thrown if stream is null
*/
public static YamlConfiguration loadConfiguration(Reader reader) {
if (reader == null) {
throw new NullPointerException("Reader cannot be null");
}
YamlConfiguration config = new YamlConfiguration();
try {
config.load(reader);
} catch (IOException | InvalidConfigurationException ex) {
PS.debug("Cannot load configuration from stream");
ex.printStackTrace();
}
return config;
}
@Override
public String saveToString() {
yamlOptions.setIndent(options().indent());
@ -116,9 +82,6 @@ public class YamlConfiguration extends FileConfiguration {
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
if (contents == null) {
throw new NullPointerException("Contents cannot be null");
}
Map<?, ?> input;
try {

View File

@ -168,8 +168,8 @@ public class JSONObject {
* The key is formed by removing the <code>"get"</code> or <code>"is"</code> prefix. If the second remaining
* character is not upper case, then the first character is converted to lower case.
*
* For example, if an object has a method named <code>"getName"</code>, and if the result of calling
* <code>object.getName()</code> is <code>"Larry Fine"</code>, then the JSONObject will contain <code>"name": "Larry
* For example, if an object has a method named <code>"getPluginName"</code>, and if the result of calling
* <code>object.getPluginName()</code> is <code>"Larry Fine"</code>, then the JSONObject will contain <code>"name": "Larry
* Fine"</code>.
*
* @param bean An object that has getter methods that should be used to make a JSONObject.

View File

@ -69,6 +69,12 @@ public interface IPlotMain extends ILogger {
*/
String getPluginVersionString();
/**
* Usually PlotSquared
* @return
*/
String getPluginName();
/**
* Get the version of Minecraft that is running.
* @return
@ -222,7 +228,7 @@ public interface IPlotMain extends ILogger {
*/
GeneratorWrapper<?> getGenerator(String world, String name);
GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator);
GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator);
/**
* Register the chunk processor which will clean out chunks that have too
@ -236,6 +242,12 @@ public interface IPlotMain extends ILogger {
*/
void registerWorldEvents();
/**
* Usually HybridGen
* @return Default implementation generator
*/
IndependentPlotGenerator getDefaultGenerator();
/**
* Get the class that will manage player titles.
* @return

View File

@ -28,6 +28,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.object.worlds.DefaultPlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager;
@ -44,7 +48,6 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap;
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
import com.intellectualcrafters.plot.util.expiry.ExpiryTask;
@ -67,6 +70,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -83,7 +87,7 @@ import java.util.zip.ZipInputStream;
/**
* An implementation of the core, with a static getter for easy access.
*/
public class PS {
public class PS{
private static PS instance;
// Implementation
public final IPlotMain IMP;
@ -92,10 +96,8 @@ public class PS {
// Current thread
private final Thread thread;
// Platform / Version / Update URL
private final String platform;
private final int[] version;
private int[] lastVersion;
public URL update;
private Updater updater;
private PlotVersion version;
// WorldEdit instance
public WorldEdit worldedit;
// Files and configuration
@ -114,15 +116,8 @@ public class PS {
// Temporary hold the plots/clusters before the worlds load
public HashMap<String, Set<PlotCluster>> clusters_tmp;
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
// All plot areas
private PlotArea[] plotAreas = new PlotArea[0];
// All plot areas mapped by world
private final HashMap<String, PlotArea[]> plotAreaMap = new HashMap<>();
// All plot areas mapped by position
private final HashMap<String, QuadMap<PlotArea>> plotAreaGrid = new HashMap<>();
// Optimization if there are no hash collisions
private boolean plotAreaHasCollision = false;
private final HashSet<Integer> plotAreaHashCheck = new HashSet<>();
private PlotAreaManager manager;
/**
* Initialize PlotSquared with the desired Implementation class.
@ -134,8 +129,7 @@ public class PS {
this.thread = Thread.currentThread();
this.IMP = iPlotMain;
this.logger = iPlotMain;
this.platform = platform;
this.version = this.IMP.getPluginVersion();
Settings.PLATFORM = platform;
try {
new ReflectionUtils(this.IMP.getNMSPackage());
try {
@ -149,14 +143,21 @@ public class PS {
}
}
if (getJavaVersion() < 1.8) {
PS.log(C.CONSOLE_JAVA_OUTDATED_1_8);
PS.log(C.CONSOLE_JAVA_OUTDATED.f(IMP.getPluginName()));
}
TaskManager.IMP = this.IMP.getTaskManager();
setupConfigs();
this.translationFile =
MainUtil.getFile(this.IMP.getDirectory(), Settings.Paths.TRANSLATIONS + File.separator + "PlotSquared.use_THIS.yml");
MainUtil.getFile(this.IMP.getDirectory(), Settings.Paths.TRANSLATIONS + File.separator + IMP.getPluginName() + ".use_THIS.yml");
C.load(this.translationFile);
// Setup manager
if (Settings.Enabled_Components.WORLDS) {
this.manager = new SinglePlotAreaManager();
} else {
this.manager = new DefaultPlotAreaManager();
}
// Database
if (Settings.Enabled_Components.DATABASE) {
setupDatabase();
@ -177,7 +178,7 @@ public class PS {
if (Settings.Enabled_Components.METRICS) {
this.IMP.startMetrics();
} else {
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS);
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(IMP.getPluginName()));
}
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
this.IMP.registerChunkProcessor();
@ -221,7 +222,7 @@ public class PS {
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
if (this.IMP.initWorldEdit()) {
PS.debug("PlotSquared hooked into WorldEdit.");
PS.debug(IMP.getPluginName() + " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber());
if (Settings.Enabled_Components.COMMANDS) {
@ -245,21 +246,19 @@ public class PS {
// Check for updates
if (Settings.Enabled_Components.UPDATER) {
TaskManager.runTaskAsync(new Runnable() {
updater = new Updater();
TaskManager.IMP.taskAsync(new Runnable() {
@Override
public void run() {
URL url = Updater.getUpdate();
if (url != null) {
PS.this.update = url;
} else if (PS.this.lastVersion == null) {
PS.log("&aThanks for installing PlotSquared!");
} else if (!get().checkVersion(PS.this.lastVersion, PS.this.version)) {
PS.log("&aThanks for updating from " + StringMan.join(PS.this.lastVersion, ".") + " to " + StringMan
.join(PS.this.version, ".") + "!");
DBFunc.updateTables(PS.this.lastVersion);
}
updater.update(getPlatform(), getVersion());
}
});
TaskManager.IMP.taskRepeatAsync(new Runnable() {
@Override
public void run() {
updater.update(getPlatform(), getVersion());
}
}, 36000);
}
// World generators:
@ -280,11 +279,9 @@ public class PS {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (!WorldUtil.IMP.isWorld(world)) {
debug("&c`" + world + "` was not properly loaded - PlotSquared will now try to load it properly: ");
debug(
"&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and "
+ "multiverse worlds.yml");
if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) {
debug("&c`" + world + "` was not properly loaded - " + IMP.getPluginName() + " will now try to load it properly: ");
debug("&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and multiverse worlds.yml");
debug("&8 - &7Your world management plugin may be faulty (or non existent)");
PS.this.IMP.setGenerator(world);
}
@ -305,9 +302,7 @@ public class PS {
} catch (Throwable e) {
e.printStackTrace();
}
if (!C.ENABLED.s().isEmpty()) {
PS.log(C.ENABLED);
}
PS.log(C.ENABLED.f(IMP.getPluginName()));
}
/**
@ -319,6 +314,13 @@ public class PS {
return PS.instance;
}
public static IPlotMain imp() {
if (instance != null) {
return instance.IMP;
}
return null;
}
/**
* Log a message to the IPlotMain logger.
*
@ -326,6 +328,9 @@ public class PS {
* @see IPlotMain#log(String)
*/
public static void log(Object message) {
if (message == null || message.toString().isEmpty()) {
return;
}
PS.get().getLogger().log(StringMan.getString(message));
}
@ -350,6 +355,18 @@ public class PS {
return logger;
}
/**
* The plugin updater
* @return
*/
public Updater getUpdater() {
return updater;
}
public PlotAreaManager getPlotAreaManager() {
return manager;
}
/**
* Set the Logger.
* @see DelegateLogger
@ -400,7 +417,7 @@ public class PS {
private void startPlotMeConversion() {
if (Settings.Enabled_Components.PLOTME_CONVERTER || Settings.PlotMe.CACHE_UUDS) {
TaskManager.runTaskLater(new Runnable() {
TaskManager.IMP.taskAsync(new Runnable() {
@Override
public void run() {
if (PS.this.IMP.initPlotMeConverter()) {
@ -408,11 +425,12 @@ public class PS {
PS.log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PlotMe!");
PS.log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
PS.log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
PS.log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the "
PS.log("&c - After the conversion is finished, please set 'plotme-converter' to false in the "
+ "'settings.yml'");
}
Settings.Enabled_Components.PLOTME_CONVERTER = false;
}
}, 20);
});
}
}
@ -431,19 +449,11 @@ public class PS {
&& version[1] == version2[1] && version[2] >= version2[2];
}
/**
* Get the last PlotSquared version.
* @return last version in config or null
*/
public int[] getLastVersion() {
return this.lastVersion;
}
/**
* Get the current PlotSquared version.
* @return current version in config or null
*/
public int[] getVersion() {
public PlotVersion getVersion() {
return this.version;
}
@ -454,204 +464,7 @@ public class PS {
* @return the server implementation
*/
public String getPlatform() {
return this.platform;
}
/**
* Get the relevant plot area for a specified location.
* <ul>
* <li>If there is only one plot area globally that will be returned.
* <li>If there is only one plot area in the world, it will return that.
* <li>If the plot area for a location cannot be unambiguously
* resolved, null will be returned.
* </ul>
* Note: An applicable plot area may not include the location i.e. clusters
* @param location the location
* @return
*/
public PlotArea getApplicablePlotArea(Location location) {
switch (this.plotAreas.length) {
case 0:
return null;
case 1:
return this.plotAreas[0];
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
String world = location.getWorld();
int hash = world.hashCode();
for (PlotArea area : this.plotAreas) {
if (hash == area.worldhash) {
if (area.contains(location.getX(), location.getZ()) && (!this.plotAreaHasCollision || world.equals(area.worldname))) {
return area;
}
}
}
return null;
default:
PlotArea[] areas = this.plotAreaMap.get(location.getWorld());
if (areas == null) {
return null;
}
int y;
int x;
switch (areas.length) {
case 1:
return areas[0];
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
x = location.getX();
y = location.getY();
for (PlotArea area : areas) {
if (area.contains(x, y)) {
return area;
}
}
return null;
default:
QuadMap<PlotArea> search = this.plotAreaGrid.get(location.getWorld());
return search.get(location.getX(), location.getZ());
}
}
}
public PlotArea getPlotArea(String world, String id) {
PlotArea[] areas = this.plotAreaMap.get(world);
if (areas == null) {
return null;
}
if (areas.length == 1) {
return areas[0];
} else if (id == null) {
return null;
}
for (PlotArea area : areas) {
if (StringMan.isEqual(id, area.id)) {
return area;
}
}
return null;
}
public PlotArea getPlotAreaAbs(String world, String id) {
PlotArea[] areas = this.plotAreaMap.get(world);
if (areas == null) {
return null;
}
for (PlotArea area : areas) {
if (StringMan.isEqual(id, area.id)) {
return area;
}
}
return null;
}
/**
* Get the {@code PlotArea} which contains a location.
* <ul>
* <li>If the plot area does not contain a location, null
* will be returned.
* </ul>
*
* @param location the location
* @return the {@link PlotArea} in the location, null if non existent
*/
public PlotArea getPlotAreaAbs(Location location) {
switch (this.plotAreas.length) {
case 0:
return null;
case 1:
PlotArea pa = this.plotAreas[0];
return pa.contains(location) ? pa : null;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
String world = location.getWorld();
int hash = world.hashCode();
for (PlotArea area : this.plotAreas) {
if (hash == area.worldhash) {
if (area.contains(location.getX(), location.getZ()) && (!this.plotAreaHasCollision || world.equals(area.worldname))) {
return area;
}
}
}
return null;
default:
PlotArea[] areas = this.plotAreaMap.get(location.getWorld());
if (areas == null) {
return null;
}
int x;
int y;
switch (areas.length) {
case 0:
PlotArea a = areas[0];
return a.contains(location.getX(), location.getZ()) ? a : null;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
x = location.getX();
y = location.getY();
for (PlotArea area : areas) {
if (area.contains(x, y)) {
return area;
}
}
return null;
default:
QuadMap<PlotArea> search = this.plotAreaGrid.get(location.getWorld());
return search.get(location.getX(), location.getZ());
}
}
}
public PlotArea getPlotAreaByString(String search) {
String[] split = search.split(";|,");
PlotArea[] areas = this.plotAreaMap.get(split[0]);
if (areas == null) {
for (PlotArea area : this.plotAreas) {
if (area.worldname.equalsIgnoreCase(split[0])) {
if (area.id == null || split.length == 2 && area.id.equalsIgnoreCase(split[1])) {
return area;
}
}
}
return null;
}
if (areas.length == 1) {
return areas[0];
} else if (split.length == 1) {
return null;
} else {
for (PlotArea area : areas) {
if (StringMan.isEqual(split[1], area.id)) {
return area;
}
}
return null;
}
}
public Set<PlotArea> getPlotAreas(String world, RegionWrapper region) {
QuadMap<PlotArea> areas = this.plotAreaGrid.get(world);
return areas != null ? areas.get(region) : new HashSet<PlotArea>();
return Settings.PLATFORM;
}
public PlotManager getPlotManager(Plot plot) {
@ -711,23 +524,7 @@ public class PS {
cluster.setArea(plotArea);
}
}
Set<PlotArea> localAreas = getPlotAreas(plotArea.worldname);
Set<PlotArea> globalAreas = getPlotAreas();
localAreas.add(plotArea);
globalAreas.add(plotArea);
this.plotAreas = globalAreas.toArray(new PlotArea[globalAreas.size()]);
this.plotAreaMap.put(plotArea.worldname, localAreas.toArray(new PlotArea[localAreas.size()]));
QuadMap<PlotArea> map = this.plotAreaGrid.get(plotArea.worldname);
if (map == null) {
map = new QuadMap<PlotArea>(Integer.MAX_VALUE, 0, 0) {
@Override
public RegionWrapper getRegion(PlotArea value) {
return value.getRegion();
}
};
this.plotAreaGrid.put(plotArea.worldname, map);
}
map.add(plotArea);
manager.addPlotArea(plotArea);
plotArea.setupBorder();
}
@ -737,22 +534,15 @@ public class PS {
* @param area the {@code PlotArea} to remove
*/
public void removePlotArea(PlotArea area) {
Set<PlotArea> areas = getPlotAreas(area.worldname);
areas.remove(area);
this.plotAreas = areas.toArray(new PlotArea[areas.size()]);
if (areas.isEmpty()) {
this.plotAreaMap.remove(area.worldname);
this.plotAreaGrid.remove(area.worldname);
} else {
this.plotAreaMap.put(area.worldname, areas.toArray(new PlotArea[areas.size()]));
this.plotAreaGrid.get(area.worldname).remove(area);
}
manager.removePlotArea(area);
setPlotsTmp(area);
}
public void removePlotAreas(String world) {
for (PlotArea area : getPlotAreas(world)) {
removePlotArea(area);
if (area.worldname.equals(world)) {
removePlotArea(area);
}
}
}
@ -1016,11 +806,11 @@ public class PS {
HashMap<PlotArea, Collection<Plot>> map = new HashMap<>();
int totalSize = getPlotCount();
if (plots.size() == totalSize) {
for (PlotArea area : this.plotAreas) {
for (PlotArea area : manager.getAllPlotAreas()) {
map.put(area, area.getPlots());
}
} else {
for (PlotArea area : this.plotAreas) {
for (PlotArea area : manager.getAllPlotAreas()) {
map.put(area, new ArrayList<Plot>(0));
}
Collection<Plot> lastList = null;
@ -1035,7 +825,7 @@ public class PS {
}
}
}
List<PlotArea> areas = Arrays.asList(this.plotAreas);
List<PlotArea> areas = Arrays.asList(manager.getAllPlotAreas());
Collections.sort(areas, new Comparator<PlotArea>() {
@Override
public int compare(PlotArea a, PlotArea b) {
@ -1224,7 +1014,7 @@ public class PS {
*/
@Deprecated
public boolean isPlotWorld(String world) {
return this.plotAreaMap.containsKey(world);
return hasPlotArea(world);
}
/**
@ -1234,29 +1024,7 @@ public class PS {
* @return if a plot world is registered
*/
public boolean hasPlotArea(String world) {
switch (this.plotAreas.length) {
case 0:
return false;
case 1:
PlotArea a = this.plotAreas[0];
return world.hashCode() == a.worldhash && (!this.plotAreaHasCollision || a.worldname.equals(world));
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
int hash = world.hashCode();
for (PlotArea area : this.plotAreas) {
if (area.worldhash == hash && (!this.plotAreaHasCollision || area.worldname.equals(world))) {
return true;
}
}
return false;
default:
return this.plotAreaMap.containsKey(world);
}
return manager.getPlotAreas(world, null).length != 0;
}
public Collection<Plot> getPlots(String world) {
@ -1386,9 +1154,7 @@ public class PS {
if (world.equals("CheckingPlotSquaredGenerator")) {
return;
}
if (!this.plotAreaHasCollision && !this.plotAreaHashCheck.add(world.hashCode())) {
this.plotAreaHasCollision = true;
}
this.manager.addWorld(world);
Set<String> worlds;
if (this.worlds.contains("worlds")) {
worlds = this.worlds.getConfigurationSection("worlds").getKeys(false);
@ -1404,7 +1170,7 @@ public class PS {
type = 0;
}
if (type == 0) {
if (this.plotAreaMap.containsKey(world)) {
if (manager.getPlotAreas(world, null).length != 0) {
debug("World possibly already loaded: " + world);
return;
}
@ -1455,12 +1221,12 @@ public class PS {
}
ConfigurationSection areasSection = worldSection.getConfigurationSection("areas");
if (areasSection == null) {
if (this.plotAreaMap.containsKey(world)) {
if (manager.getPlotAreas(world, null).length != 0) {
debug("World possibly already loaded: " + world);
return;
}
PS.log(C.PREFIX + "&aDetected world load for '" + world + "'");
String gen_string = worldSection.getString("generator.plugin", "PlotSquared");
String gen_string = worldSection.getString("generator.plugin", IMP.getPluginName());
if (type == 2) {
Set<PlotCluster> clusters = this.clusters_tmp != null ? this.clusters_tmp.get(world) : new HashSet<PlotCluster>();
if (clusters == null) {
@ -1526,20 +1292,18 @@ public class PS {
}
for (String areaId : areasSection.getKeys(false)) {
PS.log(C.PREFIX + "&3 - " + areaId);
int i1 = areaId.indexOf('-');
int i2 = areaId.indexOf(';');
if (i1 == -1 || i2 == -1) {
String[] split = areaId.split("(?<=[^;-])-");
if (split.length != 3) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<pos1>-<pos2>`");
}
String name = areaId.substring(0, i1);
String rest = areaId.substring(i1 + 1);
int i3 = rest.indexOf('-', i2 - name.length() - 1);
PlotId pos1 = PlotId.fromString(rest.substring(0, i3));
PlotId pos2 = PlotId.fromString(rest.substring(i3 + 1));
String name = split[0];
PlotId pos1 = PlotId.fromString(split[1]);
PlotId pos2 = PlotId.fromString(split[2]);
if (pos1 == null || pos2 == null || name.isEmpty()) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<x1;z1>-<x2;z2>`");
}
if (getPlotAreaAbs(world, name) != null) {
PlotArea existing = getPlotArea(world, name);
if (existing != null && name.equals(existing.id)) {
continue;
}
ConfigurationSection section = areasSection.getConfigurationSection(areaId);
@ -1560,7 +1324,7 @@ public class PS {
clone.set(key, worldSection.get(key));
}
}
String gen_string = clone.getString("generator.plugin", "PlotSquared");
String gen_string = clone.getString("generator.plugin", IMP.getPluginName());
GeneratorWrapper<?> areaGen = this.IMP.getGenerator(world, gen_string);
if (areaGen == null) {
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
@ -1695,6 +1459,10 @@ public class PS {
return sb.toString();
}
public File getJarFile() {
return jarFile;
}
public boolean update(PlotPlayer sender, URL url) {
try {
String name = this.jarFile.getName();
@ -1708,7 +1476,7 @@ public class PS {
}
MainUtil.sendMessage(sender, "$2 - Output: " + newJar);
if (!newJar.delete()) {
MainUtil.sendMessage(sender, "Failed to update PlotSquared");
MainUtil.sendMessage(sender, "Failed to update " + IMP.getPluginName() + "");
MainUtil.sendMessage(sender, "Jar file failed to delete.");
MainUtil.sendMessage(sender, " - Please update manually");
}
@ -1717,7 +1485,7 @@ public class PS {
MainUtil.sendMessage(sender, "$1The update will take effect when the server is restarted next");
return true;
} catch (IOException e) {
MainUtil.sendMessage(sender, "Failed to update PlotSquared");
MainUtil.sendMessage(sender, "Failed to update " + IMP.getPluginName() + "");
MainUtil.sendMessage(sender, " - Please update manually");
PS.log("============ Stacktrace ============");
e.printStackTrace();
@ -1781,7 +1549,7 @@ public class PS {
private Map<String, Map<PlotId, Plot>> getPlotsRaw() {
HashMap<String, Map<PlotId, Plot>> map = new HashMap<>();
for (PlotArea area : this.plotAreas) {
for (PlotArea area : this.manager.getAllPlotAreas()) {
Map<PlotId, Plot> map2 = map.get(area.toString());
if (map2 == null) {
map.put(area.toString(), area.getPlotsRaw());
@ -1811,6 +1579,7 @@ public class PS {
DBFunc.close();
UUIDHandler.handleShutdown();
} catch (NullPointerException ignored) {
ignored.printStackTrace();
PS.log("&cCould not close database connection!");
}
}
@ -1837,6 +1606,16 @@ public class PS {
}
DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, false);
this.plots_tmp = DBFunc.getPlots();
if (manager instanceof SinglePlotAreaManager) {
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
addPlotArea(area);
ConfigurationSection section = worlds.getConfigurationSection("worlds.*");
if (section == null) {
section = worlds.createSection("worlds.*");
}
area.saveConfiguration(section);
area.loadDefaultConfiguration(section);
}
this.clusters_tmp = DBFunc.getClusters();
} catch (ClassNotFoundException | SQLException e) {
PS.log(C.PREFIX + "&cFailed to open DATABASE connection. The plugin will disable itself.");
@ -1848,7 +1627,7 @@ public class PS {
PS.log("&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace();
PS.log("&d==== End of stacktrace ====");
PS.log("&6Please go to the PlotSquared 'storage.yml' and configure the database correctly.");
PS.log("&6Please go to the " + IMP.getPluginName() + " 'storage.yml' and configure the database correctly.");
this.IMP.disable();
}
}
@ -1861,25 +1640,36 @@ public class PS {
String lastVersionString = this.config.getString("version");
if (lastVersionString != null) {
String[] split = lastVersionString.split("\\.");
this.lastVersion = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
}
if (lastVersion != null && checkVersion(new int[]{3, 4, 0}, lastVersion)) {
Settings.convertLegacy(configFile);
if (config.contains("worlds")) {
ConfigurationSection worldSection = config.getConfigurationSection("worlds");
worlds.set("worlds", worldSection);
try {
worlds.save(worldsFile);
} catch (IOException e) {
PS.debug("Failed to save PlotSquared worlds.yml");
e.printStackTrace();
int[] lastVersion = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
if (checkVersion(new int[]{3, 4, 0}, lastVersion)) {
Settings.convertLegacy(configFile);
if (config.contains("worlds")) {
ConfigurationSection worldSection = config.getConfigurationSection("worlds");
worlds.set("worlds", worldSection);
try {
worlds.save(worldsFile);
} catch (IOException e) {
PS.debug("Failed to save " + IMP.getPluginName() + " worlds.yml");
e.printStackTrace();
}
}
Settings.save(configFile);
}
} else {
Settings.load(configFile);
}
Settings.VERSION = StringMan.join(this.version, ".");
Settings.PLATFORM = platform;
Settings.load(configFile);
try {
InputStream stream = getClass().getResourceAsStream("/plugin.properties");
java.util.Scanner scanner = new java.util.Scanner(stream).useDelimiter("\\A");
String versionString = scanner.next().trim();
scanner.close();
this.version = new PlotVersion(versionString);
Settings.DATE = new Date(100 + version.year, version.month, version.day).toGMTString();
Settings.BUILD = "https://ci.athion.net/job/PlotSquared/" + version.build;
Settings.COMMIT = "https://github.com/IntellectualSites/PlotSquared/commit/" + Integer.toHexString(version.hash);
System.out.println("Version is " + this.version);
} catch (Throwable ignore) {
ignore.printStackTrace();
}
Settings.save(configFile);
config = YamlConfiguration.loadConfiguration(configFile);
}
@ -1983,7 +1773,9 @@ public class PS {
* Setup the style.yml file
*/
private void setupStyle() {
this.style.set("version", StringMan.join(this.version, "."));
if (this.version != null) {
this.style.set("version", this.version.toString());
}
Map<String, Object> o = new HashMap<>(4);
o.put("color.1", "6");
o.put("color.2", "7");
@ -2000,18 +1792,18 @@ public class PS {
* Get the Java version.
* @return the java version
*/
private double getJavaVersion() {
public double getJavaVersion() {
return Double.parseDouble(System.getProperty("java.specification.version"));
}
public void foreachPlotArea(RunnableVal<PlotArea> runnable) {
for (PlotArea area : this.plotAreas) {
for (PlotArea area : this.manager.getAllPlotAreas()) {
runnable.run(area);
}
}
public void foreachPlotArea(String world, RunnableVal<PlotArea> runnable) {
PlotArea[] array = this.plotAreaMap.get(world);
PlotArea[] array = this.manager.getPlotAreas(world, null);
if (array == null) {
return;
}
@ -2021,7 +1813,7 @@ public class PS {
}
public void foreachPlot(RunnableVal<Plot> runnable) {
for (PlotArea area : this.plotAreas) {
for (PlotArea area : this.manager.getAllPlotAreas()) {
for (Plot plot : area.getPlots()) {
runnable.run(plot);
}
@ -2029,7 +1821,7 @@ public class PS {
}
public void foreachPlotRaw(RunnableVal<Plot> runnable) {
for (PlotArea area : this.plotAreas) {
for (PlotArea area : this.manager.getAllPlotAreas()) {
for (Plot plot : area.getPlots()) {
runnable.run(plot);
}
@ -2044,30 +1836,31 @@ public class PS {
}
public void foreachBasePlot(RunnableVal<Plot> run) {
for (PlotArea area : this.plotAreas) {
for (PlotArea area : this.manager.getAllPlotAreas()) {
area.foreachBasePlot(run);
}
}
public PlotArea getFirstPlotArea() {
return this.plotAreas.length > 0 ? this.plotAreas[0] : null;
PlotArea[] areas = manager.getAllPlotAreas();
return areas.length > 0 ? areas[0] : null;
}
public int getPlotAreaCount() {
return this.plotAreas.length;
return this.manager.getAllPlotAreas().length;
}
public int getPlotCount() {
int count = 0;
for (PlotArea area : this.plotAreas) {
for (PlotArea area : this.manager.getAllPlotAreas()) {
count += area.getPlotCount();
}
return count;
}
public Set<PlotArea> getPlotAreas() {
HashSet<PlotArea> set = new HashSet<>(this.plotAreas.length);
Collections.addAll(set, this.plotAreas);
HashSet<PlotArea> set = new HashSet<>();
Collections.addAll(set, manager.getAllPlotAreas());
return set;
}
@ -2077,15 +1870,17 @@ public class PS {
*/
@Deprecated
public Set<String> getPlotWorldStrings() {
HashSet<String> set = new HashSet<>(this.plotAreaMap.size());
for (String entry : this.plotAreaMap.keySet()) {
set.add(entry);
HashSet<String> set = new HashSet<>(manager.getAllPlotAreas().length);
for (String world : manager.getAllWorlds()) {
if (manager.getPlotAreas(world, null).length != 0) {
set.add(world);
}
}
return set;
}
public boolean isAugmented(String world) {
PlotArea[] areas = this.plotAreaMap.get(world);
PlotArea[] areas = manager.getPlotAreas(world, null);
if (areas == null) {
return false;
}
@ -2101,11 +1896,75 @@ public class PS {
* @return Collection of PlotArea objects
*/
public Set<PlotArea> getPlotAreas(String world) {
PlotArea[] areas = this.plotAreaMap.get(world);
Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, manager.getPlotAreas(world, null));
return set;
}
/**
* Get the relevant plot area for a specified location.
* <ul>
* <li>If there is only one plot area globally that will be returned.
* <li>If there is only one plot area in the world, it will return that.
* <li>If the plot area for a location cannot be unambiguously
* resolved, null will be returned.
* </ul>
* Note: An applicable plot area may not include the location i.e. clusters
* @param location the location
* @return
*/
public PlotArea getApplicablePlotArea(Location location) {
return manager.getApplicablePlotArea(location);
}
public PlotArea getPlotArea(String world, String id) {
return manager.getPlotArea(world, id);
}
/**
* Get the {@code PlotArea} which contains a location.
* <ul>
* <li>If the plot area does not contain a location, null
* will be returned.
* </ul>
*
* @param location the location
* @return the {@link PlotArea} in the location, null if non existent
*/
public PlotArea getPlotAreaAbs(Location location) {
return manager.getPlotArea(location);
}
public PlotArea getPlotAreaByString(String search) {
String[] split = search.split(";|,");
PlotArea[] areas = manager.getPlotAreas(split[0], null);
if (areas == null) {
return new HashSet<>(0);
for (PlotArea area : manager.getAllPlotAreas()) {
if (area.worldname.equalsIgnoreCase(split[0])) {
if (area.id == null || split.length == 2 && area.id.equalsIgnoreCase(split[1])) {
return area;
}
}
}
return null;
}
HashSet<PlotArea> set = new HashSet<>(areas.length);
if (areas.length == 1) {
return areas[0];
} else if (split.length == 1) {
return null;
} else {
for (PlotArea area : areas) {
if (StringMan.isEqual(split[1], area.id)) {
return area;
}
}
return null;
}
}
public Set<PlotArea> getPlotAreas(String world, RegionWrapper region) {
PlotArea[] areas = manager.getPlotAreas(world, region);
Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, areas);
return set;
}

View File

@ -0,0 +1,28 @@
package com.intellectualcrafters.plot;
public class PlotVersion {
public final int year, month, day, hash, build;
public PlotVersion(String version) {
String[] split = version.substring(version.indexOf('=') + 1).split("-");
if (split[0].equals("unknown")) {
this.year = month = day = hash = build = 0;
return;
}
String[] date = split[0].split("\\.");
this.year = Integer.parseInt(date[0]);
this.month = Integer.parseInt(date[1]);
this.day = Integer.parseInt(date[2]);
this.hash = Integer.parseInt(split[1], 16);
this.build = Integer.parseInt(split[2]);
}
@Override
public String toString() {
return "PlotSquared-" + year + "." + month + "." + day + "-" + Integer.toHexString(hash) + "-" + build;
}
public boolean isNewer(PlotVersion other) {
return other.build < this.build;
}
}

View File

@ -1,54 +1,73 @@
package com.intellectualcrafters.plot;
import static com.intellectualcrafters.plot.PS.log;
import com.intellectualcrafters.json.JSONArray;
import com.intellectualcrafters.json.JSONObject;
import com.intellectualcrafters.plot.util.HttpUtil;
import com.intellectualcrafters.plot.util.StringMan;
import java.net.MalformedURLException;
import com.intellectualcrafters.plot.util.MainUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Scanner;
public class Updater {
public static URL getUpdate() {
String str = HttpUtil.readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
JSONObject release = new JSONObject(str);
JSONArray assets = (JSONArray) release.get("assets");
String downloadURL = String.format("PlotSquared-%s.jar", PS.get().getPlatform());
for (int i = 0; i < assets.length(); i++) {
JSONObject asset = assets.getJSONObject(i);
String name = asset.getString("name");
if (downloadURL.equals(name)) {
try {
String[] split = release.getString("name").split("\\.");
int[] version;
if (split.length == 3) {
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
} else {
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), 0};
}
// If current version >= update
if (PS.get().checkVersion(PS.get().getVersion(), version)) {
if (!PS.get().IMP.getPluginVersionString().contains("-SNAPSHOT") || !Arrays.equals(PS.get().getVersion(), version)) {
PS.debug("&7PlotSquared is already up to date!");
return null;
}
}
log("&6PlotSquared " + StringMan.join(split, ".") + " is available:");
log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + downloadURL);
return new URL(asset.getString("browser_download_url"));
} catch (MalformedURLException e) {
e.printStackTrace();
log("&dCould not check for updates (1)");
log("&7 - Manually check for updates: https://github.com/IntellectualSites/PlotSquared/releases");
}
PlotVersion newVersion;
private String changes;
public String getChanges() {
if (changes == null) {
try (Scanner scanner = new Scanner(new URL("http://empcraft.com/plots/cl?" + Integer.toHexString(PS.get().getVersion().hash)).openStream(), "UTF-8")) {
changes = scanner.useDelimiter("\\A").next();
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
log("You are running the latest version of PlotSquared");
return null;
return changes;
}
}
public boolean isOutdated() {
return newVersion != null;
}
public void update(String platform, PlotVersion currentVersion) {
if (currentVersion == null || platform == null) {
return;
}
try {
String downloadUrl = "https://ci.athion.net/job/PlotSquared/lastSuccessfulBuild/artifact/target/PlotSquared-%platform%-%version%.jar";
String versionUrl = "http://empcraft.com/plots/version.php?%platform%";
URL url = new URL(versionUrl.replace("%platform%", platform));
try (Scanner reader = new Scanner(url.openStream())) {
String versionString = reader.next();
PlotVersion version = new PlotVersion(versionString);
if (version.isNewer(newVersion != null ? newVersion : currentVersion)) {
newVersion = version;
URL download = new URL(downloadUrl.replaceAll("%platform%", platform).replaceAll("%version%", versionString));
try (ReadableByteChannel rbc = Channels.newChannel(download.openStream())) {
File jarFile = PS.get().getJarFile();
File finalFile = new File(jarFile.getParent(), "update" + File.separator + jarFile.getName());
File outFile = new File(jarFile.getParent(), "update" + File.separator + jarFile.getName().replace(".jar", ".part"));
boolean exists = outFile.exists();
if (exists) {
outFile.delete();
} else {
File outFileParent = outFile.getParentFile();
if (!outFileParent.exists()) {
outFileParent.mkdirs();
}
}
try (FileOutputStream fos = new FileOutputStream(outFile)) {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
outFile.renameTo(finalFile);
PS.debug("Updated PlotSquared to " + versionString);
MainUtil.sendAdmin("&7Restart to update PlotSquared with these changes: &c/plot changelog &7or&c " + "http://empcraft.com/plot/cl?" + Integer.toHexString(currentVersion.hash));
}
}
}
} catch (Throwable ignore) {
}
}
}

View File

@ -18,7 +18,6 @@ import java.util.UUID;
@CommandDeclaration(
command = "add",
aliases = {"a"},
description = "Allow a user to build while you are online",
usage = "/plot add <player>",
category = CommandCategory.SETTINGS,
@ -34,7 +33,7 @@ public class Add extends Command {
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
checkTrue(plot.hasOwner(), C.PLOT_UNOWNED);
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.trust"), C.NO_PLOT_PERMS);
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.NO_PLOT_PERMS);
checkTrue(args.length == 1, C.COMMAND_SYNTAX, getUsage());
final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
checkTrue(!uuids.isEmpty(), C.INVALID_PLAYER, args[0]);
@ -42,7 +41,7 @@ public class Add extends Command {
int size = plot.getTrusted().size() + plot.getMembers().size();
while (iter.hasNext()) {
UUID uuid = iter.next();
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(player, "plots.trust.everyone") || Permissions.hasPermission(player, "plots.admin.command.trust"))) {
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(player, C.PERMISSION_TRUST_EVERYONE) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, C.INVALID_PLAYER, MainUtil.getName(uuid));
iter.remove();
continue;
@ -60,14 +59,16 @@ public class Add extends Command {
size += plot.getTrusted().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions.hasPermission(player, "plots.admin.command.trust"), C.PLOT_MAX_MEMBERS);
checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.PLOT_MAX_MEMBERS);
confirm.run(this, new Runnable() {
@Override // Success
public void run() {
for (UUID uuid : uuids) {
if (!plot.removeTrusted(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
if (uuid != DBFunc.everyone) {
if (!plot.removeTrusted(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
}
}
plot.addMember(uuid);

View File

@ -15,7 +15,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
permission = "plots.set.alias",
description = "Set the plot name",
usage = "/plot alias <alias>",
aliases = {"alias", "sa", "name", "rename", "setname", "seta"},
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE)
public class Alias extends SetCommand {

View File

@ -5,7 +5,6 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.generator.AugmentedUtils;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
@ -26,7 +25,6 @@ import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
@ -52,8 +50,8 @@ public class Area extends SubCommand {
case "c":
case "setup":
case "create":
if (!Permissions.hasPermission(player, "plots.area.create")) {
C.NO_PERMISSION.send(player, "plots.area.create");
if (!Permissions.hasPermission(player, C.PERMISSION_AREA_CREATE)) {
C.NO_PERMISSION.send(player, C.PERMISSION_AREA_CREATE);
return false;
}
switch (args.length) {
@ -109,8 +107,8 @@ public class Area extends SubCommand {
object.type = area.TYPE;
object.min = new PlotId(1, 1);
object.max = new PlotId(numX, numZ);
object.plotManager = "PlotSquared";
object.setupGenerator = "PlotSquared";
object.plotManager = PS.imp().getPluginName();
object.setupGenerator = PS.imp().getPluginName();
object.step = area.getSettingNodes();
final String path = "worlds." + area.worldname + ".areas." + area.id + '-' + object.min + '-' + object.max;
Runnable run = new Runnable() {
@ -157,7 +155,7 @@ public class Area extends SubCommand {
id = null;
}
object.world = split[0];
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, new HybridGen(), null, null);
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, PS.get().IMP.getDefaultGenerator(), null, null);
PlotArea other = PS.get().getPlotArea(pa.worldname, id);
if (other != null && Objects.equals(pa.id, other.id)) {
C.SETUP_WORLD_TAKEN.send(player, pa.toString());
@ -237,8 +235,8 @@ public class Area extends SubCommand {
ConfigurationSection section = PS.get().worlds.getConfigurationSection(path);
pa.saveConfiguration(section);
pa.loadConfiguration(section);
object.plotManager = "PlotSquared";
object.setupGenerator = "PlotSquared";
object.plotManager = PS.imp().getPluginName();
object.setupGenerator = PS.imp().getPluginName();
String world = SetupUtils.manager.setupWorld(object);
if (WorldUtil.IMP.isWorld(world)) {
C.SETUP_FINISHED.send(player);
@ -281,8 +279,8 @@ public class Area extends SubCommand {
return true;
case "i":
case "info": {
if (!Permissions.hasPermission(player, "plots.area.info")) {
C.NO_PERMISSION.send(player, "plots.area.info");
if (!Permissions.hasPermission(player, C.PERMISSION_AREA_INFO)) {
C.NO_PERMISSION.send(player, C.PERMISSION_AREA_INFO);
return false;
}
PlotArea area;
@ -336,8 +334,8 @@ public class Area extends SubCommand {
}
case "l":
case "list":
if (!Permissions.hasPermission(player, "plots.area.list")) {
C.NO_PERMISSION.send(player, "plots.area.list");
if (!Permissions.hasPermission(player, C.PERMISSION_AREA_LIST)) {
C.NO_PERMISSION.send(player, C.PERMISSION_AREA_LIST);
return false;
}
int page;
@ -398,8 +396,8 @@ public class Area extends SubCommand {
case "clear":
case "reset":
case "regenerate": {
if (!Permissions.hasPermission(player, "plots.area.regen")) {
C.NO_PERMISSION.send(player, "plots.area.regen");
if (!Permissions.hasPermission(player, C.PERMISSION_AREA_REGEN)) {
C.NO_PERMISSION.send(player, C.PERMISSION_AREA_REGEN);
return false;
}
final PlotArea area = player.getApplicablePlotArea();
@ -424,8 +422,8 @@ public class Area extends SubCommand {
case "teleport":
case "visit":
case "tp":
if (!Permissions.hasPermission(player, "plots.area.tp")) {
C.NO_PERMISSION.send(player, "plots.area.tp");
if (!Permissions.hasPermission(player, C.PERMISSION_AREA_TP)) {
C.NO_PERMISSION.send(player, C.PERMISSION_AREA_TP);
return false;
}
if (args.length != 2) {
@ -452,7 +450,7 @@ public class Area extends SubCommand {
case "remove":
MainUtil.sendMessage(player, "$1World creation settings may be stored in multiple locations:"
+ "\n$3 - $2Bukkit bukkit.yml"
+ "\n$3 - $2PlotSquared settings.yml"
+ "\n$3 - $2" + PS.imp().getPluginName() + " settings.yml"
+ "\n$3 - $2Multiverse worlds.yml (or any world management plugin)"
+ "\n$1Stop the server and delete it from these locations.");
return true;

View File

@ -1,17 +1,22 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Expression;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.Set;
@CommandDeclaration(command = "auto",
permission = "plots.auto",
@ -22,47 +27,36 @@ import com.plotsquared.general.commands.CommandDeclaration;
usage = "/plot auto [length,width]")
public class Auto extends SubCommand {
@Deprecated
public static PlotId getNextPlotId(PlotId id, int step) {
int absX = Math.abs(id.x);
int absY = Math.abs(id.y);
if (absX > absY) {
if (id.x > 0) {
return new PlotId(id.x, id.y + 1);
} else {
return new PlotId(id.x, id.y - 1);
}
} else if (absY > absX) {
if (id.y > 0) {
return new PlotId(id.x - 1, id.y);
} else {
return new PlotId(id.x + 1, id.y);
}
} else {
if (id.x == id.y && id.x > 0) {
return new PlotId(id.x, id.y + step);
}
if (id.x == absX) {
return new PlotId(id.x, id.y + 1);
}
if (id.y == absY) {
return new PlotId(id.x, id.y - 1);
}
return new PlotId(id.x + 1, id.y);
}
return id.getNextId(step);
}
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
public boolean onCommand(final PlotPlayer player, String[] args) {
PlotArea plotarea = player.getApplicablePlotArea();
if (plotarea == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT_WORLD);
return false;
if (EconHandler.manager != null) {
for (PlotArea area : PS.get().getPlotAreaManager().getAllPlotAreas()) {
if (EconHandler.manager.hasPermission(area.worldname, player.getName(), "plots.auto")) {
if (plotarea != null) {
plotarea = null;
break;
}
plotarea = area;
}
}
}
if (plotarea == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT_WORLD);
return false;
}
}
int size_x = 1;
int size_z = 1;
String schematic = null;
if (args.length > 0) {
if (Permissions.hasPermission(player, "plots.auto.mega")) {
if (Permissions.hasPermission(player, C.PERMISSION_AUTO_MEGA)) {
try {
String[] split = args[0].split(",|;");
size_x = Integer.parseInt(split[0]);
@ -95,7 +89,7 @@ public class Auto extends SubCommand {
int diff = currentPlots - player.getAllowedPlots();
if (diff + size_x * size_z > 0) {
if (diff < 0) {
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
return false;
} else if (player.hasPersistentMeta("grantedPlots")) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots"));
@ -116,6 +110,16 @@ public class Auto extends SubCommand {
return false;
}
}
if (schematic != null && !schematic.isEmpty()) {
if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic)) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic));
return true;
}
}
if (EconHandler.manager != null && plotarea.USE_ECONOMY) {
Expression<Double> costExp = plotarea.PRICES.get("claim");
double cost = costExp.evaluate((double) currentPlots);
@ -129,70 +133,116 @@ public class Auto extends SubCommand {
sendMessage(player, C.REMOVED_BALANCE, cost + "");
}
}
if (schematic != null && !schematic.isEmpty()) {
if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!Permissions.hasPermission(player, "plots.claim." + schematic) && !Permissions.hasPermission(player, "plots.admin.command.schematic")) {
MainUtil.sendMessage(player, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
}
// TODO handle type 2 the same as normal worlds!
if (plotarea.TYPE == 2) {
PlotId bot = plotarea.getMin();
PlotId top = plotarea.getMax();
PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
PlotId id = new PlotId(0, 0);
int width = Math.max(top.x - bot.x + 1, top.y - bot.y + 1);
int max = width * width;
//
for (int i = 0; i <= max; i++) {
PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
Plot current = plotarea.getPlotAbs(currentId);
if (current.canClaim(player)) {
current.claim(player, true, null);
return true;
}
id = getNextPlotId(id, 1);
if (size_x == 1 && size_z == 1) {
autoClaimSafe(player, plotarea, null, schematic);
return true;
} else {
if (plotarea.TYPE == 2) {
// TODO
MainUtil.sendMessage(player, C.NO_FREE_PLOTS);
return false;
}
// no free plots
MainUtil.sendMessage(player, C.NO_FREE_PLOTS);
return false;
}
plotarea.setMeta("lastPlot", new PlotId(0, 0));
while (true) {
PlotId start = getNextPlotId(getLastPlotId(plotarea), 1);
PlotId end = new PlotId(start.x + size_x - 1, start.y + size_z - 1);
plotarea.setMeta("lastPlot", start);
if (plotarea.canClaim(player, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
boolean teleport = i == end.x && j == end.y;
plot.claim(player, teleport, null);
while (true) {
PlotId start = plotarea.getMeta("lastPlot", new PlotId(0, 0)).getNextId(1);
PlotId end = new PlotId(start.x + size_x - 1, start.y + size_z - 1);
if (plotarea.canClaim(player, start, end)) {
plotarea.setMeta("lastPlot", start);
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
boolean teleport = i == end.x && j == end.y;
plot.claim(player, teleport, null);
}
}
}
if (size_x != 1 || size_z != 1) {
if (!plotarea.mergePlots(MainUtil.getPlotSelectionIds(start, end), true, true)) {
return false;
}
break;
}
break;
}
return true;
}
plotarea.setMeta("lastPlot", new PlotId(0, 0));
return true;
}
public PlotId getLastPlotId(PlotArea area) {
PlotId value = (PlotId) area.getMeta("lastPlot");
if (value == null) {
value = new PlotId(0, 0);
area.setMeta("lastPlot", value);
return value;
/**
* Get the next plot id (spiral out from 0,0)
* @param start
* @return
*/
@Deprecated
public static PlotId getNextPlot(PlotId start) {
int plots;
PlotId center;
center = new PlotId(0, 0);
plots = Integer.MAX_VALUE;
PlotId currentId;
for (int i = 0; i < plots; i++) {
if (start == null) {
start = new PlotId(0, 0);
} else {
start = start.getNextId(1);
}
currentId = new PlotId(center.x + start.x, center.y + start.y);
return currentId;
}
return value;
return null;
}
/**
* Teleport the player home, or claim a new plot
* @param player
* @param area
* @param start
* @param schem
*/
public static void homeOrAuto(final PlotPlayer player, final PlotArea area, PlotId start, final String schem) {
Set<Plot> plots = player.getPlots();
if (!plots.isEmpty()) {
plots.iterator().next().teleportPlayer(player);
} else {
autoClaimSafe(player, area, start, schem);
}
}
/**
* Claim a new plot for a player
* @param player
* @param area
* @param start
* @param schem
*/
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start, final String schem) {
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
@Override
public void run(final Plot plot) {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object ignore) {
if (plot == null) {
MainUtil.sendMessage(player, C.NO_FREE_PLOTS);
} else {
plot.claim(player, true, schem, false);
}
}
});
}
});
}
private static void autoClaimFromDatabase(final PlotPlayer player, final PlotArea area, PlotId start, final RunnableVal<Plot> whenDone) {
final Plot plot = area.getNextFreePlot(player, start);
if (plot == null) {
whenDone.run(null);
return;
}
whenDone.value = plot;
plot.owner = player.getUUID();
DBFunc.createPlotSafe(plot, whenDone, new Runnable() {
@Override
public void run() {
autoClaimFromDatabase(player, area, plot.getId(), whenDone);
}
});
}
}

View File

@ -29,7 +29,7 @@ public class BO3 extends SubCommand {
if (plot == null || !plot.hasOwner()) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.bo3")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_BO3)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}

View File

@ -17,7 +17,6 @@ import java.util.Set;
@CommandDeclaration(
command = "buy",
aliases = {"b"},
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",

View File

@ -0,0 +1,40 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.Updater;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
@CommandDeclaration(
command = "changelog",
permission = "plots.admin.command.changelog",
description = "View the changelog",
usage = "/plot changelog",
requiredType = RequiredType.NONE,
aliases = {"cl"},
category = CommandCategory.ADMINISTRATION)
public class Changelog extends SubCommand {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
try {
Updater updater = PS.get().getUpdater();
String changes = updater != null ? updater.getChanges() : null;
if (changes == null) {
try (Scanner scanner = new Scanner(new URL("http://empcraft.com/plots/cl?" + Integer.toHexString(PS.get().getVersion().hash)).openStream(), "UTF-8")) {
changes = scanner.useDelimiter("\\A").next();
}
}
changes = changes.replaceAll("#([0-9]+)", "github.com/IntellectualSites/PlotSquared/pulls/$1");
MainUtil.sendMessage(player, changes);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
}

View File

@ -2,14 +2,17 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Expression;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "claim",
@ -21,13 +24,13 @@ import com.plotsquared.general.commands.CommandDeclaration;
public class Claim extends SubCommand {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
public boolean onCommand(final PlotPlayer player, String[] args) {
String schematic = "";
if (args.length >= 1) {
schematic = args[0];
}
Location loc = player.getLocation();
Plot plot = loc.getPlotAbs();
final Plot plot = loc.getPlotAbs();
if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT);
}
@ -47,9 +50,23 @@ public class Claim extends SubCommand {
if (!plot.canClaim(player)) {
return sendMessage(player, C.PLOT_IS_CLAIMED);
}
PlotArea world = plot.getArea();
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
Expression<Double> costExr = world.PRICES.get("claim");
final PlotArea area = plot.getArea();
if (!schematic.isEmpty()) {
if (area.SCHEMATIC_CLAIM_SPECIFY) {
if (!area.SCHEMATICS.contains(schematic.toLowerCase())) {
return sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
}
if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic)) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
return sendMessage(player, C.NO_SCHEMATIC_PERMISSION, schematic);
}
}
}
int border = area.getBorder();
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border) {
return !sendMessage(player, C.BORDER);
}
if ((EconHandler.manager != null) && area.USE_ECONOMY) {
Expression<Double> costExr = area.PRICES.get("claim");
double cost = costExr.evaluate((double) currentPlots);
if (cost > 0d) {
if (EconHandler.manager.getMoney(player) < cost) {
@ -67,16 +84,29 @@ public class Claim extends SubCommand {
}
sendMessage(player, C.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1));
}
if (!schematic.isEmpty()) {
if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
return sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
if (plot.canClaim(player)) {
plot.owner = player.getUUID();
final String finalSchematic = schematic;
DBFunc.createPlotSafe(plot, new Runnable() {
@Override
public void run() {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
plot.claim(player, true, finalSchematic, false);
}
});
}
if (!Permissions.hasPermission(player, "plots.claim." + schematic) && !Permissions.hasPermission(player, "plots.admin.command.schematic")) {
return sendMessage(player, C.NO_SCHEMATIC_PERMISSION, schematic);
}, new Runnable() {
@Override
public void run() {
sendMessage(player, C.PLOT_NOT_CLAIMED);
}
}
});
return true;
} else {
sendMessage(player, C.PLOT_NOT_CLAIMED);
}
return plot.claim(player, false, schematic) || sendMessage(player, C.PLOT_NOT_CLAIMED);
return false;
}
}

View File

@ -34,9 +34,9 @@ public class Clear extends Command {
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
checkTrue(args.length == 0, C.COMMAND_SYNTAX, getUsage());
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.clear"), C.NO_PLOT_PERMS);
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_CLEAR), C.NO_PLOT_PERMS);
checkTrue(plot.getRunning() == 0, C.WAIT_FOR_TIMER);
checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions.hasPermission(player, "plots.continue"), C.DONE_ALREADY_DONE);
checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions.hasPermission(player, C.PERMISSION_CONTINUE), C.DONE_ALREADY_DONE);
confirm.run(this, new Runnable() {
@Override
public void run() {

View File

@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@ -42,8 +41,8 @@ public class Cluster extends SubCommand {
switch (sub) {
case "l":
case "list": {
if (!Permissions.hasPermission(player, "plots.cluster.list")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.list");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_LIST)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_LIST);
return false;
}
if (args.length != 1) {
@ -74,8 +73,8 @@ public class Cluster extends SubCommand {
}
case "c":
case "create": {
if (!Permissions.hasPermission(player, "plots.cluster.create")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.create");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_CREATE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_CREATE);
return false;
}
PlotArea area = player.getApplicablePlotArea();
@ -87,6 +86,10 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
return false;
}
int currentClusters = Settings.Limit.GLOBAL ? player.getClusterCount() : player.getPlotCount(player.getLocation().getWorld());
if (currentClusters >= player.getAllowedPlots()) {
return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS);
}
// check pos1 / pos2
PlotId pos1 = PlotId.fromString(args[2]);
PlotId pos2 = PlotId.fromString(args[3]);
@ -112,13 +115,17 @@ public class Cluster extends SubCommand {
return false;
}
// Check if it occupies existing plots
if (!area.contains(pos1) || !area.contains(pos2)) {
C.CLUSTER_OUTSIDE.send(player, area);
return false;
}
Set<Plot> plots = area.getPlotSelectionOwned(pos1, pos2);
if (!plots.isEmpty()) {
if (!Permissions.hasPermission(player, "plots.cluster.create.other")) {
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_CREATE_OTHER)) {
UUID uuid = player.getUUID();
for (Plot plot : plots) {
if (!plot.isOwner(uuid)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.create.other");
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_CREATE_OTHER);
return false;
}
}
@ -132,9 +139,9 @@ public class Cluster extends SubCommand {
} else {
current = player.getPlayerClusterCount(player.getLocation().getWorld());
}
int allowed = Permissions.hasPermissionRange(player, "plots.cluster", Settings.Limit.MAX_PLOTS);
int allowed = Permissions.hasPermissionRange(player, C.PERMISSION_CLUSTER_SIZE, Settings.Limit.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_SIZE + "." + (current + cluster.getArea()));
return false;
}
// create cluster
@ -156,8 +163,8 @@ public class Cluster extends SubCommand {
case "disband":
case "del":
case "delete": {
if (!Permissions.hasPermission(player, "plots.cluster.delete")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.delete");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_DELETE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_DELETE);
return false;
}
if (args.length != 1 && args.length != 2) {
@ -184,8 +191,8 @@ public class Cluster extends SubCommand {
}
}
if (!cluster.owner.equals(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.cluster.delete.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.delete.other");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_DELETE_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_DELETE_OTHER);
return false;
}
}
@ -195,8 +202,8 @@ public class Cluster extends SubCommand {
}
case "res":
case "resize": {
if (!Permissions.hasPermission(player, "plots.cluster.resize")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.resize");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE);
return false;
}
if (args.length != 3) {
@ -226,8 +233,8 @@ public class Cluster extends SubCommand {
return false;
}
if (!cluster.hasHelperRights(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.cluster.resize.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.resize.other");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE_OTHER);
return false;
}
}
@ -243,15 +250,15 @@ public class Cluster extends SubCommand {
removed.removeAll(newPlots);
// Check expand / shrink
if (!removed.isEmpty()) {
if (!Permissions.hasPermission(player, "plots.cluster.resize.shrink")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.resize.shrink");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE_SHRINK)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE_SHRINK);
return false;
}
}
newPlots.removeAll(existing);
if (!newPlots.isEmpty()) {
if (!Permissions.hasPermission(player, "plots.cluster.resize.expand")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.resize.expand");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_RESIZE_EXPAND)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_RESIZE_EXPAND);
return false;
}
}
@ -263,9 +270,9 @@ public class Cluster extends SubCommand {
current = player.getPlayerClusterCount(player.getLocation().getWorld());
}
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
int allowed = Permissions.hasPermissionRange(player, "plots.cluster", Settings.Limit.MAX_PLOTS);
int allowed = Permissions.hasPermissionRange(player, C.PERMISSION_CLUSTER, Settings.Limit.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER.s() + "." + (current + cluster.getArea()));
return false;
}
// resize cluster
@ -276,8 +283,8 @@ public class Cluster extends SubCommand {
case "add":
case "inv":
case "invite": {
if (!Permissions.hasPermission(player, "plots.cluster.invite")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.invite");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_INVITE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_INVITE);
return false;
}
if (args.length != 2) {
@ -295,8 +302,8 @@ public class Cluster extends SubCommand {
return false;
}
if (!cluster.hasHelperRights(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.cluster.invite.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.invite.other");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_INVITE_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_INVITE_OTHER);
return false;
}
}
@ -321,8 +328,8 @@ public class Cluster extends SubCommand {
case "k":
case "remove":
case "kick": {
if (!Permissions.hasPermission(player, "plots.cluster.kick")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.kick");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_KICK)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_KICK);
return false;
}
if (args.length != 2) {
@ -339,8 +346,8 @@ public class Cluster extends SubCommand {
return false;
}
if (!cluster.hasHelperRights(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.cluster.kick.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.kick.other");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_KICK_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_KICK_OTHER);
return false;
}
}
@ -376,8 +383,8 @@ public class Cluster extends SubCommand {
}
case "quit":
case "leave": {
if (!Permissions.hasPermission(player, "plots.cluster.leave")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.leave");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_LEAVE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_LEAVE);
return false;
}
if (args.length != 1 && args.length != 2) {
@ -427,11 +434,12 @@ public class Cluster extends SubCommand {
}
return true;
}
case "members":
case "admin":
case "helper":
case "helpers": {
if (!Permissions.hasPermission(player, "plots.cluster.helpers")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.helpers");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_HELPERS)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_HELPERS);
return false;
}
if (args.length != 3) {
@ -468,8 +476,8 @@ public class Cluster extends SubCommand {
case "spawn":
case "home":
case "tp": {
if (!Permissions.hasPermission(player, "plots.cluster.tp")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.tp");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_TP)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_TP);
return false;
}
if (args.length != 2) {
@ -488,8 +496,8 @@ public class Cluster extends SubCommand {
}
UUID uuid = player.getUUID();
if (!cluster.isAdded(uuid)) {
if (!Permissions.hasPermission(player, "plots.cluster.tp.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.tp.other");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_TP_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_TP_OTHER);
return false;
}
}
@ -500,8 +508,8 @@ public class Cluster extends SubCommand {
case "info":
case "show":
case "information": {
if (!Permissions.hasPermission(player, "plots.cluster.info")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.info");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_INFO)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_INFO);
return false;
}
if (args.length != 1 && args.length != 2) {
@ -546,8 +554,8 @@ public class Cluster extends SubCommand {
case "sh":
case "setspawn":
case "sethome":
if (!Permissions.hasPermission(player, "plots.cluster.sethome")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.sethome");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_SETHOME)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_SETHOME);
return false;
}
if (args.length != 1 && args.length != 2) {
@ -564,8 +572,8 @@ public class Cluster extends SubCommand {
return false;
}
if (!cluster.hasHelperRights(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.cluster.sethome.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.sethome.other");
if (!Permissions.hasPermission(player, C.PERMISSION_CLUSTER_SETHOME_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_CLUSTER_SETHOME_OTHER);
return false;
}
}

View File

@ -1,30 +0,0 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
public class CommandPermission {
/**
* Permission Node.
*/
public final String permission;
/**
* Command Permission
* @param permission Command Permission
*/
public CommandPermission(String permission) {
this.permission = permission.toLowerCase();
}
/**
* Check the permissions of a player.
* @param player The player to check permissions for
*
* @return true of player has the required permission node
*/
public boolean hasPermission(PlotPlayer player) {
return Permissions.hasPermission(player, this.permission);
}
}

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.CmdInstance;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.CmdConfirm;
@ -22,8 +23,8 @@ public class Confirm extends SubCommand {
return false;
}
CmdConfirm.removePending(player);
if ((System.currentTimeMillis() - command.timestamp) > 20000) {
MainUtil.sendMessage(player, C.FAILED_CONFIRM);
if ((System.currentTimeMillis() - command.timestamp) > Settings.Confirmation.CONFIRMATION_TIMEOUT_SECONDS * 1000) {
MainUtil.sendMessage(player, C.EXPIRED_CONFIRM);
return false;
}
TaskManager.runTask(command.command);

View File

@ -23,7 +23,7 @@ public class Continue extends SubCommand {
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.continue")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_CONTINUE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}
@ -33,7 +33,7 @@ public class Continue extends SubCommand {
}
int size = plot.getConnectedPlots().size();
if (Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() < player.getPlotCount() + size)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.admin.command.continue");
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_ADMIN_COMMAND_CONTINUE);
return false;
}
if (plot.getRunning() > 0) {

View File

@ -9,10 +9,10 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
@ -28,7 +28,7 @@ import java.util.Map.Entry;
permission = "plots.database",
description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE,
usage = "/plots database [area] <sqlite|mysql|import>")
usage = "/plot database [area] <sqlite|mysql|import>")
public class Database extends SubCommand {
public static void insertPlots(final SQLManager manager, final List<Plot> plots, final PlotPlayer player) {
@ -81,7 +81,7 @@ public class Database extends SubCommand {
switch (args[0].toLowerCase()) {
case "import":
if (args.length < 2) {
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
MainUtil.sendMessage(player, "/plot database import <sqlite file> [prefix]");
return false;
}
File file = MainUtil.getFile(PS.get().IMP.getDirectory(), args[1].endsWith(".db") ? args[1] : args[1] + ".db");
@ -101,11 +101,29 @@ public class Database extends SubCommand {
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
Plot plot = entry2.getValue();
if (pa.getOwnedPlotAbs(plot.getId()) != null) {
if (pa instanceof SinglePlotArea) {
Plot newPlot = pa.getNextFreePlot(null, plot.getId());
if (newPlot != null) {
PlotId newId = newPlot.getId();
PlotId id = plot.getId();
File worldFile = new File(PS.imp().getWorldContainer(), id.toCommaSeparatedString());
if (worldFile.exists()) {
File newFile = new File(PS.imp().getWorldContainer(), newId.toCommaSeparatedString());
worldFile.renameTo(newFile);
}
id.x = newId.x;
id.y = newId.y;
id.recalculateHash();
plot.setArea(pa);
plots.add(plot);
continue;
}
}
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
continue;
}
plot.create();
plots.add(entry2.getValue());
plot.setArea(pa);
plots.add(plot);
}
} else {
HashMap<PlotId, Plot> plotmap = PS.get().plots_tmp.get(areaname);

View File

@ -56,8 +56,8 @@ public class DebugClaimTest extends SubCommand {
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion "
+ "will only check the plots in the selected area.");
}
MainUtil.sendMessage(player, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(player, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
PlotManager manager = area.getPlotManager();
ArrayList<Plot> plots = new ArrayList<>();
for (PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
@ -101,7 +101,7 @@ public class DebugClaimTest extends SubCommand {
}
}
if (!plots.isEmpty()) {
MainUtil.sendMessage(player, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: &7Updating '" + plots.size() + "' plots!");
DBFunc.createPlotsAndData(plots, new Runnable() {
@Override
public void run() {
@ -111,7 +111,7 @@ public class DebugClaimTest extends SubCommand {
for (Plot plot : plots) {
plot.create();
}
MainUtil.sendMessage(player, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: &7Complete!");
} else {
MainUtil.sendMessage(player, "No plots were found for the given search.");
}

View File

@ -151,7 +151,7 @@ public class DebugExec extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
List<String> allowed_params =
Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "list-scripts");
Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "seen", "list-scripts");
if (args.length > 0) {
String arg = args[0].toLowerCase();
String script;
@ -196,7 +196,7 @@ public class DebugExec extends SubCommand {
PlotAnalysis.calcOptimalModifiers(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "$1Thank you for calibrating PlotSquared plot expiry");
MainUtil.sendMessage(player, "$1Thank you for calibrating plot expiry");
}
}, threshold);
return true;

View File

@ -0,0 +1,59 @@
package com.intellectualcrafters.plot.commands;
import com.google.common.base.Charsets;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal2;
import com.intellectualcrafters.plot.object.RunnableVal3;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File;
import java.util.UUID;
@CommandDeclaration(
command = "debugimportworlds",
permission = "plots.admin",
description = "Import worlds by player name",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.TELEPORT)
public class DebugImportWorlds extends Command {
public DebugImportWorlds() {
super(MainCommand.getInstance(), true);
}
@Override
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
PlotAreaManager pam = PS.get().getPlotAreaManager();
if (!(pam instanceof SinglePlotAreaManager)) {
player.sendMessage("Must be a single plot area!");
return;
}
SinglePlotArea area = ((SinglePlotAreaManager) pam).getArea();
PlotId id = new PlotId(0, 0);
File container = PS.imp().getWorldContainer();
for (File folder : container.listFiles()) {
String name = folder.getName();
if (!WorldUtil.IMP.isWorld(name) && PlotId.fromString(name) == null) {
UUID uuid = UUIDHandler.getUUID(name, null);
if (uuid == null) {
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
}
while (new File(container, id.toCommaSeparatedString()).exists()) {
id = Auto.getNextPlotId(id, 1);
}
File newDir = new File(container, id.toCommaSeparatedString());
if (folder.renameTo(newDir)) {
area.getPlot(id).setOwner(uuid);
}
}
}
player.sendMessage("Done!");
}
}

View File

@ -19,7 +19,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
permission = "plots.delete",
description = "Delete a plot",
usage = "/plot delete",
aliases = {"dispose", "del"},
aliases = {"dispose", "del", "reset"},
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
confirmation = true)
@ -36,7 +36,7 @@ public class Delete extends SubCommand {
if (!plot.hasOwner()) {
return !sendMessage(player, C.PLOT_UNOWNED);
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.delete")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DELETE)) {
return !sendMessage(player, C.NO_PLOT_PERMS);
}
final PlotArea plotArea = plot.getArea();
@ -62,7 +62,7 @@ public class Delete extends SubCommand {
sendMessage(player, C.ADDED_BALANCE, String.valueOf(value));
}
}
MainUtil.sendMessage(player, C.CLEARING_DONE, System.currentTimeMillis() - start);
MainUtil.sendMessage(player, C.DELETING_DONE, System.currentTimeMillis() - start);
}
});
if (result) {

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location;
@ -42,7 +43,7 @@ public class Deny extends SubCommand {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.deny")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DENY)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
@ -54,7 +55,7 @@ public class Deny extends SubCommand {
Iterator<UUID> iter = uuids.iterator();
while (iter.hasNext()) {
UUID uuid = iter.next();
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(player, "plots.deny.everyone") || Permissions.hasPermission(player, "plots.admin.command.deny"))) {
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(player, C.PERMISSION_DENY_EVERYONE) || Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DENY))) {
MainUtil.sendMessage(player, C.INVALID_PLAYER, MainUtil.getName(uuid));
continue;
}
@ -67,8 +68,10 @@ public class Deny extends SubCommand {
MainUtil.sendMessage(player, C.ALREADY_ADDED, MainUtil.getName(uuid));
return false;
}
plot.removeMember(uuid);
plot.removeTrusted(uuid);
if (uuid != DBFunc.everyone) {
plot.removeMember(uuid);
plot.removeTrusted(uuid);
}
plot.addDenied(uuid);
EventUtil.manager.callDenied(player, plot, uuid, true);
if (!uuid.equals(DBFunc.everyone)) {
@ -98,7 +101,19 @@ public class Deny extends SubCommand {
if (player.getGameMode() == PlotGameMode.SPECTATOR) {
player.stopSpectating();
}
player.teleport(WorldUtil.IMP.getSpawn(player.getLocation().getWorld()));
Location loc = player.getLocation();
Location spawn = WorldUtil.IMP.getSpawn(loc.getWorld());
MainUtil.sendMessage(player, C.YOU_GOT_DENIED);
if (plot.equals(spawn.getPlot())) {
Location newSpawn = WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]);
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
player.kick(C.YOU_GOT_DENIED.s());
} else {
player.teleport(newSpawn);
}
} else {
player.teleport(spawn);
}
}
}

View File

@ -29,7 +29,7 @@ public class Done extends SubCommand {
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.done")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DONE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}

View File

@ -42,11 +42,11 @@ public class Download extends SubCommand {
return false;
}
if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!plot.getFlag(Flags.DONE).isPresent())) && !Permissions
.hasPermission(player, "plots.admin.command.download")) {
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
MainUtil.sendMessage(player, C.DONE_NOT_DONE);
return false;
}
if ((!plot.isOwner(player.getUUID()))) {
if ((!plot.isOwner(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN.s())) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}
@ -55,6 +55,10 @@ public class Download extends SubCommand {
return false;
}
if (args.length == 0 || (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) {
if (plot.getVolume() > Integer.MAX_VALUE) {
C.SCHEMATIC_TOO_LARGE.send(player);
return false;
}
plot.addRunning();
SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
@Override
@ -73,8 +77,9 @@ public class Download extends SubCommand {
}
});
} else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "bo3", "bo2", "b03", "b02")) {
if (!Permissions.hasPermission(player, "plots.download.bo3")) {
C.NO_PERMISSION.send(player, "plots.download.bo3");
if (!Permissions.hasPermission(player, C.PERMISSION_DOWNLOAD_BO3)) {
C.NO_PERMISSION.send(player, C.PERMISSION_DOWNLOAD_BO3);
return false;
}
if (plot.getVolume() > 128d * 128d * 256) {
C.SCHEMATIC_TOO_LARGE.send(player);
@ -93,8 +98,9 @@ public class Download extends SubCommand {
}
});
} else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
if (!Permissions.hasPermission(player, "plots.download.world")) {
C.NO_PERMISSION.send(player, "plots.download.world");
if (!Permissions.hasPermission(player, C.PERMISSION_DOWNLOAD_WORLD)) {
C.NO_PERMISSION.send(player, C.PERMISSION_DOWNLOAD_WORLD);
return false;
}
MainUtil.sendMessage(player, "&cNote: The `.mca` files are 512x512");
plot.addRunning();

View File

@ -56,8 +56,8 @@ public class FlagCmd extends SubCommand {
sendMessage(player, C.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_OTHER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_OTHER);
return false;
}
Flag<?> flag = null;
@ -81,7 +81,7 @@ public class FlagCmd extends SubCommand {
}
switch (args[0].toLowerCase()) {
case "info": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
return false;
}
@ -98,8 +98,8 @@ public class FlagCmd extends SubCommand {
return true;
}
case "set": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG);
return false;
}
if (args.length < 3) {
@ -107,8 +107,8 @@ public class FlagCmd extends SubCommand {
return false;
}
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + '.' + value.toLowerCase())) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + '.' + value.toLowerCase());
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), value.toLowerCase()))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), value.toLowerCase()));
return false;
}
Object parsed = flag.parseValue(value);
@ -125,22 +125,22 @@ public class FlagCmd extends SubCommand {
return true;
}
case "remove": {
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
if (!Permissions.hasPermission(player, C.PERMISSION_FLAG_REMOVE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_FLAG_REMOVE);
return false;
}
if (args.length != 2 && args.length != 3) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
return false;
}
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
if (args.length != 2) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY.f(args[1].toLowerCase()))) {
if (args.length != 3) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY.f(args[1].toLowerCase()));
return false;
}
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + '.' + entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + '.' + entry);
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
return false;
}
}
@ -173,8 +173,8 @@ public class FlagCmd extends SubCommand {
return true;
}
case "add":
if (!Permissions.hasPermission(player, "plots.flag.add")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
if (!Permissions.hasPermission(player, C.PERMISSION_FLAG_ADD)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_FLAG_ADD);
return false;
}
if (args.length < 3) {
@ -182,8 +182,8 @@ public class FlagCmd extends SubCommand {
return false;
}
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + '.' + entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + '.' + entry);
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
return false;
}
}
@ -215,8 +215,8 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_ADDED);
return true;
case "list":
if (!Permissions.hasPermission(player, "plots.flag.list")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
if (!Permissions.hasPermission(player, C.PERMISSION_FLAG_LIST)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_FLAG_LIST);
return false;
}
if (args.length > 1) {

View File

@ -33,8 +33,8 @@ public class Grant extends Command {
switch (arg0) {
case "add":
case "check":
if (Permissions.hasPermission(player, "plots.grant." + arg0)) {
C.NO_PERMISSION.send(player, "plots.grant." + arg0);
if (!Permissions.hasPermission(player, C.PERMISSION_GRANT.f(arg0))) {
C.NO_PERMISSION.send(player, C.PERMISSION_GRANT.f(arg0));
return;
}
if (args.length > 2) {

View File

@ -47,9 +47,9 @@ public class Help extends Command {
case 2:
if (MathMan.isInteger(args[1])) {
try {
displayHelp(player, args[1], Integer.parseInt(args[1]));
displayHelp(player, args[0], Integer.parseInt(args[1]));
} catch (NumberFormatException ignored) {
displayHelp(player, args[1], 1);
displayHelp(player, args[0], 1);
}
}
return;

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location;
@ -36,7 +37,7 @@ public class Kick extends SubCommand {
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if ((!plot.hasOwner() || !plot.isOwner(player.getUUID())) && !Permissions.hasPermission(player, "plots.admin.command.kick")) {
if ((!plot.hasOwner() || !plot.isOwner(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_KICK)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}
@ -49,7 +50,7 @@ public class Kick extends SubCommand {
for (UUID uuid : uuids) {
if (uuid == DBFunc.everyone) {
for (PlotPlayer pp : plot.getPlayersInPlot()) {
if (pp == player || pp.hasPermission("plots.admin.entry.denied")) {
if (pp == player || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_ENTRY_DENIED)) {
continue;
}
players.add(pp);
@ -78,7 +79,7 @@ public class Kick extends SubCommand {
Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
C.YOU_GOT_KICKED.send(player2);
if (plot.equals(spawn.getPlot())) {
Location newSpawn = WorldUtil.IMP.getSpawn(player2);
Location newSpawn = WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]);
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
player2.kick(C.YOU_GOT_KICKED.s());

View File

@ -0,0 +1,48 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal2;
import com.intellectualcrafters.plot.object.RunnableVal3;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID;
@CommandDeclaration(command = "leave",
description = "Leave a plot",
permission = "plots.leave",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE)
public class Leave extends Command {
public Leave() {
super(MainCommand.getInstance(), true);
}
@Override
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
checkTrue(plot.hasOwner(), C.PLOT_UNOWNED);
checkTrue(plot.isAdded(player.getUUID()), C.NO_PLOT_PERMS);
checkTrue(args.length == 0, C.COMMAND_SYNTAX, getUsage());
if (plot.isOwner(player.getUUID())) {
checkTrue(plot.hasOwner(), C.ALREADY_OWNER);
// TODO setowner, other
} else {
UUID uuid = player.getUUID();
if (plot.isAdded(uuid)) {
if (plot.removeTrusted(uuid)) {
EventUtil.manager.callTrusted(player, plot, uuid, false);
}
if (plot.removeMember(uuid)) {
EventUtil.manager.callMember(player, plot, uuid, false);
}
MainUtil.sendMessage(player, C.INVALID_PLAYER, args[0]);
} else {
MainUtil.sendMessage(player, C.REMOVED_PLAYERS, 1);
}
}
}
}

View File

@ -41,43 +41,43 @@ public class ListCmd extends SubCommand {
private String[] getArgumentList(PlotPlayer player) {
List<String> args = new ArrayList<>();
if (EconHandler.manager != null && Permissions.hasPermission(player, "plots.list.forsale")) {
if (EconHandler.manager != null && Permissions.hasPermission(player, C.PERMISSION_LIST_FORSALE)) {
args.add("forsale");
}
if (Permissions.hasPermission(player, "plots.list.mine")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_MINE)) {
args.add("mine");
}
if (Permissions.hasPermission(player, "plots.list.shared")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_SHARED)) {
args.add("shared");
}
if (Permissions.hasPermission(player, "plots.list.world")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD)) {
args.add("world");
}
if (Permissions.hasPermission(player, "plots.list.top")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_TOP)) {
args.add("top");
}
if (Permissions.hasPermission(player, "plots.list.all")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_ALL)) {
args.add("all");
}
if (Permissions.hasPermission(player, "plots.list.unowned")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_UNOWNED)) {
args.add("unowned");
}
if (Permissions.hasPermission(player, "plots.list.unknown")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_UNKNOWN)) {
args.add("unknown");
}
if (Permissions.hasPermission(player, "plots.list.player")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_PLAYER)) {
args.add("<player>");
}
if (Permissions.hasPermission(player, "plots.list.world")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD)) {
args.add("<world>");
}
if (Permissions.hasPermission(player, "plots.list.done")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_DONE)) {
args.add("done");
}
if (Permissions.hasPermission(player, "plots.list.expired")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_EXPIRED)) {
args.add("expired");
}
if (Permissions.hasPermission(player, "plots.list.fuzzy")) {
if (Permissions.hasPermission(player, C.PERMISSION_LIST_FUZZY)) {
args.add("fuzzy <search...>");
}
return args.toArray(new String[args.size()]);
@ -114,16 +114,16 @@ public class ListCmd extends SubCommand {
boolean sort = true;
switch (arg) {
case "mine":
if (!Permissions.hasPermission(player, "plots.list.mine")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.mine");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_MINE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_MINE);
return false;
}
sort = false;
plots = PS.get().sortPlotsByTemp(PS.get().getBasePlots(player));
break;
case "shared":
if (!Permissions.hasPermission(player, "plots.list.shared")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.shared");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_SHARED)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_SHARED);
return false;
}
plots = new ArrayList<>();
@ -134,44 +134,44 @@ public class ListCmd extends SubCommand {
}
break;
case "world":
if (!Permissions.hasPermission(player, "plots.list.world")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.world");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_WORLD);
return false;
}
if (!Permissions.hasPermission(player, "plots.list.world." + world)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.world." + world);
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD_NAME.f(world))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_WORLD_NAME.f(world));
return false;
}
plots = new ArrayList<>(PS.get().getPlots(world));
break;
case "expired":
if (!Permissions.hasPermission(player, "plots.list.expired")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.expired");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_EXPIRED)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_EXPIRED);
return false;
}
plots = ExpireManager.IMP == null ? new ArrayList<Plot>() : new ArrayList<>(ExpireManager.IMP.getPendingExpired());
break;
case "area":
if (!Permissions.hasPermission(player, "plots.list.area")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.area");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_AREA)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_AREA);
return false;
}
if (!Permissions.hasPermission(player, "plots.list.world." + world)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.world." + world);
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD_NAME.f(world))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_WORLD_NAME.f(world));
return false;
}
plots = area == null ? new ArrayList<Plot>() : new ArrayList<>(area.getPlots());
break;
case "all":
if (!Permissions.hasPermission(player, "plots.list.all")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.all");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_ALL)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_ALL);
return false;
}
plots = new ArrayList<>(PS.get().getPlots());
break;
case "done":
if (!Permissions.hasPermission(player, "plots.list.done")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.done");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_DONE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_DONE);
return false;
}
plots = new ArrayList<>();
@ -185,8 +185,8 @@ public class ListCmd extends SubCommand {
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(Plot a, Plot b) {
String va = (String) a.getFlags().get(Flags.DONE);
String vb = (String) b.getFlags().get(Flags.DONE);
String va = "" + a.getFlags().get(Flags.DONE);
String vb = "" + b.getFlags().get(Flags.DONE);
if (MathMan.isInteger(va)) {
if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va);
@ -199,8 +199,8 @@ public class ListCmd extends SubCommand {
sort = false;
break;
case "top":
if (!Permissions.hasPermission(player, "plots.list.top")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.top");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_TOP)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_TOP);
return false;
}
plots = new ArrayList<>(PS.get().getPlots());
@ -236,8 +236,8 @@ public class ListCmd extends SubCommand {
sort = false;
break;
case "forsale":
if (!Permissions.hasPermission(player, "plots.list.forsale")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.forsale");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_FORSALE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_FORSALE);
return false;
}
if (EconHandler.manager == null) {
@ -252,8 +252,8 @@ public class ListCmd extends SubCommand {
}
break;
case "unowned":
if (!Permissions.hasPermission(player, "plots.list.unowned")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.unowned");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_UNOWNED)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_UNOWNED);
return false;
}
plots = new ArrayList<>();
@ -264,8 +264,8 @@ public class ListCmd extends SubCommand {
}
break;
case "unknown":
if (!Permissions.hasPermission(player, "plots.list.unknown")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.unknown");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_UNKNOWN)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_UNKNOWN);
return false;
}
plots = new ArrayList<>();
@ -279,8 +279,8 @@ public class ListCmd extends SubCommand {
}
break;
case "fuzzy":
if (!Permissions.hasPermission(player, "plots.list.fuzzy")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.fuzzy");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_FUZZY)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_FUZZY);
return false;
}
if (args.length < (page == -1 ? 2 : 3)) {
@ -298,12 +298,12 @@ public class ListCmd extends SubCommand {
break;
default:
if (PS.get().hasPlotArea(args[0])) {
if (!Permissions.hasPermission(player, "plots.list.world")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.world");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_WORLD);
return false;
}
if (!Permissions.hasPermission(player, "plots.list.world." + args[0])) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.world." + args[0]);
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_WORLD_NAME.f(args[0]))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_WORLD_NAME.f(args[0]));
return false;
}
plots = new ArrayList<>(PS.get().getPlots(args[0]));
@ -316,8 +316,8 @@ public class ListCmd extends SubCommand {
} catch (Exception ignored) {}
}
if (uuid != null) {
if (!Permissions.hasPermission(player, "plots.list.player")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.list.player");
if (!Permissions.hasPermission(player, C.PERMISSION_LIST_PLAYER)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_LIST_PLAYER);
return false;
}
sort = false;

View File

@ -47,7 +47,7 @@ public class Load extends SubCommand {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.load")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_LOAD)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}
@ -141,7 +141,7 @@ public class Load extends SubCommand {
try {
String schematic = schematics.get(i);
String[] split = schematic.split("_");
if (split.length != 6) {
if (split.length < 5) {
continue;
}
String time = secToTime((System.currentTimeMillis() / 1000) - Long.parseLong(split[0]));

View File

@ -44,7 +44,7 @@ public class MainCommand extends Command {
new Confirm();
new Template();
new Download();
new Update();
new Changelog();
new Template();
new Setup();
new Area();
@ -61,9 +61,11 @@ public class MainCommand extends Command {
new Delete();
new Trust();
new Add();
new Leave();
new Deny();
new Remove();
new Info();
new Near();
new ListCmd();
new Debug();
new SchematicCmd();
@ -90,7 +92,6 @@ public class MainCommand extends Command {
new DebugFixFlags();
new Move();
new Condense();
new Condense();
new Copy();
new Chat();
new Trim();
@ -106,6 +107,7 @@ public class MainCommand extends Command {
new Alias();
new SetHome();
new Cluster();
new DebugImportWorlds();
// Referenced commands
instance.toggle = new Toggle();
instance.help = new Help(instance);
@ -196,7 +198,7 @@ public class MainCommand extends Command {
}
@Override
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
// Clear perm caching //
player.deleteMeta("perm");
// Optional command scope //
@ -222,6 +224,37 @@ public class MainCommand extends Command {
// Trim command
args = Arrays.copyOfRange(args, 1, args.length);
}
if (args.length >= 2 && !args[0].isEmpty() && args[0].charAt(0) == '-') {
switch (args[0].substring(1)) {
case "f":
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
@Override
public void run(Command cmd, Runnable success, Runnable failure) {
if (EconHandler.manager != null) {
PlotArea area = player.getApplicablePlotArea();
if (area != null) {
Expression<Double> priceEval = area.PRICES.get(cmd.getFullId());
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != 0d && EconHandler.manager.getMoney(player) < price) {
if (failure != null) {
failure.run();
}
return;
}
}
}
if (success != null) {
success.run();
}
}
};
args = Arrays.copyOfRange(args, 1, args.length);
break;
default:
C.INVALID_COMMAND_FLAG.send(player);
return;
}
}
}
try {
super.execute(player, args, confirm, whenDone);

View File

@ -64,7 +64,7 @@ public class Merge extends SubCommand {
}
UUID uuid = player.getUUID();
if (!plot.isOwner(uuid)) {
if (!Permissions.hasPermission(player, "plots.admin.command.merge")) {
if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_MERGE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
} else {

View File

@ -0,0 +1,27 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal2;
import com.intellectualcrafters.plot.object.RunnableVal3;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "near",
aliases = "n",
description = "Display nearby players",
usage = "/plot near",
category = CommandCategory.INFO)
public class Near extends Command {
public Near() {
super(MainCommand.getInstance(), true);
}
@Override
public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT);
C.PLOT_NEAR.send(player, StringMan.join(plot.getPlayersInPlot(), ", "));
}
}

View File

@ -54,18 +54,18 @@ public class Owner extends SetCommand {
C.INVALID_PLAYER.send(player, value);
return false;
}
final PlotPlayer other = UUIDHandler.getPlayer(uuid);
if (plot.isOwner(uuid)) {
C.ALREADY_OWNER.send(player);
C.ALREADY_OWNER.send(player, MainUtil.getName(uuid));
return false;
}
final PlotPlayer other = UUIDHandler.getPlayer(uuid);
if (!Permissions.hasPermission(player, "plots.admin.command.setowner")) {
if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SETOWNER)) {
if (other == null) {
C.INVALID_PLAYER_OFFLINE.send(player, value);
return false;
}
int size = plots.size();
int currentPlots = (Settings.Limit.GLOBAL ? other.getPlotCount() : other.getPlotCount(plot.getArea().worldname)) + size;
int currentPlots = (Settings.Limit.GLOBAL ? other.getPlotCount() : other.getPlotCount(plot.getWorldName())) + size;
if (currentPlots > other.getAllowedPlots()) {
sendMessage(player, C.CANT_TRANSFER_MORE_PLOTS);
return false;

View File

@ -5,7 +5,7 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.HttpUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "plugin",
@ -16,11 +16,16 @@ import com.plotsquared.general.commands.CommandDeclaration;
public class PluginCmd extends SubCommand {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
MainUtil.sendMessage(player, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", StringMan.join(PS.get().getVersion(), ".")));
MainUtil.sendMessage(player, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev");
MainUtil.sendMessage(player, "$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki");
MainUtil.sendMessage(player, "$2>> $1&lNewest Version$2: $1" + getNewestVersionString());
public boolean onCommand(final PlotPlayer player, String[] args) {
TaskManager.IMP.taskAsync(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, String.format("$2>> $1&l" + PS.imp().getPluginName() + " $2($1Version$2: $1%s$2)", PS.get().getVersion()));
MainUtil.sendMessage(player, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev");
MainUtil.sendMessage(player, "$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki");
MainUtil.sendMessage(player, "$2>> $1&lNewest Version$2: $1" + getNewestVersionString());
}
});
return true;
}

View File

@ -92,7 +92,7 @@ public class Purge extends SubCommand {
}
final HashSet<Plot> toDelete = new HashSet<>();
for (Plot plot : PS.get().getBasePlots()) {
if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) {
if (world != null && !plot.getWorldName().equalsIgnoreCase(world)) {
continue;
}
if (area != null && !plot.getArea().equals(area)) {
@ -146,6 +146,7 @@ public class Purge extends SubCommand {
Runnable run = new Runnable() {
@Override
public void run() {
PS.debug("Calculating plots to purge, please wait...");
HashSet<Integer> ids = new HashSet<>();
for (Plot plot : toDelete) {
if (plot.temp != Integer.MAX_VALUE) {

View File

@ -28,7 +28,7 @@ import java.util.UUID;
@CommandDeclaration(command = "rate",
permission = "plots.rate",
description = "Rate the plot",
usage = "/plot rate [#|next]",
usage = "/plot rate [#|next|purge]",
aliases = "rt",
category = CommandCategory.INFO,
requiredType = RequiredType.NONE)
@ -37,40 +37,54 @@ public class Rate extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("next")) {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(Plot p1, Plot p2) {
double v1 = 0;
if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating();
switch (args[0].toLowerCase()) {
case "next": {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots());
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(Plot p1, Plot p2) {
double v1 = 0;
if (!p1.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating();
}
}
}
double v2 = 0;
if (!p2.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
v2 -= 11 - entry.getValue().getAverageRating();
double v2 = 0;
if (!p2.getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
v2 -= 11 - entry.getValue().getAverageRating();
}
}
if (v1 == v2) {
return -0;
}
return v2 > v1 ? 1 : -1;
}
if (v1 == v2) {
return -0;
});
UUID uuid = player.getUUID();
for (Plot p : plots) {
if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p.isBasePlot() && (!p.getRatings()
.containsKey(uuid)) && !p.isAdded(uuid)) {
p.teleportPlayer(player);
MainUtil.sendMessage(player, C.RATE_THIS);
return true;
}
return v2 > v1 ? 1 : -1;
}
});
UUID uuid = player.getUUID();
for (Plot p : plots) {
if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p.isBasePlot() && (p.hasRatings() || !p.getRatings()
.containsKey(uuid)) && !p.isAdded(uuid)) {
p.teleportPlayer(player);
MainUtil.sendMessage(player, C.RATE_THIS);
return true;
}
MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
return false;
}
case "purge": {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_RATE, true)) {
return false;
}
plot.clearRatings();
C.RATINGS_PURGED.send(player);
return true;
}
MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
return false;
}
}
final Plot plot = player.getCurrentPlot();
@ -110,7 +124,7 @@ public class Rate extends SubCommand {
Rating result = EventUtil.manager.callRating(this.player, plot, new Rating(rV));
plot.addRating(this.player.getUUID(), result);
sendMessage(this.player, C.RATING_APPLIED, plot.getId().toString());
if (Permissions.hasPermission(this.player, "plots.comment")) {
if (Permissions.hasPermission(this.player, C.PERMISSION_COMMENT)) {
Command command = MainCommand.getInstance().getCommand(Comment.class);
if (command != null) {
MainUtil.sendMessage(this.player, C.COMMENT_THIS, command.getUsage());

View File

@ -31,6 +31,9 @@ public class Reload extends SubCommand {
@Override
public void run(PlotArea area) {
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection("worlds." + area.worldname);
if (worldSection == null) {
return;
}
if (area.TYPE != 2 || !worldSection.contains("areas")) {
area.saveConfiguration(worldSection);
area.loadDefaultConfiguration(worldSection);

View File

@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
@ -18,7 +19,7 @@ import java.util.UUID;
@CommandDeclaration(
command = "remove",
aliases = {"r","untrust", "ut", "undeny", "ud"},
aliases = {"r","untrust", "ut", "undeny", "unban", "ud"},
description = "Remove a player from a plot",
usage = "/plot remove <player>",
category = CommandCategory.SETTINGS,
@ -41,7 +42,7 @@ public class Remove extends SubCommand {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.remove")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_REMOVE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
@ -71,20 +72,30 @@ public class Remove extends SubCommand {
if (!uuids.isEmpty()) {
for (UUID uuid : uuids) {
if (uuid == DBFunc.everyone) {
if (plot.removeTrusted(uuid) | plot.removeMember(uuid) | plot.removeDenied(uuid)) {
if (plot.removeTrusted(uuid)){
EventUtil.manager.callTrusted(player, plot, uuid, false);
count++;
}else if (plot.removeMember(uuid)) {
EventUtil.manager.callMember(player, plot, uuid, false);
count++;
}else if (plot.removeDenied(uuid)) {
EventUtil.manager.callDenied(player, plot, uuid, false);
count++;
}
}
else if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
EventUtil.manager.callTrusted(player, plot, uuid, false);
count++;
}
} else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
EventUtil.manager.callMember(player, plot, uuid, false);
count++;
}
} else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
EventUtil.manager.callDenied(player, plot, uuid, false);
count++;
}
}

View File

@ -47,7 +47,7 @@ public class Save extends SubCommand {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.save")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SAVE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}

View File

@ -41,8 +41,8 @@ public class SchematicCmd extends SubCommand {
String arg = args[0].toLowerCase();
switch (arg) {
case "paste": {
if (!Permissions.hasPermission(player, "plots.schematic.paste")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.schematic.paste");
if (!Permissions.hasPermission(player, C.PERMISSION_SCHEMATIC_PASTE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SCHEMATIC_PASTE);
return false;
}
if (args.length < 2) {
@ -58,7 +58,7 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.schematic.paste")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC_PASTE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}
@ -146,7 +146,7 @@ public class SchematicCmd extends SubCommand {
return false;
}
if (args.length != 2) {
MainUtil.sendMessage(player, "&cNeed world argument. Use &7/plots sch exportall <area>");
MainUtil.sendMessage(player, "&cNeed world argument. Use &7/plot sch exportall <area>");
return false;
}
PlotArea area = PS.get().getPlotAreaByString(args[1]);
@ -156,7 +156,7 @@ public class SchematicCmd extends SubCommand {
}
Collection<Plot> plots = area.getPlots();
if (plots.isEmpty()) {
MainUtil.sendMessage(player, "&cInvalid world. Use &7/plots sch exportall <area>");
MainUtil.sendMessage(player, "&cInvalid world. Use &7/plot sch exportall <area>");
return false;
}
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
@ -169,15 +169,15 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(player, "&cTask is already running.");
return false;
} else {
MainUtil.sendMessage(player, "&3PlotSquared&8->&3Schematic&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(player, "&3PlotSquared&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots...");
MainUtil.sendMessage(player, "&3Plot&8->&3Schematic&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(player, "&3Plot&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots...");
}
break;
}
case "export":
case "save":
if (!Permissions.hasPermission(player, "plots.schematic.save")) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.schematic.save");
if (!Permissions.hasPermission(player, C.PERMISSION_SCHEMATIC_SAVE)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SCHEMATIC_SAVE);
return false;
}
if (this.running) {
@ -193,7 +193,7 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.schematic.save")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC_SAVE)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}

View File

@ -58,8 +58,8 @@ public class Set extends SubCommand {
for (String component : components) {
if (component.equalsIgnoreCase(args[0])) {
if (!Permissions.hasPermission(player, "plots.set." + component)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set." + component);
if (!Permissions.hasPermission(player, C.PERMISSION_SET_COMPONENT.f(component))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_COMPONENT.f(component));
return false;
}
PlotBlock[] blocks;
@ -146,6 +146,9 @@ public class Set extends SubCommand {
}
Command cmd = MainCommand.getInstance().getCommand("set" + args[0]);
if (cmd != null) {
if (!Permissions.hasPermission(player, cmd.getPermission(), true)) {
return false;
}
cmd.execute(player, Arrays.copyOfRange(args, 1, args.length), null, null);
return true;
}

View File

@ -18,15 +18,15 @@ public abstract class SetCommand extends SubCommand {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(player, "plots.admin.command." + getFullId())) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.admin.command." + getFullId());
if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND.f(getFullId()))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_ADMIN_COMMAND.f(getFullId()));
MainUtil.sendMessage(player, C.PLOT_NOT_CLAIMED);
return false;
}
}
if (!plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.admin.command." + getFullId())) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.admin.command." + getFullId());
if (!Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND.f(getFullId()))) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_ADMIN_COMMAND.f(getFullId()));
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}

View File

@ -32,7 +32,7 @@ public class Setup extends SubCommand {
StringBuilder message = new StringBuilder();
message.append("&6What generator do you want?");
for (Entry<String, GeneratorWrapper<?>> entry : SetupUtils.generators.entrySet()) {
if (entry.getKey().equals("PlotSquared")) {
if (entry.getKey().equals(PS.imp().getPluginName())) {
message.append("\n&8 - &2").append(entry.getKey()).append(" (Default Generator)");
} else if (entry.getValue().isFull()) {
message.append("\n&8 - &7").append(entry.getKey()).append(" (Plot Generator)");
@ -79,7 +79,7 @@ public class Setup extends SubCommand {
if (args.length != 1 || !SetupUtils.generators.containsKey(args[0])) {
String prefix = "\n&8 - &7";
MainUtil.sendMessage(player, "&cYou must choose a generator!" + prefix + StringMan.join(SetupUtils.generators.keySet(), prefix)
.replaceAll("PlotSquared", "&2PlotSquared"));
.replaceAll(PS.imp().getPluginName(), "&2" + PS.imp().getPluginName()));
sendMessage(player, C.SETUP_INIT);
return false;
}
@ -137,7 +137,7 @@ public class Setup extends SubCommand {
.getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).getPlotGenerator().processSetup(object);
} else {
object.plotManager = "PlotSquared";
object.plotManager = PS.imp().getPluginName();
MainUtil.sendMessage(player, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator");
MainUtil.sendMessage(player, "&7 - You may need to manually configure the other plugin");
object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator()
@ -263,7 +263,7 @@ public class Setup extends SubCommand {
return false;
}
MainUtil.sendMessage(player,
"&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to "
"&cThe world you specified already exists. After restarting, new terrain will use " + PS.imp().getPluginName() + ", however you may need to "
+ "reset the world for it to generate correctly!");
}
object.world = args[0];

Some files were not shown because too many files have changed in this diff Show More