feat: Добавлена обработка пакетов игроков при получении команд
- В случае если команда приходит от игрока, меняется последний аргумент калбека `fromPacket`.
This commit is contained in:
@@ -9,8 +9,8 @@ import com.reider745.api.hooks.JarEditor;
|
||||
import com.reider745.hooks.*;
|
||||
import com.reider745.hooks.bugfix.DimensionsFix;
|
||||
import com.reider745.hooks.bugfix.EntityItemHooks;
|
||||
import com.reider745.network.CraftingTransactionPacket;
|
||||
import com.reider745.network.InnerCorePacket;
|
||||
import com.reider745.workbench.Workbench;
|
||||
|
||||
public class Main {
|
||||
public static InnerCoreServer innerCoreServer = new InnerCoreServer();
|
||||
@@ -71,6 +71,7 @@ public class Main {
|
||||
loader.registerHooksInitializationForClass(NetworkHooks.class);
|
||||
loader.registerHooksInitializationForClass(GlobalBlockPalette.class);
|
||||
loader.registerHooksInitializationForClass(ServerHooks.class);
|
||||
loader.registerHooksInitializationForClass(CraftingTransactionPacket.class);
|
||||
loader.registerHooksInitializationForClass(Other.class);
|
||||
loader.registerHooksInitializationForClass(PlayerHooks.class);
|
||||
loader.registerHooksInitializationForClass(RuntimeItemsHooks.class);
|
||||
@@ -78,7 +79,6 @@ public class Main {
|
||||
loader.registerHooksInitializationForClass(LevelHooks.class);
|
||||
loader.registerHooksInitializationForClass(ItemUtils.class);
|
||||
loader.registerHooksInitializationForClass(AndroidHooks.class);
|
||||
loader.registerHooksInitializationForClass(Workbench.class);
|
||||
|
||||
if (Arrays.stream(args).anyMatch("--snowfall-everywhere"::equals)) {
|
||||
loader.registerHooksInitializationForClass(SnowfallEverywhere.class);
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import cn.nukkit.event.inventory.CraftItemEvent;
|
||||
import cn.nukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import cn.nukkit.event.level.ChunkPopulateEvent;
|
||||
import cn.nukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import cn.nukkit.event.player.PlayerDeathEvent;
|
||||
import cn.nukkit.event.player.PlayerEatFoodEvent;
|
||||
import cn.nukkit.event.player.PlayerExperienceChangeEvent;
|
||||
@@ -383,13 +384,25 @@ public class EventListener implements Listener {
|
||||
NativeCallback.onCustomDimensionTransfer(event.getEntity().getId(), from, to);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onServerCommand(ServerCommandEvent event) {
|
||||
final CommandSender sender = event.getSender();
|
||||
final Position position = sender.getPosition();
|
||||
final long entityUid = sender.isEntity() ? sender.asEntity().getId() : 0;
|
||||
|
||||
consumeEvent(event, () -> NativeCallback.onServerCommand(event.getCommand(), (float) position.x,
|
||||
(float) position.y, (float) position.z, entityUid));
|
||||
consumeEvent(event, () -> NativeCallback.onServerCommand(event.getCommand(),
|
||||
(float) position.x, (float) position.y, (float) position.z, entityUid, false));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
||||
long playerUid = event.getPlayer().getId();
|
||||
Position position = event.getPlayer().getPosition();
|
||||
String command = event.getMessage();
|
||||
|
||||
consumeEvent(event,
|
||||
() -> NativeCallback.onServerCommand(command.charAt(0) == '/' ? command.substring(1) : command,
|
||||
(float) position.x, (float) position.y, (float) position.z, playerUid, true));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@@ -467,6 +480,4 @@ public class EventListener implements Listener {
|
||||
// TODO: onItemUseComplete (not only custom items)
|
||||
|
||||
// TODO: onItemDispensed
|
||||
|
||||
// TODO: onWorkbenchCraft
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.reider745.workbench;
|
||||
package com.reider745.network;
|
||||
|
||||
import cn.nukkit.inventory.Inventory;
|
||||
import cn.nukkit.inventory.PlayerInventory;
|
||||
@@ -13,7 +13,7 @@ import com.reider745.api.hooks.annotation.Hooks;
|
||||
import com.reider745.api.hooks.annotation.Inject;
|
||||
|
||||
@Hooks(className = "cn.nukkit.inventory.transaction.CraftingTransaction")
|
||||
public class Workbench implements HookClass {
|
||||
public class CraftingTransactionPacket implements HookClass {
|
||||
|
||||
@Inject(type = TypeHook.BEFORE_REPLACE)
|
||||
public static void sendInventories(CraftingTransaction transaction) {
|
||||
@@ -497,8 +497,8 @@ public class NativeCallback {
|
||||
new Pair<String, Object>("someFloat", anotherFloat)));
|
||||
}
|
||||
|
||||
public static void onServerCommand(String command, float x, float y, float z, long entity) {
|
||||
Callback.invokeAPICallback("ServerCommand", command, new Coords(x, y, z), entity);
|
||||
public static void onServerCommand(String command, float x, float y, float z, long entity, boolean fromPacket) {
|
||||
Callback.invokeAPICallback("ServerCommand", command, new Coords(x, y, z), entity, fromPacket);
|
||||
}
|
||||
|
||||
/* PLAYER CALLBACKS */
|
||||
@@ -631,13 +631,13 @@ public class NativeCallback {
|
||||
someBool2);
|
||||
|
||||
// if (entity == NativeAPI.getPlayer()) {
|
||||
// ArmorRegistry.onHurt(attacker, damageValue, damageType, someBool1,
|
||||
// someBool2);
|
||||
// ArmorRegistry.onHurt(attacker, damageValue, damageType, someBool1, someBool2);
|
||||
// }
|
||||
}
|
||||
|
||||
public static void onThrowableHit(long projectile, float hitX, float hitY, float hitZ, long entity, int blockX,
|
||||
int blockY, int blockZ, int blockSide, int itemId, int itemCount, int itemData, NativeItemInstanceExtra itemExtra) {
|
||||
int blockY, int blockZ, int blockSide, int itemId, int itemCount, int itemData,
|
||||
NativeItemInstanceExtra itemExtra) {
|
||||
Callback.invokeAPICallback("ProjectileHit", projectile,
|
||||
new ItemInstance(itemId, itemCount, itemData, itemExtra),
|
||||
new ScriptableParams(
|
||||
@@ -741,8 +741,8 @@ public class NativeCallback {
|
||||
.useNotSupport("NativeCallback.onItemDispensed(x, y, z, side, id, count, data, extra, region, slot)");
|
||||
}
|
||||
|
||||
public static void onItemDispensed(float x, float y, float z, int side, int id, int count, int data, NativeItemInstanceExtra extra,
|
||||
Level level, int slot) {
|
||||
public static void onItemDispensed(float x, float y, float z, int side, int id, int count, int data,
|
||||
NativeItemInstanceExtra extra, Level level, int slot) {
|
||||
int rx = (int) Math.floor(x);
|
||||
int ry = (int) Math.floor(y);
|
||||
int rz = (int) Math.floor(z);
|
||||
@@ -790,8 +790,8 @@ public class NativeCallback {
|
||||
}
|
||||
}
|
||||
|
||||
public static void onEnchantPostHurt(int enchantId, int itemId, int itemCount, int itemData, NativeItemInstanceExtra itemExtra,
|
||||
int damage, long actor1, long actor2) {
|
||||
public static void onEnchantPostHurt(int enchantId, int itemId, int itemCount, int itemData,
|
||||
NativeItemInstanceExtra itemExtra, int damage, long actor1, long actor2) {
|
||||
ItemStack item = new ItemStack(itemId, itemCount, itemData, itemExtra);
|
||||
Callback.invokeAPICallback("EnchantPostHurt", enchantId, item, damage, actor1, actor2);
|
||||
if (!NativeAPI.isDefaultPrevented()) {
|
||||
|
||||
Reference in New Issue
Block a user