aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0006-Timings-v2.patch
blob: 5cc53cf041db346b2e2ab843ac22e137d2a496c8 (plain)
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 29 Feb 2016 18:48:17 -0600
Subject: [PATCH] Timings v2

TODO: Add #isStopping to FullServerTickHandler#stopTiming in patch 191
expose isRunning

diff --git a/src/main/java/co/aikar/timings/FullServerTickHandler.java b/src/main/java/co/aikar/timings/FullServerTickHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..43b85ce3a6c27a2f92c67d62bee7484c2652b72a
--- /dev/null
+++ b/src/main/java/co/aikar/timings/FullServerTickHandler.java
@@ -0,0 +1,85 @@
+package co.aikar.timings;
+
+import static co.aikar.timings.TimingsManager.*;
+
+import org.bukkit.Bukkit;
+import org.jetbrains.annotations.NotNull;
+
+public class FullServerTickHandler extends TimingHandler {
+    private static final TimingIdentifier IDENTITY = new TimingIdentifier("Minecraft", "Full Server Tick", null);
+    final TimingData minuteData;
+    double avgFreeMemory = -1D;
+    double avgUsedMemory = -1D;
+    FullServerTickHandler() {
+        super(IDENTITY);
+        minuteData = new TimingData(id);
+
+        TIMING_MAP.put(IDENTITY, this);
+    }
+
+    @NotNull
+    @Override
+    public Timing startTiming() {
+        if (TimingsManager.needsFullReset) {
+            TimingsManager.resetTimings();
+        } else if (TimingsManager.needsRecheckEnabled) {
+            TimingsManager.recheckEnabled();
+        }
+        return super.startTiming();
+    }
+
+    @Override
+    public void stopTiming() {
+        super.stopTiming();
+        if (!isEnabled()) {
+            return;
+        }
+        if (TimingHistory.timedTicks % 20 == 0) {
+            final Runtime runtime = Runtime.getRuntime();
+            double usedMemory = runtime.totalMemory() - runtime.freeMemory();
+            double freeMemory = runtime.maxMemory() - usedMemory;
+            if (this.avgFreeMemory == -1) {
+                this.avgFreeMemory = freeMemory;
+            } else {
+                this.avgFreeMemory = (this.avgFreeMemory * (59 / 60D)) + (freeMemory * (1 / 60D));
+            }
+
+            if (this.avgUsedMemory == -1) {
+                this.avgUsedMemory = usedMemory;
+            } else {
+                this.avgUsedMemory = (this.avgUsedMemory * (59 / 60D)) + (usedMemory * (1 / 60D));
+            }
+        }
+
+        long start = System.nanoTime();
+        TimingsManager.tick();
+        long diff = System.nanoTime() - start;
+        TIMINGS_TICK.addDiff(diff, null);
+        // addDiff for TIMINGS_TICK incremented this, bring it back down to 1 per tick.
+        record.setCurTickCount(record.getCurTickCount()-1);
+
+        minuteData.setCurTickTotal(record.getCurTickTotal());
+        minuteData.setCurTickCount(1);
+
+        boolean violated = isViolated();
+        minuteData.processTick(violated);
+        TIMINGS_TICK.processTick(violated);
+        processTick(violated);
+
+
+        if (TimingHistory.timedTicks % 1200 == 0) {
+            MINUTE_REPORTS.add(new TimingHistory.MinuteReport());
+            TimingHistory.resetTicks(false);
+            minuteData.reset();
+        }
+        if (TimingHistory.timedTicks % Timings.getHistoryInterval() == 0) {
+            TimingsManager.HISTORY.add(new TimingHistory());
+            TimingsManager.resetTimings();
+        }
+        Bukkit.getUnsafe().reportTimings();
+    }
+
+    boolean isViolated() {
+        return record.getCurTickTotal() > 50000000;
+    }
+}
diff --git a/src/main/java/co/aikar/timings/NullTimingHandler.java b/src/main/java/co/aikar/timings/NullTimingHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..9b45ce887b9172f30302b83fe24b99b76b16dac3
--- /dev/null
+++ b/src/main/java/co/aikar/timings/NullTimingHandler.java
@@ -0,0 +1,68 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public final class NullTimingHandler implements Timing {
+    public static final Timing NULL = new NullTimingHandler();
+    @NotNull
+    @Override
+    public Timing startTiming() {
+        return this;
+    }
+
+    @Override
+    public void stopTiming() {
+
+    }
+
+    @NotNull
+    @Override
+    public Timing startTimingIfSync() {
+        return this;
+    }
+
+    @Override
+    public void stopTimingIfSync() {
+
+    }
+
+    @Override
+    public void abort() {
+
+    }
+
+    @Nullable
+    @Override
+    public TimingHandler getTimingHandler() {
+        return null;
+    }
+
+    @Override
+    public void close() {
+
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimedEventExecutor.java b/src/main/java/co/aikar/timings/TimedEventExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..4e6e1b8e8aeb07e34536941d2cbfc25e5cfa6c27
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimedEventExecutor.java
@@ -0,0 +1,83 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import org.bukkit.Bukkit;
+import org.bukkit.event.Event;
+import org.bukkit.event.EventException;
+import org.bukkit.event.Listener;
+import org.bukkit.plugin.EventExecutor;
+import org.bukkit.plugin.Plugin;
+
+import java.lang.reflect.Method;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class TimedEventExecutor implements EventExecutor {
+
+    private final EventExecutor executor;
+    private final Timing timings;
+
+    /**
+     * Wraps an event executor and associates a timing handler to it.
+     *
+     * @param executor Executor to wrap
+     * @param plugin Owning plugin
+     * @param method EventHandler method
+     * @param eventClass Owning class
+     */
+    public TimedEventExecutor(@NotNull EventExecutor executor, @NotNull Plugin plugin, @Nullable Method method, @NotNull Class<? extends Event> eventClass) {
+        this.executor = executor;
+        String id;
+
+        if (method == null) {
+            if (executor.getClass().getEnclosingClass() != null) { // Oh Skript, how we love you
+                method = executor.getClass().getEnclosingMethod();
+            }
+        }
+
+        if (method != null) {
+            id = method.getDeclaringClass().getName();
+        } else {
+            id = executor.getClass().getName();
+        }
+
+
+        final String eventName = eventClass.getSimpleName();
+        boolean verbose = "BlockPhysicsEvent".equals(eventName);
+        this.timings = Timings.ofSafe(plugin, (verbose ? "## " : "") +
+            "Event: " + id + " (" + eventName + ")");
+    }
+
+    @Override
+    public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
+        if (event.isAsynchronous() || !Timings.timingsEnabled || !Bukkit.isPrimaryThread()) {
+            executor.execute(listener, event);
+            return;
+        }
+        try (Timing ignored = timings.startTiming()){
+            executor.execute(listener, event);
+        }
+    }
+}
diff --git a/src/main/java/co/aikar/timings/Timing.java b/src/main/java/co/aikar/timings/Timing.java
new file mode 100644
index 0000000000000000000000000000000000000000..a21e5ead5024fd0058c5e3302d8201dd249d32bc
--- /dev/null
+++ b/src/main/java/co/aikar/timings/Timing.java
@@ -0,0 +1,83 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Provides an ability to time sections of code within the Minecraft Server
+ */
+public interface Timing extends AutoCloseable {
+    /**
+     * Starts timing the execution until {@link #stopTiming()} is called.
+     *
+     * @return Timing
+     */
+    @NotNull
+    Timing startTiming();
+
+    /**
+     * <p>Stops timing and records the data. Propagates the data up to group handlers.</p>
+     *
+     * Will automatically be called when this Timing is used with try-with-resources
+     */
+    void stopTiming();
+
+    /**
+     * Starts timing the execution until {@link #stopTiming()} is called.
+     *
+     * But only if we are on the primary thread.
+     *
+     * @return Timing
+     */
+    @NotNull
+    Timing startTimingIfSync();
+
+    /**
+     * <p>Stops timing and records the data. Propagates the data up to group handlers.</p>
+     *
+     * <p>Will automatically be called when this Timing is used with try-with-resources</p>
+     *
+     * But only if we are on the primary thread.
+     */
+    void stopTimingIfSync();
+
+    /**
+     * @deprecated Doesn't do anything - Removed
+     */
+    @Deprecated
+    void abort();
+
+    /**
+     * Used internally to get the actual backing Handler in the case of delegated Handlers
+     *
+     * @return TimingHandler
+     */
+    @Nullable
+    TimingHandler getTimingHandler();
+
+    @Override
+    void close();
+}
diff --git a/src/main/java/co/aikar/timings/TimingData.java b/src/main/java/co/aikar/timings/TimingData.java
new file mode 100644
index 0000000000000000000000000000000000000000..a5d13a1e44edb861f45c83a9b4309fbf799d407d
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingData.java
@@ -0,0 +1,122 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import java.util.List;
+import org.jetbrains.annotations.NotNull;
+
+import static co.aikar.util.JSONUtil.toArray;
+
+/**
+ * <p>Lightweight object for tracking timing data</p>
+ *
+ * This is broken out to reduce memory usage
+ */
+class TimingData {
+    private final int id;
+    private int count = 0;
+    private int lagCount = 0;
+    private long totalTime = 0;
+    private long lagTotalTime = 0;
+    private int curTickCount = 0;
+    private long curTickTotal = 0;
+
+    TimingData(int id) {
+        this.id = id;
+    }
+
+    private TimingData(TimingData data) {
+        this.id = data.id;
+        this.totalTime = data.totalTime;
+        this.lagTotalTime = data.lagTotalTime;
+        this.count = data.count;
+        this.lagCount = data.lagCount;
+    }
+
+    void add(long diff) {
+        ++curTickCount;
+        curTickTotal += diff;
+    }
+
+    void processTick(boolean violated) {
+        totalTime += curTickTotal;
+        count += curTickCount;
+        if (violated) {
+            lagTotalTime += curTickTotal;
+            lagCount += curTickCount;
+        }
+        curTickTotal = 0;
+        curTickCount = 0;
+    }
+
+    void reset() {
+        count = 0;
+        lagCount = 0;
+        curTickTotal = 0;
+        curTickCount = 0;
+        totalTime = 0;
+        lagTotalTime = 0;
+    }
+
+    protected TimingData clone() {
+        return new TimingData(this);
+    }
+
+    @NotNull
+    List<Object> export() {
+        List<Object> list = toArray(
+            id,
+            count,
+            totalTime);
+        if (lagCount > 0) {
+            list.add(lagCount);
+            list.add(lagTotalTime);
+        }
+        return list;
+    }
+
+    boolean hasData() {
+        return count > 0;
+    }
+
+    long getTotalTime() {
+        return totalTime;
+    }
+
+    int getCurTickCount() {
+        return curTickCount;
+    }
+
+    void setCurTickCount(int curTickCount) {
+        this.curTickCount = curTickCount;
+    }
+
+    long getCurTickTotal() {
+        return curTickTotal;
+    }
+
+    void setCurTickTotal(long curTickTotal) {
+        this.curTickTotal = curTickTotal;
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingHandler.java b/src/main/java/co/aikar/timings/TimingHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..199789d56d22fcb1b77ebd56805cc28aa5a5ab0a
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingHandler.java
@@ -0,0 +1,226 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import co.aikar.util.LoadingIntMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.bukkit.Bukkit;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+class TimingHandler implements Timing {
+
+    private static AtomicInteger idPool = new AtomicInteger(1);
+    private static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
+    final int id = idPool.getAndIncrement();
+
+    final TimingIdentifier identifier;
+    private final boolean verbose;
+
+    private final Int2ObjectOpenHashMap<TimingData> children = new LoadingIntMap<>(TimingData::new);
+
+    final TimingData record;
+    private TimingHandler startParent;
+    private final TimingHandler groupHandler;
+
+    private long start = 0;
+    private int timingDepth = 0;
+    private boolean added;
+    private boolean timed;
+    private boolean enabled;
+
+    TimingHandler(@NotNull TimingIdentifier id) {
+        this.identifier = id;
+        this.verbose = id.name.startsWith("##");
+        this.record = new TimingData(this.id);
+        this.groupHandler = id.groupHandler;
+
+        TimingIdentifier.getGroup(id.group).handlers.add(this);
+        checkEnabled();
+    }
+
+    final void checkEnabled() {
+        enabled = Timings.timingsEnabled && (!verbose || Timings.verboseEnabled);
+    }
+
+    void processTick(boolean violated) {
+        if (timingDepth != 0 || record.getCurTickCount() == 0) {
+            timingDepth = 0;
+            start = 0;
+            return;
+        }
+
+        record.processTick(violated);
+        for (TimingData handler : children.values()) {
+            handler.processTick(violated);
+        }
+    }
+
+    @NotNull
+    @Override
+    public Timing startTimingIfSync() {
+        startTiming();
+        return this;
+    }
+
+    @Override
+    public void stopTimingIfSync() {
+        stopTiming();
+    }
+
+    @NotNull
+    public Timing startTiming() {
+        if (!enabled || !Bukkit.isPrimaryThread()) {
+            return this;
+        }
+        if (++timingDepth == 1) {
+            startParent = TIMING_STACK.peekLast();
+            start = System.nanoTime();
+        }
+        TIMING_STACK.addLast(this);
+        return this;
+    }
+
+    public void stopTiming() {
+        if (!enabled || timingDepth <= 0 || start == 0 || !Bukkit.isPrimaryThread()) {
+            return;
+        }
+
+        popTimingStack();
+        if (--timingDepth == 0) {
+            addDiff(System.nanoTime() - start, startParent);
+            startParent = null;
+            start = 0;
+        }
+    }
+
+    private void popTimingStack() {
+        TimingHandler last;
+        while ((last = TIMING_STACK.removeLast()) != this) {
+            last.timingDepth = 0;
+            if ("Minecraft".equalsIgnoreCase(last.identifier.group)) {
+                Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Look above this for any errors and report this to Paper unless it has a plugin in the stack trace (" + last.identifier + " did not stopTiming)");
+            } else {
+                Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to the plugin " + last.identifier.group + " (Look for errors above this in the logs) (" + last.identifier + " did not stopTiming)", new Throwable());
+            }
+
+            boolean found = TIMING_STACK.contains(this);
+            if (!found) {
+                // We aren't even in the stack... Don't pop everything
+                TIMING_STACK.addLast(last);
+                break;
+            }
+        }
+    }
+
+    @Override
+    public final void abort() {
+
+    }
+
+    void addDiff(long diff, @Nullable TimingHandler parent) {
+        if (parent != null) {
+            parent.children.get(id).add(diff);
+        }
+
+        record.add(diff);
+        if (!added) {
+            added = true;
+            timed = true;
+            TimingsManager.HANDLERS.add(this);
+        }
+        if (groupHandler != null) {
+            groupHandler.addDiff(diff, parent);
+            groupHandler.children.get(id).add(diff);
+        }
+    }
+
+    /**
+     * Reset this timer, setting all values to zero.
+     */
+    void reset(boolean full) {
+        record.reset();
+        if (full) {
+            timed = false;
+        }
+        start = 0;
+        timingDepth = 0;
+        added = false;
+        children.clear();
+        checkEnabled();
+    }
+
+    @NotNull
+    @Override
+    public TimingHandler getTimingHandler() {
+        return this;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return (this == o);
+    }
+
+    @Override
+    public int hashCode() {
+        return id;
+    }
+
+    /**
+     * This is simply for the Closeable interface so it can be used with try-with-resources ()
+     */
+    @Override
+    public void close() {
+        stopTimingIfSync();
+    }
+
+    public boolean isSpecial() {
+        return this == TimingsManager.FULL_SERVER_TICK || this == TimingsManager.TIMINGS_TICK;
+    }
+
+    boolean isTimed() {
+        return timed;
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    @NotNull
+    TimingData[] cloneChildren() {
+        final TimingData[] clonedChildren = new TimingData[children.size()];
+        int i = 0;
+        for (TimingData child : children.values()) {
+            clonedChildren[i++] = child.clone();
+        }
+        return clonedChildren;
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingHistory.java b/src/main/java/co/aikar/timings/TimingHistory.java
new file mode 100644
index 0000000000000000000000000000000000000000..ddaed81275fcc12d1671b668697acf318e96888b
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingHistory.java
@@ -0,0 +1,354 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import co.aikar.timings.TimingHistory.RegionData.RegionId;
+import com.google.common.base.Function;
+import com.google.common.collect.Sets;
+import org.bukkit.Bukkit;
+import org.bukkit.Chunk;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.block.BlockState;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import co.aikar.util.LoadingMap;
+import co.aikar.util.MRUMapCache;
+
+import java.lang.management.ManagementFactory;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static co.aikar.timings.TimingsManager.FULL_SERVER_TICK;
+import static co.aikar.timings.TimingsManager.MINUTE_REPORTS;
+import static co.aikar.util.JSONUtil.*;
+
+@SuppressWarnings({"deprecation", "SuppressionAnnotation", "Convert2Lambda", "Anonymous2MethodRef"})
+public class TimingHistory {
+    public static long lastMinuteTime;
+    public static long timedTicks;
+    public static long playerTicks;
+    public static long entityTicks;
+    public static long tileEntityTicks;
+    public static long activatedEntityTicks;
+    private static int worldIdPool = 1;
+    static Map<String, Integer> worldMap = LoadingMap.newHashMap(new Function<String, Integer>() {
+        @NotNull
+        @Override
+        public Integer apply(@Nullable String input) {
+            return worldIdPool++;
+        }
+    });
+    private final long endTime;
+    private final long startTime;
+    private final long totalTicks;
+    private final long totalTime; // Represents all time spent running the server this history
+    private final MinuteReport[] minuteReports;
+
+    private final TimingHistoryEntry[] entries;
+    final Set<Material> tileEntityTypeSet = Sets.newHashSet();
+    final Set<EntityType> entityTypeSet = Sets.newHashSet();
+    private final Map<Object, Object> worlds;
+
+    TimingHistory() {
+        this.endTime = System.currentTimeMillis() / 1000;
+        this.startTime = TimingsManager.historyStart / 1000;
+        if (timedTicks % 1200 != 0 || MINUTE_REPORTS.isEmpty()) {
+            this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size() + 1]);
+            this.minuteReports[this.minuteReports.length - 1] = new MinuteReport();
+        } else {
+            this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size()]);
+        }
+        long ticks = 0;
+        for (MinuteReport mp : this.minuteReports) {
+            ticks += mp.ticksRecord.timed;
+        }
+        this.totalTicks = ticks;
+        this.totalTime = FULL_SERVER_TICK.record.getTotalTime();
+        this.entries = new TimingHistoryEntry[TimingsManager.HANDLERS.size()];
+
+        int i = 0;
+        for (TimingHandler handler : TimingsManager.HANDLERS) {
+            entries[i++] = new TimingHistoryEntry(handler);
+        }
+
+        // Information about all loaded chunks/entities
+        //noinspection unchecked
+        this.worlds = toObjectMapper(Bukkit.getWorlds(), new Function<World, JSONPair>() {
+            @NotNull
+            @Override
+            public JSONPair apply(World world) {
+                Map<RegionId, RegionData> regions = LoadingMap.newHashMap(RegionData.LOADER);
+
+                for (Chunk chunk : world.getLoadedChunks()) {
+                    RegionData data = regions.get(new RegionId(chunk.getX(), chunk.getZ()));
+
+                    for (Entity entity : chunk.getEntities()) {
+                        if (entity == null) {
+                            Bukkit.getLogger().warning("Null entity detected in chunk at position x: " + chunk.getX() + ", z: " + chunk.getZ());
+                            continue;
+                        }
+
+                        data.entityCounts.get(entity.getType()).increment();
+                    }
+
+                    for (BlockState tileEntity : chunk.getTileEntities()) {
+                        if (tileEntity == null) {
+                            Bukkit.getLogger().warning("Null tileentity detected in chunk at position x: " + chunk.getX() + ", z: " + chunk.getZ());
+                            continue;
+                        }
+
+                        data.tileEntityCounts.get(tileEntity.getBlock().getType()).increment();
+                    }
+                }
+                return pair(
+                    worldMap.get(world.getName()),
+                    toArrayMapper(regions.values(),new Function<RegionData, Object>() {
+                        @NotNull
+                        @Override
+                        public Object apply(RegionData input) {
+                            return toArray(
+                                input.regionId.x,
+                                input.regionId.z,
+                                toObjectMapper(input.entityCounts.entrySet(),
+                                    new Function<Map.Entry<EntityType, Counter>, JSONPair>() {
+                                        @NotNull
+                                        @Override
+                                        public JSONPair apply(Map.Entry<EntityType, Counter> entry) {
+                                            entityTypeSet.add(entry.getKey());
+                                            return pair(
+                                                    String.valueOf(entry.getKey().ordinal()),
+                                                    entry.getValue().count()
+                                            );
+                                        }
+                                    }
+                                ),
+                                toObjectMapper(input.tileEntityCounts.entrySet(),
+                                    new Function<Map.Entry<Material, Counter>, JSONPair>() {
+                                        @NotNull
+                                        @Override
+                                        public JSONPair apply(Map.Entry<Material, Counter> entry) {
+                                            tileEntityTypeSet.add(entry.getKey());
+                                            return pair(
+                                                    String.valueOf(entry.getKey().ordinal()),
+                                                    entry.getValue().count()
+                                            );
+                                        }
+                                    }
+                                )
+                            );
+                        }
+                    })
+                );
+            }
+        });
+    }
+    static class RegionData {
+        final RegionId regionId;
+        @SuppressWarnings("Guava")
+        static Function<RegionId, RegionData> LOADER = new Function<RegionId, RegionData>() {
+            @NotNull
+            @Override
+            public RegionData apply(@NotNull RegionId id) {
+                return new RegionData(id);
+            }
+        };
+        RegionData(@NotNull RegionId id) {
+            this.regionId = id;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            RegionData that = (RegionData) o;
+
+            return regionId.equals(that.regionId);
+
+        }
+
+        @Override
+        public int hashCode() {
+            return regionId.hashCode();
+        }
+
+        @SuppressWarnings("unchecked")
+        final Map<EntityType, Counter> entityCounts = MRUMapCache.of(LoadingMap.of(
+                new EnumMap<EntityType, Counter>(EntityType.class), k -> new Counter()
+        ));
+        @SuppressWarnings("unchecked")
+        final Map<Material, Counter> tileEntityCounts = MRUMapCache.of(LoadingMap.of(
+                new EnumMap<Material, Counter>(Material.class), k -> new Counter()
+        ));
+
+        static class RegionId {
+            final int x, z;
+            final long regionId;
+            RegionId(int x, int z) {
+                this.x = x >> 5 << 5;
+                this.z = z >> 5 << 5;
+                this.regionId = ((long) (this.x) << 32) + (this.z >> 5 << 5) - Integer.MIN_VALUE;
+            }
+
+            @Override
+            public boolean equals(Object o) {
+                if (this == o) return true;
+                if (o == null || getClass() != o.getClass()) return false;
+
+                RegionId regionId1 = (RegionId) o;
+
+                return regionId == regionId1.regionId;
+
+            }
+
+            @Override
+            public int hashCode() {
+                return (int) (regionId ^ (regionId >>> 32));
+            }
+        }
+    }
+    static void resetTicks(boolean fullReset) {
+        if (fullReset) {
+            // Non full is simply for 1 minute reports
+            timedTicks = 0;
+        }
+        lastMinuteTime = System.nanoTime();
+        playerTicks = 0;
+        tileEntityTicks = 0;
+        entityTicks = 0;
+        activatedEntityTicks = 0;
+    }
+
+    @NotNull
+    Object export() {
+        return createObject(
+            pair("s", startTime),
+            pair("e", endTime),
+            pair("tk", totalTicks),
+            pair("tm", totalTime),
+            pair("w", worlds),
+            pair("h", toArrayMapper(entries, new Function<TimingHistoryEntry, Object>() {
+                @Nullable
+                @Override
+                public Object apply(TimingHistoryEntry entry) {
+                    TimingData record = entry.data;
+                    if (!record.hasData()) {
+                        return null;
+                    }
+                    return entry.export();
+                }
+            })),
+            pair("mp", toArrayMapper(minuteReports, new Function<MinuteReport, Object>() {
+                @NotNull
+                @Override
+                public Object apply(MinuteReport input) {
+                    return input.export();
+                }
+            }))
+        );
+    }
+
+    static class MinuteReport {
+        final long time = System.currentTimeMillis() / 1000;
+
+        final TicksRecord ticksRecord = new TicksRecord();
+        final PingRecord pingRecord = new PingRecord();
+        final TimingData fst = TimingsManager.FULL_SERVER_TICK.minuteData.clone();
+        final double tps = 1E9 / ( System.nanoTime() - lastMinuteTime ) * ticksRecord.timed;
+        final double usedMemory = TimingsManager.FULL_SERVER_TICK.avgUsedMemory;
+        final double freeMemory = TimingsManager.FULL_SERVER_TICK.avgFreeMemory;
+        final double loadAvg = ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();
+
+        @NotNull
+        List<Object> export() {
+            return toArray(
+                time,
+                Math.round(tps * 100D) / 100D,
+                Math.round(pingRecord.avg * 100D) / 100D,
+                fst.export(),
+                toArray(ticksRecord.timed,
+                    ticksRecord.player,
+                    ticksRecord.entity,
+                    ticksRecord.activatedEntity,
+                    ticksRecord.tileEntity
+                ),
+                usedMemory,
+                freeMemory,
+                loadAvg
+            );
+        }
+    }
+
+    private static class TicksRecord {
+        final long timed;
+        final long player;
+        final long entity;
+        final long tileEntity;
+        final long activatedEntity;
+
+        TicksRecord() {
+            timed = timedTicks - (TimingsManager.MINUTE_REPORTS.size() * 1200);
+            player = playerTicks;
+            entity = entityTicks;
+            tileEntity = tileEntityTicks;
+            activatedEntity = activatedEntityTicks;
+        }
+
+    }
+
+    private static class PingRecord {
+        final double avg;
+
+        PingRecord() {
+            final Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
+            int totalPing = 0;
+            for (Player player : onlinePlayers) {
+                totalPing += player.spigot().getPing();
+            }
+            avg = onlinePlayers.isEmpty() ? 0 : totalPing / onlinePlayers.size();
+        }
+    }
+
+
+    private static class Counter {
+        private int count = 0;
+        public int increment() {
+            return ++count;
+        }
+        public int count() {
+            return count;
+        }
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingHistoryEntry.java b/src/main/java/co/aikar/timings/TimingHistoryEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..86d5ac6bd0d7d0003688761aceb3f3343575319f
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingHistoryEntry.java
@@ -0,0 +1,58 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import com.google.common.base.Function;
+
+import java.util.List;
+import org.jetbrains.annotations.NotNull;
+
+import static co.aikar.util.JSONUtil.toArrayMapper;
+
+class TimingHistoryEntry {
+    final TimingData data;
+    private final TimingData[] children;
+
+    TimingHistoryEntry(@NotNull TimingHandler handler) {
+        this.data = handler.record.clone();
+        children = handler.cloneChildren();
+    }
+
+    @NotNull
+    List<Object> export() {
+        List<Object> result = data.export();
+        if (children.length > 0) {
+            result.add(
+                toArrayMapper(children, new Function<TimingData, Object>() {
+                    @NotNull
+                    @Override
+                    public Object apply(TimingData child) {
+                        return child.export();
+                    }
+                })
+            );
+        }
+        return result;
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingIdentifier.java b/src/main/java/co/aikar/timings/TimingIdentifier.java
new file mode 100644
index 0000000000000000000000000000000000000000..df142a89b8c43acb81eb383eac0ef048a1f49a6e
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingIdentifier.java
@@ -0,0 +1,116 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import co.aikar.util.LoadingMap;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * <p>Used as a basis for fast HashMap key comparisons for the Timing Map.</p>
+ *
+ * This class uses interned strings giving us the ability to do an identity check instead of equals() on the strings
+ */
+final class TimingIdentifier {
+    /**
+     * Holds all groups. Autoloads on request for a group by name.
+     */
+    static final Map<String, TimingGroup> GROUP_MAP = LoadingMap.of(new ConcurrentHashMap<>(64, .5F), TimingGroup::new);
+    private static final TimingGroup DEFAULT_GROUP = getGroup("Minecraft");
+    final String group;
+    final String name;
+    final TimingHandler groupHandler;
+    private final int hashCode;
+
+    TimingIdentifier(@Nullable String group, @NotNull String name, @Nullable Timing groupHandler) {
+        this.group = group != null ? group: DEFAULT_GROUP.name;
+        this.name = name;
+        this.groupHandler = groupHandler != null ? groupHandler.getTimingHandler() : null;
+        this.hashCode = (31 * this.group.hashCode()) + this.name.hashCode();
+    }
+
+    @NotNull
+    static TimingGroup getGroup(@Nullable String groupName) {
+        if (groupName == null) {
+            //noinspection ConstantConditions
+            return DEFAULT_GROUP;
+        }
+
+        return GROUP_MAP.get(groupName);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null) {
+            return false;
+        }
+
+        TimingIdentifier that = (TimingIdentifier) o;
+        return Objects.equals(group, that.group) && Objects.equals(name, that.name);
+    }
+
+    @Override
+    public int hashCode() {
+        return hashCode;
+    }
+
+    @Override
+    public String toString() {
+        return "TimingIdentifier{id=" + group + ":" + name +'}';
+    }
+
+    static class TimingGroup {
+
+        private static AtomicInteger idPool = new AtomicInteger(1);
+        final int id = idPool.getAndIncrement();
+
+        final String name;
+        final List<TimingHandler> handlers = Collections.synchronizedList(new ArrayList<>(64));
+
+        private TimingGroup(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+            TimingGroup that = (TimingGroup) o;
+            return id == that.id;
+        }
+
+        @Override
+        public int hashCode() {
+            return id;
+        }
+    }
+}
diff --git a/src/main/java/co/aikar/timings/Timings.java b/src/main/java/co/aikar/timings/Timings.java
new file mode 100644
index 0000000000000000000000000000000000000000..da76e1aaee1dee794e38ddd4e0a28e0071e90bbf
--- /dev/null
+++ b/src/main/java/co/aikar/timings/Timings.java
@@ -0,0 +1,296 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.EvictingQueue;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.Validate;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.plugin.Plugin;
+
+import java.util.List;
+import java.util.Queue;
+import java.util.logging.Level;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@SuppressWarnings({"UnusedDeclaration", "WeakerAccess", "SameParameterValue"})
+public final class Timings {
+
+    final static List<CommandSender> requestingReport = Lists.newArrayList();
+    private static final int MAX_HISTORY_FRAMES = 12;
+    public static final Timing NULL_HANDLER = new NullTimingHandler();
+    static boolean timingsEnabled = false;
+    static boolean verboseEnabled = false;
+    private static int historyInterval = -1;
+    private static int historyLength = -1;
+
+    private Timings() {}
+
+    /**
+     * Returns a Timing for a plugin corresponding to a name.
+     *
+     * @param plugin Plugin to own the Timing
+     * @param name   Name of Timing
+     * @return Handler
+     */
+    @NotNull
+    public static Timing of(@NotNull Plugin plugin, @NotNull String name) {
+        Timing pluginHandler = null;
+        if (plugin != null) {
+            pluginHandler = ofSafe(plugin.getName(), "Combined Total", TimingsManager.PLUGIN_GROUP_HANDLER);
+        }
+        return of(plugin, name, pluginHandler);
+    }
+
+    /**
+     * <p>Returns a handler that has a groupHandler timer handler. Parent timers should not have their
+     * start/stop methods called directly, as the children will call it for you.</p>
+     *
+     * Parent Timers are used to group multiple subsections together and get a summary of them combined
+     * Parent Handler can not be changed after first call
+     *
+     * @param plugin       Plugin to own the Timing
+     * @param name         Name of Timing
+     * @param groupHandler Parent handler to mirror .start/stop calls to
+     * @return Timing Handler
+     */
+    @NotNull
+    public static Timing of(@NotNull Plugin plugin, @NotNull String name, @Nullable Timing groupHandler) {
+        Preconditions.checkNotNull(plugin, "Plugin can not be null");
+        return TimingsManager.getHandler(plugin.getName(), name, groupHandler);
+    }
+
+    /**
+     * Returns a Timing object after starting it, useful for Java7 try-with-resources.
+     *
+     * try (Timing ignored = Timings.ofStart(plugin, someName)) {
+     * // timed section
+     * }
+     *
+     * @param plugin Plugin to own the Timing
+     * @param name   Name of Timing
+     * @return Timing Handler
+     */
+    @NotNull
+    public static Timing ofStart(@NotNull Plugin plugin, @NotNull String name) {
+        return ofStart(plugin, name, null);
+    }
+
+    /**
+     * Returns a Timing object after starting it, useful for Java7 try-with-resources.
+     *
+     * try (Timing ignored = Timings.ofStart(plugin, someName, groupHandler)) {
+     * // timed section
+     * }
+     *
+     * @param plugin       Plugin to own the Timing
+     * @param name         Name of Timing
+     * @param groupHandler Parent handler to mirror .start/stop calls to
+     * @return Timing Handler
+     */
+    @NotNull
+    public static Timing ofStart(@NotNull Plugin plugin, @NotNull String name, @Nullable Timing groupHandler) {
+        Timing timing = of(plugin, name, groupHandler);
+        timing.startTiming();
+        return timing;
+    }
+
+    /**
+     * Gets whether or not the Spigot Timings system is enabled
+     *
+     * @return Enabled or not
+     */
+    public static boolean isTimingsEnabled() {
+        return timingsEnabled;
+    }
+
+    /**
+     * <p>Sets whether or not the Spigot Timings system should be enabled</p>
+     *
+     * Calling this will reset timing data.
+     *
+     * @param enabled Should timings be reported
+     */
+    public static void setTimingsEnabled(boolean enabled) {
+        timingsEnabled = enabled;
+        reset();
+    }
+
+    /**
+     * <p>Sets whether or not the Timings should monitor at Verbose level.</p>
+     *
+     * <p>When Verbose is disabled, high-frequency timings will not be available.</p>
+     *
+     * @return Enabled or not
+     */
+    public static boolean isVerboseTimingsEnabled() {
+        return verboseEnabled;
+    }
+
+    /**
+     * <p>Sets whether or not the Timings should monitor at Verbose level.</p>
+     *
+     * When Verbose is disabled, high-frequency timings will not be available.
+     * Calling this will reset timing data.
+     *
+     * @param enabled Should high-frequency timings be reported
+     */
+    public static void setVerboseTimingsEnabled(boolean enabled) {
+        verboseEnabled = enabled;
+        TimingsManager.needsRecheckEnabled = true;
+    }
+
+    /**
+     * <p>Gets the interval between Timing History report generation.</p>
+     *
+     * Defaults to 5 minutes (6000 ticks)
+     *
+     * @return Interval in ticks
+     */
+    public static int getHistoryInterval() {
+        return historyInterval;
+    }
+
+    /**
+     * <p>Sets the interval between Timing History report generations.</p>
+     *
+     * <p>Defaults to 5 minutes (6000 ticks)</p>
+     *
+     * This will recheck your history length, so lowering this value will lower your
+     * history length if you need more than 60 history windows.
+     *
+     * @param interval Interval in ticks
+     */
+    public static void setHistoryInterval(int interval) {
+        historyInterval = Math.max(20*60, interval);
+        // Recheck the history length with the new Interval
+        if (historyLength != -1) {
+            setHistoryLength(historyLength);
+        }
+    }
+
+    /**
+     * Gets how long in ticks Timings history is kept for the server.
+     *
+     * Defaults to 1 hour (72000 ticks)
+     *
+     * @return Duration in Ticks
+     */
+    public static int getHistoryLength() {
+        return historyLength;
+    }
+
+    /**
+     * Sets how long Timing History reports are kept for the server.
+     *
+     * Defaults to 1 hours(72000 ticks)
+     *
+     * This value is capped at a maximum of getHistoryInterval() * MAX_HISTORY_FRAMES (12)
+     *
+     * Will not reset Timing Data but may truncate old history if the new length is less than old length.
+     *
+     * @param length Duration in ticks
+     */
+    public static void setHistoryLength(int length) {
+        // Cap at 12 History Frames, 1 hour at 5 minute frames.
+        int maxLength = historyInterval * MAX_HISTORY_FRAMES;
+        // For special cases of servers with special permission to bypass the max.
+        // This max helps keep data file sizes reasonable for processing on Aikar's Timing parser side.
+        // Setting this will not help you bypass the max unless Aikar has added an exception on the API side.
+        if (System.getProperty("timings.bypassMax") != null) {
+            maxLength = Integer.MAX_VALUE;
+        }
+        historyLength = Math.max(Math.min(maxLength, length), historyInterval);
+        Queue<TimingHistory> oldQueue = TimingsManager.HISTORY;
+        int frames = (getHistoryLength() / getHistoryInterval());
+        if (length > maxLength) {
+            Bukkit.getLogger().log(Level.WARNING, "Timings Length too high. Requested " + length + ", max is " + maxLength + ". To get longer history, you must increase your interval. Set Interval to " + Math.ceil(length / MAX_HISTORY_FRAMES) + " to achieve this length.");
+        }
+        TimingsManager.HISTORY = EvictingQueue.create(frames);
+        TimingsManager.HISTORY.addAll(oldQueue);
+    }
+
+    /**
+     * Resets all Timing Data
+     */
+    public static void reset() {
+        TimingsManager.reset();
+    }
+
+    /**
+     * Generates a report and sends it to the specified command sender.
+     *
+     * If sender is null, ConsoleCommandSender will be used.
+     * @param sender The sender to send to, or null to use the ConsoleCommandSender
+     */
+    public static void generateReport(@Nullable CommandSender sender) {
+        if (sender == null) {
+            sender = Bukkit.getConsoleSender();
+        }
+        requestingReport.add(sender);
+    }
+
+    /**
+     * Generates a report and sends it to the specified listener.
+     * Use with {@link org.bukkit.command.BufferedCommandSender} to get full response when done!
+     * @param sender The listener to send responses too.
+     */
+    public static void generateReport(@NotNull TimingsReportListener sender) {
+        Validate.notNull(sender);
+        requestingReport.add(sender);
+    }
+
+    /*
+    =================
+    Protected API: These are for internal use only in Bukkit/CraftBukkit
+    These do not have isPrimaryThread() checks in the startTiming/stopTiming
+    =================
+    */
+    @NotNull
+    static TimingHandler ofSafe(@NotNull String name) {
+        return ofSafe(null, name, null);
+    }
+
+    @NotNull
+    static Timing ofSafe(@Nullable Plugin plugin, @NotNull String name) {
+        Timing pluginHandler = null;
+        if (plugin != null) {
+            pluginHandler = ofSafe(plugin.getName(), "Combined Total", TimingsManager.PLUGIN_GROUP_HANDLER);
+        }
+        return ofSafe(plugin != null ? plugin.getName() : "Minecraft - Invalid Plugin", name, pluginHandler);
+    }
+
+    @NotNull
+    static TimingHandler ofSafe(@NotNull String name, @Nullable Timing groupHandler) {
+        return ofSafe(null, name, groupHandler);
+    }
+
+    @NotNull
+    static TimingHandler ofSafe(@Nullable String groupName, @NotNull String name, @Nullable Timing groupHandler) {
+        return TimingsManager.getHandler(groupName, name, groupHandler);
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingsCommand.java b/src/main/java/co/aikar/timings/TimingsCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..f7c2245a310a084367ff25db539b3c967d5cb141
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsCommand.java
@@ -0,0 +1,119 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang.Validate;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.defaults.BukkitCommand;
+import org.bukkit.util.StringUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+
+public class TimingsCommand extends BukkitCommand {
+    private static final List<String> TIMINGS_SUBCOMMANDS = ImmutableList.of("report", "reset", "on", "off", "paste", "verbon", "verboff");
+    private long lastResetAttempt = 0;
+
+    public TimingsCommand(@NotNull String name) {
+        super(name);
+        this.description = "Manages Spigot Timings data to see performance of the server.";
+        this.usageMessage = "/timings <reset|report|on|off|verbon|verboff>";
+        this.setPermission("bukkit.command.timings");
+    }
+
+    @Override
+    public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
+        if (!testPermission(sender)) {
+            return true;
+        }
+        if (args.length < 1) {
+            sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+            return true;
+        }
+        final String arg = args[0];
+        if ("on".equalsIgnoreCase(arg)) {
+            Timings.setTimingsEnabled(true);
+            sender.sendMessage("Enabled Timings & Reset");
+            return true;
+        } else if ("off".equalsIgnoreCase(arg)) {
+            Timings.setTimingsEnabled(false);
+            sender.sendMessage("Disabled Timings");
+            return true;
+        }
+
+        if (!Timings.isTimingsEnabled()) {
+            sender.sendMessage("Please enable timings by typing /timings on");
+            return true;
+        }
+
+        long now = System.currentTimeMillis();
+        if ("verbon".equalsIgnoreCase(arg)) {
+            Timings.setVerboseTimingsEnabled(true);
+            sender.sendMessage("Enabled Verbose Timings");
+            return true;
+        } else if ("verboff".equalsIgnoreCase(arg)) {
+            Timings.setVerboseTimingsEnabled(false);
+            sender.sendMessage("Disabled Verbose Timings");
+            return true;
+        } else if ("reset".equalsIgnoreCase(arg)) {
+            if (now - lastResetAttempt < 30000) {
+                TimingsManager.reset();
+                sender.sendMessage(ChatColor.RED + "Timings reset. Please wait 5-10 minutes before using /timings report.");
+            } else {
+                lastResetAttempt = now;
+                sender.sendMessage(ChatColor.RED + "WARNING: Timings v2 should not be reset. If you are encountering lag, please wait 3 minutes and then issue a report. The best timings will include 10+ minutes, with data before and after your lag period. If you really want to reset, run this command again within 30 seconds.");
+            }
+        } else  if (
+            "paste".equalsIgnoreCase(arg) ||
+                "report".equalsIgnoreCase(arg) ||
+                "get".equalsIgnoreCase(arg) ||
+                "merged".equalsIgnoreCase(arg) ||
+                "separate".equalsIgnoreCase(arg)
+            ) {
+            Timings.generateReport(sender);
+        } else {
+            sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+        }
+        return true;
+    }
+
+    @NotNull
+    @Override
+    public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
+        Validate.notNull(sender, "Sender cannot be null");
+        Validate.notNull(args, "Arguments cannot be null");
+        Validate.notNull(alias, "Alias cannot be null");
+
+        if (args.length == 1) {
+            return StringUtil.copyPartialMatches(args[0], TIMINGS_SUBCOMMANDS,
+                new ArrayList<String>(TIMINGS_SUBCOMMANDS.size()));
+        }
+        return ImmutableList.of();
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingsManager.java b/src/main/java/co/aikar/timings/TimingsManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..a92925d41110226f7fda055b71ce7be60eedd038
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsManager.java
@@ -0,0 +1,188 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import co.aikar.util.LoadingMap;
+import com.google.common.collect.EvictingQueue;
+import org.bukkit.Bukkit;
+import org.bukkit.Server;
+import org.bukkit.command.Command;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.PluginClassLoader;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public final class TimingsManager {
+    static final Map<TimingIdentifier, TimingHandler> TIMING_MAP = LoadingMap.of(
+        new ConcurrentHashMap<>(4096, .5F), TimingHandler::new
+    );
+    public static final FullServerTickHandler FULL_SERVER_TICK = new FullServerTickHandler();
+    public static final TimingHandler TIMINGS_TICK = Timings.ofSafe("Timings Tick", FULL_SERVER_TICK);
+    public static final Timing PLUGIN_GROUP_HANDLER = Timings.ofSafe("Plugins");
+    public static String url = "https://timings.aikar.co/";
+    public static List<String> hiddenConfigs = new ArrayList<String>();
+    public static boolean privacy = false;
+
+    static final List<TimingHandler> HANDLERS = new ArrayList<>(1024);
+    static final List<TimingHistory.MinuteReport> MINUTE_REPORTS = new ArrayList<>(64);
+
+    static EvictingQueue<TimingHistory> HISTORY = EvictingQueue.create(12);
+    static long timingStart = 0;
+    static long historyStart = 0;
+    static boolean needsFullReset = false;
+    static boolean needsRecheckEnabled = false;
+
+    private TimingsManager() {}
+
+    /**
+     * Resets all timing data on the next tick
+     */
+    static void reset() {
+        needsFullReset = true;
+    }
+
+    /**
+     * Ticked every tick by CraftBukkit to count the number of times a timer
+     * caused TPS loss.
+     */
+    static void tick() {
+        if (Timings.timingsEnabled) {
+            boolean violated = FULL_SERVER_TICK.isViolated();
+
+            for (TimingHandler handler : HANDLERS) {
+                if (handler.isSpecial()) {
+                    // We manually call this
+                    continue;
+                }
+                handler.processTick(violated);
+            }
+
+            TimingHistory.playerTicks += Bukkit.getOnlinePlayers().size();
+            TimingHistory.timedTicks++;
+            // Generate TPS/Ping/Tick reports every minute
+        }
+    }
+    static void stopServer() {
+        Timings.timingsEnabled = false;
+        recheckEnabled();
+    }
+    static void recheckEnabled() {
+        synchronized (TIMING_MAP) {
+            for (TimingHandler timings : TIMING_MAP.values()) {
+                timings.checkEnabled();
+            }
+        }
+        needsRecheckEnabled = false;
+    }
+    static void resetTimings() {
+        if (needsFullReset) {
+            // Full resets need to re-check every handlers enabled state
+            // Timing map can be modified from async so we must sync on it.
+            synchronized (TIMING_MAP) {
+                for (TimingHandler timings : TIMING_MAP.values()) {
+                    timings.reset(true);
+                }
+            }
+            Bukkit.getLogger().log(Level.INFO, "Timings Reset");
+            HISTORY.clear();
+            needsFullReset = false;
+            needsRecheckEnabled = false;
+            timingStart = System.currentTimeMillis();
+        } else {
+            // Soft resets only need to act on timings that have done something
+            // Handlers can only be modified on main thread.
+            for (TimingHandler timings : HANDLERS) {
+                timings.reset(false);
+            }
+        }
+
+        HANDLERS.clear();
+        MINUTE_REPORTS.clear();
+
+        TimingHistory.resetTicks(true);
+        historyStart = System.currentTimeMillis();
+    }
+
+    @NotNull
+    static TimingHandler getHandler(@Nullable String group, @NotNull String name, @Nullable Timing parent) {
+        return TIMING_MAP.get(new TimingIdentifier(group, name, parent));
+    }
+
+
+    /**
+     * <p>Due to access restrictions, we need a helper method to get a Command TimingHandler with String group</p>
+     *
+     * Plugins should never call this
+     *
+     * @param pluginName Plugin this command is associated with
+     * @param command    Command to get timings for
+     * @return TimingHandler
+     */
+    @NotNull
+    public static Timing getCommandTiming(@Nullable String pluginName, @NotNull Command command) {
+        Plugin plugin = null;
+        final Server server = Bukkit.getServer();
+        if (!(  server == null || pluginName == null ||
+                "minecraft".equals(pluginName) || "bukkit".equals(pluginName) ||
+                "spigot".equalsIgnoreCase(pluginName) || "paper".equals(pluginName)
+        )) {
+            plugin = server.getPluginManager().getPlugin(pluginName);
+        }
+        if (plugin == null) {
+            // Plugin is passing custom fallback prefix, try to look up by class loader
+            plugin = getPluginByClassloader(command.getClass());
+        }
+        if (plugin == null) {
+            return Timings.ofSafe("Command: " + pluginName + ":" + command.getTimingName());
+        }
+
+        return Timings.ofSafe(plugin, "Command: " + pluginName + ":" + command.getTimingName());
+    }
+
+    /**
+     * Looks up the class loader for the specified class, and if it is a PluginClassLoader, return the
+     * Plugin that created this class.
+     *
+     * @param clazz Class to check
+     * @return Plugin if created by a plugin
+     */
+    @Nullable
+    public static Plugin getPluginByClassloader(@Nullable Class<?> clazz) {
+        if (clazz == null) {
+            return null;
+        }
+        final ClassLoader classLoader = clazz.getClassLoader();
+        if (classLoader instanceof PluginClassLoader) {
+            PluginClassLoader pluginClassLoader = (PluginClassLoader) classLoader;
+            return pluginClassLoader.getPlugin();
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/co/aikar/timings/TimingsReportListener.java b/src/main/java/co/aikar/timings/TimingsReportListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..ef58a6c00f444bd498a2d8fc4e457236f393954f
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsReportListener.java
@@ -0,0 +1,77 @@
+package co.aikar.timings;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.Validate;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.command.MessageCommandSender;
+import org.bukkit.command.RemoteConsoleCommandSender;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@SuppressWarnings("WeakerAccess")
+public class TimingsReportListener implements MessageCommandSender {
+    private final List<CommandSender> senders;
+    private final Runnable onDone;
+    private String timingsURL;
+
+    public TimingsReportListener(@NotNull CommandSender senders) {
+        this(senders, null);
+    }
+    public TimingsReportListener(@NotNull CommandSender sender, @Nullable Runnable onDone) {
+        this(Lists.newArrayList(sender), onDone);
+    }
+    public TimingsReportListener(@NotNull List<CommandSender> senders) {
+        this(senders, null);
+    }
+    public TimingsReportListener(@NotNull List<CommandSender> senders, @Nullable Runnable onDone) {
+        Validate.notNull(senders);
+        Validate.notEmpty(senders);
+
+        this.senders = Lists.newArrayList(senders);
+        this.onDone = onDone;
+    }
+
+    @Nullable
+    public String getTimingsURL() {
+        return timingsURL;
+    }
+
+    public void done() {
+        done(null);
+    }
+
+    public void done(@Nullable String url) {
+        this.timingsURL = url;
+        if (onDone != null) {
+            onDone.run();
+        }
+        for (CommandSender sender : senders) {
+            if (sender instanceof TimingsReportListener) {
+                ((TimingsReportListener) sender).done();
+            }
+        }
+    }
+
+    @Override
+    public void sendMessage(@NotNull String message) {
+        senders.forEach((sender) -> sender.sendMessage(message));
+    }
+
+    public void addConsoleIfNeeded() {
+        boolean hasConsole = false;
+        for (CommandSender sender : this.senders) {
+            if (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender) {
+                hasConsole = true;
+            }
+        }
+        if (!hasConsole) {
+            this.senders.add(Bukkit.getConsoleSender());
+        }
+    }
+}
diff --git a/src/main/java/co/aikar/timings/UnsafeTimingHandler.java b/src/main/java/co/aikar/timings/UnsafeTimingHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..632c4961515f5052551f841cfa840e60bba7a257
--- /dev/null
+++ b/src/main/java/co/aikar/timings/UnsafeTimingHandler.java
@@ -0,0 +1,53 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.timings;
+
+import org.bukkit.Bukkit;
+import org.jetbrains.annotations.NotNull;
+
+class UnsafeTimingHandler extends TimingHandler {
+
+    UnsafeTimingHandler(@NotNull TimingIdentifier id) {
+        super(id);
+    }
+
+    private static void checkThread() {
+        if (!Bukkit.isPrimaryThread()) {
+            throw new IllegalStateException("Calling Timings from Async Operation");
+        }
+    }
+
+    @NotNull
+    @Override
+    public Timing startTiming() {
+        checkThread();
+        return super.startTiming();
+    }
+
+    @Override
+    public void stopTiming() {
+        checkThread();
+        super.stopTiming();
+    }
+}
diff --git a/src/main/java/co/aikar/util/Counter.java b/src/main/java/co/aikar/util/Counter.java
new file mode 100644
index 0000000000000000000000000000000000000000..eff63c371c39e21a5a9cb5af8c2dcf78a60dd52b
--- /dev/null
+++ b/src/main/java/co/aikar/util/Counter.java
@@ -0,0 +1,38 @@
+package co.aikar.util;
+
+import com.google.common.collect.ForwardingMap;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class Counter <T> extends ForwardingMap<T, Long> {
+    private final Map<T, Long> counts = new HashMap<>();
+
+    public long decrement(@Nullable T key) {
+        return increment(key, -1);
+    }
+    public long increment(@Nullable T key) {
+        return increment(key, 1);
+    }
+    public long decrement(@Nullable T key, long amount) {
+        return increment(key, -amount);
+    }
+    public long increment(@Nullable T key, long amount) {
+        Long count = this.getCount(key);
+        count += amount;
+        this.counts.put(key, count);
+        return count;
+    }
+
+    public long getCount(@Nullable T key) {
+        return this.counts.getOrDefault(key, 0L);
+    }
+
+    @NotNull
+    @Override
+    protected Map<T, Long> delegate() {
+        return this.counts;
+    }
+}
diff --git a/src/main/java/co/aikar/util/JSONUtil.java b/src/main/java/co/aikar/util/JSONUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..190bf0598442c89c2a1c93ad7c8c1a29797304ae
--- /dev/null
+++ b/src/main/java/co/aikar/util/JSONUtil.java
@@ -0,0 +1,140 @@
+package co.aikar.util;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Provides Utility methods that assist with generating JSON Objects
+ */
+@SuppressWarnings({"rawtypes", "SuppressionAnnotation"})
+public final class JSONUtil {
+    private JSONUtil() {}
+
+    /**
+     * Creates a key/value "JSONPair" object
+     *
+     * @param key Key to use
+     * @param obj Value to use
+     * @return JSONPair
+     */
+    @NotNull
+    public static JSONPair pair(@NotNull String key, @Nullable Object obj) {
+        return new JSONPair(key, obj);
+    }
+
+    @NotNull
+    public static JSONPair pair(long key, @Nullable Object obj) {
+        return new JSONPair(String.valueOf(key), obj);
+    }
+
+    /**
+     * Creates a new JSON object from multiple JSONPair key/value pairs
+     *
+     * @param data JSONPairs
+     * @return Map
+     */
+    @NotNull
+    public static Map<String, Object> createObject(@NotNull JSONPair... data) {
+        return appendObjectData(new LinkedHashMap(), data);
+    }
+
+    /**
+     * This appends multiple key/value Obj pairs into a JSON Object
+     *
+     * @param parent Map to be appended to
+     * @param data Data to append
+     * @return Map
+     */
+    @NotNull
+    public static Map<String, Object> appendObjectData(@NotNull Map parent, @NotNull JSONPair... data) {
+        for (JSONPair JSONPair : data) {
+            parent.put(JSONPair.key, JSONPair.val);
+        }
+        return parent;
+    }
+
+    /**
+     * This builds a JSON array from a set of data
+     *
+     * @param data Data to build JSON array from
+     * @return List
+     */
+    @NotNull
+    public static List toArray(@NotNull Object... data) {
+        return Lists.newArrayList(data);
+    }
+
+    /**
+     * These help build a single JSON array using a mapper function
+     *
+     * @param collection Collection to apply to
+     * @param mapper Mapper to apply
+     * @param <E> Element Type
+     * @return List
+     */
+    @NotNull
+    public static <E> List toArrayMapper(@NotNull E[] collection, @NotNull Function<E, Object> mapper) {
+        return toArrayMapper(Lists.newArrayList(collection), mapper);
+    }
+
+    @NotNull
+    public static <E> List toArrayMapper(@NotNull Iterable<E> collection, @NotNull Function<E, Object> mapper) {
+        List array = Lists.newArrayList();
+        for (E e : collection) {
+            Object object = mapper.apply(e);
+            if (object != null) {
+                array.add(object);
+            }
+        }
+        return array;
+    }
+
+    /**
+     * These help build a single JSON Object from a collection, using a mapper function
+     *
+     * @param collection Collection to apply to
+     * @param mapper Mapper to apply
+     * @param <E> Element Type
+     * @return Map
+     */
+    @NotNull
+    public static <E> Map toObjectMapper(@NotNull E[] collection, @NotNull Function<E, JSONPair> mapper) {
+        return toObjectMapper(Lists.newArrayList(collection), mapper);
+    }
+
+    @NotNull
+    public static <E> Map toObjectMapper(@NotNull Iterable<E> collection, @NotNull Function<E, JSONPair> mapper) {
+        Map object = Maps.newLinkedHashMap();
+        for (E e : collection) {
+            JSONPair JSONPair = mapper.apply(e);
+            if (JSONPair != null) {
+                object.put(JSONPair.key, JSONPair.val);
+            }
+        }
+        return object;
+    }
+
+    /**
+     * Simply stores a key and a value, used internally by many methods below.
+     */
+    @SuppressWarnings("PublicInnerClass")
+    public static class JSONPair {
+        final String key;
+        final Object val;
+
+        JSONPair(@NotNull String key, @NotNull Object val) {
+            this.key = key;
+            this.val = val;
+        }
+    }
+}
diff --git a/src/main/java/co/aikar/util/LoadingIntMap.java b/src/main/java/co/aikar/util/LoadingIntMap.java
new file mode 100644
index 0000000000000000000000000000000000000000..63a899c7dbdb69daa4876a2ce2a7dfb734b5af9d
--- /dev/null
+++ b/src/main/java/co/aikar/util/LoadingIntMap.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015. Starlis LLC / dba Empire Minecraft
+ *
+ * This source code is proprietary software and must not be redistributed without Starlis LLC's approval
+ *
+ */
+package co.aikar.util;
+
+
+import com.google.common.base.Function;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Allows you to pass a Loader function that when a key is accessed that doesn't exist,
+ * automatically loads the entry into the map by calling the loader Function.
+ *
+ * .get() Will only return null if the Loader can return null.
+ *
+ * You may pass any backing Map to use.
+ *
+ * This class is not thread safe and should be wrapped with Collections.synchronizedMap on the OUTSIDE of the LoadingMap if needed.
+ *
+ * Do not wrap the backing map with Collections.synchronizedMap.
+ *
+ * @param <V> Value
+ */
+public class LoadingIntMap<V> extends Int2ObjectOpenHashMap<V> {
+    private final Function<Integer, V> loader;
+
+    public LoadingIntMap(@NotNull Function<Integer, V> loader) {
+        super();
+        this.loader = loader;
+    }
+
+    public LoadingIntMap(int expectedSize, @NotNull Function<Integer, V> loader) {
+        super(expectedSize);
+        this.loader = loader;
+    }
+
+    public LoadingIntMap(int expectedSize, float loadFactor, @NotNull Function<Integer, V> loader) {
+        super(expectedSize, loadFactor);
+        this.loader = loader;
+    }
+
+
+    @Nullable
+    @Override
+    public V get(int key) {
+        V res = super.get(key);
+        if (res == null) {
+            res = loader.apply(key);
+            if (res != null) {
+                put(key, res);
+            }
+        }
+        return res;
+    }
+
+    /**
+     * Due to java stuff, you will need to cast it to (Function) for some cases
+     *
+     * @param <T> Type
+     */
+    public abstract static class Feeder <T> implements Function<T, T> {
+        @Nullable
+        @Override
+        public T apply(@Nullable Object input) {
+            return apply();
+        }
+
+        @Nullable
+        public abstract T apply();
+    }
+}
diff --git a/src/main/java/co/aikar/util/LoadingMap.java b/src/main/java/co/aikar/util/LoadingMap.java
new file mode 100644
index 0000000000000000000000000000000000000000..aedbb03321886cb267879d7994653e447b485f6a
--- /dev/null
+++ b/src/main/java/co/aikar/util/LoadingMap.java
@@ -0,0 +1,368 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.util;
+
+import com.google.common.base.Preconditions;
+import java.lang.reflect.Constructor;
+import java.util.AbstractMap;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Allows you to pass a Loader function that when a key is accessed that doesn't exists,
+ * automatically loads the entry into the map by calling the loader Function.
+ *
+ * .get() Will only return null if the Loader can return null.
+ *
+ * You may pass any backing Map to use.
+ *
+ * This class is not thread safe and should be wrapped with Collections.synchronizedMap on the OUTSIDE of the LoadingMap if needed.
+ *
+ * Do not wrap the backing map with Collections.synchronizedMap.
+ *
+ * @param <K> Key
+ * @param <V> Value
+ */
+public class LoadingMap <K, V> extends AbstractMap<K, V> {
+    private final Map<K, V> backingMap;
+    private final java.util.function.Function<K, V> loader;
+
+    /**
+     * Initializes an auto loading map using specified loader and backing map
+     * @param backingMap Map to wrap
+     * @param loader Loader
+     */
+    public LoadingMap(@NotNull Map<K, V> backingMap, @NotNull java.util.function.Function<K, V> loader) {
+        this.backingMap = backingMap;
+        this.loader = loader;
+    }
+
+    /**
+     * Creates a new LoadingMap with the specified map and loader
+     *
+     * @param backingMap Actual map being used.
+     * @param loader Loader to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> of(@NotNull Map<K, V> backingMap, @NotNull Function<K, V> loader) {
+        return new LoadingMap<>(backingMap, loader);
+    }
+
+    /**
+     * Creates a LoadingMap with an auto instantiating loader.
+     *
+     * Will auto construct class of of Value when not found
+     *
+     * Since this uses Reflection, It is more effecient to define your own static loader
+     * than using this helper, but if performance is not critical, this is easier.
+     *
+     * @param backingMap Actual map being used.
+     * @param keyClass Class used for the K generic
+     * @param valueClass Class used for the V generic
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map that auto instantiates on .get()
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newAutoMap(@NotNull Map<K, V> backingMap, @Nullable final Class<? extends K> keyClass,
+                                              @NotNull final Class<? extends V> valueClass) {
+        return new LoadingMap<>(backingMap, new AutoInstantiatingLoader<>(keyClass, valueClass));
+    }
+    /**
+     * Creates a LoadingMap with an auto instantiating loader.
+     *
+     * Will auto construct class of of Value when not found
+     *
+     * Since this uses Reflection, It is more effecient to define your own static loader
+     * than using this helper, but if performance is not critical, this is easier.
+     *
+     * @param backingMap Actual map being used.
+     * @param valueClass Class used for the V generic
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map that auto instantiates on .get()
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newAutoMap(@NotNull Map<K, V> backingMap,
+                                              @NotNull final Class<? extends V> valueClass) {
+        return newAutoMap(backingMap, null, valueClass);
+    }
+
+    /**
+     * @see #newAutoMap
+     *
+     * new Auto initializing map using a HashMap.
+     *
+     * @param keyClass Class used for the K generic
+     * @param valueClass Class used for the V generic
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map that auto instantiates on .get()
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashAutoMap(@Nullable final Class<? extends K> keyClass, @NotNull final Class<? extends V> valueClass) {
+        return newAutoMap(new HashMap<>(), keyClass, valueClass);
+    }
+
+    /**
+     * @see #newAutoMap
+     *
+     * new Auto initializing map using a HashMap.
+     *
+     * @param valueClass Class used for the V generic
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map that auto instantiates on .get()
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashAutoMap(@NotNull final Class<? extends V> valueClass) {
+        return newHashAutoMap(null, valueClass);
+    }
+
+    /**
+     * @see #newAutoMap
+     *
+     * new Auto initializing map using a HashMap.
+     *
+     * @param keyClass Class used for the K generic
+     * @param valueClass Class used for the V generic
+     * @param initialCapacity Initial capacity to use
+     * @param loadFactor Load factor to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map that auto instantiates on .get()
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashAutoMap(@Nullable final Class<? extends K> keyClass, @NotNull final Class<? extends V> valueClass, int initialCapacity, float loadFactor) {
+        return newAutoMap(new HashMap<>(initialCapacity, loadFactor), keyClass, valueClass);
+    }
+
+    /**
+     * @see #newAutoMap
+     *
+     * new Auto initializing map using a HashMap.
+     *
+     * @param valueClass Class used for the V generic
+     * @param initialCapacity Initial capacity to use
+     * @param loadFactor Load factor to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return  Map that auto instantiates on .get()
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashAutoMap(@NotNull final Class<? extends V> valueClass, int initialCapacity, float loadFactor) {
+        return newHashAutoMap(null, valueClass, initialCapacity, loadFactor);
+    }
+
+    /**
+     * Initializes an auto loading map using a HashMap
+     *
+     * @param loader Loader to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashMap(@NotNull Function<K, V> loader) {
+        return new LoadingMap<>(new HashMap<>(), loader);
+    }
+
+    /**
+     * Initializes an auto loading map using a HashMap
+     *
+     * @param loader Loader to use
+     * @param initialCapacity Initial capacity to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashMap(@NotNull Function<K, V> loader, int initialCapacity) {
+        return new LoadingMap<>(new HashMap<>(initialCapacity), loader);
+    }
+    /**
+     * Initializes an auto loading map using a HashMap
+     *
+     * @param loader Loader to use
+     * @param initialCapacity Initial capacity to use
+     * @param loadFactor Load factor to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newHashMap(@NotNull Function<K, V> loader, int initialCapacity, float loadFactor) {
+        return new LoadingMap<>(new HashMap<>(initialCapacity, loadFactor), loader);
+    }
+
+    /**
+     * Initializes an auto loading map using an Identity HashMap
+     *
+     * @param loader Loader to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newIdentityHashMap(@NotNull Function<K, V> loader) {
+        return new LoadingMap<>(new IdentityHashMap<>(), loader);
+    }
+
+    /**
+     * Initializes an auto loading map using an Identity HashMap
+     *
+     * @param loader Loader to use
+     * @param initialCapacity Initial capacity to use
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> newIdentityHashMap(@NotNull Function<K, V> loader, int initialCapacity) {
+        return new LoadingMap<>(new IdentityHashMap<>(initialCapacity), loader);
+    }
+
+    @Override
+    public int size() {return backingMap.size();}
+
+    @Override
+    public boolean isEmpty() {return backingMap.isEmpty();}
+
+    @Override
+    public boolean containsKey(@Nullable Object key) {return backingMap.containsKey(key);}
+
+    @Override
+    public boolean containsValue(@Nullable Object value) {return backingMap.containsValue(value);}
+
+    @Nullable
+    @Override
+    public V get(@Nullable Object key) {
+        V v = backingMap.get(key);
+        if (v != null) {
+            return v;
+        }
+        return backingMap.computeIfAbsent((K) key, loader);
+    }
+
+    @Nullable
+    public V put(@Nullable K key, @Nullable V value) {return backingMap.put(key, value);}
+
+    @Nullable
+    @Override
+    public V remove(@Nullable Object key) {return backingMap.remove(key);}
+
+    public void putAll(@NotNull Map<? extends K, ? extends V> m) {backingMap.putAll(m);}
+
+    @Override
+    public void clear() {backingMap.clear();}
+
+    @NotNull
+    @Override
+    public Set<K> keySet() {return backingMap.keySet();}
+
+    @NotNull
+    @Override
+    public Collection<V> values() {return backingMap.values();}
+
+    @Override
+    public boolean equals(@Nullable Object o) {return backingMap.equals(o);}
+
+    @Override
+    public int hashCode() {return backingMap.hashCode();}
+
+    @NotNull
+    @Override
+    public Set<Entry<K, V>> entrySet() {
+        return backingMap.entrySet();
+    }
+
+    @NotNull
+    public LoadingMap<K, V> clone() {
+        return new LoadingMap<>(backingMap, loader);
+    }
+
+    private static class AutoInstantiatingLoader<K, V> implements Function<K, V> {
+        final Constructor<? extends V> constructor;
+        private final Class<? extends V> valueClass;
+
+        AutoInstantiatingLoader(@Nullable Class<? extends K> keyClass, @NotNull Class<? extends V> valueClass) {
+            try {
+                this.valueClass = valueClass;
+                if (keyClass != null) {
+                    constructor = valueClass.getConstructor(keyClass);
+                } else {
+                    constructor = null;
+                }
+            } catch (NoSuchMethodException e) {
+                throw new IllegalStateException(
+                    valueClass.getName() + " does not have a constructor for " + (keyClass != null ? keyClass.getName() : null));
+            }
+        }
+
+        @NotNull
+        @Override
+        public V apply(@Nullable K input) {
+            try {
+                return (constructor != null ? constructor.newInstance(input) : valueClass.newInstance());
+            } catch (Exception e) {
+                throw new ExceptionInInitializerError(e);
+            }
+        }
+
+        @Override
+        public int hashCode() {
+            return super.hashCode();
+        }
+
+        @Override
+        public boolean equals(Object object) {
+            return false;
+        }
+    }
+
+    /**
+     * Due to java stuff, you will need to cast it to (Function) for some cases
+     *
+     * @param <T> Type
+     */
+    public abstract static class Feeder <T> implements Function<T, T> {
+        @Nullable
+        @Override
+        public T apply(@Nullable Object input) {
+            return apply();
+        }
+
+        @Nullable
+        public abstract T apply();
+    }
+}
diff --git a/src/main/java/co/aikar/util/MRUMapCache.java b/src/main/java/co/aikar/util/MRUMapCache.java
new file mode 100644
index 0000000000000000000000000000000000000000..5989ee21297935651b0edd44b8239e655eaef1d9
--- /dev/null
+++ b/src/main/java/co/aikar/util/MRUMapCache.java
@@ -0,0 +1,111 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package co.aikar.util;
+
+import java.util.AbstractMap;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implements a Most Recently Used cache in front of a backing map, to quickly access the last accessed result.
+ *
+ * @param <K> Key Type of the Map
+ * @param <V> Value Type of the Map
+ */
+public class MRUMapCache<K, V> extends AbstractMap<K, V> {
+    final Map<K, V> backingMap;
+    Object cacheKey;
+    V cacheValue;
+    public MRUMapCache(@NotNull final Map<K, V> backingMap) {
+        this.backingMap = backingMap;
+    }
+
+    public int size() {return backingMap.size();}
+
+    public boolean isEmpty() {return backingMap.isEmpty();}
+
+    public boolean containsKey(@Nullable Object key) {
+        return key != null && key.equals(cacheKey) || backingMap.containsKey(key);
+    }
+
+    public boolean containsValue(@Nullable Object value) {
+        return value != null && value == cacheValue || backingMap.containsValue(value);
+    }
+
+    @Nullable
+    public V get(@Nullable Object key) {
+        if (cacheKey != null && cacheKey.equals(key)) {
+            return cacheValue;
+        }
+        cacheKey = key;
+        return cacheValue = backingMap.get(key);
+    }
+
+    @Nullable
+    public V put(@Nullable K key, @Nullable V value) {
+        cacheKey = key;
+        return cacheValue = backingMap.put(key, value);
+    }
+
+    @Nullable
+    public V remove(@Nullable Object key) {
+        if (key != null && key.equals(cacheKey)) {
+            cacheKey = null;
+        }
+        return backingMap.remove(key);
+    }
+
+    public void putAll(@NotNull Map<? extends K, ? extends V> m) {backingMap.putAll(m);}
+
+    public void clear() {
+        cacheKey = null;
+        cacheValue = null;
+        backingMap.clear();
+    }
+
+    @NotNull
+    public Set<K> keySet() {return backingMap.keySet();}
+
+    @NotNull
+    public Collection<V> values() {return backingMap.values();}
+
+    @NotNull
+    public Set<Map.Entry<K, V>> entrySet() {return backingMap.entrySet();}
+
+    /**
+     * Wraps the specified map with a most recently used cache
+     *
+     * @param map Map to be wrapped
+     * @param <K> Key Type of the Map
+     * @param <V> Value Type of the Map
+     * @return Map
+     */
+    @NotNull
+    public static <K, V> Map<K, V> of(@NotNull Map<K, V> map) {
+        return new MRUMapCache<K, V>(map);
+    }
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 806aeee78956fc79fda62c706f40d3edd2ef8388..a238302f2a12194aa30a88867070705dc749b36b 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -704,7 +704,6 @@ public final class Bukkit {
      */
     public static void reload() {
         server.reload();
-        org.spigotmc.CustomTimingsHandler.reload(); // Spigot
     }
 
     /**
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 70d711b51e6bb3860c17e631fe5892b6bde9b245..3e91c4000c468fd8bdcb938e942a7bbf4988cab2 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1465,6 +1465,26 @@ public interface Server extends PluginMessageRecipient {
             throw new UnsupportedOperationException("Not supported yet.");
         }
 
+        // Paper start
+        @NotNull
+        public org.bukkit.configuration.file.YamlConfiguration getBukkitConfig()
+        {
+            throw new UnsupportedOperationException( "Not supported yet." );
+        }
+
+        @NotNull
+        public org.bukkit.configuration.file.YamlConfiguration getSpigotConfig()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @NotNull
+        public org.bukkit.configuration.file.YamlConfiguration getPaperConfig()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+        // Paper end
+
         /**
          * Sends the component to the player
          *
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 247d194f86c00db11acbc58e7d163b2606db4f07..945b8b030d1b2a13afc0c4efad76997eb7bf00ba 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -18,6 +18,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
 @Deprecated
 public interface UnsafeValues {
 
+    void reportTimings(); // Paper
     Material toLegacy(Material material);
 
     Material fromLegacy(Material material);
@@ -69,4 +70,12 @@ public interface UnsafeValues {
      * @return true if a file matching this key was found and deleted
      */
     boolean removeAdvancement(NamespacedKey key);
+
+    // Paper start
+    /**
+     * Server name to report to timings v2
+     * @return name
+     */
+    String getTimingsServerName();
+    // Paper end
 }
diff --git a/src/main/java/org/bukkit/command/BufferedCommandSender.java b/src/main/java/org/bukkit/command/BufferedCommandSender.java
new file mode 100644
index 0000000000000000000000000000000000000000..f9a00aecca5ec41b460bf41dfe1c69694768cf98
--- /dev/null
+++ b/src/main/java/org/bukkit/command/BufferedCommandSender.java
@@ -0,0 +1,21 @@
+package org.bukkit.command;
+
+import org.jetbrains.annotations.NotNull;
+
+public class BufferedCommandSender implements MessageCommandSender {
+    private final StringBuffer buffer = new StringBuffer();
+    @Override
+    public void sendMessage(@NotNull String message) {
+        buffer.append(message);
+        buffer.append("\n");
+    }
+
+    @NotNull
+    public String getBuffer() {
+        return buffer.toString();
+    }
+
+    public void reset() {
+        this.buffer.setLength(0);
+    }
+}
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index 4bfc214685164a38ba4261b2bae7faa8a3bd297e..03bdc1622791e1206406c87065978688d602e39e 100644
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -33,7 +33,8 @@ public abstract class Command {
     protected String usageMessage;
     private String permission;
     private String permissionMessage;
-    public org.spigotmc.CustomTimingsHandler timings; // Spigot
+    public co.aikar.timings.Timing timings; // Paper
+    @NotNull public String getTimingName() {return getName();} // Paper
 
     protected Command(@NotNull String name) {
         this(name, "", "/" + name, new ArrayList<String>());
@@ -47,7 +48,6 @@ public abstract class Command {
         this.usageMessage = (usageMessage == null) ? "/" + name : usageMessage;
         this.aliases = aliases;
         this.activeAliases = new ArrayList<String>(aliases);
-        this.timings = new org.spigotmc.CustomTimingsHandler("** Command: " + name); // Spigot
     }
 
     /**
@@ -245,7 +245,6 @@ public abstract class Command {
         }
         this.nextLabel = name;
         if (!isRegistered()) {
-            this.timings = new org.spigotmc.CustomTimingsHandler("** Command: " + name); // Spigot
             this.label = name;
             return true;
         }
diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
index d6c8938b1e13b63116b7b0e074ea8ef5997f8dc3..a6ad94ef98a1df1d2842635d850bc990b0137849 100644
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
@@ -9,6 +9,7 @@ public class FormattedCommandAlias extends Command {
 
     public FormattedCommandAlias(@NotNull String alias, @NotNull String[] formatStrings) {
         super(alias);
+        timings = co.aikar.timings.TimingsManager.getCommandTiming("minecraft", this); // Spigot
         this.formatStrings = formatStrings;
     }
 
@@ -113,6 +114,10 @@ public class FormattedCommandAlias extends Command {
         return formatString;
     }
 
+    @NotNull
+    @Override // Paper
+    public String getTimingName() {return "Command Forwarder - " + super.getTimingName();} // Paper
+
     private static boolean inRange(int i, int j, int k) {
         return i >= j && i <= k;
     }
diff --git a/src/main/java/org/bukkit/command/MessageCommandSender.java b/src/main/java/org/bukkit/command/MessageCommandSender.java
new file mode 100644
index 0000000000000000000000000000000000000000..a7ef1f51c2b96617a32e6e7b1723e8770ba8a6a8
--- /dev/null
+++ b/src/main/java/org/bukkit/command/MessageCommandSender.java
@@ -0,0 +1,129 @@
+package org.bukkit.command;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.bukkit.Bukkit;
+import org.bukkit.Server;
+import org.bukkit.permissions.Permission;
+import org.bukkit.permissions.PermissionAttachment;
+import org.bukkit.permissions.PermissionAttachmentInfo;
+import org.bukkit.plugin.Plugin;
+
+import java.util.Set;
+import java.util.UUID;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * For when all you care about is just messaging
+ */
+public interface MessageCommandSender extends CommandSender {
+
+    @Override
+    default void sendMessage(@NotNull String[] messages) {
+        for (String message : messages) {
+            sendMessage(message);
+        }
+    }
+
+    @Override
+    default void sendMessage(@Nullable UUID sender, @NotNull String message) {
+        sendMessage(message);
+    }
+
+    @Override
+    default void sendMessage(@Nullable UUID sender, @NotNull String[] messages) {
+        for (String message : messages) {
+            sendMessage(message);
+        }
+    }
+
+    @NotNull
+    @Override
+    default Server getServer() {
+        return Bukkit.getServer();
+    }
+
+    @NotNull
+    @Override
+    default String getName() {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default boolean isOp() {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default void setOp(boolean value) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default boolean isPermissionSet(@NotNull String name) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default boolean isPermissionSet(@NotNull Permission perm) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default boolean hasPermission(@NotNull String name) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default boolean hasPermission(@NotNull Permission perm) {
+        throw new NotImplementedException();
+    }
+
+    @NotNull
+    @Override
+    default PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) {
+        throw new NotImplementedException();
+    }
+
+    @NotNull
+    @Override
+    default PermissionAttachment addAttachment(@NotNull Plugin plugin) {
+        throw new NotImplementedException();
+    }
+
+    @NotNull
+    @Override
+    default PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) {
+        throw new NotImplementedException();
+    }
+
+    @NotNull
+    @Override
+    default PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default void removeAttachment(@NotNull PermissionAttachment attachment) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    default void recalculatePermissions() {
+        throw new NotImplementedException();
+    }
+
+    @NotNull
+    @Override
+    default Set<PermissionAttachmentInfo> getEffectivePermissions() {
+        throw new NotImplementedException();
+    }
+
+    @NotNull
+    @Override
+    default Spigot spigot() {
+        throw new NotImplementedException();
+    }
+
+}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index 81e4fa57337f5a40c4b673136dd5eb595cce4629..f020cb04eba27a2e70fc7cf799ebbfb434b9d974 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -15,7 +15,6 @@ import org.bukkit.command.defaults.BukkitCommand;
 import org.bukkit.command.defaults.HelpCommand;
 import org.bukkit.command.defaults.PluginsCommand;
 import org.bukkit.command.defaults.ReloadCommand;
-import org.bukkit.command.defaults.TimingsCommand;
 import org.bukkit.command.defaults.VersionCommand;
 import org.bukkit.entity.Player;
 import org.bukkit.util.StringUtil;
@@ -35,7 +34,7 @@ public class SimpleCommandMap implements CommandMap {
         register("bukkit", new VersionCommand("version"));
         register("bukkit", new ReloadCommand("reload"));
         register("bukkit", new PluginsCommand("plugins"));
-        register("bukkit", new TimingsCommand("timings"));
+        register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper
     }
 
     public void setFallbackCommands() {
@@ -67,6 +66,7 @@ public class SimpleCommandMap implements CommandMap {
      */
     @Override
     public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) {
+        command.timings = co.aikar.timings.TimingsManager.getCommandTiming(fallbackPrefix, command); // Paper
         label = label.toLowerCase(java.util.Locale.ENGLISH).trim();
         fallbackPrefix = fallbackPrefix.toLowerCase(java.util.Locale.ENGLISH).trim();
         boolean registered = register(label, command, false, fallbackPrefix);
@@ -143,16 +143,22 @@ public class SimpleCommandMap implements CommandMap {
             return false;
         }
 
+        // Paper start - Plugins do weird things to workaround normal registration
+        if (target.timings == null) {
+            target.timings = co.aikar.timings.TimingsManager.getCommandTiming(null, target);
+        }
+        // Paper end
+
         try {
-            target.timings.startTiming(); // Spigot
+            try (co.aikar.timings.Timing ignored = target.timings.startTiming()) { // Paper - use try with resources
             // Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
             target.execute(sender, sentCommandLabel, Arrays.copyOfRange(args, 1, args.length));
-            target.timings.stopTiming(); // Spigot
+            } // target.timings.stopTiming(); // Spigot // Paper
         } catch (CommandException ex) {
-            target.timings.stopTiming(); // Spigot
+            //target.timings.stopTiming(); // Spigot // Paper
             throw ex;
         } catch (Throwable ex) {
-            target.timings.stopTiming(); // Spigot
+            //target.timings.stopTiming(); // Spigot // Paper
             throw new CommandException("Unhandled exception executing '" + commandLine + "' in " + target, ex);
         }
 
diff --git a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java b/src/main/java/org/bukkit/command/defaults/TimingsCommand.java
deleted file mode 100644
index 2a145d851ce30360aa39549745bd87590c034584..0000000000000000000000000000000000000000
--- a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java
+++ /dev/null
@@ -1,250 +0,0 @@
-package org.bukkit.command.defaults;
-
-import com.google.common.collect.ImmutableList;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.lang.Validate;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.event.Event;
-import org.bukkit.event.HandlerList;
-import org.bukkit.plugin.Plugin;
-import org.bukkit.plugin.RegisteredListener;
-import org.bukkit.plugin.TimedRegisteredListener;
-import org.bukkit.util.StringUtil;
-import org.jetbrains.annotations.NotNull;
-
-// Spigot start
-// CHECKSTYLE:OFF
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.logging.Level;
-import org.bukkit.command.RemoteConsoleCommandSender;
-import org.bukkit.plugin.SimplePluginManager;
-import org.spigotmc.CustomTimingsHandler;
-// CHECKSTYLE:ON
-// Spigot end
-
-public class TimingsCommand extends BukkitCommand {
-    private static final List<String> TIMINGS_SUBCOMMANDS = ImmutableList.of("report", "reset", "on", "off", "paste"); // Spigot
-    public static long timingStart = 0; // Spigot
-
-    public TimingsCommand(@NotNull String name) {
-        super(name);
-        this.description = "Manages Spigot Timings data to see performance of the server."; // Spigot
-        this.usageMessage = "/timings <reset|report|on|off|paste>"; // Spigot
-        this.setPermission("bukkit.command.timings");
-    }
-
-    // Spigot start - redesigned Timings Command
-    public void executeSpigotTimings(@NotNull CommandSender sender, @NotNull String[] args) {
-        if ("on".equals(args[0])) {
-            ((SimplePluginManager) Bukkit.getPluginManager()).useTimings(true);
-            CustomTimingsHandler.reload();
-            sender.sendMessage("Enabled Timings & Reset");
-            return;
-        } else if ("off".equals(args[0])) {
-            ((SimplePluginManager) Bukkit.getPluginManager()).useTimings(false);
-            sender.sendMessage("Disabled Timings");
-            return;
-        }
-
-        if (!Bukkit.getPluginManager().useTimings()) {
-            sender.sendMessage("Please enable timings by typing /timings on");
-            return;
-        }
-
-        boolean paste = "paste".equals(args[0]);
-        if ("reset".equals(args[0])) {
-            CustomTimingsHandler.reload();
-            sender.sendMessage("Timings reset");
-        } else if ("merged".equals(args[0]) || "report".equals(args[0]) || paste) {
-            long sampleTime = System.nanoTime() - timingStart;
-            int index = 0;
-            File timingFolder = new File("timings");
-            timingFolder.mkdirs();
-            File timings = new File(timingFolder, "timings.txt");
-            ByteArrayOutputStream bout = (paste) ? new ByteArrayOutputStream() : null;
-            while (timings.exists()) timings = new File(timingFolder, "timings" + (++index) + ".txt");
-            PrintStream fileTimings = null;
-            try {
-                fileTimings = (paste) ? new PrintStream(bout) : new PrintStream(timings);
-
-                CustomTimingsHandler.printTimings(fileTimings);
-                fileTimings.println("Sample time " + sampleTime + " (" + sampleTime / 1E9 + "s)");
-
-                fileTimings.println("<spigotConfig>");
-                fileTimings.println(Bukkit.spigot().getConfig().saveToString());
-                fileTimings.println("</spigotConfig>");
-
-                if (paste) {
-                    new PasteThread(sender, bout).start();
-                    return;
-                }
-
-                sender.sendMessage("Timings written to " + timings.getPath());
-                sender.sendMessage("Paste contents of file into form at http://www.spigotmc.org/go/timings to read results.");
-
-            } catch (IOException e) {
-            } finally {
-                if (fileTimings != null) {
-                    fileTimings.close();
-                }
-            }
-        }
-    }
-    // Spigot end
-
-    @Override
-    public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
-        if (!testPermission(sender)) return true;
-        if (args.length < 1) { // Spigot
-            sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
-            return false;
-        }
-        // Spigot start
-        if (true) {
-            executeSpigotTimings(sender, args);
-            return true;
-        }
-        // Spigot end
-        if (!sender.getServer().getPluginManager().useTimings()) {
-            sender.sendMessage("Please enable timings by setting \"settings.plugin-profiling\" to true in bukkit.yml");
-            return true;
-        }
-
-        boolean separate = "separate".equalsIgnoreCase(args[0]);
-        if ("reset".equalsIgnoreCase(args[0])) {
-            for (HandlerList handlerList : HandlerList.getHandlerLists()) {
-                for (RegisteredListener listener : handlerList.getRegisteredListeners()) {
-                    if (listener instanceof TimedRegisteredListener) {
-                        ((TimedRegisteredListener) listener).reset();
-                    }
-                }
-            }
-            sender.sendMessage("Timings reset");
-        } else if ("merged".equalsIgnoreCase(args[0]) || separate) {
-
-            int index = 0;
-            int pluginIdx = 0;
-            File timingFolder = new File("timings");
-            timingFolder.mkdirs();
-            File timings = new File(timingFolder, "timings.txt");
-            File names = null;
-            while (timings.exists()) timings = new File(timingFolder, "timings" + (++index) + ".txt");
-            PrintStream fileTimings = null;
-            PrintStream fileNames = null;
-            try {
-                fileTimings = new PrintStream(timings);
-                if (separate) {
-                    names = new File(timingFolder, "names" + index + ".txt");
-                    fileNames = new PrintStream(names);
-                }
-                for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
-                    pluginIdx++;
-                    long totalTime = 0;
-                    if (separate) {
-                        fileNames.println(pluginIdx + " " + plugin.getDescription().getFullName());
-                        fileTimings.println("Plugin " + pluginIdx);
-                    } else {
-                        fileTimings.println(plugin.getDescription().getFullName());
-                    }
-                    for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
-                        if (listener instanceof TimedRegisteredListener) {
-                            TimedRegisteredListener trl = (TimedRegisteredListener) listener;
-                            long time = trl.getTotalTime();
-                            int count = trl.getCount();
-                            if (count == 0) continue;
-                            long avg = time / count;
-                            totalTime += time;
-                            Class<? extends Event> eventClass = trl.getEventClass();
-                            if (count > 0 && eventClass != null) {
-                                fileTimings.println("    " + eventClass.getSimpleName() + (trl.hasMultiple() ? " (and sub-classes)" : "") + " Time: " + time + " Count: " + count + " Avg: " + avg);
-                            }
-                        }
-                    }
-                    fileTimings.println("    Total time " + totalTime + " (" + totalTime / 1000000000 + "s)");
-                }
-                sender.sendMessage("Timings written to " + timings.getPath());
-                if (separate) sender.sendMessage("Names written to " + names.getPath());
-            } catch (IOException e) {
-            } finally {
-                if (fileTimings != null) {
-                    fileTimings.close();
-                }
-                if (fileNames != null) {
-                    fileNames.close();
-                }
-            }
-        } else {
-            sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
-            return false;
-        }
-        return true;
-    }
-
-    @NotNull
-    @Override
-    public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
-        Validate.notNull(sender, "Sender cannot be null");
-        Validate.notNull(args, "Arguments cannot be null");
-        Validate.notNull(alias, "Alias cannot be null");
-
-        if (args.length == 1) {
-            return StringUtil.copyPartialMatches(args[0], TIMINGS_SUBCOMMANDS, new ArrayList<String>(TIMINGS_SUBCOMMANDS.size()));
-        }
-        return ImmutableList.of();
-    }
-
-    // Spigot start
-    private static class PasteThread extends Thread {
-
-        private final CommandSender sender;
-        private final ByteArrayOutputStream bout;
-
-        public PasteThread(@NotNull CommandSender sender, @NotNull ByteArrayOutputStream bout) {
-            super("Timings paste thread");
-            this.sender = sender;
-            this.bout = bout;
-        }
-
-        @Override
-        public synchronized void start() {
-            if (sender instanceof RemoteConsoleCommandSender) {
-                run();
-            } else {
-                super.start();
-            }
-        }
-
-        @Override
-        public void run() {
-            try {
-                HttpURLConnection con = (HttpURLConnection) new URL("https://timings.spigotmc.org/paste").openConnection();
-                con.setDoOutput(true);
-                con.setRequestMethod("POST");
-                con.setInstanceFollowRedirects(false);
-
-                OutputStream out = con.getOutputStream();
-                out.write(bout.toByteArray());
-                out.close();
-
-                com.google.gson.JsonObject location = new com.google.gson.Gson().fromJson(new java.io.InputStreamReader(con.getInputStream()), com.google.gson.JsonObject.class);
-                con.getInputStream().close();
-
-                String pasteID = location.get("key").getAsString();
-                sender.sendMessage(ChatColor.GREEN + "Timings results can be viewed at https://www.spigotmc.org/go/timings?url=" + pasteID);
-            } catch (IOException ex) {
-                sender.sendMessage(ChatColor.RED + "Error pasting timings, check your console for more information");
-                Bukkit.getServer().getLogger().log(Level.WARNING, "Could not paste timings", ex);
-            }
-        }
-    }
-    // Spigot end
-}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 306e5366d0f07974fa8a344e8a7954b6f7a1ac6f..50fae417ecab61c867a0d2c5299aedf056ff1bec 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -1459,7 +1459,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
          */
         public void sendMessage(@NotNull net.md_5.bungee.api.ChatMessageType position, @Nullable UUID sender, @NotNull net.md_5.bungee.api.chat.BaseComponent... components) {
             throw new UnsupportedOperationException("Not supported yet.");
+
+        }
+
+        // Paper start
+        public int getPing() {
+            throw new UnsupportedOperationException( "Not supported yet." );
         }
+        // Paper end
     }
 
     @NotNull
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 77dcfe35e6a765c8ccb38bc5d900989dc0456b13..7548e40af8043c1b5716f2d7d0122833466854c4 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -358,7 +358,6 @@ public final class SimplePluginManager implements PluginManager {
             }
         }
 
-        org.bukkit.command.defaults.TimingsCommand.timingStart = System.nanoTime(); // Spigot
         return result.toArray(new Plugin[result.size()]);
     }
 
@@ -397,9 +396,9 @@ public final class SimplePluginManager implements PluginManager {
 
         if (result != null) {
             plugins.add(result);
-            lookupNames.put(result.getDescription().getName(), result);
+            lookupNames.put(result.getDescription().getName().toLowerCase(java.util.Locale.ENGLISH), result); // Paper
             for (String provided : result.getDescription().getProvides()) {
-                lookupNames.putIfAbsent(provided, result);
+                lookupNames.putIfAbsent(provided.toLowerCase(java.util.Locale.ENGLISH), result); // Paper
             }
         }
 
@@ -428,7 +427,7 @@ public final class SimplePluginManager implements PluginManager {
     @Override
     @Nullable
     public synchronized Plugin getPlugin(@NotNull String name) {
-        return lookupNames.get(name.replace(' ', '_'));
+        return lookupNames.get(name.replace(' ', '_').toLowerCase(java.util.Locale.ENGLISH)); // Paper
     }
 
     @Override
@@ -646,7 +645,8 @@ public final class SimplePluginManager implements PluginManager {
             throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
         }
 
-        if (useTimings) {
+        executor = new co.aikar.timings.TimedEventExecutor(executor, plugin, null, event); // Paper
+        if (false) { // Spigot - RL handles useTimings check now // Paper
             getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
         } else {
             getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
@@ -861,7 +861,7 @@ public final class SimplePluginManager implements PluginManager {
 
     @Override
     public boolean useTimings() {
-        return useTimings;
+        return co.aikar.timings.Timings.isTimingsEnabled(); // Spigot
     }
 
     /**
@@ -870,6 +870,6 @@ public final class SimplePluginManager implements PluginManager {
      * @param use True if per event timing code should be used
      */
     public void useTimings(boolean use) {
-        useTimings = use;
+        co.aikar.timings.Timings.setTimingsEnabled(use); // Paper
     }
 }
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index a09c3f71ca563b6f40a118ce1344d0eb273bed40..cf2f517765d8f2a23cc4a17d9ee2dcd81f841b1b 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -54,7 +54,6 @@ public final class JavaPluginLoader implements PluginLoader {
     private final Pattern[] fileFilters = new Pattern[]{Pattern.compile("\\.jar$")};
     private final List<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>();
     private final LibraryLoader libraryLoader;
-    public static final CustomTimingsHandler pluginParentTimer = new CustomTimingsHandler("** Plugins"); // Spigot
 
     /**
      * This class was not meant to be constructed explicitly
@@ -292,27 +291,21 @@ public final class JavaPluginLoader implements PluginLoader {
                 }
             }
 
-            final CustomTimingsHandler timings = new CustomTimingsHandler("Plugin: " + plugin.getDescription().getFullName() + " Event: " + listener.getClass().getName() + "::" + method.getName() + "(" + eventClass.getSimpleName() + ")", pluginParentTimer); // Spigot
-            EventExecutor executor = new EventExecutor() {
+            EventExecutor executor = new co.aikar.timings.TimedEventExecutor(new EventExecutor() { // Paper
                 @Override
-                public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
+                public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper
                     try {
                         if (!eventClass.isAssignableFrom(event.getClass())) {
                             return;
                         }
-                        // Spigot start
-                        boolean isAsync = event.isAsynchronous();
-                        if (!isAsync) timings.startTiming();
                         method.invoke(listener, event);
-                        if (!isAsync) timings.stopTiming();
-                        // Spigot end
                     } catch (InvocationTargetException ex) {
                         throw new EventException(ex.getCause());
                     } catch (Throwable t) {
                         throw new EventException(t);
                     }
                 }
-            };
+            }, plugin, method, eventClass); // Paper
             if (false) { // Spigot - RL handles useTimings check now
                 eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
             } else {
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index 6bdd9f1dcc4c69c1811622cddc82526d2f8d9e52..657243776c8a2abb5a57e5c407212a8387d649eb 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -29,7 +29,8 @@ import org.jetbrains.annotations.Nullable;
 /**
  * A ClassLoader for plugins, to allow shared classes across multiple plugins
  */
-final class PluginClassLoader extends URLClassLoader {
+public final class PluginClassLoader extends URLClassLoader { // Spigot
+    public JavaPlugin getPlugin() { return plugin; } // Spigot
     private final JavaPluginLoader loader;
     private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
     private final PluginDescriptionFile description;
diff --git a/src/main/java/org/bukkit/util/CachedServerIcon.java b/src/main/java/org/bukkit/util/CachedServerIcon.java
index 5ca863b3692b2e1b58e7fb4d82f554a92cc4f01e..612958a331575d1da2715531ebdf6b1168f2e860 100644
--- a/src/main/java/org/bukkit/util/CachedServerIcon.java
+++ b/src/main/java/org/bukkit/util/CachedServerIcon.java
@@ -2,6 +2,7 @@ package org.bukkit.util;
 
 import org.bukkit.Server;
 import org.bukkit.event.server.ServerListPingEvent;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * This is a cached version of a server-icon. It's internal representation
@@ -12,4 +13,9 @@ import org.bukkit.event.server.ServerListPingEvent;
  * @see Server#loadServerIcon(java.io.File)
  * @see ServerListPingEvent#setServerIcon(CachedServerIcon)
  */
-public interface CachedServerIcon {}
+public interface CachedServerIcon {
+
+    @Nullable
+    public String getData(); // Paper
+
+}
diff --git a/src/main/java/org/spigotmc/CustomTimingsHandler.java b/src/main/java/org/spigotmc/CustomTimingsHandler.java
index 44badfedcc3fdc26bdc293b85d8c781d6f659faa..3cbe5c2bb55dead7968a6f165ef267e3e2931061 100644
--- a/src/main/java/org/spigotmc/CustomTimingsHandler.java
+++ b/src/main/java/org/spigotmc/CustomTimingsHandler.java
@@ -1,3 +1,26 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
 package org.spigotmc;
 
 import java.io.PrintStream;
@@ -5,133 +28,84 @@ import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import org.bukkit.Bukkit;
 import org.bukkit.World;
-import org.bukkit.command.defaults.TimingsCommand;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.bukkit.plugin.AuthorNagException;
+import org.bukkit.plugin.Plugin;
+import co.aikar.timings.Timing;
+import co.aikar.timings.Timings;
+import co.aikar.timings.TimingsManager;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.logging.Level;
 
 /**
- * Provides custom timing sections for /timings merged.
+ * This is here for legacy purposes incase any plugin used it.
+ *
+ * If you use this, migrate ASAP as this will be removed in the future!
+ *
+ * @deprecated
+ * @see co.aikar.timings.Timings#of
  */
-public class CustomTimingsHandler {
-
-    private static Queue<CustomTimingsHandler> HANDLERS = new ConcurrentLinkedQueue<CustomTimingsHandler>();
-    /*========================================================================*/
-    private final String name;
-    private final CustomTimingsHandler parent;
-    private long count = 0;
-    private long start = 0;
-    private long timingDepth = 0;
-    private long totalTime = 0;
-    private long curTickTotal = 0;
-    private long violations = 0;
+@Deprecated
+public final class CustomTimingsHandler {
+    private final Timing handler;
+    private static Boolean sunReflectAvailable;
+    private static Method getCallerClass;
 
     public CustomTimingsHandler(@NotNull String name) {
-        this(name, null);
-    }
+        if (sunReflectAvailable == null) {
+            String javaVer = System.getProperty("java.version");
+            String[] elements = javaVer.split("\\.");
 
-    public CustomTimingsHandler(@NotNull String name, @Nullable CustomTimingsHandler parent) {
-        this.name = name;
-        this.parent = parent;
-        HANDLERS.add(this);
-    }
+            int major = Integer.parseInt(elements.length >= 2 ? elements[1] : javaVer);
+            if (major <= 8) {
+                sunReflectAvailable = true;
 
-    /**
-     * Prints the timings and extra data to the given stream.
-     *
-     * @param printStream output stream
-     */
-    public static void printTimings(@NotNull PrintStream printStream) {
-        printStream.println("Minecraft");
-        for (CustomTimingsHandler timings : HANDLERS) {
-            long time = timings.totalTime;
-            long count = timings.count;
-            if (count == 0) {
-                continue;
+                try {
+                    Class<?> reflection = Class.forName("sun.reflect.Reflection");
+                    getCallerClass = reflection.getMethod("getCallerClass", int.class);
+                } catch (ClassNotFoundException | NoSuchMethodException ignored) {
+                }
+            } else {
+                sunReflectAvailable = false;
             }
-            long avg = time / count;
-
-            printStream.println("    " + timings.name + " Time: " + time + " Count: " + count + " Avg: " + avg + " Violations: " + timings.violations);
-        }
-        printStream.println("# Version " + Bukkit.getVersion());
-        int entities = 0;
-        int livingEntities = 0;
-        for (World world : Bukkit.getWorlds()) {
-            entities += world.getEntities().size();
-            livingEntities += world.getLivingEntities().size();
         }
-        printStream.println("# Entities " + entities);
-        printStream.println("# LivingEntities " + livingEntities);
-    }
 
-    /**
-     * Resets all timings.
-     */
-    public static void reload() {
-        if (Bukkit.getPluginManager().useTimings()) {
-            for (CustomTimingsHandler timings : HANDLERS) {
-                timings.reset();
+        Class calling = null;
+        if (sunReflectAvailable) {
+            try {
+                calling = (Class) getCallerClass.invoke(null, 2);
+            } catch (IllegalAccessException | InvocationTargetException ignored) {
             }
         }
-        TimingsCommand.timingStart = System.nanoTime();
-    }
 
-    /**
-     * Ticked every tick by CraftBukkit to count the number of times a timer
-     * caused TPS loss.
-     */
-    public static void tick() {
-        if (Bukkit.getPluginManager().useTimings()) {
-            for (CustomTimingsHandler timings : HANDLERS) {
-                if (timings.curTickTotal > 50000000) {
-                    timings.violations += Math.ceil(timings.curTickTotal / 50000000);
-                }
-                timings.curTickTotal = 0;
-                timings.timingDepth = 0; // incase reset messes this up
-            }
-        }
-    }
+        Timing timing;
 
-    /**
-     * Starts timing to track a section of code.
-     */
-    public void startTiming() {
-        // If second condtion fails we are already timing
-        if (Bukkit.getPluginManager().useTimings() && ++timingDepth == 1) {
-            start = System.nanoTime();
-            if (parent != null && ++parent.timingDepth == 1) {
-                parent.start = start;
-            }
-        }
-    }
+        Plugin plugin = null;
+        try {
+             plugin = TimingsManager.getPluginByClassloader(calling);
+        } catch (Exception ignored) {}
 
-    /**
-     * Stops timing a section of code.
-     */
-    public void stopTiming() {
-        if (Bukkit.getPluginManager().useTimings()) {
-            if (--timingDepth != 0 || start == 0) {
-                return;
-            }
-            long diff = System.nanoTime() - start;
-            totalTime += diff;
-            curTickTotal += diff;
-            count++;
-            start = 0;
-            if (parent != null) {
-                parent.stopTiming();
+        new AuthorNagException("Deprecated use of CustomTimingsHandler. Please Switch to Timings.of ASAP").printStackTrace();
+        if (plugin != null) {
+            timing = Timings.of(plugin, "(Deprecated API) " + name);
+        } else {
+            try {
+                final Method ofSafe = TimingsManager.class.getDeclaredMethod("getHandler", String.class, String.class, Timing.class);
+                ofSafe.setAccessible(true);
+                timing = (Timing) ofSafe.invoke(null,"Minecraft", "(Deprecated API) " + name, null);
+            } catch (Exception e) {
+                e.printStackTrace();
+                Bukkit.getLogger().log(Level.SEVERE, "This handler could not be registered");
+                timing = Timings.NULL_HANDLER;
             }
         }
+        handler = timing;
     }
 
-    /**
-     * Reset this timer, setting all values to zero.
-     */
-    public void reset() {
-        count = 0;
-        violations = 0;
-        curTickTotal = 0;
-        totalTime = 0;
-        start = 0;
-        timingDepth = 0;
-    }
+    public void startTiming() { handler.startTiming(); }
+    public void stopTiming() { handler.stopTiming(); }
+
 }