Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.19.2 update #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,16 +16,16 @@ apply plugin: 'com.github.johnrengelman.shadow'


group = 'net.buycraft' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'buycraftx-forge'
archivesBaseName = 'buycraftx-forge-1.19.2'

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.19.2'

runs {
client {
Expand Down Expand Up @@ -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.19.2-43.1.47'
shadow 'net.buycraft:buycraftx-plugin-shared:12.0.8'
}

version = configurations.getByName("shadow").dependencies.find().version // copy common version
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
75 changes: 44 additions & 31 deletions src/main/java/net/buycraft/plugin/forge/BuycraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,20 +18,22 @@
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.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;
Expand All @@ -51,9 +54,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;

Expand All @@ -72,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;

Expand All @@ -89,24 +92,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);
Expand All @@ -125,7 +132,7 @@ public void onServerStarting(FMLServerStartingEvent 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());

Expand Down Expand Up @@ -164,12 +171,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);
}
Expand All @@ -179,10 +186,16 @@ public void onServerStarting(FMLServerStartingEvent event) {
}
}

private LiteralArgumentBuilder<CommandSource> configureCommand(LiteralArgumentBuilder<CommandSource> command) {
private LiteralArgumentBuilder<CommandSourceStack> configureCommand(LiteralArgumentBuilder<CommandSourceStack> 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)))
Expand All @@ -197,12 +210,12 @@ private LiteralArgumentBuilder<CommandSource> configureCommand(LiteralArgumentBu

@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (event.getPlayer().getServer() != null && event.getPlayer().getServer().isDedicatedServer()) {
if (event.getEntity().getServer() != null && event.getEntity().getServer().isDedicatedServer()) {
if (apiClient == null) {
return;
}

QueuedPlayer qp = duePlayerFetcher.fetchAndRemoveDuePlayer(event.getPlayer().getName().getString());
QueuedPlayer qp = duePlayerFetcher.fetchAndRemoveDuePlayer(event.getEntity().getName().getString());
if (qp != null) {
playerJoinCheckTask.queue(qp);
}
Expand Down Expand Up @@ -308,9 +321,9 @@ public CommandExecutor getCommandExecutor() {
return commandExecutor;
}

// public BuycraftI18n getI18n() {
// return i18n;
// }
public BuycraftI18n getI18n() {
return i18n;
}

public PostCompletedCommandsTask getCompletedCommandsTask() {
return completedCommandsTask;
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/net/buycraft/plugin/forge/ForgeBuycraftPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
});
}
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public boolean isAsync() {
return async;
}

public long getDelay() {
return delay;
}

public long getDelay() {return delay;}

public long getInterval() {
return interval;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/net/buycraft/plugin/forge/command/BuyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.Component;

public class BuyCommand implements Command<CommandSource> {
public class BuyCommand implements Command<CommandSourceStack> {

private BuycraftPlugin plugin;

Expand All @@ -18,24 +18,24 @@ public BuyCommand(BuycraftPlugin plugin) {
}

@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
if(plugin.getServerInformation() == null) {
ForgeMessageUtil.sendMessage(context.getSource(), new TextComponentString(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 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(), 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 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(), Component.literal(plugin.getServerInformation().getAccount().getDomain()).withStyle().withStyle(style -> {
return style.withColor(ChatFormatting.BLUE)
.withUnderlined(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(), Component.literal(" ").withStyle(ChatFormatting.STRIKETHROUGH));
return 1;
}
}
Loading