Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Island Level Compatibility Fix #716

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/com/wasteofplastic/askyblock/listeners/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,27 @@ public ChatListener(ASkyBlock plugin) {

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChat(final AsyncPlayerChatEvent event) {
// Team chat
if (Settings.teamChat && teamChatUsers.containsKey(event.getPlayer().getUniqueId())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: team chat");
// Cancel the event
event.setCancelled(true);
// Queue the sync task because you cannot use HashMaps asynchronously. Delaying to the next tick
// won't be a major issue for synch events either.
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
teamChat(event,event.getMessage());
}});
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onChatHigh(final AsyncPlayerChatEvent event) {
if (DEBUG)
plugin.getLogger().info("DEBUG: " + event.getEventName());

// Substitute variable - thread safe
String level = "";
if (playerLevels.containsKey(event.getPlayer().getUniqueId())) {
Expand All @@ -121,6 +140,7 @@ public void onChat(final AsyncPlayerChatEvent event) {
plugin.getLogger().info("DEBUG: getFormat = " + event.getFormat());
plugin.getLogger().info("DEBUG: getMessage = " + event.getMessage());
}

String format = event.getFormat();
if (!Settings.chatLevelPrefix.isEmpty()) {
format = format.replace(Settings.chatLevelPrefix, level);
Expand All @@ -134,25 +154,11 @@ public void onChat(final AsyncPlayerChatEvent event) {
}
format = format.replace(Settings.chatChallengeLevelPrefix, level);
if (DEBUG)
plugin.getLogger().info("DEBUG: format (challenge level sub) = " + format);
plugin.getLogger().info("DEBUG: format (challenge level sub) = " + format);
}
event.setFormat(format);
if (DEBUG)
plugin.getLogger().info("DEBUG: format set");
// Team chat
if (Settings.teamChat && teamChatUsers.containsKey(event.getPlayer().getUniqueId())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: team chat");
// Cancel the event
event.setCancelled(true);
// Queue the sync task because you cannot use HashMaps asynchronously. Delaying to the next tick
// won't be a major issue for synch events either.
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
teamChat(event,event.getMessage());
}});
}
}

private void teamChat(final AsyncPlayerChatEvent event, String message) {
Expand Down