mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-23 02:25:26 +01:00
Added BarAPI support.
This commit is contained in:
parent
6a4d24df8a
commit
fd403803ca
@ -1,7 +1,7 @@
|
||||
name: ChestCommands
|
||||
main: com.gmail.filoghost.chestcommands.ChestCommands
|
||||
version: 3.0
|
||||
softdepend: [Vault]
|
||||
softdepend: [Vault, BarAPI]
|
||||
|
||||
commands:
|
||||
chestcommands:
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.MetricsLite;
|
||||
|
||||
import com.gmail.filoghost.chestcommands.SimpleUpdater.ResponseHandler;
|
||||
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||
import com.gmail.filoghost.chestcommands.command.CommandFramework;
|
||||
import com.gmail.filoghost.chestcommands.command.CommandHandler;
|
||||
@ -75,6 +76,10 @@ public class ChestCommands extends JavaPlugin {
|
||||
getLogger().info("Vault with a compatible economy plugin was not found! Icons with a PRICE or commands that give money will not work.");
|
||||
}
|
||||
|
||||
if (BarAPIBridge.setupPlugin()) {
|
||||
getLogger().info("Hooked BarAPI");
|
||||
}
|
||||
|
||||
String version = Utils.getBukkitVersion();
|
||||
try {
|
||||
Class<?> clazz = Class.forName("com.gmail.filoghost.chestcommands.nms." + version);
|
||||
|
@ -1,7 +1,34 @@
|
||||
package com.gmail.filoghost.chestcommands.bridge;
|
||||
|
||||
import me.confuser.barapi.BarAPI;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class BarAPIBridge {
|
||||
|
||||
// A big TODO
|
||||
private static BarAPI barAPI;
|
||||
|
||||
public static boolean setupPlugin() {
|
||||
Plugin barPlugin = Bukkit.getPluginManager().getPlugin("BarAPI");
|
||||
|
||||
if (barPlugin == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
barAPI = (BarAPI) barPlugin;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasValidPlugin() {
|
||||
return barAPI != null;
|
||||
}
|
||||
|
||||
public static void setMessage(Player player, String message, int seconds) {
|
||||
if (!hasValidPlugin()) throw new IllegalStateException("BarAPI plugin was not found!");
|
||||
|
||||
BarAPI.setMessage(player, message, seconds);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.gmail.filoghost.chestcommands.internal.icon.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||
|
||||
public class DragonBarIconCommand extends IconCommand {
|
||||
|
||||
String message;
|
||||
int seconds;
|
||||
|
||||
public DragonBarIconCommand(String command) {
|
||||
super(command);
|
||||
|
||||
seconds = 1;
|
||||
message = command;
|
||||
|
||||
String[] split = command.split("\\|", 2); // Max of 2 pieces.
|
||||
if (split.length > 1 && Utils.isValidPositiveInteger(split[0].trim())) {
|
||||
seconds = Integer.parseInt(split[0].trim());
|
||||
message = split[1].trim();
|
||||
}
|
||||
|
||||
message = Utils.addColors(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player) {
|
||||
if (BarAPIBridge.hasValidPlugin()) {
|
||||
BarAPIBridge.setMessage(player, message, seconds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.IconCommand;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.command.BroadcastIconCommand;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.command.ConsoleIconCommand;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.command.DragonBarIconCommand;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.command.GiveIconCommand;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.command.GiveMoneyIconCommand;
|
||||
import com.gmail.filoghost.chestcommands.internal.icon.command.OpIconCommand;
|
||||
@ -35,6 +36,7 @@ public class CommandSerializer {
|
||||
commandTypesMap.put(commandPattern("give:"), GiveIconCommand.class);
|
||||
commandTypesMap.put(commandPattern("give-?money:"), GiveMoneyIconCommand.class);
|
||||
commandTypesMap.put(commandPattern("sound:"), SoundIconCommand.class);
|
||||
commandTypesMap.put(commandPattern("dragon-?bar:"), DragonBarIconCommand.class);
|
||||
}
|
||||
|
||||
private static Pattern commandPattern(String regex) {
|
||||
@ -81,7 +83,7 @@ public class CommandSerializer {
|
||||
for (Entry<Pattern, Class<? extends IconCommand>> entry : commandTypesMap.entrySet()) {
|
||||
Matcher matcher = entry.getKey().matcher(input);
|
||||
if (matcher.find()) {
|
||||
|
||||
// Remove the command prefix.
|
||||
String cleanedCommand = matcher.replaceFirst("");
|
||||
|
||||
try {
|
||||
|
@ -187,6 +187,14 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidPositiveInteger(String input) {
|
||||
try {
|
||||
return Integer.parseInt(input) > 0;
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidShort(String input) {
|
||||
try {
|
||||
Short.parseShort(input);
|
||||
|
Loading…
Reference in New Issue
Block a user