Skip to content

Commit 0e83f45

Browse files
authored
Merge pull request #9 from HaHaWTH/dev/paper-api
Paper tick event api
2 parents 8600044 + 9ec641e commit 0e83f45

File tree

7 files changed

+144
-36
lines changed

7 files changed

+144
-36
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ project(':cleanroom') {
497497
// CatServer
498498
installer 'com.googlecode.json-simple:json-simple:1.1.1'
499499
installer 'org.yaml:snakeyaml:1.19'
500-
installer 'net.md-5:SpecialSource:1.8.0'
500+
installer 'net.md-5:SpecialSource:1.11.4'
501501
installer 'net.md-5:bungeecord-chat:1.16-R0.4'
502502
installer 'commons-lang:commons-lang:2.6' // Is needed for plugin compatibility
503503
installer 'org.xerial:sqlite-jdbc:3.21.0.1'

patches/minecraft/net/minecraft/server/MinecraftServer.java.patch

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@
579579

580580
public boolean func_71278_l()
581581
{
582-
@@ -480,64 +586,132 @@
582+
@@ -480,64 +586,134 @@
583583
this.field_71317_u = false;
584584
}
585585

@@ -727,7 +727,9 @@
727727
+ }
728728
+ lastTick = curTime;
729729
+
730+
+ org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callServerTickStartEvent(this.field_71315_w + 1); // Paper - Server Tick Events
730731
+ this.func_71217_p();
732+
+ org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callServerTickEndEvent(this.field_71315_w, lastTick, catchupTime); // Paper - Server Tick Events
731733
this.field_71296_Q = true;
732734
}
733735
+ // Spigot end
@@ -748,7 +750,7 @@
748750
}
749751
catch (Throwable throwable1)
750752
{
751-
@@ -553,26 +727,24 @@
753+
@@ -553,26 +729,24 @@
752754
crashreport = this.func_71230_b(new CrashReport("Exception in server tick loop", throwable1));
753755
}
754756

@@ -778,7 +780,7 @@
778780
this.func_71260_j();
779781
}
780782
catch (Throwable throwable)
781-
@@ -581,6 +753,8 @@
783+
@@ -581,6 +755,8 @@
782784
}
783785
finally
784786
{
@@ -787,15 +789,15 @@
787789
this.func_71240_o();
788790
}
789791
}
790-
@@ -607,6 +781,7 @@
792+
@@ -607,6 +783,7 @@
791793
ImageIO.write(bufferedimage, "PNG", new ByteBufOutputStream(bytebuf));
792794
ByteBuf bytebuf1 = Base64.encode(bytebuf);
793795
p_184107_1_.func_151320_a("data:image/png;base64," + bytebuf1.toString(StandardCharsets.UTF_8));
794796
+ bytebuf1.release(); // Forge: fix MC-122085
795797
}
796798
catch (Exception exception)
797799
{
798-
@@ -647,7 +822,10 @@
800+
@@ -647,7 +824,10 @@
799801

800802
public void func_71217_p()
801803
{
@@ -806,7 +808,7 @@
806808
++this.field_71315_w;
807809

808810
if (this.field_71295_T)
809-
@@ -669,20 +847,33 @@
811+
@@ -669,20 +849,33 @@
810812

811813
for (int k = 0; k < agameprofile.length; ++k)
812814
{
@@ -845,7 +847,7 @@
845847

846848
this.field_71304_b.func_76320_a("tallying");
847849
this.field_71311_j[this.field_71315_w % 100] = System.nanoTime() - i;
848-
@@ -701,47 +892,87 @@
850+
@@ -701,47 +894,87 @@
849851

850852
this.field_71304_b.func_76319_b();
851853
this.field_71304_b.func_76319_b();
@@ -957,7 +959,7 @@
957959
}
958960
catch (Throwable throwable1)
959961
{
960-
@@ -752,7 +983,9 @@
962+
@@ -752,7 +985,9 @@
961963

962964
try
963965
{
@@ -967,7 +969,7 @@
967969
}
968970
catch (Throwable throwable)
969971
{
970-
@@ -761,28 +994,42 @@
972+
@@ -761,28 +996,42 @@
971973
throw new ReportedException(crashreport1);
972974
}
973975

@@ -1015,7 +1017,7 @@
10151017

10161018
this.field_71304_b.func_76319_b();
10171019
}
1018-
@@ -792,137 +1039,14 @@
1020+
@@ -792,137 +1041,14 @@
10191021
return true;
10201022
}
10211023

@@ -1158,7 +1160,7 @@
11581160
}
11591161

11601162
public File func_71209_f(String p_71209_1_)
1161-
@@ -930,12 +1054,6 @@
1163+
@@ -930,12 +1056,6 @@
11621164
return new File(this.func_71238_n(), p_71209_1_);
11631165
}
11641166

