Added Command, Message, and Sound Triggers for crafting stations.

Examples:
message{format="&aHello %player%... "}
command{format="say Hello %player%"}
sound{sound=BLOCK_ANVIL_USE;volume=1;pitch=1}
This commit is contained in:
Ethan 2020-07-29 02:32:38 -04:00
parent 66b6077a77
commit a963dde0a0
5 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,21 @@
package net.Indyuce.mmoitems.api.crafting.trigger;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.MMOLineConfig;
import org.bukkit.Bukkit;
public class CommandTrigger extends Trigger {
private final String command;
public CommandTrigger(MMOLineConfig config) {
super("command");
config.validate("format");
command = config.getString("format");
}
@Override
public void whenCrafting(PlayerData data) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("%player%", data.getPlayer().getName()));
}
}

View File

@ -0,0 +1,23 @@
package net.Indyuce.mmoitems.api.crafting.trigger;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.MMOLineConfig;
import org.bukkit.Bukkit;
public class MessageTrigger extends Trigger {
private final String message;
public MessageTrigger(MMOLineConfig config) {
super("message");
config.validate("format");
message = config.getString("format");
}
@Override
public void whenCrafting(PlayerData data) {
data.getPlayer().sendMessage(MMOItems.plugin.getPlaceholderParser().parse(data.getPlayer(),
message.replace("%player%", data.getPlayer().getName())));
}
}

View File

@ -0,0 +1,25 @@
package net.Indyuce.mmoitems.api.crafting.trigger;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.api.MMOLineConfig;
import org.bukkit.Sound;
public class SoundTrigger extends Trigger {
private final Sound sound;
private final float vol, pitch;
public SoundTrigger(MMOLineConfig config) {
super("sound");
config.validate("sound");
sound = Sound.valueOf(config.getString("sound").toUpperCase().replace("-", "_"));
vol = config.contains("volume") ? (float) config.getDouble("volume") : 1f;
pitch = config.contains("pitch") ? (float) config.getDouble("pitch") : 1f;
}
@Override
public void whenCrafting(PlayerData player) {
player.getPlayer().playSound(player.getPlayer().getLocation(), sound, vol, pitch);
}
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.comp.parse.placeholders;
import net.asangarin.hexcolors.ColorParse;
import org.bukkit.OfflinePlayer;
import me.clip.placeholderapi.PlaceholderAPI;
@ -11,6 +12,6 @@ public class PlaceholderAPIParser implements PlaceholderParser {
@Override
public String parse(OfflinePlayer player, String string) {
return PlaceholderAPI.setPlaceholders(player, string.replace("%player%", player.getName()));
return new ColorParse('&', PlaceholderAPI.setPlaceholders(player, string.replace("%player%", player.getName()))).toChatColor();
}
}

View File

@ -12,6 +12,9 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Level;
import net.Indyuce.mmoitems.api.crafting.trigger.CommandTrigger;
import net.Indyuce.mmoitems.api.crafting.trigger.MessageTrigger;
import net.Indyuce.mmoitems.api.crafting.trigger.SoundTrigger;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.gson.JsonParser;
@ -49,6 +52,7 @@ public class CraftingManager {
private final Map<String, CraftingStation> stations = new HashMap<>();
public CraftingManager() {
// conditions
registerCondition("level", config -> new LevelCondition(config), new ConditionalDisplay("&a" + AltChar.check + " Requires Level #level#", "&c" + AltChar.cross + " Requires Level #level#"));
registerCondition("permission", config -> new PermissionCondition(config), null);
registerCondition("mana", config -> new ManaCondition(config), new ConditionalDisplay("&a" + AltChar.check + " Requires #mana# Mana", "&c" + AltChar.cross + " Requires #mana# Mana"));
@ -57,6 +61,12 @@ public class CraftingManager {
registerCondition("class", config -> new ClassCondition(config), new ConditionalDisplay("&a" + AltChar.check + " Required Class: #class#", "&c" + AltChar.cross + " Required Class: #class#"));
registerCondition("ingredient", config -> new IngredientCondition(), null);
// triggers
registerTrigger("command", config -> new CommandTrigger(config));
registerTrigger("message", config -> new MessageTrigger(config));
registerTrigger("sound", config -> new SoundTrigger(config));
// ingredients
registerIngredient("vanilla", config -> new VanillaIngredient(config), new ConditionalDisplay("&8" + AltChar.check + " &7#amount# #item#", "&c" + AltChar.cross + " &7#amount# #item#"), nbt -> true, item -> item.getItem().getType().name().toLowerCase() + "_" + (item.getItem().hasItemMeta() ? item.getItem().getItemMeta().getDisplayName() : null));
registerIngredient("mmoitem", config -> new MMOItemIngredient(config), new ConditionalDisplay("&8" + AltChar.check + " &7#amount# #level##item#", "&c" + AltChar.cross + " &7#amount# #level##item#"), nbt -> nbt.hasType(), item -> {
String upgradeString = item.getString("MMOITEMS_UPGRADE");