parent
235d05b6df
commit
4187a855fb
|
@ -2,12 +2,12 @@
|
|||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric properties
|
||||
minecraft_version=1.15-pre2
|
||||
yarn_mappings=1.15-pre2+build.3
|
||||
loader_version=0.7.1+build.173
|
||||
minecraft_version=1.15-pre3
|
||||
yarn_mappings=1.15-pre3+build.2
|
||||
loader_version=0.7.2+build.174
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.4.16+build.268-1.15
|
||||
fabric_version=0.4.18+build.271-1.15
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package org.samo_lego.simpleauth.event;
|
||||
|
||||
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
|
||||
import net.minecraft.client.network.packet.InventoryS2CPacket;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketEncoder;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.ChatMessageC2SPacket;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
@ -32,19 +35,17 @@ public class AuthEventHandler {
|
|||
SimpleAuth.authenticatedUsers.remove(player);
|
||||
}
|
||||
|
||||
// todo
|
||||
public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) {
|
||||
String msg = chatMessageC2SPacket.getChatMessage();
|
||||
if(!SimpleAuth.authenticatedUsers.contains(player) && !(msg.startsWith("/login") || msg.startsWith("/register"))) {
|
||||
if(!SimpleAuth.authenticatedUsers.contains(player) && !msg.startsWith("/login") && !msg.startsWith("/register")) {
|
||||
player.sendMessage(notAuthenticated);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
//todo
|
||||
// Player movement
|
||||
public static ActionResult onPlayerMove(PlayerEntity player) {
|
||||
if(!SimpleAuth.authenticatedUsers.contains(player)) {
|
||||
// TP player back?
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package org.samo_lego.simpleauth.mixin;
|
||||
|
||||
import net.minecraft.client.network.packet.InventoryS2CPacket;
|
||||
import net.minecraft.container.PlayerContainer;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.UpdateSelectedSlotC2SPacket;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import org.samo_lego.simpleauth.event.item.DropItemCallback;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
|
@ -20,7 +22,7 @@ public abstract class MixinPlayerEntity {
|
|||
@Shadow @Final public PlayerContainer playerContainer;
|
||||
|
||||
// Thanks to PR https://github.com/FabricMC/fabric/pull/260 and AbusedLib https://github.com/abused/AbusedLib
|
||||
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("HEAD"), cancellable = true)
|
||||
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("INVOKE"), cancellable = true)
|
||||
private void dropItem(ItemStack stack, boolean dropAtFeet, boolean saveThrower, CallbackInfoReturnable<ItemEntity> cir) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
|
||||
ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player);
|
||||
|
@ -28,8 +30,6 @@ public abstract class MixinPlayerEntity {
|
|||
if (result == ActionResult.FAIL) {
|
||||
// Canceling the item drop, as well as giving the items back to player (and updating inv with packet)
|
||||
player.giveItemStack(stack);
|
||||
|
||||
player.inventory.updateItems();
|
||||
playerContainer.sendContentUpdates();
|
||||
cir.cancel();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.samo_lego.simpleauth.mixin;
|
||||
|
||||
import net.minecraft.client.network.packet.InventoryS2CPacket;
|
||||
import net.minecraft.client.network.packet.PlayerSpawnPositionS2CPacket;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.ChatMessageC2SPacket;
|
||||
|
@ -14,11 +18,12 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public class MixinServerPlayNetworkHandler {
|
||||
public abstract class MixinServerPlayNetworkHandler {
|
||||
@Shadow
|
||||
public ServerPlayerEntity player;
|
||||
|
||||
// TODO
|
||||
@Shadow public abstract void sendPacket(Packet<?> packet_1);
|
||||
|
||||
@Inject(
|
||||
method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)V",
|
||||
at = @At(
|
||||
|
@ -50,6 +55,8 @@ public class MixinServerPlayNetworkHandler {
|
|||
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) {
|
||||
ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player);
|
||||
if (result == ActionResult.FAIL) {
|
||||
// A bit ugly, I know. (we need to update player position)
|
||||
player.teleport(player.getX(), player.getY(), player.getZ());
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue