-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 1.3.4: Merge pull request #24 from DiscordSRV/v1.3.x
- Hook into DiscordSRV if it's loaded late (fix #23) - Add bStats metrics - Add prefixed staff-chat messages - Improve debugging
- Loading branch information
Showing
6 changed files
with
165 additions
and
10 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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/rezzedup/discordsrv/staffchat/listeners/PlayerPrefixedMessageListener.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,51 @@ | ||
package com.rezzedup.discordsrv.staffchat.listeners; | ||
|
||
import com.rezzedup.discordsrv.staffchat.Permissions; | ||
import com.rezzedup.discordsrv.staffchat.StaffChatPlugin; | ||
import com.rezzedup.discordsrv.staffchat.util.Strings; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
|
||
@SuppressWarnings("unused") | ||
public class PlayerPrefixedMessageListener implements Listener | ||
{ | ||
private final StaffChatPlugin plugin; | ||
|
||
public PlayerPrefixedMessageListener(StaffChatPlugin plugin) { this.plugin = plugin; } | ||
|
||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) | ||
public void onPrefixedChat(AsyncPlayerChatEvent event) | ||
{ | ||
if (!plugin.getConfig().getBoolean("enable-prefixed-chat-messages", false)) { return; } | ||
|
||
Player player = event.getPlayer(); | ||
if (Permissions.ACCESS.denies(player)) { return; } | ||
|
||
String identifier = Strings.orEmpty(plugin.getConfig(), "prefixed-chat-identifier"); | ||
if (Strings.isEmptyOrNull(identifier)) | ||
{ | ||
plugin.debug(getClass()).log(event, () -> "Prefixed chat is enabled but identifier is undefined"); | ||
return; | ||
} | ||
|
||
String message = event.getMessage(); | ||
if (!message.startsWith(identifier)) { return; } | ||
|
||
String unprefixed = message.substring(identifier.length()).trim(); | ||
|
||
plugin.debug(getClass()).log(event, () -> | ||
"Sending prefixed chat from player(" + player.getName() + ") identified " + | ||
"by prefix(\"" + identifier + "\"): message(\"" + unprefixed + "\")" | ||
); | ||
|
||
event.setCancelled(true); // Cancel this message from getting sent to global chat. | ||
|
||
// Handle this on the main thread next tick. | ||
plugin.getServer().getScheduler().runTask(plugin, () -> | ||
plugin.submitMessageFromInGame(player, (Strings.isEmptyOrNull(unprefixed)) ? message : unprefixed) | ||
); | ||
} | ||
} |
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