Permalink
Browse files

Customizable messages. Fixed issue with Vault econ causing plugin to …

…not start.
  • Loading branch information...
b-turchyn committed Jan 5, 2012
1 parent d7bb3fa commit bacd5f1e10e1cdcfff38aad1defe4f77fa545916
View
@@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="lib"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="lib" path="lib/bukkit-1.0.0-R1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/Vault.jar"/>
+ <classpathentry kind="lib" path="lib/craftbukkit-1.0.1-R1.jar"/>
<classpathentry kind="output" path="dist"/>
</classpath>
View
@@ -33,7 +33,7 @@
<path id="libs">
<fileset dir="lib">
- <include name="bukkit-1.0.0-R1-SNAPSHOT.jar" />
+ <include name="craftbukkit-1.0.1-R1.jar" />
<include name="Vault.jar" />
</fileset>
</path>
Binary file not shown.
Binary file not shown.
View
@@ -1,5 +1,5 @@
name: LoginPerks
-version: 0.1b
+version: 0.1d
main: net.brianturchyn.LoginPerks.LoginPerks
description: >
Give users a bonus for logging in. The right way.
@@ -66,9 +66,8 @@ public void onEnable ( )
loginListener = new LoginListener( this );
pm.registerEvent ( Event.Type.PLAYER_JOIN, loginListener,
Event.Priority.Monitor, this );
-
- log ( Level.INFO, "version " + pdfFile.getVersion ( ) + " enabled!" );
}
+ log ( Level.INFO, "version " + pdfFile.getVersion ( ) + " enabled!" );
}
/**
@@ -100,6 +99,13 @@ public void setDefaultConfigOptions ( )
log ( Level.WARNING, "Setting default check on a per-day basis" );
getConfig().set ( LoginListener.CONFIG_PER_DAY, LoginListener.CONFIG_PER_DAY_DEFAULT );
}
+
+ // Add isDebugging() (default: false)
+ if ( getConfig().get ( LoginListener.CONFIG_DEBUG ) == null )
+ {
+ log ( Level.WARNING, "Setting default debug statement value" );
+ getConfig().set ( LoginListener.CONFIG_DEBUG, LoginListener.CONFIG_DEBUG_DEFAULT );
+ }
}
/**
@@ -114,12 +120,7 @@ public void setDefaultConfigOptions ( )
*/
public void log ( String msg )
{
-
- if ( this.logger == null )
- { // Grab logger if DNE
- this.logger = Logger.getLogger ( "Minecraft" );
- }
- this.logger.log ( Level.INFO, "[" + pdfFile.getName ( ) + "] " + msg );
+ log ( Level.INFO, msg );
}
/**
@@ -136,12 +137,11 @@ public void log ( String msg )
*/
public void log ( Level level, String msg )
{
-
if ( this.logger == null )
{ // Grab logger if DNE
this.logger = Logger.getLogger ( "Minecraft" );
}
- this.logger.log ( level, "[" + pdfFile.getName ( ) + "] " + msg );
+ this.logger.log ( level, "[" + pdfFile.getName ( ) + "] " + msg );
}
public PermissionsHandler getPermissions() {
@@ -27,14 +27,20 @@
public static final String CONFIG_UNIT_HOURS = "hours";
public static final String CONFIG_UNIT_MINUTES = "minutes";
public static final int CONFIG_VALUE_DEFAULT = 1;
+ public static final String CONFIG_DEBUG = "loginperks.debug";
+ public static final boolean CONFIG_PER_DAY_DEFAULT = true;
+ public static final String CONFIG_MSG_ITEM = "loginperks.messages.item";
+ public static final String CONFIG_MSG_MONEY = "loginperks.messages.money";
public static final long SECOND_IN_MILLIS = 1000;
public static final long MINUTE_IN_MILLIS = 60 * SECOND_IN_MILLIS;
public static final long HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS;
public static final long DAY_IN_MILLIS = 24 * HOUR_IN_MILLIS;
public static final long MONTH_IN_MILLIS = 30 * DAY_IN_MILLIS;
- public static final boolean CONFIG_PER_DAY_DEFAULT = true;
+ public static final boolean CONFIG_DEBUG_DEFAULT = false;
+
+ private static final String MSG_GIFT = "%f";
public LoginListener ( LoginPerks plugin )
{
@@ -58,39 +64,44 @@ public void onPlayerJoin ( PlayerJoinEvent event )
Player player = event.getPlayer ( );
boolean gotPerk = false;
+ plugin.log( Level.FINE, "Checking if user qualifies for perks");
if ( qualifiesToGetPerks ( player ) )
{ // "Is it Christmas yet, mommy?"
plugin.log ( Level.FINE, "Qualifies to get perks!" );
// Are we getting items? I hope it's a new computer!
if ( plugin.getPermissions ( ).receivesItem ( player ) )
{
gotPerk = true;
- plugin.log ( Level.FINE, "Getting item!" );
+ plugin.log ( Level.INFO, "Getting item!" );
Material giveMaterial = plugin.getData ( ).getMaterialID ( player );
int amount = plugin.getData ( ).getMaterialAmount ( player );
player.getInventory ( )
.addItem ( new ItemStack ( giveMaterial, amount ) );
// TODO: Offload this to a variable
- player.sendMessage ( "You got " + amount + " "
- + giveMaterial.toString ( ) + " for logging in!" );
+ String message = plugin.getConfig().getString(CONFIG_MSG_ITEM, "You got %f for logging in!");
+ message = message.replaceAll( MSG_GIFT, Integer.toString(amount) + " " + giveMaterial.toString ( ) );
+
+ player.sendMessage ( message );
}
// Are we getting money? ARE WE ARE WE ARE WE ARE WE????
plugin.log(Level.FINE, "Expecting loginperks.getsItem result of: " + player.hasPermission ( "loginperks.getsItem" ));
if ( plugin.getPermissions ( ).receivesMoney ( player ) )
{
gotPerk = true;
- plugin.log ( Level.FINE, "Getting item!" );
+ plugin.log ( Level.INFO, "Getting item!" );
int amount = plugin.getData ( ).getMoneyAmount ( player );
plugin.log ( Level.FINE, "Giving " + player.getName ( ) + " "
+ plugin.getEconomy().format ( amount ) );
plugin.getEconomy().give(player, amount);
- player.sendMessage ( "You got "
- + plugin.getEconomy().format ( amount ) + " for logging in!" );
+ String message = plugin.getConfig().getString(CONFIG_MSG_MONEY, "You got %f for logging in!");
+ message = message.replaceAll( MSG_GIFT, plugin.getEconomy().format ( amount ) );
+
+ player.sendMessage ( message );
}
if ( gotPerk )
@@ -101,7 +112,7 @@ public void onPlayerJoin ( PlayerJoinEvent event )
}
else
{
- plugin.log ( Level.FINE, "Does NOT qualify to get perks!" );
+ plugin.log ( Level.INFO, "Does NOT qualify to get perks!" );
}
}
@@ -114,17 +125,21 @@ private boolean qualifiesToGetPerks ( Player player )
.getInstance ( TimeZone.getTimeZone ( "GMT" ) );
boolean perDay = plugin.getConfig ( ).getBoolean (
LoginListener.CONFIG_PER_DAY, LoginListener.CONFIG_PER_DAY_DEFAULT );
+
+ plugin.log("Last online (according to me): " + lastOnline.toString() );
if ( perDay )
{ // If it's no longer the same day as the day (s)he last logged on
// Set every unit lower than days to 0
+ plugin.log("We're on a per-day basis");
lastOnline.setTimeInMillis ( lastOnline.getTimeInMillis ( )
/ DAY_IN_MILLIS * DAY_IN_MILLIS );
currentDate.setTimeInMillis ( currentDate.getTimeInMillis ( )
/ DAY_IN_MILLIS * DAY_IN_MILLIS );
}
else
{ // If it's value * units past his/her last logon
+ plugin.log("Not per-day basis");
String unit = plugin.getConfig ( ).getString ( CONFIG_CHECK_UNITS,
CONFIG_UNIT_DAYS );
long value = plugin.getConfig ( ).getLong ( CONFIG_CHECK_VALUE,
@@ -12,11 +12,15 @@
public EconomyHandler( LoginPerks plugin ) {
this.plugin = plugin;
- economy = EconomyHandler.initEconomy( plugin );
+ this.economy = EconomyHandler.initEconomy( plugin );
}
public boolean enabled() {
- return ( plugin != null && economy != null && economy.isEnabled() );
+ //plugin.log("Null plugin: " + (plugin == null ? "true" : "false"));
+ //plugin.log("Null econ plugin: " + (economy == null ? "true" : "false"));
+ //plugin.log("Econ enabled: " + (economy != null && economy.isEnabled() ? "true" : "false"));
+ // BUG: economy.isEnabled() returns false for some reason
+ return ( plugin != null && economy != null );
}
public boolean give ( Player player, double amount ) {

0 comments on commit bacd5f1

Please sign in to comment.