use of de.slikey.effectlib.util.ParticleEffect in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
Player player = (sender instanceof Player) ? (Player) sender : null;
String permissionKey = "wand";
if (commandName.contains("wandp")) {
permissionKey = "wandp";
if (args.length > 0) {
player = DeprecatedUtils.getPlayer(args[0]);
}
if (args.length == 1) {
options.addAll(api.getPlayerNames());
return options;
} else if (args.length > 1) {
args = Arrays.copyOfRange(args, 1, args.length);
}
}
if (args.length == 1) {
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "add");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "remove");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "name");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "fill");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "configure");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "override");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "organize");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "alphabetize");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "combine");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "upgrade");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "describe");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "enchant");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "create");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "destroy");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "duplicate");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "restore");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unlock");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "bind");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unbind");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "save");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "delete");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "levelspells");
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
addIfPermissible(sender, options, "Magic.create.", wandKey);
}
}
if (args.length == 2) {
String subCommand = args[0];
String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand;
if (!api.hasPermission(sender, subCommandPNode)) {
return options;
}
subCommandPNode += ".";
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
for (String key : BaseMagicProperties.PROPERTY_KEYS) {
options.add(key);
}
for (String damageType : api.getController().getDamageTypes()) {
options.add("protection." + damageType);
options.add("strength." + damageType);
options.add("weakness." + damageType);
}
}
if (subCommand.equalsIgnoreCase("override")) {
Collection<SpellTemplate> spellList = api.getController().getSpellTemplates(true);
String partial = args[1];
if (partial.indexOf('.') > 0) {
String[] pieces = StringUtils.split(partial, '.');
String spellKey = pieces[0];
SpellTemplate spell = api.getController().getSpellTemplate(spellKey);
if (spell != null) {
List<String> spellOptions = new ArrayList<>();
spell.getParameters(spellOptions);
for (String option : spellOptions) {
options.add(spellKey + "." + option);
}
}
} else {
for (SpellTemplate spell : spellList) {
String spellKey = spell.getKey();
if (api.hasPermission(sender, subCommandPNode + spellKey)) {
options.add(spellKey + ".");
}
}
}
}
if (subCommand.equalsIgnoreCase("remove")) {
Wand activeWand = null;
if (player != null) {
Mage mage = controller.getMage(player);
activeWand = mage.getActiveWand();
}
if (activeWand != null) {
Collection<String> spellNames = activeWand.getSpells();
for (String spellName : spellNames) {
options.add(spellName);
}
options.add("brush");
}
}
if (subCommand.equalsIgnoreCase("combine")) {
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".combine.", wandKey, true);
}
}
if (subCommand.equalsIgnoreCase("delete")) {
File wandFolder = new File(api.getController().getConfigFolder(), "wands");
if (wandFolder.exists()) {
File[] files = wandFolder.listFiles();
for (File file : files) {
if (file.getName().endsWith(".yml")) {
options.add(file.getName().replace(".yml", ""));
}
}
}
}
}
if (args.length == 3) {
String subCommand = args[0];
String subCommand2 = args[1];
String commandPNode = "Magic.commands." + permissionKey + "." + subCommand;
if (!api.hasPermission(sender, commandPNode)) {
return options;
}
if (subCommand.equalsIgnoreCase("override")) {
String[] pieces = StringUtils.split(subCommand2, '.');
if (pieces.length > 1) {
String spellKey = pieces[0];
String argument = pieces[1];
SpellTemplate spell = api.getSpellTemplate(spellKey);
if (spell != null) {
spell.getParameterOptions(options, argument);
}
}
}
if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("upgrade")) {
if (subCommand2.equals("effect_sound")) {
Sound[] sounds = Sound.values();
for (Sound sound : sounds) {
options.add(sound.name().toLowerCase());
}
} else if (subCommand2.equals("effect_particle")) {
ParticleEffect[] particleTypes = ParticleEffect.values();
for (ParticleEffect particleType : particleTypes) {
options.add(particleType.name().toLowerCase());
}
} else if (subCommand2.equals("mode")) {
for (WandMode mode : WandMode.values()) {
options.add(mode.name().toLowerCase());
}
} else if (subCommand2.equals("left_click") || subCommand2.equals("right_click") || subCommand2.equals("drop") || subCommand2.equals("swap")) {
for (WandAction action : WandAction.values()) {
options.add(action.name().toLowerCase());
}
}
}
String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand + "." + subCommand2;
if (!api.hasPermission(sender, subCommandPNode)) {
return options;
}
boolean isBrushCommand = subCommand2.equalsIgnoreCase("material") || subCommand2.equalsIgnoreCase("brush");
if (subCommand.equalsIgnoreCase("remove") && isBrushCommand) {
Wand activeWand = null;
if (player != null) {
Mage mage = controller.getMage(player);
activeWand = mage.getActiveWand();
}
if (activeWand != null) {
Collection<String> materialNames = activeWand.getBrushes();
for (String materialName : materialNames) {
options.add(materialName);
}
}
}
if (subCommand.equalsIgnoreCase("add") && isBrushCommand) {
options.addAll(api.getBrushes());
}
}
return options;
}
use of de.slikey.effectlib.util.ParticleEffect 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 de.slikey.effectlib.util.ParticleEffect in project MagicPlugin by elBukkit.
the class EffectPlayer method performEffects.
@SuppressWarnings("deprecation")
protected void performEffects(DynamicLocation source, DynamicLocation target) {
Location sourceLocation = source == null ? null : source.getLocation();
if (sourceLocation == null)
return;
Entity sourceEntity = source == null ? null : source.getEntity();
if (requireEntity && sourceEntity == null)
return;
if (effectLib != null && effectLibConfig != null) {
EffectLibPlay play = new EffectLibPlay(effectLib.play(effectLibConfig, this, source, target, parameterMap));
if (currentEffects != null) {
currentEffects.add(play);
}
}
if (effect != null) {
int data = effectData == null ? 0 : effectData;
if ((effect == Effect.STEP_SOUND) && effectData == null) {
Material material = getWorkingMaterial().getMaterial();
// Check for potential bad materials, this can get really hairy (client crashes)
if (!material.isSolid()) {
return;
}
data = material.getId();
}
sourceLocation.getWorld().playEffect(sourceLocation, effect, data);
}
if (entityEffect != null && sourceEntity != null) {
sourceEntity.playEffect(entityEffect);
}
if (sound != null) {
if (broadcastSound) {
sound.play(plugin, sourceLocation);
} else if (sourceEntity != null) {
sound.play(plugin, sourceEntity);
}
}
if (fireworkEffect != null) {
EffectUtils.spawnFireworkEffect(plugin.getServer(), sourceLocation, fireworkEffect, fireworkPower, fireworkSilent);
}
if (particleType != null) {
ParticleEffect useEffect = overrideParticle(particleType);
Material material = getWorkingMaterial().getMaterial();
Byte blockData = getWorkingMaterial().getBlockData();
ParticleEffect.ParticleData data = useEffect.getData(material, blockData);
if (data != null) {
try {
useEffect.display(data, sourceLocation, getColor1(), PARTICLE_RANGE, particleXOffset, particleYOffset, particleZOffset, particleData, particleCount);
} catch (Exception ex) {
if (effectLib.isDebugEnabled()) {
ex.printStackTrace();
}
}
} else {
if (!useEffect.requiresData()) {
try {
useEffect.display(data, sourceLocation, getColor1(), PARTICLE_RANGE, particleXOffset, particleYOffset, particleZOffset, particleData, particleCount);
} catch (Exception ex) {
if (effectLib.isDebugEnabled()) {
ex.printStackTrace();
}
}
}
}
}
}
use of de.slikey.effectlib.util.ParticleEffect in project EffectLib by Slikey.
the class DnaEffect method onRun.
@Override
public void onRun() {
Location location = getLocation();
for (int j = 0; j < particlesHelix; j++) {
if (step * grow > length) {
step = 0;
}
for (int i = 0; i < 2; i++) {
double angle = step * radials + Math.PI * i;
Vector v = new Vector(Math.cos(angle) * radius, step * grow, Math.sin(angle) * radius);
drawParticle(location, v, particleHelix, colorHelix);
}
if (step % baseInterval == 0) {
for (int i = -particlesBase; i <= particlesBase; i++) {
if (i == 0) {
continue;
}
ParticleEffect particle = particleBase1;
Color color = colorBase1;
if (i < 0) {
particle = particleBase2;
color = colorBase2;
}
double angle = step * radials;
Vector v = new Vector(Math.cos(angle), 0, Math.sin(angle)).multiply(radius * i / particlesBase).setY(step * grow);
drawParticle(location, v, particle, color);
}
}
step++;
}
}
Aggregations