Skip to content

Commit

Permalink
Almost there (VPS issues are a PITA)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jun 26, 2022
1 parent 539248d commit 6a538e4
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 80 deletions.
2 changes: 1 addition & 1 deletion MAINTAINANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ this properly.
* Get the latest copy of Spigot via BuildTools.jar
* Replace the plugins with the section available in `replacement.xml`
* Build Spigot with the `remapped` profile
* Change dependencies in project's poms
* Change dependencies in Chimera projects' poms
* Test project locally using `typist-example-plugin`

## Repository
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

| Chimera Version | Minecraft Version |
|-----------------|-------------------|
| 5.4.0 | 1.19.0 |
| 5.3.0 | 1.18.2 |
| 5.2.0 | 1.18.0 - 1.18.1 |
| 5.1.0 | 1.17.1 |
Expand Down
2 changes: 1 addition & 1 deletion annotations/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>chimera</artifactId>
<groupId>com.karuslabs</groupId>
<version>5.3.0</version>
<version>5.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>annotations</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.karuslabs</groupId>
<artifactId>chimera</artifactId>
<version>5.3.0</version>
<version>5.4.0</version>
</parent>

<artifactId>annotations</artifactId>
Expand Down
12 changes: 6 additions & 6 deletions commons/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>chimera</artifactId>
<groupId>com.karuslabs</groupId>
<version>5.3.0</version>
<version>5.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>commons</artifactId>
Expand All @@ -30,9 +30,9 @@
<goal>remap</goal>
</goals>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<srgIn>org.spigotmc:minecraft-server:1.19-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedDependencies>org.spigotmc:spigot:1.19-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
Expand All @@ -45,8 +45,8 @@
</goals>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
<srgIn>org.spigotmc:minecraft-server:1.19-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.19-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
Expand Down
12 changes: 6 additions & 6 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.karuslabs</groupId>
<artifactId>chimera</artifactId>
<version>5.3.0</version>
<version>5.4.0</version>
</parent>

<artifactId>commons</artifactId>
Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
Expand Down Expand Up @@ -59,9 +59,9 @@
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<srgIn>org.spigotmc:minecraft-server:1.19-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedDependencies>org.spigotmc:spigot:1.19-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
Expand All @@ -74,8 +74,8 @@
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
<srgIn>org.spigotmc:minecraft-server:1.19-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.19-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import net.minecraft.commands.*;
import net.minecraft.server.MinecraftServer;

import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.command.CraftCommandMap;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.command.CraftCommandMap;

import org.bukkit.Server;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@

import org.apache.logging.log4j.*;

import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.command.*;
import org.bukkit.craftbukkit.v1_18_R2.entity.*;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.command.*;
import org.bukkit.craftbukkit.v1_19_R1.entity.*;

import org.bukkit.command.*;

// Note: The source comments refer to Mojang mapped names, not Spigot mapped names.

