From ded60b4b1b5fb45523598b47b27c360815610100 Mon Sep 17 00:00:00 2001 From: MrNavaStar <43613843+MrNavaStar@users.noreply.github.com> Date: Tue, 15 Jun 2021 00:55:37 -0600 Subject: [PATCH] updated to 1.17 --- LICENSE | 12 ++++---- build.gradle | 25 ++++++++--------- gradle.properties | 8 +++--- gradle/wrapper/gradle-wrapper.properties | 6 +--- settings.gradle | 1 - .../java/com/mrnavastar/invsync/Invsync.java | 14 ---------- .../invsync/conversion/ConversionHelpers.java | 16 +++++------ .../conversion/PlayerDataConversion.java | 28 +++++++++---------- src/main/resources/fabric.mod.json | 6 +--- 9 files changed, 46 insertions(+), 70 deletions(-) diff --git a/LICENSE b/LICENSE index d5b6a63..91ef586 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2021 ethans0061 +Copyright (c) 2021 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/build.gradle b/build.gradle index 9ab0e27..9f05f23 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.7-SNAPSHOT' + id 'fabric-loom' version '0.8.1' id 'maven-publish' } @@ -16,41 +16,40 @@ repositories { } dependencies { + //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - //For formatting JSON - compile 'com.github.javadev:underscore:1.64' + implementation 'com.github.javadev:underscore:1.64' include 'com.github.javadev:underscore:1.64' //SQL implementation 'org.xerial:sqlite-jdbc:3.34.0' include 'org.xerial:sqlite-jdbc:3.34.0' - - //Addon Mods - modImplementation 'com.github.Gegy:player-roles:b0b68135723f0c3bfb26489d06b9c956f4595de3' } processResources { inputs.property "version", project.version - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" + filesMatching("fabric.mod.json") { expand "version": project.version } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" - } } +// ensure that the encoding is set to UTF-8, no matter what the system default is +// this fixes some edge cases with special characters not displaying correctly +// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html tasks.withType(JavaCompile) { options.encoding = "UTF-8" } +// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task +// if it is present. +// If you remove this task, sources will not be generated. task sourcesJar(type: Jar, dependsOn: classes) { classifier = "sources" from sourceSets.main.allSource @@ -79,4 +78,4 @@ publishing { // uncomment to publish to the local maven // mavenLocal() } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index df1003e..2c23c95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.16.5 -yarn_mappings=1.16.5+build.5 +minecraft_version=1.17 +yarn_mappings=1.17+build.7 loader_version=0.11.3 # Mod Properties -mod_version=1.1.1 +mod_version=1.2 maven_group=mrnavastar archives_base_name=invsync # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.25.1+build.416-1.16 +fabric_version=0.34.9+1.17 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bb8b2fc..a25bbaa 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip diff --git a/settings.gradle b/settings.gradle index 734ab73..5b60df3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,7 +4,6 @@ pluginManagement { maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' - } gradlePluginPortal() } diff --git a/src/main/java/com/mrnavastar/invsync/Invsync.java b/src/main/java/com/mrnavastar/invsync/Invsync.java index 703aca3..3490890 100644 --- a/src/main/java/com/mrnavastar/invsync/Invsync.java +++ b/src/main/java/com/mrnavastar/invsync/Invsync.java @@ -2,11 +2,8 @@ import com.mrnavastar.invsync.setup.ConfigManager; import com.mrnavastar.invsync.setup.PlayerDataSetup; -import com.mrnavastar.invsync.setup.PlayerRolesSetup; import com.mrnavastar.invsync.sql.SQLHandler; import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -14,7 +11,6 @@ public class Invsync implements ModInitializer { public static final String MODID = "invsync"; - public static final String databaseName = ConfigManager.Database_Name; @Override public void onInitialize() { @@ -30,16 +26,6 @@ public void onInitialize() { SQLHandler.disconnect(); PlayerDataSetup.start(); - - //Enable syncing for supported mods when present - for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { - if (modContainer.getMetadata().getId().equals("player_roles") && ConfigManager.Sync_Player_Roles) { - log(Level.INFO, "Player Roles found! Enabling support"); - PlayerRolesSetup.start(); - } else { - SQLHandler.dropTable(ConfigManager.Player_Roles_Table_Name); - } - } } } diff --git a/src/main/java/com/mrnavastar/invsync/conversion/ConversionHelpers.java b/src/main/java/com/mrnavastar/invsync/conversion/ConversionHelpers.java index 2e117c3..f1617b4 100644 --- a/src/main/java/com/mrnavastar/invsync/conversion/ConversionHelpers.java +++ b/src/main/java/com/mrnavastar/invsync/conversion/ConversionHelpers.java @@ -4,30 +4,30 @@ import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.player.HungerManager; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.StringNbtReader; public class ConversionHelpers { public static String itemStackToString(ItemStack item) { - String itemData = item.toTag(new CompoundTag()).toString(); + String itemData = item.writeNbt(new NbtCompound()).toString(); return itemData.replace("'", "$"); } public static String foodLevelToString(HungerManager hungerManager) { - CompoundTag tag = new CompoundTag(); - hungerManager.toTag(tag); + NbtCompound tag = new NbtCompound(); + hungerManager.writeNbt(tag); return tag.toString(); } public static String effectsToString(StatusEffectInstance effectInstance) { - CompoundTag tag = new CompoundTag(); - effectInstance.toTag(tag); + NbtCompound tag = new NbtCompound(); + effectInstance.writeNbt(tag); return tag.toString(); } - public static CompoundTag stringToTag(String nbt) { - CompoundTag tag = null; + public static NbtCompound stringToTag(String nbt) { + NbtCompound tag = null; try { tag = StringNbtReader.parse(nbt.replace("$", "'")); } catch (CommandSyntaxException e) { diff --git a/src/main/java/com/mrnavastar/invsync/conversion/PlayerDataConversion.java b/src/main/java/com/mrnavastar/invsync/conversion/PlayerDataConversion.java index 17f4679..99487b5 100644 --- a/src/main/java/com/mrnavastar/invsync/conversion/PlayerDataConversion.java +++ b/src/main/java/com/mrnavastar/invsync/conversion/PlayerDataConversion.java @@ -18,15 +18,15 @@ public static void nbtToSql(PlayerEntity player) { if (ConfigManager.Sync_Inv) { for (int i = 0; i < 36; i++) { - playerDataTable.set(uuid, "inv" + i, ConversionHelpers.itemStackToString(player.inventory.main.get(i))); + playerDataTable.set(uuid, "inv" + i, ConversionHelpers.itemStackToString(player.getInventory().main.get(i))); } - playerDataTable.set(uuid, "offHand", ConversionHelpers.itemStackToString(player.inventory.offHand.get(0))); - playerDataTable.set(uuid, "selectedSlot", player.inventory.selectedSlot); + playerDataTable.set(uuid, "offHand", ConversionHelpers.itemStackToString(player.getInventory().offHand.get(0))); + playerDataTable.set(uuid, "selectedSlot", player.getInventory().selectedSlot); } if (ConfigManager.Sync_Armour) { for (int i = 0; i < 4; i++) { - playerDataTable.set(uuid, "armour" + i, ConversionHelpers.itemStackToString(player.inventory.armor.get(i))); + playerDataTable.set(uuid, "armour" + i, ConversionHelpers.itemStackToString(player.getInventory().armor.get(i))); } } @@ -70,25 +70,25 @@ public static void sqlToNbt(PlayerEntity player) { if (ConfigManager.Sync_Inv) { for (int i = 0; i < 36; i++) { - player.inventory.main.set(i, ItemStack.fromTag(ConversionHelpers.stringToTag(playerDataTable - .get(uuid, "inv" + i, ConversionHelpers.itemStackToString(player.inventory.main.get(i)))))); + player.getInventory().main.set(i, ItemStack.fromNbt(ConversionHelpers.stringToTag(playerDataTable + .get(uuid, "inv" + i, ConversionHelpers.itemStackToString(player.getInventory().main.get(i)))))); } - player.inventory.offHand.set(0, ItemStack.fromTag(ConversionHelpers.stringToTag(playerDataTable - .get(uuid, "offHand", ConversionHelpers.itemStackToString(player.inventory.offHand.get(0)))))); + player.getInventory().offHand.set(0, ItemStack.fromNbt(ConversionHelpers.stringToTag(playerDataTable + .get(uuid, "offHand", ConversionHelpers.itemStackToString(player.getInventory().offHand.get(0)))))); - player.inventory.selectedSlot = playerDataTable.get(uuid, "selectedSlot", player.inventory.selectedSlot); + player.getInventory().selectedSlot = playerDataTable.get(uuid, "selectedSlot", player.getInventory().selectedSlot); } if (ConfigManager.Sync_Armour) { for (int i = 0; i < 4; i++) { - player.inventory.armor.set(i, ItemStack.fromTag(ConversionHelpers.stringToTag(playerDataTable - .get(uuid, "armour" + i, ConversionHelpers.itemStackToString(player.inventory.armor.get(i)))))); + player.getInventory().armor.set(i, ItemStack.fromNbt(ConversionHelpers.stringToTag(playerDataTable + .get(uuid, "armour" + i, ConversionHelpers.itemStackToString(player.getInventory().armor.get(i)))))); } } if (ConfigManager.Sync_eChest) { for (int i = 0; i < 27; i++) { - player.getEnderChestInventory().setStack(i, ItemStack.fromTag(ConversionHelpers.stringToTag(playerDataTable + player.getEnderChestInventory().setStack(i, ItemStack.fromNbt(ConversionHelpers.stringToTag(playerDataTable .get(uuid, "eChest" + i, ConversionHelpers.itemStackToString(player.getEnderChestInventory().getStack(i)))))); } } @@ -107,7 +107,7 @@ public static void sqlToNbt(PlayerEntity player) { } if (ConfigManager.Sync_Food_Level) { - player.getHungerManager().fromTag(ConversionHelpers.stringToTag(playerDataTable + player.getHungerManager().readNbt(ConversionHelpers.stringToTag(playerDataTable .get(uuid, "foodLevel", ConversionHelpers.foodLevelToString(player.getHungerManager())))); } @@ -117,7 +117,7 @@ public static void sqlToNbt(PlayerEntity player) { if (!str.equals("[]")) { String[] strArr = str.replace("[", "").replace("]", "").split(", "); for (String s : strArr) { - player.addStatusEffect(StatusEffectInstance.fromTag(ConversionHelpers.stringToTag(s))); + player.addStatusEffect(StatusEffectInstance.fromNbt(ConversionHelpers.stringToTag(s))); } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b4bd771..02deed0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,11 +21,7 @@ "depends": { "fabricloader": ">=0.10.5", "minecraft": [ - "1.16.5", - "1.16.4", - "1.16.3", - "1.16.2", - "1.16.1" + "1.17" ] } }