Skip to content

Commit 35d6bac

Browse files
committed
Call forge CommandEvent when call PlayerCommandPreprocessEvent
1 parent 7d4398b commit 35d6bac

1 file changed

Lines changed: 41 additions & 30 deletions

File tree

patches/minecraft/net/minecraft/network/NetHandlerPlayServer.java.patch

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@
14431443
textcomponenttranslation.func_150256_b().func_150238_a(TextFormatting.RED);
14441444
this.func_147359_a(new SPacketChat(textcomponenttranslation));
14451445
}
1446-
@@ -1029,47 +1464,313 @@
1446+
@@ -1029,47 +1464,324 @@
14471447
{
14481448
if (!ChatAllowedCharacters.func_71566_a(s.charAt(i)))
14491449
{
@@ -1680,18 +1680,29 @@
16801680
+ this.field_147370_c.info(this.field_147369_b.func_70005_c_() + " issued server command: " + p_147361_1_);
16811681
+
16821682
+ CraftPlayer player = this.getPlayer();
1683-
+ List<String> params = new ArrayList<>(List.of(p_147361_1_.split(" ")));
1684-
+ ICommand iCommand = BukkitCommandWrapper.toNMSCommand(this.field_147369_b, params.removeFirst());
1683+
+ List<String> params = new ArrayList<>(List.of(p_147361_1_.trim().split(" ")));
1684+
+ String commandWithNoArgs = params.removeFirst().replaceFirst("^/", "");
1685+
+ ICommand iCommand = this.field_147367_d.func_71187_D().func_71555_a().get(commandWithNoArgs);
1686+
+
1687+
+ if (iCommand == null) {
1688+
+ iCommand = BukkitCommandWrapper.toNMSCommand(this.field_147369_b, commandWithNoArgs);
1689+
+ }
16851690
+
16861691
+ PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, p_147361_1_, new LazyPlayerSet(field_147367_d));
1687-
+ MinecraftForge.EVENT_BUS.post(new CommandEvent(iCommand, this.field_147369_b, params.toArray(new String[0])));
16881692
+ this.craftServer.getPluginManager().callEvent(event);
16891693
+
16901694
+ if (event.isCancelled()) {
16911695
+ org.bukkit.craftbukkit.v1_12_R1.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
16921696
+ return;
16931697
+ }
16941698
+
1699+
+ CommandEvent forgeEvent = new CommandEvent(iCommand, this.field_147369_b, params.toArray(new String[0]));
1700+
+
1701+
+ if (MinecraftForge.EVENT_BUS.post(forgeEvent)) {
1702+
+ org.bukkit.craftbukkit.v1_12_R1.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
1703+
+ return;
1704+
+ }
1705+
+
16951706
+ try {
16961707
+ if (this.craftServer.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
16971708
+ org.bukkit.craftbukkit.v1_12_R1.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
@@ -1771,7 +1782,7 @@
17711782
this.field_147369_b.func_143004_u();
17721783

17731784
switch (p_147357_1_.func_180764_b())
1774-
@@ -1128,10 +1829,7 @@
1785+
@@ -1128,10 +1840,7 @@
17751786
break;
17761787
case START_FALL_FLYING:
17771788

@@ -1783,7 +1794,7 @@
17831794
{
17841795
ItemStack itemstack = this.field_147369_b.func_184582_a(EntityEquipmentSlot.CHEST);
17851796

1786-
@@ -1151,10 +1849,10 @@
1797+
@@ -1151,10 +1860,10 @@
17871798
}
17881799
}
17891800

@@ -1795,7 +1806,7 @@
17951806
WorldServer worldserver = this.field_147367_d.func_71218_a(this.field_147369_b.field_71093_bK);
17961807
Entity entity = p_147340_1_.func_149564_a(worldserver);
17971808
this.field_147369_b.func_143004_u();
1798-
@@ -1162,41 +1860,83 @@
1809+
@@ -1162,41 +1871,83 @@
17991810
if (entity != null)
18001811
{
18011812
boolean flag = this.field_147369_b.func_70685_l(entity);
@@ -1884,7 +1895,7 @@
18841895
public void func_147342_a(CPacketClientStatus p_147342_1_)
18851896
{
18861897
PacketThreadUtil.func_180031_a(p_147342_1_, this, this.field_147369_b.func_71121_q());
1887-
@@ -1220,7 +1960,7 @@
1898+
@@ -1220,7 +1971,7 @@
18881899
return;
18891900
}
18901901

@@ -1893,7 +1904,7 @@
18931904

18941905
if (this.field_147367_d.func_71199_h())
18951906
{
1896-
@@ -1235,40 +1975,345 @@
1907+
@@ -1235,40 +1986,345 @@
18971908
}
18981909
}
18991910

@@ -2251,7 +2262,7 @@
22512262
{
22522263
this.field_147369_b.field_71135_a.func_147359_a(new SPacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), true));
22532264
this.field_147369_b.field_71137_h = true;
2254-
@@ -1278,15 +2323,15 @@
2265+
@@ -1278,15 +2334,15 @@
22552266
}
22562267
else
22572268
{
@@ -2271,7 +2282,7 @@
22712282
nonnulllist1.add(itemstack1);
22722283
}
22732284

