Compare commits

..

333 Commits
v3.4.1 ... 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
005e13a216 Maybe #1239 2016-08-17 18:30:58 +10:00
3558105789 Fix default flags NPE 2016-08-17 15:08:01 +10:00
f651607d2f Might work? 2016-08-17 12:22:45 +10:00
6b95e57d9e Merge pull request #1313 from MinelinkNetwork/blocked-cmds
Only show blocked-cmds message when event is cancelled
2016-08-17 12:13:27 +10:00
98d0819383 Only show blocked-cmds message when event is cancelled 2016-08-16 19:09:02 -07:00
30da060f83 Potential fix for schematic placement on clear 2016-08-16 15:53:26 +10:00
e4408d56ec *And this 2016-08-16 14:32:31 +10:00
f07ac646f3 Possible fix for greeting spam 2016-08-15 09:31:03 +10:00
ef3380dc0a Merge remote-tracking branch 'origin/master' 2016-08-12 15:04:18 -04:00
749ab83e5d Move permission check out of loop
See #1307
2016-08-12 15:04:11 -04:00
daea9cf60d Allow teleportation for console 2016-08-10 12:33:18 +10:00
2f74368879 Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-08-09 12:45:45 -04:00
63d4476d97 Fix #1181 2016-08-09 12:40:38 -04:00
db69da5b07 *Wrong runnable 2016-08-09 08:52:31 +10: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
d22f7b8781 Merge remote-tracking branch 'origin/master' 2016-08-08 14:03:17 -04:00
112da17614 Squashed commit of the following:
commit 91c78407cd
Author: Jesse Boyd <jessepaleg@gmail.com>
Date:   Sun Aug 7 11:29:59 2016 +1000

    Use a queue for expiry

commit 395d6364be
Author: Jesse Boyd <jessepaleg@gmail.com>
Date:   Sun Aug 7 04:43:41 2016 +1000

    Cache on fail as well

commit facd43700d
Author: Jesse Boyd <jessepaleg@gmail.com>
Date:   Sun Aug 7 04:00:50 2016 +1000

    Cache entity count every second

commit 1ae694ff5b
Author: Jesse Boyd <jessepaleg@gmail.com>
Date:   Sun Aug 7 03:52:37 2016 +1000

    Tweak entity counting

commit c99dd1e74a
Author: Jesse Boyd <jessepaleg@gmail.com>
Date:   Sat Aug 6 00:10:11 2016 +1000

    Needs sponge builds

commit f408ac82be
Author: Alexander Söderberg <Sauilitired@users.noreply.github.com>
Date:   Fri Aug 5 12:13:39 2016 +0200

    Update README.md

commit 9b95990ba6
Author: Alexander Söderberg <Sauilitired@users.noreply.github.com>
Date:   Thu Aug 4 16:50:37 2016 +0200

    Update this here as well
2016-08-08 14:02:25 -04:00
91c78407cd Use a queue for expiry 2016-08-07 11:29:59 +10:00
395d6364be Cache on fail as well 2016-08-07 04:43:41 +10:00
facd43700d Cache entity count every second 2016-08-07 04:00:50 +10:00
1ae694ff5b Tweak entity counting 2016-08-07 03:52:37 +10:00
c99dd1e74a Needs sponge builds 2016-08-06 00:10:11 +10:00
f408ac82be Update README.md 2016-08-05 12:13:39 +02:00
9b95990ba6 Update this here as well 2016-08-04 16:50:37 +02:00
77fb329c9e Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-07-31 21:26:18 -04:00
a13b9fb31b flag tix 2016-08-01 11:20:06 +10:00
ea3306d070 Fix #1034 2016-07-31 20:17:35 -04:00
bcbcd6d916 Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-07-31 18:14:12 +10:00
415c6fb0d4 Fixes #1283 2016-07-31 18:14:06 +10:00
e801c6d7e8 Merge branch '3.4.5' 2016-07-31 00:16:37 -04:00
409456e895 Minor sponge fix 2016-07-31 09:16:58 +10:00
e8f4eae6f7 Merge remote-tracking branch 'origin/3.4.5' into 3.4.5
# Conflicts:
#	Sponge/build.gradle
#	Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java
2016-07-29 21:45:34 -04:00
c8419f4a4a Added more Java 8 warnings 2016-07-29 21:40:23 -04:00
09994724db Fix #1277 2016-07-29 21:40:02 -04:00
610e204d12 Fix #1281 , Fix #1282 , and Sponge gradle 2016-07-29 12:47:42 -04:00
1f341e6ba9 Merge remote-tracking branch 'origin/master' into 3.4.5
# Conflicts:
#	Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java
#	Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java
#	Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java
#	Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java
#	Sponge/src/main/java/com/plotsquared/sponge/util/block/GenChunk.java
#	build.gradle
2016-07-29 12:25:11 -04:00
ffddf5c187 Fix sponge generator cast 2016-07-29 12:12:28 +10:00
b5ec6232f9 Sponge Fixes and minor changes. 2016-07-25 22:25:15 -04:00
34c2da55ca Change Sponge method behavior 2016-07-25 22:25:15 -04:00
33ec80c2cb Fix Sponge generation casting 2016-07-25 22:25:15 -04:00
48064da1ee Fixed deny-teleport flag 2016-07-25 22:25:15 -04:00
adc021109f Added Polar Bear where missing 2016-07-25 22:25:15 -04:00
d23d8c2fd8 *should use this cause instead 2016-07-25 22:25:15 -04:00
3498f309e8 Minor sponge fixes 2016-07-25 22:24:31 -04:00
0b5177f192 Minor uuid cache changes 2016-07-25 22:23:49 -04:00
07dc6a46fb Remove metrics depend 2016-07-25 22:23:19 -04:00
0b19cc7d9d Possible fix + add guest-gamemode flag 2016-07-25 22:23:19 -04:00
4e019ab796 UUID cache changes 2016-07-25 22:23:19 -04:00
b2fdcad317 Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared into 3.4.5
# Conflicts:
#	Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java
#	Sponge/src/main/java/com/plotsquared/sponge/util/block/GenChunk.java
2016-07-25 22:08:54 -04:00
80ea3e9ce7 Sponge Fixes and minor changes. 2016-07-25 20:00:59 -04:00
5f8c77a6cd Change Sponge method behavior 2016-07-25 18:43:11 -04:00
290e5c68dc Fix Sponge generation casting 2016-07-25 18:42:31 -04:00
5d92701100 Fixed deny-teleport flag 2016-07-25 18:04:17 -04:00
1a86d5fb9e Added Polar Bear where missing 2016-07-25 01:19:29 -04:00
30d18c917d *should use this cause instead 2016-07-25 09:54:35 +10:00
b91eab2f0c Minor sponge fixes 2016-07-25 09:47:49 +10:00
770b9be160 Minor uuid cache changes 2016-07-25 09:23:20 +10:00
14b2b11bf3 Remove metrics depend 2016-07-25 08:09:57 +10:00
975a5765c1 Possible fix + add guest-gamemode flag 2016-07-25 08:02:17 +10:00
2b9c2959cf Merge branch '3.4.5' of https://github.com/IntellectualSites/PlotSquared into 3.5.0 2016-07-24 17:45:34 -04:00
07977ac2ce UUID cache changes 2016-07-25 07:44:47 +10:00
9e5ac80435 Merge remote-tracking branch 'origin/3.4.5' into 3.4.5 2016-07-24 17:42:21 -04:00
dda6849412 Fix sponge compile 2016-07-24 17:42:03 -04:00
85d6e42462 Merge branch '3.4.5' of https://github.com/IntellectualSites/PlotSquared into 3.5.0 2016-07-24 17:27:41 -04:00
b1ee223b0a Merge pull request #1271 from manuelgu/patch-1
Make debug output useful
2016-07-24 07:51:45 +02:00
98e865cdf0 Make debug output useful 2016-07-23 12:50:39 +02:00
8b084839fd Fix #1261 2016-07-19 10:22:50 -04:00
c1d4c481fb Fix #1244 2016-07-17 23:20:31 -04:00
269e409e3e Version Bump 2016-07-17 23:19:37 -04:00
8538170cba Metrics 2016-07-16 22:51:49 -04:00
76bce7c0ef Catch CommandException 2016-07-14 20:29:11 +10:00
ba568a3f60 Recover from invalid flag value 2016-07-14 00:28:46 +10:00
a43430b722 Fix NPE for null arg 2016-07-13 00:14:26 +10:00
e2c57cea52 . 2016-07-12 23:56:59 +10:00
ca776b2912 Fixes #1226 2016-07-12 22:12:14 +10:00
e859a7f56c Change to interact perm, not build 2016-07-11 20:27:25 +10:00
ad2db9b836 Merge pull request #1245 from manuelgu/fix/CentreCenterName
Add additional alias for /p middle
2016-07-10 22:58:54 +10:00
279084b043 Add additional alias for /p middle
http://grammarist.com/spelling/center-centre/
2016-07-09 09:18:55 +02:00
8b0e59209c Remove getServerName() 2016-07-05 23:43:08 -04:00
ca8b82dcbe Version Bump 2016-07-05 23:39:38 -04:00
cf5d2a5e86 Entity Fix and Gradle changes 2016-07-01 17:13:49 -04:00
b9ad75ad84 Add teleport flag 2016-06-29 21:22:55 +10:00
185352d3cf Fixes #1229 2016-06-29 15:23:10 +10:00
f4fe762135 * 2016-06-28 20:21:50 +10:00
06682b18a5 Fix compile
Recover on unknown command error
Fixes #1224
Close #1213 (fixed elsewhere)
Fixes #1212
2016-06-28 19:55:51 +10:00
f8e97f14d6 Fix end crystal spawn cap 2016-06-28 02:03:23 +10:00
a579df00db Merge remote-tracking branch 'origin/master' 2016-06-27 10:14:28 -04:00
29a0b68dcb Fix currently online for seen info. 2016-06-27 23:59:38 +10:00
d2581bf38b Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared 2016-06-27 09:58:17 -04:00
817a5bc16e Various
Fix compatibility with bukkit 1.5
Recover on failed fancy message initialization
Fix /2 remove *
2016-06-27 18:38:14 +10:00
047f9a75b9 Fix #1222 2016-06-27 17:45:19 +10:00
96d0bb0e5e bump pom version 2016-06-26 17:08:54 +10:00
7da0b9877f Fixes #1221 (the NPE at least) 2016-06-26 17:07:46 +10:00
f20ef15774 Revert creature spawn message + change expire to seen 2016-06-26 04:30:12 +10:00
3a973342ae Merge remote-tracking branch 'origin/master' 2016-06-24 10:59:18 -04:00
6e25aab51f Cleanup some docs. 2016-06-24 10:56:38 -04:00
a49492aae3 Fix roadregen 2016-06-24 16:16:22 +10:00
dbe965e901 init script engine on get 2016-06-24 15:41:34 +10:00
2c82d1106a Fixed kick message 2016-06-23 23:19:02 -04:00
5b9dc59abf Updates to docs, code style tweaks, and some code optimizations 2016-06-23 20:12:17 -04:00
b587b430b8 #1211 2016-06-24 05:30:26 +10:00
8fd2599686 Fixes #1211 2016-06-24 02:20:21 +10:00
56000d60e7 Just in case 2016-06-23 13:14:29 +10:00
1643399fc6 Alternatives for setowner none if the username is taken 2016-06-23 13:11:26 +10:00
532fd09800 Merge remote-tracking branch 'origin/master' 2016-06-22 23:10:15 -04:00
e6387419f7 Potential fix for plot biome (untested) 2016-06-23 13:09:56 +10:00
30d49880b6 Fix #1208 NPE 2016-06-22 16:31:04 -04:00
16d191db2c Fixes /plot kick * 2016-06-23 04:08:06 +10:00
7dc7714261 Update Gradle to 2.14 2016-06-22 12:31:25 -04:00
9e1f6d8748 Closes #1209 2016-06-22 13:33:32 +10:00
7fb2631421 Cast to string if necessary 2016-06-21 14:23:04 +10:00
718831e8e0 * 2016-06-21 14:10:20 +10:00
df4585a847 Check args for grant 2016-06-21 13:38:08 +10:00
88d8339cfd fix other NPE 2016-06-21 13:32:28 +10:00
e08db3d12b Check teleportation on command location prefix 2016-06-21 03:02:41 +10:00
2ff4e07919 Setup border on world creation 2016-06-21 01:13:09 +10:00
f6fec56677 Potential fix for terrain 3 worlds. 2016-06-21 00:29:39 +10:00
3fabfa10d7 Add liquid-flow flag 2016-06-20 22:48:04 +10:00
a2ca9a52ea Merge pull request #1205 from manuelgu/fix/deadlink
Remove dead link
2016-06-20 18:52:35 +10:00
e5e3600206 Why were these restricted to players? 2016-06-20 18:52:00 +10:00
7ad50b6314 Remove dead link 2016-06-20 10:49:40 +02:00
01d508edf4 Fix remove * 2016-06-20 15:08:56 +10:00
9fa28e1179 * 2016-06-20 01:50:43 +10:00
c3dd28caeb Fix clear done flag requirements 2016-06-20 01:49:35 +10:00
0888940307 bump version 2016-06-20 01:37:27 +10:00
ce7468e63a Fix economy NPE 2016-06-20 00:52:05 +10:00
f5e7d08ace Allow duplicates after 5s 2016-06-19 16:14:13 +10:00
3ce225c044 Bump version 2016-06-19 15:51:46 +10:00
c2f10a7065 Update desc for debugpaste 2016-06-19 13:44:14 +10:00
276 changed files with 14897 additions and 5984 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**:
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
**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

10
.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
@ -132,3 +133,10 @@ local.properties
# STS (Spring Tool Suite)
.springBeans
/target/
Nukkit/build/classes/
Nukkit/build/dependency-cache/
checkstyle.xml
classes/
p2error.txt
*.bat
Nukkit/build/resources/main/plugin.yml

View File

