mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-09-28 23:57:27 +02:00
1be3daf0b5
This PR updates the version of the bStats Metrics class to the latest version, supporting plugin IDs in place of just plugin names. It also adds the following graphs: - Active permissions backend - Active economy backend - Whether or not a command has been used as a bar chart (pending bStats backend implementation) - Version history graph as a multiline graph (also pending bStats impl) It also removes the weird `getMetrics` and `setMetrics` APIs which should never have been API in the first place.
140 lines
4.4 KiB
Java
140 lines
4.4 KiB
Java
package com.earth2me.essentials.xmpp;
|
|
|
|
import com.earth2me.essentials.IEssentials;
|
|
import com.earth2me.essentials.metrics.Metrics;
|
|
import com.earth2me.essentials.metrics.MetricsWrapper;
|
|
import net.ess3.api.IUser;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.logging.Level;
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP {
|
|
private static EssentialsXMPP instance = null;
|
|
private transient UserManager users;
|
|
private transient XMPPManager xmpp;
|
|
private transient IEssentials ess;
|
|
private transient MetricsWrapper metrics = null;
|
|
|
|
static IEssentialsXMPP getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
instance = this;
|
|
|
|
final PluginManager pluginManager = getServer().getPluginManager();
|
|
ess = (IEssentials) pluginManager.getPlugin("Essentials");
|
|
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
|
|
getLogger().log(Level.WARNING, tl("versionMismatchAll"));
|
|
}
|
|
if (!ess.isEnabled()) {
|
|
this.setEnabled(false);
|
|
return;
|
|
}
|
|
|
|
final EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess);
|
|
pluginManager.registerEvents(playerListener, this);
|
|
|
|
users = new UserManager(this.getDataFolder());
|
|
xmpp = new XMPPManager(this);
|
|
|
|
ess.addReloadListener(users);
|
|
ess.addReloadListener(xmpp);
|
|
|
|
if (metrics == null) {
|
|
metrics = new MetricsWrapper(this, 3818, true);
|
|
metrics.addCustomChart(new Metrics.SimplePie("config-valid", () -> xmpp.isConfigValid() ? "yes" : "no"));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
if (xmpp != null) {
|
|
xmpp.disconnect();
|
|
}
|
|
instance = null;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) {
|
|
metrics.markCommand(command.getName(), true);
|
|
return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.", null);
|
|
}
|
|
|
|
@Override
|
|
public void setAddress(final Player user, final String address) {
|
|
final String username = user.getName().toLowerCase(Locale.ENGLISH);
|
|
instance.users.setAddress(username, address);
|
|
}
|
|
|
|
@Override
|
|
public String getAddress(final String name) {
|
|
return instance.users.getAddress(name);
|
|
}
|
|
|
|
@Override
|
|
public IUser getUserByAddress(final String address) {
|
|
String username = instance.users.getUserByAddress(address);
|
|
return username == null ? null : ess.getUser(username);
|
|
}
|
|
|
|
@Override
|
|
public boolean toggleSpy(final Player user) {
|
|
final String username = user.getName().toLowerCase(Locale.ENGLISH);
|
|
final boolean spy = !instance.users.isSpy(username);
|
|
instance.users.setSpy(username, spy);
|
|
return spy;
|
|
}
|
|
|
|
@Override
|
|
public String getAddress(final Player user) {
|
|
return instance.users.getAddress(user.getName());
|
|
}
|
|
|
|
@Override
|
|
public boolean sendMessage(final Player user, final String message) {
|
|
return instance.xmpp.sendMessage(instance.users.getAddress(user.getName()), message);
|
|
}
|
|
|
|
@Override
|
|
public boolean sendMessage(final String address, final String message) {
|
|
return instance.xmpp.sendMessage(address, message);
|
|
}
|
|
|
|
static void updatePresence() {
|
|
instance.xmpp.updatePresence();
|
|
}
|
|
|
|
@Override
|
|
public List<String> getSpyUsers() {
|
|
return instance.users.getSpyUsers();
|
|
}
|
|
|
|
@Override
|
|
public void broadcastMessage(final IUser sender, final String message, final String xmppAddress) {
|
|
ess.broadcastMessage(sender, message);
|
|
try {
|
|
for (String address : getSpyUsers()) {
|
|
if (!address.equalsIgnoreCase(xmppAddress)) {
|
|
sendMessage(address, message);
|
|
}
|
|
}
|
|
} catch (Exception ignored) {}
|
|
}
|
|
|
|
@Override
|
|
public IEssentials getEss() {
|
|
return ess;
|
|
}
|
|
}
|