mirror of
https://github.com/Jikoo/OpenInv.git
synced 2026-11-04 16:50:04 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3285a6d61 | ||
|
|
806fb848a7 | ||
|
|
b269a5ed3c | ||
|
|
8c102c4400 | ||
|
|
080d02f93f | ||
|
|
54f9d30a89 | ||
|
|
6063959362 | ||
|
|
d80b8a6f4d | ||
|
|
13621901ad | ||
|
|
20cc6e004e | ||
|
|
80585dfc07 | ||
|
|
9e37b42c63 | ||
|
|
58be5cffc9 | ||
|
|
e8c8e625c0 | ||
|
|
0ee3f8c1b2 | ||
|
|
99f9099981 | ||
|
|
70ae432158 | ||
|
|
ad05f427fd | ||
|
|
252e93f872 | ||
|
|
0267090cb6 | ||
|
|
1e26c33311 | ||
|
|
34f5319f48 | ||
|
|
642e287507 | ||
|
|
4504ba2b99 | ||
|
|
9691d16506 | ||
|
|
1897790db5 | ||
|
|
cad76c6559 | ||
|
|
119ff48461 | ||
|
|
b589f79e57 | ||
|
|
f742cf5b77 | ||
|
|
19d030dd4d | ||
|
|
17dec41fea |
No files matched your search
@@ -15,7 +15,7 @@ jobs:
|
||||
# Note: this is directly from GitHub's example for using data from a triggering workflow:
|
||||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@v7
|
||||
uses: actions/github-script@v8
|
||||
with:
|
||||
script: |
|
||||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
|
||||
@@ -15,9 +15,9 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@@ -33,7 +33,7 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildtools-
|
||||
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- uses: gradle/actions/setup-gradle@v5
|
||||
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew clean build
|
||||
|
||||
@@ -13,21 +13,21 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download build
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v5
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
|
||||
- name: Create Release
|
||||
id: create-release
|
||||
uses: softprops/action-gh-release@v2.2.2
|
||||
uses: softprops/action-gh-release@v2.3.3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
name: OpenInv ${{ env.VERSIONED_NAME }}
|
||||
body: |-
|
||||
## Supported server versions
|
||||
**Paper:** TODO VERSION, 1.21.4, 1.21.3, 1.21.1
|
||||
**Paper:** TODO VERSION, 1.21.8, 1.21.7, 1.21.6, 1.21.5, 1.21.4, 1.21.3, 1.21.1
|
||||
**Spigot:** TODO VERSION
|
||||
|
||||
TODO HELLO HUMAN, PRESS THE GENERATE CHANGELOG BUTTON PLEASE.
|
||||
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Build resource pack
|
||||
id: upload-resource-pack
|
||||
|
||||
@@ -4,4 +4,5 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
compileOnly(libs.slf4j.api)
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.lishid.openinv.util;
|
||||
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.helpers.LegacyAbstractLogger;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.slf4j.helpers.NormalizedParameters;
|
||||
import org.slf4j.spi.LocationAwareLogger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* An adapter for wrapping a {@link java.util.logging.Logger} as a {@link org.slf4j.Logger}.
|
||||
* <br>Largely based on {@code JDK14LoggerAdapter}, which is not present at runtime.
|
||||
*/
|
||||
public class JulLoggerAdapter extends LegacyAbstractLogger implements LocationAwareLogger {
|
||||
|
||||
private final Logger wrapped;
|
||||
|
||||
public JulLoggerAdapter(Logger wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
this.name = wrapped.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFullyQualifiedCallerName() {
|
||||
return JulLoggerAdapter.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleNormalizedLoggingCall(
|
||||
org.slf4j.event.Level slf4jLevel,
|
||||
Marker marker,
|
||||
String msg,
|
||||
Object[] args,
|
||||
Throwable thrown
|
||||
) {
|
||||
Level level = fromSlf4jLevel(slf4jLevel);
|
||||
|
||||
if (wrapped.isLoggable(level)) {
|
||||
normalizedLog(getFullyQualifiedCallerName(), level, msg, args, thrown);
|
||||
}
|
||||
}
|
||||
|
||||
private void normalizedLog(String fqcn, Level level, String msg, Object[] args, Throwable thrown) {
|
||||
String formatted = MessageFormatter.basicArrayFormat(msg, args);
|
||||
LogRecord logRecord = new LogRecord(level, formatted);
|
||||
logRecord.setLoggerName(getName());
|
||||
logRecord.setThrown(thrown);
|
||||
|
||||
addSource(fqcn, logRecord);
|
||||
|
||||
wrapped.log(logRecord);
|
||||
}
|
||||
|
||||
private void addSource(String fqcn, LogRecord logRecord) {
|
||||
// TODO stackwalker?
|
||||
StackTraceElement[] trace = new Throwable().getStackTrace();
|
||||
int maxElements = 12;
|
||||
int lastIgnored = maxElements;
|
||||
// Start from 2; 0 is above and 1 is caller of internal method.
|
||||
for (int i = 2; i < maxElements; ++i) {
|
||||
if (isIgnored(trace[i].getClassName(), fqcn)) {
|
||||
lastIgnored = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastIgnored < maxElements - 1) {
|
||||
StackTraceElement caller = trace[lastIgnored + 1];
|
||||
logRecord.setSourceClassName(caller.getClassName());
|
||||
logRecord.setSourceMethodName(caller.getMethodName());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isIgnored(String className, String fqcn) {
|
||||
if (className.equals(fqcn)) {
|
||||
return true;
|
||||
}
|
||||
// Ignore slf4j classes - they shouldn't be the source.
|
||||
if (className.startsWith("org.slf4j.")) {
|
||||
return true;
|
||||
}
|
||||
return className.equals(getFullyQualifiedCallerName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Marker marker, String callerFqn, int levelInt, String msg, Object[] args, Throwable thrown) {
|
||||
Level level = fromSlf4jLevel(org.slf4j.event.Level.intToLevel(levelInt));
|
||||
|
||||
if (!wrapped.isLoggable(level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NormalizedParameters params = NormalizedParameters.normalize(msg, args, thrown);
|
||||
normalizedLog(callerFqn, level, params.getMessage(), params.getArguments(), params.getThrowable());
|
||||
}
|
||||
|
||||
private Level fromSlf4jLevel(org.slf4j.event.Level level) {
|
||||
return switch (level) {
|
||||
case TRACE -> Level.FINEST;
|
||||
case DEBUG -> Level.FINE;
|
||||
case INFO -> Level.INFO;
|
||||
case WARN -> Level.WARNING;
|
||||
case ERROR -> Level.SEVERE;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return wrapped.isLoggable(Level.FINEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return wrapped.isLoggable(Level.FINE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return wrapped.isLoggable(Level.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return wrapped.isLoggable(Level.WARNING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return wrapped.isLoggable(Level.SEVERE);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# Project meta
|
||||
group=com.lishid.openinv
|
||||
version=5.1.11
|
||||
version=5.1.15
|
||||
description=A Bukkit plugin for opening normally-inaccessible inventories.
|
||||
|
||||
# Gradle configuration
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
spigotapi = "1.21.5-R0.1-SNAPSHOT"
|
||||
specialsource = "1.11.5"
|
||||
planarwrappers = "3.3.0"
|
||||
annotations = "26.0.2"
|
||||
paperweight = "2.0.0-beta.16"
|
||||
shadow = "8.3.6"
|
||||
annotations = "26.0.2-1"
|
||||
paperweight = "2.0.0-beta.17"
|
||||
shadow = "9.2.2"
|
||||
folia-scheduler-wrapper = "v0.0.3"
|
||||
errorprone-core = "2.38.0"
|
||||
errorprone-core = "2.42.0"
|
||||
errorprone-gradle = "4.2.0"
|
||||
slf4j = "2.0.17"
|
||||
|
||||
[libraries]
|
||||
spigotapi = { module = "org.spigotmc:spigot-api", version.ref = "spigotapi" }
|
||||
@@ -17,6 +18,7 @@ annotations = { module = "org.jetbrains:annotations", version.ref = "annotations
|
||||
folia-scheduler-wrapper = { module = "com.github.NahuLD.folia-scheduler-wrapper:folia-scheduler-wrapper", version.ref = "folia-scheduler-wrapper" }
|
||||
errorprone-core = { module = "com.google.errorprone:error_prone_core", version.ref = "errorprone-core" }
|
||||
errorprone-gradle = { module = "net.ltgt.gradle:gradle-errorprone-plugin", version.ref = "errorprone-gradle" }
|
||||
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
|
||||
|
||||
[plugins]
|
||||
paperweight = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,5 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -80,13 +82,11 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -133,22 +133,29 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -193,11 +200,15 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
@@ -205,6 +216,12 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
||||
Vendored
+21
-16
@@ -13,8 +13,10 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@@ -25,7 +27,8 @@
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
@@ -33,7 +33,7 @@ dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
|
||||
paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle("1.21.10-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
val spigot = tasks.register<ShadowJar>("spigotRelocations") {
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.PlayerEnderChestContainer;
|
||||
@@ -92,7 +93,7 @@ public class AnySilentContainer extends AnySilentContainerBase {
|
||||
|
||||
ServerPlayer player = PlayerManager.getHandle(bukkitPlayer);
|
||||
|
||||
final net.minecraft.world.level.Level level = player.level();
|
||||
final net.minecraft.world.level.Level level = ((Entity) player).level();
|
||||
final BlockPos blockPos = new BlockPos(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
|
||||
final BlockEntity blockEntity = level.getBlockEntity(blockPos);
|
||||
|
||||
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
package com.lishid.openinv.internal.common.container;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.internal.InternalOwned;
|
||||
import com.lishid.openinv.internal.common.container.bukkit.OpenPlayerInventory;
|
||||
import com.lishid.openinv.internal.common.container.menu.OpenInventoryMenu;
|
||||
import com.lishid.openinv.internal.common.container.slot.Content;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentCrafting;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentCraftingResult;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentCursor;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentDrop;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentEquipment;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentList;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentOffHand;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentViewOnly;
|
||||
import com.lishid.openinv.internal.common.container.slot.SlotViewOnly;
|
||||
import com.lishid.openinv.internal.common.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.common.player.PlayerManager;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseOpenInventory implements Container, InternalOwned<ServerPlayer>, ISpecialPlayerInventory {
|
||||
|
||||
protected final List<Content> slots;
|
||||
private final int size;
|
||||
protected ServerPlayer owner;
|
||||
private int maxStackSize = 99;
|
||||
protected CraftInventory bukkitEntity;
|
||||
public List<HumanEntity> transaction = new ArrayList<>();
|
||||
|
||||
public BaseOpenInventory(@NotNull org.bukkit.entity.Player bukkitPlayer) {
|
||||
owner = PlayerManager.getHandle(bukkitPlayer);
|
||||
|
||||
// Get total size, rounding up to nearest 9 for client compatibility.
|
||||
int rawSize = owner.getInventory().getContainerSize() + owner.inventoryMenu.getCraftSlots().getContainerSize() + 1;
|
||||
size = ((int) Math.ceil(rawSize / 9.0)) * 9;
|
||||
|
||||
slots = NonNullList.withSize(size, new ContentViewOnly(owner));
|
||||
setupSlots();
|
||||
}
|
||||
|
||||
protected void setupSlots() {
|
||||
// Top of inventory: Regular contents.
|
||||
int nextIndex = addMainInventory();
|
||||
|
||||
// If inventory is expected size, we can arrange slots to be pretty.
|
||||
Inventory ownerInv = owner.getInventory();
|
||||
if (ownerInv.getNonEquipmentItems().size() == 36
|
||||
&& owner.inventoryMenu.getCraftSlots().getContainerSize() == 4
|
||||
&& (Inventory.EQUIPMENT_SLOT_MAPPING.size() == 5 || Inventory.EQUIPMENT_SLOT_MAPPING.size() == 7)) {
|
||||
// Armor slots: Bottom left.
|
||||
addArmor(36);
|
||||
// Off-hand: Below chestplate.
|
||||
addOffHand(46);
|
||||
// Drop slot: Bottom right.
|
||||
slots.set(53, new ContentDrop(owner));
|
||||
// Cursor slot: Above drop.
|
||||
slots.set(44, new ContentCursor(owner));
|
||||
|
||||
// Crafting is displayed in the bottom right corner.
|
||||
// As we're using the pretty view, this is a 3x2.
|
||||
addCrafting(41, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise we'll just add elements linearly.
|
||||
nextIndex = addArmor(nextIndex);
|
||||
nextIndex = addOffHand(nextIndex);
|
||||
nextIndex = addCrafting(nextIndex, false);
|
||||
slots.set(nextIndex, new ContentCursor(owner));
|
||||
// Drop slot last.
|
||||
slots.set(slots.size() - 1, new ContentDrop(owner));
|
||||
}
|
||||
|
||||
private int addMainInventory() {
|
||||
int listSize = owner.getInventory().getNonEquipmentItems().size();
|
||||
// Hotbar slots are 0-8. We want those to appear on the bottom of the inventory like a normal player inventory,
|
||||
// so everything else needs to move up a row.
|
||||
int hotbarDiff = listSize - 9;
|
||||
for (int localIndex = 0; localIndex < listSize; ++localIndex) {
|
||||
InventoryType.SlotType type;
|
||||
int invIndex;
|
||||
if (localIndex < hotbarDiff) {
|
||||
invIndex = localIndex + 9;
|
||||
type = InventoryType.SlotType.CONTAINER;
|
||||
} else {
|
||||
type = InventoryType.SlotType.QUICKBAR;
|
||||
invIndex = localIndex - hotbarDiff;
|
||||
}
|
||||
|
||||
slots.set(
|
||||
localIndex,
|
||||
new ContentList(owner, invIndex, type) {
|
||||
@Override
|
||||
public void setHolder(@NotNull ServerPlayer holder) {
|
||||
items = holder.getInventory().getNonEquipmentItems();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return listSize;
|
||||
}
|
||||
|
||||
private int addArmor(int startIndex) {
|
||||
// Armor slots go bottom to top; boots are first and helmet is last.
|
||||
// Since we have to display horizontally due to space restrictions,
|
||||
// making the left side the "top" is more user-friendly.
|
||||
EquipmentSlot[] sorted = Inventory.EQUIPMENT_SLOT_MAPPING.int2ObjectEntrySet()
|
||||
.stream()
|
||||
.sorted(Comparator.comparingInt(Int2ObjectMap.Entry::getIntKey))
|
||||
.map(Map.Entry::getValue)
|
||||
.toArray(EquipmentSlot[]::new);
|
||||
int localIndex = 0;
|
||||
for (int i = sorted.length - 1; i >= 0; --i) {
|
||||
// Skip off-hand, handled separately. Also skip non-player slots.
|
||||
if (sorted[i].getType() != EquipmentSlot.Type.HUMANOID_ARMOR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
slots.set(startIndex + localIndex, new ContentEquipment(owner, sorted[i]));
|
||||
++localIndex;
|
||||
}
|
||||
|
||||
return startIndex + localIndex;
|
||||
}
|
||||
|
||||
private int addOffHand(int startIndex) {
|
||||
// No off-hand?
|
||||
if (!Inventory.EQUIPMENT_SLOT_MAPPING.containsValue(EquipmentSlot.OFFHAND)) {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
slots.set(startIndex, new ContentOffHand(owner));
|
||||
return startIndex + 1;
|
||||
}
|
||||
|
||||
private int addCrafting(int startIndex, boolean pretty) {
|
||||
int listSize = owner.inventoryMenu.getCraftSlots().getContents().size();
|
||||
pretty &= listSize == 4;
|
||||
|
||||
for (int localIndex = 0; localIndex < listSize; ++localIndex) {
|
||||
// Pretty display is a 2x2 rather than linear.
|
||||
// If index is in top row, grid is not 2x2, or pretty is disabled, just use current index.
|
||||
// Otherwise, subtract 2 and add 9 to start in the same position on the next row.
|
||||
int modIndex = startIndex + (localIndex < 2 || !pretty ? localIndex : localIndex + 7);
|
||||
|
||||
slots.set(modIndex, new ContentCrafting(owner, localIndex));
|
||||
}
|
||||
|
||||
if (pretty) {
|
||||
slots.set(startIndex + 2, new ContentViewOnly(owner) {
|
||||
@Override
|
||||
public Slot asSlot(Container container, int slot, int x, int y) {
|
||||
return new SlotViewOnly(container, slot, x, y) {
|
||||
@Override
|
||||
public ItemStack getOrDefault() {
|
||||
return Placeholders.craftingOutput;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
slots.set(startIndex + 11, getCraftingResult(owner));
|
||||
}
|
||||
|
||||
return startIndex + listSize;
|
||||
}
|
||||
|
||||
protected Content getCraftingResult(@NotNull ServerPlayer serverPlayer) {
|
||||
return new ContentCraftingResult(serverPlayer);
|
||||
}
|
||||
|
||||
public Slot getMenuSlot(int index, int x, int y) {
|
||||
return slots.get(index).asSlot(this, index, x, y);
|
||||
}
|
||||
|
||||
public InventoryType.SlotType getSlotType(int index) {
|
||||
return slots.get(index).getSlotType();
|
||||
}
|
||||
|
||||
public abstract Component getTitle(ServerPlayer player);
|
||||
|
||||
@Override
|
||||
public ServerPlayer getOwnerHandle() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.inventory.Inventory getBukkitInventory() {
|
||||
if (bukkitEntity == null) {
|
||||
bukkitEntity = new OpenPlayerInventory(this);
|
||||
}
|
||||
return bukkitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(@NotNull org.bukkit.entity.Player player) {
|
||||
ServerPlayer newOwner = PlayerManager.getHandle(player);
|
||||
// Only transfer regular inventory - crafting and cursor slots are transient.
|
||||
newOwner.getInventory().replaceWith(owner.getInventory());
|
||||
owner = newOwner;
|
||||
// Update slots to point to new inventory.
|
||||
slots.forEach(slot -> slot.setHolder(newOwner));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !transaction.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.entity.Player getPlayer() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return slots.stream().map(Content::get).allMatch(ItemStack::isEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack getItem(int index) {
|
||||
return slots.get(index).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItem(int index, int amount) {
|
||||
return slots.get(index).removePartial(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItemNoUpdate(int index) {
|
||||
return slots.get(index).remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, @NotNull ItemStack itemStack) {
|
||||
slots.get(index).set(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int maxStackSize) {
|
||||
this.maxStackSize = maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(@NotNull Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<ItemStack> getContents() {
|
||||
NonNullList<ItemStack> contents = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < getContainerSize(); ++i) {
|
||||
contents.set(i, getItem(i));
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(@NotNull CraftHumanEntity viewer) {
|
||||
transaction.add(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(@NotNull CraftHumanEntity viewer) {
|
||||
transaction.remove(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.entity.Player getOwner() {
|
||||
return owner.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return owner.getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
owner.getInventory().clearContent();
|
||||
owner.inventoryMenu.getCraftSlots().clearContent();
|
||||
owner.inventoryMenu.slotsChanged(owner.inventoryMenu.getCraftSlots());
|
||||
owner.containerMenu.setCarried(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public @Nullable AbstractContainerMenu createMenu(Player player, int i, boolean viewOnly) {
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
return new OpenInventoryMenu(this, serverPlayer, i, viewOnly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+8
-324
@@ -1,207 +1,22 @@
|
||||
package com.lishid.openinv.internal.common.container;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.internal.InternalOwned;
|
||||
import com.lishid.openinv.internal.common.container.bukkit.OpenPlayerInventory;
|
||||
import com.lishid.openinv.internal.common.container.menu.OpenInventoryMenu;
|
||||
import com.lishid.openinv.internal.common.container.slot.Content;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentCrafting;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentCraftingResult;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentCursor;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentDrop;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentEquipment;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentList;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentOffHand;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentViewOnly;
|
||||
import com.lishid.openinv.internal.common.container.slot.SlotViewOnly;
|
||||
import com.lishid.openinv.internal.common.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.common.player.PlayerManager;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FontDescription;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
public class OpenInventory extends BaseOpenInventory {
|
||||
|
||||
public class OpenInventory implements Container, InternalOwned<ServerPlayer>, ISpecialPlayerInventory {
|
||||
|
||||
protected final List<Content> slots;
|
||||
private final int size;
|
||||
protected ServerPlayer owner;
|
||||
private int maxStackSize = 99;
|
||||
protected CraftInventory bukkitEntity;
|
||||
public List<HumanEntity> transaction = new ArrayList<>();
|
||||
|
||||
public OpenInventory(@NotNull org.bukkit.entity.Player bukkitPlayer) {
|
||||
owner = PlayerManager.getHandle(bukkitPlayer);
|
||||
|
||||
// Get total size, rounding up to nearest 9 for client compatibility.
|
||||
int rawSize = owner.getInventory().getContainerSize() + owner.inventoryMenu.getCraftSlots().getContainerSize() + 1;
|
||||
size = ((int) Math.ceil(rawSize / 9.0)) * 9;
|
||||
|
||||
slots = NonNullList.withSize(size, new ContentViewOnly(owner));
|
||||
setupSlots();
|
||||
}
|
||||
|
||||
protected void setupSlots() {
|
||||
// Top of inventory: Regular contents.
|
||||
int nextIndex = addMainInventory();
|
||||
|
||||
// If inventory is expected size, we can arrange slots to be pretty.
|
||||
Inventory ownerInv = owner.getInventory();
|
||||
if (ownerInv.getNonEquipmentItems().size() == 36
|
||||
&& Inventory.EQUIPMENT_SLOT_MAPPING.size() == 5
|
||||
&& owner.inventoryMenu.getCraftSlots().getContainerSize() == 4) {
|
||||
// Armor slots: Bottom left.
|
||||
addArmor(36);
|
||||
// Off-hand: Below chestplate.
|
||||
addOffHand(46);
|
||||
// Drop slot: Bottom right.
|
||||
slots.set(53, new ContentDrop(owner));
|
||||
// Cursor slot: Above drop.
|
||||
slots.set(44, new ContentCursor(owner));
|
||||
|
||||
// Crafting is displayed in the bottom right corner.
|
||||
// As we're using the pretty view, this is a 3x2.
|
||||
addCrafting(41, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise we'll just add elements linearly.
|
||||
nextIndex = addArmor(nextIndex);
|
||||
nextIndex = addOffHand(nextIndex);
|
||||
nextIndex = addCrafting(nextIndex, false);
|
||||
slots.set(nextIndex, new ContentCursor(owner));
|
||||
// Drop slot last.
|
||||
slots.set(slots.size() - 1, new ContentDrop(owner));
|
||||
}
|
||||
|
||||
private int addMainInventory() {
|
||||
int listSize = owner.getInventory().getNonEquipmentItems().size();
|
||||
// Hotbar slots are 0-8. We want those to appear on the bottom of the inventory like a normal player inventory,
|
||||
// so everything else needs to move up a row.
|
||||
int hotbarDiff = listSize - 9;
|
||||
for (int localIndex = 0; localIndex < listSize; ++localIndex) {
|
||||
InventoryType.SlotType type;
|
||||
int invIndex;
|
||||
if (localIndex < hotbarDiff) {
|
||||
invIndex = localIndex + 9;
|
||||
type = InventoryType.SlotType.CONTAINER;
|
||||
} else {
|
||||
type = InventoryType.SlotType.QUICKBAR;
|
||||
invIndex = localIndex - hotbarDiff;
|
||||
}
|
||||
|
||||
slots.set(
|
||||
localIndex,
|
||||
new ContentList(owner, invIndex, type) {
|
||||
@Override
|
||||
public void setHolder(@NotNull ServerPlayer holder) {
|
||||
items = holder.getInventory().getNonEquipmentItems();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return listSize;
|
||||
}
|
||||
|
||||
private int addArmor(int startIndex) {
|
||||
// Armor slots go bottom to top; boots are first and helmet is last.
|
||||
// Since we have to display horizontally due to space restrictions,
|
||||
// making the left side the "top" is more user-friendly.
|
||||
EquipmentSlot[] sorted = Inventory.EQUIPMENT_SLOT_MAPPING.int2ObjectEntrySet()
|
||||
.stream()
|
||||
.sorted(Comparator.comparingInt(Int2ObjectMap.Entry::getIntKey))
|
||||
.map(Map.Entry::getValue)
|
||||
.toArray(EquipmentSlot[]::new);
|
||||
int localIndex = 0;
|
||||
for (int i = sorted.length - 1; i >= 0; --i) {
|
||||
// Skip off-hand, handled separately.
|
||||
if (sorted[i] == EquipmentSlot.OFFHAND) {
|
||||
continue;
|
||||
}
|
||||
|
||||
slots.set(startIndex + localIndex, new ContentEquipment(owner, sorted[i]));
|
||||
++localIndex;
|
||||
}
|
||||
|
||||
return startIndex + localIndex;
|
||||
}
|
||||
|
||||
private int addOffHand(int startIndex) {
|
||||
// No off-hand?
|
||||
if (!Inventory.EQUIPMENT_SLOT_MAPPING.containsValue(EquipmentSlot.OFFHAND)) {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
slots.set(startIndex, new ContentOffHand(owner));
|
||||
return startIndex + 1;
|
||||
}
|
||||
|
||||
private int addCrafting(int startIndex, boolean pretty) {
|
||||
int listSize = owner.inventoryMenu.getCraftSlots().getContents().size();
|
||||
pretty &= listSize == 4;
|
||||
|
||||
for (int localIndex = 0; localIndex < listSize; ++localIndex) {
|
||||
// Pretty display is a 2x2 rather than linear.
|
||||
// If index is in top row, grid is not 2x2, or pretty is disabled, just use current index.
|
||||
// Otherwise, subtract 2 and add 9 to start in the same position on the next row.
|
||||
int modIndex = startIndex + (localIndex < 2 || !pretty ? localIndex : localIndex + 7);
|
||||
|
||||
slots.set(modIndex, new ContentCrafting(owner, localIndex));
|
||||
}
|
||||
|
||||
if (pretty) {
|
||||
slots.set(startIndex + 2, new ContentViewOnly(owner) {
|
||||
@Override
|
||||
public Slot asSlot(Container container, int slot, int x, int y) {
|
||||
return new SlotViewOnly(container, slot, x, y) {
|
||||
@Override
|
||||
public ItemStack getOrDefault() {
|
||||
return Placeholders.craftingOutput;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
slots.set(startIndex + 11, getCraftingResult(owner));
|
||||
}
|
||||
|
||||
return startIndex + listSize;
|
||||
}
|
||||
|
||||
protected Content getCraftingResult(@NotNull ServerPlayer serverPlayer) {
|
||||
return new ContentCraftingResult(serverPlayer);
|
||||
}
|
||||
|
||||
public Slot getMenuSlot(int index, int x, int y) {
|
||||
return slots.get(index).asSlot(this, index, x, y);
|
||||
}
|
||||
|
||||
public InventoryType.SlotType getSlotType(int index) {
|
||||
return slots.get(index).getSlotType();
|
||||
public OpenInventory(@NotNull Player bukkitPlayer) {
|
||||
super(bukkitPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getTitle(@Nullable ServerPlayer viewer) {
|
||||
MutableComponent component = Component.empty();
|
||||
// Prefix for use with custom bitmap image fonts.
|
||||
@@ -209,13 +24,13 @@ public class OpenInventory implements Container, InternalOwned<ServerPlayer>, IS
|
||||
component.append(
|
||||
Component.translatableWithFallback("openinv.container.inventory.self", "")
|
||||
.withStyle(style -> style
|
||||
.withFont(ResourceLocation.parse("openinv:font/inventory"))
|
||||
.withFont(new FontDescription.Resource(ResourceLocation.parse("openinv:font/inventory")))
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
} else {
|
||||
component.append(
|
||||
Component.translatableWithFallback("openinv.container.inventory.other", "")
|
||||
.withStyle(style -> style
|
||||
.withFont(ResourceLocation.parse("openinv:font/inventory"))
|
||||
.withFont(new FontDescription.Resource(ResourceLocation.parse("openinv:font/inventory")))
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
}
|
||||
// Normal title: "Inventory - OwnerName"
|
||||
@@ -225,135 +40,4 @@ public class OpenInventory implements Container, InternalOwned<ServerPlayer>, IS
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerPlayer getOwnerHandle() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.inventory.Inventory getBukkitInventory() {
|
||||
if (bukkitEntity == null) {
|
||||
bukkitEntity = new OpenPlayerInventory(this);
|
||||
}
|
||||
return bukkitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(@NotNull org.bukkit.entity.Player player) {
|
||||
ServerPlayer newOwner = PlayerManager.getHandle(player);
|
||||
// Only transfer regular inventory - crafting and cursor slots are transient.
|
||||
newOwner.getInventory().replaceWith(owner.getInventory());
|
||||
owner = newOwner;
|
||||
// Update slots to point to new inventory.
|
||||
slots.forEach(slot -> slot.setHolder(newOwner));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !transaction.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.entity.Player getPlayer() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return slots.stream().map(Content::get).allMatch(ItemStack::isEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack getItem(int index) {
|
||||
return slots.get(index).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItem(int index, int amount) {
|
||||
return slots.get(index).removePartial(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItemNoUpdate(int index) {
|
||||
return slots.get(index).remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, @NotNull ItemStack itemStack) {
|
||||
slots.get(index).set(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int maxStackSize) {
|
||||
this.maxStackSize = maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(@NotNull Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<ItemStack> getContents() {
|
||||
NonNullList<ItemStack> contents = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < getContainerSize(); ++i) {
|
||||
contents.set(i, getItem(i));
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(@NotNull CraftHumanEntity viewer) {
|
||||
transaction.add(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(@NotNull CraftHumanEntity viewer) {
|
||||
transaction.remove(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.entity.Player getOwner() {
|
||||
return owner.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return owner.getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
owner.getInventory().clearContent();
|
||||
owner.inventoryMenu.getCraftSlots().clearContent();
|
||||
owner.inventoryMenu.slotsChanged(owner.inventoryMenu.getCraftSlots());
|
||||
owner.containerMenu.setCarried(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public @Nullable AbstractContainerMenu createMenu(Player player, int i, boolean viewOnly) {
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
return new OpenInventoryMenu(this, serverPlayer, i, viewOnly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package com.lishid.openinv.internal.common.container.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.lishid.openinv.internal.common.container.OpenInventory;
|
||||
import com.lishid.openinv.internal.common.container.BaseOpenInventory;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@@ -18,13 +18,13 @@ import java.util.List;
|
||||
|
||||
public class OpenPlayerInventory extends CraftInventory implements PlayerInventory {
|
||||
|
||||
public OpenPlayerInventory(@NotNull OpenInventory inventory) {
|
||||
public OpenPlayerInventory(@NotNull BaseOpenInventory inventory) {
|
||||
super(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull OpenInventory getInventory() {
|
||||
return (OpenInventory) super.getInventory();
|
||||
public @NotNull BaseOpenInventory getInventory() {
|
||||
return (BaseOpenInventory) super.getInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.lishid.openinv.internal.common.container.bukkit;
|
||||
|
||||
import com.lishid.openinv.internal.common.container.OpenInventory;
|
||||
import com.lishid.openinv.internal.common.container.BaseOpenInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class OpenPlayerInventorySelf extends OpenPlayerInventory {
|
||||
|
||||
private final int offset;
|
||||
|
||||
public OpenPlayerInventorySelf(@NotNull OpenInventory inventory, int offset) {
|
||||
public OpenPlayerInventorySelf(@NotNull BaseOpenInventory inventory, int offset) {
|
||||
super(inventory);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
+16
-2
@@ -364,6 +364,18 @@ public abstract class OpenChestMenu<T extends Container & ISpecialInventory & In
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceSlot(@NotNull Container container, int slot) {
|
||||
int slotsIndex = this.findSlot(container, slot).orElse(-1);
|
||||
if (slotsIndex != -1) {
|
||||
ItemStack item = this.slots.get(slotsIndex).getItem();
|
||||
this.remoteSlots.get(slotsIndex).force(item);
|
||||
if (this.synchronizer != null) {
|
||||
this.synchronizer.sendSlotChange(this, slotsIndex, item.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastCarriedItem() {
|
||||
ItemStack carried = this.getCarried();
|
||||
@@ -424,7 +436,8 @@ public abstract class OpenChestMenu<T extends Container & ISpecialInventory & In
|
||||
}
|
||||
}
|
||||
|
||||
private void triggerSlotListeners(int index, ItemStack itemStack, Supplier<ItemStack> supplier) {
|
||||
@Override
|
||||
public void triggerSlotListeners(int index, @NotNull ItemStack itemStack, @NotNull Supplier<ItemStack> supplier) {
|
||||
ItemStack itemStack1 = this.lastSlots.get(index);
|
||||
if (!ItemStack.matches(itemStack1, itemStack)) {
|
||||
ItemStack itemStack2 = supplier.get();
|
||||
@@ -436,7 +449,8 @@ public abstract class OpenChestMenu<T extends Container & ISpecialInventory & In
|
||||
}
|
||||
}
|
||||
|
||||
private void synchronizeSlotToRemote(int i, ItemStack itemStack, Supplier<ItemStack> supplier) {
|
||||
@Override
|
||||
public void synchronizeSlotToRemote(int i, @NotNull ItemStack itemStack, @NotNull Supplier<ItemStack> supplier) {
|
||||
if (!this.suppressRemoteUpdates) {
|
||||
RemoteSlot slot = this.remoteSlots.get(i);
|
||||
if (!slot.matches(itemStack)) {
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package com.lishid.openinv.internal.common.container.menu;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.lishid.openinv.internal.common.container.OpenInventory;
|
||||
import com.lishid.openinv.internal.common.container.BaseOpenInventory;
|
||||
import com.lishid.openinv.internal.common.container.bukkit.OpenDummyPlayerInventory;
|
||||
import com.lishid.openinv.internal.common.container.bukkit.OpenPlayerInventorySelf;
|
||||
import com.lishid.openinv.internal.common.container.slot.ContentDrop;
|
||||
@@ -23,15 +23,15 @@ import org.bukkit.inventory.InventoryView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OpenInventoryMenu extends OpenChestMenu<OpenInventory> {
|
||||
public class OpenInventoryMenu extends OpenChestMenu<BaseOpenInventory> {
|
||||
|
||||
private int offset;
|
||||
|
||||
public OpenInventoryMenu(OpenInventory inventory, ServerPlayer viewer, int i, boolean viewOnly) {
|
||||
public OpenInventoryMenu(BaseOpenInventory inventory, ServerPlayer viewer, int i, boolean viewOnly) {
|
||||
super(getMenuType(inventory, viewer), i, inventory, viewer, viewOnly);
|
||||
}
|
||||
|
||||
private static MenuType<ChestMenu> getMenuType(OpenInventory inventory, ServerPlayer viewer) {
|
||||
private static MenuType<ChestMenu> getMenuType(BaseOpenInventory inventory, ServerPlayer viewer) {
|
||||
int size = inventory.getContainerSize();
|
||||
// Disallow duplicate access to own main inventory contents.
|
||||
if (inventory.getOwnerHandle().equals(viewer)) {
|
||||
@@ -99,7 +99,7 @@ public class OpenInventoryMenu extends OpenChestMenu<OpenInventory> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull CraftInventoryView<OpenChestMenu<OpenInventory>, Inventory> createBukkitEntity() {
|
||||
protected @NotNull CraftInventoryView<OpenChestMenu<BaseOpenInventory>, Inventory> createBukkitEntity() {
|
||||
org.bukkit.inventory.Inventory bukkitInventory;
|
||||
if (viewOnly) {
|
||||
bukkitInventory = new OpenDummyPlayerInventory(container);
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.lishid.openinv.internal.common.container.slot;
|
||||
|
||||
import com.lishid.openinv.internal.common.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.common.player.OpenPlayer;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
@@ -35,7 +35,7 @@ public class ContentCrafting implements Content {
|
||||
// Player must be online and not in creative - since the creative client is (semi-)authoritative,
|
||||
// it ignores changes without extra help, and will delete the item as a result.
|
||||
// Spectator mode is technically possible but may cause the item to be dropped if the client opens an inventory.
|
||||
return OpenPlayer.isConnected(holder.connection) && holder.gameMode.isSurvival();
|
||||
return BaseOpenPlayer.isConnected(holder.connection) && holder.gameMode.isSurvival();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.lishid.openinv.internal.common.container.slot;
|
||||
|
||||
import com.lishid.openinv.internal.common.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.common.player.OpenPlayer;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -64,7 +64,7 @@ public class ContentCursor implements Content {
|
||||
// Player must be online and not in creative - since the creative client is (semi-)authoritative,
|
||||
// it ignores changes without extra help, and will delete the item as a result.
|
||||
// Spectator mode is technically possible but may cause the item to be dropped if the client opens an inventory.
|
||||
return OpenPlayer.isConnected(holder.connection) && holder.gameMode.isSurvival();
|
||||
return BaseOpenPlayer.isConnected(holder.connection) && holder.gameMode.isSurvival();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package com.lishid.openinv.internal.common.container.slot;
|
||||
|
||||
import com.lishid.openinv.internal.common.container.slot.placeholder.Placeholders;
|
||||
import com.lishid.openinv.internal.common.player.OpenPlayer;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
@@ -64,14 +64,14 @@ public class ContentDrop implements Content {
|
||||
|
||||
@Override
|
||||
public ItemStack getOrDefault() {
|
||||
return OpenPlayer.isConnected(holder.connection)
|
||||
return BaseOpenPlayer.isConnected(holder.connection)
|
||||
? Placeholders.drop
|
||||
: Placeholders.blockedOffline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPlace(@NotNull ItemStack itemStack) {
|
||||
return OpenPlayer.isConnected(holder.connection);
|
||||
return BaseOpenPlayer.isConnected(holder.connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.lishid.openinv.internal.common.container.slot;
|
||||
|
||||
import com.lishid.openinv.internal.common.player.OpenPlayer;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
@@ -37,7 +37,7 @@ public class ContentOffHand extends ContentEquipment {
|
||||
return new SlotEquipment(container, slot, x, y) {
|
||||
@Override
|
||||
public void setChanged() {
|
||||
if (OpenPlayer.isConnected(holder.connection) && holder.containerMenu != holder.inventoryMenu) {
|
||||
if (BaseOpenPlayer.isConnected(holder.connection) && holder.containerMenu != holder.inventoryMenu) {
|
||||
holder.connection.send(
|
||||
new ClientboundContainerSetSlotPacket(
|
||||
holder.inventoryMenu.containerId,
|
||||
|
||||
+11
-4
@@ -1,10 +1,12 @@
|
||||
package com.lishid.openinv.internal.common.container.slot.placeholder;
|
||||
|
||||
import com.mojang.serialization.DataResult;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -21,7 +23,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class PlaceholderLoaderBase {
|
||||
|
||||
@@ -51,7 +52,7 @@ public abstract class PlaceholderLoaderBase {
|
||||
Placeholders.BLOCKED_GAME_TYPE.put(GameType.SPECTATOR, parse(section, "blocked.spectator", Placeholders.BLOCKED_GAME_TYPE.get(GameType.SPECTATOR)));
|
||||
}
|
||||
|
||||
private @NotNull ItemStack parse(
|
||||
protected @NotNull ItemStack parse(
|
||||
@Nullable ConfigurationSection section,
|
||||
@NotNull String path,
|
||||
@NotNull ItemStack defaultStack
|
||||
@@ -67,8 +68,14 @@ public abstract class PlaceholderLoaderBase {
|
||||
}
|
||||
|
||||
CompoundTag compoundTag = parseTag(itemText);
|
||||
Optional<ItemStack> parsed = ItemStack.parse(CraftRegistry.getMinecraftRegistry(), compoundTag);
|
||||
return parsed.filter(itemStack -> !itemStack.isEmpty()).orElse(defaultStack);
|
||||
DataResult<ItemStack> parsed = ItemStack.CODEC.parse(CraftRegistry.getMinecraftRegistry().createSerializationContext(NbtOps.INSTANCE), compoundTag);
|
||||
ItemStack itemStack;
|
||||
try {
|
||||
itemStack = parsed.getOrThrow();
|
||||
} catch (Exception e) {
|
||||
itemStack = null;
|
||||
}
|
||||
return itemStack == null ? defaultStack : itemStack;
|
||||
}
|
||||
|
||||
protected abstract @NotNull CompoundTag parseTag(@NotNull String itemText) throws Exception;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.lishid.openinv.internal.common.container.slot.placeholder;
|
||||
|
||||
import com.lishid.openinv.internal.common.player.OpenPlayer;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.GameType;
|
||||
@@ -23,7 +23,7 @@ public final class Placeholders {
|
||||
public static @NotNull ItemStack blockedOffline = ItemStack.EMPTY;
|
||||
|
||||
public static ItemStack survivalOnly(@NotNull ServerPlayer serverPlayer) {
|
||||
if (!OpenPlayer.isConnected(serverPlayer.connection)) {
|
||||
if (!BaseOpenPlayer.isConnected(serverPlayer.connection)) {
|
||||
return blockedOffline;
|
||||
}
|
||||
|
||||
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
package com.lishid.openinv.internal.common.player;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NumericTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class BaseOpenPlayer extends CraftPlayer {
|
||||
|
||||
/**
|
||||
* List of tags to always reset when saving. These are items that do not get written
|
||||
* if unset or empty, resulting in older values not being clobbered appropriately.
|
||||
*
|
||||
* @see net.minecraft.world.entity.Entity#saveWithoutId(ValueOutput)
|
||||
* @see net.minecraft.server.level.ServerPlayer#addAdditionalSaveData(ValueOutput)
|
||||
* @see net.minecraft.world.entity.player.Player#addAdditionalSaveData(ValueOutput)
|
||||
* @see net.minecraft.world.entity.LivingEntity#addAdditionalSaveData(ValueOutput)
|
||||
*/
|
||||
@Unmodifiable
|
||||
protected static final Set<String> RESET_TAGS = Set.of(
|
||||
// Entity#saveWithoutId(CompoundTag)
|
||||
"CustomName",
|
||||
"CustomNameVisible",
|
||||
"Silent",
|
||||
"NoGravity",
|
||||
"Glowing",
|
||||
"TicksFrozen",
|
||||
"HasVisualFire",
|
||||
"Tags",
|
||||
"data",
|
||||
"Passengers",
|
||||
// ServerPlayer#addAdditionalSaveData(CompoundTag)
|
||||
// Intentional omissions to prevent mount loss: Attach, Entity, and RootVehicle
|
||||
"warden_spawn_tracker",
|
||||
"entered_nether_pos", // Replaces enteredNetherPosition
|
||||
"enteredNetherPosition",
|
||||
"respawn", // Replaces SpawnXyz fields as of 1.21.6
|
||||
"SpawnX",
|
||||
"SpawnY",
|
||||
"SpawnZ",
|
||||
"SpawnForced",
|
||||
"SpawnAngle",
|
||||
"SpawnDimension",
|
||||
"raid_omen_position",
|
||||
"ender_pearls",
|
||||
"ShoulderEntityLeft",
|
||||
"ShoulderEntityRight",
|
||||
// Player#addAdditionalSaveData(CompoundTag)
|
||||
"LastDeathLocation",
|
||||
"current_explosion_impact_pos",
|
||||
// LivingEntity#addAdditionalSaveData(CompoundTag)
|
||||
"active_effects",
|
||||
"sleeping_pos", // Replaces SleepingXyz fields as of 1.21.6
|
||||
"SleepingX",
|
||||
"SleepingY",
|
||||
"SleepingZ",
|
||||
"Brain",
|
||||
"last_hurt_by_player",
|
||||
"last_hurt_by_player_memory_time",
|
||||
"last_hurt_by_mob",
|
||||
"ticks_since_last_hurt_by_mob",
|
||||
"equipment",
|
||||
"locator_bar_icon"
|
||||
);
|
||||
|
||||
private final PlayerManager manager;
|
||||
|
||||
protected BaseOpenPlayer(CraftServer server, ServerPlayer entity, PlayerManager manager) {
|
||||
super(server, entity);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
manager.loadData(server.getServer(), getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void saveData();
|
||||
|
||||
@Contract("null -> new")
|
||||
protected @NotNull CompoundTag getWritableTag(@Nullable CompoundTag oldData) {
|
||||
if (oldData == null) {
|
||||
return new CompoundTag();
|
||||
}
|
||||
|
||||
// Copy old data. This is a deep clone, so operating on it should be safe.
|
||||
oldData = oldData.copy();
|
||||
|
||||
// Remove vanilla/server data that is not written every time.
|
||||
oldData.keySet().removeIf(
|
||||
key -> RESET_TAGS.contains(key)
|
||||
|| key.startsWith("Bukkit")
|
||||
|| (key.startsWith("Paper") && key.length() > 5)
|
||||
);
|
||||
|
||||
return oldData;
|
||||
}
|
||||
|
||||
protected void revertSpecialValues(@NotNull CompoundTag newData, @NotNull CompoundTag oldData) {
|
||||
// Revert automatic updates to play timestamps.
|
||||
copyValue(oldData, newData, "bukkit", "lastPlayed", NumericTag.class);
|
||||
copyValue(oldData, newData, "Paper", "LastSeen", NumericTag.class);
|
||||
copyValue(oldData, newData, "Paper", "LastLogin", NumericTag.class);
|
||||
}
|
||||
|
||||
private <T extends Tag> void copyValue(
|
||||
@NotNull CompoundTag source,
|
||||
@NotNull CompoundTag target,
|
||||
@NotNull String container,
|
||||
@NotNull String key,
|
||||
@SuppressWarnings("SameParameterValue") @NotNull Class<T> tagType
|
||||
) {
|
||||
CompoundTag oldContainer = getTag(source, container, CompoundTag.class);
|
||||
CompoundTag newContainer = getTag(target, container, CompoundTag.class);
|
||||
|
||||
// New container being null means the server implementation doesn't store this data.
|
||||
if (newContainer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If old tag exists, copy it to new location, removing otherwise.
|
||||
setTag(newContainer, key, getTag(oldContainer, key, tagType));
|
||||
}
|
||||
|
||||
private <T extends Tag> @Nullable T getTag(
|
||||
@Nullable CompoundTag container,
|
||||
@NotNull String key,
|
||||
@NotNull Class<T> dataType
|
||||
) {
|
||||
if (container == null) {
|
||||
return null;
|
||||
}
|
||||
Tag value = container.get(key);
|
||||
if (value == null || !dataType.isAssignableFrom(value.getClass())) {
|
||||
return null;
|
||||
}
|
||||
return dataType.cast(value);
|
||||
}
|
||||
|
||||
private <T extends Tag> void setTag(
|
||||
@NotNull CompoundTag container,
|
||||
@NotNull String key,
|
||||
@Nullable T data
|
||||
) {
|
||||
if (data == null) {
|
||||
container.remove(key);
|
||||
} else {
|
||||
container.put(key, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConnected(@Nullable ServerGamePacketListenerImpl connection) {
|
||||
return connection != null && !connection.isDisconnected();
|
||||
}
|
||||
|
||||
}
|
||||
+20
-152
@@ -5,85 +5,25 @@ import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NumericTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraft.world.level.storage.TagValueOutput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
public class OpenPlayer extends CraftPlayer {
|
||||
public class OpenPlayer extends BaseOpenPlayer {
|
||||
|
||||
/**
|
||||
* List of tags to always reset when saving.
|
||||
*
|
||||
* @see net.minecraft.world.entity.Entity#saveWithoutId(CompoundTag)
|
||||
* @see net.minecraft.server.level.ServerPlayer#addAdditionalSaveData(CompoundTag)
|
||||
* @see net.minecraft.world.entity.player.Player#addAdditionalSaveData(CompoundTag)
|
||||
* @see net.minecraft.world.entity.LivingEntity#addAdditionalSaveData(CompoundTag)
|
||||
*/
|
||||
@Unmodifiable
|
||||
protected static final Set<String> RESET_TAGS = Set.of(
|
||||
// Entity#saveWithoutId(CompoundTag)
|
||||
"CustomName",
|
||||
"CustomNameVisible",
|
||||
"Silent",
|
||||
"NoGravity",
|
||||
"Glowing",
|
||||
"TicksFrozen",
|
||||
"HasVisualFire",
|
||||
"Tags",
|
||||
"Passengers",
|
||||
// ServerPlayer#addAdditionalSaveData(CompoundTag)
|
||||
// Intentional omissions to prevent mount loss: Attach, Entity, and RootVehicle
|
||||
// As of 1.21.5 only ender_pearls tag still needs to be reset. Rest are for backwards compatibility.
|
||||
"warden_spawn_tracker",
|
||||
"enteredNetherPosition",
|
||||
"SpawnX",
|
||||
"SpawnY",
|
||||
"SpawnZ",
|
||||
"SpawnForced",
|
||||
"SpawnAngle",
|
||||
"SpawnDimension",
|
||||
"raid_omen_position",
|
||||
"ender_pearls",
|
||||
// Player#addAdditionalSaveData(CompoundTag)
|
||||
"ShoulderEntityLeft",
|
||||
"ShoulderEntityRight",
|
||||
"LastDeathLocation",
|
||||
"current_explosion_impact_pos", // Unnecessary in 1.21.5
|
||||
// LivingEntity#addAdditionalSaveData(CompoundTag)
|
||||
"active_effects",
|
||||
"SleepingX",
|
||||
"SleepingY",
|
||||
"SleepingZ",
|
||||
"Brain",
|
||||
"last_hurt_by_player",
|
||||
"last_hurt_by_player_memory_time",
|
||||
"last_hurt_by_mob",
|
||||
"ticks_since_last_hurt_by_mob",
|
||||
"equipment"
|
||||
);
|
||||
|
||||
private final PlayerManager manager;
|
||||
|
||||
protected OpenPlayer(CraftServer server, ServerPlayer entity, PlayerManager manager) {
|
||||
super(server, entity);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
manager.loadData(getHandle());
|
||||
protected OpenPlayer(
|
||||
CraftServer server,
|
||||
ServerPlayer entity,
|
||||
PlayerManager manager
|
||||
) {
|
||||
super(server, entity, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,14 +33,18 @@ public class OpenPlayer extends CraftPlayer {
|
||||
}
|
||||
|
||||
ServerPlayer player = this.getHandle();
|
||||
Logger logger = LogUtils.getLogger();
|
||||
// See net.minecraft.world.level.storage.PlayerDataStorage#save(EntityHuman)
|
||||
try {
|
||||
PlayerDataStorage worldNBTStorage = player.server.getPlayerList().playerIo;
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), logger)) {
|
||||
PlayerDataStorage worldNBTStorage = server.getServer().getPlayerList().playerIo;
|
||||
|
||||
CompoundTag oldData = isOnline() ? null : worldNBTStorage.load(player.getName().getString(), player.getStringUUID()).orElse(null);
|
||||
CompoundTag oldData = isOnline()
|
||||
? null
|
||||
: worldNBTStorage.load(player.nameAndId()).orElse(null);
|
||||
CompoundTag playerData = getWritableTag(oldData);
|
||||
playerData = player.saveWithoutId(playerData);
|
||||
setExtraData(playerData);
|
||||
|
||||
ValueOutput valueOutput = TagValueOutput.createWrappingWithContext(scopedCollector, player.registryAccess(), playerData);
|
||||
player.saveWithoutId(valueOutput);
|
||||
|
||||
if (oldData != null) {
|
||||
// Revert certain special data values when offline.
|
||||
@@ -118,80 +62,4 @@ public class OpenPlayer extends CraftPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("null -> new")
|
||||
protected @NotNull CompoundTag getWritableTag(@Nullable CompoundTag oldData) {
|
||||
if (oldData == null) {
|
||||
return new CompoundTag();
|
||||
}
|
||||
|
||||
// Copy old data. This is a deep clone, so operating on it should be safe.
|
||||
oldData = oldData.copy();
|
||||
|
||||
// Remove vanilla/server data that is not written every time.
|
||||
oldData.keySet().removeIf(
|
||||
key -> RESET_TAGS.contains(key)
|
||||
|| key.startsWith("Bukkit")
|
||||
|| (key.startsWith("Paper") && key.length() > 5)
|
||||
);
|
||||
|
||||
return oldData;
|
||||
}
|
||||
|
||||
private void revertSpecialValues(@NotNull CompoundTag newData, @NotNull CompoundTag oldData) {
|
||||
// Revert automatic updates to play timestamps.
|
||||
copyValue(oldData, newData, "bukkit", "lastPlayed", NumericTag.class);
|
||||
copyValue(oldData, newData, "Paper", "LastSeen", NumericTag.class);
|
||||
copyValue(oldData, newData, "Paper", "LastLogin", NumericTag.class);
|
||||
}
|
||||
|
||||
private <T extends Tag> void copyValue(
|
||||
@NotNull CompoundTag source,
|
||||
@NotNull CompoundTag target,
|
||||
@NotNull String container,
|
||||
@NotNull String key,
|
||||
@SuppressWarnings("SameParameterValue") @NotNull Class<T> tagType
|
||||
) {
|
||||
CompoundTag oldContainer = getTag(source, container, CompoundTag.class);
|
||||
CompoundTag newContainer = getTag(target, container, CompoundTag.class);
|
||||
|
||||
// New container being null means the server implementation doesn't store this data.
|
||||
if (newContainer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If old tag exists, copy it to new location, removing otherwise.
|
||||
setTag(newContainer, key, getTag(oldContainer, key, tagType));
|
||||
}
|
||||
|
||||
private <T extends Tag> @Nullable T getTag(
|
||||
@Nullable CompoundTag container,
|
||||
@NotNull String key,
|
||||
@NotNull Class<T> dataType
|
||||
) {
|
||||
if (container == null) {
|
||||
return null;
|
||||
}
|
||||
Tag value = container.get(key);
|
||||
if (value == null || !dataType.isAssignableFrom(value.getClass())) {
|
||||
return null;
|
||||
}
|
||||
return dataType.cast(value);
|
||||
}
|
||||
|
||||
private <T extends Tag> void setTag(
|
||||
@NotNull CompoundTag container,
|
||||
@NotNull String key,
|
||||
@Nullable T data
|
||||
) {
|
||||
if (data == null) {
|
||||
container.remove(key);
|
||||
} else {
|
||||
container.put(key, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConnected(@Nullable ServerGamePacketListenerImpl connection) {
|
||||
return connection != null && !connection.isDisconnected();
|
||||
}
|
||||
|
||||
}
|
||||
+47
-45
@@ -1,13 +1,13 @@
|
||||
package com.lishid.openinv.internal.common.player;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.common.container.BaseOpenInventory;
|
||||
import com.lishid.openinv.internal.common.container.OpenEnderChest;
|
||||
import com.lishid.openinv.internal.common.container.OpenInventory;
|
||||
import com.lishid.openinv.util.JulLoggerAdapter;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -15,11 +15,14 @@ import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ParticleStatus;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.ChatVisiblity;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelData;
|
||||
import net.minecraft.world.level.storage.TagValueInput;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
@@ -76,7 +79,11 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
|
||||
@Override
|
||||
public @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
if (!(Bukkit.getServer() instanceof CraftServer craftServer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = craftServer.getServer();
|
||||
ServerLevel worldServer = server.getLevel(Level.OVERWORLD);
|
||||
|
||||
if (worldServer == null) {
|
||||
@@ -90,7 +97,7 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
entity.getAdvancements().stopListening();
|
||||
|
||||
// Try to load the player's data.
|
||||
if (loadData(entity)) {
|
||||
if (loadData(server, entity)) {
|
||||
// If data is loaded successfully, return the Bukkit entity.
|
||||
return entity.getBukkitEntity();
|
||||
}
|
||||
@@ -124,7 +131,7 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
ServerPlayer entity = new ServerPlayer(server, worldServer, profile, dummyInfo);
|
||||
|
||||
try {
|
||||
injectPlayer(entity);
|
||||
injectPlayer(server, entity);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(
|
||||
java.util.logging.Level.WARNING,
|
||||
@@ -136,29 +143,34 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
return entity;
|
||||
}
|
||||
|
||||
boolean loadData(@NotNull ServerPlayer player) {
|
||||
protected boolean loadData(@NotNull MinecraftServer server, @NotNull ServerPlayer player) {
|
||||
// See CraftPlayer#loadData
|
||||
CompoundTag loadedData = player.server.getPlayerList().playerIo.load(player).orElse(null);
|
||||
|
||||
if (loadedData == null) {
|
||||
// Exceptions with loading are logged by Mojang.
|
||||
return false;
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), new JulLoggerAdapter(logger))) {
|
||||
CompoundTag loadedData = server.getPlayerList().playerIo.load(player.nameAndId()).orElse(null);
|
||||
|
||||
if (loadedData == null) {
|
||||
// Exceptions with loading are logged.
|
||||
return false;
|
||||
}
|
||||
|
||||
ValueInput valueInput = TagValueInput.create(scopedCollector, player.registryAccess(), loadedData);
|
||||
|
||||
// Read basic data into the player.
|
||||
player.load(valueInput);
|
||||
|
||||
// World is not loaded by ServerPlayer#load(CompoundTag) on Paper.
|
||||
parseWorld(server, player, valueInput);
|
||||
}
|
||||
|
||||
// Read basic data into the player.
|
||||
player.load(loadedData);
|
||||
// Also read "extra" data.
|
||||
player.readAdditionalSaveData(loadedData);
|
||||
// Game type settings are also loaded separately.
|
||||
player.loadGameTypes(loadedData);
|
||||
|
||||
// World is not loaded by ServerPlayer#load(CompoundTag) on Paper.
|
||||
parseWorld(player, loadedData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void parseWorld(@NotNull ServerPlayer player, @NotNull CompoundTag loadedData) {
|
||||
protected void parseWorld(
|
||||
@NotNull MinecraftServer server,
|
||||
@NotNull ServerPlayer player,
|
||||
@NotNull ValueInput loadedData
|
||||
) {
|
||||
// See PlayerList#placeNewPlayer
|
||||
World bukkitWorld;
|
||||
Optional<Long> msbs = loadedData.getLong("WorldUUIDMost");
|
||||
@@ -167,56 +179,46 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
// Modern Bukkit world.
|
||||
bukkitWorld = Bukkit.getServer().getWorld(new UUID(msbs.get(), lsbs.get()));
|
||||
} else {
|
||||
Optional<String> worldName = loadedData.getString("world");
|
||||
if (worldName.isPresent()) {
|
||||
// Legacy Bukkit world.
|
||||
bukkitWorld = Bukkit.getServer().getWorld(worldName.get());
|
||||
} else {
|
||||
// Vanilla player data.
|
||||
DimensionType.parseLegacy(new Dynamic<>(NbtOps.INSTANCE, loadedData.get("Dimension")))
|
||||
.resultOrPartial(logger::warning)
|
||||
.map(player.server::getLevel)
|
||||
// If ServerLevel exists, set, otherwise move to spawn.
|
||||
.ifPresentOrElse(player::setServerLevel, () -> spawnInDefaultWorld(player));
|
||||
return;
|
||||
}
|
||||
bukkitWorld = loadedData.getString("world").map(Bukkit::getWorld).orElse(null);
|
||||
}
|
||||
if (bukkitWorld == null) {
|
||||
spawnInDefaultWorld(player);
|
||||
spawnInDefaultWorld(server, player);
|
||||
return;
|
||||
}
|
||||
player.setServerLevel(((CraftWorld) bukkitWorld).getHandle());
|
||||
}
|
||||
|
||||
protected void spawnInDefaultWorld(ServerPlayer player) {
|
||||
ServerLevel level = player.server.getLevel(Level.OVERWORLD);
|
||||
protected void spawnInDefaultWorld(@NotNull MinecraftServer server, @NotNull ServerPlayer player) {
|
||||
ServerLevel level = server.getLevel(Level.OVERWORLD);
|
||||
if (level != null) {
|
||||
// Adjust player to default spawn (in keeping with Paper handling) when world not found.
|
||||
player.snapTo(player.adjustSpawnLocation(level, level.getSharedSpawnPos()).getBottomCenter(), level.getSharedSpawnAngle(), 0.0F);
|
||||
LevelData.RespawnData respawnData = level.levelData.getRespawnData();
|
||||
player.snapTo(player.adjustSpawnLocation(level, respawnData.pos()).getBottomCenter(), respawnData.yaw(), 0.0F);
|
||||
player.spawnIn(level);
|
||||
} else {
|
||||
logger.warning("Tried to load player with invalid world when no fallback was available!");
|
||||
}
|
||||
}
|
||||
|
||||
protected void injectPlayer(ServerPlayer player) throws IllegalAccessException {
|
||||
protected void injectPlayer(@NotNull MinecraftServer server, @NotNull ServerPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitEntity.setAccessible(true);
|
||||
|
||||
bukkitEntity.set(player, new OpenPlayer(player.server.server, player, this));
|
||||
bukkitEntity.set(player, new OpenPlayer(server.server, player, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Player inject(@NotNull Player player) {
|
||||
try {
|
||||
ServerPlayer nmsPlayer = getHandle(player);
|
||||
if (nmsPlayer.getBukkitEntity() instanceof OpenPlayer openPlayer) {
|
||||
if (nmsPlayer.getBukkitEntity() instanceof BaseOpenPlayer openPlayer) {
|
||||
return openPlayer;
|
||||
}
|
||||
injectPlayer(nmsPlayer);
|
||||
MinecraftServer server = nmsPlayer.level().getServer();
|
||||
injectPlayer(server, nmsPlayer);
|
||||
return nmsPlayer.getBukkitEntity();
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(
|
||||
@@ -235,14 +237,14 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
) {
|
||||
ServerPlayer player = getHandle(bukkitPlayer);
|
||||
|
||||
if (!OpenPlayer.isConnected(player.connection)) {
|
||||
if (!BaseOpenPlayer.isConnected(player.connection)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// See net.minecraft.server.level.ServerPlayer#openMenu(MenuProvider)
|
||||
AbstractContainerMenu menu;
|
||||
Component title;
|
||||
if (inventory instanceof OpenInventory playerInv) {
|
||||
if (inventory instanceof BaseOpenInventory playerInv) {
|
||||
menu = playerInv.createMenu(player, player.nextContainerCounter(), viewOnly);
|
||||
title = playerInv.getTitle(player);
|
||||
} else if (inventory instanceof OpenEnderChest enderChest) {
|
||||
|
||||
@@ -21,6 +21,8 @@ dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
implementation(project(":openinvadaptercommon"))
|
||||
implementation(project(":openinvadapterpaper1_21_8"))
|
||||
implementation(project(":openinvadapterpaper1_21_5"))
|
||||
implementation(project(":openinvadapterpaper1_21_4"))
|
||||
implementation(project(":openinvadapterpaper1_21_3"))
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class PlayerManager extends com.lishid.openinv.internal.paper1_21_4.playe
|
||||
ServerPlayer entity = new ServerPlayer(server, worldServer, profile, dummyInfo);
|
||||
|
||||
try {
|
||||
injectPlayer(entity);
|
||||
injectPlayer(server, entity);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(
|
||||
java.util.logging.Level.WARNING,
|
||||
|
||||
@@ -21,6 +21,8 @@ dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
implementation(project(":openinvadaptercommon"))
|
||||
implementation(project(":openinvadapterpaper1_21_8"))
|
||||
implementation(project(":openinvadapterpaper1_21_5"))
|
||||
implementation(project(":openinvadapterpaper1_21_4"))
|
||||
|
||||
paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT")
|
||||
|
||||
@@ -21,6 +21,8 @@ dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
implementation(project(":openinvadaptercommon"))
|
||||
implementation(project(":openinvadapterpaper1_21_8"))
|
||||
implementation(project(":openinvadapterpaper1_21_5"))
|
||||
|
||||
paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OpenInventory extends com.lishid.openinv.internal.common.container.OpenInventory {
|
||||
public class OpenInventory extends com.lishid.openinv.internal.paper1_21_8.container.OpenInventory {
|
||||
|
||||
public OpenInventory(@NotNull org.bukkit.entity.Player bukkitPlayer) {
|
||||
super(bukkitPlayer);
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.lishid.openinv.internal.paper1_21_4.container.slot;
|
||||
|
||||
import com.lishid.openinv.internal.common.player.OpenPlayer;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
@@ -37,7 +37,7 @@ public class ContentOffHand extends ContentEquipment {
|
||||
return new SlotEquipment(container, slot, x, y) {
|
||||
@Override
|
||||
public void setChanged() {
|
||||
if (OpenPlayer.isConnected(holder.connection) && holder.containerMenu != holder.inventoryMenu) {
|
||||
if (BaseOpenPlayer.isConnected(holder.connection) && holder.containerMenu != holder.inventoryMenu) {
|
||||
holder.connection.send(
|
||||
new ClientboundContainerSetSlotPacket(
|
||||
holder.inventoryMenu.containerId,
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package com.lishid.openinv.internal.paper1_21_4.player;
|
||||
|
||||
import com.lishid.openinv.internal.common.player.PlayerManager;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
@@ -8,7 +7,7 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OpenPlayer extends com.lishid.openinv.internal.common.player.OpenPlayer {
|
||||
public class OpenPlayer extends com.lishid.openinv.internal.paper1_21_5.player.OpenPlayer {
|
||||
|
||||
protected OpenPlayer(
|
||||
CraftServer server, ServerPlayer entity,
|
||||
|
||||
+7
-6
@@ -3,6 +3,7 @@ package com.lishid.openinv.internal.paper1_21_4.player;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -15,7 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PlayerManager extends com.lishid.openinv.internal.common.player.PlayerManager {
|
||||
public class PlayerManager extends com.lishid.openinv.internal.paper1_21_5.player.PlayerManager {
|
||||
|
||||
public PlayerManager(@NotNull Logger logger) {
|
||||
super(logger);
|
||||
@@ -37,19 +38,19 @@ public class PlayerManager extends com.lishid.openinv.internal.common.player.Pla
|
||||
.resultOrPartial(logger::warning)
|
||||
.map(player.server::getLevel)
|
||||
// If ServerLevel exists, set, otherwise move to spawn.
|
||||
.ifPresentOrElse(player::setServerLevel, () -> spawnInDefaultWorld(player));
|
||||
.ifPresentOrElse(player::setServerLevel, () -> spawnInDefaultWorld(player.server, player));
|
||||
return;
|
||||
}
|
||||
if (bukkitWorld == null) {
|
||||
spawnInDefaultWorld(player);
|
||||
spawnInDefaultWorld(player.server, player);
|
||||
return;
|
||||
}
|
||||
player.setServerLevel(((CraftWorld) bukkitWorld).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnInDefaultWorld(ServerPlayer player) {
|
||||
ServerLevel level = player.server.getLevel(Level.OVERWORLD);
|
||||
protected void spawnInDefaultWorld(@NotNull MinecraftServer server, @NotNull ServerPlayer player) {
|
||||
ServerLevel level = server.getLevel(Level.OVERWORLD);
|
||||
if (level != null) {
|
||||
// Adjust player to default spawn (in keeping with Paper handling) when world not found.
|
||||
player.moveTo(player.adjustSpawnLocation(level, level.getSharedSpawnPos()).getBottomCenter(), level.getSharedSpawnAngle(), 0.0F);
|
||||
@@ -60,7 +61,7 @@ public class PlayerManager extends com.lishid.openinv.internal.common.player.Pla
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void injectPlayer(ServerPlayer player) throws IllegalAccessException {
|
||||
protected void injectPlayer(@NotNull MinecraftServer server, @NotNull ServerPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
`openinv-base`
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy.capabilitiesResolution.withCapability("org.spigotmc:spigot-api") {
|
||||
val paper = candidates.firstOrNull {
|
||||
it.id.let { id ->
|
||||
id is ModuleComponentIdentifier && id.module == "paper-api"
|
||||
}
|
||||
}
|
||||
if (paper != null) {
|
||||
select(paper)
|
||||
}
|
||||
because("module is written for Paper servers")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
implementation(project(":openinvadaptercommon"))
|
||||
implementation(project(":openinvadapterpaper1_21_8"))
|
||||
|
||||
paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT")
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.lishid.openinv.internal.paper1_21_5;
|
||||
|
||||
import com.lishid.openinv.internal.paper1_21_5.container.slot.placeholder.PlaceholderLoaderLegacyParse;
|
||||
import com.lishid.openinv.internal.paper1_21_5.player.PlayerManager;
|
||||
import com.lishid.openinv.util.lang.LanguageManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class InternalAccessor extends com.lishid.openinv.internal.paper1_21_8.InternalAccessor {
|
||||
|
||||
private final @NotNull PlayerManager manager;
|
||||
|
||||
public InternalAccessor(@NotNull Logger logger, @NotNull LanguageManager lang) {
|
||||
super(logger, lang);
|
||||
manager = new PlayerManager(logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerManager getPlayerManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(@NotNull ConfigurationSection config) {
|
||||
ConfigurationSection placeholders = config.getConfigurationSection("placeholders");
|
||||
try {
|
||||
// Reset placeholders to defaults and try to load configuration.
|
||||
new PlaceholderLoaderLegacyParse().load(placeholders);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Caught exception loading placeholder overrides!", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.lishid.openinv.internal.paper1_21_5.container.slot.placeholder;
|
||||
|
||||
import com.lishid.openinv.internal.common.container.slot.placeholder.PlaceholderLoader;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class PlaceholderLoaderLegacyParse extends PlaceholderLoader {
|
||||
|
||||
@Override
|
||||
protected @NotNull ItemStack parse(
|
||||
@Nullable ConfigurationSection section,
|
||||
@NotNull String path,
|
||||
@NotNull ItemStack defaultStack
|
||||
) throws Exception {
|
||||
if (section == null) {
|
||||
return defaultStack;
|
||||
}
|
||||
|
||||
String itemText = section.getString(path);
|
||||
|
||||
if (itemText == null) {
|
||||
return defaultStack;
|
||||
}
|
||||
|
||||
CompoundTag compoundTag = parseTag(itemText);
|
||||
Optional<ItemStack> parsed = ItemStack.parse(CraftRegistry.getMinecraftRegistry(), compoundTag);
|
||||
return parsed.filter(itemStack -> !itemStack.isEmpty()).orElse(defaultStack);
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.lishid.openinv.internal.paper1_21_5.player;
|
||||
|
||||
import com.lishid.openinv.event.OpenEvents;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class OpenPlayer extends BaseOpenPlayer {
|
||||
|
||||
protected OpenPlayer(CraftServer server, ServerPlayer entity, PlayerManager manager) {
|
||||
super(server, entity, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
if (OpenEvents.saveCancelled(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerPlayer player = this.getHandle();
|
||||
// See net.minecraft.world.level.storage.PlayerDataStorage#save(EntityHuman)
|
||||
try {
|
||||
PlayerDataStorage worldNBTStorage = player.server.getPlayerList().playerIo;
|
||||
|
||||
CompoundTag oldData = isOnline() ? null : worldNBTStorage.load(player.getName().getString(), player.getStringUUID()).orElse(null);
|
||||
CompoundTag playerData = getWritableTag(oldData);
|
||||
|
||||
playerData = player.saveWithoutId(playerData);
|
||||
|
||||
if (oldData != null) {
|
||||
// Revert certain special data values when offline.
|
||||
revertSpecialValues(playerData, oldData);
|
||||
}
|
||||
|
||||
Path playerDataDir = worldNBTStorage.getPlayerDir().toPath();
|
||||
Path tempFile = Files.createTempFile(playerDataDir, player.getStringUUID() + "-", ".dat");
|
||||
NbtIo.writeCompressed(playerData, tempFile);
|
||||
Path dataFile = playerDataDir.resolve(player.getStringUUID() + ".dat");
|
||||
Path backupFile = playerDataDir.resolve(player.getStringUUID() + ".dat_old");
|
||||
Util.safeReplaceFile(dataFile, tempFile, backupFile);
|
||||
} catch (Exception e) {
|
||||
LogUtils.getLogger().warn("Failed to save player data for {}: {}", player.getScoreboardName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.lishid.openinv.internal.paper1_21_5.player;
|
||||
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PlayerManager extends com.lishid.openinv.internal.paper1_21_8.player.PlayerManager {
|
||||
|
||||
public PlayerManager(@NotNull Logger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean loadData(@NotNull MinecraftServer server, @NotNull ServerPlayer player) {
|
||||
// See CraftPlayer#loadData
|
||||
CompoundTag loadedData = server.getPlayerList().playerIo.load(player).orElse(null);
|
||||
|
||||
if (loadedData == null) {
|
||||
// Exceptions with loading are logged.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read basic data into the player.
|
||||
player.load(loadedData);
|
||||
// Game type settings are also loaded separately.
|
||||
player.loadGameTypes(loadedData);
|
||||
|
||||
// World is not loaded by ServerPlayer#load(CompoundTag) on Paper.
|
||||
parseWorld(player, loadedData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void parseWorld(@NotNull ServerPlayer player, @NotNull CompoundTag loadedData) {
|
||||
// See PlayerList#placeNewPlayer
|
||||
World bukkitWorld;
|
||||
Optional<Long> msbs = loadedData.getLong("WorldUUIDMost");
|
||||
Optional<Long> lsbs = loadedData.getLong("WorldUUIDLeast");
|
||||
if (msbs.isPresent() && lsbs.isPresent()) {
|
||||
// Modern Bukkit world.
|
||||
bukkitWorld = Bukkit.getServer().getWorld(new UUID(msbs.get(), lsbs.get()));
|
||||
} else {
|
||||
Optional<String> worldName = loadedData.getString("world");
|
||||
if (worldName.isPresent()) {
|
||||
// Legacy Bukkit world.
|
||||
bukkitWorld = Bukkit.getServer().getWorld(worldName.get());
|
||||
} else {
|
||||
// Vanilla player data.
|
||||
DimensionType.parseLegacy(new Dynamic<>(NbtOps.INSTANCE, loadedData.get("Dimension")))
|
||||
.resultOrPartial(logger::warning)
|
||||
.map(player.server::getLevel)
|
||||
// If ServerLevel exists, set, otherwise move to spawn.
|
||||
.ifPresentOrElse(player::setServerLevel, () -> spawnInDefaultWorld(player.server, player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (bukkitWorld == null) {
|
||||
spawnInDefaultWorld(player.server, player);
|
||||
return;
|
||||
}
|
||||
player.setServerLevel(((CraftWorld) bukkitWorld).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Player inject(@NotNull Player player) {
|
||||
try {
|
||||
ServerPlayer nmsPlayer = getHandle(player);
|
||||
if (nmsPlayer.getBukkitEntity() instanceof OpenPlayer openPlayer) {
|
||||
return openPlayer;
|
||||
}
|
||||
injectPlayer(nmsPlayer.server, nmsPlayer);
|
||||
return nmsPlayer.getBukkitEntity();
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(
|
||||
java.util.logging.Level.WARNING,
|
||||
e,
|
||||
() -> "Unable to inject ServerPlayer, certain player data may be lost when saving!"
|
||||
);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void injectPlayer(@NotNull MinecraftServer server, @NotNull ServerPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitEntity.setAccessible(true);
|
||||
|
||||
bukkitEntity.set(player, new OpenPlayer(player.server.server, player, this));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
plugins {
|
||||
`openinv-base`
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy.capabilitiesResolution.withCapability("org.spigotmc:spigot-api") {
|
||||
val paper = candidates.firstOrNull {
|
||||
it.id.let { id ->
|
||||
id is ModuleComponentIdentifier && id.module == "paper-api"
|
||||
}
|
||||
}
|
||||
if (paper != null) {
|
||||
select(paper)
|
||||
}
|
||||
because("module is written for Paper servers")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
implementation(project(":openinvadaptercommon"))
|
||||
|
||||
paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT")
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.lishid.openinv.internal.paper1_21_8;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.internal.paper1_21_8.container.OpenInventory;
|
||||
import com.lishid.openinv.internal.paper1_21_8.player.PlayerManager;
|
||||
import com.lishid.openinv.util.lang.LanguageManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class InternalAccessor extends com.lishid.openinv.internal.common.InternalAccessor {
|
||||
|
||||
private final @NotNull PlayerManager manager;
|
||||
|
||||
public InternalAccessor(@NotNull Logger logger, @NotNull LanguageManager lang) {
|
||||
super(logger, lang);
|
||||
manager = new PlayerManager(logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerManager getPlayerManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ISpecialPlayerInventory createPlayerInventory(@NotNull Player player) {
|
||||
return new OpenInventory(player);
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.lishid.openinv.internal.paper1_21_8.container;
|
||||
|
||||
import com.lishid.openinv.internal.common.container.BaseOpenInventory;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OpenInventory extends BaseOpenInventory {
|
||||
|
||||
public OpenInventory(@NotNull Player bukkitPlayer) {
|
||||
super(bukkitPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component getTitle(@Nullable ServerPlayer viewer) {
|
||||
MutableComponent component = Component.empty();
|
||||
// Prefix for use with custom bitmap image fonts.
|
||||
if (owner.equals(viewer)) {
|
||||
component.append(
|
||||
Component.translatableWithFallback("openinv.container.inventory.self", "")
|
||||
.withStyle(style -> style
|
||||
.withFont(ResourceLocation.parse("openinv:font/inventory"))
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
} else {
|
||||
component.append(
|
||||
Component.translatableWithFallback("openinv.container.inventory.other", "")
|
||||
.withStyle(style -> style
|
||||
.withFont(ResourceLocation.parse("openinv:font/inventory"))
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
}
|
||||
// Normal title: "Inventory - OwnerName"
|
||||
component.append(Component.translatableWithFallback("openinv.container.inventory.prefix", "", owner.getName()))
|
||||
.append(Component.translatable("container.inventory"))
|
||||
.append(Component.translatableWithFallback("openinv.container.inventory.suffix", " - %s", owner.getName()));
|
||||
return component;
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.lishid.openinv.internal.paper1_21_8.player;
|
||||
|
||||
import com.lishid.openinv.event.OpenEvents;
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraft.world.level.storage.TagValueOutput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class OpenPlayer extends BaseOpenPlayer {
|
||||
|
||||
protected OpenPlayer(
|
||||
CraftServer server,
|
||||
ServerPlayer entity,
|
||||
PlayerManager manager
|
||||
) {
|
||||
super(server, entity, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
if (OpenEvents.saveCancelled(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerPlayer player = this.getHandle();
|
||||
Logger logger = LogUtils.getLogger();
|
||||
// See net.minecraft.world.level.storage.PlayerDataStorage#save(EntityHuman)
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), logger)) {
|
||||
PlayerDataStorage worldNBTStorage = server.getServer().getPlayerList().playerIo;
|
||||
|
||||
CompoundTag oldData = isOnline()
|
||||
? null
|
||||
: worldNBTStorage.load(player.getName().getString(), player.getStringUUID(), scopedCollector).orElse(null);
|
||||
CompoundTag playerData = getWritableTag(oldData);
|
||||
|
||||
ValueOutput valueOutput = TagValueOutput.createWrappingWithContext(scopedCollector, player.registryAccess(), playerData);
|
||||
player.saveWithoutId(valueOutput);
|
||||
|
||||
if (oldData != null) {
|
||||
// Revert certain special data values when offline.
|
||||
revertSpecialValues(playerData, oldData);
|
||||
}
|
||||
|
||||
Path playerDataDir = worldNBTStorage.getPlayerDir().toPath();
|
||||
Path tempFile = Files.createTempFile(playerDataDir, player.getStringUUID() + "-", ".dat");
|
||||
NbtIo.writeCompressed(playerData, tempFile);
|
||||
Path dataFile = playerDataDir.resolve(player.getStringUUID() + ".dat");
|
||||
Path backupFile = playerDataDir.resolve(player.getStringUUID() + ".dat_old");
|
||||
Util.safeReplaceFile(dataFile, tempFile, backupFile);
|
||||
} catch (Exception e) {
|
||||
LogUtils.getLogger().warn("Failed to save player data for {}: {}", player.getScoreboardName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.lishid.openinv.internal.paper1_21_8.player;
|
||||
|
||||
import com.lishid.openinv.internal.common.player.BaseOpenPlayer;
|
||||
import com.lishid.openinv.util.JulLoggerAdapter;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PlayerManager extends com.lishid.openinv.internal.common.player.PlayerManager {
|
||||
|
||||
public PlayerManager(@NotNull Logger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean loadData(@NotNull MinecraftServer server, @NotNull ServerPlayer player) {
|
||||
// See CraftPlayer#loadData
|
||||
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), new JulLoggerAdapter(logger))) {
|
||||
ValueInput loadedData = server.getPlayerList().playerIo.load(player, scopedCollector).orElse(null);
|
||||
|
||||
if (loadedData == null) {
|
||||
// Exceptions with loading are logged.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read basic data into the player.
|
||||
player.load(loadedData);
|
||||
// Game type settings are loaded separately.
|
||||
player.loadGameTypes(loadedData);
|
||||
|
||||
// World is not loaded by ServerPlayer#load(CompoundTag) on Paper.
|
||||
parseWorld(server, player, loadedData);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnInDefaultWorld(@NotNull MinecraftServer server, @NotNull ServerPlayer player) {
|
||||
ServerLevel level = server.getLevel(Level.OVERWORLD);
|
||||
if (level != null) {
|
||||
// Adjust player to default spawn (in keeping with Paper handling) when world not found.
|
||||
player.snapTo(player.adjustSpawnLocation(level, level.getSharedSpawnPos()).getBottomCenter(), level.getSharedSpawnAngle(), 0.0F);
|
||||
player.spawnIn(level);
|
||||
} else {
|
||||
logger.warning("Tried to load player with invalid world when no fallback was available!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void injectPlayer(@NotNull MinecraftServer server, @NotNull ServerPlayer player) throws IllegalAccessException {
|
||||
if (bukkitEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitEntity.setAccessible(true);
|
||||
|
||||
bukkitEntity.set(player, new OpenPlayer(server.server, player, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Player inject(@NotNull Player player) {
|
||||
try {
|
||||
ServerPlayer nmsPlayer = getHandle(player);
|
||||
if (nmsPlayer.getBukkitEntity() instanceof BaseOpenPlayer openPlayer) {
|
||||
return openPlayer;
|
||||
}
|
||||
MinecraftServer server = nmsPlayer.getServer();
|
||||
if (server == null) {
|
||||
if (!(Bukkit.getServer() instanceof CraftServer craftServer)) {
|
||||
logger.warning(() ->
|
||||
"Unable to inject ServerPlayer, certain player data may be lost when saving! Server is not a CraftServer: "
|
||||
+ Bukkit.getServer().getClass().getName());
|
||||
return player;
|
||||
}
|
||||
server = craftServer.getServer();
|
||||
}
|
||||
injectPlayer(server, nmsPlayer);
|
||||
return nmsPlayer.getBukkitEntity();
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(
|
||||
java.util.logging.Level.WARNING,
|
||||
e,
|
||||
() -> "Unable to inject ServerPlayer, certain player data may be lost when saving!"
|
||||
);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,9 @@ plugins {
|
||||
apply<SpigotSetup>()
|
||||
apply<SpigotReobf>()
|
||||
|
||||
val spigotVer = "1.21.5-R0.1-SNAPSHOT"
|
||||
val spigotVer = "1.21.10-R0.1-SNAPSHOT"
|
||||
// Used by common adapter to relocate Craftbukkit classes to a versioned package.
|
||||
rootProject.extra["craftbukkitPackage"] = "v1_21_R4"
|
||||
rootProject.extra["craftbukkitPackage"] = "v1_21_R6"
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy.capabilitiesResolution.withCapability("org.spigotmc:spigot-api") {
|
||||
|
||||
+6
-6
@@ -1,11 +1,11 @@
|
||||
package com.lishid.openinv.internal.reobf.container.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.lishid.openinv.internal.reobf.container.OpenInventory;
|
||||
import com.lishid.openinv.internal.reobf.container.BaseOpenInventory;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -15,13 +15,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OpenPlayerInventory extends CraftInventory implements PlayerInventory {
|
||||
|
||||
public OpenPlayerInventory(@NotNull OpenInventory inventory) {
|
||||
public OpenPlayerInventory(@NotNull BaseOpenInventory inventory) {
|
||||
super(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull OpenInventory getInventory() {
|
||||
return (OpenInventory) super.getInventory();
|
||||
public @NotNull BaseOpenInventory getInventory() {
|
||||
return (BaseOpenInventory) super.getInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.inventory.CraftItemStack;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
package com.lishid.openinv.internal.reobf.player;
|
||||
|
||||
import com.lishid.openinv.event.OpenEvents;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NumericTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraft.world.level.storage.TagValueOutput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.entity.CraftPlayer;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
public class OpenPlayer extends CraftPlayer {
|
||||
|
||||
/**
|
||||
* List of tags to always reset when saving.
|
||||
*
|
||||
* @see net.minecraft.world.entity.Entity#saveWithoutId(ValueOutput)
|
||||
* @see ServerPlayer#addAdditionalSaveData(ValueOutput)
|
||||
* @see net.minecraft.world.entity.player.Player#addAdditionalSaveData(ValueOutput)
|
||||
* @see net.minecraft.world.entity.LivingEntity#addAdditionalSaveData(ValueOutput)
|
||||
*/
|
||||
@Unmodifiable
|
||||
protected static final Set<String> RESET_TAGS = Set.of(
|
||||
// Entity#saveWithoutId(CompoundTag)
|
||||
"CustomName",
|
||||
"CustomNameVisible",
|
||||
"Silent",
|
||||
"NoGravity",
|
||||
"Glowing",
|
||||
"TicksFrozen",
|
||||
"HasVisualFire",
|
||||
"Tags",
|
||||
"Passengers",
|
||||
// ServerPlayer#addAdditionalSaveData(CompoundTag)
|
||||
// Intentional omissions to prevent mount loss: Attach, Entity, and RootVehicle
|
||||
"warden_spawn_tracker",
|
||||
"entered_nether_pos", // Replaces enteredNetherPosition
|
||||
"enteredNetherPosition",
|
||||
"respawn", // Replaces SpawnXyz fields as of 1.21.6
|
||||
"SpawnX",
|
||||
"SpawnY",
|
||||
"SpawnZ",
|
||||
"SpawnForced",
|
||||
"SpawnAngle",
|
||||
"SpawnDimension",
|
||||
"raid_omen_position",
|
||||
"ender_pearls",
|
||||
// Player#addAdditionalSaveData(CompoundTag)
|
||||
"ShoulderEntityLeft",
|
||||
"ShoulderEntityRight",
|
||||
"LastDeathLocation",
|
||||
"current_explosion_impact_pos",
|
||||
// LivingEntity#addAdditionalSaveData(CompoundTag)
|
||||
"active_effects",
|
||||
"sleeping_pos", // Replaces SleepingXyz fields as of 1.21.6
|
||||
"SleepingX",
|
||||
"SleepingY",
|
||||
"SleepingZ",
|
||||
"Brain",
|
||||
"last_hurt_by_player",
|
||||
"last_hurt_by_player_memory_time",
|
||||
"last_hurt_by_mob",
|
||||
"ticks_since_last_hurt_by_mob",
|
||||
"equipment",
|
||||
"locator_bar_icon"
|
||||
);
|
||||
|
||||
private final PlayerManager manager;
|
||||
|
||||
protected OpenPlayer(CraftServer server, ServerPlayer entity, PlayerManager manager) {
|
||||
super(server, entity);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
manager.loadData(getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
if (OpenEvents.saveCancelled(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerPlayer player = this.getHandle();
|
||||
Logger logger = LogUtils.getLogger();
|
||||
// See net.minecraft.world.level.storage.PlayerDataStorage#save(EntityHuman)
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), logger)) {
|
||||
PlayerDataStorage worldNBTStorage = server.getServer().getPlayerList().playerIo;
|
||||
|
||||
CompoundTag oldData = isOnline()
|
||||
? null
|
||||
: worldNBTStorage.load(player.nameAndId()).orElse(null);
|
||||
CompoundTag playerData = getWritableTag(oldData);
|
||||
|
||||
ValueOutput valueOutput = TagValueOutput.createWithContext(scopedCollector, player.registryAccess());
|
||||
Field tagValueOutputOutput = TagValueOutput.class.getDeclaredField("output");
|
||||
tagValueOutputOutput.setAccessible(true);
|
||||
CompoundTag newPlayerData = (CompoundTag) tagValueOutputOutput.get(valueOutput);
|
||||
// Add existing old data.
|
||||
newPlayerData.merge(playerData);
|
||||
playerData = newPlayerData;
|
||||
|
||||
player.saveWithoutId(valueOutput);
|
||||
|
||||
if (oldData != null) {
|
||||
// Revert certain special data values when offline.
|
||||
revertSpecialValues(playerData, oldData);
|
||||
}
|
||||
|
||||
Path playerDataDir = worldNBTStorage.getPlayerDir().toPath();
|
||||
Path tempFile = Files.createTempFile(playerDataDir, player.getStringUUID() + "-", ".dat");
|
||||
NbtIo.writeCompressed(playerData, tempFile);
|
||||
Path dataFile = playerDataDir.resolve(player.getStringUUID() + ".dat");
|
||||
Path backupFile = playerDataDir.resolve(player.getStringUUID() + ".dat_old");
|
||||
Util.safeReplaceFile(dataFile, tempFile, backupFile);
|
||||
} catch (Exception e) {
|
||||
LogUtils.getLogger().warn("Failed to save player data for {}: {}", player.getScoreboardName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("null -> new")
|
||||
protected @NotNull CompoundTag getWritableTag(@Nullable CompoundTag oldData) {
|
||||
if (oldData == null) {
|
||||
return new CompoundTag();
|
||||
}
|
||||
|
||||
// Copy old data. This is a deep clone, so operating on it should be safe.
|
||||
oldData = oldData.copy();
|
||||
|
||||
// Remove vanilla/server data that is not written every time.
|
||||
oldData.keySet().removeIf(
|
||||
key -> RESET_TAGS.contains(key)
|
||||
|| key.startsWith("Bukkit")
|
||||
|| (key.startsWith("Paper") && key.length() > 5)
|
||||
);
|
||||
|
||||
return oldData;
|
||||
}
|
||||
|
||||
protected void revertSpecialValues(@NotNull CompoundTag newData, @NotNull CompoundTag oldData) {
|
||||
// Revert automatic updates to play timestamps.
|
||||
copyValue(oldData, newData, "bukkit", "lastPlayed", NumericTag.class);
|
||||
copyValue(oldData, newData, "Paper", "LastSeen", NumericTag.class);
|
||||
copyValue(oldData, newData, "Paper", "LastLogin", NumericTag.class);
|
||||
}
|
||||
|
||||
private <T extends Tag> void copyValue(
|
||||
@NotNull CompoundTag source,
|
||||
@NotNull CompoundTag target,
|
||||
@NotNull String container,
|
||||
@NotNull String key,
|
||||
@SuppressWarnings("SameParameterValue") @NotNull Class<T> tagType
|
||||
) {
|
||||
CompoundTag oldContainer = getTag(source, container, CompoundTag.class);
|
||||
CompoundTag newContainer = getTag(target, container, CompoundTag.class);
|
||||
|
||||
// New container being null means the server implementation doesn't store this data.
|
||||
if (newContainer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If old tag exists, copy it to new location, removing otherwise.
|
||||
setTag(newContainer, key, getTag(oldContainer, key, tagType));
|
||||
}
|
||||
|
||||
private <T extends Tag> @Nullable T getTag(
|
||||
@Nullable CompoundTag container,
|
||||
@NotNull String key,
|
||||
@NotNull Class<T> dataType
|
||||
) {
|
||||
if (container == null) {
|
||||
return null;
|
||||
}
|
||||
Tag value = container.get(key);
|
||||
if (value == null || !dataType.isAssignableFrom(value.getClass())) {
|
||||
return null;
|
||||
}
|
||||
return dataType.cast(value);
|
||||
}
|
||||
|
||||
private <T extends Tag> void setTag(
|
||||
@NotNull CompoundTag container,
|
||||
@NotNull String key,
|
||||
@Nullable T data
|
||||
) {
|
||||
if (data == null) {
|
||||
container.remove(key);
|
||||
} else {
|
||||
container.put(key, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConnected(@Nullable ServerGamePacketListenerImpl connection) {
|
||||
return connection != null && !connection.isDisconnected();
|
||||
}
|
||||
|
||||
}
|
||||
+24
-15
@@ -3,6 +3,7 @@ package com.lishid.openinv.internal.reobf.player;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.reobf.container.OpenEnderChest;
|
||||
import com.lishid.openinv.internal.reobf.container.OpenInventory;
|
||||
import com.lishid.openinv.util.JulLoggerAdapter;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -12,16 +13,19 @@ import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ParticleStatus;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.ChatVisiblity;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.storage.TagValueInput;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_21_R4.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_21_R6.event.CraftEventFactory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -68,7 +72,11 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
|
||||
@Override
|
||||
public @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline) {
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
if (!(Bukkit.getServer() instanceof CraftServer craftServer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = craftServer.getServer();
|
||||
ServerLevel worldServer = server.getLevel(Level.OVERWORLD);
|
||||
|
||||
if (worldServer == null) {
|
||||
@@ -130,20 +138,21 @@ public class PlayerManager implements com.lishid.openinv.internal.PlayerManager
|
||||
|
||||
boolean loadData(@NotNull ServerPlayer player) {
|
||||
// See CraftPlayer#loadData
|
||||
CompoundTag loadedData = player.server.getPlayerList().playerIo.load(player).orElse(null);
|
||||
|
||||
if (loadedData == null) {
|
||||
// Exceptions with loading are logged by Mojang.
|
||||
return false;
|
||||
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), new JulLoggerAdapter(logger))) {
|
||||
CompoundTag loadedData = player.server.getPlayerList().playerIo.load(player.nameAndId()).orElse(null);
|
||||
|
||||
if (loadedData == null) {
|
||||
// Exceptions with loading are logged.
|
||||
return false;
|
||||
}
|
||||
|
||||
ValueInput valueInput = TagValueInput.create(scopedCollector, player.registryAccess(), loadedData);
|
||||
|
||||
// Read basic data into the player.
|
||||
player.load(valueInput);
|
||||
}
|
||||
|
||||
// Read basic data into the player.
|
||||
player.load(loadedData);
|
||||
// Also read "extra" data.
|
||||
player.readAdditionalSaveData(loadedData);
|
||||
// Game type settings are also loaded separately.
|
||||
player.loadGameTypes(loadedData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ dependencies {
|
||||
implementation(project(":openinvapi"))
|
||||
implementation(project(":openinvcommon"))
|
||||
implementation(project(":openinvadaptercommon"))
|
||||
implementation(project(":openinvadapterpaper1_21_8"))
|
||||
implementation(project(":openinvadapterpaper1_21_5"))
|
||||
implementation(project(":openinvadapterpaper1_21_4"))
|
||||
implementation(project(":openinvadapterpaper1_21_3"))
|
||||
implementation(project(":openinvadapterpaper1_21_1"))
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ClearInvCommand extends PlayerLookupCommand {
|
||||
@@ -44,6 +45,17 @@ public class ClearInvCommand extends PlayerLookupCommand {
|
||||
@Nullable String argument,
|
||||
boolean accessInv
|
||||
) {
|
||||
if (!Permissions.CLEAR_OTHER.hasPermission(sender)) {
|
||||
// If the sender does not have permissions to clear others, use self.
|
||||
if (sender instanceof Player player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
// Console can't target itself. Send error.
|
||||
lang.sendMessage(sender, "messages.error.permissionOpenOther");
|
||||
return null;
|
||||
}
|
||||
|
||||
// If argument is provided, use it.
|
||||
if (argument != null) {
|
||||
return argument;
|
||||
@@ -99,4 +111,18 @@ public class ClearInvCommand extends PlayerLookupCommand {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(
|
||||
@NotNull CommandSender sender,
|
||||
@NotNull Command command,
|
||||
@NotNull String label,
|
||||
@NotNull String[] args
|
||||
) {
|
||||
if (!Permissions.CLEAR_OTHER.hasPermission(sender)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return super.onTabComplete(sender, command, label, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class InternalAccessor {
|
||||
}
|
||||
|
||||
private @Nullable Accessor getAccessor(@NotNull Logger logger, @NotNull LanguageManager lang) {
|
||||
Version maxSupported = Version.of(1, 21, 5);
|
||||
Version maxSupported = Version.of(1, 21, 10);
|
||||
Version minSupported = Version.of(1, 21, 1);
|
||||
|
||||
// Ensure version is in supported range.
|
||||
@@ -84,9 +84,17 @@ public class InternalAccessor {
|
||||
}
|
||||
|
||||
// Paper or a Paper fork, can use Mojang-mapped internals.
|
||||
if (BukkitVersions.MINECRAFT.equals(maxSupported)) { // 1.21.5
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(maxSupported)
|
||||
&& BukkitVersions.MINECRAFT.greaterThanOrEqual(Version.of(1, 21, 9))) { // 1.21.9, 1.21.10
|
||||
return new com.lishid.openinv.internal.common.InternalAccessor(logger, lang);
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 8))
|
||||
&& BukkitVersions.MINECRAFT.greaterThanOrEqual(Version.of(1, 21, 6))) { // 1.21.6, 1.21.7, 1.21.8
|
||||
return new com.lishid.openinv.internal.paper1_21_8.InternalAccessor(logger, lang);
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.equals(Version.of(1, 21, 5))) { // 1.21.5
|
||||
return new com.lishid.openinv.internal.paper1_21_5.InternalAccessor(logger, lang);
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.equals(Version.of(1, 21, 4))) { // 1.21.4
|
||||
return new com.lishid.openinv.internal.paper1_21_4.InternalAccessor(logger, lang);
|
||||
}
|
||||
@@ -166,18 +174,39 @@ public class InternalAccessor {
|
||||
if (BukkitVersions.MINECRAFT.equals(Version.of(1, 20, 5))) { // 1.20.5
|
||||
return "Unsupported; upgrade to 1.20.6: https://github.com/Jikoo/OpenInv/releases/tag/5.1.2";
|
||||
}
|
||||
if (PAPER && BukkitVersions.MINECRAFT.greaterThanOrEqual(Version.of(1, 21, 1))) { // Paper 1.21.1-1.21.3
|
||||
return "https://github.com/Jikoo/OpenInv/releases";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21))) { // 1.20.4, 1.20.6, 1.21
|
||||
return "https://github.com/Jikoo/OpenInv/releases/tag/5.1.2";
|
||||
}
|
||||
if (!PAPER) {
|
||||
return getSpigotReleaseLink();
|
||||
}
|
||||
// Paper 1.21.1+
|
||||
return "https://github.com/Jikoo/OpenInv/releases";
|
||||
}
|
||||
|
||||
private String getSpigotReleaseLink() {
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 2))) {
|
||||
return "https://github.com/Jikoo/OpenInv/releases/tag/5.1.3";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 3))) {
|
||||
return "https://github.com/Jikoo/OpenInv/releases/tag/5.1.6";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 4))) {
|
||||
return "https://github.com/Jikoo/OpenInv/releases/tag/5.1.9";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 5))) {
|
||||
return "https://github.com/Jikoo/OpenInv/releases/tag/5.1.11";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 6))) {
|
||||
return "Unsupported; upgrade to 1.21.7: https://github.com/Jikoo/OpenInv/releases";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 8))) {
|
||||
return "https://github.com/Jikoo/OpenInv/releases/tag/5.1.13";
|
||||
}
|
||||
if (BukkitVersions.MINECRAFT.lessThanOrEqual(Version.of(1, 21, 9))) {
|
||||
return "Unsupported; upgrade to 1.21.10: https://github.com/Jikoo/OpenInv/releases";
|
||||
}
|
||||
|
||||
return "https://github.com/Jikoo/OpenInv/releases";
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -15,5 +15,6 @@
|
||||
"model": "minecraft:block/crafting_table"
|
||||
},
|
||||
"property": "minecraft:custom_model_data"
|
||||
}
|
||||
},
|
||||
"oversized_in_gui": true
|
||||
}
|
||||
+2
-1
@@ -15,5 +15,6 @@
|
||||
"model": "item/white_stained_glass_pane"
|
||||
},
|
||||
"property": "custom_model_data"
|
||||
}
|
||||
},
|
||||
"oversized_in_gui": true
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "Improve OpenInv's legibility",
|
||||
"pack_format": 55,
|
||||
"supported_formats": [ 34, 55 ]
|
||||
"min_format": 34,
|
||||
"max_format": [69, 0],
|
||||
"pack_format": 64,
|
||||
"supported_formats": [ 34, 69 ]
|
||||
},
|
||||
"overlays": {
|
||||
"entries": [
|
||||
{
|
||||
"formats": [ 44, 55 ],
|
||||
"min_format": 44,
|
||||
"max_format": [69, 0],
|
||||
"formats": [ 44, 69 ],
|
||||
"directory": "openinv_44"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@ if (!java.lang.Boolean.getBoolean("jitpack")) {
|
||||
|
||||
val internals = listOf(
|
||||
"common",
|
||||
"paper1_21_8",
|
||||
"paper1_21_5",
|
||||
"paper1_21_4",
|
||||
"paper1_21_3",
|
||||
"paper1_21_1",
|
||||
|
||||
Reference in new issue
Block a user