-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# HealhName | ||
# HealthName | ||
|
||
### Description | ||
|
||
|
40 changes: 40 additions & 0 deletions
40
src/main/java/com/github/games647/healthname/ConnectionListener.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,40 @@ | ||
package com.github.games647.healthname; | ||
|
||
import com.github.games647.healthname.HealthName; | ||
import java.util.Optional; | ||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.network.ClientConnectionEvent; | ||
import org.spongepowered.api.scoreboard.Team; | ||
import org.spongepowered.api.text.Text; | ||
|
||
public class ConnectionListener { | ||
|
||
private final HealthName plugin; | ||
|
||
public ConnectionListener(HealthName plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Listener | ||
public void onJoin(ClientConnectionEvent.Join joinEvent) { | ||
Player player = joinEvent.getTargetEntity(); | ||
//everyone should have a global scoreboard to see the health from others | ||
if (plugin.getConfig().isNametagHealth() || plugin.getConfig().isBelowNameHealth()) { | ||
//don't override the old scoreboard if the feature isn't needed | ||
player.setScoreboard(plugin.getGlobalScoreboard()); | ||
} | ||
} | ||
|
||
@Listener | ||
public void onQuit(ClientConnectionEvent.Disconnect disconnectEvent) { | ||
String playerName = disconnectEvent.getTargetEntity().getName(); | ||
//Clean up scoreboard in order to prevent to big ones | ||
plugin.getGlobalScoreboard().removeScores(Text.of(playerName)); | ||
Optional<Team> optionalTeam = plugin.getGlobalScoreboard().getTeam(playerName); | ||
if (optionalTeam.isPresent()) { | ||
Team team = optionalTeam.get(); | ||
team.unregister(); | ||
} | ||
} | ||
} |
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