Created
May 15, 2014 23:31
-
-
Save samschooler/34f4155442ab1f0dd6f4 to your computer and use it in GitHub Desktop.
The NumberOne qQuests plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.quaz3l.numberone; | |
import me.quaz3l.qQuests.qQuests; | |
import me.quaz3l.qQuests.API.QuestAPI; | |
import me.quaz3l.qQuests.API.PluginModels.qRequirement; | |
import org.bukkit.plugin.Plugin; | |
public class qQuestsHandler | |
{ | |
Plugin plugin; | |
QuestAPI qAPI; | |
public qQuestsHandler(Plugin pl) | |
{ | |
this.plugin = pl; | |
} | |
public boolean setupQQuests() | |
{ | |
qQuests qQuests = (qQuests) plugin.getServer().getPluginManager().getPlugin("qQuests"); | |
if (this.qAPI == null) | |
{ | |
if (qQuests != null) | |
{ | |
this.qAPI = qQuests.qAPI; | |
return true; | |
} | |
} | |
return false; | |
} | |
public void addRequirements() | |
{ | |
try | |
{ | |
Class.forName("me.quaz3l.qQuests.qQuests"); | |
this.qAPI.getRequirementHandler().addRequirement(new qRequirement() | |
{ | |
@Override | |
public int passedRequirement(String player, Object value) | |
{ | |
try | |
{ | |
if(Integer.parseInt(value.toString()) != 1) { | |
return -2; // The number is not one | |
} | |
} catch (NumberFormatException e) | |
{ | |
return -1; // The number is invalid | |
} | |
return 0; // The number is one | |
} | |
@Override | |
public int validate(Object value) | |
{ | |
if (value == null) | |
{ | |
return -1; | |
} | |
try | |
{ | |
Integer.parseInt(value.toString()); | |
} catch (NumberFormatException e) | |
{ | |
return -1; | |
} | |
return 0; | |
} | |
@Override | |
public String getName() | |
{ | |
return "numberone"; | |
} | |
@Override | |
public String parseError(String player, Object value, int errorCode) { | |
switch(errorCode) { | |
case -2: return "The requirement " + this.getName() + ", is NOT a number, it MUST be a number!"; | |
case -1: return "The requirement " + this.getName() + ", is NOT one, it MUST be a number!"; | |
default: return "Unknown Error! LULZ! :p"; | |
} | |
} | |
@Override | |
public void onDisable() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onEnable() { | |
// TODO Auto-generated method stub | |
} | |
}); | |
} catch (ClassNotFoundException e) { } // Silently fails if qQuests is not installed. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment