From e828782be61d567491400bf519142c32356fc1cc Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 27 Jan 2023 01:54:13 +0800 Subject: [PATCH] Snowman performance change --- .../java/net/citizensnpcs/EventListen.java | 12 +++++++++ .../citizensnpcs/commands/NPCCommands.java | 9 +++++-- .../net/citizensnpcs/trait/text/Text.java | 4 +-- .../v1_10_R1/entity/SnowmanController.java | 12 --------- .../v1_11_R1/entity/SnowmanController.java | 12 --------- .../v1_12_R1/entity/SnowmanController.java | 12 --------- .../v1_13_R2/entity/SnowmanController.java | 26 ------------------- .../v1_14_R1/entity/SnowmanController.java | 13 ---------- .../v1_15_R1/entity/SnowmanController.java | 13 ---------- .../v1_16_R3/entity/SnowmanController.java | 13 ---------- .../v1_17_R1/entity/SnowmanController.java | 13 ---------- .../v1_18_R2/entity/SnowmanController.java | 13 ---------- .../v1_19_R2/entity/SnowmanController.java | 13 ---------- .../nms/v1_8_R3/entity/SnowmanController.java | 12 --------- 14 files changed, 21 insertions(+), 156 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index 2576290ee..6234cb05c 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -13,12 +13,14 @@ import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Minecart; import org.bukkit.entity.Player; +import org.bukkit.entity.Snowman; import org.bukkit.entity.Vehicle; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityCombustByBlockEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent; @@ -211,6 +213,16 @@ public class EventListen implements Listener { checkCreationEvent(event); } + @EventHandler + public void onEntityBlockForm(EntityBlockFormEvent event) { + NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity()); + if (npc == null) + return; + if (npc.getEntity() instanceof Snowman) { + event.setCancelled(true); + } + } + /* * Entity events */ diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 5d7a24188..3a143107f 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -123,6 +123,7 @@ import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.MirrorTrait; import net.citizensnpcs.trait.MountTrait; import net.citizensnpcs.trait.OcelotModifiers; +import net.citizensnpcs.trait.PacketNPC; import net.citizensnpcs.trait.Poses; import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.RabbitType; @@ -638,9 +639,9 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary),c(enter)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --nameplate [true|false|hover] --temporaryticks [ticks] --registry [registry name])", + usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary),c(enter),p(acket)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --nameplate [true|false|hover] --temporaryticks [ticks] --registry [registry name])", desc = "Create a new NPC", - flags = "bustc", + flags = "bustpc", modifiers = { "create" }, min = 2, permission = "citizens.npc.create") @@ -729,6 +730,10 @@ public class NPCCommands { npc.getOrAddTrait(MobType.class).setType(type); + if (args.hasFlag('p')) { + npc.addTrait(PacketNPC.class); + } + Location spawnLoc = null; if (sender instanceof Player) { spawnLoc = args.getSenderLocation(); diff --git a/main/src/main/java/net/citizensnpcs/trait/text/Text.java b/main/src/main/java/net/citizensnpcs/trait/text/Text.java index 4bcafaae1..609136b1f 100644 --- a/main/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/main/src/main/java/net/citizensnpcs/trait/text/Text.java @@ -279,8 +279,8 @@ public class Text extends Trait implements Runnable, Listener { sendText(player); int delay = this.delay == -1 - ? Util.getFastRandom().nextInt(Setting.DEFAULT_TEXT_DELAY_MIN.asInt(), - Setting.DEFAULT_TEXT_DELAY_MAX.asInt()) + ? Setting.DEFAULT_TEXT_DELAY_MIN.asInt() + Util.getFastRandom() + .nextInt(Setting.DEFAULT_TEXT_DELAY_MAX.asInt() - Setting.DEFAULT_TEXT_DELAY_MIN.asInt()) : this.delay; if (delay <= 0) return; diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/SnowmanController.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/SnowmanController.java index bb07db264..e36c7640d 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/SnowmanController.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/SnowmanController.java @@ -174,18 +174,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void n() { - boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing"); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", "false"); - } - super.n(); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing)); - } - } - @Override public void setSize(float f, float f1) { if (npc == null) { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/SnowmanController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/SnowmanController.java index d99bfcc90..d570c4b3f 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/SnowmanController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/SnowmanController.java @@ -174,18 +174,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void n() { - boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing"); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", "false"); - } - super.n(); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing)); - } - } - @Override public void setSize(float f, float f1) { if (npc == null) { diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/SnowmanController.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/SnowmanController.java index 6a283c373..c956d05c5 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/SnowmanController.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/SnowmanController.java @@ -177,18 +177,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void n() { - boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing"); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", "false"); - } - super.n(); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing)); - } - } - @Override public void setSize(float f, float f1) { if (npc == null) { diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/SnowmanController.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/SnowmanController.java index 564f55a25..6f5ab5811 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/SnowmanController.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/SnowmanController.java @@ -1,7 +1,5 @@ package net.citizensnpcs.nms.v1_13_R2.entity; -import java.lang.reflect.Method; - import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_13_R2.CraftServer; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; @@ -15,7 +13,6 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.nms.v1_13_R2.util.NMSImpl; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.v1_13_R2.BlockPosition; import net.minecraft.server.v1_13_R2.DamageSource; @@ -189,27 +186,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void movementTick() { - boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing"); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", "false", this.world.getMinecraftServer()); - } - try { - super.movementTick(); - } catch (NoSuchMethodError ex) { - try { - MOVEMENT_TICK.invoke(this); - } catch (Throwable ex2) { - ex2.printStackTrace(); - } - } - if (npc != null) { - this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing), - this.world.getMinecraftServer()); - } - } - @Override protected boolean n(Entity entity) { if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) { @@ -235,8 +211,6 @@ public class SnowmanController extends MobEntityController { return false; } } - - private static final Method MOVEMENT_TICK = NMS.getMethod(EntitySnowman.class, "k", false); } public static class SnowmanNPC extends CraftSnowman implements NPCHolder { diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/SnowmanController.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/SnowmanController.java index 417f30a1b..005fa5740 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/SnowmanController.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/SnowmanController.java @@ -22,7 +22,6 @@ import net.minecraft.server.v1_14_R1.EntityMinecartAbstract; import net.minecraft.server.v1_14_R1.EntitySnowman; import net.minecraft.server.v1_14_R1.EntityTypes; import net.minecraft.server.v1_14_R1.FluidType; -import net.minecraft.server.v1_14_R1.GameRules; import net.minecraft.server.v1_14_R1.IBlockData; import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.SoundEffect; @@ -195,18 +194,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void movementTick() { - boolean allowsGriefing = this.world.getGameRules().get(GameRules.MOB_GRIEFING).a(); - if (npc != null) { - this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue("false"); - } - super.movementTick(); - if (npc != null) { - this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue(Boolean.toString(allowsGriefing)); - } - } - @Override protected boolean n(Entity entity) { if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/SnowmanController.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/SnowmanController.java index 865ae595a..4da5314bb 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/SnowmanController.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/SnowmanController.java @@ -23,7 +23,6 @@ import net.minecraft.server.v1_15_R1.EntityMinecartAbstract; import net.minecraft.server.v1_15_R1.EntitySnowman; import net.minecraft.server.v1_15_R1.EntityTypes; import net.minecraft.server.v1_15_R1.FluidType; -import net.minecraft.server.v1_15_R1.GameRules; import net.minecraft.server.v1_15_R1.IBlockData; import net.minecraft.server.v1_15_R1.NBTTagCompound; import net.minecraft.server.v1_15_R1.SoundEffect; @@ -198,18 +197,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void movementTick() { - boolean allowsGriefing = this.world.getGameRules().get(GameRules.MOB_GRIEFING).a(); - if (npc != null) { - this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue("false"); - } - super.movementTick(); - if (npc != null) { - this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue(Boolean.toString(allowsGriefing)); - } - } - @Override protected boolean n(Entity entity) { if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) { diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/SnowmanController.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/SnowmanController.java index e658db1cb..8d55777c3 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/SnowmanController.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/SnowmanController.java @@ -23,7 +23,6 @@ import net.minecraft.server.v1_16_R3.EntityMinecartAbstract; import net.minecraft.server.v1_16_R3.EntitySnowman; import net.minecraft.server.v1_16_R3.EntityTypes; import net.minecraft.server.v1_16_R3.FluidType; -import net.minecraft.server.v1_16_R3.GameRules; import net.minecraft.server.v1_16_R3.IBlockData; import net.minecraft.server.v1_16_R3.NBTTagCompound; import net.minecraft.server.v1_16_R3.SoundEffect; @@ -198,18 +197,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void movementTick() { - boolean allowsGriefing = this.world.getGameRules().get(GameRules.MOB_GRIEFING).a(); - if (npc != null) { - this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue("false"); - } - super.movementTick(); - if (npc != null) { - this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue(Boolean.toString(allowsGriefing)); - } - } - @Override protected boolean n(Entity entity) { if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) { diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/SnowmanController.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/SnowmanController.java index 8bc05edf4..37a550308 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/SnowmanController.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/SnowmanController.java @@ -24,7 +24,6 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.animal.SnowGolem; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.entity.vehicle.Boat; -import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; @@ -52,18 +51,6 @@ public class SnowmanController extends MobEntityController { this.npc = (CitizensNPC) npc; } - @Override - public void aiStep() { - boolean allowsGriefing = this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); - if (npc != null) { - this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(false, getServer()); - } - super.aiStep(); - if (npc != null) { - this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(allowsGriefing, getServer()); - } - } - @Override protected boolean canRide(Entity entity) { if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) { diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/SnowmanController.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/SnowmanController.java index 5dbdfc02a..aa3ee3dd2 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/SnowmanController.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/SnowmanController.java @@ -25,7 +25,6 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.animal.SnowGolem; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.entity.vehicle.Boat; -import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; @@ -53,18 +52,6 @@ public class SnowmanController extends MobEntityController { this.npc = (CitizensNPC) npc; } - @Override - public void aiStep() { - boolean allowsGriefing = this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); - if (npc != null) { - this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(false, getServer()); - } - super.aiStep(); - if (npc != null) { - this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(allowsGriefing, getServer()); - } - } - @Override protected boolean canRide(Entity entity) { if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) { diff --git a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/SnowmanController.java b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/SnowmanController.java index de17e3675..2bdffa85d 100644 --- a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/SnowmanController.java +++ b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/SnowmanController.java @@ -1,7 +1,6 @@ package net.citizensnpcs.nms.v1_19_R2.entity; import org.bukkit.Bukkit; -import org.bukkit.GameRule; import org.bukkit.craftbukkit.v1_19_R2.CraftServer; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftSnowman; @@ -54,18 +53,6 @@ public class SnowmanController extends MobEntityController { this.npc = (CitizensNPC) npc; } - @Override - public void aiStep() { - boolean allowsGriefing = this.level.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING); - if (npc != null) { - this.level.getWorld().setGameRule(GameRule.MOB_GRIEFING, false); - } - super.aiStep(); - if (npc != null) { - this.level.getWorld().setGameRule(GameRule.MOB_GRIEFING, allowsGriefing); - } - } - @Override protected boolean canRide(Entity entity) { if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) { diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java index 32b34d688..77ebd4405 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java @@ -168,18 +168,6 @@ public class SnowmanController extends MobEntityController { } } - @Override - public void m() { - boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing"); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", "false"); - } - super.m(); - if (npc != null) { - this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing)); - } - } - @Override public void setSize(float f, float f1) { if (npc == null) {