2018-09-26 02:07:46 -06:00
|
|
|
package com.esophose.playerparticles.command;
|
|
|
|
|
2018-10-16 02:38:12 -06:00
|
|
|
import java.util.ArrayList;
|
2018-09-26 02:07:46 -06:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-10-16 02:38:12 -06:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.StringUtil;
|
|
|
|
|
|
|
|
import com.esophose.playerparticles.manager.DataManager;
|
|
|
|
import com.esophose.playerparticles.manager.LangManager;
|
|
|
|
import com.esophose.playerparticles.manager.PermissionManager;
|
2018-09-26 02:07:46 -06:00
|
|
|
import com.esophose.playerparticles.manager.LangManager.Lang;
|
|
|
|
import com.esophose.playerparticles.particles.PPlayer;
|
2018-10-16 02:38:12 -06:00
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleGroup;
|
|
|
|
import com.esophose.playerparticles.particles.ParticlePair;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
|
|
|
|
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
|
|
|
|
import com.esophose.playerparticles.styles.api.ParticleStyle;
|
|
|
|
import com.esophose.playerparticles.util.ParticleUtils;
|
2018-09-26 02:07:46 -06:00
|
|
|
|
|
|
|
public class EditCommandModule implements CommandModule {
|
|
|
|
|
2018-09-27 18:16:50 -06:00
|
|
|
public void onCommandExecute(PPlayer pplayer, String[] args) {
|
2018-10-16 02:38:12 -06:00
|
|
|
if (args.length < 3) {
|
|
|
|
CommandModule.printUsage(pplayer, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = -1;
|
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[0]);
|
|
|
|
} catch (Exception e) {
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.ID_INVALID);
|
2018-10-16 02:38:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id <= 0) {
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.ID_INVALID);
|
2018-10-16 02:38:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pplayer.getActiveParticle(id) == null) {
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.ID_UNKNOWN, id);
|
2018-10-16 02:38:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] cmdArgs = new String[args.length - 2];
|
|
|
|
for (int i = 2; i < args.length; i++) {
|
|
|
|
cmdArgs[i - 2] = args[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args[1].toLowerCase()) {
|
|
|
|
case "effect":
|
|
|
|
editEffect(pplayer, id, cmdArgs);
|
|
|
|
break;
|
|
|
|
case "style":
|
|
|
|
editStyle(pplayer, id, cmdArgs);
|
|
|
|
break;
|
|
|
|
case "data":
|
|
|
|
editData(pplayer, id, cmdArgs);
|
|
|
|
break;
|
|
|
|
default:
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.EDIT_INVALID_PROPERTY, args[1]);
|
2018-10-16 02:38:12 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the effect subcommand
|
|
|
|
*
|
|
|
|
* @param pplayer The PPlayer executing the command
|
|
|
|
* @param id The target particle ID
|
|
|
|
* @param args The rest of the args
|
|
|
|
*/
|
|
|
|
private void editEffect(PPlayer pplayer, int id, String[] args) {
|
|
|
|
ParticleEffect effect = ParticleEffect.fromName(args[0]);
|
|
|
|
if (effect == null) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.EFFECT_INVALID, args[0]);
|
|
|
|
return;
|
|
|
|
} else if (!PermissionManager.hasEffectPermission(pplayer.getPlayer(), effect)) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.EFFECT_NO_PERMISSION, effect.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParticleGroup group = pplayer.getActiveParticleGroup();
|
|
|
|
for (ParticlePair particle : group.getParticles()) {
|
|
|
|
if (particle.getId() == id) {
|
|
|
|
particle.setEffect(effect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.EDIT_SUCCESS_EFFECT, id, effect.getName());
|
2018-10-16 02:38:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the style subcommand
|
|
|
|
*
|
|
|
|
* @param pplayer The PPlayer executing the command
|
|
|
|
* @param id The target particle ID
|
|
|
|
* @param args The rest of the args
|
|
|
|
*/
|
|
|
|
private void editStyle(PPlayer pplayer, int id, String[] args) {
|
|
|
|
ParticleStyle style = ParticleStyle.fromName(args[0]);
|
|
|
|
if (style == null) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.STYLE_INVALID, args[0]);
|
|
|
|
return;
|
|
|
|
} else if (!PermissionManager.hasStylePermission(pplayer.getPlayer(), style)) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.STYLE_NO_PERMISSION, style.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParticleGroup group = pplayer.getActiveParticleGroup();
|
|
|
|
for (ParticlePair particle : group.getParticles()) {
|
|
|
|
if (particle.getId() == id) {
|
|
|
|
particle.setStyle(style);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.EDIT_SUCCESS_STYLE, id, style.getName());
|
2018-10-16 02:38:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the data subcommand
|
|
|
|
*
|
|
|
|
* @param pplayer The PPlayer executing the command
|
|
|
|
* @param id The target particle ID
|
|
|
|
* @param args The rest of the args
|
|
|
|
*/
|
|
|
|
private void editData(PPlayer pplayer, int id, String[] args) {
|
|
|
|
Material itemData = null;
|
|
|
|
Material blockData = null;
|
|
|
|
OrdinaryColor colorData = null;
|
|
|
|
NoteColor noteColorData = null;
|
2018-10-07 21:18:19 -06:00
|
|
|
|
2018-10-16 02:38:12 -06:00
|
|
|
ParticleEffect effect = pplayer.getActiveParticle(id).getEffect();
|
|
|
|
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
|
|
|
if (effect == ParticleEffect.NOTE) {
|
|
|
|
if (args[0].equalsIgnoreCase("rainbow")) {
|
|
|
|
noteColorData = new NoteColor(99);
|
2018-11-07 20:06:08 -07:00
|
|
|
} else if (args[0].equalsIgnoreCase("random")) {
|
|
|
|
noteColorData = new NoteColor(98);
|
2018-10-16 02:38:12 -06:00
|
|
|
} else {
|
|
|
|
int note = -1;
|
|
|
|
try {
|
|
|
|
note = Integer.parseInt(args[0]);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_NOTE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-07 03:21:46 -07:00
|
|
|
if (note < 0 || note > 24) {
|
2018-10-16 02:38:12 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_NOTE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
noteColorData = new NoteColor(note);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (args[0].equalsIgnoreCase("rainbow")) {
|
|
|
|
colorData = new OrdinaryColor(999, 999, 999);
|
2018-11-07 20:06:08 -07:00
|
|
|
} else if (args[0].equalsIgnoreCase("random")) {
|
|
|
|
colorData = new OrdinaryColor(998, 998, 998);
|
2018-10-16 02:38:12 -06:00
|
|
|
} else {
|
|
|
|
int r = -1;
|
|
|
|
int g = -1;
|
|
|
|
int b = -1;
|
|
|
|
|
|
|
|
try {
|
|
|
|
r = Integer.parseInt(args[0]);
|
|
|
|
g = Integer.parseInt(args[1]);
|
|
|
|
b = Integer.parseInt(args[2]);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_COLOR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_COLOR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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[0]);
|
|
|
|
if (blockData == null || !blockData.isBlock()) throw new Exception();
|
|
|
|
} catch (Exception e) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_BLOCK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (effect == ParticleEffect.ITEM) {
|
|
|
|
try {
|
|
|
|
itemData = ParticleUtils.closestMatch(args[0]);
|
|
|
|
if (itemData == null || itemData.isBlock()) throw new Exception();
|
|
|
|
} catch (Exception e) {
|
|
|
|
LangManager.sendMessage(pplayer, Lang.DATA_INVALID_ITEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String updatedDataString = null;
|
|
|
|
ParticleGroup group = pplayer.getActiveParticleGroup();
|
|
|
|
for (ParticlePair particle : group.getParticles()) {
|
|
|
|
if (particle.getId() == id) {
|
|
|
|
if (itemData != null) particle.setItemMaterial(itemData);
|
|
|
|
if (blockData != null) particle.setBlockMaterial(blockData);
|
|
|
|
if (colorData != null) particle.setColor(colorData);
|
|
|
|
if (noteColorData != null) particle.setNoteColor(noteColorData);
|
|
|
|
updatedDataString = particle.getDataString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
|
2018-10-16 19:09:20 -06:00
|
|
|
LangManager.sendMessage(pplayer, Lang.EDIT_SUCCESS_DATA, id, updatedDataString);
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
|
2018-10-16 02:38:12 -06:00
|
|
|
Player p = pplayer.getPlayer();
|
|
|
|
List<String> matches = new ArrayList<String>();
|
|
|
|
List<String> ids = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (ParticlePair particles : pplayer.getActiveParticles())
|
|
|
|
ids.add(String.valueOf(particles.getId()));
|
|
|
|
|
|
|
|
if (args.length == 0) {
|
|
|
|
matches = ids;
|
|
|
|
} else if (args.length == 1) {
|
|
|
|
StringUtil.copyPartialMatches(args[0], ids, matches);
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = -1;
|
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[0]);
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
|
|
|
if (pplayer.getActiveParticle(id) != null) {
|
|
|
|
if (args.length == 2) {
|
|
|
|
List<String> possibleValues = new ArrayList<String>();
|
|
|
|
possibleValues.add("effect");
|
|
|
|
possibleValues.add("style");
|
|
|
|
possibleValues.add("data");
|
|
|
|
StringUtil.copyPartialMatches(args[1], possibleValues, matches);
|
|
|
|
} else if (args.length >= 3) {
|
|
|
|
switch (args[1].toLowerCase()) {
|
|
|
|
case "effect":
|
2018-10-16 19:09:20 -06:00
|
|
|
if (args.length == 3)
|
2018-11-07 03:21:46 -07:00
|
|
|
StringUtil.copyPartialMatches(args[2], PermissionManager.getEffectNamesUserHasPermissionFor(p), matches);
|
2018-10-16 02:38:12 -06:00
|
|
|
break;
|
|
|
|
case "style":
|
2018-10-16 19:09:20 -06:00
|
|
|
if (args.length == 3)
|
2018-11-07 03:21:46 -07:00
|
|
|
StringUtil.copyPartialMatches(args[2], PermissionManager.getStyleNamesUserHasPermissionFor(p), matches);
|
2018-10-16 02:38:12 -06:00
|
|
|
break;
|
|
|
|
case "data":
|
|
|
|
ParticleEffect effect = pplayer.getActiveParticle(id).getEffect();
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
|
|
|
List<String> possibleValues = new ArrayList<String>();
|
|
|
|
if (effect == ParticleEffect.NOTE) { // Note data
|
|
|
|
if (args.length == 3) {
|
2018-11-07 03:21:46 -07:00
|
|
|
possibleValues.add("<0-24>");
|
2018-10-16 02:38:12 -06:00
|
|
|
possibleValues.add("rainbow");
|
2018-11-07 20:06:08 -07:00
|
|
|
possibleValues.add("random");
|
2018-10-16 02:38:12 -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-16 02:38:12 -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-16 02:38:12 -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-16 02:38:12 -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
|
|
|
|
matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches);
|
|
|
|
} else if (effect == ParticleEffect.ITEM) { // Item material
|
|
|
|
matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return "edit";
|
|
|
|
}
|
|
|
|
|
2018-09-29 17:27:37 -06:00
|
|
|
public Lang getDescription() {
|
2018-10-01 22:23:05 -06:00
|
|
|
return Lang.COMMAND_DESCRIPTION_EDIT;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getArguments() {
|
2019-02-02 20:03:51 -07:00
|
|
|
return "<ID> <effect>|<style>|<data> <args>";
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean requiresEffects() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-26 02:07:46 -06:00
|
|
|
}
|