-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make displays more modular, add actionbar support
- Loading branch information
1 parent
0e38db2
commit c91d4da
Showing
9 changed files
with
228 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/triassic/geyserdebuginfo/display/Display.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.triassic.geyserdebuginfo.display; | ||
|
||
import lombok.Getter; | ||
import org.geysermc.geyser.session.GeyserSession; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public abstract class Display { | ||
|
||
protected final GeyserSession session; | ||
@Getter | ||
protected final DisplayType displayType; | ||
protected final long refreshInterval; | ||
private ScheduledFuture<?> updateTask; | ||
|
||
public Display(@NotNull GeyserSession session, @NotNull DisplayType displayType, long refreshInterval) { | ||
this.session = session; | ||
this.displayType = displayType; | ||
this.refreshInterval = refreshInterval; | ||
} | ||
|
||
/** | ||
* Updates the display with the given text. | ||
*/ | ||
public abstract void updateDisplay(); | ||
|
||
/** | ||
* Removes the display from the player. | ||
*/ | ||
public abstract void removeDisplay(); | ||
|
||
/** | ||
* Starts the scheduled update task for the display. | ||
*/ | ||
public void startUpdating(ScheduledExecutorService executor) { | ||
updateTask = executor.scheduleAtFixedRate(this::updateDisplay, 0, refreshInterval, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
/** | ||
* Stops the scheduled update task for the display. | ||
*/ | ||
public void stopUpdating() { | ||
if (updateTask != null) { | ||
updateTask.cancel(false); | ||
updateTask = null; | ||
} | ||
removeDisplay(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/triassic/geyserdebuginfo/display/DisplayType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.triassic.geyserdebuginfo.display; | ||
|
||
public enum DisplayType { | ||
ACTIONBAR, | ||
BOSSBAR | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/triassic/geyserdebuginfo/display/displays/ActionBarDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.triassic.geyserdebuginfo.display.displays; | ||
|
||
import com.triassic.geyserdebuginfo.GeyserDebugInfo; | ||
import com.triassic.geyserdebuginfo.display.Display; | ||
import com.triassic.geyserdebuginfo.display.DisplayType; | ||
import com.triassic.geyserdebuginfo.manager.PlaceholderManager; | ||
import org.cloudburstmc.protocol.bedrock.packet.SetTitlePacket; | ||
import org.geysermc.geyser.session.GeyserSession; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ActionBarDisplay extends Display { | ||
|
||
private final GeyserDebugInfo instance; | ||
private final SetTitlePacket titlePacket; | ||
private final PlaceholderManager placeholderManager; | ||
|
||
public ActionBarDisplay(GeyserDebugInfo instance, @NotNull GeyserSession session) { | ||
super(session, DisplayType.ACTIONBAR, 50); | ||
|
||
this.titlePacket = new SetTitlePacket(); | ||
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR); | ||
titlePacket.setFadeOutTime(1); | ||
titlePacket.setStayTime(2); | ||
titlePacket.setXuid(""); | ||
titlePacket.setPlatformOnlineId(""); | ||
|
||
this.instance = instance; | ||
this.placeholderManager = instance.getPlaceholderManager(); | ||
} | ||
|
||
@Override | ||
public void updateDisplay() { | ||
titlePacket.setText(placeholderManager.setPlaceholders(session, instance.getConfig().getDisplay().getActionBar().getText())); | ||
session.sendUpstreamPacket(titlePacket); | ||
} | ||
|
||
@Override | ||
public void removeDisplay() { | ||
titlePacket.setText(""); | ||
session.sendUpstreamPacket(titlePacket); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/triassic/geyserdebuginfo/display/displays/BossBarDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.triassic.geyserdebuginfo.display.displays; | ||
|
||
import com.triassic.geyserdebuginfo.GeyserDebugInfo; | ||
import com.triassic.geyserdebuginfo.display.Display; | ||
import com.triassic.geyserdebuginfo.display.DisplayType; | ||
import com.triassic.geyserdebuginfo.manager.PlaceholderManager; | ||
import net.kyori.adventure.text.Component; | ||
import org.geysermc.geyser.session.GeyserSession; | ||
import org.geysermc.geyser.session.cache.BossBar; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class BossBarDisplay extends Display { | ||
|
||
private final GeyserDebugInfo instance; | ||
private final BossBar bossBar; | ||
private final PlaceholderManager placeholderManager; | ||
|
||
public BossBarDisplay(GeyserDebugInfo instance, @NotNull GeyserSession session, long entityId) { | ||
super(session, DisplayType.BOSSBAR, 50); | ||
this.bossBar = new BossBar(session, entityId, Component.empty(), 1.0f, 1, 0, 0); | ||
session.getEntityCache().addBossBar(session.playerUuid(), bossBar); | ||
|
||
this.instance = instance; | ||
this.placeholderManager = instance.getPlaceholderManager(); | ||
} | ||
|
||
@Override | ||
public void updateDisplay() { | ||
List<String> displayFormat = instance.getConfig().getDisplay().getBossBar().getText(); | ||
String displayText = displayFormat.stream() | ||
.map(line -> placeholderManager.setPlaceholders(session, line)) | ||
.collect(Collectors.joining("\n")); | ||
|
||
bossBar.updateTitle(Component.text(displayText)); | ||
} | ||
|
||
@Override | ||
public void removeDisplay() { | ||
bossBar.removeBossBar(); | ||
} | ||
} |
19 changes: 4 additions & 15 deletions
19
src/main/java/com/triassic/geyserdebuginfo/listener/PlayerJoinListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,36 @@ | ||
package com.triassic.geyserdebuginfo.listener; | ||
|
||
import com.triassic.geyserdebuginfo.GeyserDebugInfo; | ||
import com.triassic.geyserdebuginfo.manager.BossBarManager; | ||
import com.triassic.geyserdebuginfo.manager.PlayerDataManager; | ||
import org.geysermc.event.subscribe.Subscribe; | ||
import org.geysermc.geyser.api.event.bedrock.SessionDisconnectEvent; | ||
import org.geysermc.geyser.api.event.bedrock.SessionJoinEvent; | ||
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; | ||
import org.geysermc.geyser.session.GeyserSession; | ||
|
||
/** | ||
* This class is responsible for listening for player connection events. | ||
*/ | ||
public class PlayerJoinListener { | ||
|
||
private final BossBarManager bossBarManager; | ||
private final PlayerDataManager playerDataManager; | ||
|
||
public PlayerJoinListener( | ||
final GeyserDebugInfo instance | ||
) { | ||
this.bossBarManager = instance.getBossBarManager(); | ||
this.playerDataManager = instance.getPlayerDataManager(); | ||
} | ||
|
||
/** | ||
* Called when a player joins. | ||
*/ | ||
@Subscribe | ||
public void onJoin(final SessionJoinEvent event) { | ||
final GeyserSession session = (GeyserSession) event.connection(); | ||
final SessionPlayerEntity player = session.getPlayerEntity(); | ||
|
||
if (playerDataManager.isF3Enabled(player.getUuid())) | ||
bossBarManager.createBossBar(player); | ||
if (playerDataManager.isF3Enabled(player.getUuid())) { | ||
// TODO: Re-implement this. | ||
} | ||
} | ||
|
||
/** | ||
* Called when a player disconnects. | ||
*/ | ||
@Subscribe | ||
public void onDisconnect(final SessionDisconnectEvent event) { | ||
final GeyserSession session = (GeyserSession) event.connection(); | ||
bossBarManager.removeBossBar(session.getPlayerEntity(), false); | ||
// TODO: Remove Bossbar | ||
} | ||
} |
87 changes: 0 additions & 87 deletions
87
src/main/java/com/triassic/geyserdebuginfo/manager/BossBarManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.