Pretty much the command equivalent to

hard coding
This commit is contained in:
alisolarflare 2016-11-06 16:44:56 -05:00
parent 419dddc4b1
commit 45b88354e5
8 changed files with 128 additions and 16 deletions

View file

@ -18,10 +18,10 @@ public class AliPresents extends JavaPlugin{
public void onEnable(){ public void onEnable(){
PluginDescriptionFile pdfFile = getDescription(); PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger(); Logger logger = getLogger();
logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ")."); logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ").");
new FlairDoorModule().register(this); new FlairDoorModule().register(this);
new GPowerModule().register(this); new GPowerModule().register(this);
new AliLinkModule().register(this); new AliLinkModule().register(this);
@ -30,6 +30,7 @@ public class AliPresents extends JavaPlugin{
new MinigameModule().register(this); new MinigameModule().register(this);
new CreativeBoundariesModule().register(this); new CreativeBoundariesModule().register(this);
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ")."); logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");

View file

@ -8,10 +8,10 @@ import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
/** /**
* A Module class is a helper class that allows the compacting of projects into one single package. * A Module class allows the compacting of projects into one single package.
* Each feature, whether game, arrow trail listener, or command tool, can have its command and listener *
* registration coded into the Module class, as well as any other pointers to memory units, or other * Each feature can have its commands and listeners coded into the Module class,
* classes in the package. * as well as any other pointers to memory units, or other classes in the package.
* *
* This package can then be moved from eclipse project to eclipse project smoothly, * This package can then be moved from eclipse project to eclipse project smoothly,
* as long as the destination project has the Module abstract class, and as long as all dependencies are either * as long as the destination project has the Module abstract class, and as long as all dependencies are either
@ -21,19 +21,14 @@ import buttondevteam.lib.chat.TBMCCommandBase;
*/ */
public abstract class Module{ public abstract class Module{
/** /**
* Registers the project, when called by the Main JavaPlugin class that handles * Registers the module, when called by the JavaPlugin class. Call
* the main plugin. * registerCommand() and registerListener() within this method.
* *
* To register a command, call plugin.getCommand(//label).setExecutor(//commandExecutor); where
* label is a string containing the name of the command in plugin.yml, and where commandExecutor
* is a class implementing command executor
*
* To register a listener,
* @param plugin Plugin class called to register commands and listeners * @param plugin Plugin class called to register commands and listeners
*/ */
public abstract void register(JavaPlugin plugin); public abstract void register(JavaPlugin plugin);
/** /**
* Lazy route to type plugin.getCommand("label").setExecutor * Registers a TBMCCommand to the plugin
* @param plugin Main plugin responsible for stuff * @param plugin Main plugin responsible for stuff
* @param label Name of the command in plugin.yml * @param label Name of the command in plugin.yml
* @param commandExecutor Custom coded CommandExecutor class * @param commandExecutor Custom coded CommandExecutor class
@ -41,8 +36,15 @@ public abstract class Module{
protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){ protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){
TBMCChatAPI.AddCommand(plugin, commandBase); TBMCChatAPI.AddCommand(plugin, commandBase);
} }
/**
* Registers a Listener to this plugin
* @param plugin Main plugin responsible for stuff
* @param label Name of the command in plugin.yml
* @param commandExecutor Custom coded CommandExecutor class
*/
protected Listener registerListener(JavaPlugin plugin, Listener listener){ protected Listener registerListener(JavaPlugin plugin, Listener listener){
TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin); TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin);
return listener; return listener;
} }
} }

View file

@ -10,6 +10,8 @@ import alisolarflare.Module;
import alisolarflare.creativeboundaries.commands.Cbgm0; import alisolarflare.creativeboundaries.commands.Cbgm0;
import alisolarflare.creativeboundaries.commands.Cbgm1; import alisolarflare.creativeboundaries.commands.Cbgm1;
import alisolarflare.creativeboundaries.commands.SetDickmode; import alisolarflare.creativeboundaries.commands.SetDickmode;
import alisolarflare.creativeboundaries.listeners.ItemRestrictionListener;
import alisolarflare.creativeboundaries.listeners.PlotChangeListener;
public class CreativeBoundariesModule extends Module{ public class CreativeBoundariesModule extends Module{
@ -21,8 +23,8 @@ public class CreativeBoundariesModule extends Module{
registerCommand(plugin, new Cbgm0(this)); registerCommand(plugin, new Cbgm0(this));
registerCommand(plugin, new SetDickmode(this)); registerCommand(plugin, new SetDickmode(this));
registerListener(plugin, new PlotChangeListener(this)); registerListener(plugin, new PlotChangeListener(this));
//registerListener(plugin, new ItemRestrictionListener(this));
} }
} }

