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

Actionbar Fix #717

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Expand Down
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
6 changes: 4 additions & 2 deletions src/com/wasteofplastic/askyblock/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;

import com.wasteofplastic.askyblock.ASkyBlock;
import com.wasteofplastic.askyblock.Settings;
import com.wasteofplastic.askyblock.nms.NMSAbstraction;
Expand Down Expand Up @@ -509,8 +512,7 @@ public static void sendEnterExit(Player player, String message) {
sendMessage(player, message);
return;
}
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
"minecraft:title " + player.getName() + " actionbar {\"text\":\"" + ChatColor.stripColor(message) + "\"}");
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', message)));
}

/**
Expand Down