3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +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:
ImDaBigBoss 2021-04-01 06:06:01 +02:00 committet von GitHub
Ursprung aa5c3c30e1
Commit fb18a6493a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 50 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -187,7 +187,7 @@ public class GeyserConnector {
defaultAuthType = AuthType.getByName(config.getRemote().getAuthType()); 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 DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls(); SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls();

Datei anzeigen

@ -73,7 +73,7 @@ public interface GeyserConfiguration {
boolean isAllowThirdPartyEars(); boolean isAllowThirdPartyEars();
boolean isShowCooldown(); String getShowCooldown();
boolean isShowCoordinates(); boolean isShowCoordinates();

Datei anzeigen

@ -95,7 +95,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
private boolean allowThirdPartyCapes = true; private boolean allowThirdPartyCapes = true;
@JsonProperty("show-cooldown") @JsonProperty("show-cooldown")
private boolean showCooldown = true; private String showCooldown = "title";
@JsonProperty("show-coordinates") @JsonProperty("show-coordinates")
private boolean showCoordinates = true; private boolean showCoordinates = true;

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket; import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import lombok.Getter;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import java.util.concurrent.TimeUnit; 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 * Much of the work here is from the wonderful folks from ViaRewind: https://github.com/ViaVersion/ViaRewind
*/ */
public class CooldownUtils { public class CooldownUtils {
private static boolean SHOW_COOLDOWN; private static CooldownType SHOW_COOLDOWN;
public static void setShowCooldown(boolean showCooldown) { public static void setShowCooldown(String showCooldown) {
SHOW_COOLDOWN = showCooldown; SHOW_COOLDOWN = CooldownType.getByName(showCooldown);
} }
/** /**
@ -46,7 +47,7 @@ public class CooldownUtils {
* @param session GeyserSession * @param session GeyserSession
*/ */
public static void sendCooldown(GeyserSession session) { 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 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 // Needs to be sent or no subtitle packet is recognized by the client
SetTitlePacket titlePacket = new SetTitlePacket(); 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 (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 if (lastHitTime != session.getLastHitTime()) return; // Means another cooldown has started so there's no need to continue this one
SetTitlePacket titlePacket = new SetTitlePacket(); SetTitlePacket titlePacket = new SetTitlePacket();
if (SHOW_COOLDOWN == CooldownType.ACTIONBAR) {
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
} else {
titlePacket.setType(SetTitlePacket.Type.SUBTITLE); titlePacket.setType(SetTitlePacket.Type.SUBTITLE);
}
titlePacket.setText(getTitle(session)); titlePacket.setText(getTitle(session));
titlePacket.setFadeInTime(0); titlePacket.setFadeInTime(0);
titlePacket.setFadeOutTime(5); 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 session.getConnector().getGeneralThreadPool().schedule(() -> computeCooldown(session, lastHitTime), 50, TimeUnit.MILLISECONDS); // Updated per tick. 1000 divided by 20 ticks equals 50
} else { } else {
SetTitlePacket removeTitlePacket = new SetTitlePacket(); SetTitlePacket removeTitlePacket = new SetTitlePacket();
if (SHOW_COOLDOWN == CooldownType.ACTIONBAR) {
removeTitlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
} else {
removeTitlePacket.setType(SetTitlePacket.Type.SUBTITLE); removeTitlePacket.setType(SetTitlePacket.Type.SUBTITLE);
}
removeTitlePacket.setText(" "); removeTitlePacket.setText(" ");
session.sendUpstreamPacket(removeTitlePacket); session.sendUpstreamPacket(removeTitlePacket);
} }
@ -114,4 +123,33 @@ public class CooldownUtils {
} }
return builder.toString(); 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;
}
}
} }

Datei anzeigen

@ -112,7 +112,8 @@ allow-third-party-capes: true
allow-third-party-ears: false 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 # 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. # Controls if coordinates are shown to players.
show-coordinates: true show-coordinates: true

@ -1 +1 @@
Subproject commit 216e9008678a761b3885808f4f3d43000404381b Subproject commit 2ce794e21a0212865059e7551db893c28843620a