1.14 support, fixes #105
6 changed files with 305 additions and 300 deletions
4
pom.xml
4
pom.xml
|
@ -155,10 +155,10 @@
|
|||
<id>Essentials</id>
|
||||
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<!-- <repository>
|
||||
<id>Minigames</id>
|
||||
<url>http://maven.addstar.com.au/artifactory/release</url>
|
||||
</repository>
|
||||
</repository> -->
|
||||
<!-- <repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
@ -165,32 +164,28 @@ public class ChatProcessing {
|
|||
|
||||
try {
|
||||
if (!channel.isGlobal()) {
|
||||
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
||||
int score = -1;
|
||||
String senderGroup = e.getGroupID(sender);
|
||||
if (senderGroup == null) { // Never send messages to score below 0
|
||||
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
||||
return true;
|
||||
}
|
||||
val tc = ComponentManager.getIfEnabled(TownyComponent.class);
|
||||
if (tc != null) tc.handleSpiesInit(channel, json, ChatProcessing::toJson);
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
final int mcScore;
|
||||
final String group;
|
||||
if (player != null
|
||||
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
||||
mcScore = -1; // Don't send the message to them
|
||||
group = null; // Don't send the message to them
|
||||
else
|
||||
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
||||
obj.getScore(p.getName())
|
||||
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
||||
? score = mcScore : mcScore);
|
||||
}
|
||||
if (score == -1) // Even if the player object isn't null, it may not be in OnlinePlayers
|
||||
score = e.getMCScore(sender);
|
||||
if (score < 0) // Never send messages to score below 0
|
||||
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
||||
else {
|
||||
ChatUtils.dispatchConsoleCommand(
|
||||
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
|
||||
score, jsonstr), true);
|
||||
val tc = ComponentManager.getIfEnabled(TownyComponent.class);
|
||||
if (tc != null) tc.handleSpies(channel, json, ChatProcessing::toJson);
|
||||
group = VanillaUtils.getGroupIfChatOn(p, e);
|
||||
if (group != null)
|
||||
VanillaUtils.tellRaw(p, jsonstr);
|
||||
else if (tc != null) tc.handleSpies(channel, p);
|
||||
//Only sends if didn't send normally
|
||||
}
|
||||
} else
|
||||
ChatUtils.dispatchConsoleCommand(String.format("tellraw @a %s", jsonstr), true);
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
VanillaUtils.tellRaw(p, jsonstr);
|
||||
} catch (Exception ex) {
|
||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
||||
sender.sendMessage("§cAn error occured while sending the message.");
|
||||
|
|
|
@ -29,7 +29,6 @@ import net.milkbowl.vault.permission.Permission;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15.
|
||||
// A user, which flair isn't obtainable:
|
||||
|
@ -37,8 +36,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
|
|||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console;
|
||||
|
||||
public static Scoreboard SB;
|
||||
|
||||
public ConfigData<String> notificationSound() {
|
||||
return getIConfig().getData("notificationSound", "");
|
||||
}
|
||||
|
@ -58,8 +55,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
|
|||
MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler
|
||||
Console = this.getServer().getConsoleSender();
|
||||
|
||||
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
|
||||
Component.registerComponent(this, new TownyComponent());
|
||||
|
||||
|
|
|
@ -4,25 +4,22 @@ import buttondevteam.core.MainPlugin;
|
|||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.val;
|
||||
import net.minecraft.server.v1_12_R1.ChatComponentUtils;
|
||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@UtilityClass
|
||||
public class VanillaUtils {
|
||||
public int getMCScoreIfChatOn(Player p, TBMCChatEvent e) {
|
||||
public String getGroupIfChatOn(Player p, TBMCChatEvent e) {
|
||||
try {
|
||||
if (isChatOn(p)) // Only send if client allows chat
|
||||
return e.getMCScore(p);
|
||||
return e.getGroupID(p);
|
||||
else
|
||||
return -1;
|
||||
return null;
|
||||
} catch (NoClassDefFoundError ex) {
|
||||
MainPlugin.Instance.getLogger().warning("Compatibility error, can't check if the chat is hidden by the player.");
|
||||
return e.getMCScore(p);
|
||||
return e.getGroupID(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +44,7 @@ public class VanillaUtils {
|
|||
val full = ff.get(null); // EnumChatVisibility.FULL
|
||||
isChatOn = pl -> {
|
||||
try {
|
||||
if (notCraftPlayer(pl.getClass())) return true; //Need to check each time
|
||||
val ph = hm.invoke(pl); //pl.getHandle()
|
||||
val flags = gcfm.invoke(ph); //handle.getChatFlags()
|
||||
return flags == full; //TODO: It's only checked if not global
|
||||
|
@ -72,14 +70,15 @@ public class VanillaUtils {
|
|||
return Short.parseShort(v);
|
||||
}*/
|
||||
|
||||
private BiConsumer<Player, String> tellRaw;
|
||||
private BiPredicate<Player, String> tellRaw;
|
||||
|
||||
public boolean tellRaw(Player p, String json) {
|
||||
try {
|
||||
if (tellRaw == null) {
|
||||
val pcl = p.getClass();
|
||||
if (notCraftPlayer(pcl)) return false;
|
||||
val hm = pcl.getMethod("getHandle");
|
||||
val handle = hm.invoke(p); ;
|
||||
val handle = hm.invoke(p);
|
||||
val nms = handle.getClass().getPackage().getName();
|
||||
val chatcompcl = Class.forName(nms + ".IChatBaseComponent");
|
||||
val sendmsg = handle.getClass().getMethod("sendMessage", chatcompcl);
|
||||
|
@ -87,19 +86,33 @@ public class VanillaUtils {
|
|||
val ccucl = Class.forName(nms + ".ChatComponentUtils");
|
||||
val iclcl = Class.forName(nms + ".ICommandListener");
|
||||
val encl = Class.forName(nms + ".Entity");
|
||||
val ffdm = ccucl.getMethod("filterForDisplay", iclcl, chatcompcl, encl);
|
||||
//val ffdm = ccucl.getMethod("filterForDisplay", iclcl, chatcompcl, encl);
|
||||
|
||||
val cscl = Class.forName(chatcompcl.getName() + "$ChatSerializer");
|
||||
val am = cscl.getMethod("a", String.class);
|
||||
val deserialized = am.invoke(null, json);
|
||||
val filtered = ffdm.invoke(null, handle, deserialized, handle); //TODO: Use BiConsumer
|
||||
sendmsg.invoke(handle, filtered);
|
||||
|
||||
((CraftPlayer) p).getHandle().sendMessage(ChatComponentUtils
|
||||
.filterForDisplay(((CraftPlayer) p).getHandle(),
|
||||
IChatBaseComponent.ChatSerializer.a(json), ((CraftPlayer) p).getHandle()));
|
||||
tellRaw = (pl, jsonStr) -> {
|
||||
if (notCraftPlayer(pl.getClass())) return false;
|
||||
try {
|
||||
val hhandle = hm.invoke(pl);
|
||||
val deserialized = am.invoke(null, jsonStr);
|
||||
//val filtered = ffdm.invoke(null, hhandle, deserialized, hhandle);
|
||||
sendmsg.invoke(hhandle, deserialized);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*((CraftPlayer) p).getHandle().sendMessage(ChatComponentUtils
|
||||
.filterForDisplay(((CraftPlayer) p).getHandle(),
|
||||
IChatBaseComponent.ChatSerializer.a(json), ((CraftPlayer) p).getHandle()));*/
|
||||
return tellRaw.test(p, json);
|
||||
} catch (Exception e) {
|
||||
PluginMain.Instance.getLogger().warning("Could not use tellRaw: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package buttondevteam.chat.components.towny;
|
||||
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.VanillaUtils;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -48,12 +49,20 @@ public class TownyComponent extends Component<PluginMain> {
|
|||
TownyAnnouncer.setdown();
|
||||
}
|
||||
|
||||
public void handleSpies(Channel channel, TellrawPart json, Function<TellrawPart, String> toJson) {
|
||||
public void handleSpiesInit(Channel channel, TellrawPart json, Function<TellrawPart, String> toJson) {
|
||||
if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) {
|
||||
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
||||
String jsonstr = toJson.apply(json);
|
||||
ChatUtils.dispatchConsoleCommand(String.format(
|
||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr), true);
|
||||
jsonstr = toJson.apply(json);
|
||||
}
|
||||
}
|
||||
|
||||
private String jsonstr;
|
||||
|
||||
public void handleSpies(Channel channel, Player p) {
|
||||
if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) {
|
||||
if (Optional.ofNullable(TU.getResidentMap().get(p.getName().toLowerCase()))
|
||||
.filter(r -> r.hasMode("spy")).isPresent())
|
||||
VanillaUtils.tellRaw(p, jsonstr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import buttondevteam.chat.components.flair.FlairComponent;
|
|||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.core.component.channel.ChatChannelRegisterEvent;
|
||||
import buttondevteam.core.component.channel.ChatRoom;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
|
@ -178,12 +177,6 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChannelRegistered(ChatChannelRegisterEvent e) {
|
||||
if (!e.getChannel().isGlobal() && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet
|
||||
PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNickChange(NickChangeEvent e) {
|
||||
String nick = e.getValue();
|
||||
|
|
Loading…
Reference in a new issue