fix: don't respond to events for other players if on client
This commit is contained in:
parent
3b5e262bea
commit
0e036599cf
|
@ -1,6 +1,7 @@
|
|||
package io.gitlab.jfronny.breakme.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.thread.ThreadExecutor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -10,4 +11,11 @@ public class ClientImpl implements Client {
|
|||
public ThreadExecutor<Runnable> getRunner() {
|
||||
return Objects.requireNonNull(MinecraftClient.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlayer(PlayerEntity player) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
if (client == null || client.player == null) return false;
|
||||
return client.player.getUuid().equals(player.getUuid());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package io.gitlab.jfronny.breakme;
|
||||
|
||||
import io.gitlab.jfronny.breakme.client.Client;
|
||||
import io.gitlab.jfronny.breakme.crash.Method;
|
||||
import io.gitlab.jfronny.commons.logging.Logger;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Language;
|
||||
|
||||
|
@ -22,11 +25,17 @@ public class BreakMe implements ModInitializer {
|
|||
}
|
||||
|
||||
public static BreakMeConfig.Cause resolveEvent(PlayerEntity player) {
|
||||
if (player.isDead()) {
|
||||
return BreakMeConfig.Cause.Death;
|
||||
} else {
|
||||
return BreakMeConfig.Cause.Damage;
|
||||
if (!isValidPlayer(player)) return BreakMeConfig.Cause.None;
|
||||
else if (player.isDead()) return BreakMeConfig.Cause.Death;
|
||||
else return BreakMeConfig.Cause.Damage;
|
||||
}
|
||||
|
||||
public static boolean isValidPlayer(PlayerEntity player) {
|
||||
if (player == null) return false;
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
return Client.INSTANCE.isValidPlayer(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void crash() throws Exception {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package io.gitlab.jfronny.breakme.client;
|
||||
|
||||
import io.gitlab.jfronny.commons.throwable.Try;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.thread.ThreadExecutor;
|
||||
|
||||
public interface Client {
|
||||
Client INSTANCE = (Client) Try.orThrow(() -> Class.forName(Client.class.getName() + "Impl").getConstructor().newInstance());
|
||||
|
||||
ThreadExecutor<Runnable> getRunner();
|
||||
boolean isValidPlayer(PlayerEntity player);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ public class PlayerEntityMixin {
|
|||
|
||||
@Inject(at = @At("TAIL"), method = "onDeath(Lnet/minecraft/entity/damage/DamageSource;)V")
|
||||
private void onDeath(DamageSource damageSource, CallbackInfo ci) throws Exception {
|
||||
BreakMe.tryInvokeCrash(BreakMeConfig.Cause.Death);
|
||||
if (BreakMe.isValidPlayer((PlayerEntity)(Object)this)) {
|
||||
BreakMe.tryInvokeCrash(BreakMeConfig.Cause.Death);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue