Skip to content

Commit

Permalink
Allow commands in kits. Adds #15.
Browse files Browse the repository at this point in the history
Syntax is /<command> with the ability to add {player} as an argument.
  • Loading branch information
drtshock committed Apr 17, 2015
1 parent c22978c commit 555f151
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Essentials/src/com/earth2me/essentials/Kit.java
Expand Up @@ -9,6 +9,7 @@
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IEssentials;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -131,7 +132,7 @@ public long getNextUse(final User user) throws Exception {
delayTime.add(Calendar.MILLISECOND, (int) ((delay * 1000.0) % 1000.0));

if (lastTime == 0L || lastTime > time.getTimeInMillis()) {
// If we have no record of kit use, or its corrupted, give them benifit of the doubt.
// If we have no record of kit use, or its corrupted, give them benefit of the doubt.
return 0L;
} else if (delay < 0d) {
// If the kit has a negative kit time, it can only be used once.
Expand Down Expand Up @@ -188,6 +189,14 @@ public void expandItems(final User user, final List<String> items) throws Except
continue;
}

if(kitItem.startsWith("/")) {
String command = kitItem.substring(1);
String name = user.getName();
command = command.replace("{player}", name);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
continue;

This comment has been minimized.

Copy link
@khobbits

khobbits Jul 8, 2015

Contributor

I always find that firing other plugin commands, is best done as a scheduled task, rather than blocking ess until the command completes.
This also seems to fix confusing errors when the resulting command throws stack traces, and it shows as an ess stack trace.

}

final String[] parts = kitItem.split(" +");
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

Expand Down

0 comments on commit 555f151

Please sign in to comment.