mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-30 01:39:51 +02:00
Cleanup of ranks and make it more resistant against exceptions from external code
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.ess3.ranks;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IRanks;
|
||||
import net.ess3.api.ISettings;
|
||||
@@ -19,84 +20,130 @@ public class GMGroups extends AbstractRanks implements IRanks
|
||||
this.ess = ess;
|
||||
this.groupManager = (GroupManager)groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealCooldown(CommandSender player)
|
||||
|
||||
private double getGMDouble(final CommandSender player, final String key, final double defaultValue)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
try
|
||||
{
|
||||
return 0;
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return handler.getPermissionDouble(player.getName(), key);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private int getGMInteger(final CommandSender player, final String key, final int defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return handler.getPermissionInteger(player.getName(), key);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private String getGMString(final CommandSender player, final String key, final String defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return handler.getPermissionString(player.getName(), key);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return defaultValue;
|
||||
}
|
||||
return handler.getPermissionDouble(player.getName(), "healcooldown");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportCooldown(CommandSender player)
|
||||
public double getHealCooldown(final CommandSender player)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return handler.getPermissionDouble(player.getName(), "teleportcooldown");
|
||||
return getGMDouble(player, "healcooldown", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportDelay(CommandSender player)
|
||||
public double getTeleportCooldown(final CommandSender player)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return handler.getPermissionDouble(player.getName(), "teleportdelay");
|
||||
return getGMDouble(player, "teleportcooldown", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(CommandSender player)
|
||||
public double getTeleportDelay(final CommandSender player)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
return getGMDouble(player, "teleportdelay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(final CommandSender player)
|
||||
{
|
||||
try
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return handler.getUserPrefix(player.getName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
return handler.getUserPrefix(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix(CommandSender player)
|
||||
public String getSuffix(final CommandSender player)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
try
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return handler.getUserSuffix(player.getName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
return handler.getUserSuffix(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHomeLimit(CommandSender player)
|
||||
public int getHomeLimit(final CommandSender player)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return handler.getPermissionInteger(player.getName(), "homes");
|
||||
return getGMInteger(player, "homes", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRawChatFormat(final CommandSender player)
|
||||
{
|
||||
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler != null)
|
||||
String chatformat = getGMString(player, "chatformat", null);
|
||||
if (chatformat != null && !chatformat.isEmpty())
|
||||
{
|
||||
String chatformat = handler.getPermissionString(player.getName(), "chatformat");
|
||||
if (chatformat != null && !chatformat.isEmpty())
|
||||
{
|
||||
return chatformat;
|
||||
}
|
||||
return chatformat;
|
||||
}
|
||||
|
||||
ISettings settings = ess.getSettings();
|
||||
@@ -106,22 +153,38 @@ public class GMGroups extends AbstractRanks implements IRanks
|
||||
@Override
|
||||
public String getMainGroup(CommandSender player)
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
try
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return handler.getGroup(player.getName());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
return handler.getGroup(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(CommandSender player, String groupname)
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
try
|
||||
{
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
|
||||
if (handler == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return handler.inGroup(player.getName(), groupname);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
return handler.inGroup(player.getName(), groupname);
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import net.ess3.storage.StorageObject;
|
||||
public class RankOptions implements StorageObject
|
||||
{
|
||||
@Comment("Message format of chat messages")
|
||||
private String messageFormat;
|
||||
private String chatFormat;
|
||||
@Comment("Prefix for name")
|
||||
private String prefix;
|
||||
@Comment("Suffix for name")
|
||||
|
@@ -17,14 +17,15 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRanks
|
||||
{
|
||||
private AbstractRanks abstractRanks = new AbstractRanks() {
|
||||
private AbstractRanks abstractRanks = new AbstractRanks()
|
||||
{
|
||||
@Override
|
||||
protected String getRawChatFormat(CommandSender sender)
|
||||
protected String getRawChatFormat(final CommandSender sender)
|
||||
{
|
||||
return RanksStorage.this.getRawChatFormat(sender);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void finishRead()
|
||||
{
|
||||
@@ -150,9 +151,9 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
|
||||
{
|
||||
for (Entry<String, RankOptions> groupOptions : getGroups(player))
|
||||
{
|
||||
if (groupOptions.getValue().getMessageFormat() != null)
|
||||
if (groupOptions.getValue().getChatFormat() != null)
|
||||
{
|
||||
return groupOptions.getValue().getMessageFormat();
|
||||
return groupOptions.getValue().getChatFormat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(CommandSender player, String groupname)
|
||||
public boolean inGroup(final CommandSender player, final String groupname)
|
||||
{
|
||||
for (Entry<String, RankOptions> groupOptions : getGroups(player))
|
||||
{
|
||||
@@ -174,7 +175,7 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainGroup(CommandSender player)
|
||||
public String getMainGroup(final CommandSender player)
|
||||
{
|
||||
for (Entry<String, RankOptions> groupOptions : getGroups(player))
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package net.ess3.ranks;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IRanks;
|
||||
import net.ess3.api.ISettings;
|
||||
@@ -16,86 +17,155 @@ public class VaultGroups extends AbstractRanks implements IRanks
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
private <T> T getServiceProvider(Class<T> clazz) {
|
||||
RegisteredServiceProvider<T> provider = ess.getServer().getServicesManager().getRegistration(clazz);
|
||||
|
||||
private <T> T getServiceProvider(final Class<T> clazz)
|
||||
{
|
||||
final RegisteredServiceProvider<T> provider = ess.getServer().getServicesManager().getRegistration(clazz);
|
||||
return provider.getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealCooldown(CommandSender player)
|
||||
private double getVaultDouble(final CommandSender player, final String key, final double defaultValue)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoDouble(getPlayer(player), "healcooldown", 0);
|
||||
try
|
||||
{
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoDouble(getPlayer(player), key, defaultValue);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private int getVaultInteger(final CommandSender player, final String key, final int defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoInteger(getPlayer(player), key, defaultValue);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private String getVaultString(final CommandSender player, final String key, final String defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoString(getPlayer(player), key, defaultValue);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportCooldown(CommandSender player)
|
||||
public double getHealCooldown(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoDouble(getPlayer(player), "teleportcooldown", 0);
|
||||
return getVaultDouble(player, "healcooldown", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportDelay(CommandSender player)
|
||||
public double getTeleportCooldown(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoDouble(getPlayer(player), "teleportdelay", 0);
|
||||
return getVaultDouble(player, "teleportcooldown", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(CommandSender player)
|
||||
public double getTeleportDelay(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerPrefix(getPlayer(player));
|
||||
return getVaultDouble(player, "teleportdelay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix(CommandSender player)
|
||||
public String getPrefix(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerSuffix(getPlayer(player));
|
||||
try
|
||||
{
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerPrefix(getPlayer(player));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHomeLimit(CommandSender player)
|
||||
public String getSuffix(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerInfoInteger(getPlayer(player), "homes", 0);
|
||||
try
|
||||
{
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPlayerSuffix(getPlayer(player));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHomeLimit(final CommandSender player)
|
||||
{
|
||||
return getVaultInteger(player, "homes", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRawChatFormat(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
String chatformat = chat.getPlayerInfoString(getPlayer(player), "chatformat", "");
|
||||
final String chatformat = getVaultString(player, "chatformat", null);
|
||||
if (chatformat != null && !chatformat.isEmpty())
|
||||
{
|
||||
return chatformat;
|
||||
}
|
||||
|
||||
ISettings settings = ess.getSettings();
|
||||
final ISettings settings = ess.getSettings();
|
||||
return settings.getData().getChat().getDefaultFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainGroup(CommandSender player)
|
||||
public String getMainGroup(final CommandSender player)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPrimaryGroup(getPlayer(player));
|
||||
try
|
||||
{
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
return chat.getPrimaryGroup(getPlayer(player));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(CommandSender player, String groupname)
|
||||
public boolean inGroup(final CommandSender player, final String groupname)
|
||||
{
|
||||
Chat chat = getServiceProvider(Chat.class);
|
||||
for (String group : chat.getPlayerGroups(getPlayer(player)))
|
||||
try
|
||||
{
|
||||
if (group.equalsIgnoreCase(groupname))
|
||||
final Chat chat = getServiceProvider(Chat.class);
|
||||
for (String group : chat.getPlayerGroups(getPlayer(player)))
|
||||
{
|
||||
return true;
|
||||
if (group.equalsIgnoreCase(groupname))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user