Commit d39dd9e8 by Jonathan Thomas

Don't allow interaction or damage messages from whitelist or blacklist entities

parent 05e3c903
Pipeline #12673 passed with stages
in 2 minutes 5 seconds
package com.owlmaddie.mixin; package com.owlmaddie.mixin;
import com.owlmaddie.chat.ChatDataManager; import com.owlmaddie.chat.ChatDataManager;
import com.owlmaddie.commands.ConfigurationHandler;
import com.owlmaddie.network.ServerPackets; import com.owlmaddie.network.ServerPackets;
import com.owlmaddie.utils.LivingEntityInterface; import com.owlmaddie.utils.LivingEntityInterface;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
...@@ -10,8 +11,10 @@ import net.minecraft.entity.mob.MobEntity; ...@@ -10,8 +11,10 @@ import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
...@@ -19,6 +22,8 @@ import org.spongepowered.asm.mixin.injection.Inject; ...@@ -19,6 +22,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.List;
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
public class MixinLivingEntity implements LivingEntityInterface { public class MixinLivingEntity implements LivingEntityInterface {
...@@ -44,6 +49,23 @@ public class MixinLivingEntity implements LivingEntityInterface { ...@@ -44,6 +49,23 @@ public class MixinLivingEntity implements LivingEntityInterface {
// If PLAYER attacks MOB then // If PLAYER attacks MOB then
if (attacker instanceof PlayerEntity && thisEntity instanceof MobEntity && !thisEntity.isDead()) { if (attacker instanceof PlayerEntity && thisEntity instanceof MobEntity && !thisEntity.isDead()) {
// Get config (whitelist / blacklist)
ConfigurationHandler.Config config = new ConfigurationHandler(ServerPackets.serverInstance).loadConfig();
List<String> whitelist = config.getWhitelist();
List<String> blacklist = config.getBlacklist();
Identifier entityId = Registries.ENTITY_TYPE.getId(thisEntity.getType());
String entityIdString = entityId.toString();
if (blacklist.contains(entityIdString)) {
// entity is black listed (no interacting)
return;
}
if (!whitelist.isEmpty() && !whitelist.contains(entityIdString)) {
// entity is not white listed (no interacting)
return;
}
// Generate attacked message (only if the previous user message was not an attacked message) // Generate attacked message (only if the previous user message was not an attacked message)
// We don't want to constantly generate messages during a prolonged, multi-damage event // We don't want to constantly generate messages during a prolonged, multi-damage event
ChatDataManager chatDataManager = ChatDataManager.getServerInstance(); ChatDataManager chatDataManager = ChatDataManager.getServerInstance();
......
package com.owlmaddie.mixin; package com.owlmaddie.mixin;
import com.owlmaddie.chat.ChatDataManager; import com.owlmaddie.chat.ChatDataManager;
import com.owlmaddie.commands.ConfigurationHandler;
import com.owlmaddie.network.ServerPackets; import com.owlmaddie.network.ServerPackets;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.List;
/** /**
* The {@code MixinMobEntity} mixin class exposes the goalSelector field from the MobEntity class. * The {@code MixinMobEntity} mixin class exposes the goalSelector field from the MobEntity class.
*/ */
...@@ -26,6 +31,22 @@ public class MixinMobEntity { ...@@ -26,6 +31,22 @@ public class MixinMobEntity {
ItemStack itemStack = player.getStackInHand(hand); ItemStack itemStack = player.getStackInHand(hand);
MobEntity thisEntity = (MobEntity) (Object) this; MobEntity thisEntity = (MobEntity) (Object) this;
// Get config (whitelist / blacklist)
ConfigurationHandler.Config config = new ConfigurationHandler(ServerPackets.serverInstance).loadConfig();
List<String> whitelist = config.getWhitelist();
List<String> blacklist = config.getBlacklist();
Identifier entityId = Registries.ENTITY_TYPE.getId(thisEntity.getType());
String entityIdString = entityId.toString();
if (blacklist.contains(entityIdString)) {
// entity is black listed (no interacting)
return;
}
if (!whitelist.isEmpty() && !whitelist.contains(entityIdString)) {
// entity is not white listed (no interacting)
return;
}
// Determine if the item is a bucket // Determine if the item is a bucket
// We don't want to interact on buckets // We don't want to interact on buckets
Item item = itemStack.getItem(); Item item = itemStack.getItem();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment