Skip to content

Commit

Permalink
feat: Удалена гроза на время праздников
Browse files Browse the repository at this point in the history
  • Loading branch information
MaXFeeD committed Dec 25, 2023
1 parent b45ffd1 commit d42c895
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
20 changes: 14 additions & 6 deletions src/main/java/com/reider745/InnerCoreServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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()) {
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/reider745/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -279,7 +280,8 @@ public void onBlockUpdate(BlockGrowEvent event) {

// TODO: onItemDispensed

// TODO: onEnchantPostAttack, onEnchantPostHurt, onEnchantGetDamageBonus, onEnchantGetProtectionBonus
// TODO: onEnchantPostAttack, onEnchantPostHurt, onEnchantGetDamageBonus,
// onEnchantGetProtectionBonus

// TODO: onWorkbenchCraft

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/reider745/hooks/SnowfallEverywhere.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -105,4 +108,9 @@ private static byte[] serializeEntities(BaseChunk chunk, int protocol) {
throw new RuntimeException(e);
}
}

@EventHandler
public void onLightningStrike(LightningStrikeEvent event) {
event.setCancelled();
}
}

0 comments on commit d42c895

Please sign in to comment.