Skip to content

Commit

Permalink
Added support for command execution from console and changed version
Browse files Browse the repository at this point in the history
  • Loading branch information
nik2143 committed Oct 5, 2020
1 parent af244f5 commit d255d43
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.nik2143</groupId>
<artifactId>CustomGapple</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>

<name>CustomGapple</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.nik2143.customgapple.CustomGapple;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -14,6 +15,7 @@
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand All @@ -28,84 +30,91 @@ public CustomGappleCommand (CustomGapple plugin){
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("customgapple")) {
Player player = null;
if (!(sender instanceof Player)) {
sender.sendMessage("[CustomGapple] You can't use this command from console");
return true;
if (args.length == 0 || args.length == 1 || args.length == 2){
sender.sendMessage("Wrong sintax. Use /customgapple <Player> <EffectsNumbers> <Effects> [Levels] [Durations] [Amount] [Enchanted (true/false)]");
return true;
}
if (Bukkit.getPlayerExact(args[0])!=null){
player = Bukkit.getPlayerExact(args[0]);
ArrayList<String> argslist = new ArrayList<>(Arrays.asList(args));
argslist.remove(0);
args = argslist.toArray(new String[argslist.size()]);
} else {
sender.sendMessage("Player "+ args[0] +" isn't online");
}
} else {
if (args.length == 0 || args.length == 1){
sender.sendMessage("Wrong sintax. Use /customgapple <EffectsNumbers> <Effects> [Levels] [Durations] [Amount] [Enchanted (true/false)]");
return true;
}
player = (Player) sender;
}
if (!sender.isOp() || !sender.hasPermission("customgapple.use")) {
sender.sendMessage("[CustomGapple] You haven't permissions to use this command");
return true;
}
Player player = (Player) sender;
switch (args.length) {
case 0:
sender.sendMessage("Wrong sintax. Use /customgapple <EffectsNumbers> <Effects> [Levels] [Durations] [Amount] [Enchanted (true/false)]");
return true;
case 1:
sender.sendMessage("Wrong sintax. Use /customgapple <EffectsNumber> <Effects> [Levels] [Durations] [Amount] [Enchanted (true/false)]");
if (!NumberUtils.isNumber(args[0])){
sender.sendMessage(args[0] + " isn't a number");
return true;
}
List<PotionEffectType> effects = new ArrayList<>();
List<Integer> levels = new ArrayList<>();
List<Integer> durations = new ArrayList<>();
boolean enchantedGapple = false;
int effectsnumber = Integer.parseInt(args[0]);
if (args.length < effectsnumber+1) {
sender.sendMessage("The number of effects is wrong");
return true;
}
for (int i = 0; i < effectsnumber; i++){
if (PotionEffectType.getByName(args[i+1])!=null){
effects.add(PotionEffectType.getByName(args[i+1]));
} else {
sender.sendMessage("Effect " + args[i+1] + " doesn't exist");
return true;
default:
if (!NumberUtils.isNumber(args[0])){
sender.sendMessage(args[0] + " isn't a number");
return true;
}
List<PotionEffectType> effects = new ArrayList<>();
List<Integer> levels = new ArrayList<>();
List<Integer> durations = new ArrayList<>();
boolean enchantedGapple = false;
int effectsnumber = Integer.parseInt(args[0]);
if (args.length < effectsnumber+1) {
sender.sendMessage("The number of effects is wrong");
}
}
if (args.length >= effectsnumber * 2 + 1) {
for (int i = 0; i < effectsnumber; i++){
if (NumberUtils.isNumber(args[i+effectsnumber+1])){
levels.add(Integer.valueOf(args[i+effectsnumber+1]));
} else {
sender.sendMessage(args[i+effectsnumber+1] + " isn't a number");
return true;
}
for (int i = 0; i < effectsnumber; i++){
if (PotionEffectType.getByName(args[i+1])!=null){
effects.add(PotionEffectType.getByName(args[i+1]));
} else {
sender.sendMessage("Effect " + args[i+1] + " doesn't exist");
return true;
}
}
if (args.length >= effectsnumber * 2 + 1) {
for (int i = 0; i < effectsnumber; i++){
if (NumberUtils.isNumber(args[i+effectsnumber+1])){
levels.add(Integer.valueOf(args[i+effectsnumber+1]));
} else {
sender.sendMessage(args[i+effectsnumber+1] + " isn't a number");
return true;
}
}
}else {
for (int i = 0; i<effectsnumber;i++){
levels.add(1);
}
}
if (args.length >= effectsnumber * 3 + 1){
for (int i = 0; i < effectsnumber; i++){
if (NumberUtils.isNumber(args[i+effectsnumber*2+1])){
durations.add(Integer.valueOf(args[i+effectsnumber*2+1]));
} else {
sender.sendMessage(args[i+effectsnumber+1] + " isn't a number");
return true;
}
}
}else {
for (int i = 0; i < effectsnumber; i++){
durations.add(plugin.getConfig().getInt("Default-Duration"));
}
}
if (args.length >= effectsnumber * 3 + 3){
enchantedGapple = Boolean.parseBoolean(args[effectsnumber * 3 + 2]);
}
if (args.length >= effectsnumber * 3 + 2){
if (!NumberUtils.isNumber(args[effectsnumber * 3 + 1])){
sender.sendMessage(args[effectsnumber * 3 + 1] + " isn't a number");
return true;
}
player.getInventory().addItem(CreateGapple(effectsnumber, effects, levels, durations, Integer.parseInt(args[effectsnumber * 3 + 1 ]),enchantedGapple));
}
}else {
for (int i = 0; i<effectsnumber;i++){
levels.add(1);
}
}
if (args.length >= effectsnumber * 3 + 1){
for (int i = 0; i < effectsnumber; i++){
if (NumberUtils.isNumber(args[i+effectsnumber*2+1])){
durations.add(Integer.valueOf(args[i+effectsnumber*2+1]));
} else {
player.getInventory().addItem(CreateGapple(effectsnumber, effects, levels, durations, plugin.getConfig().getInt("Default-Amount"),enchantedGapple));
sender.sendMessage(args[i+effectsnumber+1] + " isn't a number");
return true;
}
}
}else {
for (int i = 0; i < effectsnumber; i++){
durations.add(plugin.getConfig().getInt("Default-Duration"));
}
}
if (args.length >= effectsnumber * 3 + 3){
enchantedGapple = Boolean.parseBoolean(args[effectsnumber * 3 + 2]);
}
if (args.length >= effectsnumber * 3 + 2){
if (!NumberUtils.isNumber(args[effectsnumber * 3 + 1])){
sender.sendMessage(args[effectsnumber * 3 + 1] + " isn't a number");
return true;
}
player.getInventory().addItem(CreateGapple(effectsnumber, effects, levels, durations, Integer.parseInt(args[effectsnumber * 3 + 1 ]),enchantedGapple));
} else {
player.getInventory().addItem(CreateGapple(effectsnumber, effects, levels, durations, plugin.getConfig().getInt("Default-Amount"),enchantedGapple));
}
return true;
}
Expand All @@ -116,6 +125,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (command.getName().equalsIgnoreCase("customgapple")){
List<String> autocomplete = new ArrayList<>();
if (!(sender instanceof Player)){
return Collections.emptyList();
}
if (args.length > 1 && NumberUtils.isNumber(args[0]) && args.length < Integer.parseInt(args[0]) + 2){
for (PotionEffectType effect : PotionEffectType.values()){
if(effect == null) {
Expand Down

0 comments on commit d255d43

Please sign in to comment.