Update to 1.15pre2

Added chat protection and movement protection. Mod should now enter polishing state.
This commit is contained in:
samo_lego 2019-11-26 22:11:56 +01:00
parent beeb1183fc
commit 653230e534
5 changed files with 37 additions and 27 deletions

View File

@ -1,14 +1,13 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
minecraft_version=1.15-pre1
yarn_mappings=1.15-pre1+build.3
# Fabric properties
minecraft_version=1.15-pre2
yarn_mappings=1.15-pre2+build.3
loader_version=0.7.1+build.173
# Dependencies
# Fabric API
fabric_version=0.4.13+build.264-1.15
#Fabric api
fabric_version=0.4.16+build.268-1.15
# Mod Properties
mod_version = 1.0.0

View File

@ -35,20 +35,16 @@ public class AuthEventHandler {
// todo
public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) {
String msg = chatMessageC2SPacket.getChatMessage();
System.out.println(msg);
if(!SimpleAuth.authenticatedUsers.contains(player) || !msg.startsWith("/login") || !msg.startsWith("/register")) {
System.out.println("Ok.");
if(!SimpleAuth.authenticatedUsers.contains(player) && !(msg.startsWith("/login") || msg.startsWith("/register"))) {
player.sendMessage(notAuthenticated);
return ActionResult.FAIL;
}
System.out.println("Pass "+ msg.startsWith("/login")+msg.startsWith("/register"));
return ActionResult.PASS;
}
//todo
public static ActionResult onPlayerMove(PlayerEntity player) {
if(!SimpleAuth.authenticatedUsers.contains(player)) {
System.out.println("Ok. Moved & should fail. AuthEventHandler");
player.sendMessage(notAuthenticated);
// TP player back?
return ActionResult.FAIL;
}
return ActionResult.PASS;

View File

@ -26,10 +26,12 @@ public abstract class MixinPlayerEntity {
ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player);
if (result == ActionResult.FAIL) {
// Canceling the item drop, as well as giving the items back to player
cir.cancel();
// 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();
}
}
}

View File

@ -12,7 +12,6 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerPlayNetworkHandler.class)
public class MixinServerPlayNetworkHandler {
@ -20,24 +19,38 @@ public class MixinServerPlayNetworkHandler {
public ServerPlayerEntity player;
// TODO
@Inject(method = "onChatMessage", at = @At(value = "HEAD"), cancellable = true)
private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket_1, CallbackInfoReturnable cir) {
@Inject(
method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)V",
at = @At(
value = "INVOKE",
// Thanks to Liach for helping me out!
target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V",
shift = At.Shift.AFTER
),
cancellable = true
)
private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket_1, CallbackInfo ci) {
ActionResult result = OnChatCallback.EVENT.invoker().onPlayerChat(player, chatMessageC2SPacket_1);
System.out.println("Mixined");
if (result == ActionResult.FAIL) {
cir.cancel();
ci.cancel();
}
}
// TODO
@Inject(method="onPlayerMove", at = @At(value = "HEAD"), cancellable = true)
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo cir) {
@Inject(
method="onPlayerMove(Lnet/minecraft/server/network/packet/PlayerMoveC2SPacket;)V",
at = @At(
value = "INVOKE",
// Thanks to Liach for helping me out!
target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V",
shift = At.Shift.AFTER
),
cancellable = true
)
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) {
ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player);
System.out.println("Player move");
if (result == ActionResult.FAIL) {
cir.cancel();
ci.cancel();
}
}
}

View File

@ -5,7 +5,7 @@
"mixins": [
],
"server": [
"MixinServerPlayNetworkHandler",
"MixinPlayerManager",
"MixinPlayerEntity"
],