Skip to content

Commit 1aa55ee

Browse files
Merge pull request #171 from Dans-Plugins/ponder-integration
Ponder integration
2 parents d346a57 + 5751ab1 commit 1aa55ee

File tree

9 files changed

+179
-138
lines changed

9 files changed

+179
-138
lines changed
80.1 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mvn install:install-file -Dfile=<path> -DgroupId=preponderous -DartifactId=ponder -Dversion=<version> -Dpackaging=Jar

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,11 @@
7070
<version>1.13.1-R0.1-SNAPSHOT</version>
7171
<scope>provided</scope>
7272
</dependency>
73+
<dependency>
74+
<groupId>preponderous</groupId>
75+
<artifactId>ponder</artifactId>
76+
<version>v0.15-alpha-2</version>
77+
<scope>compile</scope>
78+
</dependency>
7379
</dependencies>
7480
</project>
Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package dansplugins.recipesystem;
22

33
import dansplugins.recipesystem.bstats.Metrics;
4-
import dansplugins.recipesystem.services.LocalCommandService;
4+
import dansplugins.recipesystem.commands.DefaultCommand;
5+
import dansplugins.recipesystem.commands.GetCommand;
6+
import dansplugins.recipesystem.commands.HelpCommand;
7+
import dansplugins.recipesystem.commands.ListItemsCommand;
58
import dansplugins.recipesystem.utils.RecipeRegistry;
69
import org.bukkit.command.Command;
710
import org.bukkit.command.CommandSender;
8-
import org.bukkit.plugin.java.JavaPlugin;
11+
import preponderous.ponder.minecraft.bukkit.PonderMC;
12+
import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand;
13+
import preponderous.ponder.minecraft.bukkit.abs.PonderBukkitPlugin;
14+
import preponderous.ponder.minecraft.bukkit.services.CommandService;
915

