9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-23 08:39:19 +00:00

feat: add ProtocolLib support for deeper-level packet cancellation (#274)

* feat: add support for ProtocolLib packet-level state cancelling

* refactor: move commands to event listener, document ProtocolLib support

* docs: make Setup less claustrophobic

* fix: remove `@Getter` on `PlayerPacketAdapter`

* build: add missing license headers

* fix: inaccessible method on Paper

* test: add ProtocolLib to network spin test

* fix: whoops I targeted the wrong packets

* fix: bad command disabled check logic

* fix: final protocollib adjustments
This commit is contained in:
William
2024-04-10 17:09:53 +01:00
committed by GitHub
parent 4dfbc0e32b
commit 2f5ddf6164
14 changed files with 308 additions and 120 deletions

View File

@@ -57,7 +57,7 @@ public class Locales {
Map<String, String> locales = Maps.newTreeMap();
/**
* Returns a raw, un-formatted locale loaded from the locales file
* Returns a raw, unformatted locale loaded from the locale file
*
* @param localeId String identifier of the locale, corresponding to a key in the file
* @return An {@link Optional} containing the locale corresponding to the id, if it exists

View File

@@ -75,6 +75,9 @@ public class Settings {
@Comment({"Whether to enable the Player Analytics hook.", "Docs: https://william278.net/docs/husksync/plan-hook"})
private boolean enablePlanHook = true;
@Comment("Whether to cancel game event packets directly when handling locked players if ProtocolLib is installed")
private boolean cancelPackets = true;
// Database settings
@Comment("Database settings")

View File

@@ -28,7 +28,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static net.william278.husksync.config.Settings.SynchronizationSettings.SaveOnDeathSettings;
@@ -104,15 +103,6 @@ public abstract class EventListener {
plugin.getDataSyncer().saveData(user, snapshot);
}
/**
* Determine whether a player event should be canceled
*
* @param userUuid The UUID of the user to check
* @return Whether the event should be canceled
*/
protected final boolean cancelPlayerEvent(@NotNull UUID userUuid) {
return plugin.isDisabling() || plugin.isLocked(userUuid);
}
/**
* Handle the plugin disabling

View File

@@ -0,0 +1,57 @@
/*
* 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.HuskSync;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
/**
* Interface for doing stuff with locked users or when the plugin is disabled
*/
public interface LockedHandler {
/**
* Get if a command should be disabled while the user is locked
*/
default boolean isCommandDisabled(@NotNull String label) {
final List<String> blocked = getPlugin().getSettings().getSynchronization().getBlacklistedCommandsWhileLocked();
return blocked.contains("*") || blocked.contains(label.toLowerCase(Locale.ENGLISH));
}
/**
* Determine whether a player event should be canceled
*
* @param userUuid The UUID of the user to check
* @return Whether the event should be canceled
*/
default boolean cancelPlayerEvent(@NotNull UUID userUuid) {
return getPlugin().isDisabling() || getPlugin().isLocked(userUuid);
}
@NotNull
@ApiStatus.Internal
HuskSync getPlugin();
}