Skip to content

Commit

Permalink
Initial support for Minecraft 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannyboy11 committed Jun 13, 2024
1 parent f68c8a0 commit 46d71a6
Show file tree
Hide file tree
Showing 40 changed files with 4,793 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ jobs:
distribution: 'temurin'
java-version: '8'
cache: 'maven'
- name: Install CraftBukkit 1.8.8, 1.12.2, 1.15.2, 1.16.5
- name: Install CraftBukkit 1.8.8, 1.12.2, 1.16.5
run: |
java -jar BuildTools.jar --rev 1.8.8 --compile craftbukkit
java -jar BuildTools.jar --rev 1.12.2 --compile craftbukkit
java -jar BuildTools.jar --rev 1.15.2 --compile craftbukkit
java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit
- name: Install JDK 17
uses: actions/setup-java@v3
Expand All @@ -33,20 +32,21 @@ jobs:
java -jar BuildTools.jar --rev 1.17.1 --compile craftbukkit --remapped
java -jar BuildTools.jar --rev 1.18.2 --compile craftbukkit --remapped
java -jar BuildTools.jar --rev 1.19.4 --compile craftbukkit --remapped
java -jar BuildTools.jar --rev 1.20.1 --compile craftbukkit --remapped
java -jar BuildTools.jar --rev 1.20.4 --compile craftbukkit --remapped
- name: Install JDK 21
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '21'
cache: 'maven'
- name: Install CraftBukkit 1.20.5, 1.20.6
- name: Install CraftBukkit 1.20.6, 1.21
# Use build number 4133 to compile CraftBukkit 1.20.5, see:
# https://hub.spigotmc.org/jira/browse/BUILDTOOLS-658
# https://hub.spigotmc.org/versions/
run: |
java -jar BuildTools.jar --rev 4133 --compile craftbukkit --remapped
java -jar BuildTools.jar --rev 1.20.6 --compile craftbukkit --remapped
java -jar BuildTools.jar --rev 1.21 --compile craftbukkit --remapped
- name: Compile InvSee++
run: mvn clean package install --batch-mode --update-snapshots
- name: Create tagged release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private CraftbukkitMappingsVersion() {
static final String _1_20_4 = "60a2bb6bf2684dc61c56b90d7c41bddc";
static final String _1_20_5 = "ad1a88fd7eaf2277f2507bf34d7b994c";
static final String _1_20_6 = "ee13f98a43b9c5abffdcc0bb24154460";
static final String _1_21 = "229d7afc75b70a6c388337687ac4da1f";

/**
* Get the version of the mappings used by CraftBukkit. Note that this method only works on (forks of) CraftBukkit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum MinecraftVersion {
_1_17, _1_17_1,
_1_18, _1_18_1, _1_18_2,
_1_19, _1_19_1, _1_19_2, _1_19_3, _1_19_4,
_1_20, _1_20_1, _1_20_2, _1_20_3, _1_20_4, _1_20_5, _1_20_6;
_1_20, _1_20_1, _1_20_2, _1_20_3, _1_20_4, _1_20_5, _1_20_6,
_1_21;

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ServerSoftware {
CRAFTBUKKIT_1_19_4 = new ServerSoftware(CRAFTBUKKIT, _1_19_4),
CRAFTBUKKIT_1_20_4 = new ServerSoftware(CRAFTBUKKIT, _1_20_4),
CRAFTBUKKIT_1_20_6 = new ServerSoftware(CRAFTBUKKIT, _1_20_6),
CRAFTBUKKIT_1_21 = new ServerSoftware(CRAFTBUKKIT, _1_21),
GLOWSTONE_1_8_8 = new ServerSoftware(GLOWSTONE, _1_8_8),
GLOWSTONE_1_8_9 = new ServerSoftware(GLOWSTONE, _1_8_9),
GLOWSTONE_1_12_2 = new ServerSoftware(GLOWSTONE, _1_12_2);
Expand Down Expand Up @@ -95,16 +96,21 @@ public static ServerSoftware detect(final Server server) {
case CraftbukkitMappingsVersion._1_20_5: return new ServerSoftware(CRAFTBUKKIT, _1_20_5);
case CraftbukkitMappingsVersion._1_20_6: return CRAFTBUKKIT_1_20_6;
}

case "org.bukkit.craftbukkit.v1_21_R1.CraftServer":
switch (CraftbukkitMappingsVersion.getMappingsVersion(server)) {
case CraftbukkitMappingsVersion._1_21: return CRAFTBUKKIT_1_21;
}
case "org.bukkit.craftbukkit.CraftServer":
// CraftBukkit 1.20.6 and up or Paper 1.20.4 and up:
try {
// Call Server#getMinecraftVersion() to find out the version (this method was added by Paper).
return new ServerSoftware(PAPER, MinecraftVersion.fromString(server.getMinecraftVersion()));
} catch (NoSuchMethodError nsme) {
// Apparently we are not running on Paper (thanks CraftBukkit...)
//TODO does this code-path ackshually trigger on re-obfuscated craftbukkit?
switch (CraftbukkitMappingsVersion.getMappingsVersion(server)) {
case CraftbukkitMappingsVersion._1_20_6: return CRAFTBUKKIT_1_20_6;
case CraftbukkitMappingsVersion._1_21: return CRAFTBUKKIT_1_21;
}
}

Expand Down
99 changes: 99 additions & 0 deletions InvSee++_Give_Platforms/Give_Impl_1_21_R1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<relativePath>../../pom.xml</relativePath>
<groupId>com.janboerman.invsee</groupId>
<artifactId>invsee-plus-plus</artifactId>
<version>0.27.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>give_impl_1_21_r1</artifactId>
<name>InvSee++ Give implementation for CraftBukkit 1.21</name>

<properties>
<bukkit.version>1.21-R0.1-SNAPSHOT</bukkit.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>21</release>
</configuration>
</plugin>

<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>${specialsource-maven-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:${bukkit.version}:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.bukkit:craftbukkit:${bukkit.version}:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>target/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:${bukkit.version}:csrg:maps-spigot</srgIn>
<remappedDependencies>org.bukkit:craftbukkit:${bukkit.version}:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.janboerman.invsee</groupId>
<artifactId>invsee-plus-plus_give_common</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.janboerman.invsee</groupId>
<artifactId>utils</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TheNullicorn</groupId>
<artifactId>Nedit</artifactId>
<version>49615cf47c</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>${bukkit.version}</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.janboerman.invsee.spigot.addon.give.impl_1_21_R1;

import com.janboerman.invsee.spigot.addon.give.common.Convert;
import com.janboerman.invsee.spigot.addon.give.common.GiveApi;
import com.janboerman.invsee.spigot.addon.give.common.ItemType;
import com.janboerman.invsee.utils.Either;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import org.bukkit.inventory.ItemStack;

import net.minecraft.world.Container;

public class GiveImpl implements GiveApi {

public static final GiveImpl INSTANCE = new GiveImpl();

private GiveImpl() {
}

@Override
public ItemStack applyTag(ItemStack stack, String tag) {
if (tag == null) {
return stack;
} else {
throw new IllegalArgumentException("InvSee++ for Minecraft 1.20.5 and up does not support NBT tags on item stacks.");
}
}

@Override
public Either<String, ItemType> parseItemType(String itemType) {
Either<String, ItemType> stackFromLegacySyntax = Convert.convertItemType(itemType);
if (stackFromLegacySyntax.isRight()) {
return stackFromLegacySyntax;
}

try {
return Either.right(new WithComponents(ItemParser.parseItemType(itemType)));
} catch (CommandSyntaxException e) {
return Either.left(e.getMessage());
}
}

@Override
public int maxStackSize() {
return Container.MAX_STACK;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.janboerman.invsee.spigot.addon.give.impl_1_21_R1;

import java.util.Optional;
import java.util.stream.Stream;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.arguments.item.ItemArgument;
import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.resources.ResourceKey;

final class ItemParser {

private static final CommandBuildContext COMMAND_BUILD_CONTEXT = getContext();

private ItemParser() {
}

static ItemInput parseItemType(String text) throws CommandSyntaxException {
ItemArgument argument = new ItemArgument(COMMAND_BUILD_CONTEXT);
ItemInput itemInput = argument.parse(new StringReader(text));
return itemInput;
}

private static CommandBuildContext getContext() {
HolderLookup.Provider provider = VanillaRegistries.createLookup();

return new CommandBuildContext() {
@Override
public Stream<ResourceKey<? extends Registry<?>>> listRegistries() {
return provider.listRegistries();
}

@Override
public <T> Optional<HolderLookup.RegistryLookup<T>> lookup(ResourceKey<? extends Registry<? extends T>> resourceKey) {
return provider.lookup(resourceKey);
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.janboerman.invsee.spigot.addon.give.impl_1_21_R1;

import com.janboerman.invsee.spigot.addon.give.common.ItemType;
import com.janboerman.invsee.utils.Either;

import com.mojang.brigadier.exceptions.CommandSyntaxException;

import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;

import net.minecraft.commands.arguments.item.ItemInput;

final class WithComponents implements ItemType {

private final ItemInput input;

WithComponents(ItemInput input) {
this.input = input;
}

@Override
public Either<String, ItemStack> toItemStack(int amount) {
try {
return Either.right(CraftItemStack.asCraftMirror(input.createItemStack(amount, false/*don't check stack size*/)));
} catch (CommandSyntaxException e) {
// This shouldn't really ever happen since we never check the count against the max stack size.
return Either.left(e.getMessage());
}
}
}
6 changes: 6 additions & 0 deletions InvSee++_Give_Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.janboerman.invsee</groupId>
<artifactId>give_impl_1_21_r1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.janboerman.invsee</groupId>
<artifactId>give_impl_1_20_6_r4</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SetupImpl implements Setup {
SUPPORTED.registerSupportedVersion(ServerSoftware.CRAFTBUKKIT_1_19_4, () -> new Impl_1_19_4());
SUPPORTED.registerSupportedVersion(() -> new Impl_1_20_4(), ServerSoftware.CRAFTBUKKIT_1_20_4, new ServerSoftware(MinecraftPlatform.PAPER, MinecraftVersion._1_20_4));
SUPPORTED.registerSupportedVersion(() -> new Impl_1_20_6(), ServerSoftware.CRAFTBUKKIT_1_20_6, new ServerSoftware(MinecraftPlatform.PAPER, MinecraftVersion._1_20_6));
SUPPORTED.registerSupportedVersion(() -> new Impl_1_21(), ServerSoftware.CRAFTBUKKIT_1_21, new ServerSoftware(MinecraftPlatform.PAPER, MinecraftVersion._1_21));
final SetupProvider glowstoneProver = () -> new Impl_Glowstone();
final MinecraftVersion[] minecraftVersions = MinecraftVersion.values();
for (int idx = MinecraftVersion._1_8.ordinal(); idx < MinecraftVersion._1_12_2.ordinal(); idx ++) {
Expand All @@ -59,6 +60,12 @@ public GiveApi getGiveApi() {
}
}

class Impl_1_21 extends SetupImpl {
Impl_1_21() {
super(com.janboerman.invsee.spigot.addon.give.impl_1_21_R1.GiveImpl.INSTANCE);
}
}

class Impl_1_20_6 extends SetupImpl {
Impl_1_20_6() {
super(com.janboerman.invsee.spigot.addon.give.impl_1_20_6_R4.GiveImpl.INSTANCE);
Expand Down
Loading

0 comments on commit 46d71a6

Please sign in to comment.