10-
public final class MoreRecipes extends JavaPlugin {
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
1118

19+
public final class MoreRecipes extends PonderBukkitPlugin {
1220
private static MoreRecipes instance;
13-
14-
// version
15-
public final String version = "v1.5";
21+
public final String version = "v1.6-alpha-1";
22+
private final CommandService commandService = new CommandService((PonderMC) getPonder());
1623

1724
public static MoreRecipes getInstance() {
1825
return instance;
@@ -21,21 +28,51 @@ public static MoreRecipes getInstance() {
2128
@Override
2229
public void onEnable() {
2330
instance = this;
24-
2531
RecipeRegistry.getInstance().registerRecipes();
26-
27-
// bStats
28-
int pluginId = 12140;
29-
Metrics metrics = new Metrics(this, pluginId);
32+
handlebStatsIntegration();
33+
initializeCommandService();
3034
}
3135

3236
@Override
3337
public void onDisable() {
3438

3539
}
3640

41+
/**
42+
* This method handles commands sent to the minecraft server and interprets them if the label matches one of the core commands.
43+
* @param sender The sender of the command.
44+
* @param cmd The command that was sent. This is unused.
45+
* @param label The core command that has been invoked.
46+
* @param args Arguments of the core command. Often sub-commands.
47+
* @return A boolean indicating whether the execution of the command was successful.
48+
*/
49+
@Override
3750
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
38-
LocalCommandService localCommandService = new LocalCommandService();
39-
return localCommandService.interpretCommand(sender, label, args);
51+
if (args.length == 0) {
52+
DefaultCommand defaultCommand = new DefaultCommand();
53+
return defaultCommand.execute(sender);
54+
}
55+
return commandService.interpretAndExecuteCommand(sender, label, args);
56+
}
57+
58+
public String getVersion() {
59+
return version;
60+
}
61+
62+
private void handlebStatsIntegration() {
63+
int pluginId = 12140;
64+
new Metrics(this, pluginId);
65+
}
66+
67+
/**
68+
* Initializes Ponder's command service with the plugin's commands.
69+
*/
70+
private void initializeCommandService() {
71+
ArrayList<AbstractPluginCommand> commands = new ArrayList<AbstractPluginCommand>(Arrays.asList(
72+
new HelpCommand(),
73+
new GetCommand(),
74+
new ListItemsCommand()
75+
));
76+
commandService.initialize(commands, "That command wasn't found.");
4077
}
41-
}
78+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dansplugins.recipesystem.commands;
2+
3+
import dansplugins.recipesystem.MoreRecipes;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.command.CommandSender;
6+
import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand;
7+
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
11+
/**
12+
* @author Daniel McCoy Stephenson
13+
*/
14+
public class DefaultCommand extends AbstractPluginCommand {
15+
16+
public DefaultCommand() {
17+
super(new ArrayList<>(Arrays.asList("default")), new ArrayList<>(Arrays.asList("morerecipes.default")));
18+
}
19+
20+
@Override
21+
public boolean execute(CommandSender commandSender) {
22+
commandSender.sendMessage(ChatColor.AQUA + "More Recipes " + MoreRecipes.getInstance().getVersion());
23+
commandSender.sendMessage(ChatColor.AQUA + "Developed by: Daniel Stephenson");
24+
commandSender.sendMessage(ChatColor.AQUA + "Wiki: https://github.com/Dans-Plugins/More-Recipes/wiki");
25+
return true;
26+
}
27+
28+
@Override
29+
public boolean execute(CommandSender commandSender, String[] strings) {
30+
return execute(commandSender);
31+
}
32+
}

src/main/java/dansplugins/recipesystem/commands/GetCommand.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,54 @@
55
import org.bukkit.command.CommandSender;
66
import org.bukkit.entity.Player;
77
import org.bukkit.inventory.ItemStack;
8+
import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand;
89

9-
public class GetCommand {
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
1012

11-
public void execute(CommandSender sender, String[] args) {
13+
public class GetCommand extends AbstractPluginCommand {
1214

13-
if (sender instanceof Player) {
14-
15-
Player player = (Player) sender;
15+
public GetCommand() {
16+
super(new ArrayList<>(Arrays.asList("get")), new ArrayList<>(Arrays.asList("morerecipes.get")));
17+
}
1618

17-
if (player.hasPermission("morerecipes.get") || player.hasPermission("morerecipes.admin")) {
19+
@Override
20+
public boolean execute(CommandSender commandSender) {
21+
commandSender.sendMessage(ChatColor.RED + "Usage: /morerecipes get (itemName) (amount)");
22+
return false;
23+
}
1824

19-
if (args.length > 2) {
25+
@Override
26+
public boolean execute(CommandSender sender, String[] args) {
27+
if (!(sender instanceof Player)) {
28+
sender.sendMessage("This command can't be used in the console.");
29+
return false;
30+
}
2031

21-
String itemToGet = args[1];
22-
int amount = Integer.parseInt(args[2]);
32+
Player player = (Player) sender;
2333

24-
ItemStack item = LocalItemStackService.getInstance().getItemStack(itemToGet, amount);
34+
if (args.length < 2) {
35+
player.sendMessage(ChatColor.RED + "Usage: /morerecipes get (itemName) (amount)");
36+
}
2537

26-
if (item != null) {
27-
// add to player's inventory
28-
// if player's inventory has space
29-
if (player.getInventory().firstEmpty() != -1) {
30-
player.getInventory().addItem(item);
31-
player.sendMessage(ChatColor.GREEN + "" + itemToGet + " created.");
32-
}
33-
else { // player's inventory is full
34-
player.sendMessage(ChatColor.RED + "Inventory full.");
35-
}
36-
}
37-
else {
38-
player.sendMessage(ChatColor.RED + "That isn't an item in More Recipes!");
39-
}
38+
String itemToGet = args[1];
39+
int amount = Integer.parseInt(args[2]);
4040

41-
}
42-
else {
43-
player.sendMessage(ChatColor.RED + "Usage: /morerecipes get (itemName) (amount)");
44-
}
41+
ItemStack item = LocalItemStackService.getInstance().getItemStack(itemToGet, amount);
4542

46-
}
47-
else {
48-
player.sendMessage(ChatColor.RED + "Sorry! In order to use this command, you need the following permission: 'morerecipes.get'");
49-
}
43+
if (item == null) {
44+
player.sendMessage(ChatColor.RED + "That isn't an item in More Recipes!");
45+
}
5046

47+
// add to player's inventory
48+
// if player's inventory has space
49+
if (player.getInventory().firstEmpty() == -1) {
50+
player.sendMessage(ChatColor.RED + "Inventory full.");
51+
return false;
5152
}
5253

54+
player.getInventory().addItem(item);
55+
player.sendMessage(ChatColor.GREEN + "" + itemToGet + " created.");
56+
return true;
5357
}
54-
55-
}
58+
}

src/main/java/dansplugins/recipesystem/commands/HelpCommand.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,32 @@
33
import org.bukkit.ChatColor;
44
import org.bukkit.command.CommandSender;
55
import org.bukkit.entity.Player;
6+
import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand;
67

7-
public class HelpCommand {
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
810

9-
public void execute(CommandSender sender) {
10-
if (sender instanceof Player) {
11-
Player player = (Player) sender;
12-
if (!player.hasPermission("morerecipes.help")) {
13-
sender.sendMessage(ChatColor.RED + "You don't have permission to use this command.");
14-
return;
15-
}
11+
public class HelpCommand extends AbstractPluginCommand {
12+
13+
public HelpCommand() {
14+
super(new ArrayList<>(Arrays.asList("help")), new ArrayList<>(Arrays.asList("morerecipes.help")));
15+
}
16+
17+
@Override
18+
public boolean execute(CommandSender sender) {
19+
if (!(sender instanceof Player)) {
20+
sender.sendMessage("This command can't be used in the console.");
21+
return false;
1622
}
23+
sender.sendMessage(ChatColor.AQUA + "=== More Recipes Commands ===");
1724
sender.sendMessage(ChatColor.AQUA + "/mr help - View a list of helpful commands.");
1825
sender.sendMessage(ChatColor.AQUA + "/mr listitems - List the items that can be crafted.");
1926
sender.sendMessage(ChatColor.AQUA + "/mr get (name) (amount) - Get an certain amount of a specified item.");
27+
return true;
2028
}
2129

22-
}
30+
@Override
31+
public boolean execute(CommandSender commandSender, String[] strings) {
32+
return execute(commandSender);
33+
}
34+
}

src/main/java/dansplugins/recipesystem/commands/ListItemsCommand.java

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,42 @@
22

33
import org.bukkit.ChatColor;
44
import org.bukkit.command.CommandSender;
5-
import org.bukkit.entity.Player;
5+
import preponderous.ponder.minecraft.bukkit.abs.AbstractPluginCommand;
66

7-
public class ListItemsCommand {
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
89

9-
public void execute(CommandSender sender) {
10+
public class ListItemsCommand extends AbstractPluginCommand {
1011

11-
if (sender instanceof Player) {
12-
13-
Player player = (Player) sender;
14-
15-
if (player.hasPermission("morerecipes.listitems") || player.hasPermission("morerecipes.default")) {
16-
17-
// title
18-
player.sendMessage(ChatColor.AQUA + " == More Recipes - Items == ");
19-
20-
// items
21-
player.sendMessage(ChatColor.AQUA + "BlazeRod");
22-
player.sendMessage(ChatColor.AQUA + "ChainmailBoots");
23-
player.sendMessage(ChatColor.AQUA + "ChainmailChestplate");
24-
player.sendMessage(ChatColor.AQUA + "ChainmailHelmet");
25-
player.sendMessage(ChatColor.AQUA + "ChainmailLeggings");
26-
player.sendMessage(ChatColor.AQUA + "Cobweb");
27-
player.sendMessage(ChatColor.AQUA + "DiamondHorseArmor");
28-
player.sendMessage(ChatColor.AQUA + "GoldenHorseArmor");
29-
player.sendMessage(ChatColor.AQUA + "GrassBlock");
30-
player.sendMessage(ChatColor.AQUA + "Gunpowder");
31-
player.sendMessage(ChatColor.AQUA + "IronHorseArmor");
32-
player.sendMessage(ChatColor.AQUA + "Lead");
33-
player.sendMessage(ChatColor.AQUA + "NameTag");
34-
player.sendMessage(ChatColor.AQUA + "Saddle");
35-
player.sendMessage(ChatColor.AQUA + "SlimeBall");
36-
player.sendMessage(ChatColor.AQUA + "String");
37-
player.sendMessage(ChatColor.AQUA + "TotemOfUndying");
38-
39-
}
40-
else {
41-
player.sendMessage(ChatColor.RED + "Sorry! In order to use this command, you need the following permission: 'morerecipes.listitems'");
42-
}
12+
public ListItemsCommand() {
13+
super(new ArrayList<>(Arrays.asList("list")), new ArrayList<>(Arrays.asList("morerecipes.list")));
14+
}
4315

44-
}
16+
public boolean execute(CommandSender sender) {
17+
sender.sendMessage(ChatColor.AQUA + " == Items provided by More Recipes == ");
18+
sender.sendMessage(ChatColor.AQUA + "BlazeRod");
19+
sender.sendMessage(ChatColor.AQUA + "ChainmailBoots");
20+
sender.sendMessage(ChatColor.AQUA + "ChainmailChestplate");
21+
sender.sendMessage(ChatColor.AQUA + "ChainmailHelmet");
22+
sender.sendMessage(ChatColor.AQUA + "ChainmailLeggings");
23+
sender.sendMessage(ChatColor.AQUA + "Cobweb");
24+
sender.sendMessage(ChatColor.AQUA + "DiamondHorseArmor");
25+
sender.sendMessage(ChatColor.AQUA + "GoldenHorseArmor");
26+
sender.sendMessage(ChatColor.AQUA + "GrassBlock");
27+
sender.sendMessage(ChatColor.AQUA + "Gunpowder");
28+
sender.sendMessage(ChatColor.AQUA + "IronHorseArmor");
29+
sender.sendMessage(ChatColor.AQUA + "Lead");
30+
sender.sendMessage(ChatColor.AQUA + "NameTag");
31+
sender.sendMessage(ChatColor.AQUA + "Saddle");
32+
sender.sendMessage(ChatColor.AQUA + "SlimeBall");
33+
sender.sendMessage(ChatColor.AQUA + "String");
34+
sender.sendMessage(ChatColor.AQUA + "TotemOfUndying");
35+
return true;
36+
}
4537

38+
@Override
39+
public boolean execute(CommandSender commandSender, String[] strings) {
40+
return execute(commandSender);
4641
}
4742

4843
}

src/main/java/dansplugins/recipesystem/services/LocalCommandService.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)