Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-04 23:30:17 +01:00
Add an option for actionbar hit cooldown (#2006)
Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com>
Dieser Commit ist enthalten in:
Ursprung
aa5c3c30e1
Commit
fb18a6493a
@ -187,7 +187,7 @@ public class GeyserConnector {
|
||||
|
||||
defaultAuthType = AuthType.getByName(config.getRemote().getAuthType());
|
||||
|
||||
CooldownUtils.setShowCooldown(config.isShowCooldown());
|
||||
CooldownUtils.setShowCooldown(config.getShowCooldown());
|
||||
DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
|
||||
SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls();
|
||||
|
||||
|
@ -73,7 +73,7 @@ public interface GeyserConfiguration {
|
||||
|
||||
boolean isAllowThirdPartyEars();
|
||||
|
||||
boolean isShowCooldown();
|
||||
String getShowCooldown();
|
||||
|
||||
boolean isShowCoordinates();
|
||||
|
||||
|
@ -95,7 +95,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
|
||||
private boolean allowThirdPartyCapes = true;
|
||||
|
||||
@JsonProperty("show-cooldown")
|
||||
private boolean showCooldown = true;
|
||||
private String showCooldown = "title";
|
||||
|
||||
@JsonProperty("show-coordinates")
|
||||
private boolean showCoordinates = true;
|
||||
|
@ -26,6 +26,7 @@
|
||||
package org.geysermc.connector.utils;
|
||||
|
||||
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -35,10 +36,10 @@ import java.util.concurrent.TimeUnit;
|
||||
* Much of the work here is from the wonderful folks from ViaRewind: https://github.com/ViaVersion/ViaRewind
|
||||
*/
|
||||
public class CooldownUtils {
|
||||
private static boolean SHOW_COOLDOWN;
|
||||
private static CooldownType SHOW_COOLDOWN;
|
||||
|
||||
public static void setShowCooldown(boolean showCooldown) {
|
||||
SHOW_COOLDOWN = showCooldown;
|
||||
public static void setShowCooldown(String showCooldown) {
|
||||
SHOW_COOLDOWN = CooldownType.getByName(showCooldown);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,7 +47,7 @@ public class CooldownUtils {
|
||||
* @param session GeyserSession
|
||||
*/
|
||||
public static void sendCooldown(GeyserSession session) {
|
||||
if (!SHOW_COOLDOWN) return;
|
||||
if (SHOW_COOLDOWN == CooldownType.DISABLED) return;
|
||||
if (session.getAttackSpeed() == 0.0 || session.getAttackSpeed() > 20) return; // 0.0 usually happens on login and causes issues with visuals; anything above 20 means a plugin like OldCombatMechanics is being used
|
||||
// Needs to be sent or no subtitle packet is recognized by the client
|
||||
SetTitlePacket titlePacket = new SetTitlePacket();
|
||||
@ -67,7 +68,11 @@ public class CooldownUtils {
|
||||
if (session.isClosed()) return; // Don't run scheduled tasks if the client left
|
||||
if (lastHitTime != session.getLastHitTime()) return; // Means another cooldown has started so there's no need to continue this one
|
||||
SetTitlePacket titlePacket = new SetTitlePacket();
|
||||
if (SHOW_COOLDOWN == CooldownType.ACTIONBAR) {
|
||||
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
|
||||
} else {
|
||||
titlePacket.setType(SetTitlePacket.Type.SUBTITLE);
|
||||
}
|
||||
titlePacket.setText(getTitle(session));
|
||||
titlePacket.setFadeInTime(0);
|
||||
titlePacket.setFadeOutTime(5);
|
||||
@ -77,7 +82,11 @@ public class CooldownUtils {
|
||||
session.getConnector().getGeneralThreadPool().schedule(() -> computeCooldown(session, lastHitTime), 50, TimeUnit.MILLISECONDS); // Updated per tick. 1000 divided by 20 ticks equals 50
|
||||
} else {
|
||||
SetTitlePacket removeTitlePacket = new SetTitlePacket();
|
||||
if (SHOW_COOLDOWN == CooldownType.ACTIONBAR) {
|
||||
removeTitlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
|
||||
} else {
|
||||
removeTitlePacket.setType(SetTitlePacket.Type.SUBTITLE);
|
||||
}
|
||||
removeTitlePacket.setText(" ");
|
||||
session.sendUpstreamPacket(removeTitlePacket);
|
||||
}
|
||||
@ -114,4 +123,33 @@ public class CooldownUtils {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Getter
|
||||
public enum CooldownType {
|
||||
TITLE,
|
||||
ACTIONBAR,
|
||||
DISABLED;
|
||||
|
||||
public static final CooldownType[] VALUES = values();
|
||||
|
||||
/**
|
||||
* Convert the CooldownType string (from config) to the enum, TITLE on fail
|
||||
*
|
||||
* @param name CooldownType string
|
||||
*
|
||||
* @return The converted CooldownType
|
||||
*/
|
||||
public static CooldownType getByName(String name) {
|
||||
if (name.equalsIgnoreCase("true")) { // Backwards config compatibility
|
||||
return CooldownType.TITLE;
|
||||
}
|
||||
|
||||
for (CooldownType type : VALUES) {
|
||||
if (type.name().equalsIgnoreCase(name)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return DISABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,8 @@ allow-third-party-capes: true
|
||||
allow-third-party-ears: false
|
||||
|
||||
# Allow a fake cooldown indicator to be sent. Bedrock players do not see a cooldown as they still use 1.8 combat
|
||||
show-cooldown: true
|
||||
# Can be title, actionbar or false
|
||||
show-cooldown: title
|
||||
|
||||
# Controls if coordinates are shown to players.
|
||||
show-coordinates: true
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 216e9008678a761b3885808f4f3d43000404381b
|
||||
Subproject commit 2ce794e21a0212865059e7551db893c28843620a
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren