init 1.18
This commit is contained in:
parent
5ef817a9b7
commit
e7836a37a4
|
|
@ -13,7 +13,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
|||
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
|
||||
minecraft {
|
||||
|
||||
mappings channel: 'official', version: '1.19.2'
|
||||
mappings channel: 'official', version: '1.18.2'
|
||||
|
||||
//accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
minecraft 'net.minecraftforge:forge:1.19.2-43.1.1'
|
||||
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
|
||||
|
||||
jarJar("curse.maven:MySQL-561280:3685108") {
|
||||
jarJar.ranged(it, '[1.0,)')
|
||||
|
|
@ -126,8 +126,8 @@ dependencies {
|
|||
jarJar.ranged(it, '[3.4.5,)')
|
||||
}
|
||||
|
||||
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.19.2-5.1.1.0")
|
||||
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.19.2-5.1.1.0:api")
|
||||
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.2-5.0.7.1")
|
||||
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.2-5.0.7.1:api")
|
||||
implementation fg.deobf("curse.maven:MySQL-561280:3685108")
|
||||
implementation group: 'com.zaxxer', name: 'HikariCP', version: '3.4.5'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,51 @@
|
|||
package vip.fubuki.playersync.sync;
|
||||
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import vip.fubuki.playersync.util.JDBCsetUp;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class ChatSync {
|
||||
static int tick = 0;
|
||||
static long current = System.currentTimeMillis();
|
||||
|
||||
public static void register(){}
|
||||
|
||||
static PlayerList playerList;
|
||||
|
||||
public static void register(){
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerChat(net.minecraftforge.event.ServerChatEvent event) throws SQLException {
|
||||
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
|
||||
public static void Tick(net.minecraftforge.event.TickEvent.ServerTickEvent event) throws SQLException {
|
||||
tick++;
|
||||
if(tick == 20) {
|
||||
ReadMessage(event.getServer().getPlayerList());
|
||||
ReadMessage(playerList);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event){
|
||||
playerList= Objects.requireNonNull(event.getPlayer().getServer()).getPlayerList();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event){
|
||||
playerList= Objects.requireNonNull(event.getPlayer().getServer()).getPlayerList();
|
||||
}
|
||||
|
||||
public static void ReadMessage(PlayerList playerList) throws SQLException {
|
||||
ResultSet resultSet= JDBCsetUp.executeQuery("SELECT * FROM chat WHERE timestamp > " + current);
|
||||
current = System.currentTimeMillis();
|
||||
|
|
@ -36,8 +53,8 @@ public class ChatSync {
|
|||
while(resultSet.next()) {
|
||||
String player = resultSet.getString("player");
|
||||
String message = resultSet.getString("message");
|
||||
Component textComponents = Component.literal(player+": "+message);
|
||||
playerList.broadcastSystemMessage(textComponents, true);
|
||||
Component textComponents = Component.nullToEmpty(player+": "+message);
|
||||
playerList.broadcastMessage(textComponents, ChatType.CHAT, UUID.nameUUIDFromBytes(player.getBytes()));
|
||||
}
|
||||
resultSet.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,15 @@ import java.sql.SQLException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"InstantiationOfUtilityClass", "AccessStaticViaInstance"})
|
||||
|
||||
public class ModsSupport {
|
||||
|
||||
public void onPlayerJoin(Player player) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
public void onPlayerJoin(Player player) throws SQLException {
|
||||
if (ModList.get().isLoaded("curios")) {
|
||||
//TODO curios support
|
||||
top.theillusivec4.curios.api.CuriosApi CuriosApi = new top.theillusivec4.curios.api.CuriosApi();
|
||||
LazyOptional<IItemHandlerModifiable> itemHandler = CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
||||
/*
|
||||
Curios Support
|
||||
*/
|
||||
LazyOptional<IItemHandlerModifiable> itemHandler = top.theillusivec4.curios.api.CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
||||
ResultSet resultSet = JDBCsetUp.executeQuery("SELECT curios_item FROM curios WHERE uuid = '"+player.getUUID()+"'");
|
||||
if(resultSet.next()) {
|
||||
String curios_data=resultSet.getString("curios_item");
|
||||
|
|
@ -46,15 +47,14 @@ public class ModsSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public void onPlayerLeave(Player player) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
public void onPlayerLeave(Player player) throws SQLException {
|
||||
if (ModList.get().isLoaded("curios")) {
|
||||
StoreCurios(player, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void StoreCurios(Player player,boolean init) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
top.theillusivec4.curios.api.CuriosApi CuriosApi = new top.theillusivec4.curios.api.CuriosApi();
|
||||
LazyOptional<IItemHandlerModifiable> itemHandler = CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
||||
public void StoreCurios(Player player,boolean init) throws SQLException {
|
||||
LazyOptional<IItemHandlerModifiable> itemHandler = top.theillusivec4.curios.api.CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
||||
Map<Integer, String> curios = new HashMap<>();
|
||||
itemHandler.ifPresent(handler -> {
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package vip.fubuki.playersync.sync;
|
|||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
|
|
@ -39,12 +39,12 @@ public class VanillaSync {
|
|||
|
||||
static ExecutorService executorService = Executors.newCachedThreadPool(new PSThreadPoolFactory("PlayerSync"));
|
||||
|
||||
public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, CommandSyntaxException, IOException {
|
||||
public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, CommandSyntaxException, IOException {
|
||||
String player_uuid = event.getEntity().getUUID().toString();
|
||||
ResultSet resultSet=JDBCsetUp.executeQuery("SELECT online, last_server FROM player_data WHERE uuid='"+player_uuid+"'");
|
||||
ServerPlayer serverPlayer = (ServerPlayer) event.getEntity();
|
||||
if(!resultSet.next()){
|
||||
Store(event.getEntity(),true,Dist.CLIENT.isDedicatedServer());
|
||||
Store(event.getPlayer(),true,Dist.CLIENT.isDedicatedServer());
|
||||
return;
|
||||
}
|
||||
boolean online = resultSet.getBoolean("online");
|
||||
|
|
@ -58,7 +58,7 @@ public class VanillaSync {
|
|||
boolean enable = getServerInfo.getBoolean("enable");
|
||||
if(enable && System.currentTimeMillis() < last_update + 300000.0){
|
||||
event.getEntity().removeTag("player_synced");
|
||||
serverPlayer.connection.disconnect(Component.translatable("playersync.already_online"));
|
||||
serverPlayer.connection.disconnect(new TranslatableComponent("playersync.already_online"));
|
||||
return;
|
||||
}
|
||||
JDBCsetUp.executeUpdate("UPDATE server_info SET enable=false WHERE id=" + lastServer);
|
||||
|
|
@ -154,13 +154,13 @@ public class VanillaSync {
|
|||
return ItemStack.of(compoundTag);
|
||||
}
|
||||
|
||||
public static void doPlayerSaveToFile(PlayerEvent.SaveToFile event) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
public static void doPlayerSaveToFile(PlayerEvent.SaveToFile event) throws SQLException, IOException {
|
||||
JDBCsetUp.executeUpdate("UPDATE server_info SET last_update=" + System.currentTimeMillis() + " WHERE id=" + JdbcConfig.SERVER_ID.get());
|
||||
if(!event.getEntity().getTags().contains("player_synced")) return;
|
||||
Store(event.getEntity(),false,Dist.CLIENT.isDedicatedServer());
|
||||
Store(event.getPlayer(),false,Dist.CLIENT.isDedicatedServer());
|
||||
//Mod support
|
||||
ModsSupport modsSupport = new ModsSupport();
|
||||
modsSupport.onPlayerLeave(event.getEntity());
|
||||
modsSupport.onPlayerLeave(event.getPlayer());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
@ -179,14 +179,14 @@ public class VanillaSync {
|
|||
JDBCsetUp.executeUpdate("UPDATE server_info SET enable=false WHERE id=" + JdbcConfig.SERVER_ID.get());
|
||||
}
|
||||
|
||||
public static void doPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
|
||||
public static void doPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) throws SQLException, IOException {
|
||||
if(!event.getEntity().getTags().contains("player_synced")) return;
|
||||
String player_uuid = event.getEntity().getUUID().toString();
|
||||
JDBCsetUp.executeUpdate("UPDATE player_data SET online=false WHERE uuid='"+player_uuid+"'");
|
||||
Store(event.getEntity(),false,Dist.CLIENT.isDedicatedServer());
|
||||
Store(event.getPlayer(),false,Dist.CLIENT.isDedicatedServer());
|
||||
//Mod support
|
||||
ModsSupport modsSupport = new ModsSupport();
|
||||
modsSupport.onPlayerLeave(event.getEntity());
|
||||
modsSupport.onPlayerLeave(event.getPlayer());
|
||||
event.getEntity().removeTag("player_synced");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user