-
Notifications
You must be signed in to change notification settings - Fork 16
/
CustomMessages.java
641 lines (570 loc) · 40.6 KB
/
CustomMessages.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
package io.github.niestrat99.advancedteleport.config;
import io.github.niestrat99.advancedteleport.CoreClass;
import io.github.niestrat99.advancedteleport.fanciful.FancyMessage;
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.*;
import java.util.function.Consumer;
public class CustomMessages extends ATConfig {
public static CustomMessages config;
private static HashMap<CommandSender, BukkitRunnable> titleManager;
private static HashMap<CommandSender, BukkitRunnable> actionBarManager;
private static HashMap<CommandSender, BukkitRunnable> soundManager;
public CustomMessages() throws IOException {
super("custom-messages.yml");
config = this;
titleManager = new HashMap<>();
actionBarManager = new HashMap<>();
soundManager = new HashMap<>();
}
public void loadDefaults() {
makeSectionLenient("Teleport");
addDefault("Teleport.eventBeforeTP" , "&b↑ &8» &7Teleporting in &b{countdown} seconds&7, please do not move!");
addComment("Teleport.eventBeforeTP_title", "This is an example use for titles and subtitles in the plugin." +
"\nThis feature is supported only if you're on version 1.8.8 or newer.");
addExample("Teleport.eventBeforeTP_title.length" , 80 , "How many seconds (in ticks) the header should last. This is not including fading.");
addExample("Teleport.eventBeforeTP_title.fade-in" , 0 , "How many seconds (in ticks) the header should take to fade in.");
addExample("Teleport.eventBeforeTP_title.fade-out" , 10 , "How many seconds (in ticks) the header should take to fade out.");
addExample("Teleport.eventBeforeTP_title.0", "&7&lTeleporting...");
addExample("Teleport.eventBeforeTP_title.20", "&b> &7&lTeleporting... &b<");
addExample("Teleport.eventBeforeTP_title.40", "&b>> &7&lTeleporting... &b<<");
addExample("Teleport.eventBeforeTP_title.60", "&b>>> &e&lTeleported! &b<<<");
addExample("Teleport.eventBeforeTP_subtitle.0", "&bPlease do not move!");
addExample("Teleport.eventBeforeTP_subtitle.60", "");
addDefault("Teleport.eventBeforeTPMovementAllowed" , "&b↑ &8» &7Teleporting in &b{countdown} seconds&7!");
addDefault("Teleport.eventTeleport" , "&b↑ &8» &7Teleporting...");
addDefault("Teleport.eventMovement" , "&b↑ &8» &7Teleport has been cancelled due to movement.");
addDefault("Teleport.eventMovement_title.length", 60);
addDefault("Teleport.eventMovement_title.fade-in", 0);
addDefault("Teleport.eventMovement_title.fade-out", 10);
addDefault("Teleport.eventMovement_title.0", "&e&l! &c&lCancelled &e&l!");
addDefault("Teleport.teleportingToSpawn", "&b↑ &8» &7Teleporting you to spawn!");
addDefault("Teleport.teleporting", "&b↑ &8» &7Teleporting to &b{player}&7!");
addDefault("Teleport.teleportingToHome", "&b↑ &8» &7Teleporting to &b{home}&7!");
addDefault("Teleport.teleportingToHomeOther", "&b↑ &8» &7Teleporting to &b{player}&7's home, &b{home}&7!");
addDefault("Teleport.teleportingToWarp", "&b↑ &8» &7Teleporting you to &b{warp}&7!");
addDefault("Teleport.teleportingPlayerToSelf", "&b↑ &8» &7Teleporting &b{player} &7to you!");
addDefault("Teleport.teleportingSelfToPlayer", "&b↑ &8» &7Teleporting you to &b{player}&7!");
addDefault("Teleport.teleportingToRandomPlace", "&b↑ &8» &7Teleporting you to a random place!");
addDefault("Teleport.teleportingToLastLoc", "&b↑ &8» &7Teleporting to your last location!");
addDefault("Teleport.teleportedToOfflinePlayer", "&b↑ &8» &7Teleported to offline player &b{player}&7!");
addDefault("Teleport.teleportedOfflinePlayerHere", "&b↑ &8» &7Teleported offline player &b{player} &7to your location!");
makeSectionLenient("Error");
addDefault("Error.noPermission", "&b↑ &8» &7You do not have permission to use this command!");
addDefault("Error.noPermissionSign", "&b↑ &8» &7You do not have permission to make this sign!");
addDefault("Error.featureDisabled", "&b↑ &8» &7This feature has been disabled!");
addDefault("Error.noRequests", "&b↑ &8» &7You do not have any pending requests!");
// Config.addDefault("Error.requestSendFail", "&cCould not send request to &e{player}!"); - NOT USED!!!
addDefault("Error.tpOff", "&b↑ &8» &b{player} &7has their teleportation disabled!");
addDefault("Error.tpBlock", "&b↑ &8» &b{player} &7has blocked you from sending requests to them!");
addDefault("Error.alreadyOn", "&b↑ &8» &7Your teleport requests are already enabled!");
addDefault("Error.alreadyOff", "&b↑ &8» &7Your teleport requests are already disabled!");
addDefault("Error.alreadyBlocked", "&b↑ &8» &7This player is already blocked!");
addDefault("Error.neverBlocked", "&b↑ &8» &7This player was never blocked!");
addDefault("Error.onCooldown", "&b↑ &8» &7Please wait another &b{time} &7seconds to use this command!");
addDefault("Error.requestSentToSelf", "&b↑ &8» &7You can't send a request to yourself!");
addDefault("Error.noSuchPlayer", "&b↑ &8» &7The player is either currently offline or doesn't exist!");
addDefault("Error.alreadySentRequest", "&b↑ &8» &7You've already sent a request to &7{player}&b!");
addDefault("Error.notEnoughEXP", "&b↑ &8» &7You do not have enough EXP Levels to teleport there!" +
"\n&b↑ &8» &7You need at least &b{levels} &7EXP levels!");
addDefault("Error.notEnoughEXPPoints", "&b↑ &8» &7You do not have enough EXP Points to teleport there!" +
"\n&b↑ &8» &7You need at least &b{points} &7EXP points!");
addDefault("Error.notEnoughMoney", "&b↑ &8» &7You do not have enough money to teleport there!" +
"\n&b↑ &8» &7You need at least &b${amount}&7!");
addDefault("Error.requestExpired", "&b↑ &8» &7Your teleport request to &b{player} &7has expired!");
addDefault("Error.noPlayerInput", "&b↑ &8» &7You must include a player name!");
addDefault("Error.blockSelf", "&b↑ &8» &7You can't block yourself!");
addDefault("Error.noRequestsFromPlayer", "&b↑ &8» &7You don't have any pending requests from &b{player}&7!");
addDefault("Error.noRequests", "&b↑ &8» &7You don't have any pending requests!");
addDefault("Error.invalidPageNo", "&b↑ &8» &7You've inserted an invalid page number!");
addDefault("Error.noHomeInput", "&b↑ &8» &7You have to include a home name!");
addDefault("Error.noSuchHome", "&b↑ &8» &7This home doesn't exist!");
addDefault("Error.noBedHome", "&b↑ &8» &7You don't have any bed spawn set!");
addDefault("Error.noBedHomeOther", "&b↑ &8» &b{player} &7doesn't have a bed spawn set!");
addDefault("Error.reachedHomeLimit", "&b↑ &8» &7You can't set any more homes!");
addDefault("Error.homeAlreadySet", "&b↑ &8» &7You already have a home called &b{home}&7!");
addDefault("Error.noWarpInput", "&b↑ &8» &7You have to include the warp's name!");
addDefault("Error.noSuchWarp", "&b↑ &8» &7That warp doesn't exist!");
addDefault("Error.warpAlreadySet", "&b↑ &8» &7There is already a warp called &b{warp}&7!");
addDefault("Error.noSuchWorld", "&b↑ &8» &7That world doesn't exist!");
addDefault("Error.noLocation", "&b↑ &8» &7You don't have any location to teleport back to!");
addDefault("Error.notAPlayer", "&b↑ &8» &7You must be a player to run this command!");
addDefault("Error.noHomes", "&b↑ &8» &7You haven't got any homes!");
addDefault("Error.noHomesOtherPlayer", "&b↑ &8» &b{player} &7hasn't got any homes!");
addDefault("Error.tooFarAway", "&b↑ &8» &7The teleport destination is too far away so you can not teleport there!");
addDefault("Error.noRequestsSent", "&b↑ &8» &7Couldn't send a request to anyone :(");
addDefault("Error.onCountdown","&b↑ &8» &7You can't use this command whilst waiting to teleport!");
addDefault("Error.noPermissionWarp", "&b↑ &8» &7You can't warp to &b{warp}&7!");
addDefault("Error.cantTPToWorld", "&b↑ &8» &7You can't randomly teleport in that world!");
// config.addDefault("Error.invalidName", "&cHomes and warps may only have letters and numbers in the names!");
addDefault("Error.cantTPToWorldLim", "&b↑ &8» &7You can't teleport to &b{world}&7!");
addDefault("Error.tooFewArguments", "&b↑ &8» &7Too few arguments!");
addDefault("Error.invalidArgs", "&b↑ &8» &7Invalid arguments!");
addDefault("Error.cantTPToPlayer", "&b↑ &8» &7You can't request a teleportation to &b{player}&7!");
addDefault("Error.noWarps", "&b↑ &8» &7There are no warps as of currently!");
addDefault("Error.noAccessHome", "&b↑ &8» &7You cannot access &b{home}&7 as of currently!");
addDefault("Error.moveHomeFail", "&b↑ &8» &7The home has been moved but the data has not been stored successfully. The plugin will try to fix this itself.");
addDefault("Error.setMainHomeFail", "&b↑ &8» &7The main home has been set but the data has not been stored successfully. The plugin will try to fix this itself.");
addDefault("Error.deleteHomeFail", "&b↑ &8» &7The home has been deleted but the data has not been stored successfully. The plugin will try to fix this itself.");
addDefault("Error.setHomeFail", "&b↑ &8» &7The home has been set but the data has not been stored successfully. The plugin will try to fix this itself.");
addDefault("Error.deleteWarpFail", "&b↑ &8» &7The warp has been set but the data has not been stored successfully. The plugin will try to fix this itself.");
addDefault("Error.purgeWarpsFail", "&b↑ &8» &7Could not purge warps. Please check the console for more information.");
addDefault("Error.purgeHomesFail", "&b↑ &8» &7Could not purge homes. Please check the console for more information.");
addDefault("Error.homesNotLoaded", "&b↑ &8» &7Homes for this player haven't loaded yet, please wait a little bit (even just a second) before trying this again!");
addDefault("Error.noOfflineLocation", "&b↑ &8» &7No offline location was found for &b{player}&7!");
addDefault("Error.failedOfflineTeleport", "&b↑ &8» &7Failed to teleport to offline player &b{player}&7!");
addDefault("Error.failedOfflineTeleportHere", "&b↑ &8» &7Failed to teleport offline player &b{player} &7 to your location!");
addDefault("Error.alreadySearching", "&b↑ &8» &7Already searching for a location to teleport to!");
addDefault("Error.mirrorSpawnNoArguments", "&b↑ &8» &7No worlds/spawn points have been specified!");
addDefault("Error.mirrorSpawnLackOfArguments", "&b↑ &8» &7You must be a player to only specify one world - please specify a world and a spawnpoint to mirror players to!");
addDefault("Error.noSuchSpawn", "&b↑ &8» &7There is no such spawn called &b{spawn}&7!");
addDefault("Error.cannotSetMainSpawn", "&b↑ &8» &7You can only make existing spawnpoints into the main spawnpoint rather than create new ones!");
addDefault("Error.cannotSetMainSpawnConsole", "&b↑ &8» &7You can only make existing spawnpoints into the main spawnpoint rather than create new ones since you are not a player!");
addDefault("Error.nonAlphanumericSpawn", "&b↑ &8» &7Spawnpoints need to be alphanumeric!");
addDefault("Error.removeSpawnNoArgs", "&b↑ &8» &7You have to specify a spawnpoint to remove!");
addDefault("Error.noSuchPlugin", "&b↑ &8» &7This plugin is not supported for importing/exporting yet!");
addDefault("Error.cantImport", "&b↑ &8» &7Can't import plugin data from &b{plugin} &7(make sure it's enabled and by the correct authors)!");
addDefault("Error.cantExport", "&b↑ &8» &7Can't export plugin data from &b{plugin} &7(make sure it's enabled and by the correct authors)!");
addDefault("Error.notEnoughItems", "&b↑ &8» &7You do not have enough items to teleport there!\n" +
"&b↑ &8» &7You need at least &b{amount} {type}(s)!");
addDefault("Error.mirrorSpawnFail", "&b↑ &8» &7Failed to mirror &b{from}&7's spawnpoint to &b{spawn}&7!");
addDefault("Error.removeSpawnFail", "&b↑ &8» &7Failed to remove the spawnpoint &b{spawn}&7!");
addDefault("Error.setMainSpawnFail", "&b↑ &8» &7Failed to set the main spawnpoint &b{spawn}&7!");
addDefault("Error.rtpManagerNotUsed", "&b↑ &8» &7The feature required for this command is not enabled!");
addDefault("Info.tpOff", "&b↑ &8» &7Successfully disabled teleport requests!");
addDefault("Info.tpOn", "&b↑ &8» &7Successfully enabled teleport requests!");
addDefault("Info.tpAdminOff", "&b↑ &8» &7Successfully disabled teleport requests for &b{player}&7!");
addDefault("Info.tpAdminOn", "&b↑ &8» &7Successfully enabled teleport requests for &b{player}&7!");
addDefault("Info.requestSent", "&b↑ &8» &7Successfully sent request to &b{player}&7!" +
"\n&b↑ &8» &7They've got &b{lifetime} &7to respond!" +
"\n&7To cancel the request use &b/tpcancel &7to cancel it." +
"\n" +
"\n [&7&l[CANCEL]](/tpcancel {player})" +
"\n&7");
addDefault("Info.tpaRequestReceived", "&b↑ &8» &7The player &b{player} &7wants to teleport to you!" +
"\n&b↑ &8» &7If you want to accept it, use &b/tpayes&7, but if not, use &b/tpano&7." +
"\n&b↑ &8» &7You've got &b{lifetime} &7to respond to it!" +
"\n" +
"\n [&a&l[ACCEPT]](/tpayes {player}|&aClick here to accept the request.) [&c&l[DENY]](/tpano {player}|&cClick here to deny the request.)" +
"\n&7");
addDefault("Info.tpaRequestHere", "&b↑ &8» &7The player &b{player} &7wants to teleport you to them!" +
"\n&b↑ &8» &7If you want to accept it, use &b/tpayes&7, but if not, use &b/tpano&7." +
"\n&b↑ &8» &7You've got &b{lifetime} seconds &7to respond to it!" +
"\n" +
"\n [&a&l[ACCEPT]](/tpayes {player}|&aClick here to accept the request.) [&c&l[DENY]](/tpano {player}|&cClick here to deny the request.)" +
"\n&7");
addDefault("Info.blockPlayer", "&b↑ &8» &b{player} &7has been blocked.");
addDefault("Info.tpCancel", "&b↑ &8» &7You have cancelled your teleport request.");
addDefault("Info.tpCancelResponder", "&b↑ &8» &b{player} &7has cancelled their teleport request.");
addDefault("Info.multipleRequestsCancel", "&b↑ &8» &7You have multiple teleport requests pending! Click one of the following to cancel:");
addDefault("Info.multipleRequestsIndex", "&b> {player}");
addDefault("Info.multipleRequestsList", "&b↑ &8» &7Do /tpalist <Page Number> To check other requests.");
addDefault("Info.multipleRequestAccept", "&b↑ &8» &7You have multiple teleport requests pending! Click one of the following to accept:");
addDefault("Info.multipleRequestDeny", "&b↑ &8» &7You have multiple teleport requests pending! Click one of the following to deny:");
addDefault("Info.requestDeclined", "&b↑ &8» &7You've declined the teleport request!");
addDefault("Info.requestDeclinedResponder", "&b↑ &8» &b{player} &7has declined your teleport request!");
addDefault("Info.requestDisplaced", "&b↑ &8» &7Your request has been cancelled because &b{player} &7got another request!");
addDefault("Info.deletedHome", "&b↑ &8» &7Successfully deleted the home &b{home}&7!");
addDefault("Info.deletedHomeOther", "&b↑ &8» &7Successfully deleted the home &b{home} &7for &b{player}&7!");
addDefault("Info.setHome", "&b↑ &8» &7Successfully set the home &b{home}&7!");
addDefault("Info.setHomeOther", "&b↑ &8» &7Successfully set the home &b{home} &7for &b{player}&7!");
addDefault("Info.setSpawn", "&b↑ &8» &7Successfully set the spawnpoint!");
addDefault("Info.setWarp", "&b↑ &8» &7Successfully set the warp &b{warp}&7!");
addDefault("Info.deletedWarp", "&b↑ &8» &7Successfully deleted the warp &b{warp}&7!");
addDefault("Info.purgeWarpsWorld", "&b↑ &8» &7Successfully purged warps in &b{world}&7!");
addDefault("Info.purgeWarpsCreator", "&b↑ &8» &7Successfully purged warps created by &b{player}&7!");
addDefault("Info.purgeHomesWorld", "&b↑ &8» &7Successfully purged homes in &b{world}&7!");
addDefault("Info.purgeHomesCreator", "&b↑ &8» &7Successfully purged homes created for &b{player}&7!");
addDefault("Info.searching", "&b↑ &8» &7Searching for a location...");
addDefault("Info.unblockPlayer", "&b↑ &8» &7Successfully unblocked &b{player}&7!");
addDefault("Info.reloadingConfig", "&b↑ &8» &7Reloading &bAdvancedTeleport&7's config...");
addDefault("Info.reloadedConfig", "&b↑ &8» &7Finished reloading the config!");
addDefault("Info.warps", "&b&lWarps &8» &r");
addDefault("Info.homes", "&b&lHomes &8» &r");
addDefault("Info.homesOther", "&b&l{player}'s homes &8» &r");
addDefault("Info.requestAccepted", "&b↑ &8» &7You've accepted the teleport request!");
addDefault("Info.requestAcceptedResponder", "&b↑ &8» &b{player} &7has accepted the teleport request!");
addDefault("Info.paymentVault", "&b↑ &8» &7You have paid &b${amount} &7and now have &b${balance}&7!");
addDefault("Info.paymentEXP", "&b↑ &8» &7You have paid &b{amount} EXP Levels &7and now have &b{levels} &7levels!");
addDefault("Info.paymentPoints", "&b↑ &8» &7You have paid &b{amount} EXP Points &7and now have &b{points} &7points!");
addDefault("Info.createdWarpSign", "&b↑ &8» &7Successfully created the warp sign!");
addDefault("Info.createdRTPSign", "&b↑ &8» &7Successfully created the RandomTP sign!");
addDefault("Info.createdSpawnSign", "&b↑ &8» &7Successfully created the spawn sign!");
addDefault("Info.tpallRequestSent", "&b↑ &8» &7Successfully sent a teleport request to &b{amount} &7player(s)!");
addDefault("Info.teleportedToLoc", "&b↑ &8» &7Successfully teleported you to &b{x}&7, &b{y}&7, &b{z}&7! (Yaw: &b{yaw}&7, Pitch: &b{pitch}&7, World: &b{world}&7)");
addDefault("Info.teleportedToLocOther", "&b↑ &8» &7Successfully teleported &b{player} &7to &b{x}&7, &b{y}&7, &b{z}&7! (Yaw: &b{yaw}&7, Pitch: &b{pitch}&7, World: &b{world}&7)");
addDefault("Info.movedWarp", "&b↑ &8» &7Moved &b{warp} &7to your current location!");
addDefault("Info.movedHome", "&b↑ &8» &7Moved home &b{home} &7to your current location!");
addDefault("Info.movedHomeOther", "&b↑ &8» &7Moved &b{player}'s &7home &b{home} &7to your location!");
addDefault("Info.setMainHome", "&b↑ &8» &7Made &b{home} &7your main home!");
addDefault("Info.setAndMadeMainHome", "&b↑ &8» &7Set &b{home} &7at your current location and made it your main home!");
addDefault("Info.setMainHomeOther", "&b↑ &8» &7Made &b{home} {player}'s &7main home!");
addDefault("Info.setAndMadeMainHomeOther", "&b↑ &8» &7Set &b{home} &7for &b{player} &7at your current location and made it their main home!");
addDefault("Info.mirroredSpawn", "&b↑ &8» &7Mirrored &b{from}&7's spawnpoint to &b{spawn}&7!");
addDefault("Info.setMainSpawn", "&b↑ &8» &7Set the main spawnpoint to &b{spawn}&7! All players will teleport there if there are no overriding spawns/permissions.");
addDefault("Info.removedSpawn", "&b↑ &8» &7Removed the spawnpoint &b{spawn}&7!");
addDefault("Info.setSpawnSpecial", "&b↑ &8» &7Set spawnpoint &b{spawn}&7!");
addDefault("Info.importStarted", "&b↑ &8» &7Starting import from &b{plugin}&7...");
addDefault("Info.importFinished", "&b↑ &8» &7Finished import from &b{plugin}&7!");
addDefault("Info.exportStarted", "&b↑ &8» &7Starting export to &b{plugin}&7...");
addDefault("Info.exportFinished", "&b↑ &8» &7Finished export to &b{plugin}&7!");
addDefault("Info.paymentItems", "&b↑ &8» &7You have paid &b{amount} {type}(s) &7for that teleport!");
addDefault("Info.updateInfo", "&b↑ &8» [&7AdvancedTeleport has an update available! " +
"Click/hover over this text for more information.]" +
"(&bCurrent Version &8» &7{version}|&bNew Version &8» &7{new-version}|&bTitle &8» &7{title}" +
"|https://www.spigotmc.org/resources/advancedteleport.64139/)");
addDefault("Info.clearEverything", "&b↑ &8» &7The RTP cache has been fully cleared!");
addDefault("Info.clearWorld", "&b↑ &8» &7The RTP cache has cleared for {world}!");
addDefault("Tooltip.homes", "&b↑ &8» &7Teleports you to your home: &b{home}");
addDefault("Tooltip.warps", "&b↑ &8» &7Teleports you to warp: &b{warp}");
addDefault("Tooltip.location", "" +
"\n&bX &8» &7{x}" +
"\n&bY &8» &7{y}" +
"\n&bZ &8» &7{z}" +
"\n&bWorld &8» &7{world}");
addDefault("Descriptions.Subcommands.help", "Sends the help menu, providing a full list of commands.");
addDefault("Descriptions.Subcommands.info", "Sends information regarding the plugin.");
addDefault("Descriptions.Subcommands.import", "Imports data from another plugin so that it can be used within AT.");
addDefault("Descriptions.Subcommands.export", "Exports data within AT to another plugin.");
addDefault("Descriptions.Subcommands.reload", "Reloads the plugin's configuration.");
addDefault("Descriptions.Subcommands.clearcache", "Clears the RTP cache.");
addDefault("Descriptions.at", "The core command for AT.");
addDefault("Descriptions.tpa", "Sends a request to teleport to the player.");
addDefault("Descriptions.tpahere", "Sends a request to the player to teleport to you.");
addDefault("Descriptions.tpyes", "Accepts a player's teleport request.");
addDefault("Descriptions.tpno", "Declines a player's teleport request.");
addDefault("Descriptions.tpcancel", "Cancels your teleport request to a player.");
addDefault("Descriptions.toggletp", "Either stops or allows players to send teleport requests to you.");
addDefault("Descriptions.tpon", "Allows players to send teleport requests to you.");
addDefault("Descriptions.tpoff", "Stops players from sending teleport requests to you.");
addDefault("Descriptions.tpblock", "Stops a specific player from sending teleport requests to you.");
addDefault("Descriptions.tpunblock", "Allows a blocked player to send you teleport requests again.");
addDefault("Descriptions.back", "Teleports you to your previous location.");
addDefault("Descriptions.tpalist", "Lists all of your current teleport requests.");
addDefault("Descriptions.tpo", "Instantly teleports you to a player.");
addDefault("Descriptions.tpohere", "Instantly teleports a player to you.");
addDefault("Descriptions.tpall", "Sends a teleport request to everyone in the server to you.");
addDefault("Descriptions.tploc", "Teleports you to a specific location.");
addDefault("Descriptions.tpoffline", "Teleports you to an offline player.");
addDefault("Descriptions.tpofflinehere", "Teleports an offline player to you.");
addDefault("Descriptions.tpr", "Teleports you to a random location.");
addDefault("Descriptions.warp", "Teleports you to a given warp point.");
addDefault("Descriptions.warps", "Gives you a list of warps you can teleport to.");
addDefault("Descriptions.setwarp", "Sets a warp at your location.");
addDefault("Descriptions.delwarp", "Deletes a warp.");
addDefault("Descriptions.movewarp", "Moves a warp to a new location.");
addDefault("Descriptions.spawn", "Teleports you to the spawnpoint.");
addDefault("Descriptions.setspawn", "Sets a spawn with a name when specified.");
addDefault("Descriptions.mirrorspawn", "Redirects people using /spawn in one world to another spawn point.");
addDefault("Descriptions.setmainspawn", "Sets a specified spawnpoint to become the main spawnpoint. If it does not exist, it will be created if you have /setspawn permissions.");
addDefault("Descriptions.removespawn", "Removes a specified spawnpoint. If none is specified, the one in your current world is removed.");
addDefault("Descriptions.home", "Teleports you to your home.");
addDefault("Descriptions.homes", "Gives you a list of homes you've set.");
addDefault("Descriptions.sethome", "Sets a home at your current location.");
addDefault("Descriptions.delhome", "Deletes a home.");
addDefault("Descriptions.movehome", "Moves a home to a new location.");
addDefault("Descriptions.setmainhome", "Sets a home at your location or makes an existing one your main home.");
addDefault("Descriptions.purge", "Removes all warps or homes for the specified player or world.");
addDefault("Usages.Subcommands.help", "/at help [Category|Page]");
addDefault("Usages.Subcommands.info", "/at info");
addDefault("Usages.Subcommands.import", "/at import <Plugin> [All|Homes|LastLocs|Warps|Spawns|Players]");
addDefault("Usages.Subcommands.export", "/at export <Plugin> [All|Homes|LastLocs|Warps|Spawns|Players]");
addDefault("Usages.Subcommands.purge", "/at purge <Homes|Warps> <Player|World> <Player Name|World Name>");
addDefault("Usages.Subcommands.reload", "/at reload");
addDefault("Usages.Subcommands.clearcache", "/at clearcache [World]");
addDefault("Usages.at", "/at <Command>");
addDefault("Usages.tpa", "/tpa <Player>");
addDefault("Usages.tpahere", "/tpahere <Player>");
addDefault("Usages.tpyes", "/tpyes [Player]");
addDefault("Usages.tpno", "/tpno [Player]");
addDefault("Usages.tpcancel", "/tpcancel [Player]");
addDefault("Usages.toggletp", "/toggletp");
addDefault("Usages.tpon", "/tpon");
addDefault("Usages.tpoff", "/tpoff");
addDefault("Usages.tpblock", "/tpblock <Player> [Reason]");
addDefault("Usages.tpunblock", "/tpunblock <Player>");
addDefault("Usages.back", "/back");
addDefault("Usages.tpalist", "/tpalist");
addDefault("Usages.tpo", "/tpo <Player>");
addDefault("Usages.tpohere", "/tpohere <Player>");
addDefault("Usages.tpall", "/tpall");
addDefault("Usages.tploc", "/tploc <x|~> <y|~> <z|~> [Yaw|~] [Pitch|~] [World|~] [Player] [precise|noflight]");
addDefault("Usages.tpoffline", "/tpoffline <Player>");
addDefault("Usages.tpofflinehere", "/tpofflinehere <Player>");
addDefault("Usages.tpr", "/tpr [World]");
addDefault("Usages.warp", "/warp <Warp>");
addDefault("Usages.warps", "/warps");
addDefault("Usages.setwarp", "/setwarp <Name>");
addDefault("Usages.delwarp", "/delwarp <Name>");
addDefault("Usages.movewarp", "/movewarp <Name>");
addDefault("Usages.spawn", "/spawn");
addDefault("Usages.setspawn", "/setspawn [ID]");
addDefault("Usages.mirrorspawn", "/mirrorspawn <To Point>|[From World] [To Point]");
addDefault("Usages.setmainspawn", "/setmainspawn [Point]");
addDefault("Usages.removespawn", "/removespawn [Point]");
addDefault("Usages.home", "/home [Home]");
addDefault("Usages.homes", "/homes");
addDefault("Usages.sethome", "/sethome <Name>");
addDefault("Usages.delhome", "/delhome <Home>");
addDefault("Usages.movehome", "/movehome <Home>");
addDefault("Usages.setmainhome", "/setmainhome <Home>");
addDefault("Usages-Admin.tpr", "/tpr [World] [Player]");
addDefault("Usages-Admin.home", "/home [Home]|<Player> <Home>");
addDefault("Usages-Admin.homes", "/homes [Player]");
addDefault("Usages-Admin.delhome", "/delhome <Home>|<Player> <Home>");
addDefault("Usages-Admin.sethome", "/sethome <Name>|<Player> <Name>");
addDefault("Usages-Admin.movehome", "/movehome <Home>|<Player> <Home>");
addDefault("Usages-Admin.setmainhome", "/setmainhome <Home>|<Player> <Home>");
addDefault("Usages-Admin.spawn", "/spawn <ID>");
}
public static String getStringA(String path) {
return translateString(config.getString(path));
}
public static String getString(String path, String... placeholders) {
return translateString(config.getString(path), placeholders);
}
public static String translateString(String str, String... placeholders) {
if (str == null) return "";
str = str.replaceAll("''", "'");
str = str.replaceAll("^'", "");
str = str.replaceAll("'$", "");
str = ChatColor.translateAlternateColorCodes('&', str);
for (int i = 0; i < placeholders.length; i += 2) {
try {
str = str.replace(placeholders[i], placeholders[i + 1]);
} catch (ArrayIndexOutOfBoundsException ignored) {
}
}
return str;
}
public static void sendMessage(CommandSender sender, String path, String... placeholders) {
if (config == null) return;
if (sender instanceof Player) {
Player player = (Player) sender;
handleSpecialMessage(player, path + "_actionbar", (content -> sendActionBar(player, content, placeholders)), actionBarManager);
handleSpecialMessage(player, path + "_sound", (sound -> sendSound(player, sound, path)), soundManager);
@Nullable ConfigSection titles = config.getConfigSection(path + "_title");
@Nullable ConfigSection subtitles = config.getConfigSection(path + "_subtitle");
if (titles != null || subtitles != null) {
// Debug
CoreClass.debug("Found special message format - titles: " + titles + ", subtitles: " + subtitles);
// Fade in, stay, out
int[] titleInfo = new int[]{0, 0, 0};
if (titles != null) {
titleInfo[0] = titles.getInteger("fade-in");
titleInfo[1] = titles.getInteger("length");
titleInfo[2] = titles.getInteger("fade-out");
}
// Handle t
BukkitRunnable titleRunnable = new BukkitRunnable() {
private int current = 0;
private String previousTitle = null;
private String previousSubtitle = null;
@Override
public void run() {
if (current == titleInfo[1] || titleManager.get(player) != this) {
cancel();
return;
}
String title = null;
String subtitle = null;
if (titles != null) title = titles.getString(String.valueOf(current));
if (subtitles != null) subtitle = subtitles.getString(String.valueOf(current));
sendTitle(player,
title == null ? previousTitle : (previousTitle = title),
subtitle == null ? previousSubtitle : (previousSubtitle = subtitle),
titleInfo[0],
titleInfo[1] - current,
titleInfo[2],
placeholders);
current++;
}
};
titleManager.put(player, titleRunnable);
titleRunnable.runTaskTimer(CoreClass.getInstance(), 1, 1);
}
}
if (config.get(path) instanceof List) {
List<String> messages = config.getStringList(path);
for (int i = 0; i < messages.size(); i++) {
getFancyMessage(translateString(messages.get(i), placeholders)).sendProposal(sender, i);
}
} else {
String rawMessage = translateString(config.getString(path), placeholders);
if (rawMessage.isEmpty()) return;
String[] messages = rawMessage.split("\n");
for (int i = 0; i < messages.length; i++) {
getFancyMessage(messages[i]).sendProposal(sender, i);
}
}
FancyMessage.send(sender);
}
private static void sendTitle(Player player, String title, String subtitle, int fadeIn, int length, int fadeOut, String... placeholders) {
try {
CoreClass.debug("Attempting modern title sending: " + title + ", " + subtitle);
player.sendTitle(translateString(title, placeholders), translateString(subtitle, placeholders), fadeIn, length, fadeOut);
} catch (NoSuchMethodError e) {
try {
CoreClass.debug("Attempting old title sending: " + title + ", " + subtitle);
player.sendTitle(title, subtitle);
} catch (NoSuchMethodError ignored) {
}
}
}
private static void handleSpecialMessage(
@NotNull Player player,
@NotNull String id,
@NotNull Consumer<String> consumer,
@NotNull HashMap<CommandSender, BukkitRunnable> runnableTracker
) {
// If the section does not exist, stop there
if (!config.contains(id)) return;
// If it's just a string, then consume that
if (config.get(id) instanceof String) {
consumer.accept(config.getString(id));
return;
}
// If it's not a section though, then stop there
if (config.getConfigSection(id) == null) return;
ConfigSection section = config.getConfigSection(id);
// Create the BukkitRunnable
BukkitRunnable runnable = new BukkitRunnable() {
private final Queue<String> times = new ArrayDeque<>(section.getKeys(false));
private int current = 0;
@Override
public void run() {
// If the times queue is empty stop there
if (times.isEmpty() || runnableTracker.get(player) != this) {
cancel();
return;
}
// If the next element is equal to the current timer, use that
if (!String.valueOf(current++).equals(times.peek())) return;
// Get the message to be sent and send it
String content = section.getString(times.poll());
consumer.accept(content);
}
};
// Add it to the hashmap and run it
runnableTracker.put(player, runnable);
runnable.runTaskTimer(CoreClass.getInstance(), 1, 1);
}
private static void sendActionBar(Player player, String text, String... placeholders) {
try {
// chad paper
CoreClass.debug("Attempting Paper-based action bar sending: " + text);
player.sendActionBar(translateString(text, placeholders));
} catch (NoSuchMethodError e) {
// virgin spigot
CoreClass.debug("Attempting Spigot-based action bar sending: " + text);
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(translateString(text, placeholders)));
}
}
private static void sendSound(Player player, String sound, String id) {
// Set default variables
float volume = 1.0f;
float pitch = 1.0f;
// Check the formatting of the sound
String[] rawSound = sound.split(";");
if (rawSound.length == 0) return;
// Set the volume and pitch
if (rawSound.length == 2) volume = Float.parseFloat(rawSound[1]);
if (rawSound.length >= 3) pitch = Float.parseFloat(rawSound[2]);
// Get the sound type
if (rawSound[0].matches("([a-z0-9_\\-.]+:)?[a-z0-9_\\-./]+")) {
try {
player.playSound(Sound.sound(Key.key(rawSound[0]), Sound.Source.NEUTRAL, volume, pitch));
} catch (NoSuchMethodError | NoClassDefFoundError ignored) {
CoreClass.getInstance().getLogger().warning("Sound for " + id + " (" + rawSound[0] + ") could not be played: namespaces are not supported on your platform.");
}
} else {
try {
player.playSound(player, org.bukkit.Sound.valueOf(rawSound[0]), volume, pitch);
} catch (IllegalArgumentException ex) {
CoreClass.getInstance().getLogger().warning("Sound for " + id + " (" + rawSound[0] + ") could not be played: sound does not exist.");
}
}
}
// Doing it like this because Regex is not co-operating
private static FancyMessage getFancyMessage(String str) {
int startTextPointer = -1;
int endTextPointer = -1;
int startCommandPointer = -1;
int endCommandPointer;
int lastMarkdownPointer = 0;
FancyMessage builder = new FancyMessage();
boolean buildingComponent = false;
for (int i = 0; i < str.length(); i++) {
if (!buildingComponent && str.charAt(i) == '[' && (i == 0 || !(str.charAt(i - 1) == '\\'))) {
startTextPointer = i + 1;
buildingComponent = true;
} else if (buildingComponent && str.charAt(i) == ']' && !(str.charAt(i - 1) == '\\')) {
endTextPointer = i;
} else if (buildingComponent && str.charAt(i) == '(') {
if (str.charAt(i - 1) == ']') {
startCommandPointer = i + 1;
} else if (startCommandPointer == -1) {
buildingComponent = false;
startTextPointer = -1;
endTextPointer = -1;
}
} else if (buildingComponent && str.charAt(i) == ')' && !(str.charAt(i - 1) == '\\')) {
if (startCommandPointer != -1) {
endCommandPointer = i;
// Get all the
builder.text(str.substring(lastMarkdownPointer, startTextPointer - 1));
String command = "";
String link = "";
List<String> tooltip = new ArrayList<>();
String fullCommand = str.substring(startCommandPointer, endCommandPointer);
int dividerIndex = fullCommand.indexOf('|');
if (dividerIndex != -1 && fullCommand.charAt(dividerIndex - 1) != '\\') {
String[] parts = fullCommand.split("\\|");
for (String part : parts) {
if (part.startsWith("/") && command.isEmpty()) {
command = part;
} else if (part.startsWith("http")) {
link = part;
} else if (!part.isEmpty()) {
tooltip.add(part);
}
}
} else {
if (fullCommand.startsWith("/")) {
command = fullCommand;
} else if (fullCommand.startsWith("http")) {
link = fullCommand;
} else if (!fullCommand.isEmpty()) {
tooltip.add(fullCommand);
}
}
builder.then(str.substring(startTextPointer, endTextPointer)).tooltip(tooltip);
if (!command.isEmpty()) {
builder.command(command);
}
if (!link.isEmpty()) {
builder.link(link);
}
builder.then();
lastMarkdownPointer = endCommandPointer + 1;
startTextPointer = -1;
endTextPointer = -1;
startCommandPointer = -1;
buildingComponent = false;
}
}
}
builder.text(str.substring(lastMarkdownPointer));
return builder;
}
}