@ -1,8 +1,16 @@
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.bukkit:bukkit:1.10-R0.1-SNAPSHOT'
compile 'org.mcstats.bukkit:metrics:R7'
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
@ -17,19 +25,18 @@ processResources {
)
}
}
apply plugin: 'com.github.johnrengelman.shadow'
// We only want the shadow jar produced
jar.enabled = false
shadowJar {
dependencies {
include(dependency(':Core'))
include(dependency('org.mcstats.bukkit:metrics:R7'))
}
relocate 'org.mcstats', 'com.plotsquared.stats'
relocate('org.mcstats', 'com.plotsquared.stats')
archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
destinationDir = file '../target'
}
shadowJar.doLast {
task ->
ant.checksum file: task.archivePath

View File

@ -20,17 +20,18 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.bukkit.util.BukkitUtil;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
/**
* PlotSquared API.
@ -378,9 +379,9 @@ public class PlotAPI {
}
/**
* Register a flag for use in plots.
* Registers a flag for use in plots.
*
* @param flag the flag being registered
* @param flag the flag to register
*
*/
public void addFlag(Flag<?> flag) {
@ -388,7 +389,7 @@ public class PlotAPI {
}
/**
* Get a plot based on the ID.
* Gets a plot based on the ID.
*
* @param world the world the plot is located in
* @param x The PlotID x coordinate
@ -617,7 +618,7 @@ public class PlotAPI {
}
/**
* Get the PlotSquared class.
* Gets the PlotSquared class.
*
* @return PlotSquared Class
*
@ -628,7 +629,7 @@ public class PlotAPI {
}
/**
* Get the player plot count.
* Gets the player plot count.
*
* @param world Specify the world we want to select the plots from
* @param player Player, for whom we're getting the plot count
@ -644,7 +645,7 @@ public class PlotAPI {
}
/**
* Get a collection containing the players plots.
* Gets a collection containing the players plots.
*
* @param world Specify the world we want to select the plots from
* @param player Player, for whom we're getting the plots
@ -663,7 +664,7 @@ public class PlotAPI {
}
/**
* Get the numbers of plots, which the player is able to build in.
* Gets the number of plots, which the player is able to build in.
*
* @param player player, for whom we're getting the plots
*
@ -676,7 +677,7 @@ public class PlotAPI {
}
/**
* Get the PlotPlayer for a player. The PlotPlayer is usually cached and
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
* will provide useful functions relating to players.
*
* @see PlotPlayer#wrap(Object)

View File

@ -12,9 +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;
@ -37,14 +43,14 @@ import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.bukkit.listeners.ChunkListener;
import com.plotsquared.bukkit.listeners.ForceFieldListener;
import com.plotsquared.bukkit.listeners.EntitySpawnListener;
import com.plotsquared.bukkit.listeners.PlayerEvents;
import com.plotsquared.bukkit.listeners.PlayerEvents183;
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;
@ -52,11 +58,11 @@ import com.plotsquared.bukkit.util.BukkitEconHandler;
import com.plotsquared.bukkit.util.BukkitEventUtil;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.plotsquared.bukkit.util.BukkitPlainChatManager;
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;
@ -72,13 +78,17 @@ 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;
@ -90,13 +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;
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() {
@ -113,7 +172,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
e.printStackTrace();
PS.debug(StringMan.getString(Bukkit.getBukkitVersion()));
PS.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
return new int[]{1, 9, 2};
return new int[]{1, 10, 0};
}
}
return this.version;
@ -121,7 +180,53 @@ 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.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);
}
}
}
}
}
}
@Override
@ -158,6 +263,15 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
}
@Override public String getPluginVersionString() {
return getDescription().getVersion();
}
@Override
public String getPluginName() {
return name;
}
@Override
public void registerCommands() {
BukkitCommand bukkitCommand = new BukkitCommand();
@ -202,7 +316,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
Entity entity = iterator.next();
switch (entity.getType()) {
case EGG:
case ENDER_CRYSTAL:
case COMPLEX_PART:
case FISHING_HOOK:
case ENDER_SIGNAL:
@ -226,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:
@ -233,18 +347,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
// Not vehicles
continue;
case ARMOR_STAND:
// Tempirarily classify as vehicle
// Temporarily classify as vehicle
case MINECART:
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case ENDER_CRYSTAL:
case MINECART_TNT:
case BOAT: {
if (!Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
continue;
}
case BOAT:
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
com.intellectualcrafters.plot.object.Location location = BukkitUtil.getLocation(entity.getLocation());
Plot plot = location.getPlot();
if (plot == null) {
@ -264,6 +377,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
entity.remove();
}
continue;
} else {
continue;
}
case SMALL_FIREBALL:
case FIREBALL:
@ -275,6 +390,21 @@ 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:
case CAVE_SPIDER:
@ -309,9 +439,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
case ZOMBIE:
case SHULKER:
default:
if (!Settings.Enabled_Components.KILL_ROAD_MOBS) {
continue;
}
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
Location location = entity.getLocation();
if (BukkitUtil.getLocation(location).isPlotRoad()) {
if (entity instanceof LivingEntity) {
@ -333,6 +461,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
@ -344,32 +473,48 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
HybridGen result = new HybridGen();
if (Settings.Enabled_Components.PLOTME_CONVERTER) {
initPlotMeConverter();
Settings.Enabled_Components.PLOTME_CONVERTER = false;
}
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();
}
return (ChunkGenerator) result.specify(world);
}
@Override
public void registerPlayerEvents() {
PlayerEvents main = new PlayerEvents();
getServer().getPluginManager().registerEvents(main, this);
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
try {
getServer().getClass().getMethod("spigot");
Class.forName("org.bukkit.event.entity.EntitySpawnEvent");
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
PS.debug("Not running Spigot. Skipping EntitySpawnListener event.");
}
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) {
@ -391,7 +536,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public void registerForceFieldEvents() {
getServer().getPluginManager().registerEvents(new ForceFieldListener(), this);
}
@Override
@ -422,16 +566,16 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
new SendChunk();
MainUtil.canSendChunk = true;
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
e.printStackTrace();
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);
@ -444,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;
return true;
} else if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
return true;
}
if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
return;
}
}
}, 20);
return Bukkit.getPluginManager().getPlugin("PlotMe") != null;
return false;
}
@Override
@ -471,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());
}
}
@ -487,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) {
@ -511,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);
@ -555,20 +693,19 @@ 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();
}
@Override
public String getServerName() {
return Bukkit.getServerName();
}
@Override
public void startMetrics() {
Metrics metrics = new Metrics(this);
metrics.start();
new Metrics(this).start();
PS.log(C.PREFIX + "&6Metrics enabled.");
}
@ -578,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);
@ -587,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);
@ -647,12 +785,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
if (Settings.Chat.INTERACTIVE) {
return new BukkitChatManager();
} else {
return new BukkitPlainChatManager();
return new PlainChatManager();
}
}
@Override
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
public GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(generator);
}

View File

@ -1,10 +1,25 @@
package com.plotsquared.bukkit.chat;
import static com.plotsquared.bukkit.chat.TextualComponent.rawText;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;
import org.bukkit.Achievement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.Statistic.Type;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.Constructor;
@ -19,21 +34,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.bukkit.Achievement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.Statistic.Type;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import static com.plotsquared.bukkit.chat.TextualComponent.rawText;
/**
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
@ -60,7 +60,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
@Override
public FancyMessage clone() throws CloneNotSupportedException {
FancyMessage instance = (FancyMessage) super.clone();
instance.messageParts = new ArrayList<MessagePart>(messageParts.size());
instance.messageParts = new ArrayList<>(messageParts.size());
for (int i = 0; i < messageParts.size(); i++) {
instance.messageParts.add(i, messageParts.get(i).clone());
}
@ -78,15 +78,14 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
this(rawText(firstPartText));
}
public FancyMessage(final com.plotsquared.bukkit.chat.TextualComponent firstPartText) {
messageParts = new ArrayList<MessagePart>();
private FancyMessage(final TextualComponent firstPartText) {
messageParts = new ArrayList<>();
messageParts.add(new MessagePart(firstPartText));
jsonString = null;
dirty = false;
if (nmsPacketPlayOutChatConstructor == null) {
try {
nmsPacketPlayOutChatConstructor = com.plotsquared.bukkit.chat.Reflection.getNMSClass("PacketPlayOutChat").getDeclaredConstructor(com.plotsquared.bukkit.chat.Reflection.getNMSClass("IChatBaseComponent"));
nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat").getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent"));
nmsPacketPlayOutChatConstructor.setAccessible(true);
} catch (NoSuchMethodException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not find Minecraft method or constructor.", e);
@ -100,7 +99,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
* Creates a JSON message without text.
*/
public FancyMessage() {
this((com.plotsquared.bukkit.chat.TextualComponent) null);
this((TextualComponent) null);
}
/**
@ -122,7 +121,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
* @param text The new text of the current editing component.
* @return This builder instance.
*/
public FancyMessage text(com.plotsquared.bukkit.chat.TextualComponent text) {
public FancyMessage text(TextualComponent text) {
MessagePart latest = latest();
latest.text = text;
dirty = true;
@ -243,8 +242,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
*/
public FancyMessage achievementTooltip(final Achievement which) {
try {
Object achievement = com.plotsquared.bukkit.chat.Reflection.getMethod(com.plotsquared.bukkit.chat.Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
return achievementTooltip((String) com.plotsquared.bukkit.chat.Reflection.getField(com.plotsquared.bukkit.chat.Reflection.getNMSClass("Achievement"), "name").get(achievement));
Object achievement = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
@ -252,7 +251,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occured durring invoking of method.", e);
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
@ -271,8 +270,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
throw new IllegalArgumentException("That statistic requires an additional " + type + " parameter!");
}
try {
Object statistic = com.plotsquared.bukkit.chat.Reflection.getMethod(com.plotsquared.bukkit.chat.Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
return achievementTooltip((String) com.plotsquared.bukkit.chat.Reflection.getField(com.plotsquared.bukkit.chat.Reflection.getNMSClass("Statistic"), "name").get(statistic));
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
@ -280,7 +279,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occured durring invoking of method.", e);
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
@ -303,8 +302,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
}
try {
Object statistic = com.plotsquared.bukkit.chat.Reflection.getMethod(com.plotsquared.bukkit.chat.Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
return achievementTooltip((String) com.plotsquared.bukkit.chat.Reflection.getField(com.plotsquared.bukkit.chat.Reflection.getNMSClass("Statistic"), "name").get(statistic));
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
@ -312,7 +311,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occured durring invoking of method.", e);
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
@ -335,8 +334,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
}
try {
Object statistic = com.plotsquared.bukkit.chat.Reflection.getMethod(com.plotsquared.bukkit.chat.Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
return achievementTooltip((String) com.plotsquared.bukkit.chat.Reflection.getField(com.plotsquared.bukkit.chat.Reflection.getNMSClass("Statistic"), "name").get(statistic));
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
} catch (IllegalAccessException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
return this;
@ -344,7 +343,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
return this;
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occured durring invoking of method.", e);
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
return this;
}
}
@ -370,8 +369,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
*/
public FancyMessage itemTooltip(final ItemStack itemStack) {
try {
Object nmsItem = com.plotsquared.bukkit.chat.Reflection.getMethod(com.plotsquared.bukkit.chat.Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
return itemTooltip(com.plotsquared.bukkit.chat.Reflection.getMethod(com.plotsquared.bukkit.chat.Reflection.getNMSClass("ItemStack"), "save", com.plotsquared.bukkit.chat.Reflection.getNMSClass("NBTTagCompound")).invoke(nmsItem, com.plotsquared.bukkit.chat.Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound")).invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
} catch (Exception e) {
e.printStackTrace();
return this;
@ -565,7 +564,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
* @param text The text which will populate the new message component.
* @return This builder instance.
*/
public FancyMessage then(final com.plotsquared.bukkit.chat.TextualComponent text) {
public FancyMessage then(final TextualComponent text) {
if (!latest().hasText()) {
throw new IllegalStateException("previous message part has no text");
}
@ -641,9 +640,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
}
Player player = (Player) sender;
try {
Object handle = com.plotsquared.bukkit.chat.Reflection.getHandle(player);
Object connection = com.plotsquared.bukkit.chat.Reflection.getField(handle.getClass(), "playerConnection").get(handle);
com.plotsquared.bukkit.chat.Reflection.getMethod(connection.getClass(), "sendPacket", com.plotsquared.bukkit.chat.Reflection.getNMSClass("Packet")).invoke(connection, createChatPacket(jsonString));
Object handle = Reflection.getHandle(player);
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")).invoke(connection, createChatPacket(jsonString));
} catch (IllegalArgumentException e) {
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
} catch (IllegalAccessException e) {
@ -651,7 +650,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
} catch (InstantiationException e) {
Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "A error has occured durring invoking of method.", e);
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
} catch (NoSuchMethodException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
} catch (ClassNotFoundException e) {
@ -673,16 +672,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
// X = major
// Y = minor
// Z = revision
final String version = com.plotsquared.bukkit.chat.Reflection.getVersion();
final String version = Reflection.getVersion();
String[] split = version.substring(1, version.length() - 1).split("_"); // Remove trailing dot
//int majorVersion = Integer.parseInt(split[0]);
int minorVersion = Integer.parseInt(split[1]);
int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R
if (minorVersion < 8 || (minorVersion == 8 && revisionVersion == 1)) {
chatSerializerClazz = com.plotsquared.bukkit.chat.Reflection.getNMSClass("ChatSerializer");
chatSerializerClazz = Reflection.getNMSClass("ChatSerializer");
} else {
chatSerializerClazz = com.plotsquared.bukkit.chat.Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
}
if (chatSerializerClazz == null) {
@ -702,7 +701,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
// Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)' than to reflectively call it
// Of course, the implementation may change, but fuzzy matches might break with signature changes
Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, com.plotsquared.bukkit.chat.Reflection.getNMSClass("IChatBaseComponent"));
Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, Reflection.getNMSClass("IChatBaseComponent"));
return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent);
}
@ -781,7 +780,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
// Doc copied from interface
public Map<String, Object> serialize() {
HashMap<String, Object> map = new HashMap<String, Object>();
HashMap<String, Object> map = new HashMap<>();
map.put("messageParts", messageParts);
// map.put("JSON", toJSONString());
return map;
@ -829,9 +828,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
JsonObject messagePart = mPrt.getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
// Deserialize text
if (com.plotsquared.bukkit.chat.TextualComponent.isTextKey(entry.getKey())) {
if (TextualComponent.isTextKey(entry.getKey())) {
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
Map<String, Object> serializedMapForm = new HashMap<String, Object>(); // Must be object due to Bukkit serializer API compliance
Map<String, Object> serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance
serializedMapForm.put("key", entry.getKey());
if (entry.getValue().isJsonPrimitive()) {
// Assume string
@ -842,7 +841,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
serializedMapForm.put("value." + compositeNestedElement.getKey(), compositeNestedElement.getValue().getAsString());
}
}
component.text = com.plotsquared.bukkit.chat.TextualComponent.deserialize(serializedMapForm);
component.text = TextualComponent.deserialize(serializedMapForm);
} else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) {
if (entry.getValue().getAsBoolean()) {
component.styles.add(MessagePart.stylesToNames.inverse().get(entry.getKey()));

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.

View File

@ -20,12 +20,14 @@ import java.util.logging.Level;
final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable {
ChatColor color = ChatColor.WHITE;
ArrayList<ChatColor> styles = new ArrayList<ChatColor>();
String clickActionName = null, clickActionData = null, hoverActionName = null;
ArrayList<ChatColor> styles = new ArrayList<>();
String clickActionName = null;
String clickActionData = null;
String hoverActionName = null;
JsonRepresentedObject hoverActionData = null;
TextualComponent text = null;
String insertionData = null;
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<JsonRepresentedObject>();
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
MessagePart(final TextualComponent text) {
this.text = text;
@ -121,7 +123,7 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
}
public Map<String, Object> serialize() {
HashMap<String, Object> map = new HashMap<String, Object>();
HashMap<String, Object> map = new HashMap<>();
map.put("text", text);
map.put("styles", styles);
map.put("color", color.getChar());

View File

@ -3,6 +3,7 @@ package com.plotsquared.bukkit.chat;
import org.bukkit.Bukkit;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
@ -14,6 +15,20 @@ 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;
private Reflection() { }
@ -37,16 +52,6 @@ public final class Reflection {
return _versionString;
}
/**
* Stores loaded classes from the {@code net.minecraft.server} package.
*/
private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<String, Class<?>>();
/**
* Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages).
*/
private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<String, Class<?>>();
/**
* 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).
@ -60,13 +65,12 @@ public final class Reflection {
}
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = null;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
} catch (Exception e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
_loadedNMSClasses.put(className, null);
return null;
throw new RuntimeException(e);
}
_loadedNMSClasses.put(className, clazz);
return clazz;
@ -85,13 +89,12 @@ public final class Reflection {
}
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz = null;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
} catch (Exception e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
_loadedOBCClasses.put(className, null);
return null;
throw new RuntimeException(e);
}
_loadedOBCClasses.put(className, clazz);
return clazz;
@ -106,16 +109,9 @@ public final class Reflection {
* @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) {
try {
public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
return getMethod(obj.getClass(), "getHandle").invoke(obj);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<Class<?>, Map<String, Field>>();
/**
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
@ -138,7 +134,7 @@ public final class Reflection {
public synchronized static Field getField(Class<?> clazz, String name) {
Map<String, Field> loaded;
if (!_loadedFields.containsKey(clazz)) {
loaded = new HashMap<String, Field>();
loaded = new HashMap<>();
_loadedFields.put(clazz, loaded);
} else {
loaded = _loadedFields.get(clazz);
@ -152,7 +148,7 @@ public final class Reflection {
field.setAccessible(true);
loaded.put(name, field);
return field;
} catch (Exception e) {
} catch (NoSuchFieldException | SecurityException e) {
// Error loading
e.printStackTrace();
// Cache field as not existing
@ -161,12 +157,6 @@ public final class Reflection {
}
}
/**
* 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<Class<?>, Map<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
@ -174,11 +164,9 @@ public final class Reflection {
* <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>
* <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>
* <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...)}.
@ -199,7 +187,7 @@ public final class Reflection {
}
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<Class<?>>(args);
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
if (loadedSignatures.containsKey(wrappedArg)) {
return loadedSignatures.get(wrappedArg);
}

View File

@ -23,6 +23,119 @@ public abstract class TextualComponent implements Cloneable {
ConfigurationSerialization.registerClass(TextualComponent.ComplexTextTypeComponent.class);
}
static TextualComponent deserialize(Map<String, Object> map) {
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
// Arbitrary text component
return ArbitraryTextTypeComponent.deserialize(map);
} else if (map.size() >= 2 && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
// Complex JSON object
return ComplexTextTypeComponent.deserialize(map);
}
return null;
}
static boolean isTextKey(String key) {
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
}
static boolean isTranslatableText(TextualComponent component) {
return component instanceof ComplexTextTypeComponent && component.getKey().equals("translate");
}
/**
* Create a textual component representing a string literal.
*
* <p>This is the default type of textual component when a single string
* literal is given to a method.
*
* @param textValue The text which will be represented.
* @return The text component representing the specified literal text.
*/
public static TextualComponent rawText(String textValue) {
return new ArbitraryTextTypeComponent("text", textValue);
}
/**
* Create a textual component representing a localized string.
* The client will see this text component as their localized version of the specified string <em>key</em>, which can be overridden by a
* resource pack.
* <p>
* If the specified translation key is not present on the client resource pack, the translation key will be displayed as a string literal to
* the client.
* </p>
*
* @param translateKey The string key which maps to localized text.
* @return The text component representing the specified localized text.
*/
public static TextualComponent localizedText(String translateKey) {
return new ArbitraryTextTypeComponent("translate", translateKey);
}
private static void throwUnsupportedSnapshot() {
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
}
/**
* Create a textual component representing a scoreboard value.
* The client will see their own score for the specified objective as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param scoreboardObjective The name of the objective for which to display the score.
* @return The text component representing the specified scoreboard score (for the viewing player), or {@code null} if an error occurs during
* JSON serialization.
*/
public static TextualComponent objectiveScore(String scoreboardObjective) {
return objectiveScore("*", scoreboardObjective);
}
/**
* Create a textual component representing a scoreboard value.
* The client will see the score of the specified player for the specified objective as the text represented by this component.
*
* <p><b>This method is currently guaranteed to throw an {@code UnsupportedOperationException}
* as it is only supported on snapshot clients.</b>
*
* @param playerName The name of the player whos score will be shown. If
* this string represents the single-character sequence
* "*", the viewing player's score will be displayed.
* Standard minecraft selectors (@a, @p, etc)
* are <em>not</em> supported.
* @param scoreboardObjective The name of the objective for
* which to display the score.
* @return The text component representing the specified scoreboard score
* for the specified player, or {@code null} if an error occurs during JSON serialization.
*/
public static TextualComponent objectiveScore(String playerName, String scoreboardObjective) {
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
// OVERLOADS documentation accordingly
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String>builder()
.put("name", playerName)
.put("objective", scoreboardObjective)
.build());
}
/**
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
* The client will see the players or entities captured by the specified selector as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param selector The minecraft player or entity selector which will capture the entities whose string representations will be displayed in
* the place of this text component.
* @return The text component representing the name of the entities captured by the selector.
*/
public static TextualComponent selector(String selector) {
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
// OVERLOADS documentation accordingly
return new ArbitraryTextTypeComponent("selector", selector);
}
@Override
public String toString() {
return getReadableString();
@ -54,59 +167,43 @@ public abstract class TextualComponent implements Cloneable {
*/
public abstract void writeJson(JsonWriter writer) throws IOException;
static TextualComponent deserialize(Map<String, Object> map) {
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
// Arbitrary text component
return ArbitraryTextTypeComponent.deserialize(map);
} else if (map.size() >= 2 && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
// Complex JSON object
return ComplexTextTypeComponent.deserialize(map);
}
return null;
}
static boolean isTextKey(String key) {
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
}
static boolean isTranslatableText(TextualComponent component) {
return component instanceof ComplexTextTypeComponent && ((ComplexTextTypeComponent) component).getKey().equals("translate");
}
/**
* Internal class used to represent all types of text components.
* Exception validating done is on keys and values.
*/
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
private String key;
private String value;
public ArbitraryTextTypeComponent(String key, String value) {
setKey(key);
setValue(value);
}
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
}
@Override
public String getKey() {
return _key;
return key;
}
public void setKey(String key) {
Preconditions.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
_key = key;
this.key = key;
}
public String getValue() {
return _value;
return value;
}
public void setValue(String value) {
Preconditions.checkArgument(value != null, "The value must be specified.");
_value = value;
this.value = value;
}
private String _key;
private String _value;
@Override
public TextualComponent clone() throws CloneNotSupportedException {
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
@ -118,16 +215,15 @@ public abstract class TextualComponent implements Cloneable {
writer.name(getKey()).value(getValue());
}
@Override
@SuppressWarnings("serial")
public Map<String, Object> serialize() {
return new HashMap<String, Object>() {{
return new HashMap<String, Object>() {
{
put("key", getKey());
put("value", getValue());
}};
}
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
};
}
@Override
@ -137,40 +233,55 @@ public abstract class TextualComponent implements Cloneable {
}
/**
* Internal class used to represent a text component with a nested JSON value.
* Exception validating done is on keys and values.
* Internal class used to represent a text component with a nested JSON
* value.
*
* <p>Exception validating done is on keys and values.
*/
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
private String key;
private Map<String, String> value;
public ComplexTextTypeComponent(String key, Map<String, String> values) {
setKey(key);
setValue(values);
}
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
String key = null;
Map<String, String> value = new HashMap<>();
for (Map.Entry<String, Object> valEntry : map.entrySet()) {
if (valEntry.getKey().equals("key")) {
key = (String) valEntry.getValue();
} else if (valEntry.getKey().startsWith("value.")) {
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
}
}
return new ComplexTextTypeComponent(key, value);
}
@Override
public String getKey() {
return _key;
return key;
}
public void setKey(String key) {
Preconditions.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
_key = key;
this.key = key;
}
public Map<String, String> getValue() {
return _value;
return value;
}
public void setValue(Map<String, String> value) {
Preconditions.checkArgument(value != null, "The value must be specified.");
_value = value;
this.value = value;
}
private String _key;
private Map<String, String> _value;
@Override
public TextualComponent clone() throws CloneNotSupportedException {
public TextualComponent clone() {
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
return new ComplexTextTypeComponent(getKey(), getValue());
}
@ -179,33 +290,23 @@ public abstract class TextualComponent implements Cloneable {
public void writeJson(JsonWriter writer) throws IOException {
writer.name(getKey());
writer.beginObject();
for (Map.Entry<String, String> jsonPair : _value.entrySet()) {
for (Map.Entry<String, String> jsonPair : value.entrySet()) {
writer.name(jsonPair.getKey()).value(jsonPair.getValue());
}
writer.endObject();
}
@Override
@SuppressWarnings("serial")
public Map<String, Object> serialize() {
return new java.util.HashMap<String, Object>() {{
return new java.util.HashMap<String, Object>() {
{
put("key", getKey());
for (Map.Entry<String, String> valEntry : getValue().entrySet()) {
put("value." + valEntry.getKey(), valEntry.getValue());
}
}};
}
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
String key = null;
Map<String, String> value = new HashMap<String, String>();
for (Map.Entry<String, Object> valEntry : map.entrySet()) {
if (valEntry.getKey().equals("key")) {
key = (String) valEntry.getValue();
} else if (valEntry.getKey().startsWith("value.")) {
value.put(((String) valEntry.getKey()).substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
}
}
return new ComplexTextTypeComponent(key, value);
};
}
@Override
@ -213,85 +314,4 @@ public abstract class TextualComponent implements Cloneable {
return getKey();
}
}
/**
* Create a textual component representing a string literal.
* This is the default type of textual component when a single string literal is given to a method.
*
* @param textValue The text which will be represented.
* @return The text component representing the specified literal text.
*/
public static TextualComponent rawText(String textValue) {
return new ArbitraryTextTypeComponent("text", textValue);
}
/**
* Create a textual component representing a localized string.
* The client will see this text component as their localized version of the specified string <em>key</em>, which can be overridden by a resource pack.
* <p>
* If the specified translation key is not present on the client resource pack, the translation key will be displayed as a string literal to the client.
* </p>
*
* @param translateKey The string key which maps to localized text.
* @return The text component representing the specified localized text.
*/
public static TextualComponent localizedText(String translateKey) {
return new ArbitraryTextTypeComponent("translate", translateKey);
}
private static void throwUnsupportedSnapshot() {
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
}
/**
* Create a textual component representing a scoreboard value.
* The client will see their own score for the specified objective as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param scoreboardObjective The name of the objective for which to display the score.
* @return The text component representing the specified scoreboard score (for the viewing player), or {@code null} if an error occurs during JSON serialization.
*/
public static TextualComponent objectiveScore(String scoreboardObjective) {
return objectiveScore("*", scoreboardObjective);
}
/**
* Create a textual component representing a scoreboard value.
* The client will see the score of the specified player for the specified objective as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param playerName The name of the player whos score will be shown. If this string represents the single-character sequence "*", the viewing player's score will be displayed.
* Standard minecraft selectors (@a, @p, etc) are <em>not</em> supported.
* @param scoreboardObjective The name of the objective for which to display the score.
* @return The text component representing the specified scoreboard score for the specified player, or {@code null} if an error occurs during JSON serialization.
*/
public static TextualComponent objectiveScore(String playerName, String scoreboardObjective) {
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE OVERLOADS documentation accordingly
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String>builder()
.put("name", playerName)
.put("objective", scoreboardObjective)
.build());
}
/**
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
* The client will see the players or entities captured by the specified selector as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param selector The minecraft player or entity selector which will capture the entities whose string representations will be displayed in the place of this text component.
* @return The text component representing the name of the entities captured by the selector.
*/
public static TextualComponent selector(String selector) {
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE OVERLOADS documentation accordingly
return new ArbitraryTextTypeComponent("selector", selector);
}
}

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

@ -13,7 +13,7 @@ import java.util.HashMap;
public abstract class APlotMeConnector {
public abstract Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder);
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;

View File

@ -26,12 +26,12 @@ import java.util.UUID;
public class ClassicPlotMeConnector extends APlotMeConnector {
private String plugin;
private String plugin = "PlotMe";
private String prefix;
@Override
public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) {
this.plugin = this.plugin.toLowerCase();
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
this.plugin = plugin.toLowerCase();
this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase());
try {
if (plotConfig.getBoolean("usemySQL")) {

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();
@ -123,14 +151,14 @@ public class LikePlotMeConverter {
PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
Connection connection = connector.getPlotMeConnection(plotConfig, dataFolder);
Connection connection = connector.getPlotMeConnection(plugin,plotConfig, dataFolder);
if (!connector.isValidConnection(connection)) {
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
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); //
HashSet<String> allWorlds = new HashSet<>(plots.keySet());
allWorlds.addAll(worlds);
for (String world : allWorlds) {
copyConfig(plotmeDgYml, world);
}
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);
} catch (IOException ignored) {
ignored.printStackTrace();
}
} catch (IOException ignored) {}
}
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,9 +294,13 @@ 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 + "'...");
if (!Bukkit.getWorlds().isEmpty() && Bukkit.getWorlds().get(0).getName().equals(worldName)) {
sendMessage("&cYou need to stop the server to reload this world properly");
} else {
PS.get().removePlotAreas(actualWorldName);
if (mv) {
// unload world with MV
@ -302,7 +312,7 @@ public class LikePlotMeConverter {
}
// load world with MV
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mv import " + actualWorldName + " normal -g PlotSquared");
"mv import " + actualWorldName + " normal -g " + PS.imp().getPluginName());
} else if (mw) {
// unload world with MW
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
@ -313,15 +323,16 @@ public class LikePlotMeConverter {
}
// load world with MW
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
"mw create " + actualWorldName + " plugin:PlotSquared");
"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(new HybridGen())).createWorld();
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator())).createWorld();
myWorld.save();
}
}
}
} catch (CommandException e) {
e.printStackTrace();
}
@ -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

@ -26,8 +26,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
private String plugin;
@Override
public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) {
this.plugin = this.plugin.toLowerCase();
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
this.plugin = plugin.toLowerCase();
try {
if (plotConfig.getBoolean("usemySQL")) {
String user = plotConfig.getString("mySQLuname");
@ -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;
@ -36,7 +35,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
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<>();
@ -48,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;
@ -118,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
@ -128,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
@ -187,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();
}
@ -245,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);
@ -255,7 +255,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) {
GenChunk result = (GenChunk) this.chunkSetter;
GenChunk result = this.chunkSetter;
// Set the chunk location
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
// Set the result data
@ -303,7 +303,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid grid) {
GenChunk result = (GenChunk) this.chunkSetter;
GenChunk result = this.chunkSetter;
// Set the chunk location
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
// Set the result data

View File

@ -1,8 +1,7 @@
package com.plotsquared.bukkit.listeners;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
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;
@ -10,6 +9,8 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.TaskManager;
import java.lang.reflect.Method;
import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@ -28,8 +29,8 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import java.lang.reflect.Method;
import java.util.HashSet;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
public class ChunkListener implements Listener {
@ -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;
}
}
@ -100,14 +101,21 @@ public class ChunkListener implements Listener {
}, 1);
}
private boolean ignoreUnload = false;
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) {
return false;
}
Object c = this.methodGetHandleChunk.of(chunk).call();
this.mustSave.of(c).set(false);
RefField.RefExecutor field = this.mustSave.of(c);
if ((Boolean) field.get() == true) {
field.set(false);
if (chunk.isLoaded()) {
ignoreUnload = true;
chunk.unload(false, false);
ignoreUnload = false;
}
}
return true;
}
@ -139,6 +147,9 @@ public class ChunkListener implements Listener {
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
if (ignoreUnload) {
return;
}
if (Settings.Chunk_Processor.AUTO_TRIM) {
Chunk chunk = event.getChunk();
String world = chunk.getWorld().getName();
@ -218,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;
}
@ -226,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;
}
@ -236,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;
}
@ -260,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

@ -0,0 +1,43 @@
package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.plotsquared.bukkit.util.BukkitUtil;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
public class EntitySpawnListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void creatureSpawnEvent(EntitySpawnEvent event) {
Entity entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity.getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
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 (PlayerEvents.checkEntity(entity, plot)) {
event.setCancelled(true);
}
}
}
}

View File

@ -1,27 +1,27 @@
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.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
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 implements Listener {
public class ForceFieldListener {
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
Set<PlotPlayer> players = new HashSet<>();
for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
for (Player nearPlayer : Iterables.filter(player.getNearbyEntities(5d, 5d, 5d),Player.class)) {
PlotPlayer plotPlayer;
if (!(entity instanceof Player) || ((plotPlayer = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(plotPlayer.getCurrentPlot())) {
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) {
continue;
}
if (!plot.isAdded(plotPlayer.getUUID())) {
@ -32,15 +32,9 @@ public class ForceFieldListener implements Listener {
}
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
if (!(entity instanceof Player)) {
continue;
}
for (Player nearPlayer : Iterables.filter(player.getNearbyEntities(5d, 5d, 5d),Player.class)) {
PlotPlayer plotPlayer;
if ((plotPlayer = BukkitUtil.getPlayer((Player) entity)) == null) {
continue;
}
if (!plot.equals(plotPlayer.getCurrentPlot())) {
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) {
continue;
}
if (plot.isAdded(plotPlayer.getUUID())) {
@ -86,15 +80,19 @@ public class ForceFieldListener implements Listener {
if (plot.isAdded(uuid)) {
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
for (PlotPlayer oPlayer : players) {
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;
}
if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
}
}
}
}
}

View File

@ -20,16 +20,18 @@ 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.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -65,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;
@ -74,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;
@ -86,7 +90,9 @@ import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.PotionSplashEvent;
@ -158,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:
@ -192,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;
}
@ -201,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;
@ -279,8 +297,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!(shooter instanceof Player)) {
return;
}
ThrownPotion potion = (ThrownPotion) entity;
Location l = BukkitUtil.getLocation(potion);
Location l = BukkitUtil.getLocation(entity);
if (!PS.get().hasPlotArea(l.getWorld())) {
return;
}
@ -303,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);
@ -345,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);
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;
}
}
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = pp.getCurrentPlot();
}
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];
@ -410,7 +430,6 @@ public class PlayerEvents extends PlotListener implements Listener {
pattern = RegExUtil.compiledPatterns.get(s);
}
if (pattern.matcher(msg).matches()) {
MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
String perm;
if (plot.isAdded(pp.getUUID())) {
perm = "plots.admin.command.blocked-cmds.shared";
@ -418,6 +437,7 @@ public class PlayerEvents extends PlotListener implements Listener {
perm = "plots.admin.command.blocked-cmds.other";
}
if (!Permissions.hasPermission(pp, perm)) {
MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
event.setCancelled(true);
}
return;
@ -426,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();
@ -466,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();
@ -487,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;
}
@ -538,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);
}
}
@ -575,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);
@ -588,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)) {
@ -603,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)
@ -617,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) {
@ -699,7 +774,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (this.lastRadius != 0) {
List<Entity> nearby = event.getEntity().getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
for (Entity near : nearby) {
if (near instanceof TNTPrimed || near.getType() == EntityType.MINECART_TNT) {
if (near instanceof TNTPrimed || near.getType().equals(EntityType.MINECART_TNT)) {
if (!near.hasMetadata("plot")) {
near.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
}
@ -725,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")) {
@ -744,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)
@ -764,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);
}
}
@ -804,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();
@ -818,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);
@ -898,8 +1031,19 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot != null) {
if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
event.setCancelled(true);
return;
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) {
event.setCancelled(true);
return;
}
if (Flags.LIQUID_FLOW.isFalse(plot)) {
switch (to.getType()) {
case WATER:
case STATIONARY_WATER:
case LAVA:
case STATIONARY_LAVA:
event.setCancelled(true);
}
}
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) {
event.setCancelled(true);
@ -941,12 +1085,12 @@ public class PlayerEvents extends PlotListener implements Listener {
}
List<Block> blocks = event.getBlocks();
for (Block b : blocks) {
Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative));
if (!area.contains(bloc.getX(), bloc.getZ())) {
Location bloc = BukkitUtil.getLocation(b.getLocation());
if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
event.setCancelled(true);
return;
}
if (!plot.equals(area.getOwnedPlot(bloc))) {
if (!plot.equals(area.getOwnedPlot(bloc)) || !plot.equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
event.setCancelled(true);
return;
}
@ -1067,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;
@ -1087,7 +1231,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -1161,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:
@ -1174,14 +1337,13 @@ public class PlayerEvents extends PlotListener implements Listener {
}
lb = new BukkitLazyBlock(blockId, block);
ItemStack hand = player.getItemInHand();
if (eventType != null) {
if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK || !player.isSneaking())) {
break;
}
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;
lb = new BukkitLazyBlock(0, block);
break;
}
if (id < 198) {
@ -1197,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:
@ -1272,7 +1431,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void MobSpawn(CreatureSpawnEvent event) {
public void creatureSpawnEvent(CreatureSpawnEvent event) {
Entity entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity.getLocation());
PlotArea area = location.getPlotArea();
@ -1318,10 +1477,6 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
if (checkEntity(entity, plot)) {
PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
if (owner != null) {
C.ENTITY_CAP.send(owner);
}
event.setCancelled(true);
}
}
@ -1368,7 +1523,10 @@ public class PlayerEvents extends PlotListener implements Listener {
this.lastRadius = event.getRadius() + 1;
}
public boolean checkEntity(Plot plot, IntegerFlag... flags) {
public static boolean checkEntity(Plot plot, IntegerFlag... flags) {
if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(plot)) {
return true;
}
int[] mobs = null;
for (IntegerFlag flag : flags) {
int i;
@ -1398,23 +1556,59 @@ public class PlayerEvents extends PlotListener implements Listener {
if (cap == Integer.MAX_VALUE) {
continue;
}
if (cap == 0) {
return true;
}
if (mobs == null) {
mobs = plot.countEntities();
}
if (mobs[i] >= cap) {
plot.setMeta("EntityCount", mobs);
plot.setMeta("EntityCountTime", System.currentTimeMillis());
return true;
}
}
if (mobs != null) {
for (IntegerFlag flag : flags) {
int i;
switch (flag.getName()) {
case "entity-cap":
i = 0;
break;
case "mob-cap":
i = 3;
break;
case "hostile-cap":
i = 2;
break;
case "animal-cap":
i = 1;
break;
case "vehicle-cap":
i = 4;
break;
case "misc-cap":
i = 5;
break;
default:
i = 0;
}
mobs[i]++;
}
plot.setMeta("EntityCount", mobs);
plot.setMeta("EntityCountTime", System.currentTimeMillis());
}
return false;
}
public boolean checkEntity(Entity entity, Plot plot) {
public static boolean checkEntity(Entity entity, Plot plot) {
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS.isEmpty()) {
return false;
}
switch (entity.getType()) {
case PLAYER:
return false;
case LLAMA_SPIT:
case SMALL_FIREBALL:
case FIREBALL:
case DROPPED_ITEM:
@ -1444,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);
@ -1461,6 +1656,7 @@ public class PlayerEvents extends PlotListener implements Listener {
case MINECART_TNT:
case BOAT:
return checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
case POLAR_BEAR:
case RABBIT:
case SHEEP:
case MUSHROOM_COW:
@ -1475,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:
@ -1496,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:
@ -1622,153 +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.getPlotAbs(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)) {
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.getPlotAbs(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)) {
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();
@ -1779,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;
@ -1833,6 +1895,9 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onLeave(PlayerQuitEvent event) {
if (TaskManager.TELEPORT_QUEUE.contains(event.getPlayer().getName())) {
TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
}
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
pp.unregister();
}
@ -1847,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;
@ -1902,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);
@ -1943,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);
@ -1973,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)) {
@ -2004,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);
@ -2032,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);
@ -2050,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");
@ -2097,6 +2165,32 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
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)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
@ -2294,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)) {
@ -2333,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;
@ -12,9 +13,12 @@ import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventException;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.UUID;
import org.bukkit.plugin.RegisteredListener;
public class BukkitPlayer extends PlotPlayer {
@ -57,6 +61,39 @@ public class BukkitPlayer extends PlotPlayer {
return this.player.getLastPlayed();
}
@Override
public boolean canTeleport(Location loc) {
org.bukkit.Location to = BukkitUtil.getLocation(loc);
org.bukkit.Location from = player.getLocation();
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
for (RegisteredListener listener : listeners) {
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
continue;
}
try {
listener.callEvent(event);
} catch (EventException e) {
e.printStackTrace();
}
}
if (event.isCancelled() || !event.getTo().equals(to)) {
return false;
}
event = new PlayerTeleportEvent(player, to, from);
for (RegisteredListener listener : listeners) {
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
continue;
}
try {
listener.callEvent(event);
} catch (EventException e) {
e.printStackTrace();
}
}
return true;
}
@Override
public boolean hasPermission(String permission) {
if (this.offline && EconHandler.manager != null) {
@ -65,10 +102,16 @@ 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)) {
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
setMeta("lastMessage", message);
setMeta("lastMessageTime", System.currentTimeMillis());
this.player.sendMessage(message);
}
}

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 {
@ -366,7 +367,11 @@ public class EntityWrapper {
}
private void restoreInventory(InventoryHolder entity) {
try {
entity.getInventory().setContents(this.inventory);
} catch (IllegalArgumentException e) {
PS.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
}
}
public void storeLiving(LivingEntity lived) {
@ -393,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 {
@ -483,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);
}
@ -491,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);
}
@ -30,7 +30,6 @@ public class DefaultTitleManager_183 extends DefaultTitleManager {
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
this.nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
}
@Override
@ -68,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