/**
* Utility methods that handle exceptions which occur when parsing and executing commands.
* <br><br>
Expand All @@ -68,7 +70,7 @@ static void report(CommandSender sender, CommandSyntaxException exception) {
if (input != null && exception.getCursor() >= 0) {
var index = Math.min(input.length(), exception.getCursor());

var text = new TextComponent("").withStyle(ChatFormatting.GRAY).withStyle(style ->
var text = Component.empty().withStyle(ChatFormatting.GRAY).withStyle(style ->
style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, input))
);

Expand All @@ -79,11 +81,11 @@ static void report(CommandSender sender, CommandSyntaxException exception) {
text.append(input.substring(Math.max(0, index - 20), index));

if (index < input.length()) {
var error = new TextComponent(input.substring(index)).withStyle(new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.UNDERLINE});
var error = Component.literal(input.substring(index)).withStyle(new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.UNDERLINE});
text.append(error);
}

var context = new TranslatableComponent("command.context.here").withStyle(new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.ITALIC});
var context = Component.translatable("command.context.here").withStyle(new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.ITALIC});
text.append(context);

stack.sendFailure(text);
Expand All @@ -96,7 +98,7 @@ static void report(CommandSender sender, String command, Exception exception) {
var stack = from(sender);

var message = exception.getMessage();
var details = new TextComponent(message == null ? exception.getClass().getName() : message);
var details = Component.literal(message == null ? exception.getClass().getName() : message);

if (LOGGER.isDebugEnabled()) {
LOGGER.error("Command exception: {}", command, exception);
Expand All @@ -108,12 +110,12 @@ static void report(CommandSender sender, String command, Exception exception) {
}
}

stack.sendFailure((new TranslatableComponent("command.failed")).withStyle(style ->
stack.sendFailure((Component.translatable("command.failed")).withStyle(style ->
style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, details))
));

if (SharedConstants.IS_RUNNING_IN_IDE) {
stack.sendFailure(new TextComponent(Util.describeError(exception)));
stack.sendFailure(Component.literal(Util.describeError(exception)));
LOGGER.error("'{}' threw an exception", command, exception);
}
}
Expand All @@ -125,12 +127,17 @@ static void report(CommandSender sender, String command, Exception exception) {
// We wrote it slightly to check agaisnt NMS types rather than Spigot types to make it safer.
static CommandSourceStack from(CommandSender sender) {
if (sender instanceof CraftPlayer player) {
// We can't mock/test this path as of Spigot 1.19. This is because player.getHandle()
// returns ServerPlayer which ancestor does WAY too much work in it's
// constructor and tries to initialize some registry. This registry
// throws an IllegalArgumentException since it was not properly bootstrapped.
return player.getHandle().createCommandSourceStack();

} else if (sender instanceof CraftBlockCommandSender block) {
return block.getWrapper();

} else if (sender instanceof CraftMinecartCommand minecart) {
// Same with CraftMinecartCommand
return ((MinecartCommandBlock) minecart.getHandle()).getCommandBlock().createCommandSourceStack();

} else if (sender instanceof RemoteConsoleCommandSender) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.bukkit.command.*;
import org.bukkit.plugin.Plugin;

import org.bukkit.craftbukkit.v1_18_R2.command.CraftCommandMap;
import org.bukkit.craftbukkit.v1_19_R1.command.CraftCommandMap;

import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down
15 changes: 15 additions & 0 deletions commons/src/test/java/com/karuslabs/commons/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,20 @@ public PlayerProfile createPlayerProfile(String name) {
public int getSpawnLimit(SpawnCategory spawnCategory) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean shouldSendChatPreviews() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean isEnforcingSecureProfiles() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public int getMaxChainedNeighborUpdates() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
import java.util.List;

import net.minecraft.commands.*;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.chat.Component;

import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R1.command.CraftBlockCommandSender;

import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
Expand All @@ -49,8 +48,7 @@
class DispatcherCommandTest {

CommandSourceStack stack = mock(CommandSourceStack.class);
ServerPlayer player = when(mock(ServerPlayer.class).createCommandSourceStack()).thenReturn(stack).getMock();
CommandSender sender = when(mock(CraftPlayer.class).getHandle()).thenReturn(player).getMock();
CommandSender sender = when(mock(CraftBlockCommandSender.class).getWrapper()).thenReturn(stack).getMock();

Plugin plugin = mock(Plugin.class);
CommandDispatcher<CommandSender> dispatcher = mock(CommandDispatcher.class);
Expand Down Expand Up @@ -84,7 +82,7 @@ void execute() throws CommandSyntaxException {
@Test
void execute_CommandRuntimeException() throws CommandSyntaxException {
doReturn(true).when(command).testPermission(sender);
doThrow(new CommandRuntimeException(new TextComponent("message"))).when(dispatcher).execute(any(StringReader.class), any(CommandSender.class));
doThrow(new CommandRuntimeException(Component.literal("message"))).when(dispatcher).execute(any(StringReader.class), any(CommandSender.class));

assertTrue(command.execute(sender, "command", "a", "b"));
verify(stack, times(1)).sendFailure(any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.*;

import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.command.CraftCommandMap;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftScheduler;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.command.CraftCommandMap;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftScheduler;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.event.server.ServerLoadEvent.LoadType;
import org.junit.jupiter.api.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@
import net.minecraft.commands.*;
import net.minecraft.network.chat.*;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.*;
import net.minecraft.world.entity.vehicle.MinecartCommandBlock;
import net.minecraft.world.level.BaseCommandBlock;

import org.bukkit.command.*;

import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.command.*;
import org.bukkit.craftbukkit.v1_18_R2.entity.*;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.command.*;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -53,29 +49,28 @@ class ExceptionsTest {
static final CommandSourceStack LISTENER = mock(CommandSourceStack.class);

CommandSourceStack stack = mock(CommandSourceStack.class);
ServerPlayer player = when(mock(ServerPlayer.class).createCommandSourceStack()).thenReturn(stack).getMock();
CommandSender sender = when(mock(CraftPlayer.class).getHandle()).thenReturn(player).getMock();
CommandSender sender = when(mock(CraftBlockCommandSender.class).getWrapper()).thenReturn(stack).getMock();

@Test
void report_command_runtime_exception() {
Exceptions.report(sender, new CommandRuntimeException(new TextComponent("message")));
Exceptions.report(sender, new CommandRuntimeException(Component.literal("message")));

verify(stack, times(1)).sendFailure(any(TextComponent.class));
verify(stack, times(1)).sendFailure(any(Component.class));
}


@Test
void report_command_syntax_exception() {
Exceptions.report(sender, new CommandSyntaxException(null, new LiteralMessage("test"), "abc", 1));

verify(stack, times(2)).sendFailure(any(TextComponent.class));
verify(stack, times(2)).sendFailure(any(Component.class));
}


@Test
void report_exception() {
Exceptions.report(sender, "/command", new IllegalArgumentException());
verify(stack).sendFailure(any(TranslatableComponent.class));
verify(stack).sendFailure(any(Component.class));
}


Expand All @@ -86,17 +81,11 @@ void from(CommandSender sender) {
}

static Stream<CommandSender> senders() {
ServerPlayer player = when(mock(ServerPlayer.class).createCommandSourceStack()).thenReturn(LISTENER).getMock();
BaseCommandBlock commandblock = when(mock(BaseCommandBlock.class).createCommandSourceStack()).thenReturn(LISTENER).getMock();
MinecartCommandBlock minecart = when(mock(MinecartCommandBlock.class).getCommandBlock()).thenReturn(commandblock).getMock();

DedicatedServer server = when(mock(DedicatedServer.class).createCommandSourceStack()).thenReturn(LISTENER).getMock();
CraftServer craftserver = when(mock(CraftServer.class).getServer()).thenReturn(server).getMock();

return Stream.of(
when(mock(CraftPlayer.class).getHandle()).thenReturn(player).getMock(),
when(mock(CraftBlockCommandSender.class).getWrapper()).thenReturn(LISTENER).getMock(),
when(mock(CraftMinecartCommand.class).getHandle()).thenReturn(minecart).getMock(),
when(mock(ConsoleCommandSender.class).getServer()).thenReturn(craftserver).getMock(),
when(mock(ProxiedNativeCommandSender.class).getHandle()).thenReturn(LISTENER).getMock()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

import org.bukkit.craftbukkit.v1_18_R2.command.CraftCommandMap;
import org.bukkit.craftbukkit.v1_19_R1.command.CraftCommandMap;

import org.junit.jupiter.api.*;

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.karuslabs</groupId>
<artifactId>chimera</artifactId>
<version>5.3.0</version>
<version>5.4.0</version>
<packaging>pom</packaging>

<name>Chimera</name>
Expand Down
Loading

0 comments on commit 6a538e4

Please sign in to comment.