fix chat and effects bugs.

This commit is contained in:
mlus-Asuka 2023-02-16 14:26:24 +08:00
parent d2921adc88
commit 30b1690a73
5 changed files with 16 additions and 17 deletions

View File

@ -4,7 +4,7 @@ plugins {
id 'net.minecraftforge.gradle' version '5.1.+' id 'net.minecraftforge.gradle' version '5.1.+'
} }
version = '1.0' version = '1.1.2'
group = 'vip.fubuki.PlayerSync' // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = 'vip.fubuki.PlayerSync' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'playersync' archivesBaseName = 'playersync'

View File

@ -3,19 +3,19 @@ package vip.fubuki.playersync.sync;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.players.PlayerList; import net.minecraft.server.players.PlayerList;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import vip.fubuki.playersync.util.JDBCsetUp; import vip.fubuki.playersync.util.JDBCsetUp;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Objects;
@Mod.EventBusSubscriber
public class ChatSync { public class ChatSync {
static int tick = 0; static int tick = 0;
static long current = System.currentTimeMillis(); static long current = System.currentTimeMillis();
@SubscribeEvent @SubscribeEvent
public static void onPlayerChat(net.minecraftforge.event.ServerChatEvent event) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException { public static void onPlayerChat(net.minecraftforge.event.ServerChatEvent event) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
ReadMessage(Objects.requireNonNull(event.getPlayer().getServer()).getPlayerList()); JDBCsetUp.executeUpdate("INSERT INTO chat (player, message, timestamp) VALUES ('" + event.getUsername() + "', '" + event.getRawText() + "', '" + current + "')");
JDBCsetUp.executeUpdate("INSERT INTO chat (player, message, timestamp) VALUES ('" + event.getUsername() + "', '" + event.getMessage() + "', '" + current + "')");
} }
@SubscribeEvent @SubscribeEvent

View File

@ -1,7 +1,6 @@
package vip.fubuki.playersync.sync; package vip.fubuki.playersync.sync;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -14,7 +13,6 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import vip.fubuki.playersync.PlayerSync;
import vip.fubuki.playersync.config.JdbcConfig; import vip.fubuki.playersync.config.JdbcConfig;
import vip.fubuki.playersync.util.JDBCsetUp; import vip.fubuki.playersync.util.JDBCsetUp;
import vip.fubuki.playersync.util.LocalJsonUtil; import vip.fubuki.playersync.util.LocalJsonUtil;
@ -69,13 +67,16 @@ public class VanillaSync {
serverPlayer.getEnderChestInventory().setItem(entry.getKey(),Deserialize(entry)); serverPlayer.getEnderChestInventory().setItem(entry.getKey(),Deserialize(entry));
} }
//Effects //Effects
serverPlayer.removeAllEffects(); String effectData=resultSet.getString("effects");
Map<Integer, String> effects = LocalJsonUtil.StringToEntryMap(resultSet.getString("effects")); if(effectData.length()>2) {
for (Map.Entry<Integer, String> entry : effects.entrySet()) { serverPlayer.removeAllEffects();
CompoundTag effectTag = NbtUtils.snbtToStructure(entry.getValue().replace("|", ",")); Map<Integer, String> effects = LocalJsonUtil.StringToEntryMap(effectData);
MobEffectInstance mobEffectInstance = MobEffectInstance.load(effectTag); for (Map.Entry<Integer, String> entry : effects.entrySet()) {
assert mobEffectInstance != null; CompoundTag effectTag = NbtUtils.snbtToStructure(entry.getValue().replace("|", ","));
serverPlayer.addEffect(mobEffectInstance); MobEffectInstance mobEffectInstance = MobEffectInstance.load(effectTag);
assert mobEffectInstance != null;
serverPlayer.addEffect(mobEffectInstance);
}
} }
//Advancements //Advancements
File gameDir = serverPlayer.getServer().getServerDirectory(); File gameDir = serverPlayer.getServer().getServerDirectory();

View File

@ -32,9 +32,7 @@ public class JDBCsetUp {
} }
public static void executeUpdate(String sql) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException { public static void executeUpdate(String sql) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
Statement statement= getConnection(false).createStatement(); executeUpdate(sql,false);
statement.executeUpdate(sql);
statement.close();
} }
public static void executeUpdate(String sql,boolean init) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException { public static void executeUpdate(String sql,boolean init) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {

View File

@ -19,7 +19,7 @@ modId="playersync" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build # see the associated build.gradle script for how to populate this completely automatically during a build
version="1.0" #mandatory version="1.1.2" #mandatory
# A display name for the mod # A display name for the mod
displayName="PlayerSync" #mandatory displayName="PlayerSync" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/