@ -52,7 +52,7 @@ public abstract class TitleManager {
abstract void loadClasses();
/**
* Get title text.
* Gets title text.
*
* @return Title text
*/
@ -61,7 +61,7 @@ public abstract class TitleManager {
}
/**
* Set title text.
* Sets the text for the title.
*
* @param title Title
*/
@ -70,7 +70,7 @@ public abstract class TitleManager {
}
/**
* Get subtitle text.
* Gets the subtitle text.
*
* @return Subtitle text
*/
@ -79,7 +79,7 @@ public abstract class TitleManager {
}
/**
* Set subtitle text.
* Sets subtitle text.
*
* @param subtitle Subtitle text
*/
@ -88,7 +88,7 @@ public abstract class TitleManager {
}
/**
* Set the title color.
* Sets the title color.
*
* @param color Chat color
*/
@ -97,7 +97,7 @@ public abstract class TitleManager {
}
/**
* Set the subtitle color.
* Sets the subtitle color.
*
* @param color Chat color
*/
@ -106,7 +106,7 @@ public abstract class TitleManager {
}
/**
* Set title fade in time.
* Sets title fade in time.
*
* @param time Time
*/
@ -115,7 +115,7 @@ public abstract class TitleManager {
}
/**
* Set title fade out time.
* Sets title fade out time.
*
* @param time Time
*/
@ -124,7 +124,7 @@ public abstract class TitleManager {
}
/**
* Set title stay time.
* Sets title stay time.
*
* @param time Time
*/
@ -133,21 +133,21 @@ public abstract class TitleManager {
}
/**
* Set timings to ticks.
* Sets timings to ticks.
*/
public final void setTimingsToTicks() {
this.ticks = true;
}
/**
* Set timings to seconds.
* Sets timings to seconds.
*/
public final void setTimingsToSeconds() {
this.ticks = false;
}
/**
* Send the title to a player.
* Sends the title to a player.
*
* @param player Player
* @throws IllegalArgumentException
@ -157,18 +157,18 @@ public abstract class TitleManager {
public abstract void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
/**
* Broadcast the title to all players.
* Broadcasts the title to all players.
*
* @throws Exception
*/
public final void broadcast() throws Exception {
for (Player p : Bukkit.getOnlinePlayers()) {
send(p);
for (Player player : Bukkit.getOnlinePlayers()) {
send(player);
}
}
/**
* Clear the title.
* Clears the title.
*
* @param player Player
* @throws IllegalArgumentException
@ -178,7 +178,7 @@ public abstract class TitleManager {
public abstract void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
/**
* Reset the title settings.
* Resets the title settings.
*
* @param player Player
* @throws IllegalArgumentException
@ -195,7 +195,7 @@ public abstract class TitleManager {
}
}
final Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
int a;
if (classes != null) {
a = classes.length;
@ -229,7 +229,7 @@ public abstract class TitleManager {
return null;
}
final boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
private boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
@ -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

@ -17,14 +17,6 @@ import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
import com.plotsquared.bukkit.object.entity.EntityWrapper;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.DyeColor;
@ -57,6 +49,15 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class BukkitChunkManager extends ChunkManager {
public static boolean isIn(RegionWrapper region, int x, int z) {
@ -424,6 +425,10 @@ public class BukkitChunkManager extends ChunkManager {
@Override
public int[] countEntities(Plot plot) {
int[] existing = (int[]) plot.getMeta("EntityCount");
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
return existing;
}
PlotArea area = plot.getArea();
World world = BukkitUtil.getWorld(area.worldname);
@ -448,9 +453,9 @@ public class BukkitChunkManager extends ChunkManager {
boolean doWhole = false;
List<Entity> entities = null;
if (size > 200) {
if (size > 200 && chunks.size() > 200) {
entities = world.getEntities();
if (entities.size() < 16 + size * size / 64) {
if (entities.size() < 16 + size / 8) {
doWhole = true;
}
}
@ -511,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:
@ -528,12 +534,14 @@ public class BukkitChunkManager extends ChunkManager {
case UNKNOWN:
case AREA_EFFECT_CLOUD:
case LINGERING_POTION:
case EVOKER_FANGS:
// non moving / unremovable
break;
case ITEM_FRAME:
case PAINTING:
case ARMOR_STAND:
count[5]++;
break;
// misc
case MINECART:
case MINECART_CHEST:
@ -545,6 +553,7 @@ public class BukkitChunkManager extends ChunkManager {
case BOAT:
count[4]++;
break;
case POLAR_BEAR:
case RABBIT:
case SHEEP:
case MUSHROOM_COW:
@ -559,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]++;
@ -582,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]++;
@ -603,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,12 +173,14 @@ public class BukkitHybridUtils extends HybridUtils {
}
Material material = Material.getMaterial(now);
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,6 +33,7 @@ public class BukkitSetupUtils extends SetupUtils {
}
String testWorld = "CheckingPlotSquaredGenerator";
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
try {
if (plugin.isEnabled()) {
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
if (generator != null) {
@ -45,8 +48,33 @@ public class BukkitSetupUtils extends SetupUtils {
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) {
@ -55,13 +83,13 @@ public class BukkitSetupUtils extends SetupUtils {
String world = object.world;
int type = object.type;
String worldPath = "worlds." + object.world;
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);
switch (type) {
case 2: {
if (object.id != null) {
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,12 +144,20 @@ public class BukkitSetupUtils extends SetupUtils {
object.setupGenerator = null;
}
break;
case 0:
}
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);
} catch (IOException e) {
@ -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

@ -1,6 +1,5 @@
package com.plotsquared.bukkit.util;
import com.intellectualcrafters.plot.PS;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -9,71 +8,38 @@ import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
public class Metrics {
/**
* The current revision number.
*/
/** The current revision number. */
private static final int REVISION = 7;
/**
* The base url of the metrics domain.
*/
/** The base url of the metrics domain.*/
private static final String BASE_URL = "http://report.mcstats.org";
/**
* The url used to report a server's status.
*/
/** The url used to report a server's status. */
private static final String REPORT_URL = "/plugin/%s";
/**
* Interval of time to ping (in minutes).
*/
/** Interval of time to ping (in minutes). */
private static final int PING_INTERVAL = 15;
/**
* The plugin this metrics submits for.
*/
/** The plugin this metrics submits for. */
private final Plugin plugin;
/**
* All of the custom graphs to submit to metrics.
*/
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/**
* Unique server id.
*/
/** Unique server id. */
private final String guid;
/**
* Debug mode.
*/
private final boolean debug;
/**
* The scheduled task.
*/
/** The scheduled task. */
private volatile BukkitTask task = null;
public Metrics(Plugin plugin) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
this.plugin = plugin;
this.guid = UUID.randomUUID().toString();
this.debug = false;
}
/**
@ -186,38 +152,6 @@ public class Metrics {
return URLEncoder.encode(text, "UTF-8");
}
/**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* website. Plotters can be added to the graph object returned.
*
* @param name The name of the graph
*
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(String name) {
if (name == null) {
throw new IllegalArgumentException("Graph name cannot be null");
}
// Construct the graph object
Graph graph = new Graph(name);
// Now we can add our graph
this.graphs.add(graph);
// and return back
return graph;
}
/**
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
*
* @param graph The name of the graph
*/
public void addGraph(Graph graph) {
if (graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
this.graphs.add(graph);
}
/**
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
@ -244,54 +178,12 @@ public class Metrics {
this.firstPost = false;
} catch (IOException e) {
e.printStackTrace();
if (Metrics.this.debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}
}, 0, PING_INTERVAL * 1200);
return true;
}
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*/
public void enable() {
// Enable Task, if it is not running
if (this.task == null) {
start();
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
*/
public void disable() {
// Disable Task, if it is running
if (this.task != null) {
this.task.cancel();
this.task = null;
}
}
/**
* Gets the File object of the config file that should be used to store
* data such as the GUID and opt-out status.
*
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set
// via -P) for plugins to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory.
File pluginsFolder = this.plugin.getDataFolder().getParentFile();
// return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
/**
* Generic method that posts a plugin to the metrics website.
*/
@ -342,46 +234,12 @@ public class Metrics {
if (isPing) {
appendJSONPair(json, "ping", "1");
}
if (!this.graphs.isEmpty()) {
synchronized (this.graphs) {
json.append(',');
json.append('"');
json.append("graphs");
json.append('"');
json.append(':');
json.append('{');
boolean firstGraph = true;
for (Graph graph : this.graphs) {
StringBuilder graphJson = new StringBuilder();
graphJson.append('{');
for (Plotter plotter : graph.getPlotters()) {
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
}
graphJson.append('}');
if (!firstGraph) {
json.append(',');
}
json.append(escapeJSON(graph.getName()));
json.append(':');
json.append(graphJson);
firstGraph = false;
}
json.append('}');
}
}
// close json
json.append('}');
// Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website
URLConnection connection;
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
}
URLConnection connection = url.openConnection();
byte[] uncompressed = json.toString().getBytes();
byte[] compressed = gzip(json.toString());
// Headers
@ -392,9 +250,6 @@ public class Metrics {
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.setDoOutput(true);
if (this.debug) {
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
}
try {
try (OutputStream os = connection.getOutputStream()) {
os.write(compressed);
@ -403,9 +258,6 @@ public class Metrics {
String response;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
response = reader.readLine();
if (this.debug) {
PS.debug("[Metrics] Response for " + pluginName + ": " + response);
}
}
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) {
@ -414,171 +266,7 @@ public class Metrics {
response = response.substring(response.startsWith("7,") ? 2 : 1);
}
throw new IOException(response);
} else {
// Is this the first update this hour?
if ("1".equals(response) || response.contains("This is your first update this hour")) {
synchronized (this.graphs) {
for (Graph graph : this.graphs) {
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
}
}
}
}
} catch (Exception e) {
if (this.debug) {
e.printStackTrace();
}
}
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
*
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (ClassNotFoundException ignored) {
return false;
}
}
/**
* Represents a custom graph on the website
*/
public static class Graph {
/**
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
* rejected
*/
private final String name;
/**
* The set of plotters that are contained within this graph
*/
private final Set<Plotter> plotters = new LinkedHashSet<>();
private Graph(String name) {
this.name = name;
}
/**
* Gets the graph's name
*
* @return the Graph's name
*/
public String getName() {
return this.name;
}
/**
* Add a plotter to the graph, which will be used to plot entries
*
* @param plotter the plotter to add to the graph
*/
public void addPlotter(Plotter plotter) {
this.plotters.add(plotter);
}
/**
* Remove a plotter from the graph
*
* @param plotter the plotter to remove from the graph
*/
public void removePlotter(Plotter plotter) {
this.plotters.remove(plotter);
}
/**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
*
* @return an unmodifiable {@link Set} of the plotter objects
*/
public Set<Plotter> getPlotters() {
return Collections.unmodifiableSet(this.plotters);
}
@Override
public int hashCode() {
return this.name.hashCode();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Graph)) {
return false;
}
Graph graph = (Graph) object;
return graph.name.equals(this.name);
}
}
/**
* Interface used to collect custom data for a plugin
*/
public abstract static class Plotter {
/**
* The plot's name
*/
private final String name;
/**
* Construct a plotter with the default plot name
*/
public Plotter() {
this("Default");
}
/**
* Construct a plotter with a specific plot name
*
* @param name the name of the plotter to use, which will show up on the website
*/
public Plotter(String name) {
this.name = name;
}
/**
* Get the current value for the plotted point. Since this function defers to an external function it may or may
* not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
* from any thread so care should be taken when accessing resources that need to be synchronized.
*
* @return the current value for the point to be plotted.
*/
public abstract int getValue();
/**
* Get the column name for the plotted point
*
* @return the plotted point's column name
*/
public String getColumnName() {
return this.name;
}
/**
* Called after the website graphs have been updated
*/
public void reset() {}
@Override
public int hashCode() {
return getColumnName().hashCode();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Plotter)) {
return false;
}
Plotter plotter = (Plotter) object;
return plotter.name.equals(this.name) && plotter.getValue() == getValue();
}
}
} catch (IOException ignored) {}
}
}

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