@@ -1171,7 +1173,7 @@
11711173
public void func_71236_h(String p_71236_1_)
11721174
{
11731175
field_147145_h.warn(p_71236_1_);
1174-
@@ -943,14 +1061,18 @@
1176+
@@ -943,14 +1063,18 @@
11751177

11761178
public WorldServer func_71218_a(int p_71218_1_)
11771179
{
@@ -1198,7 +1200,7 @@
11981200
}
11991201

12001202
public String func_71249_w()
1201-
@@ -978,30 +1100,10 @@
1203+
@@ -978,30 +1102,10 @@
12021204
return this.field_71318_t.func_152600_g();
12031205
}
12041206

@@ -1231,7 +1233,7 @@
12311233
}
12321234

12331235
public CrashReport func_71230_b(CrashReport p_71230_1_)
1234-
@@ -1016,21 +1118,13 @@
1236+
@@ -1016,21 +1120,13 @@
12351237

12361238
if (this.field_71318_t != null)
12371239
{
@@ -1256,7 +1258,7 @@
12561258
}
12571259

12581260
return p_71230_1_;
1259-
@@ -1038,7 +1132,7 @@
1261+
@@ -1038,7 +1134,7 @@
12601262

12611263
public List<String> func_184104_a(ICommandSender p_184104_1_, String p_184104_2_, @Nullable BlockPos p_184104_3_, boolean p_184104_4_)
12621264
{
@@ -1265,7 +1267,7 @@
12651267
boolean flag = p_184104_2_.startsWith("/");
12661268

12671269
if (flag)
1268-
@@ -1055,11 +1149,9 @@
1270+
@@ -1055,11 +1151,9 @@
12691271
{
12701272
if (CommandBase.func_71523_a(s2, s1))
12711273
{
@@ -1278,7 +1280,7 @@
12781280
}
12791281
else
12801282
{
1281-
@@ -1072,37 +1164,37 @@
1283+
@@ -1072,37 +1166,37 @@
12821284
{
12831285
if (flag1 && !p_184104_4_)
12841286
{
@@ -1325,7 +1327,7 @@
13251327
public boolean func_70003_b(int p_70003_1_, String p_70003_2_)
13261328
{
13271329
return true;
1328-
@@ -1118,18 +1210,6 @@
1330+
@@ -1118,18 +1212,6 @@
13291331
return this.field_71292_I;
13301332
}
13311333

@@ -1344,7 +1346,7 @@
13441346
public String func_71214_G()
13451347
{
13461348
return this.field_71293_J;
1347-
@@ -1174,24 +1254,24 @@
1349+
@@ -1174,24 +1256,24 @@
13481350

13491351
public void func_147139_a(EnumDifficulty p_147139_1_)
13501352
{
@@ -1378,7 +1380,7 @@
13781380
}
13791381
}
13801382
}
1381-
@@ -1238,58 +1318,55 @@
1383+
@@ -1238,58 +1320,55 @@
13821384
this.field_175588_P = p_180507_2_;
13831385
}
13841386

@@ -1462,7 +1464,7 @@
14621464
public boolean func_70002_Q()
14631465
{
14641466
return true;
1465-
@@ -1299,7 +1376,8 @@
1467+
@@ -1299,7 +1378,8 @@
14661468

14671469
public boolean func_71266_T()
14681470
{
@@ -1472,7 +1474,7 @@
14721474
}
14731475

14741476
public void func_71229_d(boolean p_71229_1_)
1475-
@@ -1312,12 +1390,6 @@
1477+
@@ -1312,12 +1392,6 @@
14761478
return this.field_190519_A;
14771479
}
14781480

@@ -1485,7 +1487,7 @@
14851487
public boolean func_71268_U()
14861488
{
14871489
return this.field_71324_y;
1488-
@@ -1394,14 +1466,14 @@
1490+
@@ -1394,14 +1468,14 @@
14891491

14901492
public void func_184105_a(PlayerList p_184105_1_)
14911493
{
@@ -1503,7 +1505,7 @@
15031505
}
15041506
}
15051507

1506-
@@ -1439,16 +1511,9 @@
1508+
@@ -1439,16 +1513,9 @@
15071509
return this.field_71307_n;
15081510
}
15091511

@@ -1521,7 +1523,7 @@
15211523
}
15221524

15231525
public boolean func_175579_a(World p_175579_1_, BlockPos p_175579_2_, EntityPlayer p_175579_3_)
1524-
@@ -1456,12 +1521,6 @@
1526+
@@ -1456,12 +1523,6 @@
15251527
return false;
15261528
}
15271529

