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>
|
<id>Essentials</id>
|
||||||
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<!-- <repository>
|
||||||
<id>Minigames</id>
|
<id>Minigames</id>
|
||||||
<url>http://maven.addstar.com.au/artifactory/release</url>
|
<url>http://maven.addstar.com.au/artifactory/release</url>
|
||||||
</repository>
|
</repository> -->
|
||||||
<!-- <repository>
|
<!-- <repository>
|
||||||
<id>vault-repo</id>
|
<id>vault-repo</id>
|
||||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
<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.Sound;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Objective;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -165,32 +164,28 @@ public class ChatProcessing {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!channel.isGlobal()) {
|
if (!channel.isGlobal()) {
|
||||||
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
String senderGroup = e.getGroupID(sender);
|
||||||
int score = -1;
|
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()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
final int mcScore;
|
final String group;
|
||||||
if (player != null
|
if (player != null
|
||||||
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
&& 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
|
else
|
||||||
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
group = VanillaUtils.getGroupIfChatOn(p, e);
|
||||||
obj.getScore(p.getName())
|
if (group != null)
|
||||||
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
VanillaUtils.tellRaw(p, jsonstr);
|
||||||
? score = mcScore : mcScore);
|
else if (tc != null) tc.handleSpies(channel, p);
|
||||||
}
|
//Only sends if didn't send normally
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
ChatUtils.dispatchConsoleCommand(String.format("tellraw @a %s", jsonstr), true);
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
VanillaUtils.tellRaw(p, jsonstr);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
||||||
sender.sendMessage("§cAn error occured while sending the message.");
|
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.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
|
||||||
|
|
||||||
public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15.
|
public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15.
|
||||||
// A user, which flair isn't obtainable:
|
// 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 PluginMain Instance;
|
||||||
public static ConsoleCommandSender Console;
|
public static ConsoleCommandSender Console;
|
||||||
|
|
||||||
public static Scoreboard SB;
|
|
||||||
|
|
||||||
public ConfigData<String> notificationSound() {
|
public ConfigData<String> notificationSound() {
|
||||||
return getIConfig().getData("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
|
MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler
|
||||||
Console = this.getServer().getConsoleSender();
|
Console = this.getServer().getConsoleSender();
|
||||||
|
|
||||||
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
|
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
|
||||||
Component.registerComponent(this, new TownyComponent());
|
Component.registerComponent(this, new TownyComponent());
|
||||||
|
|
||||||
|
|
|
@ -4,25 +4,22 @@ import buttondevteam.core.MainPlugin;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import lombok.val;
|
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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class VanillaUtils {
|
public class VanillaUtils {
|
||||||
public int getMCScoreIfChatOn(Player p, TBMCChatEvent e) {
|
public String getGroupIfChatOn(Player p, TBMCChatEvent e) {
|
||||||
try {
|
try {
|
||||||
if (isChatOn(p)) // Only send if client allows chat
|
if (isChatOn(p)) // Only send if client allows chat
|
||||||
return e.getMCScore(p);
|
return e.getGroupID(p);
|
||||||
else
|
else
|
||||||
return -1;
|
return null;
|
||||||
} catch (NoClassDefFoundError ex) {
|
} catch (NoClassDefFoundError ex) {
|
||||||
MainPlugin.Instance.getLogger().warning("Compatibility error, can't check if the chat is hidden by the player.");
|
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
|
val full = ff.get(null); // EnumChatVisibility.FULL
|
||||||
isChatOn = pl -> {
|
isChatOn = pl -> {
|
||||||
try {
|
try {
|
||||||
|
if (notCraftPlayer(pl.getClass())) return true; //Need to check each time
|
||||||
val ph = hm.invoke(pl); //pl.getHandle()
|
val ph = hm.invoke(pl); //pl.getHandle()
|
||||||
val flags = gcfm.invoke(ph); //handle.getChatFlags()
|
val flags = gcfm.invoke(ph); //handle.getChatFlags()
|
||||||
return flags == full; //TODO: It's only checked if not global
|
return flags == full; //TODO: It's only checked if not global
|
||||||
|
@ -72,14 +70,15 @@ public class VanillaUtils {
|
||||||
return Short.parseShort(v);
|
return Short.parseShort(v);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
private BiConsumer<Player, String> tellRaw;
|
private BiPredicate<Player, String> tellRaw;
|
||||||
|
|
||||||
public boolean tellRaw(Player p, String json) {
|
public boolean tellRaw(Player p, String json) {
|
||||||
try {
|
try {
|
||||||
|
if (tellRaw == null) {
|
||||||
val pcl = p.getClass();
|
val pcl = p.getClass();
|
||||||
if (notCraftPlayer(pcl)) return false;
|
if (notCraftPlayer(pcl)) return false;
|
||||||
val hm = pcl.getMethod("getHandle");
|
val hm = pcl.getMethod("getHandle");
|
||||||
val handle = hm.invoke(p); ;
|
val handle = hm.invoke(p);
|
||||||
val nms = handle.getClass().getPackage().getName();
|
val nms = handle.getClass().getPackage().getName();
|
||||||
val chatcompcl = Class.forName(nms + ".IChatBaseComponent");
|
val chatcompcl = Class.forName(nms + ".IChatBaseComponent");
|
||||||
val sendmsg = handle.getClass().getMethod("sendMessage", chatcompcl);
|
val sendmsg = handle.getClass().getMethod("sendMessage", chatcompcl);
|
||||||
|
@ -87,19 +86,33 @@ public class VanillaUtils {
|
||||||
val ccucl = Class.forName(nms + ".ChatComponentUtils");
|
val ccucl = Class.forName(nms + ".ChatComponentUtils");
|
||||||
val iclcl = Class.forName(nms + ".ICommandListener");
|
val iclcl = Class.forName(nms + ".ICommandListener");
|
||||||
val encl = Class.forName(nms + ".Entity");
|
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 cscl = Class.forName(chatcompcl.getName() + "$ChatSerializer");
|
||||||
val am = cscl.getMethod("a", String.class);
|
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
|
tellRaw = (pl, jsonStr) -> {
|
||||||
.filterForDisplay(((CraftPlayer) p).getHandle(),
|
if (notCraftPlayer(pl.getClass())) return false;
|
||||||
IChatBaseComponent.ChatSerializer.a(json), ((CraftPlayer) p).getHandle()));
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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;
|
package buttondevteam.chat.components.towny;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatUtils;
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.chat.VanillaUtils;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -48,12 +49,20 @@ public class TownyComponent extends Component<PluginMain> {
|
||||||
TownyAnnouncer.setdown();
|
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)) {
|
if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) {
|
||||||
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
||||||
String jsonstr = toJson.apply(json);
|
jsonstr = toJson.apply(json);
|
||||||
ChatUtils.dispatchConsoleCommand(String.format(
|
}
|
||||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr), true);
|
}
|
||||||
|
|
||||||
|
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.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.core.component.channel.ChatChannelRegisterEvent;
|
|
||||||
import buttondevteam.core.component.channel.ChatRoom;
|
import buttondevteam.core.component.channel.ChatRoom;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
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
|
@EventHandler
|
||||||
public void onNickChange(NickChangeEvent e) {
|
public void onNickChange(NickChangeEvent e) {
|
||||||
String nick = e.getValue();
|
String nick = e.getValue();
|
||||||
|
|
Loading…
Reference in a new issue