forked from public-mirrors/HuskSync
Paper plugin support, save player itemsToKeep rather than drops if not empty (#179)
* Paper plugin support, save itemsToKeep if present, close #172 * Fixup wrong packages, suppress a warning * Update docs, add settings for death saving, reorganise config slightly * Improve default server name lookup * docs: Add note on Unsupported Versions * docs: Minor Sync Modes tweaksfeat/data-edit-commands
parent
6d9e68a65b
commit
7db3ed678f
@ -0,0 +1,10 @@
|
|||||||
|
This plugin does not support the following software-Minecraft version combinations. The plugin will fail to load if you attempt to run it with these versions. Apologies for the inconvenience.
|
||||||
|
|
||||||
|
## Incompatibility table
|
||||||
|
| Minecraft Versions | Server Software | Notes |
|
||||||
|
|--------------------|-------------------------------------------|----------------------------------------|
|
||||||
|
| 1.19.4 | Only: `Purpur, Pufferfish`† | Older Paper builds also not supported. |
|
||||||
|
| 1.19.3 | Only: `Paper, Purpur, Pufferfish`† | Upgrade to 1.19.4 or use Spigot |
|
||||||
|
| below 1.16.5 | _All_ | Upgrade to 1.16.5 |
|
||||||
|
|
||||||
|
†Further downstream forks of this server software are also affected.
|
@ -0,0 +1,41 @@
|
|||||||
|
dependencies {
|
||||||
|
implementation project(':bukkit')
|
||||||
|
compileOnly project(':common')
|
||||||
|
|
||||||
|
compileOnly 'io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
dependencies {
|
||||||
|
exclude(dependency('com.mojang:brigadier'))
|
||||||
|
}
|
||||||
|
|
||||||
|
relocate 'org.apache.commons.io', 'net.william278.husksync.libraries.commons.io'
|
||||||
|
relocate 'org.apache.commons.text', 'net.william278.husksync.libraries.commons.text'
|
||||||
|
relocate 'org.apache.commons.lang3', 'net.william278.husksync.libraries.commons.lang3'
|
||||||
|
relocate 'com.google.gson', 'net.william278.husksync.libraries.gson'
|
||||||
|
relocate 'org.json', 'net.william278.husksync.libraries.json'
|
||||||
|
relocate 'com.fatboyindustrial', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'de.themoep', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'net.kyori', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'org.jetbrains', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'org.intellij', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'com.zaxxer', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'dev.dejvokep', 'net.william278.husksync.libraries'
|
||||||
|
relocate 'net.william278.desertwell', 'net.william278.husksync.libraries.desertwell'
|
||||||
|
relocate 'net.william278.paginedown', 'net.william278.husksync.libraries.paginedown'
|
||||||
|
relocate 'net.william278.mapdataapi', 'net.william278.husksync.libraries.mapdataapi'
|
||||||
|
relocate 'net.william278.andjam', 'net.william278.husksync.libraries.andjam'
|
||||||
|
relocate 'net.querz', 'net.william278.husksync.libraries.nbtparser'
|
||||||
|
relocate 'net.roxeez', 'net.william278.husksync.libraries'
|
||||||
|
|
||||||
|
relocate 'me.lucko.commodore', 'net.william278.husksync.libraries.commodore'
|
||||||
|
relocate 'net.byteflux.libby', 'net.william278.husksync.libraries.libby'
|
||||||
|
relocate 'org.bstats', 'net.william278.husksync.libraries.bstats'
|
||||||
|
relocate 'dev.triumphteam.gui', 'net.william278.husksync.libraries.triumphgui'
|
||||||
|
relocate 'net.william278.mpdbconverter', 'net.william278.husksync.libraries.mpdbconverter'
|
||||||
|
relocate 'net.william278.hslmigrator', 'net.william278.husksync.libraries.hslconverter'
|
||||||
|
relocate 'net.william278.annotaml', 'net.william278.husksync.libraries.annotaml'
|
||||||
|
relocate 'space.arim.morepaperlib', 'net.william278.husksync.libraries.paperlib'
|
||||||
|
relocate 'de.tr7zw.changeme.nbtapi', 'net.william278.husksync.libraries.nbtapi'
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of HuskSync, licensed under the Apache License 2.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.husksync;
|
||||||
|
|
||||||
|
import net.william278.husksync.listener.BukkitEventListener;
|
||||||
|
import net.william278.husksync.listener.PaperEventListener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class PaperHuskSync extends BukkitHuskSync {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected BukkitEventListener createEventListener() {
|
||||||
|
return new PaperEventListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of HuskSync, licensed under the Apache License 2.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.husksync;
|
||||||
|
|
||||||
|
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
|
||||||
|
import io.papermc.paper.plugin.loader.PluginLoader;
|
||||||
|
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
|
||||||
|
import net.william278.annotaml.Annotaml;
|
||||||
|
import net.william278.annotaml.YamlFile;
|
||||||
|
import net.william278.annotaml.YamlKey;
|
||||||
|
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||||
|
import org.eclipse.aether.graph.Dependency;
|
||||||
|
import org.eclipse.aether.repository.RemoteRepository;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@SuppressWarnings({"UnstableApiUsage", "unused"})
|
||||||
|
public class PaperHuskSyncLoader implements PluginLoader {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) {
|
||||||
|
MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||||
|
|
||||||
|
resolveLibraries(classpathBuilder).stream()
|
||||||
|
.map(DefaultArtifact::new)
|
||||||
|
.forEach(artifact -> resolver.addDependency(new Dependency(artifact, null)));
|
||||||
|
resolver.addRepository(new RemoteRepository.Builder(
|
||||||
|
"maven", "default", "https://repo.maven.apache.org/maven2/"
|
||||||
|
).build());
|
||||||
|
|
||||||
|
classpathBuilder.addLibrary(resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<String> resolveLibraries(@NotNull PluginClasspathBuilder classpathBuilder) {
|
||||||
|
try (InputStream input = getLibraryListFile()) {
|
||||||
|
return Annotaml.create(PaperLibraries.class, Objects.requireNonNull(input)).get().libraries;
|
||||||
|
} catch (Exception e) {
|
||||||
|
classpathBuilder.getContext().getLogger().error("Failed to resolve libraries", e);
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static InputStream getLibraryListFile() {
|
||||||
|
return PaperHuskSyncLoader.class.getClassLoader().getResourceAsStream("paper-libraries.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@YamlFile(header = "Dependencies for HuskSync on Paper")
|
||||||
|
public static class PaperLibraries {
|
||||||
|
|
||||||
|
@YamlKey("libraries")
|
||||||
|
private List<String> libraries;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private PaperLibraries() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of HuskSync, licensed under the Apache License 2.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.husksync.listener;
|
||||||
|
|
||||||
|
import net.william278.husksync.BukkitHuskSync;
|
||||||
|
import net.william278.husksync.data.BukkitData;
|
||||||
|
import net.william278.husksync.user.BukkitUser;
|
||||||
|
import net.william278.husksync.user.OnlineUser;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PaperEventListener extends BukkitEventListener {
|
||||||
|
|
||||||
|
public PaperEventListener(@NotNull BukkitHuskSync plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handlePlayerDeath(@NotNull PlayerDeathEvent event) {
|
||||||
|
// If the player is locked or the plugin disabling, clear their drops
|
||||||
|
final OnlineUser user = BukkitUser.adapt(event.getEntity(), plugin);
|
||||||
|
if (cancelPlayerEvent(user.getUuid())) {
|
||||||
|
event.getDrops().clear();
|
||||||
|
event.getItemsToKeep().clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle saving player data snapshots on death
|
||||||
|
if (!plugin.getSettings().doSaveOnDeath()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paper - support saving the player's items to keep if enabled
|
||||||
|
final int maxInventorySize = BukkitData.Items.Inventory.INVENTORY_SLOT_COUNT;
|
||||||
|
final List<ItemStack> itemsToSave = switch (plugin.getSettings().getDeathItemsMode()) {
|
||||||
|
case DROPS -> event.getDrops();
|
||||||
|
case ITEMS_TO_KEEP -> event.getItemsToKeep();
|
||||||
|
};
|
||||||
|
if (itemsToSave.size() > maxInventorySize) {
|
||||||
|
itemsToSave.subList(maxInventorySize, itemsToSave.size()).clear();
|
||||||
|
}
|
||||||
|
super.saveOnPlayerDeath(user, BukkitData.Items.ItemArray.adapt(itemsToSave));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
# Dependencies for HuskSync on Paper
|
||||||
|
libraries:
|
||||||
|
- 'redis.clients:jedis:${jedis_version}'
|
||||||
|
- 'com.mysql:mysql-connector-j:${mysql_driver_version}'
|
||||||
|
- 'org.mariadb.jdbc:mariadb-java-client:${mariadb_driver_version}'
|
||||||
|
- 'org.xerial.snappy:snappy-java:${snappy_version}'
|
@ -0,0 +1,18 @@
|
|||||||
|
name: 'HuskSync'
|
||||||
|
description: '${description}'
|
||||||
|
author: 'William278'
|
||||||
|
website: 'https://william278.net/'
|
||||||
|
main: 'net.william278.husksync.PaperHuskSync'
|
||||||
|
loader: 'net.william278.husksync.PaperHuskSyncLoader'
|
||||||
|
version: '${version}'
|
||||||
|
api-version: '1.19'
|
||||||
|
dependencies:
|
||||||
|
server:
|
||||||
|
MysqlPlayerDataBridge:
|
||||||
|
required: false
|
||||||
|
load: BEFORE
|
||||||
|
join-classpath: true
|
||||||
|
Plan:
|
||||||
|
required: false
|
||||||
|
load: BEFORE
|
||||||
|
join-classpath: true
|
@ -1,3 +1,4 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation project(path: ':bukkit', configuration: 'shadow')
|
implementation project(path: ':bukkit', configuration: 'shadow')
|
||||||
|
runtimeOnly project(path: ':paper')
|
||||||
}
|
}
|
Loading…
Reference in New Issue