@@ -1534,7 +1536,7 @@
15341536
public boolean func_104056_am()
15351537
{
15361538
return this.field_104057_T;
1537-
@@ -1515,11 +1574,11 @@
1539+
@@ -1515,11 +1576,11 @@
15381540
@Nullable
15391541
public Entity func_175576_a(UUID p_175576_1_)
15401542
{
@@ -1549,7 +1551,7 @@
15491551

15501552
if (entity != null)
15511553
{
1552-
@@ -1531,18 +1590,21 @@
1554+
@@ -1531,18 +1592,21 @@
15531555
return null;
15541556
}
15551557

@@ -1574,7 +1576,7 @@
15741576
public int func_175580_aG()
15751577
{
15761578
return 29999984;
1577-
@@ -1552,37 +1614,34 @@
1579+
@@ -1552,37 +1616,34 @@
15781580
{
15791581
Validate.notNull(p_175586_1_);
15801582

@@ -1621,7 +1623,7 @@
16211623
public boolean func_152345_ab()
16221624
{
16231625
return Thread.currentThread() == this.field_175590_aa;
1624-
@@ -1593,18 +1652,6 @@
1626+
@@ -1593,18 +1654,6 @@
16251627
return 256;
16261628
}
16271629

@@ -1640,7 +1642,7 @@
16401642
public int func_184108_a(@Nullable WorldServer p_184108_1_)
16411643
{
16421644
return p_184108_1_ != null ? p_184108_1_.func_82736_K().func_180263_c("spawnRadius") : 10;
1643-
@@ -1612,12 +1659,12 @@
1645+
@@ -1612,12 +1661,12 @@
16441646

16451647
public AdvancementManager func_191949_aK()
16461648
{
@@ -1655,7 +1657,7 @@
16551657
}
16561658

16571659
public void func_193031_aM()
1658-
@@ -1625,7 +1672,7 @@
1660+
@@ -1625,7 +1674,7 @@
16591661
if (this.func_152345_ab())
16601662
{
16611663
this.func_184103_al().func_72389_g();
@@ -1664,7 +1666,7 @@
16641666
this.func_191949_aK().func_192779_a();
16651667
this.func_193030_aL().func_193059_f();
16661668
this.func_184103_al().func_193244_w();
1667-
@@ -1634,5 +1681,151 @@
1669+
@@ -1634,5 +1683,151 @@
16681670
{
16691671
this.func_152344_a(this::func_193031_aM);
16701672
}

src/main/java/catserver/server/CatServerEventHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ public void onBlockBreak(BlockEvent.BreakEvent event) {
5353

5454
// CatRoom start - Handle mod explosion event
5555
@SubscribeEvent(priority = EventPriority.HIGHEST)
56-
public void onExplode(ExplosionEvent.Detonate event) {
56+
public void onExplosionDetonate(ExplosionEvent.Detonate event) {
5757
if (!CatServer.getConfig().bridgeForgeExplosionEventToBukkit) return;
5858
Explosion explosion = event.getExplosion();
5959
if (explosion.getClass() != Explosion.class) {
60+
// Copied from Explosion class
6061
Entity exploder = explosion.exploder;
6162
World bworld = event.getWorld().getWorld();
6263
Vec3d explosionPos = explosion.getPosition();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.destroystokyo.paper.event.server;
2+
3+
import org.bukkit.event.Event;
4+
import org.bukkit.event.HandlerList;
5+
6+
/**
7+
* Called when the server has finished ticking the main loop
8+
*/
9+
public class ServerTickEndEvent extends Event {
10+
11+
private static final HandlerList HANDLER_LIST = new HandlerList();
12+
13+
private final int tickNumber;
14+
private final double tickDuration;
15+
private final long timeEnd;
16+
17+
public ServerTickEndEvent(final int tickNumber, final double tickDuration, final long timeRemaining) {
18+
this.tickNumber = tickNumber;
19+
this.tickDuration = tickDuration;
20+
this.timeEnd = System.nanoTime() + timeRemaining;
21+
}
22+
23+
/**
24+
* @return What tick this was since start (first tick = 1)
25+
*/
26+
public int getTickNumber() {
27+
return this.tickNumber;
28+
}
29+
30+
/**
31+
* @return Time in milliseconds of how long this tick took
32+
*/
33+
public double getTickDuration() {
34+
return this.tickDuration;
35+
}
36+
37+
/**
38+
* Amount of nanoseconds remaining before the next tick should start.
39+
* <p>
40+
* If this value is negative, then that means the server has exceeded the tick time limit and TPS has been lost.
41+
* <p>
42+
* Method will continuously return the updated time remaining value. (return value is not static)
43+
*
44+
* @return Amount of nanoseconds remaining before the next tick should start
45+
*/
46+
public long getTimeRemaining() {
47+
return this.timeEnd - System.nanoTime();
48+
}
49+
50+
@Override
51+
public HandlerList getHandlers() {
52+
return HANDLER_LIST;
53+
}
54+
55+
public static HandlerList getHandlerList() {
56+
return HANDLER_LIST;
57+
}
58+
}

0 commit comments

Comments
 (0)