Created
June 22, 2017 15:28
-
-
Save TheMasteredPanda/dcf978836b2db2df9a1ed6b9b4276e76 to your computer and use it in GitHub Desktop.
This file contains 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
public class AddCommand extends MCommand | |
{ | |
private Locale locale = null; | |
private DataManager dataManager = null; | |
private HCBooster instance = null; | |
private MainConfig config = null; | |
public AddCommand(HCBooster instance) | |
{ | |
super(instance, "add", "hcbooster.admin", "Command to add a booster to the players", false); | |
this.locale = instance.getLocale(); | |
this.dataManager = instance.getDataManager(); | |
this.instance = instance; | |
this.config = instance.getMainConfig(); | |
this.addArgumentField(new ArgumentField("booster", "money")); | |
this.addArgumentField(new ArgumentField("duration", "500")); | |
this.addArgumentField(new ArgumentField("multiplier", "2")); | |
this.addArgumentField(new ArgumentField("id", "dwankdnawkdnkawndkwa-id")); | |
this.addArgumentField(new ArgumentField("name")); | |
} | |
@Override | |
public CommandResponse execute(CommandSender commandSender, MCommand mCommand, LinkedList<String> linkedList) | |
{ | |
Package.BoosterType type = null; | |
for (Package.BoosterType bType : Package.BoosterType.values()) { | |
if (!bType.name().equalsIgnoreCase(linkedList.get(0))) { | |
continue; | |
} | |
type = bType; | |
} | |
if (type == null) { | |
return new CommandResponse(commandSender, CommandResponse.ResponseType.FAILURE, Format.color(Format.replace(this.locale.get("Messages.Commands.BoosterTypeNotFound", "{prefix} &cBooster type was not found."), pairs)), null); | |
} | |
int duration; | |
List<Pair> newPairs = Lists.newArrayList(pairs); | |
if (!NumberUtils.parseable(Integer.class, linkedList.get(1))) { | |
newPairs.add(Pair.make("{argument}", this.getArgumentFields().get(1).getField())); | |
return new CommandResponse(commandSender, CommandResponse.ResponseType.FAILURE, Format.color(Format.replace(this.locale.get("Messages.Commands.NotANumber", "{prefix} &cArgument {argument} needs to be a number"), newPairs.toArray(new Pair[newPairs.size()]))), null); | |
} | |
duration = NumberUtils.parse(Integer.class, linkedList.get(1)); | |
double multiplier; | |
if (!NumberUtils.parseable(Double.class, linkedList.get(2))) { | |
newPairs.add(Pair.make("{argument}", this.getArgumentFields().get(2).getField())); | |
return new CommandResponse(commandSender, CommandResponse.ResponseType.FAILURE, Format.color(Format.replace(this.locale.get("Messages.Commands.NotANumber", "{prefix} Argument {argument} needs to be a number"), (Pair[]) Lists.newArrayList(pairs, Pair.make("{argument}", this.getArgumentFields().get(3).getField())).toArray())), null); | |
} | |
multiplier = NumberUtils.parse(Double.class, linkedList.get(2)); | |
if (this.instance.activePackages.containsKey(linkedList.get(3)) || this.config.isBoosterPackage(linkedList.get(3))) { | |
newPairs.add(Pair.make("{id}", linkedList.get(3))); | |
return new CommandResponse(commandSender, CommandResponse.ResponseType.FAILURE, Format.color(Format.replace(this.locale.get("Messages.Commands.IDInUse", "{prefix} &cID {id} is already in use"), newPairs.toArray(new Pair[newPairs.size()]))), null); | |
} | |
Package boosterPackage = new Package(linkedList.get(3), linkedList.get(4) != null ? linkedList.get(4).replace("-", " ") : linkedList.get(3), type, duration, multiplier); | |
this.dataManager.addBooster(boosterPackage); | |
return new CommandResponse(commandSender, CommandResponse.ResponseType.SUCCESS, null, null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment