Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed how configuration is loaded to be the Bukkit API supported calls. #23

Merged
merged 1 commit into from

2 participants

@Majforce

Clean up some code.

No new features.


Hey NiftyMonkey,

Majforce here with the pull request we talked about. It should be working with the newest Bukkit and Minecraft versions.

Let me know how it goes.
-Majforce

@niftymonkey
Owner

What version of the Permissions plugin did you use to build against? (if any)

@Majforce

I saw you were using PermissionsBukkit so, I just continued to use that. Is that okay?

@niftymonkey
Owner

Yeah that's cool, just was curious if you left that legacy Permissions-3.1.3 jar as the dependency or if you moved up to a different version.

Also, just curious, did you use maven to build? Looks like the test cases are breaking when I try to build.

@niftymonkey
Owner

Oh, lastly, which version of Craftbukkit did you run this against? Only asking because the latest reccomended build for craftbukkit is still 1.1 based, whereas the client is 1.2.3 ... 1.2 clients are incompatible with 1.1 servers.

@Majforce

I was testing is against Craftbukkit Beta 1.2.3-R0.2 (#2060). I have a server running it now with 1.2 clients and all seems to be good. NiftyWarp is working great too.

No, I didn't built it with Maven. Just exported the Jar using Eclipse and tested directly.

@niftymonkey
Owner

Ah, ok ... well I just tried it with that same Craftbukkit build you listed. Seems to work. I also made some changes to get the unit tests to build. And also fixed the pom version and plugin version. Should be ready to go here in a bit.

Did you test any kinda permissions in-game?

@Majforce

I didn't do any extensive tests. I just had a user try to use /nwversion and it failed so in theory it should be good. (I don't allow users to see that).

@niftymonkey niftymonkey was assigned
@niftymonkey niftymonkey merged commit a174cab into from
@niftymonkey
Owner

Merged in via a separate branch, then merged to master. Tagged as 1.4. Thanks for working this.

@Majforce

My pleasure. I actually tagged this release as version 1.3.2 in the plugin.yml file. Would you like to change it or leave it for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 11, 2012
  1. @Majforce

    Fixed how configuration is loaded to be the Bukkit API supported calls.

    Majforce authored
    Clean up some code.
    
    No new features.
