Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
714 lines (656 loc) · 34.6 KB
/
Copy pathMain.java
File metadata and controls
714 lines (656 loc) · 34.6 KB
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
package newestfile.here.newestplugin;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.nio.charset.StandardCharsets;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.File;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.event.EventHandler;
import java.nio.file.Files;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import java.util.Random;
@SuppressWarnings("deprecation")
public class Main extends JavaPlugin implements Listener
{
private HashMap <UUID, BukkitTask> tasks = new HashMap<>();
private File dataFolder;
private List<Player> activePlayers;
private List<Location> Follow1;
private boolean isListActive = false;
private static final Random RANDOM = new Random();
private static final Location[] PREY_LOCATIONS = {
new Location(Bukkit.getWorld("world"), 40, -58, 75),
new Location(Bukkit.getWorld("world"), 39, -58, 55),
new Location(Bukkit.getWorld("world"), 2, -58, 55),
new Location(Bukkit.getWorld("world"), 3, -58, 75)
};
private static final Location[] PRED1_LOCATIONS = {
new Location(Bukkit.getWorld("world"), 30, -58, 66),
new Location(Bukkit.getWorld("world"), 29, -58, 60),
new Location(Bukkit.getWorld("world"), 6, -58, 50),
new Location(Bukkit.getWorld("world"), 6, -58, 30)
};
private static final Location[] PRED2_LOCATIONS = {
new Location(Bukkit.getWorld("world"), 35, -58, 67),
new Location(Bukkit.getWorld("world"), 34, -58, 67),
new Location(Bukkit.getWorld("world"), 13, -58, 54),
new Location(Bukkit.getWorld("world"), 15, -58, 72)
};
public void teleportCharacters(Player prey, Player pred1, Player pred2) {
int setIndex = RANDOM.nextInt(4);
Location preyLocation = PREY_LOCATIONS[setIndex];
prey.teleport(preyLocation);
Location pred1Location = PRED1_LOCATIONS[setIndex];
pred1.teleport(pred1Location);
Location pred2Location = PRED2_LOCATIONS[setIndex];
pred2.teleport(pred2Location);
}
public void onEnable() {
Bukkit.getServer().getPluginManager().registerEvents(this,this);
activePlayers = new ArrayList<>();
Follow1 = new ArrayList<>();
isListActive = false;
getLogger().info("HELLO! WELCOME TO THE TRACKER PLUGIN");
dataFolder = new File(getDataFolder(), "newdata");
dataFolder.mkdirs();
}
@EventHandler
public void onLogin(final PlayerJoinEvent event) {
final Player thePlayer = event.getPlayer();
final Location playerSpawnLocation = thePlayer.getLocation();
getLogger().info("Welcome " + thePlayer.getName() + ". Your current position is: " + playerSpawnLocation);
BukkitTask task = getServer().getScheduler().runTaskTimer(this, () ->
logToFile(thePlayer, thePlayer.getLocation()), 0L, 20L);
tasks.put(thePlayer.getUniqueId(),task);
}
@EventHandler
public void onQuit(final PlayerQuitEvent event) {
Player thePlayer = event.getPlayer();
if(!thePlayer.isOnline()) {
getLogger().info(String.valueOf(event.getPlayer().getName()) + " has left the game");
BukkitTask task = tasks.remove(thePlayer.getUniqueId());
if(task != null) {
task.cancel();
}
}
}
private void logToFile(final Player currentPlayer, final Location playerCurrentLocation) {
double distance = 0;
int bin = 0;
double distance2 = 0;
int bin2 = 0;
double distance3 = 0;
int bin3 = 0;
Player targetPlayer = Bukkit.getPlayer("anna232224");
if (targetPlayer != null) {
distance = playerCurrentLocation.distance(targetPlayer.getLocation());
bin = getBin(distance);
}
Player targetPlayer2 = Bukkit.getPlayer("TwentyPoet26227");
if (targetPlayer2 != null) {
distance2 = playerCurrentLocation.distance(targetPlayer2.getLocation());
bin2 = getBin(distance2);
}
Player targetPlayer3 = Bukkit.getPlayer("caledonian26");
if (targetPlayer3 != null) {
distance3 = playerCurrentLocation.distance(targetPlayer3.getLocation());
bin3 = getBin(distance3);
}
String playerName = currentPlayer.getName();
String content = generateLogContent(currentPlayer, playerCurrentLocation, distance, bin, distance2, bin2, distance3, bin3);
saveLogToFile(playerName, content);
}
private int getBin(double distance) {
int[] binValues = new int[]{5, 10, 15, 20, 25};
int[] radiusValues = new int[]{5, 10, 15, 20, Integer.MAX_VALUE};
for (int i = 0; i < radiusValues.length; i++) {
if (distance <= radiusValues[i]) {
return binValues[i];
}
}
return 0;
}
private String generateLogContent(Player currentPlayer, Location playerCurrentLocation, double distance, int bin,
double distance2, int bin2, double distance3, int bin3) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String timestamp = sdf.format(new Date());
return timestamp + " CurrentLocation(x,y,z): " + playerCurrentLocation.getBlockX() + " " + playerCurrentLocation.getBlockY()
+ " " + playerCurrentLocation.getBlockZ() + " Distance to anna232224 (prey): " + distance + " Distance to anna232224 (prey) bin: "
+ bin + " Distance to other predator 1: " + distance2 + " Distance to other predator 1 bin: " + bin2
+ " Distance to other predator 2: " + distance3 + " Distance to other predator 2 bin: " + bin3
+ " Current Yaw: " + currentPlayer.getEyeLocation().getYaw() + " Current Pitch: " + currentPlayer.getEyeLocation().getPitch()
+ " Heading Direction: " + currentPlayer.getEyeLocation().getDirection() + "\n";
}
private void saveLogToFile(String playerName, String content) {
try {
fileNameSuffix = "here";
final File file = new File(dataFolder, playerName + "_" + String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
List<String> vowels = new ArrayList<>();
List<String> vowels2 = new ArrayList<>();
private Map<String, Long> buttonPressTimes = new HashMap<>();
Player otherPlayer;
BukkitTask grouppracticeChaseRunnable = null;
BukkitTask grouppracticeFollowRunnable = null;
BukkitTask groupFollowJUMP = null;
BukkitTask pred1FOLLOWJUMP = null;
BukkitTask pred2FOLLOWJUMP = null;
Player damagedPlayer = null;
private String fileNameSuffix;
private String trialtype;
HashMap<String, Integer> playerClicks1 = new HashMap<>();
HashMap<String, Integer> playerClicks2 = new HashMap<>();
private void dressPlayerAndPlaceItems(Player player, String trial, String color, String inventorycolor) {
player.getInventory().setArmorContents(new ItemStack[]{null, null, null, null});
player.getInventory().clear();
ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) chestplate.getItemMeta();
switch (color.toLowerCase()) {
case "blue":
chestplateMeta.setColor(Color.fromRGB(0, 0, 255));
chestplate.setItemMeta(chestplateMeta);
break;
case "white":
chestplateMeta.setColor(Color.fromRGB(192, 192, 192));
chestplate.setItemMeta(chestplateMeta);
break;
case "light green":
chestplateMeta.setColor(Color.fromRGB(144, 238, 144));
chestplate.setItemMeta(chestplateMeta);
break;
default:
player.sendMessage("Invalid color specified!");
return;
}
if (trial.equalsIgnoreCase("groupfollow") || trial.equalsIgnoreCase("groupchase")) {
player.getInventory().setChestplate(chestplate);
}
ItemStack inventoryChestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
LeatherArmorMeta inventoryChestplateMeta = (LeatherArmorMeta) inventoryChestplate.getItemMeta();
switch (inventorycolor.toLowerCase()) {
case "blue":
inventoryChestplateMeta.setColor(Color.fromRGB(0, 0, 255));
break;
case "white":
inventoryChestplateMeta.setColor(Color.fromRGB(192, 192, 192));
break;
default:
player.sendMessage("Invalid inventory color specified!");
return;
}
inventoryChestplate.setItemMeta(inventoryChestplateMeta);
player.getInventory().addItem(inventoryChestplate);
}
private void replaceBlocksWithAir1() {
int[][] coordinatesToReplace1 = {
{49, -58, 64}, {7, -58, 42}, {16, -58, 70}, {53, -58, 86}
};
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
String playerName = player.getName();
if (playerName.equals("TwentyPoet26227")) {
World world = player.getWorld();
if (world != null) {
for (int[] coord : coordinatesToReplace1) {
int x = coord[0];
int y = coord[1];
int z = coord[2];
Location loc = new Location(world, x, y, z);
Block block = loc.getBlock();
block.setType(org.bukkit.Material.AIR);
}
}
}
}
}
private static final long COOLDOWN_DURATION = 2000;
BukkitTask task2a = null;
BukkitTask task2b = null;
Player playerclick;
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (activePlayers.contains(player) && isListActive) {
Block block = player.getLocation().getBlock();
if (!Follow1.contains(block.getLocation())) {
Follow1.add(block.getLocation());
try {
fileNameSuffix = "here";
String content = String.valueOf(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) +
" Player: " + event.getPlayer().getName() +
" Location: " + event.getPlayer().getLocation();
final File file = new File(dataFolder, "TESTFOLLOWROUTES" + event.getPlayer().getName() +
String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null) {
return;
}
if (event.getClickedBlock() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.WARPED_BUTTON) {
if (event.getPlayer().getName().equals("caledonian26")) {
trialtype = "groupchase";
Player tao = Bukkit.getPlayer("anna232224");
Player emre = Bukkit.getPlayer("caledonian26");
Player anna = Bukkit.getPlayer("TwentyPoet26227");
int setIndex = RANDOM.nextInt(4);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendTitle("Keep still!","Look at me jump!", 10, 70, 20);
}
if (emre != null) {
Location preyLocation = PREY_LOCATIONS[setIndex];
World world = emre.getWorld();
Location emreLocation = new Location(world, preyLocation.getX(), preyLocation.getY(), preyLocation.getZ());
dressPlayerAndPlaceItems(emre, "groupchase", "blue","blue");
emre.teleport(emreLocation);
}
if (anna != null) {
Location pred1Location = PRED1_LOCATIONS[setIndex]; // Optionally randomize index inside the set
World world = anna.getWorld();
Location annaLocation = new Location(world, pred1Location.getX(), pred1Location.getY(), pred1Location.getZ());
dressPlayerAndPlaceItems(anna, "groupchase","light green","blue");
anna.teleport(annaLocation);
}
if (tao != null) {
Location pred2Location = PRED2_LOCATIONS[setIndex]; // Optionally randomize index inside the set
World world = tao.getWorld();
Location taoLocation = new Location(world, pred2Location.getX(), pred2Location.getY(), pred2Location.getZ());
dressPlayerAndPlaceItems(tao, "groupchase","light green","blue");
tao.sendMessage("The next trial is a group hunt.");
tao.teleport(taoLocation);
}
new BukkitRunnable() {
@Override
public void run() {
Player emre = Bukkit.getPlayer("caledonian26");
if (emre != null && emre.isOnline()) {
emre.sendMessage("30 seconds has passed.");
}
}
}.runTaskLater(this, 600);
}
}
if (event.getClickedBlock() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CRIMSON_BUTTON) {
if (event.getPlayer().getName().equals("caledonian26")) {
trialtype = "groupfollow";
Player tao = Bukkit.getPlayer("anna232224");
Player emre = Bukkit.getPlayer("caledonian26");
Player anna = Bukkit.getPlayer("TwentyPoet26227");
int setIndex = RANDOM.nextInt(4);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendTitle("Keep still!","Look at me jump!", 10, 70, 20);
}
if (emre != null) {
Location preyLocation = PREY_LOCATIONS[setIndex];
World world = emre.getWorld();
Location emreLocation = new Location(world, preyLocation.getX(), preyLocation.getY(), preyLocation.getZ());
dressPlayerAndPlaceItems(emre, "groupfollow", "white","white");
emre.teleport(emreLocation);
}
if (anna != null) {
Location pred1Location = PRED1_LOCATIONS[setIndex]; // Optionally randomize index inside the set
World world = anna.getWorld();
Location annaLocation = new Location(world, pred1Location.getX(), pred1Location.getY(), pred1Location.getZ());
dressPlayerAndPlaceItems(anna, "groupfollow","light green","white");
anna.teleport(annaLocation);
}
if (tao != null) {
Location pred2Location = PRED2_LOCATIONS[setIndex]; // Optionally randomize index inside the set
World world = tao.getWorld();
Location taoLocation = new Location(world, pred2Location.getX(), pred2Location.getY(), pred2Location.getZ());
dressPlayerAndPlaceItems(tao, "groupfollow","light green","white");
tao.sendMessage("The next trial is a group follow.");
tao.teleport(taoLocation);
}
new BukkitRunnable() {
@Override
public void run() {
Player emre = Bukkit.getPlayer("caledonian26");
if (emre != null && emre.isOnline()) {
emre.sendMessage("30 seconds has passed.");
}
}
}.runTaskLater(this, 600);
}
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.SPRUCE_BUTTON) {
if (event.getPlayer().getName().equals("caledonian26")) {
Player anna = Bukkit.getPlayer("TwentyPoet26227");
if (anna != null && anna.isOnline()) {
int x = ThreadLocalRandom.current().nextInt(2, 11);
String title = "Well done!";
String subtitle = "You caught the prey " + x + " times";
anna.sendTitle(title, subtitle, 10, 70, 20);
}
}
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.STRIPPED_ACACIA_WOOD) {
playerClicks2.clear();
if (grouppracticeChaseRunnable != null) {
grouppracticeChaseRunnable.cancel();
}
if (grouppracticeFollowRunnable != null) {
grouppracticeFollowRunnable.cancel();
}
if (groupFollowJUMP != null) {
groupFollowJUMP.cancel();
}
if (pred1FOLLOWJUMP != null) {
pred1FOLLOWJUMP.cancel();
}
if (pred2FOLLOWJUMP != null) {
pred2FOLLOWJUMP.cancel();
}
if (event.getPlayer().getName().equals("caledonian26")) {
try {
fileNameSuffix = "here";
String content = String.valueOf(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) +
" Player: " + event.getPlayer().getName() +
" Location: " + event.getPlayer().getLocation() +
" Material: " + event.getClickedBlock().getType() + "\n";
final File file = new File(dataFolder, "eventsworldtour" + event.getPlayer().getName() +
String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.OAK_WOOD) {
replaceBlocksWithAir1();
playerClicks2.clear();
if (grouppracticeChaseRunnable != null) {
grouppracticeChaseRunnable.cancel();
}
if (grouppracticeFollowRunnable != null) {
grouppracticeFollowRunnable.cancel();
}
if (groupFollowJUMP != null) {
groupFollowJUMP.cancel();
}
if (pred1FOLLOWJUMP != null) {
pred1FOLLOWJUMP.cancel();
}
if (pred2FOLLOWJUMP != null) {
pred2FOLLOWJUMP.cancel();
}
event.getPlayer().sendTitle("Runnables reset!", "", 10, 70, 20);
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.CHERRY_BUTTON) {
Player player = event.getPlayer();
Player emre = Bukkit.getPlayer("caledonian26");
Player anna = Bukkit.getPlayer("anna232224");
Player poet = Bukkit.getPlayer("TwentyPoet26227");
if (emre != null && emre.isOnline()) {
emre.sendTitle("Starting soon!", "Keep still", 10, 70, 20);
}
if (anna != null && anna.isOnline()) {
anna.sendTitle("Starting soon!", "Keep still", 10, 70, 20);
}
if (poet != null && poet.isOnline()) {
poet.sendTitle("Starting soon!", "Keep still", 10, 70, 20);
}
if (player.getName().equalsIgnoreCase("caledonian26")) {
player.setWalkSpeed(0.2f);
new BukkitRunnable() {
@Override
public void run() {
float randomSpeedVariation = 0.1f + (RANDOM.nextFloat() * 0.3f);
player.setWalkSpeed(randomSpeedVariation);
}
}.runTaskTimer(this, 100L, 100L);
}
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.STRIPPED_OAK_WOOD) {
Player player = event.getPlayer();
if (grouppracticeChaseRunnable != null) {
grouppracticeChaseRunnable.cancel();
}
if (grouppracticeFollowRunnable != null) {
grouppracticeFollowRunnable.cancel();
}
Player emre = Bukkit.getPlayer("caledonian26");
World world = emre.getWorld();
int setIndex = RANDOM.nextInt(4);
Player anna = Bukkit.getPlayer("anna232224");
if (anna != null && anna.isOnline()) {
anna.sendTitle("Time up!", "Stop Moving.", 10, 20, 10);
Location pred1Location = PRED1_LOCATIONS[setIndex];
Location annaLocation = new Location(world, pred1Location.getX(), pred1Location.getY(), pred1Location.getZ());
anna.teleport(annaLocation);
}
Player poet = Bukkit.getPlayer("TwentyPoet26227");
if (poet != null && poet.isOnline()) {
poet.sendTitle("Time up!", "Stop Moving.", 10, 20, 10);
Location pred2Location = PRED2_LOCATIONS[setIndex];
Location poetLocation = new Location(world, pred2Location.getX(), pred2Location.getY(), pred2Location.getZ());
poet.teleport(poetLocation);
}
Location preyLocation = PREY_LOCATIONS[setIndex];
Location emreLocation = new Location(world, preyLocation.getX(), preyLocation.getY(), preyLocation.getZ());
emre.teleport(emreLocation);
player.sendTitle(ChatColor.YELLOW + "END FOR YOU!", ChatColor.WHITE + " ", 10, 100, 10);
long currentTime = System.currentTimeMillis();
String playerName = player.getName();
long buttonPressTime = buttonPressTimes.get(playerName);
long timeDifferenceInSeconds = (currentTime - buttonPressTime) / 1000;
if (player.getName().equals("caledonian26")) {
if (trialtype.equals("groupchase")) {
fileNameSuffix = "here";
try {
String content = String.valueOf("End of chase:" + " " + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) + "\n" +
"Prey: " + player.getName() + "\n" +
" Time taken to catch prey: " + timeDifferenceInSeconds + "\n" +
" Location: " + player.getLocation() + "\n";
final File file = new File(dataFolder, "eventspracticegroupchasepart" + "anna232224" +
String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
else if (trialtype.equals("groupfollow")) {
fileNameSuffix = "here";
try {
String content = String.valueOf("End of follow:" + " " + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) + "\n" +
"Prey: " + player.getName() + "\n" +
" Length of trial: " + timeDifferenceInSeconds + "\n" +
" Location: " + player.getLocation() + "\n";
final File file = new File(dataFolder, "eventspracticegroupfollowpart" + "anna232224" +
String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.MOSS_CARPET) {
Player playerclick = event.getPlayer();
if (buttonPressTimes.containsKey(playerclick.getName()) &&
System.currentTimeMillis() - buttonPressTimes.get(playerclick.getName()) < COOLDOWN_DURATION) {
return;
}
buttonPressTimes.put(playerclick.getName(), System.currentTimeMillis());
if (event.getPlayer().getName().equals("caledonian26")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendTitle("Hunt!", "", 10, 20, 10);
}
if (trialtype.equals("groupchase")) {
try {
fileNameSuffix = "here";
String content = String.valueOf(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) +
" Player: " + event.getPlayer().getName() +
" Location at start of chase: " + event.getPlayer().getLocation() +
" Material: " + event.getClickedBlock().getType() + "\n";
final File file = new File(dataFolder, "eventspracticegroupchasepart" + "anna232224" +
String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
grouppracticeChaseRunnable = new BukkitRunnable() {
public void run() {
if (event.getClickedBlock().getType() == Material.MOSS_CARPET && trialtype.equals("groupchase")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
String playerName = player.getName();
if (playerName.equals("caledonian26")) {
for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
onlinePlayer.sendTitle("Time up!", "Stop Moving.", 10, 20, 10);
}
fileNameSuffix = "here";
try {
String content = String.valueOf("End of chase:" + " " + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) +
" Time taken to catch prey: " + "No prey caught on this trial" + "\n";
final File file = new File(dataFolder, "eventspracticegroupchasepart" + "anna232224" +
String.valueOf(new SimpleDateFormat("dd-MM-yyyy").format(new Date())) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}.runTaskLater(this, 1200);
new BukkitRunnable() {
public void run() {
if (!event.getPlayer().isOnline()) {
grouppracticeChaseRunnable.cancel();
this.cancel();
}
if (event.getPlayer().isDead()) {
grouppracticeChaseRunnable.cancel();
this.cancel();
}
}
}.runTaskTimer(this, 0, 1);
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.BROWN_CARPET) {
Player playerclick = event.getPlayer();
if (buttonPressTimes.containsKey(playerclick.getName()) &&
System.currentTimeMillis() - buttonPressTimes.get(playerclick.getName()) < COOLDOWN_DURATION) {
return;
}
buttonPressTimes.put(playerclick.getName(), System.currentTimeMillis());
if (playerclick.getName().equals("caledonian26")) {
for (Player Player : Bukkit.getServer().getOnlinePlayers()) {
Player.sendTitle("Follow!", "", 10, 20, 10);
}
if (trialtype.equals("groupfollow")) {
try {
fileNameSuffix = "here";
String content = String.valueOf(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) +
" Player: " + playerclick.getName() +
" Location at start of follow: " + playerclick.getLocation() +
" Material: " + event.getClickedBlock().getType() + "\n";
final File file = new File(dataFolder, "eventspracticegroupfollowpart" + "anna232224" +
new SimpleDateFormat("dd-MM-yyyy").format(new Date()) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
grouppracticeFollowRunnable = new BukkitRunnable() {
public void run() {
if (event.getClickedBlock().getType() == Material.BROWN_CARPET && trialtype.equals("groupfollow")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
String playerName = player.getName();
if (playerName.equals("caledonian26")) {
for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
onlinePlayer.sendTitle("Time up!", "Stop Moving.", 10, 20, 10);
}
try {
fileNameSuffix = "here";
String content = String.valueOf("Time at end of follow:" + " " + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())) +
" Player: " + event.getPlayer().getName() +
" length of follow: " + 60 + "\n";
final File file = new File(dataFolder, "eventspracticegroupfollowpart" + "anna232224" +
new SimpleDateFormat("dd-MM-yyyy").format(new Date()) + fileNameSuffix + ".log");
if (!file.exists()) {
file.createNewFile();
}
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}.runTaskLater(this, 1200);
new BukkitRunnable() {
public void run() {
if (!event.getPlayer().isOnline()) {
grouppracticeFollowRunnable.cancel();
this.cancel();
}
if (event.getPlayer().isDead()) {
grouppracticeFollowRunnable.cancel();
this.cancel();
}
}
}.runTaskTimer(this, 0, 1);
}
}