1.14 support, fixes #105
3 changed files with 75 additions and 12 deletions
18
pom.xml
18
pom.xml
|
@ -217,12 +217,18 @@
|
|||
<version>1.16.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap-Towny</artifactId>
|
||||
|
|
|
@ -1,18 +1,65 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.core.MainPlugin;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.server.v1_12_R1.EntityHuman.EnumChatVisibility;
|
||||
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.Predicate;
|
||||
|
||||
@UtilityClass
|
||||
public class VanillaUtils {
|
||||
public int getMCScoreIfChatOn(Player p, TBMCChatEvent e) {
|
||||
if (!(p instanceof CraftPlayer) || ((CraftPlayer) p).getHandle().getChatFlags() == EnumChatVisibility.FULL) // Only send if client allows chat
|
||||
try {
|
||||
if (isChatOn(p)) // Only send if client allows chat
|
||||
return e.getMCScore(p);
|
||||
else
|
||||
return -1;
|
||||
} catch (NoClassDefFoundError ex) {
|
||||
MainPlugin.Instance.getLogger().warning("Compatibility error, can't check if the chat is hidden by the player.");
|
||||
return e.getMCScore(p);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate<Player> isChatOn;
|
||||
|
||||
private boolean isChatOn(Player p) {
|
||||
try {
|
||||
if (isChatOn == null) {
|
||||
val cl = p.getClass();
|
||||
if (!cl.getSimpleName().contains("CraftPlayer")) return true; // p instanceof CraftPlayer
|
||||
val hm = cl.getMethod("getHandle");
|
||||
val handle = hm.invoke(p); //p.getHandle()
|
||||
val vpcl = handle.getClass();
|
||||
val gcfm = vpcl.getMethod("getChatFlags");
|
||||
Class<?> encl;
|
||||
try {
|
||||
encl = Class.forName(handle.getClass().getPackage().getName() + ".EnumChatVisibility");
|
||||
} catch (ClassNotFoundException e) {
|
||||
encl = Class.forName(handle.getClass().getPackage().getName() + ".EntityHuman$EnumChatVisibility");
|
||||
}
|
||||
val ff = encl.getField("FULL");
|
||||
val full = ff.get(null); // EnumChatVisibility.FULL
|
||||
isChatOn = pl -> {
|
||||
try {
|
||||
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
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
return isChatOn.test(p);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*private String version;
|
||||
|
@ -23,4 +70,13 @@ public class VanillaUtils {
|
|||
"org.bukkit.craftbukkit.v", "_R1").orElse("1_8").replace("_", "");
|
||||
return Short.parseShort(v);
|
||||
}*/
|
||||
|
||||
public String tellRaw(Player p, String json) {
|
||||
try {
|
||||
ChatComponentUtils.filterForDisplay(((CraftPlayer) p).getHandle(), //TODO: Reflection
|
||||
IChatBaseComponent.ChatSerializer.a(json), ((CraftPlayer) p).getHandle());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package buttondevteam.chat.components.towny;
|
||||
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
|
@ -51,8 +52,8 @@ public class TownyComponent extends Component<PluginMain> {
|
|||
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);
|
||||
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
|
||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
|
||||
ChatUtils.dispatchConsoleCommand(String.format(
|
||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue