Use internal Essentials instance.

Drops the usage of Towny's Essentials instance.
This commit is contained in:
LlmDl committed 2022-12-19 19:06:41 -06:00
1 parent be073a1c49
commit 7b932e2310
5 files changed
+37 -23

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit</groupId> <groupId>com.palmergames.bukkit</groupId>
<artifactId>TownyChat</artifactId> <artifactId>TownyChat</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.99</version> <version>0.100</version>
<licenses> <licenses>
<license> <license>
+2
View File
@@ -430,3 +430,5 @@ v0.99:
- On the off chance you have put unparse-able placeholders into your chatconfig.yml you will be made aware of them in your log. - On the off chance you have put unparse-able placeholders into your chatconfig.yml you will be made aware of them in your log.
- This new system should be able to let TownyChat format your chat properly when this occurs. - This new system should be able to let TownyChat format your chat properly when this occurs.
- Update min. Towny version to 0.98.4.0. - Update min. Towny version to 0.98.4.0.
v0.100:
- Use internal Essentials object instead of the one found in Towny.
+22 -1
View File
@@ -1,5 +1,6 @@
package com.palmergames.bukkit.TownyChat; package com.palmergames.bukkit.TownyChat;
import com.earth2me.essentials.Essentials;
import com.palmergames.bukkit.TownyChat.Command.ChannelCommand; import com.palmergames.bukkit.TownyChat.Command.ChannelCommand;
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand; import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand; import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand;
@@ -52,6 +53,7 @@ public class Chat extends JavaPlugin {
private static Chat chat = null; private static Chat chat = null;
private Towny towny = null; private Towny towny = null;
private DynmapAPI dynMap = null; private DynmapAPI dynMap = null;
private Essentials essentials = null;
private static Version requiredTownyVersion = Version.fromString("0.98.4.0"); private static Version requiredTownyVersion = Version.fromString("0.98.4.0");
public static boolean usingPlaceholderAPI = false; public static boolean usingPlaceholderAPI = false;
@@ -168,6 +170,11 @@ public class Chat extends JavaPlugin {
usingEssentialsDiscord = true; usingEssentialsDiscord = true;
} }
test = pm.getPlugin("Essentials");
if (test != null) {
this.essentials = (Essentials) test;
}
} }
public void registerEvents() { public void registerEvents() {
@@ -241,8 +248,22 @@ public class Chat extends JavaPlugin {
return dynMap; return dynMap;
} }
public boolean isUsingEssentials() {
return essentials != null;
}
public Essentials getEssentials() {
return essentials;
}
public boolean isEssentialsMuted(Player player) {
if (!isUsingEssentials())
return false;
return EssentialsIntegration.isMuted(player);
}
public boolean isIgnoredByEssentials(Player sender, Player player) { public boolean isIgnoredByEssentials(Player sender, Player player) {
if (!getTowny().isEssentials()) if (!isUsingEssentials())
return false; return false;
return EssentialsIntegration.ignoredByEssentials(sender, player); return EssentialsIntegration.ignoredByEssentials(sender, player);
} }
@@ -7,7 +7,6 @@ import com.palmergames.bukkit.TownyChat.channels.channelTypes;
import com.palmergames.bukkit.TownyChat.config.ChatSettings; import com.palmergames.bukkit.TownyChat.config.ChatSettings;
import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Translatable; import com.palmergames.bukkit.towny.object.Translatable;
import com.palmergames.bukkit.towny.object.metadata.StringDataField; import com.palmergames.bukkit.towny.object.metadata.StringDataField;
@@ -172,16 +171,10 @@ public class TownyChatPlayerListener implements Listener {
* @return true if muted by Essentials. * @return true if muted by Essentials.
*/ */
private boolean isEssentialsMuted(Player player) { private boolean isEssentialsMuted(Player player) {
if (!plugin.getTowny().isEssentials()) // Check if essentials has this player muted.
return false; if (plugin.isEssentialsMuted(player)) {
try { TownyMessaging.sendErrorMsg(player, Translatable.of("tc_err_unable_to_talk_essentials_mute"));
// Check if essentials has this player muted. return true;
if (plugin.getTowny().getEssentials().getUser(player).isMuted()) {
TownyMessaging.sendErrorMsg(player, Translatable.of("tc_err_unable_to_talk_essentials_mute"));
return true;
}
} catch (TownyException e) {
// Get essentials failed
} }
return false; return false;
} }
@@ -2,19 +2,17 @@ package com.palmergames.bukkit.TownyChat.util;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.TownyChat.Chat;
import com.palmergames.bukkit.towny.exceptions.TownyException;
public class EssentialsIntegration { public class EssentialsIntegration {
public static boolean ignoredByEssentials(Player sender, Player player) { public static boolean ignoredByEssentials(Player sender, Player player) {
try { com.earth2me.essentials.User targetUser = Chat.getTownyChat().getEssentials().getUser(player);
com.earth2me.essentials.User targetUser = Towny.getPlugin().getEssentials().getUser(player); com.earth2me.essentials.User senderUser = Chat.getTownyChat().getEssentials().getUser(sender);
com.earth2me.essentials.User senderUser = Towny.getPlugin().getEssentials().getUser(sender); return targetUser.isIgnoredPlayer(senderUser);
return targetUser.isIgnoredPlayer(senderUser); }
} catch (TownyException ignored) {
// Failed to fetch user so ignore. public static boolean isMuted(Player player) {
} return Chat.getTownyChat().getEssentials().getUser(player).isMuted();
return false;
} }
} }