3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 15:00:09 +01:00

Add armor toggle patch for Bukkit (#3210)

Dieser Commit ist enthalten in:
Camotoy 2023-02-03 11:02:22 -05:00 committet von GitHub
Ursprung 93654b8eaf
Commit 734bc9e88c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 78 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -458,4 +458,6 @@ public interface ViaVersionConfig {
boolean cache1_17Light(); boolean cache1_17Light();
@Nullable String chatTypeFormat(String translationKey); @Nullable String chatTypeFormat(String translationKey);
boolean isArmorToggleFix();
} }

Datei anzeigen

@ -0,0 +1,56 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2023 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.bukkit.listeners.protocol1_19_4To1_19_3;
import com.viaversion.viaversion.ViaVersionPlugin;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
public final class ArmorToggleListener extends ViaBukkitListener {
public ArmorToggleListener(ViaVersionPlugin plugin) {
super(plugin, Protocol1_19_4To1_19_3.class);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void itemUse(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (!isOnPipe(player)) return;
final ItemStack item = event.getItem();
if (item == null) {
return;
}
final EquipmentSlot equipmentSlot = item.getType().getEquipmentSlot();
// Name comparison for OFF_HAND so 1.8 doesn't complain
if (equipmentSlot != EquipmentSlot.HAND && !equipmentSlot.name().equals("OFF_HAND")) {
final ItemStack armor = player.getInventory().getItem(equipmentSlot);
// If two pieces of armor are equal, the client will do nothing.
if (armor != null && armor.getType() != Material.AIR && !armor.equals(item)) {
player.updateInventory();
}
}
}
}

Datei anzeigen

@ -33,6 +33,7 @@ public class BukkitViaConfig extends AbstractViaConfig {
private boolean hitboxFix1_9; private boolean hitboxFix1_9;
private boolean hitboxFix1_14; private boolean hitboxFix1_14;
private String blockConnectionMethod; private String blockConnectionMethod;
private boolean armorToggleFix;
public BukkitViaConfig() { public BukkitViaConfig() {
super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml")); super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml"));
@ -47,6 +48,7 @@ public class BukkitViaConfig extends AbstractViaConfig {
hitboxFix1_9 = getBoolean("change-1_9-hitbox", false); hitboxFix1_9 = getBoolean("change-1_9-hitbox", false);
hitboxFix1_14 = getBoolean("change-1_14-hitbox", false); hitboxFix1_14 = getBoolean("change-1_14-hitbox", false);
blockConnectionMethod = getString("blockconnection-method", "packet"); blockConnectionMethod = getString("blockconnection-method", "packet");
armorToggleFix = getBoolean("armor-toggle-fix", true);
} }
@Override @Override
@ -78,6 +80,11 @@ public class BukkitViaConfig extends AbstractViaConfig {
return blockConnectionMethod; return blockConnectionMethod;
} }
@Override
public boolean isArmorToggleFix() {
return armorToggleFix;
}
@Override @Override
public List<String> getUnsupportedOptions() { public List<String> getUnsupportedOptions() {
return UNSUPPORTED; return UNSUPPORTED;

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.bukkit.listeners.JoinListener;
import com.viaversion.viaversion.bukkit.listeners.UpdateListener; import com.viaversion.viaversion.bukkit.listeners.UpdateListener;
import com.viaversion.viaversion.bukkit.listeners.multiversion.PlayerSneakListener; import com.viaversion.viaversion.bukkit.listeners.multiversion.PlayerSneakListener;
import com.viaversion.viaversion.bukkit.listeners.protocol1_15to1_14_4.EntityToggleGlideListener; import com.viaversion.viaversion.bukkit.listeners.protocol1_15to1_14_4.EntityToggleGlideListener;
import com.viaversion.viaversion.bukkit.listeners.protocol1_19_4To1_19_3.ArmorToggleListener;
import com.viaversion.viaversion.bukkit.listeners.protocol1_19to1_18_2.BlockBreakListener; import com.viaversion.viaversion.bukkit.listeners.protocol1_19to1_18_2.BlockBreakListener;
import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.ArmorListener; import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.ArmorListener;
import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.BlockListener; import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.BlockListener;
@ -142,6 +143,10 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
} }
if (serverProtocolVersion < ProtocolVersion.v1_19_4.getVersion() && plugin.getConf().isArmorToggleFix()) {
storeListener(new ArmorToggleListener(plugin)).register();
}
/* Providers */ /* Providers */
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) { if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());

Datei anzeigen

@ -533,4 +533,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public @Nullable String chatTypeFormat(final String translationKey) { public @Nullable String chatTypeFormat(final String translationKey) {
return chatTypeFormats.get(translationKey); return chatTypeFormats.get(translationKey);
} }
@Override
public boolean isArmorToggleFix() {
return false;
}
} }

Datei anzeigen

@ -172,6 +172,9 @@ chat-types-1_19:
chat.type.team.text: "%s <%s> %s" chat.type.team.text: "%s <%s> %s"
chat.type.emote: "* %s %s" chat.type.emote: "* %s %s"
# #
# Force-update 1.19.4+ player's inventory when they try to swap armor in a pre-occupied slot.
armor-toggle-fix: true
#
#----------------------------------------------------------# #----------------------------------------------------------#
# 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS # # 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS #
#----------------------------------------------------------# #----------------------------------------------------------#