Skip to content

Commit a582605

Browse files
Now using one single command for the whole plugin but with many options.
1 parent 3901525 commit a582605

6 files changed

Lines changed: 96 additions & 32 deletions

File tree

src/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ helper-removed: You have removed an helper.
5151
non-active-world: You need to set the world ${world} as active to continue.
5252
near-spawn-placing: You cannot place a block that near from the spawn.
5353
no-drop: You are not allowed to drop items.
54+
command-non-existing: Please enter a correct option. Try with the help option.
55+
command-help-message: |+
56+
ClutchesPractice Command
57+
Options:
58+
help: Shows this message
59+
summonhelper: Allows you to summon an helper
5460
try-again: Try again.
5561

5662
# prefix: The prefix to put on each message.

src/io/github/ascpialgroup/clp/ClutchesPracticePlugin.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import io.github.ascpialgroup.clp.configuration.LoadedConfiguration;
1919
import io.github.ascpialgroup.clp.configuration.Translations;
20-
import io.github.ascpialgroup.clp.listeners.CommandsHandler;
20+
import io.github.ascpialgroup.clp.listeners.CommandHandler;
21+
import io.github.ascpialgroup.clp.listeners.CommandTabCompleter;
2122
import io.github.ascpialgroup.clp.listeners.EventsHandlerClp;
2223

