Re-did how OnCommand works in AliPresents

Removed CommandSender sender for all Player and Mod Commands, replaced
with Player player
This commit is contained in:
alisolarflare 2016-11-24 21:48:10 -05:00
parent 1554f3f2f0
commit 63a6c775a4
24 changed files with 213 additions and 245 deletions

View file

@ -1,11 +1,6 @@
package alisolarflare.components;
import org.bukkit.command.CommandSender;
public abstract class ModCommand extends BaseCommand{
@Override
public abstract boolean OnCommand(CommandSender sender, String alias, String[] args);
public abstract class ModCommand extends PlayerCommand{
@Override
public String[] GetHelpText(String alias){
@ -15,12 +10,6 @@ public abstract class ModCommand extends BaseCommand{
};
}
@Override
public boolean GetPlayerOnly() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean GetModOnly() {
// TODO Auto-generated method stub

View file

@ -1,6 +1,14 @@
package alisolarflare.components;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public abstract class PlayerCommand extends BaseCommand{
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args){
return OnCommand((Player) sender, alias, args);
}
public abstract boolean OnCommand(Player player, String alias, String[] args);
@Override
public boolean GetPlayerOnly() {
// TODO Auto-generated method stub

View file

@ -1,15 +1,15 @@
package alisolarflare.components.bankchest;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
public class CreateBankChest extends ModCommand {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
public boolean OnCommand(Player player, String alias, String[] args) {
// TODO Auto-generated method stub
return false;
}
}
}

View file

@ -3,7 +3,6 @@ package alisolarflare.components.creativeboundaries.commands;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.PlayerCommand;
@ -18,13 +17,7 @@ public class Cbgm0 extends PlayerCommand{
}
@Override
public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) {
if (!(sender instanceof Player)){
sender.sendMessage("You must be a player to use this command!");
return false;
}
Player player = (Player) sender;
public boolean OnCommand(Player player, String arg2, String[] arg3) {
player.setGameMode(GameMode.SURVIVAL);
cbCreatives.remove(player);
return true;

View file

@ -3,7 +3,6 @@ package alisolarflare.components.creativeboundaries.commands;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
@ -24,10 +23,7 @@ public class Cbgm1 extends PlayerCommand {
}
@Override
public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String arg2, String[] arg3) {
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
if (tb == null) {

View file

@ -1,13 +1,13 @@
package alisolarflare.components.easyuhc.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
public class ActivatePowers extends ModCommand{
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
public boolean OnCommand(Player player, String alias, String[] args) {
return false;
}
}

View file

@ -1,6 +1,5 @@
package alisolarflare.components.flairdoor.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.PlayerCommand;
@ -13,9 +12,9 @@ public class FlairMe extends PlayerCommand {
this.component = flairDoorComponent;
}
@Override
public boolean OnCommand(CommandSender sender, String label, String[] args) {
component.playersToBeFlaired.add((Player) sender);
sender.sendMessage("Setup Successful! Walk through a portal to get your flair");
public boolean OnCommand(Player player, String label, String[] args) {
component.playersToBeFlaired.add(player);
player.sendMessage("Setup Successful! Walk through a portal to get your flair");
return true;
}
@Override

View file

@ -1,6 +1,5 @@
package alisolarflare.components.gpowers.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.PlayerCommand;
@ -15,8 +14,7 @@ public class GPower extends PlayerCommand {
}
@Override
public boolean OnCommand(CommandSender sender, String label, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String label, String[] args) {
if (args.length < 2) {
player.sendMessage("Proper Usage to test G-Powers:");
player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple] [active=true/false]");

View file

@ -1,7 +1,6 @@
package alisolarflare.components.insurance;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
@ -11,9 +10,7 @@ public class getInsurance extends ModCommand {
private final int defaultAmount = 1;
private final InsuranceType defaultInsuranceType = InsuranceType.Block;
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
int amount = defaultAmount;
InsuranceType insuranceType = defaultInsuranceType;

View file

@ -1,7 +1,6 @@
package alisolarflare.components.insurance;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
@ -10,8 +9,7 @@ import alisolarflare.components.insurance.Insurance.InsuranceType;
public class getInsuranceBar extends ModCommand {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length > 0 && StringUtils.isNumeric(args[0])){
player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Ingot, Integer.parseInt(args[0])));
}else{

View file

@ -1,7 +1,6 @@
package alisolarflare.components.insurance;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
@ -10,8 +9,7 @@ import alisolarflare.components.insurance.Insurance.InsuranceType;
public class getInsuranceBlock extends ModCommand {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length > 0 && StringUtils.isNumeric(args[0])){
player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Block, Integer.parseInt(args[0])));
}else{

View file

@ -1,7 +1,6 @@
package alisolarflare.components.insurance;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
@ -10,8 +9,7 @@ import alisolarflare.components.insurance.Insurance.InsuranceType;
public class getInsuranceNugget extends ModCommand {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length > 0 && StringUtils.isNumeric(args[0])){
player.getInventory().addItem(Insurance.getInsurance(InsuranceType.Nugget, Integer.parseInt(args[0])));
}else{

View file

@ -1,6 +1,5 @@
package alisolarflare.components.magic.tricks;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
@ -11,12 +10,7 @@ public class BoomBowRule extends ModCommand{
public static boolean endCrystal;
public static boolean localized;;
@Override
public boolean OnCommand(CommandSender sender, String label, String[] args) {
if (sender instanceof Player == false){
sender.sendMessage("You must be a player to use this command");
return false;
}
Player player = (Player) sender;
public boolean OnCommand(Player player, String label, String[] args) {
if (player.getName().equals("alisolarflare") == false){
player.sendMessage("You must be alisolarflare to use this command");
return false;

View file

@ -1,6 +1,5 @@
package alisolarflare.components.metrics.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
@ -15,11 +14,13 @@ public class GetLoginMetrics extends ModCommand{
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
for (String metric : module.metricsList){
player.sendMessage(metric);
}
if (args.length < 1){
return true;
}
return true;
}
}

View file

@ -1,6 +1,6 @@
package alisolarflare.components.minigames.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.PlayerCommand;
import alisolarflare.components.minigames.MinigameComponent;
@ -13,17 +13,17 @@ public class JoinMinigame extends PlayerCommand {
}
@Override
public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) {
String name = sender.getName();
public boolean OnCommand(Player player, String arg2, String[] arg3) {
String name = player.getName();
if (module.fighters.contains(name)) {
sender.sendMessage("You are already in the minigame!");
player.sendMessage("You are already in the minigame!");
return true;
}
module.fighters.add(name);
if (module.fighters.contains(name)) {
sender.sendMessage("You have joined the minigame!");
player.sendMessage("You have joined the minigame!");
}
return true;
}

View file

@ -1,6 +1,5 @@
package alisolarflare.components.minigames.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.PlayerCommand;
@ -15,21 +14,21 @@ public class LeaveMinigame extends PlayerCommand {
}
@Override
public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) {
if(!(sender instanceof Player))
sender.sendMessage("You must be a player to use this command!");
public boolean OnCommand(Player player, String arg2, String[] arg3) {
if(!(player instanceof Player))
player.sendMessage("You must be a player to use this command!");
String name = sender.getName();
String name = player.getName();
if (!(module.fighters.contains(name))) {
sender.sendMessage("You are not fighting!");
player.sendMessage("You are not fighting!");
return true;
}
while(module.fighters.contains(name)){
module.fighters.remove(name);
}
sender.sendMessage("You have left the fighters category!");
player.sendMessage("You have left the fighters category!");
return true;
}

View file

@ -1,6 +1,6 @@
package alisolarflare.components.minigames.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.PlayerCommand;
import alisolarflare.components.minigames.MinigameComponent;
@ -13,8 +13,8 @@ public class ListFighters extends PlayerCommand {
}
@Override
public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) {
sender.sendMessage(lobby.fighters.toString());
public boolean OnCommand(Player player, String arg2, String[] arg3) {
player.sendMessage(lobby.fighters.toString());
return true;
}
@Override

View file

@ -1,55 +1,55 @@
package graveyard.autouhc.idle;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
import graveyard.autouhc.memory.UHCMatch;
/**
* This class handles the specific command /addToUHC which, in-game, adds a player to a specific UltraHardcore match, that is defined by the constructor: {@linkplain #AddToUHC(UHCMatch)}
*
* @author Alisolarflare
*/
/**@deprecated*/
public class AddToUHC extends ModCommand {
private UHCMatch match;
public AddToUHC(UHCMatch match) {
this.match = match;
}
@Override
public boolean OnCommand(CommandSender sender, String label, String[] args) {
// INPUT SANITATION
Player player = (Player) sender;
if (!player.getName().equalsIgnoreCase("alisolarflare") && !player.getName().equalsIgnoreCase("Arsen_Derby_FTW")) {
sender.sendMessage("You must be Ali to add someone else to a UHC, send her a message to change the permissions");
return false;
}
if (args.length <= 1) {
sender.sendMessage("You must supply at least one playername");
}
switch(match.getMatchState()){
case IDLE:
case WAITING:
case SETUP:
case INTRO:
// Adds players to memory
sender.sendMessage("Adding Players to matchList!");
for (int i = 0; i > args.length; i++) {
match.getPlayerList().add(args[i]);
}sender.sendMessage("Finished!");
case PEACE:
case TENSION:
case POWER:
case END:
sender.sendMessage("There is already a match going on!");
}
return false;
}
}
//package graveyard.autouhc.idle;
//
//import org.bukkit.command.CommandSender;
//import org.bukkit.entity.Player;
//
//import alisolarflare.components.ModCommand;
//import graveyard.autouhc.memory.UHCMatch;
//
///**
// * This class handles the specific command /addToUHC which, in-game, adds a player to a specific UltraHardcore match, that is defined by the constructor: {@linkplain #AddToUHC(UHCMatch)}
// *
// * @author Alisolarflare
// */
///**@deprecated*/
//public class AddToUHC extends ModCommand {
// private UHCMatch match;
//
// public AddToUHC(UHCMatch match) {
// this.match = match;
// }
//
// @Override
// public boolean OnCommand(CommandSender sender, String label, String[] args) {
// // INPUT SANITATION
// Player player = (Player) sender;
// if (!player.getName().equalsIgnoreCase("alisolarflare") && !player.getName().equalsIgnoreCase("Arsen_Derby_FTW")) {
// sender.sendMessage("You must be Ali to add someone else to a UHC, send her a message to change the permissions");
// return false;
// }
// if (args.length <= 1) {
// sender.sendMessage("You must supply at least one playername");
// }
//
// switch(match.getMatchState()){
// case IDLE:
// case WAITING:
// case SETUP:
// case INTRO:
// // Adds players to memory
// sender.sendMessage("Adding Players to matchList!");
// for (int i = 0; i > args.length; i++) {
// match.getPlayerList().add(args[i]);
// }sender.sendMessage("Finished!");
// case PEACE:
// case TENSION:
// case POWER:
// case END:
// sender.sendMessage("There is already a match going on!");
// }
//
//
//
// return false;
// }
//}

View file

@ -1,48 +1,48 @@
package graveyard.autouhc.idle;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.ModCommand;
import graveyard.autouhc.memory.UHCMatch;
/**@deprecated*/
public class JoinUHC extends ModCommand{
private UHCMatch match;
public JoinUHC(UHCMatch match) {
this.match = match;
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
player.sendMessage("Adding you to the UltraHardcore match!");
switch(match.getMatchState()){
//Before the game
case IDLE:
case WAITING:
case SETUP:
case INTRO:
player.sendMessage("Adding you to the UltraHardcore match!");
match.getPlayerList().add(player.getName());
break;
//During the game
case PEACE:
case TENSION:
case POWER:
player.sendMessage("There is currently an UltraHardcore match going on! #POINTTOSPECTATORMODE, tell Ali asap if you see this");
//After the game
case END:
player.sendMessage("There is currently an ending ceremony going on! #POINTTOCEREMONY, tell Ali ASAP if you see this");
}
return false;
}
}
//package graveyard.autouhc.idle;
//
//import org.bukkit.command.CommandSender;
//import org.bukkit.entity.Player;
//
//import alisolarflare.components.ModCommand;
//import graveyard.autouhc.memory.UHCMatch;
///**@deprecated*/
//public class JoinUHC extends ModCommand{
//
// private UHCMatch match;
//
// public JoinUHC(UHCMatch match) {
// this.match = match;
// }
//
// @Override
// public boolean OnCommand(CommandSender sender, String alias, String[] args) {
// if (!(sender instanceof Player))
// return false;
// Player player = (Player) sender;
// player.sendMessage("Adding you to the UltraHardcore match!");
// switch(match.getMatchState()){
//
// //Before the game
// case IDLE:
// case WAITING:
// case SETUP:
// case INTRO:
// player.sendMessage("Adding you to the UltraHardcore match!");
// match.getPlayerList().add(player.getName());
// break;
//
// //During the game
// case PEACE:
// case TENSION:
// case POWER:
// player.sendMessage("There is currently an UltraHardcore match going on! #POINTTOSPECTATORMODE, tell Ali asap if you see this");
//
// //After the game
// case END:
// player.sendMessage("There is currently an ending ceremony going on! #POINTTOCEREMONY, tell Ali ASAP if you see this");
//
// }
//
// return false;
// }
//}

View file

@ -1,19 +1,19 @@
package graveyard.autouhc.intro;
import org.bukkit.command.CommandSender;
import alisolarflare.components.ModCommand;
import graveyard.autouhc.memory.UHCMatch;
/**@deprecated*/
public class ConfigureMatch extends ModCommand{
public ConfigureMatch(UHCMatch match) {
// TODO Auto-generated constructor stub
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
// TODO Auto-generated method stub
return false;
}
}
//package graveyard.autouhc.intro;
//
//import org.bukkit.command.CommandSender;
//
//import alisolarflare.components.ModCommand;
//import graveyard.autouhc.memory.UHCMatch;
///**@deprecated*/
//public class ConfigureMatch extends ModCommand{
//
// public ConfigureMatch(UHCMatch match) {
// // TODO Auto-generated constructor stub
// }
//
// @Override
// public boolean OnCommand(CommandSender sender, String alias, String[] args) {
// // TODO Auto-generated method stub
// return false;
// }
//}

View file

@ -1,5 +1,5 @@
package graveyard.autouhc.intro;
/**@deprecated*/
public class IntroductionCutscene {
//TODO: Teleport all players to the area.
}
//package graveyard.autouhc.intro;
///**@deprecated*/
//public class IntroductionCutscene {
// //TODO: Teleport all players to the area.
//}

View file

@ -1,19 +1,19 @@
package graveyard.autouhc.listeners;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
/**
* Main launcher for the repeating task that activates the
* ghostie powers if an Ultrahardcore Match is going on,
* and it's time for powers to activate
*/
/**@deprecated*/
public class MatchCyclingListener implements Listener {
public BukkitTask PowerCyclingTask;
public MatchCyclingListener(JavaPlugin plugin){
PowerCyclingTask = (new MatchMainLoop()).runTaskTimer(plugin, 20, 20);
}
}
//package graveyard.autouhc.listeners;
//
//import org.bukkit.event.Listener;
//import org.bukkit.plugin.java.JavaPlugin;
//import org.bukkit.scheduler.BukkitTask;
//
///**
// * Main launcher for the repeating task that activates the
// * ghostie powers if an Ultrahardcore Match is going on,
// * and it's time for powers to activate
// */
///**@deprecated*/
//public class MatchCyclingListener implements Listener {
// public BukkitTask PowerCyclingTask;
//
// public MatchCyclingListener(JavaPlugin plugin){
// PowerCyclingTask = (new MatchMainLoop()).runTaskTimer(plugin, 20, 20);
// }
//}

View file

@ -1,12 +1,12 @@
package graveyard.autouhc.listeners;
import org.bukkit.scheduler.BukkitRunnable;
/**@deprecated*/
public class MatchMainLoop extends BukkitRunnable{
@Override
public void run() {
}
}
//package graveyard.autouhc.listeners;
//
//import org.bukkit.scheduler.BukkitRunnable;
///**@deprecated*/
//public class MatchMainLoop extends BukkitRunnable{
// @Override
// public void run() {
//
// }
//
//
//}

View file

@ -1,12 +1,12 @@
package graveyard.autouhc.memory;
/**@deprecated*/
public enum MatchState {
IDLE, //Idle: Configure Match, Wait: Schedule Match, Intro: Start Match
WAITING, //SETUP: Scheduled Time, INTRO: No Setup
SETUP, //INTRO: Done
INTRO, //Peace: Done, and players ready
PEACE, //Tension: Timer, End: All dead
TENSION, //Power: Timer, End: All dead
POWER, //End: All dead
END//IDLE: Ceremony over
}
//package graveyard.autouhc.memory;
///**@deprecated*/
//public enum MatchState {
// IDLE, //Idle: Configure Match, Wait: Schedule Match, Intro: Start Match
// WAITING, //SETUP: Scheduled Time, INTRO: No Setup
// SETUP, //INTRO: Done
// INTRO, //Peace: Done, and players ready
// PEACE, //Tension: Timer, End: All dead
// TENSION, //Power: Timer, End: All dead
// POWER, //End: All dead
// END//IDLE: Ceremony over
//}