Compare commits

...

3 Commits

3 changed files with 18 additions and 14 deletions

View File

@ -16,19 +16,20 @@ public abstract class MixinSlot {
// Denying item moving etc. // Denying item moving etc.
@Inject(method = "canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At(value = "HEAD"), cancellable = true)
private void canTakeItems(PlayerEntity playerEntity, CallbackInfoReturnable<Boolean> cir) { private void canTakeItems(PlayerEntity playerEntity, CallbackInfoReturnable<Boolean> cir) {
ServerPlayerEntity player = (ServerPlayerEntity) playerEntity; if (playerEntity instanceof ServerPlayerEntity player) {
ActionResult result = AuthEventHandler.onTakeItem(player); ActionResult result = AuthEventHandler.onTakeItem(player);
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
// Canceling the item taking // Canceling the item taking
player.networkHandler.sendPacket( player.networkHandler.sendPacket(
new ScreenHandlerSlotUpdateS2CPacket( new ScreenHandlerSlotUpdateS2CPacket(
-2, -2,
0, 0,
player.getInventory().selectedSlot, player.getInventory().selectedSlot,
player.getInventory().getStack(player.getInventory().selectedSlot)) player.getInventory().getStack(player.getInventory().selectedSlot))
); );
cir.setReturnValue(false); cir.setReturnValue(false);
}
} }
} }
} }

View File

@ -2,9 +2,11 @@ package org.samo_lego.simpleauth;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.event.server.ServerStoppedEvent; import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.loading.FMLPaths;
@ -15,7 +17,7 @@ import org.samo_lego.simpleauth.commands.*;
public class SimpleAuthForge { public class SimpleAuthForge {
public SimpleAuthForge() { public SimpleAuthForge() {
SimpleAuth.init(FMLPaths.GAMEDIR.get()); SimpleAuth.init(FMLPaths.GAMEDIR.get());
MinecraftForge.EVENT_BUS.register(this); DistExecutor.safeRunWhenOn(Dist.DEDICATED_SERVER, () -> () -> MinecraftForge.EVENT_BUS.register(this));
} }
@SubscribeEvent @SubscribeEvent

View File

@ -2,6 +2,7 @@ package org.samo_lego.simpleauth.event;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
@ -15,7 +16,7 @@ import static org.samo_lego.simpleauth.SimpleAuth.MOD_ID;
* This class will take care of actions players try to do, * This class will take care of actions players try to do,
* and cancel them if they aren't authenticated * and cancel them if they aren't authenticated
*/ */
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) @Mod.EventBusSubscriber(value = Dist.DEDICATED_SERVER, modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class AuthEventHandlerForge { public class AuthEventHandlerForge {
@SubscribeEvent(priority = HIGHEST) @SubscribeEvent(priority = HIGHEST)
public static void onContainerOpen(PlayerContainerEvent.Open event) { public static void onContainerOpen(PlayerContainerEvent.Open event) {