From d42c895139d24c94e144c5bd05c05b439be349d3 Mon Sep 17 00:00:00 2001 From: MaXFeeD Date: Mon, 25 Dec 2023 06:44:41 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B3=D1=80=D0=BE=D0=B7=D0=B0=20=D0=BD=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D1=8F=20=D0=BF=D1=80=D0=B0=D0=B7=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/reider745/InnerCoreServer.java | 20 ++++++++++++----- .../com/reider745/event/EventListener.java | 22 ++++++++++--------- .../reider745/hooks/SnowfallEverywhere.java | 10 ++++++++- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/reider745/InnerCoreServer.java b/src/main/java/com/reider745/InnerCoreServer.java index f4764ccac..4a67906d8 100644 --- a/src/main/java/com/reider745/InnerCoreServer.java +++ b/src/main/java/com/reider745/InnerCoreServer.java @@ -2,12 +2,14 @@ import cn.nukkit.Server; import cn.nukkit.plugin.PluginDescription; +import cn.nukkit.plugin.PluginManager; import com.reider745.api.CallbackHelper; import com.reider745.block.CustomBlock; import com.reider745.commands.CommandsHelper; import com.reider745.event.EventListener; import com.reider745.event.InnerCorePlugin; +import com.reider745.hooks.SnowfallEverywhere; import com.reider745.item.CustomItem; import com.reider745.item.ItemMethod; @@ -290,8 +292,10 @@ public void preload(Server server) throws Exception { public void afterload() { server.getLogger().info("Registering Nukkit-MOT containment..."); - Logger.info("Register events ZotCoreLoader"); - InnerCoreServer.server.getPluginManager().registerEvents(new EventListener(), InnerCoreServer.plugin); + Logger.info("Registering ZoteCore events..."); + PluginManager pluginManager = server.getPluginManager(); + pluginManager.registerEvents(new EventListener(), plugin); + pluginManager.registerEvents(new SnowfallEverywhere(), plugin); CustomBlock.init(); CustomItem.postInit(); @@ -320,8 +324,9 @@ public static String getName() { } public static void useNotSupport(String name) { - if (!isDevelopMode()) + if (!isDevelopMode()) { return; + } String message = "Use not support multiplayer method " + name; if (isRuntimeException()) { throw new RuntimeException(message); @@ -331,8 +336,9 @@ public static void useNotSupport(String name) { } public static void useClientMethod(String name) { - if (!isDevelopMode()) + if (!isDevelopMode()) { return; + } String message = "Use client method " + name; if (isRuntimeException()) { throw new RuntimeException(message); @@ -342,8 +348,9 @@ public static void useClientMethod(String name) { } public static void useNotCurrentSupport(String name) { - if (!isDevelopMode()) + if (!isDevelopMode()) { return; + } String message = "The " + name + " method is currently not supported"; if (isRuntimeException()) { throw new RuntimeException(message); @@ -353,8 +360,9 @@ public static void useNotCurrentSupport(String name) { } public static void useIncomprehensibleMethod(String name) { - if (!isDevelopMode()) + if (!isDevelopMode()) { return; + } String message = "I don't really understand what this method does (" + name + "), which is why you're reading this right now"; if (isRuntimeException()) { diff --git a/src/main/java/com/reider745/event/EventListener.java b/src/main/java/com/reider745/event/EventListener.java index 68d69bfef..a91e29489 100644 --- a/src/main/java/com/reider745/event/EventListener.java +++ b/src/main/java/com/reider745/event/EventListener.java @@ -20,13 +20,13 @@ import cn.nukkit.event.player.PlayerInteractEntityEvent; import cn.nukkit.event.player.PlayerInteractEvent; import cn.nukkit.event.redstone.RedstoneUpdateEvent; -import cn.nukkit.inventory.Inventory; import cn.nukkit.item.Item; import cn.nukkit.item.food.Food; import cn.nukkit.level.Level; import cn.nukkit.level.Position; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.Vector3; + import com.reider745.api.CallbackHelper; import com.reider745.entity.EntityMethod; import com.reider745.hooks.ItemUtils; @@ -50,11 +50,12 @@ public void onInteract(PlayerInteractEvent event) { final Block block = event.getBlock(); final Player player = event.getPlayer(); - if (event.getAction() == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) + if (event.getAction() == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { consumeEvent(event, () -> NativeCallback.onItemUsed((int) block.x, (int) block.y, (int) block.z, event.getFace().getIndex(), (float) pos.x, (float) pos.y, (float) pos.z, true, player.getHealth() > 0, player.getId())); + } } public static void onBlockBreak(BlockBreakEvent event, boolean isNukkitPrevent) { @@ -177,8 +178,8 @@ private static int convertDamageCauseToEnum(DamageCause cause) { @EventHandler public void onEntityDamage(EntityDamageEvent event) { final Entity entity = event.getEntity(); - final Entity attacker = event instanceof EntityDamageByEntityEvent damageByEntity ? damageByEntity.getDamager() - : null; + final Entity attacker = event instanceof EntityDamageByEntityEvent damageByEntity + ? damageByEntity.getDamager() : null; if (attacker instanceof Player) { consumeEvent(event, @@ -196,8 +197,7 @@ public void onEntityDeath(EntityDeathEvent event) { final Entity entity = event.getEntity(); final EntityDamageEvent damageEvent = entity.getLastDamageCause(); final Entity attacker = damageEvent instanceof EntityDamageByEntityEvent damageByEntityEvent - ? damageByEntityEvent.getDamager() - : null; + ? damageByEntityEvent.getDamager() : null; NativeCallback.onEntityDied(entity.getId(), attacker != null ? attacker.getId() : -1, convertDamageCauseToEnum(damageEvent != null ? damageEvent.getCause() : DamageCause.CUSTOM)); @@ -242,9 +242,10 @@ public void onInteractEntity(PlayerInteractEntityEvent event) { @EventHandler public void onPickupItem(InventoryPickupItemEvent event) { final long dropEntity = event.getItem().getId(); - final long entity = event.getInventory() instanceof Inventory inventory - && inventory.getHolder() instanceof Entity pickupEntity ? pickupEntity.getId() : -1; - final int count = event.getItem().getItem() instanceof Item item ? item.getCount() : 0; + final long entity = event.getInventory().getHolder() instanceof Entity pickupEntity + ? pickupEntity.getId() : -1; + final Item item = event.getItem().getItem(); + final int count = item != null ? item.getCount() : 0; consumeEvent(event, () -> NativeCallback.onEntityPickUpDrop(entity, dropEntity, count)); } @@ -279,7 +280,8 @@ public void onBlockUpdate(BlockGrowEvent event) { // TODO: onItemDispensed - // TODO: onEnchantPostAttack, onEnchantPostHurt, onEnchantGetDamageBonus, onEnchantGetProtectionBonus + // TODO: onEnchantPostAttack, onEnchantPostHurt, onEnchantGetDamageBonus, + // onEnchantGetProtectionBonus // TODO: onWorkbenchCraft diff --git a/src/main/java/com/reider745/hooks/SnowfallEverywhere.java b/src/main/java/com/reider745/hooks/SnowfallEverywhere.java index 799d663d4..78df91aea 100644 --- a/src/main/java/com/reider745/hooks/SnowfallEverywhere.java +++ b/src/main/java/com/reider745/hooks/SnowfallEverywhere.java @@ -10,6 +10,9 @@ import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.blockentity.BlockEntitySpawnable; +import cn.nukkit.event.EventHandler; +import cn.nukkit.event.Listener; +import cn.nukkit.event.weather.LightningStrikeEvent; import cn.nukkit.level.DimensionData; import cn.nukkit.level.biome.Biome; import cn.nukkit.level.format.ChunkSection; @@ -28,7 +31,7 @@ * Special christmas adaptation, do not use anywhere else. */ @Hooks -public class SnowfallEverywhere implements HookClass { +public class SnowfallEverywhere implements HookClass, Listener { @Inject(className = "cn.nukkit.level.format.generic.serializer.NetworkChunkSerializer") public static void serialize(IntSet protocols, BaseChunk chunk, @@ -105,4 +108,9 @@ private static byte[] serializeEntities(BaseChunk chunk, int protocol) { throw new RuntimeException(e); } } + + @EventHandler + public void onLightningStrike(LightningStrikeEvent event) { + event.setCancelled(); + } }