use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.
the class ConfigurationUtils method replaceParameters.
@Nullable
public static ConfigurationSection replaceParameters(ConfigurationSection configuration, ConfigurationSection parameters) {
if (configuration == null)
return null;
ConfigurationSection replaced = new MemoryConfiguration();
Map<String, Object> map = NMSUtils.getMap(configuration);
for (Map.Entry<String, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value == null)
continue;
Object replacement = replaceParameters(value, parameters);
if (replacement != null) {
replaced.set(entry.getKey(), replacement);
}
}
return replaced;
}
use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.
the class MultiplyAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
multiply = parameters.getInt("multiply", parameters.getInt("repeat", 2));
multiplied = new ArrayList<>();
ActionHandler base = getHandler("actions");
if (base != null) {
ConfigurationSection initialParameters = ConfigurationUtils.getConfigurationSection(parameters, "first");
if (initialParameters != null) {
ConfigurationSection combined = ConfigurationUtils.addConfigurations(new MemoryConfiguration(), parameters);
initialParameters = ConfigurationUtils.addConfigurations(combined, initialParameters);
}
for (int i = 0; i < multiply; i++) {
ActionHandler handler = (ActionHandler) base.clone();
if (i == 0 && initialParameters != null) {
handler.prepare(context, initialParameters);
} else {
handler.prepare(context, parameters);
}
multiplied.add(handler);
}
}
}
use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.
the class MagicCitizensTrait method perform.
@Override
public boolean perform(net.citizensnpcs.api.event.NPCRightClickEvent event) {
if (spellKey == null || spellKey.isEmpty())
return false;
CommandSender sender = event.getClicker();
Entity entity = event.getClicker();
ConfigurationSection config = this.parameters;
if (npcCaster) {
if (event.getNPC().isSpawned()) {
entity = event.getNPC().getEntity();
if (!messagePlayer) {
sender = null;
}
if (targetPlayer) {
config = new MemoryConfiguration();
ConfigurationUtils.addConfigurations(config, parameters);
config.set("player", event.getClicker().getName());
}
}
}
return api.cast(spellKey, config, sender, entity);
}
use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.
the class EffectLibManager method play.
@Nullable
public Effect play(ConfigurationSection configuration, EffectPlayer player, DynamicLocation origin, DynamicLocation target, Map<String, String> parameterMap) {
if (parameterMap == null) {
parameterMap = new HashMap<>();
}
Entity originEntity = origin == null ? null : origin.getEntity();
if (originEntity != null && originEntity instanceof Player) {
parameterMap.put("$name", ((Player) originEntity).getName());
} else if (originEntity != null && originEntity instanceof LivingEntity) {
parameterMap.put("$name", ((LivingEntity) originEntity).getCustomName());
} else {
parameterMap.put("$name", "Unknown");
}
Entity targetEntity = target == null ? null : target.getEntity();
if (targetEntity != null && targetEntity instanceof Player) {
parameterMap.put("$target", ((Player) targetEntity).getName());
} else if (originEntity != null && targetEntity instanceof LivingEntity) {
parameterMap.put("$target", ((LivingEntity) targetEntity).getCustomName());
} else {
parameterMap.put("$target", "Unknown");
}
Effect effect = null;
String effectClass = configuration.getString("class");
ParticleEffect particleEffect = player.overrideParticle(null);
String effectOverride = player.getParticleOverrideName();
if (effectOverride != null && effectOverride.isEmpty())
effectOverride = null;
String colorOverrideName = player.getColorOverrideName();
if (colorOverrideName != null && colorOverrideName.isEmpty())
colorOverrideName = null;
ConfigurationSection parameters = configuration;
Color colorOverride = player.getColor1();
if ((colorOverrideName != null && colorOverride != null) || (effectOverride != null && particleEffect != null)) {
parameters = new MemoryConfiguration();
Collection<String> keys = configuration.getKeys(false);
for (String key : keys) {
parameters.set(key, configuration.get(key));
}
if (effectOverride != null && particleEffect != null) {
parameters.set(effectOverride, particleEffect.name());
}
if (colorOverride != null && colorOverrideName != null) {
String hexColor = Integer.toHexString(colorOverride.asRGB());
parameters.set(colorOverrideName, hexColor);
}
}
try {
effect = effectManager.start(effectClass, parameters, origin, target, parameterMap);
if (!parameters.contains("material")) {
MaterialAndData mat = player.getWorkingMaterial();
if (mat != null) {
effect.material = mat.getMaterial();
effect.materialData = mat.getBlockData();
}
}
} catch (Throwable ex) {
Bukkit.getLogger().warning("Error playing effects of class: " + effectClass);
ex.printStackTrace();
}
return effect;
}
use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.
the class BaseSpell method cast.
@Override
public boolean cast(String[] extraParameters, Location defaultLocation) {
ConfigurationSection parameters = null;
if (extraParameters != null && extraParameters.length > 0) {
parameters = new MemoryConfiguration();
ConfigurationUtils.addParameters(extraParameters, parameters);
}
return cast(parameters, defaultLocation);
}
Aggregations