1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-30 17:59:53 +02:00

Cleanup of ranks and make it more resistant against exceptions from external code

This commit is contained in:
snowleo
2012-10-16 00:15:38 +02:00
parent 80bdae2cc9
commit 4f4f9d8702
4 changed files with 224 additions and 90 deletions

View File

@@ -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;
@@ -20,84 +21,130 @@ public class GMGroups extends AbstractRanks implements IRanks
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));
try
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
if (handler == null)
{
return 0;
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));
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;
}
}
@Override
public String getSuffix(CommandSender player)
public String getSuffix(final CommandSender player)
{
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
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;
}
}
@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 = handler.getPermissionString(player.getName(), "chatformat");
String chatformat = getGMString(player, "chatformat", null);
if (chatformat != null && !chatformat.isEmpty())
{
return chatformat;
}
}
ISettings settings = ess.getSettings();
return settings.getData().getChat().getDefaultFormat();
@@ -105,6 +152,8 @@ public class GMGroups extends AbstractRanks implements IRanks
@Override
public String getMainGroup(CommandSender player)
{
try
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
if (handler == null)
@@ -113,9 +162,17 @@ public class GMGroups extends AbstractRanks implements IRanks
}
return handler.getGroup(player.getName());
}
catch (Exception e)
{
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
return null;
}
}
@Override
public boolean inGroup(CommandSender player, String groupname)
{
try
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(getPlayer(player));
if (handler == null)
@@ -124,4 +181,10 @@ public class GMGroups extends AbstractRanks implements IRanks
}
return handler.inGroup(player.getName(), groupname);
}
catch (Exception e)
{
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
return false;
}
}
}

View File

@@ -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")

View File

@@ -17,9 +17,10 @@ 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);
}
@@ -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))
{

View File

@@ -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;
@@ -17,78 +18,142 @@ 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 getVaultDouble(player, "teleportdelay", 0);
}
@Override
public String getPrefix(final CommandSender player)
{
try
{
final Chat chat = getServiceProvider(Chat.class);
return chat.getPlayerPrefix(getPlayer(player));
}
@Override
public String getSuffix(CommandSender player)
catch (Exception e)
{
Chat chat = getServiceProvider(Chat.class);
return chat.getPlayerSuffix(getPlayer(player));
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);
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);
try
{
final Chat chat = getServiceProvider(Chat.class);
for (String group : chat.getPlayerGroups(getPlayer(player)))
{
if (group.equalsIgnoreCase(groupname))
@@ -96,6 +161,11 @@ public class VaultGroups extends AbstractRanks implements IRanks
return true;
}
}
}
catch (Exception e)
{
ess.getLogger().log(Level.WARNING, e.getMessage(), e);
}
return false;
}
}