2274-
@@ -1296,39 +2341,46 @@
2285+
@@ -1296,39 +2352,46 @@
22752286
}
22762287
}
22772288

@@ -2327,7 +2338,7 @@
23272338

23282339
if (this.field_147369_b.field_71134_c.func_73083_d())
23292340
{
2330-
@@ -1356,7 +2408,46 @@
2341+
@@ -1356,7 +2419,46 @@
23312342
}
23322343

23332344
boolean flag1 = p_147344_1_.func_149627_c() >= 1 && p_147344_1_.func_149627_c() <= 45;
@@ -2375,7 +2386,7 @@
23752386

23762387
if (flag1 && flag2)
23772388
{
2378-
@@ -1384,26 +2475,22 @@
2389+
@@ -1384,26 +2486,22 @@
23792390
}
23802391
}
23812392

@@ -2405,7 +2416,7 @@
24052416
this.field_147369_b.func_143004_u();
24062417
WorldServer worldserver = this.field_147367_d.func_71218_a(this.field_147369_b.field_71093_bK);
24072418
BlockPos blockpos = p_147343_1_.func_179722_a();
2408-
@@ -1423,14 +2510,30 @@
2419+
@@ -1423,14 +2521,30 @@
24092420
if (!tileentitysign.func_145914_a() || tileentitysign.func_145911_b() != this.field_147369_b)
24102421
{
24112422
this.field_147367_d.func_71236_h("Player " + this.field_147369_b.func_70005_c_() + " just tried to change non-editable sign");
@@ -2437,7 +2448,7 @@
24372448
}
24382449

24392450
tileentitysign.func_70296_d();
2440-
@@ -1438,9 +2541,9 @@
2451+
@@ -1438,9 +2552,9 @@
24412452
}
24422453
}
24432454

@@ -2448,7 +2459,7 @@
24482459
if (this.field_194403_g && p_147353_1_.func_149460_c() == this.field_194404_h)
24492460
{
24502461
int i = (int)(this.func_147363_d() - this.field_194402_f);
2451-
@@ -1449,7 +2552,7 @@
2462+
@@ -1449,7 +2563,7 @@
24522463
}
24532464
else if (!this.field_147369_b.func_70005_c_().equals(this.field_147367_d.func_71214_G()))
24542465
{
@@ -2457,7 +2468,7 @@
24572468
}
24582469
}
24592470

2460-
@@ -1458,36 +2561,44 @@
2471+
@@ -1458,36 +2572,44 @@
24612472
return System.nanoTime() / 1000000L;
24622473
}
24632474

@@ -2511,7 +2522,7 @@
25112522
public void func_147349_a(CPacketCustomPayload p_147349_1_)
25122523
{
25132524
PacketThreadUtil.func_180031_a(p_147349_1_, this, this.field_147369_b.func_71121_q());
2514-
@@ -1495,6 +2606,11 @@
2525+
@@ -1495,6 +2617,11 @@
25152526

25162527
if ("MC|BEdit".equals(s))
25172528
{
@@ -2523,7 +2534,7 @@
25232534
PacketBuffer packetbuffer = p_147349_1_.func_180760_b();
25242535

25252536
try
2526-
@@ -1521,15 +2637,22 @@
2537+
@@ -1521,15 +2648,22 @@
25272538
if (itemstack.func_77973_b() == Items.field_151099_bA && itemstack.func_77973_b() == itemstack1.func_77973_b())
25282539
{
25292540
itemstack1.func_77983_a("pages", itemstack.func_77978_p().func_150295_c("pages", 8));
@@ -2546,7 +2557,7 @@
25462557
PacketBuffer packetbuffer1 = p_147349_1_.func_180760_b();
25472558

25482559
try
2549-
@@ -1569,12 +2692,14 @@
2560+
@@ -1569,12 +2703,14 @@
25502561
}
25512562

25522563
itemstack2.func_77983_a("pages", nbttaglist);
@@ -2562,7 +2573,7 @@
25622573
}
25632574
}
25642575
else if ("MC|TrSel".equals(s))
2565-
@@ -1592,19 +2717,20 @@
2576+
@@ -1592,19 +2728,20 @@
25662577
catch (Exception exception5)
25672578
{
25682579
field_147370_c.error("Couldn't select trade", (Throwable)exception5);
@@ -2585,7 +2596,7 @@
25852596
return;
25862597
}
25872598

2588-
@@ -1617,9 +2743,7 @@
2599+
@@ -1617,9 +2754,7 @@
25892600

25902601
if (l == 0)
25912602
{
@@ -2596,7 +2607,7 @@
25962607

25972608
if (tileentity instanceof TileEntityCommandBlock)
25982609
{
2599-
@@ -1646,29 +2770,30 @@
2610+
@@ -1646,29 +2781,30 @@
26002611

26012612
if (!flag2)
26022613
{
@@ -2631,7 +2642,7 @@
26312642
return;
26322643
}
26332644

2634-
@@ -1695,39 +2820,21 @@
2645+
@@ -1695,39 +2831,21 @@
26352646

26362647
if (commandblockbaselogic != null)
26372648
{
@@ -2675,7 +2686,7 @@
26752686
}
26762687

26772688
tileentity2.func_145829_t();
2678-
@@ -1737,7 +2844,7 @@
2689+
@@ -1737,7 +2855,7 @@
26792690

26802691
if (!flag3)
26812692
{
@@ -2684,7 +2695,7 @@
26842695
}
26852696

26862697
tileentitycommandblock.func_184253_b(flag1);
2687-
@@ -1745,13 +2852,14 @@
2698+
@@ -1745,13 +2863,14 @@
26882699

26892700
if (!net.minecraft.util.StringUtils.func_151246_b(s7))
26902701
{
@@ -2700,15 +2711,15 @@
27002711
}
27012712
}
27022713
else if ("MC|Beacon".equals(s))
2703-
@@ -1778,6 +2886,7 @@
2714+
@@ -1778,6 +2897,7 @@
27042715
catch (Exception exception2)
27052716
{
27062717
field_147370_c.error("Couldn't set beacon", (Throwable)exception2);
27072718
+ this.disconnect("Invalid beacon data!");
27082719
}
27092720
}
27102721
}
2711-
@@ -1848,37 +2957,37 @@
2722+
@@ -1848,37 +2968,37 @@
27122723
{
27132724
if (tileentitystructure.func_184419_m())
27142725
{
@@ -2753,15 +2764,15 @@
27532764
}
27542765
}
27552766

2756-
@@ -1889,6 +2998,7 @@
2767+
@@ -1889,6 +3009,7 @@
27572768
catch (Exception exception1)
27582769
{
27592770
field_147370_c.error("Couldn't set structure block", (Throwable)exception1);
27602771
+ this.disconnect("Invalid structure data!");
27612772
}
27622773
}
27632774
else if ("MC|PickItem".equals(s))
2764-
@@ -1899,22 +3009,50 @@
2775+
@@ -1899,22 +3020,50 @@
27652776
{
27662777
int j1 = packetbuffer6.func_150792_a();
27672778
this.field_147369_b.field_71071_by.func_184430_d(j1);

0 commit comments

Comments
 (0)