From ba9f0653d86af59f7c864c74e8711cbdc43c1bea Mon Sep 17 00:00:00 2001 From: Waterpicker Date: Wed, 16 Mar 2022 21:22:04 -0500 Subject: [PATCH 1/3] Commited Codebase necromancy and updated 1.18.1 --- build.gradle | 16 ++--- gradle/wrapper/gradle-wrapper.properties | 3 +- .../buycraft/plugin/forge/BuycraftPlugin.java | 60 +++++++++++-------- .../plugin/forge/ForgeBuycraftPlatform.java | 28 ++++----- .../plugin/forge/command/BuyCommand.java | 32 +++++----- .../plugin/forge/command/CouponCmd.java | 22 +++---- .../plugin/forge/command/ForceCheckCmd.java | 14 ++--- .../forge/command/ForgeMessageUtil.java | 11 ++-- .../plugin/forge/command/InfoCmd.java | 42 ++++++------- .../plugin/forge/command/ReportCmd.java | 20 +++---- .../plugin/forge/command/SecretCmd.java | 21 +++---- .../plugin/forge/util/VersionCheck.java | 12 ++-- 12 files changed, 145 insertions(+), 136 deletions(-) diff --git a/build.gradle b/build.gradle index b373aa0..d8918f1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ buildscript { repositories { - maven { url = 'https://files.minecraftforge.net/maven' } - jcenter() + maven { url = 'https://maven.minecraftforge.net' } mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true - classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4' + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true + classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2" } } apply plugin: 'net.minecraftforge.gradle' @@ -18,14 +18,14 @@ apply plugin: 'com.github.johnrengelman.shadow' group = 'net.buycraft' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'buycraftx-forge' -sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. +java.toolchain.languageVersion = JavaLanguageVersion.of(17) repositories { mavenLocal() } minecraft { - mappings channel: 'snapshot', version: '20180921-1.13' + mappings channel: 'official', version: '1.18.1' runs { client { @@ -63,8 +63,8 @@ minecraft { } dependencies { - minecraft 'net.minecraftforge:forge:1.13.2-25.0.175' - shadow 'net.buycraft:buycraftx-plugin-shared:12.0.1' + minecraft 'net.minecraftforge:forge:1.18.1-39.1.2' + shadow 'net.buycraft:buycraftx-plugin-shared:12.0.8' } version = configurations.getByName("shadow").dependencies.find().version // copy common version diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c3682a6..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Apr 18 19:34:51 AEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip diff --git a/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java b/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java index 68c72f4..b0dd41e 100644 --- a/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java +++ b/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.buycraft.plugin.BuyCraftAPI; import net.buycraft.plugin.IBuycraftPlatform; import net.buycraft.plugin.data.QueuedPlayer; @@ -19,18 +20,19 @@ import net.buycraft.plugin.shared.config.BuycraftConfiguration; import net.buycraft.plugin.shared.tasks.PlayerJoinCheckTask; import net.buycraft.plugin.shared.util.AnalyticsSend; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Style; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.gameevent.PlayerEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import okhttp3.OkHttpClient; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -51,9 +53,9 @@ public class BuycraftPlugin { private static final Logger LOGGER = LogManager.getLogger("Tebex"); - public static final Style SUCCESS_STYLE = new Style().setColor(TextFormatting.GREEN); - public static final Style INFO_STYLE = new Style().setColor(TextFormatting.YELLOW); - public static final Style ERROR_STYLE = new Style().setColor(TextFormatting.RED); + public static final Style SUCCESS_STYLE = Style.EMPTY.withColor(ChatFormatting.GREEN); + public static final Style INFO_STYLE = Style.EMPTY.withColor(ChatFormatting.YELLOW); + public static final Style ERROR_STYLE = Style.EMPTY.withColor(ChatFormatting.RED); private final String pluginVersion; @@ -89,24 +91,28 @@ public boolean test(RunnableScheduledFuture runnableScheduledFuture) { } } + @SubscribeEvent + public void onCommandRegister(RegisterCommandsEvent event) { + //region Commands + event.getDispatcher().register(this.configureCommand(Commands.literal("tebex"))); + event.getDispatcher().register(this.configureCommand(Commands.literal("buycraft"))); + + if (!configuration.isDisableBuyCommand()) + configuration.getBuyCommandName().forEach(cmd -> + event.getDispatcher().register(Commands.literal(cmd).executes(new BuyCommand(this)))); + //endregion + + } + // As as close to an onEnable as we are ever going to get :( @SubscribeEvent - public void onServerStarting(FMLServerStartingEvent event) { + public void onServerStarting(ServerStartingEvent event) { if (event.getServer().isDedicatedServer()) { server = event.getServer(); executor = Executors.newScheduledThreadPool(2, r -> new Thread(r, "Buycraft Scheduler Thread")); platform = new ForgeBuycraftPlatform(this); - //region Commands - event.getCommandDispatcher().register(this.configureCommand(Commands.literal("tebex"))); - event.getCommandDispatcher().register(this.configureCommand(Commands.literal("buycraft"))); - - if (!configuration.isDisableBuyCommand()) - configuration.getBuyCommandName().forEach(cmd -> - event.getCommandDispatcher().register(Commands.literal(cmd).executes(new BuyCommand(this)))); - //endregion - try { try { Files.createDirectory(baseDirectory); @@ -164,12 +170,12 @@ public void onServerStarting(FMLServerStartingEvent event) { scheduledTasks.add(ForgeScheduledTask.Builder.create().withInterval(20).withDelay(20).withTask(playerJoinCheckTask).build()); if (serverInformation != null) { - scheduledTasks.add(ForgeScheduledTask.Builder.create() + scheduledTasks.add(ForgeScheduledTask.Builder.create()/*server.isServerInOnlineMode()*/ .withAsync(true) .withInterval(20 * 60 * 60 * 24) .withTask(() -> { try { - AnalyticsSend.postServerInformation(httpClient, configuration.getServerKey(), platform, server.isServerInOnlineMode()); + AnalyticsSend.postServerInformation(httpClient, configuration.getServerKey(), platform, server.usesAuthentication()); } catch (IOException e) { getLogger().warn("Can't send analytics", e); } @@ -179,10 +185,16 @@ public void onServerStarting(FMLServerStartingEvent event) { } } - private LiteralArgumentBuilder configureCommand(LiteralArgumentBuilder command) { + private LiteralArgumentBuilder configureCommand(LiteralArgumentBuilder command) { CouponCmd couponCmd = new CouponCmd(this); return command - .requires(player -> player.hasPermissionLevel(2)) + .requires(player -> { + try { + return player.getPlayerOrException().hasPermissions(2); + } catch (CommandSyntaxException e) { + return false; + } + }) .then(Commands.literal("coupon") .then(Commands.literal("create") .then(Commands.argument("data", StringArgumentType.greedyString()).executes(couponCmd::create))) diff --git a/src/main/java/net/buycraft/plugin/forge/ForgeBuycraftPlatform.java b/src/main/java/net/buycraft/plugin/forge/ForgeBuycraftPlatform.java index 74df6ea..4dcd3d8 100644 --- a/src/main/java/net/buycraft/plugin/forge/ForgeBuycraftPlatform.java +++ b/src/main/java/net/buycraft/plugin/forge/ForgeBuycraftPlatform.java @@ -10,9 +10,9 @@ import net.buycraft.plugin.execution.strategy.CommandExecutor; import net.buycraft.plugin.platform.PlatformInformation; import net.buycraft.plugin.platform.PlatformType; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.versions.forge.ForgeVersion; import java.util.HashMap; @@ -51,11 +51,11 @@ public PlaceholderManager getPlaceholderManager() { @Override public void dispatchCommand(String command) { - plugin.getServer().addScheduledTask(() -> { //Ensure main + plugin.getServer().execute(() -> { //Ensure main try { - plugin.getServer().getCommandManager().getDispatcher().execute(command, plugin.getServer().getCommandSource()); + plugin.getServer().getCommands().getDispatcher().execute(command, plugin.getServer().createCommandSourceStack()); } catch (CommandSyntaxException e) { - log(Level.SEVERE, "Failed to dispatch command \'" + command + "\'", e); + log(Level.SEVERE, "Failed to dispatch command '" + command + "'", e); } }); } @@ -72,20 +72,20 @@ public void executeAsyncLater(Runnable runnable, long l, TimeUnit timeUnit) { @Override public void executeBlocking(Runnable runnable) { - plugin.getServer().addScheduledTask(runnable); + plugin.getServer().executeBlocking(runnable); } @Override public void executeBlockingLater(Runnable runnable, long l, TimeUnit timeUnit) { - plugin.getExecutor().schedule(() -> plugin.getServer().addScheduledTask(runnable), l, timeUnit); + plugin.getExecutor().schedule(() -> plugin.getServer().execute(runnable), l, timeUnit); } - private EntityPlayerMP getPlayer(QueuedPlayer player) { - if (player.getUuid() != null && plugin.getServer().isServerInOnlineMode()) { + private ServerPlayer getPlayer(QueuedPlayer player) { + if (player.getUuid() != null/* && plugin.getServer().isServerInOnlineMode()*/) { UUID uuid = UuidUtil.mojangUuidToJavaUuid(player.getUuid()); return plugin.getServer().getPlayerList().getPlayers() .stream() - .filter(entityPlayerMP -> entityPlayerMP.getUniqueID().equals(uuid)) + .filter(entityPlayerMP -> entityPlayerMP.getUUID().equals(uuid)) .findFirst().orElse(null); } else { return plugin.getServer().getPlayerList().getPlayers() @@ -102,8 +102,8 @@ public boolean isPlayerOnline(QueuedPlayer queuedPlayer) { @Override public int getFreeSlots(QueuedPlayer queuedPlayer) { - InventoryPlayer inventory = getPlayer(queuedPlayer).inventory; - return (int) (inventory.mainInventory.size() - inventory.mainInventory.stream().filter(stack -> stack == ItemStack.EMPTY).count()); + Inventory inventory = getPlayer(queuedPlayer).getInventory(); + return (int) (inventory.items.size() - inventory.items.stream().filter(stack -> stack == ItemStack.EMPTY).count()); } @Override @@ -123,7 +123,7 @@ public CommandExecutor getExecutor() { @Override public PlatformInformation getPlatformInformation() { - return new PlatformInformation(PlatformType.FORGE, plugin.getServer().getMinecraftVersion() + "-" + ForgeVersion.getVersion()); + return new PlatformInformation(PlatformType.FORGE, plugin.getServer().getServerVersion() + "-" + ForgeVersion.getVersion()); } @Override diff --git a/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java b/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java index 1715dba..0139b38 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java +++ b/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java @@ -4,12 +4,12 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.buycraft.plugin.forge.BuycraftPlugin; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.TextComponent; -public class BuyCommand implements Command { +public class BuyCommand implements Command { private BuycraftPlugin plugin; @@ -18,24 +18,24 @@ public BuyCommand(BuycraftPlugin plugin) { } @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { if(plugin.getServerInformation() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("information_no_server")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("information_no_server")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(" ").applyTextStyles(TextFormatting.STRIKETHROUGH)); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("To view the webstore, click this link: ")).applyTextStyle(style -> { - style.setColor(TextFormatting.GREEN); - style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, plugin.getServerInformation().getAccount().getDomain())); + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(" ").withStyle(ChatFormatting.STRIKETHROUGH)); + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("To view the webstore, click this link: ")).withStyle(style -> { + return style.withColor(ChatFormatting.GREEN) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, plugin.getServerInformation().getAccount().getDomain())); })); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(plugin.getServerInformation().getAccount().getDomain()).applyTextStyle(style -> { - style.setColor(TextFormatting.BLUE); - style.setUnderlined(true); - style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, plugin.getServerInformation().getAccount().getDomain())); + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(plugin.getServerInformation().getAccount().getDomain()).withStyle().withStyle(style -> { + return style.withColor(ChatFormatting.BLUE) + .setUnderlined(true) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, plugin.getServerInformation().getAccount().getDomain())); })); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(" ").applyTextStyles(TextFormatting.STRIKETHROUGH)); + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(" ").withStyle(ChatFormatting.STRIKETHROUGH)); return 1; } } diff --git a/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java b/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java index 0a2d0d0..53e62ea 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java @@ -5,8 +5,8 @@ import net.buycraft.plugin.data.Coupon; import net.buycraft.plugin.forge.BuycraftPlugin; import net.buycraft.plugin.shared.util.CouponUtil; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.TextComponent; import java.io.IOException; @@ -17,9 +17,9 @@ public CouponCmd(final BuycraftPlugin plugin) { this.plugin = plugin; } - public int create(CommandContext context) { + public int create(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -28,7 +28,7 @@ public int create(CommandContext context) { try { coupon = CouponUtil.parseArguments(StringArgumentType.getString(context, "data").split(" ")); } catch (Exception e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("coupon_creation_arg_parse_failure", e.getMessage())) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("coupon_creation_arg_parse_failure", e.getMessage())) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -36,10 +36,10 @@ public int create(CommandContext context) { plugin.getPlatform().executeAsync(() -> { try { plugin.getApiClient().createCoupon(coupon).execute(); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("coupon_creation_success", coupon.getCode())) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("coupon_creation_success", coupon.getCode())) .setStyle(BuycraftPlugin.SUCCESS_STYLE)); } catch (IOException e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); } }); @@ -47,9 +47,9 @@ public int create(CommandContext context) { return 1; } - public int delete(CommandContext context) { + public int delete(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -58,9 +58,9 @@ public int delete(CommandContext context) { plugin.getPlatform().executeAsync(() -> { try { plugin.getApiClient().deleteCoupon(code).execute(); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("coupon_deleted")).setStyle(BuycraftPlugin.SUCCESS_STYLE)); + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("coupon_deleted")).setStyle(BuycraftPlugin.SUCCESS_STYLE)); } catch (Exception e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(e.getMessage()).setStyle(BuycraftPlugin.ERROR_STYLE)); + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(e.getMessage()).setStyle(BuycraftPlugin.ERROR_STYLE)); } }); diff --git a/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java b/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java index eaccce4..9ec8636 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java @@ -3,10 +3,10 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; import net.buycraft.plugin.forge.BuycraftPlugin; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.TextComponent; -public class ForceCheckCmd implements Command { +public class ForceCheckCmd implements Command { private final BuycraftPlugin plugin; public ForceCheckCmd(final BuycraftPlugin plugin) { @@ -14,21 +14,21 @@ public ForceCheckCmd(final BuycraftPlugin plugin) { } @Override - public int run(CommandContext context) { + public int run(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("need_secret_key")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("need_secret_key")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } if (plugin.getDuePlayerFetcher().inProgress()) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("already_checking_for_purchases")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("already_checking_for_purchases")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } plugin.getExecutor().submit(() -> plugin.getDuePlayerFetcher().run(false)); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("forcecheck_queued")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("forcecheck_queued")) .setStyle(BuycraftPlugin.SUCCESS_STYLE)); return 1; } diff --git a/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java b/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java index b98df2f..724fe0c 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java @@ -1,8 +1,9 @@ package net.buycraft.plugin.forge.command; import com.google.common.collect.ImmutableMap; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.Util; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import java.text.MessageFormat; import java.util.Map; @@ -66,9 +67,9 @@ public final class ForgeMessageUtil { .build(); //Look idk, forge methods are still kinda busted in how they work, so a util it is \o/ - public static void sendMessage(CommandSource source, ITextComponent message) { - if (source.getEntity() != null) source.getEntity().sendMessage(message); - else if (source.getServer() != null) source.getServer().sendMessage(message); + public static void sendMessage(CommandSourceStack source, Component message) { + if (source.getEntity() != null) source.getEntity().sendMessage(message, Util.NIL_UUID); + else source.getServer().sendMessage(message, Util.NIL_UUID); } public static String format(String message, Object... params) { diff --git a/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java b/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java index 97c7580..84b6529 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java @@ -3,16 +3,16 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; import net.buycraft.plugin.forge.BuycraftPlugin; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.event.ClickEvent; -import net.minecraft.util.text.event.HoverEvent; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.TextComponent; import java.util.stream.Stream; -public class InfoCmd implements Command { +public class InfoCmd implements Command { private final BuycraftPlugin plugin; public InfoCmd(final BuycraftPlugin plugin) { @@ -20,36 +20,36 @@ public InfoCmd(final BuycraftPlugin plugin) { } @Override - public int run(CommandContext context) { + public int run(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } if (plugin.getServerInformation() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("information_no_server")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("information_no_server")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } String webstoreURL = plugin.getServerInformation().getAccount().getDomain(); - ITextComponent webstore = new TextComponentString(webstoreURL) - .applyTextStyle(style -> { - style.setColor(TextFormatting.GREEN); - style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, webstoreURL)); - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(webstoreURL))); + Component webstore = new TextComponent(webstoreURL) + .withStyle(style -> { + return style.withColor(ChatFormatting.GREEN) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, webstoreURL)) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(webstoreURL))); }); - ITextComponent server = new TextComponentString(plugin.getServerInformation().getServer().getName()).applyTextStyle(TextFormatting.GREEN); + Component server = new TextComponent(plugin.getServerInformation().getServer().getName()).withStyle(ChatFormatting.GREEN); Stream.of( - new TextComponentString(ForgeMessageUtil.format("information_title") + " ").applyTextStyle(TextFormatting.GRAY), - new TextComponentString(ForgeMessageUtil.format("information_sponge_server") + " ").applyTextStyle(TextFormatting.GRAY).appendSibling(server), - new TextComponentString(ForgeMessageUtil.format("information_currency", plugin.getServerInformation().getAccount().getCurrency().getIso4217())) - .applyTextStyle(TextFormatting.GRAY), - new TextComponentString(ForgeMessageUtil.format("information_domain", "")).applyTextStyle(TextFormatting.GRAY).appendSibling(webstore) + new TextComponent(ForgeMessageUtil.format("information_title") + " ").withStyle(ChatFormatting.GRAY), + new TextComponent(ForgeMessageUtil.format("information_sponge_server") + " ").withStyle(ChatFormatting.GRAY).append(server), + new TextComponent(ForgeMessageUtil.format("information_currency", plugin.getServerInformation().getAccount().getCurrency().getIso4217())) + .withStyle(ChatFormatting.GRAY), + new TextComponent(ForgeMessageUtil.format("information_domain", "")).withStyle(ChatFormatting.GRAY).append(webstore) ).forEach(message -> ForgeMessageUtil.sendMessage(context.getSource(), message)); return 1; diff --git a/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java b/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java index 90c7435..f2da4eb 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java @@ -5,8 +5,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.buycraft.plugin.forge.BuycraftPlugin; import net.buycraft.plugin.shared.util.ReportBuilder; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.TextComponent; import java.io.BufferedWriter; import java.io.IOException; @@ -17,7 +17,7 @@ import java.text.SimpleDateFormat; import java.util.Date; -public class ReportCmd implements Command { +public class ReportCmd implements Command { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); private final BuycraftPlugin plugin; @@ -27,12 +27,12 @@ public ReportCmd(final BuycraftPlugin plugin) { } @Override - public int run(CommandContext context) throws CommandSyntaxException { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("report_wait")) + public int run(CommandContext context) throws CommandSyntaxException { + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("report_wait")) .setStyle(BuycraftPlugin.SUCCESS_STYLE)); plugin.getPlatform().executeAsync(() -> { - String serverIP = plugin.getServer().getServerHostname().trim().isEmpty() ? "0.0.0.0" : plugin.getServer().getServerHostname().trim(); + String serverIP = plugin.getServer().getLocalIp().trim().isEmpty() ? "0.0.0.0" : plugin.getServer().getLocalIp().trim(); ReportBuilder builder = ReportBuilder.builder() .client(plugin.getHttpClient()) @@ -40,8 +40,8 @@ public int run(CommandContext context) throws CommandSyntaxExcept .platform(plugin.getPlatform()) .duePlayerFetcher(plugin.getDuePlayerFetcher()) .ip(serverIP) - .port(plugin.getServer().getServerPort()) - .serverOnlineMode(plugin.getServer().isServerInOnlineMode()) + .port(plugin.getServer().getPort()) + .serverOnlineMode(plugin.getServer().usesAuthentication()) .build(); String filename = "report-" + DATE_FORMAT.format(new Date()) + ".txt"; @@ -50,10 +50,10 @@ public int run(CommandContext context) throws CommandSyntaxExcept try (BufferedWriter w = Files.newBufferedWriter(p, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW)) { w.write(generated); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("report_saved", p.toAbsolutePath().toString())) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("report_saved", p.toAbsolutePath().toString())) .setStyle(BuycraftPlugin.INFO_STYLE)); } catch (IOException e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("report_cant_save")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("report_cant_save")) .setStyle(BuycraftPlugin.ERROR_STYLE)); plugin.getLogger().info(generated); } diff --git a/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java b/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java index 3be9cc0..680936f 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java @@ -7,12 +7,12 @@ import net.buycraft.plugin.BuyCraftAPI; import net.buycraft.plugin.data.responses.ServerInformation; import net.buycraft.plugin.forge.BuycraftPlugin; -import net.minecraft.command.CommandSource; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.TextComponent; import java.io.IOException; -public class SecretCmd implements Command { +public class SecretCmd implements Command { private final BuycraftPlugin plugin; public SecretCmd(final BuycraftPlugin plugin) { @@ -20,9 +20,9 @@ public SecretCmd(final BuycraftPlugin plugin) { } @Override - public int run(CommandContext context) throws CommandSyntaxException { + public int run(CommandContext context) throws CommandSyntaxException { if (context.getSource().getEntity() != null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("secret_console_only")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_console_only")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -36,7 +36,7 @@ public int run(CommandContext context) throws CommandSyntaxExcept plugin.updateInformation(client); } catch (IOException e) { plugin.getLogger().error("Unable to verify secret", e); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("secret_does_not_work")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_does_not_work")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return; } @@ -48,17 +48,14 @@ public int run(CommandContext context) throws CommandSyntaxExcept try { plugin.saveConfiguration(); } catch (IOException e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("secret_cant_be_saved")) + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_cant_be_saved")) .setStyle(BuycraftPlugin.ERROR_STYLE)); } - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(ForgeMessageUtil.format("secret_success", + ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_success", information.getServer().getName(), information.getAccount().getName())).setStyle(BuycraftPlugin.SUCCESS_STYLE)); - boolean repeatChecks = false; - if (currentKey.equals("INVALID")) { - repeatChecks = true; - } + boolean repeatChecks = currentKey.equals("INVALID"); plugin.getDuePlayerFetcher().run(repeatChecks); }); diff --git a/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java b/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java index 6a78cd7..555cf0d 100644 --- a/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java +++ b/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java @@ -4,10 +4,10 @@ import net.buycraft.plugin.forge.BuycraftPlugin; import net.buycraft.plugin.forge.command.ForgeMessageUtil; import net.buycraft.plugin.shared.util.VersionUtil; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.Util; +import net.minecraft.network.chat.TextComponent; +import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.PlayerEvent; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -49,10 +49,10 @@ public void verify() throws IOException { @SubscribeEvent public void onPostLogin(final PlayerEvent.PlayerLoggedInEvent event) { - if (event.getPlayer().hasPermissionLevel(2) && !upToDate) { + if (event.getPlayer().hasPermissions(2) && !upToDate) { plugin.getPlatform().executeAsyncLater(() -> - event.getPlayer().sendMessage(new TextComponentString(ForgeMessageUtil.format("update_available", lastKnownVersion.getVersion())) - .setStyle(BuycraftPlugin.INFO_STYLE)), + event.getPlayer().sendMessage(new TextComponent(ForgeMessageUtil.format("update_available", lastKnownVersion.getVersion())) + .setStyle(BuycraftPlugin.INFO_STYLE), Util.NIL_UUID), 3, TimeUnit.SECONDS); } } From f8c674e52b923e285d58f487d8aa6ab7d72cfb23 Mon Sep 17 00:00:00 2001 From: SkyNetCloud Date: Wed, 8 Jun 2022 17:16:50 -0400 Subject: [PATCH 2/3] Update 1.19 --- build.gradle | 4 ++-- .../plugin/forge/command/BuyCommand.java | 14 +++++++------- .../plugin/forge/command/CouponCmd.java | 17 +++++++++-------- .../plugin/forge/command/ForceCheckCmd.java | 7 ++++--- .../plugin/forge/command/ReportCmd.java | 8 ++++---- .../plugin/forge/command/SecretCmd.java | 10 +++++----- .../plugin/forge/util/VersionCheck.java | 7 +++---- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index d8918f1..045880f 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ repositories { } minecraft { - mappings channel: 'official', version: '1.18.1' + mappings channel: 'official', version: '1.19' runs { client { @@ -63,7 +63,7 @@ minecraft { } dependencies { - minecraft 'net.minecraftforge:forge:1.18.1-39.1.2' + minecraft 'net.minecraftforge:forge:1.19-41.0.1' shadow 'net.buycraft:buycraftx-plugin-shared:12.0.8' } diff --git a/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java b/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java index 0139b38..ca7e3ef 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java +++ b/src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java @@ -7,7 +7,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.ClickEvent; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; public class BuyCommand implements Command { @@ -20,22 +20,22 @@ public BuyCommand(BuycraftPlugin plugin) { @Override public int run(CommandContext context) throws CommandSyntaxException { if(plugin.getServerInformation() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("information_no_server")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("information_no_server")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(" ").withStyle(ChatFormatting.STRIKETHROUGH)); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("To view the webstore, click this link: ")).withStyle(style -> { + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(" ").withStyle(ChatFormatting.STRIKETHROUGH)); + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("To view the webstore, click this link: ")).withStyle(style -> { return style.withColor(ChatFormatting.GREEN) .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, plugin.getServerInformation().getAccount().getDomain())); })); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(plugin.getServerInformation().getAccount().getDomain()).withStyle().withStyle(style -> { + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(plugin.getServerInformation().getAccount().getDomain()).withStyle().withStyle(style -> { return style.withColor(ChatFormatting.BLUE) - .setUnderlined(true) + .withUnderlined(true) .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, plugin.getServerInformation().getAccount().getDomain())); })); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(" ").withStyle(ChatFormatting.STRIKETHROUGH)); + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(" ").withStyle(ChatFormatting.STRIKETHROUGH)); return 1; } } diff --git a/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java b/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java index 53e62ea..f0601d3 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/CouponCmd.java @@ -6,7 +6,8 @@ import net.buycraft.plugin.forge.BuycraftPlugin; import net.buycraft.plugin.shared.util.CouponUtil; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; + import java.io.IOException; @@ -19,7 +20,7 @@ public CouponCmd(final BuycraftPlugin plugin) { public int create(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -28,7 +29,7 @@ public int create(CommandContext context) { try { coupon = CouponUtil.parseArguments(StringArgumentType.getString(context, "data").split(" ")); } catch (Exception e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("coupon_creation_arg_parse_failure", e.getMessage())) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("coupon_creation_arg_parse_failure", e.getMessage())) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -36,10 +37,10 @@ public int create(CommandContext context) { plugin.getPlatform().executeAsync(() -> { try { plugin.getApiClient().createCoupon(coupon).execute(); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("coupon_creation_success", coupon.getCode())) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("coupon_creation_success", coupon.getCode())) .setStyle(BuycraftPlugin.SUCCESS_STYLE)); } catch (IOException e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); } }); @@ -49,7 +50,7 @@ public int create(CommandContext context) { public int delete(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -58,9 +59,9 @@ public int delete(CommandContext context) { plugin.getPlatform().executeAsync(() -> { try { plugin.getApiClient().deleteCoupon(code).execute(); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("coupon_deleted")).setStyle(BuycraftPlugin.SUCCESS_STYLE)); + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("coupon_deleted")).setStyle(BuycraftPlugin.SUCCESS_STYLE)); } catch (Exception e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(e.getMessage()).setStyle(BuycraftPlugin.ERROR_STYLE)); + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(e.getMessage()).setStyle(BuycraftPlugin.ERROR_STYLE)); } }); diff --git a/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java b/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java index 9ec8636..6401af2 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.context.CommandContext; import net.buycraft.plugin.forge.BuycraftPlugin; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; public class ForceCheckCmd implements Command { @@ -16,19 +17,19 @@ public ForceCheckCmd(final BuycraftPlugin plugin) { @Override public int run(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("need_secret_key")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("need_secret_key")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } if (plugin.getDuePlayerFetcher().inProgress()) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("already_checking_for_purchases")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("already_checking_for_purchases")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } plugin.getExecutor().submit(() -> plugin.getDuePlayerFetcher().run(false)); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("forcecheck_queued")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("forcecheck_queued")) .setStyle(BuycraftPlugin.SUCCESS_STYLE)); return 1; } diff --git a/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java b/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java index f2da4eb..69db34f 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ReportCmd.java @@ -6,7 +6,7 @@ import net.buycraft.plugin.forge.BuycraftPlugin; import net.buycraft.plugin.shared.util.ReportBuilder; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; import java.io.BufferedWriter; import java.io.IOException; @@ -28,7 +28,7 @@ public ReportCmd(final BuycraftPlugin plugin) { @Override public int run(CommandContext context) throws CommandSyntaxException { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("report_wait")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("report_wait")) .setStyle(BuycraftPlugin.SUCCESS_STYLE)); plugin.getPlatform().executeAsync(() -> { @@ -50,10 +50,10 @@ public int run(CommandContext context) throws CommandSyntaxE try (BufferedWriter w = Files.newBufferedWriter(p, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW)) { w.write(generated); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("report_saved", p.toAbsolutePath().toString())) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("report_saved", p.toAbsolutePath().toString())) .setStyle(BuycraftPlugin.INFO_STYLE)); } catch (IOException e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("report_cant_save")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("report_cant_save")) .setStyle(BuycraftPlugin.ERROR_STYLE)); plugin.getLogger().info(generated); } diff --git a/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java b/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java index 680936f..934a814 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java @@ -8,7 +8,7 @@ import net.buycraft.plugin.data.responses.ServerInformation; import net.buycraft.plugin.forge.BuycraftPlugin; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; import java.io.IOException; @@ -22,7 +22,7 @@ public SecretCmd(final BuycraftPlugin plugin) { @Override public int run(CommandContext context) throws CommandSyntaxException { if (context.getSource().getEntity() != null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_console_only")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("secret_console_only")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 0; } @@ -36,7 +36,7 @@ public int run(CommandContext context) throws CommandSyntaxE plugin.updateInformation(client); } catch (IOException e) { plugin.getLogger().error("Unable to verify secret", e); - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_does_not_work")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("secret_does_not_work")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return; } @@ -48,11 +48,11 @@ public int run(CommandContext context) throws CommandSyntaxE try { plugin.saveConfiguration(); } catch (IOException e) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_cant_be_saved")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("secret_cant_be_saved")) .setStyle(BuycraftPlugin.ERROR_STYLE)); } - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("secret_success", + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("secret_success", information.getServer().getName(), information.getAccount().getName())).setStyle(BuycraftPlugin.SUCCESS_STYLE)); boolean repeatChecks = currentKey.equals("INVALID"); diff --git a/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java b/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java index 555cf0d..9ef9aeb 100644 --- a/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java +++ b/src/main/java/net/buycraft/plugin/forge/util/VersionCheck.java @@ -4,8 +4,7 @@ import net.buycraft.plugin.forge.BuycraftPlugin; import net.buycraft.plugin.forge.command.ForgeMessageUtil; import net.buycraft.plugin.shared.util.VersionUtil; -import net.minecraft.Util; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -51,8 +50,8 @@ public void verify() throws IOException { public void onPostLogin(final PlayerEvent.PlayerLoggedInEvent event) { if (event.getPlayer().hasPermissions(2) && !upToDate) { plugin.getPlatform().executeAsyncLater(() -> - event.getPlayer().sendMessage(new TextComponent(ForgeMessageUtil.format("update_available", lastKnownVersion.getVersion())) - .setStyle(BuycraftPlugin.INFO_STYLE), Util.NIL_UUID), + event.getPlayer().sendSystemMessage(Component.literal(ForgeMessageUtil.format("update_available", lastKnownVersion.getVersion())) + .setStyle(BuycraftPlugin.INFO_STYLE)), 3, TimeUnit.SECONDS); } } From 525702bc27f9f28fc1ae0e367db7723035dfeaec Mon Sep 17 00:00:00 2001 From: SkyNetCloud Date: Wed, 8 Jun 2022 20:05:05 -0400 Subject: [PATCH 3/3] Fix all code now all of it work with 1.19 --- build.gradle | 2 ++ .../buycraft/plugin/forge/BuycraftPlugin.java | 11 ++++++----- .../plugin/forge/ForgeScheduledTask.java | 5 ++--- .../plugin/forge/command/ForceCheckCmd.java | 1 - .../forge/command/ForgeMessageUtil.java | 4 ++-- .../plugin/forge/command/InfoCmd.java | 19 +++++++++---------- .../plugin/forge/command/SecretCmd.java | 1 + src/main/resources/META-INF/mods.toml | 3 ++- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index 045880f..f6ada36 100644 --- a/build.gradle +++ b/build.gradle @@ -75,6 +75,8 @@ shadowJar { relocate 'okio', 'net.buycraft.plugin.internal.okio' relocate 'retrofit2', 'net.buycraft.plugin.internal.retrofit2' relocate 'com.fasterxml.jackson', 'net.buycraft.plugin.internal.jackson' + //TODO remove Com.google from being complied with the code + relocate 'com.google', 'net.buycraft.plugin.internal.google' classifier '' // Replace the default JAR } diff --git a/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java b/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java index b0dd41e..4c60ed5 100644 --- a/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java +++ b/src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java @@ -18,6 +18,7 @@ import net.buycraft.plugin.forge.util.VersionCheck; import net.buycraft.plugin.shared.Setup; import net.buycraft.plugin.shared.config.BuycraftConfiguration; +import net.buycraft.plugin.shared.config.BuycraftI18n; import net.buycraft.plugin.shared.tasks.PlayerJoinCheckTask; import net.buycraft.plugin.shared.util.AnalyticsSend; import net.minecraft.ChatFormatting; @@ -74,7 +75,7 @@ public class BuycraftPlugin { private OkHttpClient httpClient; private IBuycraftPlatform platform; private CommandExecutor commandExecutor; -// private BuycraftI18n i18n; //TODO Re-enable when forge fixes resource loading + private BuycraftI18n i18n; private PostCompletedCommandsTask completedCommandsTask; private PlayerJoinCheckTask playerJoinCheckTask; @@ -131,7 +132,7 @@ public void onServerStarting(ServerStartingEvent event) { return; } -// i18n = configuration.createI18n(); //TODO Re-enable when forge fixes resource loading + i18n = configuration.createI18n(); getLogger().warn("Forcing english translations while we wait on a forge bugfix!"); httpClient = Setup.okhttp(baseDirectory.resolve("cache").toFile()); @@ -320,9 +321,9 @@ public CommandExecutor getCommandExecutor() { return commandExecutor; } -// public BuycraftI18n getI18n() { -// return i18n; -// } + public BuycraftI18n getI18n() { + return i18n; + } public PostCompletedCommandsTask getCompletedCommandsTask() { return completedCommandsTask; diff --git a/src/main/java/net/buycraft/plugin/forge/ForgeScheduledTask.java b/src/main/java/net/buycraft/plugin/forge/ForgeScheduledTask.java index d133e59..2f1eeaa 100644 --- a/src/main/java/net/buycraft/plugin/forge/ForgeScheduledTask.java +++ b/src/main/java/net/buycraft/plugin/forge/ForgeScheduledTask.java @@ -19,9 +19,8 @@ public boolean isAsync() { return async; } - public long getDelay() { - return delay; - } + + public long getDelay() {return delay;} public long getInterval() { return interval; diff --git a/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java b/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java index 6401af2..90792c9 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ForceCheckCmd.java @@ -5,7 +5,6 @@ import net.buycraft.plugin.forge.BuycraftPlugin; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; public class ForceCheckCmd implements Command { private final BuycraftPlugin plugin; diff --git a/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java b/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java index 724fe0c..2a0bc63 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java +++ b/src/main/java/net/buycraft/plugin/forge/command/ForgeMessageUtil.java @@ -68,8 +68,8 @@ public final class ForgeMessageUtil { //Look idk, forge methods are still kinda busted in how they work, so a util it is \o/ public static void sendMessage(CommandSourceStack source, Component message) { - if (source.getEntity() != null) source.getEntity().sendMessage(message, Util.NIL_UUID); - else source.getServer().sendMessage(message, Util.NIL_UUID); + if (source.getEntity() != null) source.getEntity().sendSystemMessage(message); + else source.getServer().sendSystemMessage(message); } public static String format(String message, Object... params) { diff --git a/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java b/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java index 84b6529..b40b4b8 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/InfoCmd.java @@ -8,7 +8,6 @@ import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; -import net.minecraft.network.chat.TextComponent; import java.util.stream.Stream; @@ -22,34 +21,34 @@ public InfoCmd(final BuycraftPlugin plugin) { @Override public int run(CommandContext context) { if (plugin.getApiClient() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("generic_api_operation_error")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("generic_api_operation_error")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } if (plugin.getServerInformation() == null) { - ForgeMessageUtil.sendMessage(context.getSource(), new TextComponent(ForgeMessageUtil.format("information_no_server")) + ForgeMessageUtil.sendMessage(context.getSource(), Component.literal(ForgeMessageUtil.format("information_no_server")) .setStyle(BuycraftPlugin.ERROR_STYLE)); return 1; } String webstoreURL = plugin.getServerInformation().getAccount().getDomain(); - Component webstore = new TextComponent(webstoreURL) + Component webstore = Component.literal(webstoreURL) .withStyle(style -> { return style.withColor(ChatFormatting.GREEN) .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, webstoreURL)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(webstoreURL))); + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(webstoreURL))); }); - Component server = new TextComponent(plugin.getServerInformation().getServer().getName()).withStyle(ChatFormatting.GREEN); + Component server = Component.literal(plugin.getServerInformation().getServer().getName()).withStyle(ChatFormatting.GREEN); Stream.of( - new TextComponent(ForgeMessageUtil.format("information_title") + " ").withStyle(ChatFormatting.GRAY), - new TextComponent(ForgeMessageUtil.format("information_sponge_server") + " ").withStyle(ChatFormatting.GRAY).append(server), - new TextComponent(ForgeMessageUtil.format("information_currency", plugin.getServerInformation().getAccount().getCurrency().getIso4217())) + Component.literal(ForgeMessageUtil.format("information_title") + " ").withStyle(ChatFormatting.GRAY), + Component.literal(ForgeMessageUtil.format("information_sponge_server") + " ").withStyle(ChatFormatting.GRAY).append(server), + Component.literal(ForgeMessageUtil.format("information_currency", plugin.getServerInformation().getAccount().getCurrency().getIso4217())) .withStyle(ChatFormatting.GRAY), - new TextComponent(ForgeMessageUtil.format("information_domain", "")).withStyle(ChatFormatting.GRAY).append(webstore) + Component.literal(ForgeMessageUtil.format("information_domain", "")).withStyle(ChatFormatting.GRAY).append(webstore) ).forEach(message -> ForgeMessageUtil.sendMessage(context.getSource(), message)); return 1; diff --git a/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java b/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java index 934a814..f9cc782 100644 --- a/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java +++ b/src/main/java/net/buycraft/plugin/forge/command/SecretCmd.java @@ -10,6 +10,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; + import java.io.IOException; public class SecretCmd implements Command { diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 5238d27..37f57ba 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,6 @@ modLoader="javafml" #mandatory -loaderVersion="[25,)" #mandatory (24 is current forge version) +loaderVersion="[41,)" #mandatory (24 is current forge version) +license="All Rights Reserved By Tebex" [[mods]] modId="buycraftx"