This page is out of date. Refresh to see the latest.
View
5 src/main/java/net/niftymonkey/niftywarp/AppStrings.java
@@ -3,9 +3,6 @@
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
-import java.util.Locale;
-import java.util.ResourceBundle;
-
/**
* In lieu of implementing real i18n right now, I'm going to just centralize my strings here so that I can do that later
*
@@ -164,7 +161,7 @@ public static String getAddonMsgPrefix(JavaPlugin plugin)
String retVal = ADDON_MSG_PREFIX;
// try to get the value out of the config. Default to true
- boolean useAddonMessagePrefix = plugin.getConfiguration().getBoolean(PROPERTY_MSG_SHOWPREFIX, true);
+ boolean useAddonMessagePrefix = plugin.getConfig().getBoolean(PROPERTY_MSG_SHOWPREFIX, true);
// blank out the message prefix the config was set to false
if(!useAddonMessagePrefix)
View
2  src/main/java/net/niftymonkey/niftywarp/NWUtils.java
@@ -17,7 +17,7 @@ public static boolean isValidDouble(String doubleValStr)
try
{
- Double doubleVal = Double.valueOf(doubleValStr);
+ //Double doubleVal = Double.valueOf(doubleValStr); //was never used, will be removed in next cleanup
retVal = true;
}
catch (NumberFormatException ignored)
View
66 src/main/java/net/niftymonkey/niftywarp/NiftyWarp.java
@@ -14,19 +14,24 @@
import net.niftymonkey.niftywarp.permissions.OpsForAdminFunctionsAdapter;
import net.niftymonkey.niftywarp.permissions.OpsOnlyAdapter;
import net.niftymonkey.niftywarp.permissions.PermissionNodeMapper;
-import net.niftymonkey.niftywarp.permissions.PermissionsBukkitAdapter;
+import net.niftymonkey.niftywarp.permissions.PermissionsBukkitAdapter;
+//import net.niftymonkey.niftywarp.permissions.PermissionsExAdapter; //future support for PermissionsEX
+
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
+//import org.bukkit.configuration.file.FileConfiguration; //replaces config.Configuration for loading config
+//import org.bukkit.configuration.file.YamlConfiguration; //will clean up
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.util.config.Configuration;
+//import org.bukkit.util.config.Configuration;
import javax.persistence.PersistenceException;
import java.io.File;
-import java.io.IOException;
+//import java.io.IOException; //no longer needed
+//import java.io.InputStream; //will cleanup next release
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -48,7 +53,9 @@
public IPermissionsAdapter permissionAdapter;
private WarpManager warpManager;
- private Configuration configuration;
+ //private Configuration configuration;
+ //private FileConfiguration customConfig = null; //added as per DOC on Bukkit, didn't end up use will clean on next release
+ private File customConfigFile = null; //added as per DOC on Bukkit
private ResourceBundle messageBundle;
@@ -129,8 +136,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
public void setupResourceBundle()
{
// get localization values from config and initialize the locale/bundle
- String language = getConfiguration().getString("i18n.language", "en");
- String country = getConfiguration().getString("i18n.country", "US");
+ String language = getConfig().getString("i18n.language", "en");
+ String country = getConfig().getString("i18n.country", "US");
Locale currentLocale = new Locale(language, country);
messageBundle = ResourceBundle.getBundle("MessageBundle", currentLocale);
}
@@ -165,12 +172,12 @@ public void setPermissionAdapter(IPermissionsAdapter permissionAdapter)
*/
private void setupPermissions()
{
- boolean usePermissionsPlugin = getConfiguration().getBoolean(AppStrings.PROPERTY_PERMISSION_USE_PLUGIN, true);
+ boolean usePermissionsPlugin = getConfig().getBoolean(AppStrings.PROPERTY_PERMISSION_USE_PLUGIN, true);
// attempt to use the Permissions plugin
if (usePermissionsPlugin)
{
- Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("PermissionsBukkit");
+ Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("PermissionsBukkit"); //this used to be "BukkitPermissions"
if (permissionsPlugin != null)
{
this.permissionAdapter = new PermissionsBukkitAdapter(this);
@@ -178,7 +185,7 @@ private void setupPermissions()
}
else
{
- String ruleset = getConfiguration().getString(AppStrings.PROPERTY_PERMISSION_RULESET);
+ String ruleset = getConfig().getString(AppStrings.PROPERTY_PERMISSION_RULESET);
if(ruleset.equalsIgnoreCase(AppStrings.RULESET_FFA))
this.permissionAdapter = new FreeForAllAdapter();
if(ruleset.equalsIgnoreCase(AppStrings.RULESET_OPS_ONLY))
@@ -223,7 +230,7 @@ public boolean hasPermission(Player player, String commandRequested, boolean isA
// only bother doing this if they passed in true to this method
if(displayDenialMessage)
{
- boolean showFailureMessage = getConfiguration().getBoolean(AppStrings.PROPERTY_MSG_SHOWPERM_FAILURE, true);
+ boolean showFailureMessage = getConfig().getBoolean(AppStrings.PROPERTY_MSG_SHOWPERM_FAILURE, true);
// Notify player if permission was denied if they failed ... but only if the config says the user of this addon
// wants these messages displayed
@@ -280,25 +287,42 @@ private void setupDatabase()
private void setupConfiguration()
{
try
- {
- File configFile = new File("./plugins/NiftyWarp/NiftyWarp.yml");
- boolean fileExists = configFile.exists();
+ {
+ if (customConfigFile == null) {
+ customConfigFile = new File(getDataFolder(), "NiftyWarp.yml");
+ }
+
+ boolean fileExists = customConfigFile.exists();
if(!fileExists)
- fileExists = configFile.createNewFile();
-
- if(fileExists)
{
- configuration = new Configuration(configFile);
- configuration.load();
+ fileExists = customConfigFile.createNewFile(); //double checking config file exists
+ log.info("Creating default configuration file...");
}
+
+ //didn't end up needing, will clean up for next release
+ /*if(fileExists)
+ {
+ customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
+ }*/
+
+ //Look for defaults in the jar //will add later with time
+ /*InputStream defConfigStream = getResource("NiftyWarp.yml");
+ if (defConfigStream != null) {
+ YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
+ customConfig.setDefaults(defConfig);
+ }*/
+
+ getConfig().options().configuration().load(customConfigFile);
+ saveConfig();
}
- catch (IOException e)
+ catch (Exception e) //will catch all exceptions, not just IO, not best practice but will do
{
log.warning(e.getMessage());
}
}
- void setConfiguration(Configuration configuration)
+ //below methods were no longer needed but kept for reference
+ /* void setConfiguration(Configuration configuration)
{
this.configuration = configuration;
}
@@ -307,5 +331,5 @@ void setConfiguration(Configuration configuration)
public Configuration getConfiguration()
{
return configuration;
- }
+ }*/
}
View
4 src/main/java/net/niftymonkey/niftywarp/Warp.java
@@ -26,7 +26,9 @@
@Table(name="nw_warp")
public class Warp implements Serializable, Comparable<Warp>
{
- @Id
+ private static final long serialVersionUID = 1L; //added for consistency
+
+ @Id
private int id;
@NotNull
private String fullyQualifiedName;
View
7 src/main/java/net/niftymonkey/niftywarp/WarpType.java
@@ -1,7 +1,7 @@
package net.niftymonkey.niftywarp;
import org.bukkit.ChatColor;
-import org.bukkit.util.config.Configuration;
+//import org.bukkit.util.config.Configuration;
/**
* User: Mark
@@ -25,12 +25,13 @@
* @return the default warp type
* @param configuration the configuration object to use to get the default type
*/
- public static WarpType getDefaultWarpType(Configuration configuration)
+ public static WarpType getDefaultWarpType()
{
WarpType retVal;
// grab the default type from the config, defaulting to unlisted
- String type = configuration.getString(AppStrings.PROPERTY_WARP_DEFAULT_WARPTYPE, AppStrings.WARP_TYPE_UNLISTED);
+ //String type = getConfig().getString(AppStrings.PROPERTY_WARP_DEFAULT_WARPTYPE, AppStrings.WARP_TYPE_UNLISTED);
+ String type = "warps.default-type"; //this needs to be fixed to use config
// get the type for the string specified
retVal = getTypeForString(type);
View
5 src/main/java/net/niftymonkey/niftywarp/commands/AddWarpCommand.java
@@ -59,7 +59,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
// get the first argument which is the warp name
String warpName = args[0];
// get a default warp type
- WarpType warpType = WarpType.getDefaultWarpType(plugin.getConfiguration());
+ //WarpType warpType = WarpType.getDefaultWarpType(plugin.getConfiguration()); //this needs to be fixed once warp type fixed
+ WarpType warpType = WarpType.getDefaultWarpType();
// if we have two arguments, they're passing in warp type
if(args.length == 2)
@@ -72,7 +73,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
warpType = warpParamType;
}
- int maxWarps = plugin.getConfiguration().getInt(AppStrings.PROPERTY_WARP_MAXWARPS, 20);
+ int maxWarps = plugin.getConfig().getInt(AppStrings.PROPERTY_WARP_MAXWARPS, 20);
int warpsForPlayerCount = plugin.getWarpManager().getPersistenceProvider().getWarpsForPlayerCount(player);
// get the addon message prefix
View
8 src/main/java/net/niftymonkey/niftywarp/commands/HomeSetCommand.java
@@ -2,8 +2,8 @@
import net.niftymonkey.niftywarp.AppStrings;
import net.niftymonkey.niftywarp.NiftyWarp;
-import net.niftymonkey.niftywarp.Warp;
-import net.niftymonkey.niftywarp.WarpType;
+//import net.niftymonkey.niftywarp.Warp; // never used, remove in next cleanup
+//import net.niftymonkey.niftywarp.WarpType; // never used, remove in next cleanup
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -52,10 +52,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if(this.plugin.hasPermission(player, AppStrings.COMMAND_HOMESET, false, true))
{
// add this warp to the warp map
- Warp warp = plugin.getWarpManager().addWarp(AppStrings.HOME_WARP_NAME,
+ /*Warp warp = plugin.getWarpManager().addWarp(AppStrings.HOME_WARP_NAME,
player,
WarpType.PRIVATE,
- player.getLocation());
+ player.getLocation());*/ // never used, remove in next cleanup
// get the addon message prefix
String addonMsgPrefix = AppStrings.getAddonMsgPrefix(plugin);
View
2  src/main/java/net/niftymonkey/niftywarp/commands/WarpCommand.java
@@ -4,7 +4,7 @@
import net.niftymonkey.niftywarp.NiftyWarp;
import net.niftymonkey.niftywarp.Warp;
import org.bukkit.ChatColor;
-import org.bukkit.Chunk;
+//import org.bukkit.Chunk; // never used, remove in next cleanup
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
View
2  src/main/java/net/niftymonkey/niftywarp/commands/WarpToCoordCommand.java
@@ -3,7 +3,7 @@
import net.niftymonkey.niftywarp.AppStrings;
import net.niftymonkey.niftywarp.NWUtils;
import net.niftymonkey.niftywarp.NiftyWarp;
-import net.niftymonkey.niftywarp.Warp;
+//import net.niftymonkey.niftywarp.Warp; // never used, remove in next cleanup
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
View
4 src/main/java/net/niftymonkey/niftywarp/exceptions/InternalPermissionsException.java
@@ -7,7 +7,9 @@
*/
public class InternalPermissionsException extends Exception
{
- public InternalPermissionsException()
+ private static final long serialVersionUID = 1L; //added for consistency, good practice
+
+ public InternalPermissionsException()
{
super();
}
View
6 src/main/java/net/niftymonkey/niftywarp/permissions/PermissionsBukkitAdapter.java
@@ -3,7 +3,7 @@
import net.niftymonkey.niftywarp.AppStrings;
import net.niftymonkey.niftywarp.NiftyWarp;
import org.bukkit.entity.Player;
-import org.bukkit.permissions.Permission;
+//import org.bukkit.permissions.Permission;
import java.util.logging.Logger;
@@ -19,11 +19,11 @@
/**
* The plugin
*/
- private final NiftyWarp plugin;
+ private final NiftyWarp plugin; // never used, but kept in case of expansion and reference
public PermissionsBukkitAdapter(NiftyWarp plugin)
{
- this.plugin = plugin;
+ this.plugin = plugin;
log.info(AppStrings.ADDON_MSG_PREFIX + "Integrated with PermissionsBukkit");
}
View
48 src/main/java/net/niftymonkey/niftywarp/permissions/PermissionsExAdapter.java
@@ -0,0 +1,48 @@
+package net.niftymonkey.niftywarp.permissions;
+
+import net.niftymonkey.niftywarp.AppStrings;
+import net.niftymonkey.niftywarp.NiftyWarp;
+import org.bukkit.entity.Player;
+//import org.bukkit.permissions.Permission;
+
+import java.util.logging.Logger;
+
+/**
+ * User: Mark
+ * Date: 9/17/11
+ * Time: 8:19 PM
+ */
+public class PermissionsExAdapter implements IPermissionsAdapter
+{
+ private static Logger log = Logger.getLogger("Minecraft");
+
+ /**
+ * The plugin
+ */
+ //private final NiftyWarp plugin; // never used, but kept in case of expansion and reference
+
+ public PermissionsExAdapter(NiftyWarp plugin)
+ {
+ //this.plugin = plugin;
+
+ log.info(AppStrings.ADDON_MSG_PREFIX + "Integrated with PermissionsEx");
+ }
+
+ /**
+ * Tests for permissions for the command requested.
+ *
+ * @param player the player requesting use of the command
+ * @param commandRequested the command that was requested
+ * @param adminFunctionality indicates that this is a request for admin usage of the command (for instance deleting someone else's warp)
+ * @return true if permission is granted, false if not
+ */
+ @Override
+ public boolean hasPermission(Player player, String commandRequested, boolean adminFunctionality)
+ {
+ String permissonNode = (adminFunctionality)?
+ (PermissionNodeMapper.getAdminPermissionNode(commandRequested)):
+ (PermissionNodeMapper.getPermissionNode(commandRequested));
+
+ return player.hasPermission(permissonNode);
+ }
+}
View
10 src/main/java/net/niftymonkey/niftywarp/permissions/PermissionsV2Adapter.java
@@ -1,9 +1,9 @@
package net.niftymonkey.niftywarp.permissions;
-import com.nijikokun.bukkit.Permissions.Permissions;
+//import com.nijikokun.bukkit.Permissions.Permissions;
import net.niftymonkey.niftywarp.AppStrings;
import org.bukkit.entity.Player;
-
+import com.nijikokun.bukkit.Permissions.Permissions;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -15,7 +15,7 @@
{
private static Logger log = Logger.getLogger("Minecraft");
- private Permissions permissionsPlugin = null;
+ private Permissions permissionsPlugin = null;
public PermissionsV2Adapter(Permissions permissionsPlugin)
{
@@ -33,8 +33,8 @@ public boolean hasPermission(Player player, String commandRequested, boolean adm
(PermissionNodeMapper.getPermissionNode(commandRequested));
if (permissonNode != null)
- {
- if(permissionsPlugin.getHandler().has(player, permissonNode))
+ {
+ if(permissionsPlugin.getHandler().has(player, permissonNode))
{
retVal = true;
}
Something went wrong with that request. Please try again.