2324
public class ClutchesPracticePlugin extends JavaPlugin {
@@ -52,14 +53,16 @@ private void loadTranslations() {
5253
lTrans = new Translations();
5354
lTrans.prefix = loadTranslation("prefix", false);
5455
lTrans.noPermissions = loadTranslation("no-permission", true);
55-
lTrans.consoleSummoning = loadTranslation("console-summoning", false);
56+
lTrans.consoleSummoning = loadTranslation("console-summoning", true);
5657
lTrans.punchMe = loadTranslation("punch-me", false);
5758
lTrans.helperAdded = loadTranslation("helper-added", true);
5859
lTrans.helperRemoved = loadTranslation("helper-removed", true);
5960
lTrans.nonActiveWorld = loadTranslation("non-active-world", true);
6061
lTrans.nearSpawnPlacing = loadTranslation("near-spawn-placing", true);
6162
lTrans.tryAgain = loadTranslation("try-again", true);
6263
lTrans.noDropping = loadTranslation("no-drop", true);
64+
lTrans.commandNotExisting = loadTranslation("command-non-existing", true);
65+
lTrans.commandHelpMessage = loadTranslation("command-help-message", true);
6366
getLogger().log(Level.INFO, "Translations parsed.");
6467
}
6568

@@ -117,7 +120,8 @@ public void onEnable() {
117120
loadArmorStandsConf();
118121
cleanupUnusedRefs();
119122
Bukkit.getPluginManager().registerEvents(new EventsHandlerClp(this, lConfig, lTrans), this);
120-
getCommand("summonhelper").setExecutor(new CommandsHandler(this, lConfig, lTrans));
123+
getCommand("clutchespractice").setExecutor(new CommandHandler(this, lConfig, lTrans));
124+
getCommand("clutchespractice").setTabCompleter(new CommandTabCompleter());
121125
}
122126

123127
@Override

src/io/github/ascpialgroup/clp/configuration/Translations.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public class Translations {
1111
public String tryAgain;
1212
public String prefix;
1313
public String noDropping;
14+
public String commandNotExisting;
15+
public String commandHelpMessage;
1416
}

src/io/github/ascpialgroup/clp/listeners/CommandsHandler.java renamed to src/io/github/ascpialgroup/clp/listeners/CommandHandler.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,31 @@
1515
import io.github.ascpialgroup.clp.configuration.LoadedConfiguration;
1616
import io.github.ascpialgroup.clp.configuration.Translations;
1717

18-
public class CommandsHandler implements CommandExecutor {
18+
public class CommandHandler implements CommandExecutor {
1919
private ClutchesPracticePlugin referer;
2020
private LoadedConfiguration config;
2121
private Translations lTrans;
2222

23-
public CommandsHandler(ClutchesPracticePlugin referer, LoadedConfiguration config, Translations lTrans) {
23+
public CommandHandler(ClutchesPracticePlugin referer, LoadedConfiguration config, Translations lTrans) {
2424
this.referer = referer;
2525
this.config = config;
2626
this.lTrans = lTrans;
2727
}
2828

2929
@Override
30-
public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
31-
if (arg1.getName().equals("summonhelper")) {
32-
if (arg3.length == 0) {
33-
if (!(arg0 instanceof Player)) {
34-
arg0.sendMessage(lTrans.consoleSummoning);
30+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
31+
if (args.length < 1) {
32+
sender.sendMessage(lTrans.commandNotExisting);
33+
return true;
34+
}
35+
switch (args[0]) {
36+
case "summonhelper":
37+
if (sender.hasPermission("clp.summonhelper")) {
38+
if (!(sender instanceof Player)) {
39+
sender.sendMessage(lTrans.consoleSummoning);
3540
referer.getLogger().log(Level.INFO, "A non player has tried to summon an helper.");
3641
} else {
37-
Player ref = (Player) arg0;
42+
Player ref = (Player) sender;
3843
if (config.activeWorlds.contains(ref.getWorld().getName())) {
3944
ArmorStand a = (ArmorStand) ref.getWorld().spawnEntity(ref.getLocation(),
4045
EntityType.ARMOR_STAND);
@@ -48,15 +53,24 @@ public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[]
4853
a.setCustomName(lTrans.punchMe);
4954
a.setCustomNameVisible(true);
5055
referer.registerNewArmorStandIfNotExisting(a.getUniqueId());
51-
arg0.sendMessage(lTrans.helperAdded);
56+
sender.sendMessage(lTrans.helperAdded);
5257
referer.getLogger().log(Level.INFO, "An helper has been added.");
5358
} else {
54-
arg0.sendMessage(lTrans.nonActiveWorld.replace("${world}", ref.getWorld().getName()));
59+
sender.sendMessage(lTrans.nonActiveWorld.replace("${world}", ref.getWorld().getName()));
5560
referer.getLogger().log(Level.INFO, "Someone tried to summon an helper in a non active world.");
5661
}
5762

5863
}
64+
} else {
65+
sender.sendMessage(lTrans.noPermissions.replace("${perm}", "clp.summonhelper"));
5966
}
67+
break;
68+
case "help":
69+
sender.sendMessage(lTrans.commandHelpMessage);
70+
break;
71+
default:
72+
sender.sendMessage(lTrans.commandNotExisting);
73+
break;
6074
}
6175
return true;
6276
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.ascpialgroup.clp.listeners;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandSender;
8+
import org.bukkit.command.TabCompleter;
9+
10+
public class CommandTabCompleter implements TabCompleter {
11+
private List<String> allPossible;
12+
13+
public CommandTabCompleter() {
14+
allPossible = new ArrayList<>();
15+
allPossible.add("help");
16+
allPossible.add("summonhelper");
17+
}
18+
19+
@Override
20+
public List<String> onTabComplete(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
21+
22+
if (arg3.length == 1) {
23+
List<String> possible = new ArrayList<>();
24+
allPossible.forEach(option -> {
25+
if (option.startsWith(arg3[0]))
26+
possible.add(option);
27+
});
28+
return possible;
29+
}
30+
return allPossible;
31+
}
32+
33+
}

src/plugin.yml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
main: io.github.ascpialgroup.clp.ClutchesPracticePlugin
22
name: ClutchesPractice
3-
version: 1.0.1
3+
version: 1.0.2
44
description: This plugin adds a system to learn to clutch.
55
load: POSTWORLD
66
author: ASCPIAL Group
77
website: ascpialgroup.github.io
88

99
commands:
10-
summonhelper:
11-
description: This command summon the helper armor stand for practice.
12-
usage: /<command>
13-
permission: clp.summonhelper
14-
permission-message: Sorry, you need permission <permission> to do this.
15-
10+
clutchespractice:
11+
description: This command allows you to do everything with this plugin.
12+
usage: /<command>
13+
permission: clp.maincommand
14+
permission-message: Sorry, you need permission <permission> to do this.
15+
aliases:
16+
- clp
1617

1718
permissions:
18-
clp.*:
19-
description: Gives access to all clutches practice commands
20-
children:
21-
clp.summonhelper: true
22-
clp.removehelper: true
23-
clp.breakblocks: true
19+
clp.*:
20+
description: Gives access to all clutches practice commands.
21+
children:
22+
clp.summonhelper: true
23+
clp.removehelper: true
24+
clp.breakblocks: true
25+
clp.maincommand: true
2426
clp.summonhelper:
25-
description: Allows you to summon an helper armor stand
26-
default: op
27+
description: Allows you to summon an helper armor stand.
28+
default: op
2729
clp.removehelper:
28-
description: Allows you to remove an helper armor stand
29-
default: op
30+
description: Allows you to remove an helper armor stand.
31+
default: op
3032
clp.breakblocks:
31-
description: Allows you to break blocks in ClutchesPractice active worlds.
32-
default: op
33+
description: Allows you to break blocks in ClutchesPractice active worlds.
34+
default: op
35+
clp.maincommand:
36+
description: Allows you to use the main command of this plugin.
37+
default: op

0 commit comments

Comments
 (0)