2018-09-26 02:07:46 -06:00
|
|
|
package com.esophose.playerparticles.command;
|
|
|
|
|
2018-10-05 21:01:28 -06:00
|
|
|
import java.util.ArrayList;
|
2018-09-26 02:07:46 -06:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-09-29 17:27:37 -06:00
|
|
|
import org.bukkit.Material;
|
2018-10-05 21:01:28 -06:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.StringUtil;
|
2018-09-29 17:27:37 -06:00
|
|
|
|
2018-10-05 17:25:13 -06:00
|
|
|
import com.esophose.playerparticles.manager.DataManager;
|
2018-09-29 17:27:37 -06:00
|
|
|
import com.esophose.playerparticles.manager.LangManager;
|
2018-10-05 21:01:28 -06:00
|
|
|
import com.esophose.playerparticles.manager.LangManager.Lang;
|
2018-09-29 17:27:37 -06:00
|
|
|
import com.esophose.playerparticles.manager.PermissionManager;
|
2018-09-26 02:07:46 -06:00
|
|
|
import com.esophose.playerparticles.particles.PPlayer;
|
2018-09-29 17:27:37 -06:00
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
|
2018-10-05 17:25:13 -06:00
|
|
|
import com.esophose.playerparticles.particles.ParticleGroup;
|
|
|
|
import com.esophose.playerparticles.particles.ParticlePair;
|
2018-09-29 17:27:37 -06:00
|
|
|
import com.esophose.playerparticles.styles.api.ParticleStyle;
|
2018-10-30 03:17:23 -06:00
|
|
|
import com.esophose.playerparticles.styles.api.ParticleStyleManager;
|
2018-09-29 17:27:37 -06:00
|
|
|
import com.esophose.playerparticles.util.ParticleUtils;
|
2018-09-26 02:07:46 -06:00
|
|
|
|
|
|
|
public class AddCommandModule implements CommandModule {
|
|
|
|
|
2018-09-27 18:16:50 -06:00
|
|
|
public void onCommandExecute(PPlayer pplayer, String[] args) {
|
2018-09-29 17:27:37 -06:00
|
|
|
if (args.length < 2) {
|
|
|
|
CommandModule.printUsage(pplayer, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-30 03:17:23 -06:00
|
|
|
int maxParticlesAllowed = PermissionManager.getMaxParticlesAllowed(pplayer.getPlayer());
|
|
|
|
if (pplayer.getActiveParticles().size() >= maxParticlesAllowed) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.ADD_REACHED_MAX, maxParticlesAllowed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-13 16:38:01 -06:00
|
|
|
ParticleEffect effect = ParticleEffect.fromName(args[0]);
|
2018-09-29 17:27:37 -06:00
|
|
|
if (effect == null) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.EFFECT_INVALID, args[0]);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
} else if (!PermissionManager.hasEffectPermission(pplayer.getPlayer(), effect)) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.EFFECT_NO_PERMISSION, effect.getName());
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 02:38:12 -06:00
|
|
|
ParticleStyle style = ParticleStyle.fromName(args[1]);
|
2018-09-29 17:27:37 -06:00
|
|
|
if (style == null) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.STYLE_INVALID, args[1]);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
} else if (!PermissionManager.hasStylePermission(pplayer.getPlayer(), style)) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.STYLE_NO_PERMISSION, args[1]);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material itemData = null;
|
|
|
|
Material blockData = null;
|
|
|
|
OrdinaryColor colorData = null;
|
|
|
|
NoteColor noteColorData = null;
|
|
|
|
|
|
|
|
if (args.length > 2) {
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
|
|
|
if (effect == ParticleEffect.NOTE) {
|
|
|
|
if (args[2].equalsIgnoreCase("rainbow")) {
|
|
|
|
noteColorData = new NoteColor(99);
|
2018-11-07 20:06:08 -07:00
|
|
|
} else if (args[2].equalsIgnoreCase("random")) {
|
|
|
|
noteColorData = new NoteColor(98);
|
2018-09-29 17:27:37 -06:00
|
|
|
} else {
|
2019-04-28 00:17:08 -06:00
|
|
|
int note;
|
2018-09-29 17:27:37 -06:00
|
|
|
try {
|
|
|
|
note = Integer.parseInt(args[2]);
|
|
|
|
} catch (Exception e) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_NOTE);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-07 03:21:46 -07:00
|
|
|
if (note < 0 || note > 24) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_NOTE);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
noteColorData = new NoteColor(note);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (args[2].equalsIgnoreCase("rainbow")) {
|
|
|
|
colorData = new OrdinaryColor(999, 999, 999);
|
2018-11-07 20:06:08 -07:00
|
|
|
} else if (args[2].equalsIgnoreCase("random")) {
|
|
|
|
colorData = new OrdinaryColor(998, 998, 998);
|
2018-09-29 17:27:37 -06:00
|
|
|
} else {
|
2019-04-28 00:17:08 -06:00
|
|
|
int r, g, b;
|
2018-09-29 17:27:37 -06:00
|
|
|
|
|
|
|
try {
|
|
|
|
r = Integer.parseInt(args[2]);
|
|
|
|
g = Integer.parseInt(args[3]);
|
|
|
|
b = Integer.parseInt(args[4]);
|
|
|
|
} catch (Exception e) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_COLOR);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_COLOR);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-09-29 17:27:37 -06:00
|
|
|
colorData = new OrdinaryColor(r, g, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
|
|
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
|
|
|
|
try {
|
|
|
|
blockData = ParticleUtils.closestMatch(args[2]);
|
2018-10-16 02:38:12 -06:00
|
|
|
if (blockData == null || !blockData.isBlock()) throw new Exception();
|
2018-09-29 17:27:37 -06:00
|
|
|
} catch (Exception e) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_BLOCK);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (effect == ParticleEffect.ITEM) {
|
|
|
|
try {
|
|
|
|
itemData = ParticleUtils.closestMatch(args[2]);
|
2018-10-16 02:38:12 -06:00
|
|
|
if (itemData == null || itemData.isBlock()) throw new Exception();
|
2018-09-29 17:27:37 -06:00
|
|
|
} catch (Exception e) {
|
2018-10-01 22:23:05 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_ITEM);
|
2018-09-29 17:27:37 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 21:01:28 -06:00
|
|
|
|
|
|
|
ParticleGroup group = pplayer.getActiveParticleGroup();
|
2019-04-28 00:17:08 -06:00
|
|
|
ParticlePair newParticle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, itemData, blockData, colorData, noteColorData);
|
2018-10-05 21:01:28 -06:00
|
|
|
group.getParticles().add(newParticle);
|
|
|
|
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
|
|
|
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.ADD_PARTICLE_APPLIED, newParticle.getEffect().getName(), newParticle.getStyle().getName(), newParticle.getDataString());
|
2018-10-30 03:17:23 -06:00
|
|
|
|
|
|
|
if (ParticleStyleManager.isCustomHandled(newParticle.getStyle())) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.STYLE_EVENT_SPAWNING_INFO, newParticle.getStyle().getName());
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
|
2018-10-05 21:01:28 -06:00
|
|
|
Player p = pplayer.getPlayer();
|
2019-04-28 00:17:08 -06:00
|
|
|
List<String> matches = new ArrayList<>();
|
2018-10-06 13:53:31 -06:00
|
|
|
|
2018-10-05 21:01:28 -06:00
|
|
|
if (args.length <= 1) { // Effect name
|
2018-11-07 03:21:46 -07:00
|
|
|
if (args.length == 0) matches = PermissionManager.getEffectNamesUserHasPermissionFor(p);
|
|
|
|
else StringUtil.copyPartialMatches(args[0], PermissionManager.getEffectNamesUserHasPermissionFor(p), matches);
|
2018-10-05 21:01:28 -06:00
|
|
|
} else if (args.length == 2) { // Style name
|
2018-11-07 03:21:46 -07:00
|
|
|
StringUtil.copyPartialMatches(args[1], PermissionManager.getStyleNamesUserHasPermissionFor(p), matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
} else { // Data
|
2018-10-05 21:01:28 -06:00
|
|
|
ParticleEffect effect = ParticleEffect.fromName(args[0]);
|
|
|
|
if (effect != null) {
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
2019-04-28 00:17:08 -06:00
|
|
|
List<String> possibleValues = new ArrayList<>();
|
2018-10-05 21:01:28 -06:00
|
|
|
if (effect == ParticleEffect.NOTE) { // Note data
|
|
|
|
if (args.length == 3) {
|
2018-11-07 03:21:46 -07:00
|
|
|
possibleValues.add("<0-24>");
|
2018-10-05 21:01:28 -06:00
|
|
|
possibleValues.add("rainbow");
|
2018-11-07 20:06:08 -07:00
|
|
|
possibleValues.add("random");
|
2018-10-05 21:01:28 -06:00
|
|
|
}
|
|
|
|
} else { // Color data
|
2018-11-07 20:06:08 -07:00
|
|
|
if (args.length <= 5 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
|
2018-10-05 21:01:28 -06:00
|
|
|
possibleValues.add("<0-255>");
|
|
|
|
}
|
2018-11-07 20:06:08 -07:00
|
|
|
if (args.length <= 4 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
|
2018-10-05 21:01:28 -06:00
|
|
|
possibleValues.add("<0-255> <0-255>");
|
|
|
|
}
|
|
|
|
if (args.length <= 3) {
|
|
|
|
possibleValues.add("<0-255> <0-255> <0-255>");
|
|
|
|
possibleValues.add("rainbow");
|
2018-11-07 20:06:08 -07:00
|
|
|
possibleValues.add("random");
|
2018-10-05 21:01:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
|
|
|
|
} else if (args.length == 3 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
|
|
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
|
2019-04-28 00:17:08 -06:00
|
|
|
StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches);
|
2018-10-05 21:01:28 -06:00
|
|
|
} else if (effect == ParticleEffect.ITEM) { // Item material
|
2019-04-28 00:17:08 -06:00
|
|
|
StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches);
|
2018-10-05 21:01:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return "add";
|
|
|
|
}
|
|
|
|
|
2018-09-29 17:27:37 -06:00
|
|
|
public Lang getDescription() {
|
2018-10-01 22:23:05 -06:00
|
|
|
return Lang.COMMAND_DESCRIPTION_ADD;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getArguments() {
|
|
|
|
return "<effect> <style> [data]";
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean requiresEffects() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-26 02:07:46 -06:00
|
|
|
}
|