FTB init
This commit is contained in:
parent
079ccb4c09
commit
1cb3998755
|
|
@ -1,12 +1,19 @@
|
||||||
package vip.fubuki.playersync;
|
package vip.fubuki.playersync;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import vip.fubuki.playersync.config.JdbcConfig;
|
import vip.fubuki.playersync.config.JdbcConfig;
|
||||||
|
import vip.fubuki.playersync.util.JDBCsetUp;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
@Mod(PlayerSync.MODID)
|
@Mod(PlayerSync.MODID)
|
||||||
public class PlayerSync
|
public class PlayerSync
|
||||||
|
|
@ -19,4 +26,22 @@ public class PlayerSync
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException {
|
||||||
|
if (event.getPlayer() instanceof ServerPlayerEntity) {
|
||||||
|
String player_uuid = event.getEntity().getUUID().toString();
|
||||||
|
JDBCsetUp.QueryResult queryResult=JDBCsetUp.executeQuery("SELECT * FROM AstralSorcery WHERE player='" + player_uuid + "';");
|
||||||
|
ResultSet resultSet=queryResult.getResultSet();
|
||||||
|
if(!resultSet.next()){
|
||||||
|
JDBCsetUp.executeUpdate("INSERT INTO AstralSorcery(player,tag) VALUES('"+player_uuid+"','{}');");
|
||||||
|
}
|
||||||
|
|
||||||
|
queryResult=JDBCsetUp.executeQuery("SELECT * FROM FTB WHERE player='" + player_uuid + "';");
|
||||||
|
resultSet=queryResult.getResultSet();
|
||||||
|
if(!resultSet.next()){
|
||||||
|
JDBCsetUp.executeUpdate("INSERT INTO FTB(player,tag) VALUES('"+player_uuid+"','{}');");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,61 +1,30 @@
|
||||||
package vip.fubuki.playersync.mixin;
|
package vip.fubuki.playersync.mixin;
|
||||||
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import hellfirepvp.astralsorcery.common.data.research.PlayerProgress;
|
import hellfirepvp.astralsorcery.common.data.research.PlayerProgress;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.nbt.JsonToNBT;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
import vip.fubuki.playersync.util.JDBCsetUp;
|
import vip.fubuki.playersync.util.JDBCsetUp;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
@Mixin(PlayerProgress.class)
|
@Mixin(PlayerProgress.class)
|
||||||
public abstract class MixinPlayerProgress {
|
public class MixinPlayerProgress{
|
||||||
@Shadow public abstract void load(CompoundNBT compound);
|
|
||||||
|
|
||||||
@ModifyArg(method = "store", at = @At(value = "INVOKE", target = "Lhellfirepvp/astralsorcery/common/data/research/PlayerPerkData;save(Lnet/minecraft/nbt/CompoundNBT;)V"))
|
@ModifyArg(method = "store", at = @At(value = "INVOKE", target = "Lhellfirepvp/astralsorcery/common/data/research/PlayerPerkData;save(Lnet/minecraft/nbt/CompoundNBT;)V"))
|
||||||
private CompoundNBT save(CompoundNBT tag) {
|
private CompoundNBT save(CompoundNBT tag) {
|
||||||
tag.putBoolean("PlayerSync",false);
|
String nbt = tag.toString();
|
||||||
String nbt = tag.toString().replace(",","|").replace("\"","^").replace("{","<").replace("}",">").replace("'","~");
|
nbt.replace(",","|").replace("\"","^").replace("{","<").replace("}",">").replace("'","~");
|
||||||
try {
|
try {
|
||||||
PreparedStatement preparedStatement= JDBCsetUp.getConnection().prepareStatement("INSERT INTO AstralSorcery(player,tag) VALUES(?,?) ON DUPLICATE KEY UPDATE player=?");
|
PreparedStatement preparedStatement= JDBCsetUp.getConnection().prepareStatement("UPDATE AstralSorcery SET tag=? WHERE player=?");
|
||||||
preparedStatement.setString(1,tag.getString("UUID"));
|
preparedStatement.setString(2,tag.getString("UUID"));
|
||||||
preparedStatement.setString(2,nbt);
|
preparedStatement.setString(1,nbt);
|
||||||
preparedStatement.setString(3,tag.getString("UUID"));
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException throwable) {
|
} catch (SQLException throwable) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "load",at=@At(value="HEAD"), cancellable = true)
|
|
||||||
private void load(CompoundNBT compound, CallbackInfo ci){
|
|
||||||
if(compound.get("PlayerSync")==null || !compound.getBoolean("PlayerSync")){
|
|
||||||
try {
|
|
||||||
ResultSet result= JDBCsetUp.executeQuery("SELECT * FROM AstralSorcery WHERE player='" + compound.getString("UUID") + "';").getResultSet();
|
|
||||||
if(result.next()){
|
|
||||||
String nbt = result.getString("tag").replace("|",",").replace("^","\"").replace("<","{").replace(">","}").replace("~", "'");
|
|
||||||
compound=JsonToNBT.parseTag(nbt);
|
|
||||||
compound.putBoolean("PlayerSync",true);
|
|
||||||
load(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (SQLException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (CommandSyntaxException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package vip.fubuki.playersync.mixin;
|
package vip.fubuki.playersync.mixin;
|
||||||
|
|
||||||
|
|
||||||
import dev.ftb.mods.ftblibrary.snbt.SNBT;
|
|
||||||
import dev.ftb.mods.ftbquests.quest.ServerQuestFile;
|
import dev.ftb.mods.ftbquests.quest.ServerQuestFile;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
|
@ -12,25 +11,85 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import static dev.ftb.mods.ftbquests.quest.ServerQuestFile.FTBQUESTS_DATA;
|
|
||||||
|
|
||||||
@Mixin(ServerQuestFile.class)
|
@Mixin(ServerQuestFile.class)
|
||||||
public class MixinServerQuestFile {
|
public abstract class MixinServerQuestFile {
|
||||||
|
|
||||||
@Shadow @Final public MinecraftServer server;
|
@Shadow @Final public MinecraftServer server;
|
||||||
|
|
||||||
@Inject(method ="saveNow",at = @At("RETURN"))
|
@Shadow
|
||||||
private void saveNow(CallbackInfo ci){
|
private boolean shouldSave;
|
||||||
Path path = this.server.getWorldPath(FTBQUESTS_DATA);
|
|
||||||
|
|
||||||
|
@Shadow private Path folder;
|
||||||
|
@Shadow private boolean isLoading;
|
||||||
|
|
||||||
|
@Shadow public abstract Path getFolder();
|
||||||
|
|
||||||
|
@Inject(method ="saveNow",at = @At("RETURN"), cancellable = true)
|
||||||
|
private void saveNow(CallbackInfo ci){
|
||||||
|
// if (shouldSave) {
|
||||||
|
// ((QuestFileAccessor) this).invokeWriteDataFull(this.getFolder());
|
||||||
|
// shouldSave = false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Path path = server.getWorldPath(FTBQUESTS_DATA);
|
||||||
|
//
|
||||||
|
// for (TeamData data : ((QuestFileAccessor) this).invokeGetAllData()) {
|
||||||
|
// if (data.shouldSave) {
|
||||||
|
// SNBT.write(path.resolve(data.uuid + ".snbt"), data.serializeNBT());
|
||||||
|
//
|
||||||
|
// String nbt = data.serializeNBT().toString();
|
||||||
|
// nbt.replace(",", "|").replace("\"", "^").replace("{", "<").replace("}", ">").replace("'", "~");
|
||||||
|
// try {
|
||||||
|
// PreparedStatement preparedStatement = JDBCsetUp.getConnection().prepareStatement("UPDATE FTB SET tag=? WHERE player=?");
|
||||||
|
// preparedStatement.setString(2, data.uuid.toString());
|
||||||
|
// preparedStatement.setString(1, nbt);
|
||||||
|
// preparedStatement.executeUpdate();
|
||||||
|
// } catch (SQLException throwable) {
|
||||||
|
// throwable.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// data.shouldSave = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method="load",at = @At("HEAD"))
|
@Inject(method="load",at = @At("HEAD"))
|
||||||
private void load(CallbackInfo ci){
|
private void load(CallbackInfo ci){
|
||||||
Path path = this.server.getWorldPath(FTBQUESTS_DATA);
|
// folder = Platform.getConfigFolder().resolve("ftbquests/quests");
|
||||||
// SNBT.write(path.resolve(data.uuid + ".snbt"), data.serializeNBT());
|
//
|
||||||
|
// if (Files.exists(folder)) {
|
||||||
|
// FTBQuests.LOGGER.info("Loading quests from " + folder);
|
||||||
|
// isLoading = true;
|
||||||
|
// ((QuestFileAccessor)this).invokeReadDataFull(folder);
|
||||||
|
// isLoading = false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Path path = server.getWorldPath(FTBQUESTS_DATA);
|
||||||
|
//
|
||||||
|
// if (Files.exists(path)) {
|
||||||
|
// try {
|
||||||
|
// Files.list(path).filter(p -> p.getFileName().toString().contains("-")).forEach(path1 -> {
|
||||||
|
// SNBTCompoundTag nbt = SNBT.read(path1);
|
||||||
|
//
|
||||||
|
// if (nbt != null) {
|
||||||
|
// try {
|
||||||
|
// UUID uuid = UUIDTypeAdapter.fromString(nbt.getString("uuid"));
|
||||||
|
// TeamData data = new TeamData(uuid);
|
||||||
|
// data.file = (ServerQuestFile)((Object)this);
|
||||||
|
// this.addData(data, true);
|
||||||
|
// data.deserializeNBT(nbt);
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// ex.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// ex.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package vip.fubuki.playersync.mixin.accessor;
|
||||||
|
|
||||||
|
import dev.ftb.mods.ftbquests.quest.QuestFile;
|
||||||
|
import dev.ftb.mods.ftbquests.quest.TeamData;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Mixin(value = QuestFile.class,remap = false)
|
||||||
|
public interface QuestFileAccessor {
|
||||||
|
@Invoker
|
||||||
|
void invokeWriteDataFull(Path folder);
|
||||||
|
@Invoker
|
||||||
|
Collection<TeamData> invokeGetAllData();
|
||||||
|
|
||||||
|
@Invoker
|
||||||
|
void invokeReadDataFull(Path folder);
|
||||||
|
void invokeAddData(TeamData data, boolean override);
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,8 @@
|
||||||
"refmap": "thirst.refmap.json",
|
"refmap": "thirst.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinPlayerProgress",
|
"MixinPlayerProgress",
|
||||||
"MixinServerQuestFile"
|
"MixinServerQuestFile",
|
||||||
|
"accessor.QuestFileAccessor"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user