View file

@ -0,0 +1,26 @@
package alisolarflare.creativeboundaries.listeners;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCreativeEvent;
import alisolarflare.creativeboundaries.CreativeBoundariesModule;
public class ItemRestrictionListener implements Listener {
private CreativeBoundariesModule module;
public ItemRestrictionListener(CreativeBoundariesModule module) {
this.module = module;
}
@EventHandler
public void onItemTake(InventoryCreativeEvent event){
List<Player> cbCreatives = module.cbCreatives;
}
}

View file

@ -1,4 +1,4 @@
package alisolarflare.creativeboundaries; package alisolarflare.creativeboundaries.listeners;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,6 +12,8 @@ import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse; import com.palmergames.bukkit.towny.object.TownyUniverse;
import alisolarflare.creativeboundaries.CreativeBoundariesModule;
public class PlotChangeListener implements Listener{ public class PlotChangeListener implements Listener{
public CreativeBoundariesModule module; public CreativeBoundariesModule module;
public PlotChangeListener(CreativeBoundariesModule module){ public PlotChangeListener(CreativeBoundariesModule module){

View file

@ -12,7 +12,7 @@ public class BoomBowDeathListener implements Listener{
if (player.getLastDamage() > 7.42420 && player.getLastDamage() < 7.42429){ if (player.getLastDamage() > 7.42420 && player.getLastDamage() < 7.42429){
player.sendMessage("42!"); player.sendMessage("42!");
event.setDeathMessage(player.getName() + "got trigger happy with the Boom Bow"); event.setDeathMessage(player.getName() + " got trigger happy with the [Boom Bow]");
} }
} }
} }

View file

@ -3,6 +3,7 @@ package alisolarflare.uhc;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.Module; import alisolarflare.Module;
import alisolarflare.uhc.controller.SetMatchState;
import alisolarflare.uhc.idle.AddToUHC; import alisolarflare.uhc.idle.AddToUHC;
import alisolarflare.uhc.idle.JoinUHC; import alisolarflare.uhc.idle.JoinUHC;
import alisolarflare.uhc.intro.ConfigureMatch; import alisolarflare.uhc.intro.ConfigureMatch;
@ -23,6 +24,8 @@ public class UHCModule extends Module {
match = new UHCMatch(plugin.getConfig(), MatchState.IDLE); match = new UHCMatch(plugin.getConfig(), MatchState.IDLE);
} }
registerCommand(plugin, new SetMatchState(match));
registerCommand(plugin, new AddToUHC(match)); registerCommand(plugin, new AddToUHC(match));
registerCommand(plugin, new JoinUHC(match)); registerCommand(plugin, new JoinUHC(match));
registerCommand(plugin, new StartMatch(match)); registerCommand(plugin, new StartMatch(match));

View file

@ -0,0 +1,76 @@
package alisolarflare.uhc.controller;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.uhc.memory.MatchState;
import alisolarflare.uhc.memory.UHCMatch;
import buttondevteam.lib.chat.TBMCCommandBase;
public class SetMatchState extends TBMCCommandBase{
UHCMatch match;
public SetMatchState(UHCMatch match) {
this.match = match;
}
@Override
public String[] GetHelpText(String alias) {
return null;
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (!(sender instanceof Player)){
sender.sendMessage("You must be a player to use this command!");
return false;
}
Player player = (Player) sender;
if (player.getName().equalsIgnoreCase("alisolarflare") && player.getName().equalsIgnoreCase("Arsen_Derby_FTW")){
sender.sendMessage("You must be either Ali or Arsen to use this command!");
return false;
}
if(args.length < 1 ){
player.sendMessage("Usage: /setMatchState [stateToBeSet]");
player.sendMessage("States: IDLE, WAITING, SETUP, INTRO, PEACE, POWER, TENSION, END");
return false;
}
String inputState = args[0];
boolean inputIsValidState = false;
for (MatchState defaultMatchState : MatchState.values()){
if(inputState.equalsIgnoreCase(defaultMatchState.toString())){
inputIsValidState = true;
}
}
if (inputIsValidState){
match.setMatchState(MatchState.valueOf(inputState));
player.sendMessage("Match State set to: " + match.getMatchState().toString() + "!");
}else{
player.sendMessage("Error, could not parse state.");
player.sendMessage("Valid States: IDLE, WAITING, SETUP, INTRO, PEACE, POWER, TENSION, END");
return false;
}
return false;
}
@Override
public boolean GetPlayerOnly() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean GetModOnly() {
// TODO Auto-generated method stub
return false;
}
}