mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
1 parent
44c58eeec4
commit
be5e10037b
3 files changed
+102
-19
No files matched your search
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package net.draycia.carbon.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||||
|
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
|
||||||
|
public class BukkitPlayerDeathListener implements Listener {
|
||||||
|
|
||||||
|
private final CarbonChat carbonChat;
|
||||||
|
private final PrimaryConfig primaryConfig;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public BukkitPlayerDeathListener(
|
||||||
|
final CarbonChat carbonChat,
|
||||||
|
final PrimaryConfig primaryConfig
|
||||||
|
) {
|
||||||
|
this.carbonChat = carbonChat;
|
||||||
|
this.primaryConfig = primaryConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDeath(final PlayerDeathEvent event) {
|
||||||
|
// Early exit in case "hide muted join / leave messages when muted" is disabled
|
||||||
|
if (!this.primaryConfig.hideMutedJoinLeaveQuit()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ComponentPlayerResult result = this.carbonChat.server().player(event.getEntity().getUniqueId()).join();
|
||||||
|
|
||||||
|
if (result.player() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CarbonPlayer player = result.player();
|
||||||
|
|
||||||
|
if (player.muted()) {
|
||||||
|
event.deathMessage(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+50
-19
@@ -4,7 +4,9 @@ import com.google.inject.Inject;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||||
import net.draycia.carbon.bukkit.util.BukkitCapabilities;
|
import net.draycia.carbon.bukkit.util.BukkitCapabilities;
|
||||||
|
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
@@ -15,40 +17,69 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class BukkitPlayerJoinListener implements Listener {
|
public class BukkitPlayerJoinListener implements Listener {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
private final PrimaryConfig primaryConfig;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BukkitPlayerJoinListener(final CarbonChat carbonChat) {
|
public BukkitPlayerJoinListener(
|
||||||
|
final CarbonChat carbonChat,
|
||||||
|
final PrimaryConfig primaryConfig
|
||||||
|
) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
this.primaryConfig = primaryConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerLogin(final PlayerJoinEvent event) {
|
public void onPlayerLogin(final PlayerJoinEvent event) {
|
||||||
this.carbonChat.server()
|
final ComponentPlayerResult result = this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
|
||||||
.player(event.getPlayer().getUniqueId()).thenAccept(result -> {
|
|
||||||
if (result.player() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CarbonPlayer player = result.player();
|
if (result.player() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) this.carbonChat, () -> {
|
final CarbonPlayer player = result.player();
|
||||||
if (player.hasCustomDisplayName()) {
|
|
||||||
player.displayName(player.displayName());
|
|
||||||
} else {
|
|
||||||
final @Nullable Component nickname = this.createDefaultNickname(player);
|
|
||||||
|
|
||||||
if (nickname != null) {
|
// Apply temporary and non temporary display names
|
||||||
player.temporaryDisplayName(nickname);
|
if (player.hasCustomDisplayName()) {
|
||||||
}
|
player.displayName(player.displayName());
|
||||||
}
|
} else {
|
||||||
});
|
final @Nullable Component nickname = this.createDefaultNickname(player);
|
||||||
});
|
|
||||||
|
if (nickname != null) {
|
||||||
|
player.temporaryDisplayName(nickname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't show join messages when muted
|
||||||
|
if (this.primaryConfig.hideMutedJoinLeaveQuit() && player.muted()) {
|
||||||
|
event.joinMessage(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
|
// Early exit in case "hide muted join / leave messages when muted" is disabled
|
||||||
|
if (!this.primaryConfig.hideMutedJoinLeaveQuit()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ComponentPlayerResult result = this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
|
||||||
|
|
||||||
|
if (result.player() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CarbonPlayer player = result.player();
|
||||||
|
|
||||||
|
// Don't show quit messages when muted
|
||||||
|
if (player.muted()) {
|
||||||
|
event.quitMessage(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable Component createDefaultNickname(final CarbonPlayer player) {
|
private @Nullable Component createDefaultNickname(final CarbonPlayer player) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public class PrimaryConfig {
|
|||||||
private final Key defaultChannel = Key.key("carbon", "basic");
|
private final Key defaultChannel = Key.key("carbon", "basic");
|
||||||
@Comment("The service that will be used to store and load player information.")
|
@Comment("The service that will be used to store and load player information.")
|
||||||
private final StorageType storageType = StorageType.JSON;
|
private final StorageType storageType = StorageType.JSON;
|
||||||
|
@Comment("Should we hide join/quit and death messages of muted players?")
|
||||||
|
private final boolean hideMutedJoinLeaveQuit = false;
|
||||||
|
|
||||||
public Locale defaultLocale() {
|
public Locale defaultLocale() {
|
||||||
return this.defaultLocale;
|
return this.defaultLocale;
|
||||||
@@ -30,6 +32,10 @@ public class PrimaryConfig {
|
|||||||
return this.storageType;
|
return this.storageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hideMutedJoinLeaveQuit() {
|
||||||
|
return this.hideMutedJoinLeaveQuit;
|
||||||
|
}
|
||||||
|
|
||||||
public enum StorageType {
|
public enum StorageType {
|
||||||
JSON,
|
JSON,
|
||||||
MYSQL,
|
MYSQL,
|
||||||
|
|||||||
Reference in new issue
Block a user