@ -26,9 +26,8 @@ import java.util.HashSet;
import java.util.Map.Entry;
/**
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
*
* An utility that can be used to send chunks, rather than using bukkit code
* to do so (uses heavy NMS).
*/
public class SendChunk {
@ -40,7 +39,7 @@ public class SendChunk {
private final RefMethod methodInitLighting;
/**
* Constructor
* Constructor.
*/
public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
RefConstructor tempMapChunk;
@ -51,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 {
@ -90,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();
@ -117,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;
@ -82,9 +84,10 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
if (blocksLayer != null) {
for (int j = 0; j < blocksLayer.length; j++) {
PlotBlock block = blocksLayer[j];
if (block != null) {
int x = MainUtil.x_loc[layer][j];
int y = MainUtil.y_loc[layer][j];
int z = MainUtil.y_loc[layer][j];
int z = MainUtil.z_loc[layer][j];
Block existing = chunk.getBlock(x, y, z);
int existingId = existing.getTypeId();
if (existingId == block.id) {
@ -100,6 +103,7 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
}
}
}
}
public void setBiomes(LocalChunk<T> lc) {
if (lc.biomes != null) {
@ -124,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,6 +115,7 @@ 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 != null) {
if (newBlock.id == -1) {
chunk.getBlock(x, y, z).setData(newBlock.data, false);
continue;
@ -120,6 +124,7 @@ public class BukkitLocalQueue_1_7 extends BukkitLocalQueue<PlotBlock[]> {
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;

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,33 +374,17 @@ 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();
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];
@ -461,6 +439,8 @@ public class BukkitLocalQueue_1_9 extends BukkitLocalQueue<char[]> {
}
}
}
}
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;
@ -80,8 +80,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
e.printStackTrace();
}
}
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
PS.debug("&aFast mode UUID caching enabled!");
File playerDataFolder = new File(container, world + File.separator + "playerdata");
@ -94,10 +94,9 @@ 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 does not contain the the key \"bukkit\"");
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
} else {
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
String name = (String) bukkit.get("lastKnownName");
@ -108,7 +107,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
toAdd.put(new StringWrapper(name), uuid);
}
}
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
}
@ -124,7 +123,6 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
PS.debug("Failed to cache: " + all.size() + " uuids - slowly processing all files");
}
}
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
HashSet<String> worlds = Sets.newHashSet(world, "world");
HashSet<UUID> uuids = new HashSet<>();
HashSet<String> names = new HashSet<>();
@ -161,13 +159,14 @@ 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 does not contain the the key \"bukkit\"");
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
} else {
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
String name = (String) bukkit.get("lastKnownName");
StringWrapper wrap = new StringWrapper(name);
if (!toAdd.containsKey(wrap)) {
long last = (long) bukkit.get("lastPlayed");
if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase().equals(name)) {
@ -181,7 +180,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
if (ExpireManager.IMP != null) {
ExpireManager.IMP.storeDate(uuid, last);
}
toAdd.put(new StringWrapper(name), uuid);
toAdd.put(wrap, uuid);
}
}
} catch (Exception ignored) {
PS.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
@ -199,6 +199,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
if (last != 0) {
String name = op.getName();
StringWrapper wrap = new StringWrapper(name);
if (!toAdd.containsKey(wrap)) {
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(op);
toAdd.put(wrap, uuid);
if (ExpireManager.IMP != null) {
@ -207,6 +208,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
}
}
}
}
add(toAdd);
if (whenDone != null) {
whenDone.run();

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());
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

@ -2,14 +2,14 @@ package com.intellectualcrafters.configuration;
/**
* Various settings for controlling the input and output of a {@link
* Configuration}
* Configuration}.
*/
class ConfigurationOptions {
private final Configuration configuration;
private char pathSeparator = '.';
private boolean copyDefaults = false;
protected ConfigurationOptions(final Configuration configuration) {
protected ConfigurationOptions(Configuration configuration) {
this.configuration = configuration;
}
@ -24,9 +24,9 @@ class ConfigurationOptions {
/**
* Gets the char that will be used to separate {@link
* ConfigurationSection}s
* <p>
* This value does not affect how the {@link Configuration} is stored,
* ConfigurationSection}s.
*
* <p>This value does not affect how the {@link Configuration} is stored,
* only in how you access the data. The default value is '.'.
*
* @return Path separator
@ -37,15 +37,15 @@ class ConfigurationOptions {
/**
* Sets the char that will be used to separate {@link
* ConfigurationSection}s
* <p>
* This value does not affect how the {@link Configuration} is stored,
* ConfigurationSection}s.
*
* <p>This value does not affect how the {@link Configuration} is stored,
* only in how you access the data. The default value is '.'.
*
* @param value Path separator
* @return This object, for chaining
*/
public ConfigurationOptions pathSeparator(final char value) {
public ConfigurationOptions pathSeparator(char value) {
pathSeparator = value;
return this;
}
@ -53,8 +53,8 @@ class ConfigurationOptions {
/**
* Checks if the {@link Configuration} should copy values from its default
* {@link Configuration} directly.
* <p>
* If this is true, all values in the default Configuration will be
*
* <p>If this is true, all values in the default Configuration will be
* directly copied, making it impossible to distinguish between values
* that were set and values that are provided by default. As a result,
* {@link ConfigurationSection#contains(String)} will always
@ -71,8 +71,8 @@ class ConfigurationOptions {
/**
* Sets if the {@link Configuration} should copy values from its default
* {@link Configuration} directly.
* <p>
* If this is true, all values in the default Configuration will be
*
* <p>If this is true, all values in the default Configuration will be
* directly copied, making it impossible to distinguish between values
* that were set and values that are provided by default. As a result,
* {@link ConfigurationSection#contains(String)} will always
@ -83,7 +83,7 @@ class ConfigurationOptions {
* @param value Whether or not defaults are directly copied
* @return This object, for chaining
*/
public ConfigurationOptions copyDefaults(final boolean value) {
public ConfigurationOptions copyDefaults(boolean value) {
copyDefaults = value;
return this;
}

View File

@ -5,18 +5,18 @@ import java.util.Map;
import java.util.Set;
/**
* Represents a section of a {@link Configuration}
* Represents a section of a {@link Configuration}.
*/
public interface ConfigurationSection {
/**
* Gets a set containing all keys in this section.
* <p>
* If deep is set to true, then this will contain all the keys within any
*
* <p>If deep is set to true, then this will contain all the keys within any
* child {@link ConfigurationSection}s (and their children, etc). These
* will be in a valid path notation for you to use.
* <p>
* If deep is set to false, then this will contain only the keys of any
*
* <p>If deep is set to false, then this will contain only the keys of any
* direct children, and not their own children.
*
* @param deep Whether or not to get a deep list, as opposed to a shallow
@ -27,12 +27,12 @@ public interface ConfigurationSection {
/**
* Gets a Map containing all keys and their values for this section.
* <p>
* If deep is set to true, then this will contain all the keys and values
*
* <p>If deep is set to true, then this will contain all the keys and values
* within any child {@link ConfigurationSection}s (and their children,
* etc). These keys will be in a valid path notation for you to use.
* <p>
* If deep is set to false, then this will contain only the keys and
*
* <p>If deep is set to false, then this will contain only the keys and
* values of any direct children, and not their own children.
*
* @param deep Whether or not to get a deep list, as opposed to a shallow
@ -43,43 +43,44 @@ public interface ConfigurationSection {
/**
* Checks if this {@link ConfigurationSection} contains the given path.
* <p>
* If the value for the requested path does not exist but a default value
*
* <p>If the value for the requested path does not exist but a default value
* has been specified, this will return true.
*
* @param path Path to check for existence.
* @return True if this section contains the requested path, either via
* default or being set.
* @throws IllegalArgumentException Thrown when path is null.
* @throws IllegalArgumentException Thrown when path is {@code null}.
*/
boolean contains(String path);
/**
* Checks if this {@link ConfigurationSection} has a value set for the
* given path.
* <p>
* If the value for the requested path does not exist but a default value
*
* <p>If the value for the requested path does not exist but a default value
* has been specified, this will still return false.
*
* @param path Path to check for existence.
* @return True if this section contains the requested path, regardless of
* having a default.
* @throws IllegalArgumentException Thrown when path is null.
* @throws IllegalArgumentException Thrown when path is {@code null}.
*/
boolean isSet(String path);
/**
* Gets the path of this {@link ConfigurationSection} from its root {@link
* Configuration}
* <p>
* For any {@link Configuration} themselves, this will return an empty
* Configuration}.
*
* <p>For any {@link Configuration} themselves, this will return an empty
* string.
* <p>
* If the section is no longer contained within its root for any reason,
* such as being replaced with a different value, this may return null.
* <p>
* To retrieve the single name of this section, that is, the final part of
* the path returned by this method, you may use {@link #getName()}.
*
* <p>If the section is no longer contained within its root for any reason,
* such as being replaced with a different value,
* this may return {@code null}.
*
* <p>To retrieve the single name of this section, that is, the final part
* of the path returned by this method, you may use {@link #getName()}.
*
* @return Path of this section relative to its root
*/
@ -88,8 +89,8 @@ public interface ConfigurationSection {
/**
* Gets the name of this individual {@link ConfigurationSection}, in the
* path.
* <p>
* This will always be the final part of {@link #getCurrentPath()}, unless
*
* <p>This will always be the final part of {@link #getCurrentPath()}, unless
* the section is orphaned.
*
* @return Name of this section
@ -99,12 +100,13 @@ public interface ConfigurationSection {
/**
* Gets the root {@link Configuration} that contains this {@link
* ConfigurationSection}
* <p>
* For any {@link Configuration} themselves, this will return its own
*
* <p>For any {@link Configuration} themselves, this will return its own
* object.
* <p>
* If the section is no longer contained within its root for any reason,
* such as being replaced with a different value, this may return null.
*
* <p>If the section is no longer contained within its root for any reason,
* such as being replaced with a different value,
* this may return {@code null}.
*
* @return Root configuration containing this section.
*/
@ -113,11 +115,13 @@ public interface ConfigurationSection {
/**
* Gets the parent {@link ConfigurationSection} that directly contains
* this {@link ConfigurationSection}.
* <p>
* For any {@link Configuration} themselves, this will return null.
* <p>
* If the section is no longer contained within its parent for any reason,
* such as being replaced with a different value, this may return null.
*
* <p>For any {@link Configuration} themselves, this will return
* {@code null}.
*
* <p>If the section is no longer contained within its parent for any
* reason, such as being replaced with a different value, this may
* return {@code null}.
*
* @return Parent section containing this section.
*/
@ -125,10 +129,10 @@ public interface ConfigurationSection {
/**
* Gets the requested Object by path.
* <p>
* If the Object does not exist but a default value has been specified,
*
* <p>If the Object does not exist but a default value has been specified,
* this will return the default value. If the Object does not exist and no
* default value was specified, this will return null.
* default value was specified, this will return {@code null}.
*
* @param path Path of the Object to get.
* @return Requested Object.
@ -138,8 +142,8 @@ public interface ConfigurationSection {
/**
* Gets the requested Object by path, returning a default value if not
* found.
* <p>
* If the Object does not exist then the specified default value will
*
* <p>If the Object does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.
*
@ -151,11 +155,11 @@ public interface ConfigurationSection {
/**
* Sets the specified path to the given value.
* <p>
* If value is null, the entry will be removed. Any existing entry will be
* replaced, regardless of what the new value is.
* <p>
* Some implementations may have limitations on what you may store. See
*
* <p>If value is {@code null}, the entry will be removed. Any
* existing entry will be replaced, regardless of what the new value is.
*
* <p>Some implementations may have limitations on what you may store. See
* their individual javadoc for details. No implementations should allow
* you to store {@link Configuration}s or {@link ConfigurationSection}s,
* please use {@link #createSection(String)} for that.
@ -167,8 +171,8 @@ public interface ConfigurationSection {
/**
* Creates an empty {@link ConfigurationSection} at the specified path.
* <p>
* Any value that was previously set at this path will be overwritten. If
*
* <p>Any value that was previously set at this path will be overwritten. If
* the previous value was itself a {@link ConfigurationSection}, it will
* be orphaned.
*
@ -180,8 +184,8 @@ public interface ConfigurationSection {
/**
* Creates a {@link ConfigurationSection} at the specified path, with
* specified values.
* <p>
* Any value that was previously set at this path will be overwritten. If
*
* <p>Any value that was previously set at this path will be overwritten. If
* the previous value was itself a {@link ConfigurationSection}, it will
* be orphaned.
*
@ -195,10 +199,10 @@ public interface ConfigurationSection {
/**
* Gets the requested String by path.
* <p>
* If the String does not exist but a default value has been specified,
*
* <p>If the String does not exist but a default value has been specified,
* this will return the default value. If the String does not exist and no
* default value was specified, this will return null.
* default value was specified, this will return {@code null}.
*
* @param path Path of the String to get.
* @return Requested String.
@ -208,8 +212,8 @@ public interface ConfigurationSection {
/**
* Gets the requested String by path, returning a default value if not
* found.
* <p>
* If the String does not exist then the specified default value will
*
* <p>If the String does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.
*
@ -223,10 +227,10 @@ public interface ConfigurationSection {
/**
* Checks if the specified path is a String.
*
* <p> If the path exists but is not a String, this will return false. If the
* path does not exist, this will return false. If the path does not exist
* but a default value has been specified, this will check if that default
* value is a String and return appropriately.</p>
* <p>If the path exists but is not a String, this will return false. If
* the path does not exist, this will return false. If the path does not
* exist but a default value has been specified, this will check if that
* defaultvalue is a String and return appropriately.
*
* @param path Path of the String to check.
* @return Whether or not the specified path is a String.
@ -238,7 +242,7 @@ public interface ConfigurationSection {
*
* <p>If the int does not exist but a default value has been specified, this
* will return the default value. If the int does not exist and no default
* value was specified, this will return 0.</p>
* value was specified, this will return 0.
*
* @param path Path of the int to get.
* @return Requested int.
@ -250,7 +254,7 @@ public interface ConfigurationSection {
*
* <p>If the int does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.</p>
* {@link Configuration}.
*
* @param path Path of the int to get.
* @param def The default value to return if the path is not found or is
@ -265,7 +269,7 @@ public interface ConfigurationSection {
* <p>If the path exists but is not a int, this will return false. If the
* path does not exist, this will return false. If the path does not exist
* but a default value has been specified, this will check if that default
* value is a int and return appropriately.</p>
* value is a int and return appropriately.
*
* @param path Path of the int to check.
* @return Whether or not the specified path is an int.
@ -274,8 +278,8 @@ public interface ConfigurationSection {
/**
* Gets the requested boolean by path.
* <p>
* If the boolean does not exist but a default value has been specified,
*
* <p>If the boolean does not exist but a default value has been specified,
* this will return the default value. If the boolean does not exist and
* no default value was specified, this will return false.
*
@ -287,8 +291,8 @@ public interface ConfigurationSection {
/**
* Gets the requested boolean by path, returning a default value if not
* found.
* <p>
* If the boolean does not exist then the specified default value will
*
* <p>If the boolean does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.
*
@ -301,8 +305,8 @@ public interface ConfigurationSection {
/**
* Checks if the specified path is a boolean.
* <p>
* If the path exists but is not a boolean, this will return false. If the
*
* <p>If the path exists but is not a boolean, this will return false. If the
* path does not exist, this will return false. If the path does not exist
* but a default value has been specified, this will check if that default
* value is a boolean and return appropriately.
@ -314,8 +318,8 @@ public interface ConfigurationSection {
/**
* Gets the requested double by path.
* <p>
* If the double does not exist but a default value has been specified,
*
* <p>If the double does not exist but a default value has been specified,
* this will return the default value. If the double does not exist and no
* default value was specified, this will return 0.
*
@ -327,8 +331,8 @@ public interface ConfigurationSection {
/**
* Gets the requested double by path, returning a default value if not
* found.
* <p>
* If the double does not exist then the specified default value will
*
* <p>If the double does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.
*
@ -341,8 +345,8 @@ public interface ConfigurationSection {
/**
* Checks if the specified path is a double.
* <p>
* If the path exists but is not a double, this will return false. If the
*
* <p>If the path exists but is not a double, this will return false. If the
* path does not exist, this will return false. If the path does not exist
* but a default value has been specified, this will check if that default
* value is a double and return appropriately.
@ -354,8 +358,8 @@ public interface ConfigurationSection {
/**
* Gets the requested long by path.
* <p>
* If the long does not exist but a default value has been specified, this
*
* <p>If the long does not exist but a default value has been specified, this
* will return the default value. If the long does not exist and no
* default value was specified, this will return 0.
*
@ -367,8 +371,8 @@ public interface ConfigurationSection {
/**
* Gets the requested long by path, returning a default value if not
* found.
* <p>
* If the long does not exist then the specified default value will
*
* <p>If the long does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.
*
@ -381,8 +385,8 @@ public interface ConfigurationSection {
/**
* Checks if the specified path is a long.
* <p>
* If the path exists but is not a long, this will return false. If the
*
* <p>If the path exists but is not a long, this will return false. If the
* path does not exist, this will return false. If the path does not exist
* but a default value has been specified, this will check if that default
* value is a long and return appropriately.
@ -396,8 +400,8 @@ public interface ConfigurationSection {
/**
* Gets the requested List by path.
* <p>
* If the List does not exist but a default value has been specified, this
*
* <p>If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
* default value was specified, this will return null.
*
@ -409,8 +413,8 @@ public interface ConfigurationSection {
/**
* Gets the requested List by path, returning a default value if not
* found.
* <p>
* If the List does not exist then the specified default value will
*
* <p>If the List does not exist then the specified default value will
* returned regardless of if a default has been identified in the root
* {@link Configuration}.
*
@ -423,8 +427,8 @@ public interface ConfigurationSection {
/**
* Checks if the specified path is a List.
* <p>
* If the path exists but is not a List, this will return false. If the
*
* <p>If the path exists but is not a List, this will return false. If the
* path does not exist, this will return false. If the path does not exist
* but a default value has been specified, this will check if that default
* value is a List and return appropriately.
@ -436,12 +440,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of String by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a String if possible,
*
* <p>This method will attempt to cast any values into a String if possible,
* but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
@ -451,13 +455,13 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Integer by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Integer if possible,
* but may miss any values out if they are not compatible.
*
* <p>This method will attempt to cast any values into a Integer if
* possible, but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
* @return Requested List of Integer.
@ -466,13 +470,13 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Boolean by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Boolean if possible,
* but may miss any values out if they are not compatible.
*
* <p>This method will attempt to cast any values into a Boolean if
* possible, but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
* @return Requested List of Boolean.
@ -481,12 +485,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Double by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Double if possible,
*
* <p>This method will attempt to cast any values into a Double if possible,
* but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
@ -496,12 +500,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Float by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Float if possible,
*
* <p>This method will attempt to cast any values into a Float if possible,
* but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
@ -511,12 +515,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Long by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Long if possible,
*
* <p>This method will attempt to cast any values into a Long if possible,
* but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
@ -526,12 +530,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Byte by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Byte if possible,
*
* <p>This method will attempt to cast any values into a Byte if possible,
* but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
@ -541,12 +545,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Character by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Character if
*
* <p>This method will attempt to cast any values into a Character if
* possible, but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
@ -556,13 +560,13 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Short by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Short if possible,
* but may miss any values out if they are not compatible.
*
* <p>This method will attempt to cast any values into a Short if
* possible, but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
* @return Requested List of Short.
@ -571,13 +575,12 @@ public interface ConfigurationSection {
/**
* Gets the requested List of Maps by path.
* <p>
* If the List does not exist but a default value has been specified, this
* will return the default value. If the List does not exist and no
*
* <p>If the List does not exist but a default value has been specified,
* this will return the default value. If the List does not exist and no
* default value was specified, this will return an empty List.
* <p>
* This method will attempt to cast any values into a Map if possible, but
* may miss any values out if they are not compatible.
* <p>This method will attempt to cast any values into a Map if possible,
* but may miss any values out if they are not compatible.
*
* @param path Path of the List to get.
* @return Requested List of Maps.
@ -586,11 +589,11 @@ public interface ConfigurationSection {
/**
* Gets the requested ConfigurationSection by path.
* <p>
* If the ConfigurationSection does not exist but a default value has been
* specified, this will return the default value. If the
*
* <p>If the ConfigurationSection does not exist but a default value has
* been specified, this will return the default value. If the
* ConfigurationSection does not exist and no default value was specified,
* this will return null.
* this will return {@code null}.
*
* @param path Path of the ConfigurationSection to get.
* @return Requested ConfigurationSection.
@ -599,8 +602,8 @@ public interface ConfigurationSection {
/**
* Checks if the specified path is a ConfigurationSection.
* <p>
* If the path exists but is not a ConfigurationSection, this will return
*
* <p>If the path exists but is not a ConfigurationSection, this will return
* false. If the path does not exist, this will return false. If the path
* does not exist but a default value has been specified, this will check
* if that default value is a ConfigurationSection and return
@ -614,10 +617,10 @@ public interface ConfigurationSection {
/**
* Gets the equivalent {@link ConfigurationSection} from the default
* {@link Configuration} defined in {@link #getRoot()}.
* <p>
* If the root contains no defaults, or the defaults doesn't contain a
*
* <p>If the root contains no defaults, or the defaults doesn't contain a
* value for this path, or the value at this path is not a {@link
* ConfigurationSection} then this will return null.
* ConfigurationSection} then this will return {@code null}.
*
* @return Equivalent section in root configuration
*/
@ -625,21 +628,21 @@ public interface ConfigurationSection {
/**
* Sets the default value in the root at the given path as provided.
* <p>
* If no source {@link Configuration} was provided as a default
*
* <p>If no source {@link Configuration} was provided as a default
* collection, then a new {@link MemoryConfiguration} will be created to
* hold the new default value.
* <p>
* If value is null, the value will be removed from the default
* Configuration source.
* <p>
* If the value as returned by {@link #getDefaultSection()} is null, then
* this will create a new section at the path, replacing anything that may
* have existed there previously.
*
* @param path Path of the value to set.
* @param value Value to set the default to.
* @throws IllegalArgumentException Thrown if path is null.
* <p>If value is {@code null}, the value will be removed from the
* default Configuration source.
*
* <p>If the value as returned by {@link #getDefaultSection()} is
* {@code null}, then this will create a new section at the path,
* replacing anything that may have existed there previously.
*
* @param path Path of the value to set
* @param value Value to set the default to
* @throws IllegalArgumentException Thrown if path is {@code null}
*/
void addDefault(String path, Object value);
}

View File

@ -1,7 +1,7 @@
package com.intellectualcrafters.configuration;
/**
* Exception thrown when attempting to load an invalid {@link Configuration}
* Exception thrown when attempting to load an invalid {@link Configuration}.
*/
@SuppressWarnings("serial")
public class InvalidConfigurationException extends Exception {
@ -18,7 +18,7 @@ public class InvalidConfigurationException extends Exception {
*
* @param msg The details of the exception.
*/
public InvalidConfigurationException(final String msg) {
public InvalidConfigurationException(String msg) {
super(msg);
}
@ -28,7 +28,7 @@ public class InvalidConfigurationException extends Exception {
*
* @param cause The cause of the exception.
*/
public InvalidConfigurationException(final Throwable cause) {
public InvalidConfigurationException(Throwable cause) {
super(cause);
}
@ -39,7 +39,7 @@ public class InvalidConfigurationException extends Exception {
* @param cause The cause of the exception.
* @param msg The details of the exception.
*/
public InvalidConfigurationException(final String msg, final Throwable cause) {
public InvalidConfigurationException(String msg, Throwable cause) {
super(msg, cause);
}
}

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

@ -2,10 +2,10 @@ package com.intellectualcrafters.configuration;
/**
* Various settings for controlling the input and output of a {@link
* MemoryConfiguration}
* MemoryConfiguration}.
*/
public class MemoryConfigurationOptions extends ConfigurationOptions {
protected MemoryConfigurationOptions(final MemoryConfiguration configuration) {
protected MemoryConfigurationOptions(MemoryConfiguration configuration) {
super(configuration);
}
@ -15,13 +15,13 @@ public class MemoryConfigurationOptions extends ConfigurationOptions {
}
@Override
public MemoryConfigurationOptions copyDefaults(final boolean value) {
public MemoryConfigurationOptions copyDefaults(boolean value) {
super.copyDefaults(value);
return this;
}
@Override
public MemoryConfigurationOptions pathSeparator(final char value) {
public MemoryConfigurationOptions pathSeparator(char value) {
super.pathSeparator(value);
return this;
}

View File

@ -21,8 +21,8 @@ public class MemorySection implements ConfigurationSection {
/**
* Creates an empty MemorySection for use as a root {@link Configuration}
* section.
* <p>
* Note that calling this without being yourself a {@link Configuration}
*
* <p>Note that calling this without being yourself a {@link Configuration}
* will throw an exception!
*
* @throws IllegalStateException Thrown if this is not a {@link
@ -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();
@ -74,7 +67,8 @@ public class MemorySection implements ConfigurationSection {
if (obj instanceof String) {
try {
return Double.parseDouble((String) obj);
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (obj instanceof List) {
List<?> val = (List<?>) obj;
if (!val.isEmpty()) {
@ -91,7 +85,8 @@ public class MemorySection implements ConfigurationSection {
if (obj instanceof String) {
try {
return Integer.parseInt((String) obj);
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (obj instanceof List) {
List<?> val = (List<?>) obj;
if (!val.isEmpty()) {
@ -108,7 +103,8 @@ public class MemorySection implements ConfigurationSection {
if (obj instanceof String) {
try {
return Long.parseLong((String) obj);
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (obj instanceof List) {
List<?> val = (List<?>) obj;
if (!val.isEmpty()) {
@ -121,8 +117,8 @@ public class MemorySection implements ConfigurationSection {
/**
* Creates a full path to the given {@link ConfigurationSection} from its
* root {@link Configuration}.
* <p>
* You may use this method for any given {@link ConfigurationSection}, not
*
* <p>You may use this method for any given {@link ConfigurationSection}, not
* only {@link MemorySection}.
*
* @param section Section to create a path for.
@ -130,14 +126,14 @@ 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());
}
/**
* Creates a relative path to the given {@link ConfigurationSection} from
* the given relative section.
* <p>
* You may use this method for any given {@link ConfigurationSection}, not
*
* <p>You may use this method for any given {@link ConfigurationSection}, not
* only {@link MemorySection}.
*
* @param section Section to create a path for.
@ -146,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");
@ -250,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");
@ -280,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");
@ -292,7 +277,8 @@ public class MemorySection implements ConfigurationSection {
char separator = root.options().pathSeparator();
// i1 is the leading (higher) index
// i2 is the trailing (lower) index
int i1 = -1, i2;
int i1 = -1;
int i2;
ConfigurationSection section = this;
while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
String node = path.substring(i2, i1);
@ -363,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");
@ -374,7 +357,8 @@ public class MemorySection implements ConfigurationSection {
char separator = root.options().pathSeparator();
// i1 is the leading (higher) index
// i2 is the trailing (lower) index
int i1 = -1, i2;
int i1 = -1;
int i2;
ConfigurationSection section = this;
while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
String node = path.substring(i2, i1);
@ -563,7 +547,8 @@ public class MemorySection implements ConfigurationSection {
} else if (object instanceof String) {
try {
result.add(Integer.valueOf((String) object));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (object instanceof Character) {
result.add((int) (Character) object);
} else if (object instanceof Number) {
@ -607,7 +592,8 @@ public class MemorySection implements ConfigurationSection {
} else if (object instanceof String) {
try {
result.add(Double.valueOf((String) object));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (object instanceof Character) {
result.add((double) (Character) object);
} else if (object instanceof Number) {
@ -630,7 +616,8 @@ public class MemorySection implements ConfigurationSection {
} else if (object instanceof String) {
try {
result.add(Float.valueOf((String) object));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (object instanceof Character) {
result.add((float) (Character) object);
} else if (object instanceof Number) {
@ -653,7 +640,8 @@ public class MemorySection implements ConfigurationSection {
} else if (object instanceof String) {
try {
result.add(Long.valueOf((String) object));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (object instanceof Character) {
result.add((long) (Character) object);
} else if (object instanceof Number) {
@ -676,7 +664,8 @@ public class MemorySection implements ConfigurationSection {
} else if (object instanceof String) {
try {
result.add(Byte.valueOf((String) object));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (object instanceof Character) {
result.add((byte) ((Character) object).charValue());
} else if (object instanceof Number) {
@ -722,7 +711,8 @@ public class MemorySection implements ConfigurationSection {
} else if (object instanceof String) {
try {
result.add(Short.valueOf((String) object));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
} else if (object instanceof Character) {
result.add((short) ((Character) object).charValue());
} else if (object instanceof Number) {
@ -776,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));
@ -831,7 +817,10 @@ public class MemorySection implements ConfigurationSection {
@Override
public String toString() {
Configuration root = getRoot();
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + (root == null ? null : root.getClass().getSimpleName()) +
"']";
if (root == null) {
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + null + "']";
} else {
return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + root.getClass().getSimpleName() + "']";
}
}
}

View File

@ -18,7 +18,7 @@ import java.nio.charset.StandardCharsets;
/**
* This is a base class for all File based implementations of {@link
* Configuration}
* Configuration}.
*/
public abstract class FileConfiguration extends MemoryConfiguration {
@ -39,21 +39,23 @@ public abstract class FileConfiguration extends MemoryConfiguration {
/**
* Saves this {@link FileConfiguration} to the specified location.
* <p>
* If the file does not exist, it will be created. If already exists, it
*
* <p>If the file does not exist, it will be created. If already exists, it
* will be overwritten. If it cannot be overwritten or created, an
* exception will be thrown.
* <p>
* This method will save using the system default encoding, or possibly
*
* <p>This method will save using the system default encoding, or possibly
* using UTF8.
*
* @param file File to save to.
* @throws IOException Thrown when the given file cannot be written to for
* any reason.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void save(File file) throws IOException {
file.getParentFile().mkdirs();
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
String data = saveToString();
@ -71,14 +73,13 @@ public abstract class FileConfiguration extends MemoryConfiguration {
/**
* Loads this {@link FileConfiguration} from the specified location.
* <p>
* All the values contained within this configuration will be removed,
*
* <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
*
* <p>If the file cannot be loaded for any reason, an exception will be
* thrown.
* <p>
*
* @param file File to load from.
* @throws FileNotFoundException Thrown when the given file cannot be
@ -89,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);
@ -100,8 +98,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
/**
* Loads this {@link FileConfiguration} from the specified reader.
* <p>
* All the values contained within this configuration will be removed,
*
* <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 stream.
*
@ -109,7 +107,6 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IOException thrown when underlying reader throws an IOException
* @throws InvalidConfigurationException thrown when the reader does not
* represent a valid Configuration
* @throws IllegalArgumentException thrown when reader is null
*/
public void load(Reader reader) throws IOException, InvalidConfigurationException {
@ -127,54 +124,27 @@ 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.
* <p>
* All the values contained within this configuration will be removed,
*
* <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 string.
* <p>
* If the string is invalid in any way, an exception will be thrown.
*
* <p>If the string is invalid in any way, an exception will be thrown.
*
* @param contents Contents of a Configuration to load.
* @throws InvalidConfigurationException Thrown if the specified string is
* invalid.
* @throws IllegalArgumentException Thrown if contents is null.
*/
public abstract void loadFromString(String contents) throws InvalidConfigurationException;
/**
* Compiles the header for this {@link FileConfiguration} and returns the
* result.
* <p>
* This will use the header from {@link #options()} -> {@link
*
* <p>This will use the header from {@link #options()} -> {@link
* FileConfigurationOptions#header()}, respecting the rules of {@link
* FileConfigurationOptions#copyHeader()} if set.
*

View File

@ -6,13 +6,13 @@ import com.intellectualcrafters.configuration.MemoryConfigurationOptions;
/**
* Various settings for controlling the input and output of a {@link
* FileConfiguration}
* FileConfiguration}.
*/
public class FileConfigurationOptions extends MemoryConfigurationOptions {
private String header = null;
private boolean copyHeader = true;
protected FileConfigurationOptions(final MemoryConfiguration configuration) {
protected FileConfigurationOptions(MemoryConfiguration configuration) {
super(configuration);
}
@ -22,28 +22,28 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
}
@Override
public FileConfigurationOptions copyDefaults(final boolean value) {
public FileConfigurationOptions copyDefaults(boolean value) {
super.copyDefaults(value);
return this;
}
@Override
public FileConfigurationOptions pathSeparator(final char value) {
public FileConfigurationOptions pathSeparator(char value) {
super.pathSeparator(value);
return this;
}
/**
* Gets the header that will be applied to the top of the saved output.
* <p>
* This header will be commented out and applied directly at the top of
*
* <p>This header will be commented out and applied directly at the top of
* the generated output of the {@link FileConfiguration}. It is not
* required to include a newline at the end of the header as it will
* automatically be applied, but you may include one if you wish for extra
* spacing.
* <p>
* Null is a valid value which will indicate that no header is to be
* applied. The default value is null.
*
* <p>{@code null} is a valid value which will indicate that no header]
* is to be applied. The default value is {@code null}.
*
* @return Header
*/
@ -53,39 +53,38 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
/**
* Sets the header that will be applied to the top of the saved output.
* <p>
* This header will be commented out and applied directly at the top of
*
* <p>This header will be commented out and applied directly at the top of
* the generated output of the {@link FileConfiguration}. It is not
* required to include a newline at the end of the header as it will
* automatically be applied, but you may include one if you wish for extra
* spacing.
* <p>
* Null is a valid value which will indicate that no header is to be
* applied.
*
* <p>{@code null} is a valid value which will indicate that no header
* is to be applied.
*
* @param value New header
* @return This object, for chaining
*/
public FileConfigurationOptions header(final String value) {
public FileConfigurationOptions header(String value) {
header = value;
return this;
}
/**
* Gets whether or not the header should be copied from a default source.
* <p>
* If this is true, if a default {@link FileConfiguration} is passed to
* {@link
* FileConfiguration#setDefaults(Configuration)}
*
* <p>If this is true, if a default {@link FileConfiguration} is passed to
* {@link FileConfiguration#setDefaults(Configuration)}
* then upon saving it will use the header from that config, instead of
* the one provided here.
* <p>
* If no default is set on the configuration, or the default is not of
*
* <p>If no default is set on the configuration, or the default is not of
* type FileConfiguration, or that config has no header ({@link #header()}
* returns null) then the header specified in this configuration will be
* used.
* <p>
* Defaults to true.
*
* <p>Defaults to true.
*
* @return Whether or not to copy the header
*/
@ -95,24 +94,23 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
/**
* Sets whether or not the header should be copied from a default source.
* <p>
* If this is true, if a default {@link FileConfiguration} is passed to
* {@link
* FileConfiguration#setDefaults(Configuration)}
*
* <p>If this is true, if a default {@link FileConfiguration} is passed to
* {@link FileConfiguration#setDefaults(Configuration)}
* then upon saving it will use the header from that config, instead of
* the one provided here.
* <p>
* If no default is set on the configuration, or the default is not of
*
* <p>If no default is set on the configuration, or the default is not of
* type FileConfiguration, or that config has no header ({@link #header()}
* returns null) then the header specified in this configuration will be
* used.
* <p>
* Defaults to true.
*
* <p>Defaults to true.
*
* @param value Whether or not to copy the header
* @return This object, for chaining
*/
public FileConfigurationOptions copyHeader(final boolean value) {
public FileConfigurationOptions copyHeader(boolean value) {
copyHeader = value;
return this;

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;
@ -29,23 +28,18 @@ public class YamlConfiguration extends FileConfiguration {
/**
* Creates a new {@link YamlConfiguration}, loading from the given file.
* <p>
* Any errors loading the Configuration will be logged and then ignored.
*
* <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.
* <p>
* The encoding used may follow the system dependent default.
*
* <p>The encoding used may follow the system dependent default.
*
* @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");
}
final YamlConfiguration config = new YamlConfiguration();
YamlConfiguration config = new YamlConfiguration();
try {
config.load(file);
@ -62,7 +56,7 @@ public class YamlConfiguration extends FileConfiguration {
PS.debug("&c============ Full stacktrace ============");
ex.printStackTrace();
PS.debug("&c=========================================");
} catch (final IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
@ -70,41 +64,13 @@ 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(final Reader reader) {
if (reader == null) {
throw new NullPointerException("Reader cannot be null");
}
final YamlConfiguration config = new YamlConfiguration();
try {
config.load(reader);
} catch (final IOException | InvalidConfigurationException ex) {
PS.debug("Cannot load configuration from stream");
ex.printStackTrace();
}
return config;
}
@Override
public String saveToString() {
yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final String header = buildHeader();
String header = buildHeader();
String dump = yaml.dump(getValues(false));
if (dump.equals(BLANK_CONFIG)) {
@ -115,21 +81,18 @@ public class YamlConfiguration extends FileConfiguration {
}
@Override
public void loadFromString(final String contents) throws InvalidConfigurationException {
if (contents == null) {
throw new NullPointerException("Contents cannot be null");
}
public void loadFromString(String contents) throws InvalidConfigurationException {
Map<?, ?> input;
try {
input = (Map<?, ?>) yaml.load(contents);
} catch (final YAMLException e) {
} catch (YAMLException e) {
throw new InvalidConfigurationException(e);
} catch (final ClassCastException ignored) {
} catch (ClassCastException ignored) {
throw new InvalidConfigurationException("Top level is not a Map.");
}
final String header = parseHeader(contents);
String header = parseHeader(contents);
if (!header.isEmpty()) {
options().header(header);
}
@ -139,10 +102,10 @@ public class YamlConfiguration extends FileConfiguration {
}
}
protected void convertMapsToSections(final Map<?, ?> input, final ConfigurationSection section) {
for (final Map.Entry<?, ?> entry : input.entrySet()) {
final String key = entry.getKey().toString();
final Object value = entry.getValue();
protected void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
for (Map.Entry<?, ?> entry : input.entrySet()) {
String key = entry.getKey().toString();
Object value = entry.getValue();
if (value instanceof Map) {
convertMapsToSections((Map<?, ?>) value, section.createSection(key));
@ -152,14 +115,14 @@ public class YamlConfiguration extends FileConfiguration {
}
}
protected String parseHeader(final String input) {
final String[] lines = input.split("\r?\n", -1);
final StringBuilder result = new StringBuilder();
protected String parseHeader(String input) {
String[] lines = input.split("\r?\n", -1);
StringBuilder result = new StringBuilder();
boolean readingHeader = true;
boolean foundHeader = false;
for (int i = 0; (i < lines.length) && readingHeader; i++) {
final String line = lines[i];
String line = lines[i];
if (line.startsWith(COMMENT_PREFIX)) {
if (i > 0) {
@ -183,14 +146,14 @@ public class YamlConfiguration extends FileConfiguration {
@Override
protected String buildHeader() {
final String header = options().header();
String header = options().header();
if (options().copyHeader()) {
final Configuration def = getDefaults();
Configuration def = getDefaults();
if (def instanceof FileConfiguration) {
final FileConfiguration fileDefaults = (FileConfiguration) def;
final String defaultsHeader = fileDefaults.buildHeader();
FileConfiguration fileDefaults = (FileConfiguration) def;
String defaultsHeader = fileDefaults.buildHeader();
if ((defaultsHeader != null) && !defaultsHeader.isEmpty()) {
return defaultsHeader;
@ -202,8 +165,8 @@ public class YamlConfiguration extends FileConfiguration {
return "";
}
final StringBuilder builder = new StringBuilder();
final String[] lines = header.split("\r?\n", -1);
StringBuilder builder = new StringBuilder();
String[] lines = header.split("\r?\n", -1);
boolean startedHeader = false;
for (int i = lines.length - 1; i >= 0; i--) {

View File

@ -2,12 +2,12 @@ package com.intellectualcrafters.configuration.file;
/**
* Various settings for controlling the input and output of a {@link
* YamlConfiguration}
* YamlConfiguration}.
*/
public class YamlConfigurationOptions extends FileConfigurationOptions {
private int indent = 2;
YamlConfigurationOptions(final YamlConfiguration configuration) {
YamlConfigurationOptions(YamlConfiguration configuration) {
super(configuration);
}
@ -17,33 +17,33 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
}
@Override
public YamlConfigurationOptions copyDefaults(final boolean value) {
public YamlConfigurationOptions copyDefaults(boolean value) {
super.copyDefaults(value);
return this;
}
@Override
public YamlConfigurationOptions pathSeparator(final char value) {
public YamlConfigurationOptions pathSeparator(char value) {
super.pathSeparator(value);
return this;
}
@Override
public YamlConfigurationOptions header(final String value) {
public YamlConfigurationOptions header(String value) {
super.header(value);
return this;
}
@Override
public YamlConfigurationOptions copyHeader(final boolean value) {
public YamlConfigurationOptions copyHeader(boolean value) {
super.copyHeader(value);
return this;
}
/**
* Gets how much spaces should be used to indent each line.
* <p>
* The minimum value this may be is 2, and the maximum is 9.
*
* <p>The minimum value this may be is 2, and the maximum is 9.
*
* @return How much to indent by
*/
@ -53,13 +53,13 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
/**
* Sets how much spaces should be used to indent each line.
* <p>
* The minimum value this may be is 2, and the maximum is 9.
*
* <p>The minimum value this may be is 2, and the maximum is 9.
*
* @param value New indent
* @return This object, for chaining
*/
public YamlConfigurationOptions indent(final int value) {
public YamlConfigurationOptions indent(int value) {
if (value < 2) {
throw new IllegalArgumentException("Indent must be at least 2 characters");
}

View File

@ -11,7 +11,7 @@ import java.util.Map;
class YamlRepresenter extends Representer {
public YamlRepresenter() {
YamlRepresenter() {
this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
}

View File

@ -4,9 +4,8 @@ import java.util.Map;
/**
* Represents an object that may be serialized.
* <p>
* These objects MUST implement one of the following, in addition to the
* methods as defined by this interface:
* <p>These objects MUST implement one of the following, in addition to
* the methods as defined by this interface:
* <ul>
* <li>A static method "deserialize" that accepts a single {@link Map}&lt;
* {@link String}, {@link Object}> and returns the class.</li>
@ -25,8 +24,8 @@ public interface ConfigurationSerializable {
/**
* Creates a Map representation of this class.
* <p>
* This class must provide a method to restore this class, as defined in
*
* <p>This class must provide a method to restore this class, as defined in
* the {@link ConfigurationSerializable} interface javadoc.
*
* @return Map containing the current state of this class

View File

@ -7,10 +7,11 @@ import java.io.OutputStream;
import java.util.List;
/**
* <p> This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong> <code>Tag</code> objects to an
* underlying <code>OutputStream</code>. </p> <p> The NBT format was created by Markus Persson, and the
* specification may be found at
* @linktourl http://www.minecraft.net/docs/NBT.txt
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* {@code Tag} objects to an underlying {@code OutputStream}.
*
* <p> The NBT format was created by Markus Persson, and the specification may
* be found at @linktourl http://www.minecraft.net/docs/NBT.txt
* </p>
*
* @author Graham Edgecombe
@ -23,7 +24,8 @@ public final class NBTOutputStream implements Closeable {
private final DataOutputStream os;
/**
* Creates a new <code>NBTOutputStream</code>, which will write data to the specified underlying output stream.
* Creates a new {@code NBTOutputStream}, which will write data to the
* specified underlying output stream.
*
* @param os The output stream.
*
@ -105,7 +107,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Byte</code> tag.
* Writes a {@code TAG_Byte} tag.
*
* @param tag The tag.
*
@ -116,7 +118,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Byte_Array</code> tag.
* Writes a {@code TAG_Byte_Array} tag.
*
* @param tag The tag.
*
@ -129,7 +131,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Compound</code> tag.
* Writes a {@code TAG_Compound} tag.
*
* @param tag The tag.
*
@ -143,7 +145,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_List</code> tag.
* Writes a {@code TAG_List} tag.
*
* @param tag The tag.
*
@ -161,7 +163,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_String</code> tag.
* Writes a {@code TAG_String} tag.
*
* @param tag The tag.
*
@ -174,7 +176,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Double</code> tag.
* Writes a {@code TAG_Double} tag.
*
* @param tag The tag.
*
@ -185,7 +187,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Float</code> tag.
* Writes a {@code TAG_Float} tag.
*
* @param tag The tag.
*
@ -196,7 +198,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Long</code> tag.
* Writes a {@code TAG_Long} tag.
*
* @param tag The tag.
*
@ -207,7 +209,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Int</code> tag.
* Writes a {@code TAG_Int} tag.
*
* @param tag The tag.
*
@ -218,7 +220,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Short</code> tag.
* Writes a {@code TAG_Short} tag.
*
* @param tag The tag.
*
@ -229,7 +231,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Writes a <code>TAG_Empty</code> tag.
* Writes a {@code TAG_Empty} tag.
*
* @param tag The tag.
*/
@ -251,7 +253,7 @@ public final class NBTOutputStream implements Closeable {
}
/**
* Flush output
* Flush output.
* @throws IOException
*/
public void flush() throws IOException {

View File

@ -107,9 +107,9 @@ public class Cookie {
}
/**
* Convert <code>%</code><i>hh</i> sequences to single characters, and convert plus to space.
* Convert {@code %}<i>hh</i> sequences to single characters, and convert plus to space.
*
* @param string A string that may contain <code>+</code> &nbsp;<small>(plus)</small> and <code>%</code><i>hh</i>
* @param string A string that may contain {@code +} &nbsp;<small>(plus)</small> and <code>%</code><i>hh</i>
* sequences.
*
* @return The unescaped string.

View File

@ -10,28 +10,28 @@ import java.util.Map;
/**
* A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with
* commas separating the values. The internal form is an object having <code>get</code> and <code>opt</code> methods for
* accessing the values by index, and <code>put</code> methods for adding or replacing values. The values can be any of
* these types: <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>,
* <code>String</code>, or the <code>JSONObject.NULL object</code>.
* commas separating the values. The internal form is an object having {@code get} and {@code opt} methods for
* accessing the values by index, and {@code put} methods for adding or replacing values. The values can be any of
* these types: {@code Boolean}, {@code JSONArray}, {@code JSONObject}, {@code Number},
* {@code String}, or the {@code JSONObject.NULL object}.
*
* The constructor can convert a JSON text into a Java object. The <code>toString</code> method converts to JSON text.
* <p>The constructor can convert a JSON text into a Java object. The {@code toString} method converts to JSON text.
*
* A <code>get</code> method returns a value if one can be found, and throws an exception if one cannot be found. An
* <code>opt</code> method returns a default value instead of throwing an exception, and so is useful for obtaining
* <p>A {@code get} method returns a value if one can be found, and throws an exception if one cannot be found. An
* {@code opt} method returns a default value instead of throwing an exception, and so is useful for obtaining
* optional values.
*
* The generic <code>get()</code> and <code>opt()</code> methods return an object which you can cast or query for type.
* There are also typed <code>get</code> and <code>opt</code> methods that do type checking and type coercion for you.
* <p>The generic {@code get()} and {@code opt()} methods return an object which you can cast or query for type.
* There are also typed {@code get} and {@code opt} methods that do type checking and type coercion for you.
*
* The texts produced by the <code>toString</code> methods strictly conform to JSON syntax rules. The constructors are
* more forgiving in the texts they will accept: <ul> <li>An extra <code>,</code>&nbsp;<small>(comma)</small> may appear
* just before the closing bracket.</li> <li>The <code>null</code> value will be inserted when there is <code>,</code>
* &nbsp;<small>(comma)</small> elision.</li> <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single
* <p>The texts produced by the {@code toString} methods strictly conform to JSON syntax rules. The constructors are
* more forgiving in the texts they will accept: <ul> <li>An extra {@code ,}&nbsp;<small>(comma)</small> may appear
* just before the closing bracket.</li> <li>The {@code null} value will be inserted when there is {@code ,}
* &nbsp;<small>(comma)</small> elision.</li> <li>Strings may be quoted with {@code '}&nbsp;<small>(single
* quote)</small>.</li> <li>Strings do not need to be quoted at all if they do not begin with a quote or single quote,
* and if they do not contain leading or trailing spaces, and if they do not contain any of these characters: <code>{ }
* [ ] / \ : , #</code> and if they do not look like numbers and if they are not the reserved words <code>true</code>,
* <code>false</code>, or <code>null</code>.</li> </ul>
* and if they do not contain leading or trailing spaces, and if they do not contain any of these characters: {@code { }
* [ ] / \ : , #} and if they do not look like numbers and if they are not the reserved words {@code true},
* {@code false}, or {@code null}.</li> </ul>
*
* @author JSON.org
* @version 2014-05-03
@ -90,8 +90,8 @@ public class JSONArray {
/**
* Construct a JSONArray from a source JSON text.
*
* @param source A string that begins with <code>[</code>&nbsp;<small>(left bracket)</small> and ends with
* <code>]</code> &nbsp;<small>(right bracket)</small>.
* @param source A string that begins with {@code [}&nbsp;<small>(left bracket)</small> and ends with
* {@code ]} &nbsp;<small>(right bracket)</small>.
*
* @throws JSONException If there is a syntax error.
*/
@ -283,7 +283,7 @@ public class JSONArray {
}
/**
* Make a string from the contents of this JSONArray. The <code>separator</code> string is inserted between each
* Make a string from the contents of this JSONArray. The {@code separator} string is inserted between each
* element. Warning: This method assumes that the data structure is acyclical.
*
* @param separator A string that will be inserted between the elements.
@ -449,8 +449,9 @@ public class JSONArray {
}
/**
* Get the optional long value associated with an index. The defaultValue is returned if there is no value for the
* index, or if the value is not a number and cannot be converted to a number.
* Get the optional long value associated with an index. The defaultValue
* is returned if there is no value for the index, or if the value is not a
* number and cannot be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
@ -466,8 +467,9 @@ public class JSONArray {
}
/**
* Get the optional string value associated with an index. It returns an empty string if there is no value at that
* index. If the value is not a string and is not null, then it is converted to a string.
* Get the optional string value associated with an index. It returns an
* empty string if there is no value at that index. If the value is not a
* string and is not null, then it is converted to a string.
*
* @param index The index must be between 0 and length() - 1.
*
@ -478,7 +480,8 @@ public class JSONArray {
}
/**
* Get the optional string associated with an index. The defaultValue is returned if the key is not found.
* Get the optional string associated with an index. The defaultValue is
* returned if the key is not found.
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
@ -503,7 +506,8 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
* Put a value in the JSONArray, where the value will be a JSONArray which
* is produced from a Collection.
*
* @param value A Collection value.
*
@ -555,7 +559,8 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONObject which is produced from a Map.
* Put a value in the JSONArray, where the value will be a JSONObject which
* is produced from a Map.
*
* @param value A Map value.
*
@ -569,8 +574,8 @@ public class JSONArray {
/**
* Append an object value. This increases the array's length by one.
*
* @param value An object value. The value should be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or
* String, or the JSONObject.NULL object.
* @param value An object value. The value should be a Boolean, Double,
* Integer, JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
*
* @return this.
*/
@ -596,14 +601,16 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
* Put a value in the JSONArray, where the value will be a JSONArray which
* is produced from a Collection.
*
* @param index The subscript.
* @param value A Collection value.
*
* @return this.
*
* @throws JSONException If the index is negative or if the value is not finite.
* @throws JSONException If the index is negative or if the value is not
* finite.
*/
public JSONArray put(int index, Collection<Object> value) throws JSONException {
this.put(index, new JSONArray(value));
@ -611,15 +618,17 @@ public class JSONArray {
}
/**
* Put or replace a double value. If the index is greater than the length of the JSONArray, then null elements will
* be added as necessary to pad it out.
* Put or replace a double value. If the index is greater than the length
* of the JSONArray, then null elements will be added as necessary to pad
* it out.
*
* @param index The subscript.
* @param value A double value.
*
* @return this.
*
* @throws JSONException If the index is negative or if the value is not finite.
* @throws JSONException If the index is negative or if the value is not
* finite.
*/
public JSONArray put(int index, double value) throws JSONException {
this.put(index, new Double(value));
@ -659,14 +668,16 @@ public class JSONArray {
}
/**
* Put a value in the JSONArray, where the value will be a JSONObject that is produced from a Map.
* Put a value in the JSONArray, where the value will be a JSONObject that
* is produced from a Map.
*
* @param index The subscript.
* @param value The Map value.
*
* @return this.
*
* @throws JSONException If the index is negative or if the the value is an invalid number.
* @throws JSONException If the index is negative or if the the value is an
* invalid number.
*/
public JSONArray put(int index, Map<String, Object> value) throws JSONException {
this.put(index, new JSONObject(value));
@ -790,7 +801,7 @@ public class JSONArray {
* @param indentFactor The number of spaces to add to each level of indentation.
*
* @return a printable, displayable, transmittable representation of the object, beginning with
* <code>[</code>&nbsp;<small>(left bracket)</small> and ending with <code>]</code> &nbsp;<small>(right
* {@code [}&nbsp;<small>(left bracket)</small> and ending with {@code ]} &nbsp;<small>(right
* bracket)</small>.
*
* @throws JSONException

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

@ -17,6 +17,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.block.QueueProvider;
import java.io.File;
import java.util.List;
@ -51,17 +52,29 @@ public interface IPlotMain extends ILogger {
* Disable the implementation.
*
* <ul>
* <li>If a full disable isn't feasibly, just disable what it can.</li>
* <li>If a full disable isn't feasibly, just disable what it can.
* </ul>
*/
void disable();
/**
* Get the version of the PlotSquared being used.
* @return
* @return the plugin version
*/
int[] getPluginVersion();
/**
* Get the version of the PlotSquared being used as a string.
* @return the plugin version as a string
*/
String getPluginVersionString();
/**
* Usually PlotSquared
* @return
*/
String getPluginName();
/**
* Get the version of Minecraft that is running.
* @return
@ -215,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
@ -230,10 +243,10 @@ public interface IPlotMain extends ILogger {
void registerWorldEvents();
/**
* Get the name of the server.
* @return The server name
* Usually HybridGen
* @return Default implementation generator
*/
String getServerName();
IndependentPlotGenerator getDefaultGenerator();
/**
* Get the class that will manage player titles.

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;
@ -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();
@ -171,14 +172,13 @@ public class PS {
this.IMP.registerPlayerEvents();
this.IMP.registerInventoryEvents();
this.IMP.registerPlotPlusEvents();
this.IMP.registerForceFieldEvents();
}
// Required
this.IMP.registerWorldEvents();
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();
@ -222,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) {
@ -246,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:
@ -281,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);
}
@ -306,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()));
}
/**
@ -320,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.
*
@ -327,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));
}
@ -351,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
@ -370,13 +386,16 @@ public class PS {
@Override
public void run() {
UUIDHandler.add(new StringWrapper("*"), DBFunc.everyone);
for (Plot plot : getPlots()) {
foreachPlotRaw(new RunnableVal<Plot>() {
@Override
public void run(Plot plot) {
if (plot.hasOwner() && plot.temp != -1) {
if (UUIDHandler.getName(plot.owner) == null) {
UUIDHandler.implementation.unknown.add(plot.owner);
}
}
}
});
startExpiryTasks();
startPlotMeConversion();
}
@ -398,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()) {
@ -406,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);
});
}
}
@ -429,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;
}
@ -452,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) {
@ -709,23 +524,8 @@ 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();
}
/**
@ -734,24 +534,17 @@ 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)) {
if (area.worldname.equals(world)) {
removePlotArea(area);
}
}
}
private void setPlotsTmp(PlotArea area) {
if (this.plots_tmp == null) {
@ -1013,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;
@ -1032,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) {
@ -1077,14 +870,15 @@ public class PS {
public void run(PlotArea value) {
for (PlotFilter filter : filters) {
if (!filter.allowsArea(value)) {
continue;
return;
}
}
loop:
for (Entry<PlotId, Plot> entry2 : value.getPlotEntries()) {
Plot plot = entry2.getValue();
for (PlotFilter filter : filters) {
if (!filter.allowsPlot(plot)) {
continue;
continue loop;
}
}
set.add(plot);
@ -1220,7 +1014,7 @@ public class PS {
*/
@Deprecated
public boolean isPlotWorld(String world) {
return this.plotAreaMap.containsKey(world);
return hasPlotArea(world);
}
/**
@ -1230,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) {
@ -1382,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);
@ -1400,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;
}
@ -1445,19 +1215,18 @@ public class PS {
// Now add it
addPlotArea(plotArea);
plotGenerator.initialize(plotArea);
plotArea.setupBorder();
} else {
if (!worlds.contains(world)) {
return;
}
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) {
@ -1523,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);
@ -1557,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);
@ -1692,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();
@ -1705,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");
}
@ -1714,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();
@ -1778,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());
@ -1808,6 +1579,7 @@ public class PS {
DBFunc.close();
UUIDHandler.handleShutdown();
} catch (NullPointerException ignored) {
ignored.printStackTrace();
PS.log("&cCould not close database connection!");
}
}
@ -1834,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.");
@ -1845,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();
}
}
@ -1858,9 +1640,8 @@ 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)) {
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");
@ -1868,15 +1649,27 @@ public class PS {
try {
worlds.save(worldsFile);
} catch (IOException e) {
PS.debug("Failed to save PlotSquared worlds.yml");
PS.debug("Failed to save " + IMP.getPluginName() + " worlds.yml");
e.printStackTrace();
}
}
} else {
Settings.load(configFile);
Settings.save(configFile);
}
}
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.VERSION = StringMan.join(this.version, ".");
Settings.PLATFORM = platform;
Settings.save(configFile);
config = YamlConfiguration.loadConfiguration(configFile);
}
@ -1980,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");
@ -1997,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;
}
@ -2018,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);
}
@ -2026,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);
}
@ -2041,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;
}
@ -2074,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;
}
@ -2098,11 +1896,75 @@ public class PS {
* @return Collection of PlotArea objects
*/
public Set<PlotArea> getPlotAreas(String world) {
PlotArea[] areas = this.plotAreaMap.get(world);
if (areas == null) {
return new HashSet<>(0);
Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, manager.getPlotAreas(world, null));
return set;
}
HashSet<PlotArea> set = new HashSet<>(areas.length);
/**
* 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) {
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;
}
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,9 @@
package com.intellectualcrafters.plot;
public enum Platform {
Bukkit,
Sponge,
Spigot,
Cauldron
}

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,51 +1,73 @@
package com.intellectualcrafters.plot;
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 static com.intellectualcrafters.plot.PS.log;
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)) {
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) {
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();
log("&dCould not check for updates (1)");
log("&7 - Manually check for updates: https://github.com/IntellectualSites/PlotSquared/releases");
return "";
}
}
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));
}
}
}
log("You are running the latest version of PlotSquared");
return null;
} catch (Throwable ignore) {
}
}
}

View File

@ -18,12 +18,11 @@ 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,
permission = "plots.add",
requiredType = RequiredType.PLAYER)
requiredType = RequiredType.NONE)
public class Add extends Command {
public Add() {
@ -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,16 +59,18 @@ 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 (uuid != DBFunc.everyone) {
if (!plot.removeTrusted(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
}
}
plot.addMember(uuid);
EventUtil.manager.callMember(player, plot, uuid, true);
MainUtil.sendMessage(player, C.MEMBER_ADDED);

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) {
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]);
@ -116,9 +110,19 @@ 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.evalute((double) currentPlots);
double cost = costExp.evaluate((double) currentPlots);
cost = (size_x * size_z) * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(player) < cost) {
@ -129,44 +133,21 @@ 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);
if (size_x == 1 && size_z == 1) {
autoClaimSafe(player, plotarea, null, schematic);
return true;
}
id = getNextPlotId(id, 1);
}
// no free plots
} else {
if (plotarea.TYPE == 2) {
// TODO
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 start = plotarea.getMeta("lastPlot", new PlotId(0, 0)).getNextId(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)) {
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));
@ -174,25 +155,94 @@ public class Auto extends SubCommand {
plot.claim(player, teleport, null);
}
}
if (size_x != 1 || size_z != 1) {
if (!plotarea.mergePlots(MainUtil.getPlotSelectionIds(start, end), true, true)) {
return false;
}
}
break;
}
}
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);
}
return value;
currentId = new PlotId(center.x + start.x, center.y + start.y);
return currentId;
}
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

@ -12,11 +12,11 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.Set;
@CommandDeclaration(
command = "buy",
aliases = {"b"},
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",
@ -43,7 +43,9 @@ public class Buy extends Command {
Set<Plot> plots = plot.getConnectedPlots();
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(), C.CANT_CLAIM_MORE_PLOTS);
Optional<Double> flag = plot.getFlag(Flags.PRICE);
checkTrue(flag.isPresent(), C.NOT_FOR_SALE);
if (!flag.isPresent()) {
throw new CommandException(C.NOT_FOR_SALE);
}
final double price = flag.get();
checkTrue(player.getMoney() >= price, C.CANNOT_AFFORD_PLOT);
player.withdraw(price);

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,32 +2,35 @@ 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",
aliases = "c",
description = "Claim the current plot you're standing on",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER,
requiredType = RequiredType.NONE,
permission = "plots.claim", usage = "/plot claim")
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,10 +50,24 @@ 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");
double cost = costExr.evalute((double) currentPlots);
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) {
return sendMessage(player, C.CANNOT_AFFORD_PLOT, "" + 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);
}
}
}
return plot.claim(player, false, schematic) || sendMessage(player, C.PLOT_NOT_CLAIMED);
});
}
}, new Runnable() {
@Override
public void run() {
sendMessage(player, C.PLOT_NOT_CLAIMED);
}
});
return true;
} else {
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((!Flags.DONE.isSet(plot) || Permissions.hasPermission(player, "plots.continue")) && (!Settings.Done.COUNTS_TOWARDS_LIMIT || player.getAllowedPlots() >= player.getPlotCount() + plot.getConnectedPlots().size()), 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

@ -84,6 +84,9 @@ public class DebugExec extends SubCommand {
}
public ScriptEngine getEngine() {
if (this.engine == null) {
init();
}
return this.engine;
}
@ -148,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;
@ -193,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

@ -15,7 +15,7 @@ import java.io.IOException;
@CommandDeclaration(command = "debugpaste",
aliases = "dp", usage = "/plot debugpaste",
description = "Upload settings.yml & latest.log to HasteBin",
description = "Upload settings.yml, worlds.yml, commands.yml and latest.log to www.hastebin.com",
permission = "plots.debugpaste",
category = CommandCategory.DEBUG)
public class DebugPaste extends SubCommand {

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();
@ -56,13 +56,13 @@ public class Delete extends SubCommand {
plot.removeRunning();
if ((EconHandler.manager != null) && plotArea.USE_ECONOMY) {
Expression<Double> valueExr = plotArea.PRICES.get("sell");
double value = plots.size() * valueExr.evalute((double) currentPlots);
double value = plots.size() * valueExr.evaluate((double) currentPlots);
if (value > 0d) {
EconHandler.manager.depositMoney(player, value);
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;
@ -23,7 +24,7 @@ import java.util.UUID;
description = "Deny a user from a plot",
usage = "/plot deny <player>",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
requiredType = RequiredType.NONE)
public class Deny extends SubCommand {
public Deny() {
@ -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;
}
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

@ -19,7 +19,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
description = "Mark a plot as done",
permission = "plots.done",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
requiredType = RequiredType.NONE)
public class Done extends SubCommand {
@Override
@ -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

@ -22,7 +22,7 @@ import java.net.URL;
command = "download",
aliases = {"dl"},
category = CommandCategory.SCHEMATIC,
requiredType = RequiredType.PLAYER,
requiredType = RequiredType.NONE,
description = "Download your plot",
permission = "plots.download")
public class Download extends SubCommand {
@ -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

@ -28,7 +28,7 @@ import java.util.Map;
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
description = "Set plot flags",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER,
requiredType = RequiredType.NONE,
permission = "plots.flag")
public class FlagCmd extends SubCommand {
@ -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;
}
}
@ -166,12 +166,15 @@ public class FlagCmd extends SubCommand {
return false;
}
}
if(flag == Flags.TIME) {
player.setTime(Long.MAX_VALUE);
}
MainUtil.sendMessage(player, C.FLAG_REMOVED);
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) {
@ -179,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;
}
}
@ -212,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

@ -4,12 +4,14 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.RunnableVal2;
import com.intellectualcrafters.plot.object.RunnableVal3;
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID;
@CommandDeclaration(
@ -18,17 +20,22 @@ import java.util.UUID;
usage = "/plot grant <check|add> [player]",
permission = "plots.grant",
requiredType = RequiredType.NONE)
public class Grant extends SubCommand {
public class Grant extends Command {
public Grant() {
super(MainCommand.getInstance(), true);
}
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
checkTrue(args.length >= 1 && args.length <= 2, C.COMMAND_SYNTAX, getUsage());
final String arg0 = args[0].toLowerCase();
switch (arg0) {
case "add":
case "check":
if (Permissions.hasPermission(player, "plots.grant." + arg0)) {
C.NO_PERMISSION.send(player, "plots.grant." + arg0);
return false;
if (!Permissions.hasPermission(player, C.PERMISSION_GRANT.f(arg0))) {
C.NO_PERMISSION.send(player, C.PERMISSION_GRANT.f(arg0));
return;
}
if (args.length > 2) {
break;
@ -36,7 +43,7 @@ public class Grant extends SubCommand {
final UUID uuid = args.length == 2 ? UUIDHandler.getUUIDFromString(args[1]) : player.getUUID();
if (uuid == null) {
C.INVALID_PLAYER.send(player, args[1]);
return false;
return;
}
MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal<byte[]>() {
@Override
@ -51,10 +58,7 @@ public class Grant extends SubCommand {
}
}
});
return true;
}
C.COMMAND_SYNTAX.send(player, getUsage());
return false;
}
}

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

@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID;
@ -35,6 +36,7 @@ public class Info extends SubCommand {
case "id":
case "size":
case "members":
case "seen":
case "owner":
case "rating":
plot = MainUtil.getPlotFromString(player, null, false);
@ -82,7 +84,7 @@ public class Info extends SubCommand {
"&cAlias: &6" + plot.getAlias(),
"&cBiome: &6" + plot.getBiome().replaceAll("_", "").toLowerCase(),
"&cCan Build: &6" + plot.isAdded(uuid),
"&cExpires: &6" + plot.isAdded(uuid),
"&cSeen: &6" + MainUtil.secToTime((int) (ExpireManager.IMP.getAge(plot) / 1000)),
"&cIs Denied: &6" + plot.isDenied(uuid)));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", "&cAmount: &6" + plot.getTrusted().size(),
"&8Click to view a list of the trusted users"));
@ -110,7 +112,7 @@ public class Info extends SubCommand {
info = getCaption(arg);
if (info == null) {
MainUtil.sendMessage(player,
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aexpires&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
+ "&aowner&7, &arating");
return false;
}
@ -149,8 +151,8 @@ public class Info extends SubCommand {
return C.PLOT_INFO_OWNER.s();
case "rating":
return C.PLOT_INFO_RATING.s();
case "expires":
return C.PLOT_INFO_EXPIRES.s();
case "seen":
return C.PLOT_INFO_SEEN.s();
default:
return null;
}

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