Implement /pp add command

Note: Untested
This commit is contained in:
Esophose 2018-10-05 17:25:13 -06:00
parent 4babd4a792
commit 4532455ccc
3 changed files with 44 additions and 12 deletions

View file

@ -4,6 +4,7 @@ import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.manager.PermissionManager;
@ -13,6 +14,8 @@ import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor; import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.styles.api.ParticleStyleManager; import com.esophose.playerparticles.styles.api.ParticleStyleManager;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
@ -114,7 +117,9 @@ public class AddCommandModule implements CommandModule {
} }
} }
// TODO: Update active group and save ParticleGroup group = pplayer.getActiveParticleGroup();
group.getParticles().add(new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, blockData, blockData, colorData, noteColorData));
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
} }

View file

@ -75,7 +75,8 @@ public class PPlayer {
*/ */
public ParticleGroup getParticlesByName(String name) { public ParticleGroup getParticlesByName(String name) {
for (ParticleGroup group : this.particleGroups) for (ParticleGroup group : this.particleGroups)
if (group.getName().equalsIgnoreCase(name)) return group; if (group.getName().equalsIgnoreCase(name))
return group;
return null; return null;
} }
@ -85,8 +86,18 @@ public class PPlayer {
* @return A List<ParticlePair> of all particles this player has set * @return A List<ParticlePair> of all particles this player has set
*/ */
public List<ParticlePair> getActiveParticles() { public List<ParticlePair> getActiveParticles() {
return this.getActiveParticleGroup().getParticles();
}
/**
* Get the PPlayer's active ParticleGroup
*
* @return A ParticleGroup of this player's active particles
*/
public ParticleGroup getActiveParticleGroup() {
for (ParticleGroup group : this.particleGroups) for (ParticleGroup group : this.particleGroups)
if (group.getName() == null) return group.getParticles(); if (group.getName() == null)
return group;
return null; // This should never return null, there will always be at least one ParticleGroup return null; // This should never return null, there will always be at least one ParticleGroup
} }
@ -99,7 +110,8 @@ public class PPlayer {
public List<ParticlePair> getActiveParticlesForStyle(ParticleStyle style) { public List<ParticlePair> getActiveParticlesForStyle(ParticleStyle style) {
List<ParticlePair> matches = new ArrayList<ParticlePair>(); List<ParticlePair> matches = new ArrayList<ParticlePair>();
for (ParticlePair pair : this.getActiveParticles()) for (ParticlePair pair : this.getActiveParticles())
if (pair.getStyle().equals(style)) matches.add(pair); if (pair.getStyle().equals(style))
matches.add(pair);
return matches; return matches;
} }
@ -111,7 +123,8 @@ public class PPlayer {
*/ */
public ParticlePair getActiveParticle(int id) { public ParticlePair getActiveParticle(int id) {
for (ParticlePair particle : this.getActiveParticles()) for (ParticlePair particle : this.getActiveParticles())
if (particle.getId() == id) return particle; if (particle.getId() == id)
return particle;
return null; return null;
} }
@ -132,7 +145,8 @@ public class PPlayer {
*/ */
public FixedParticleEffect getFixedEffectById(int id) { public FixedParticleEffect getFixedEffectById(int id) {
for (FixedParticleEffect fixedEffect : this.fixedParticles) for (FixedParticleEffect fixedEffect : this.fixedParticles)
if (fixedEffect.getId() == id) return fixedEffect; if (fixedEffect.getId() == id)
return fixedEffect;
return null; return null;
} }
@ -164,13 +178,13 @@ public class PPlayer {
*/ */
public void removeFixedEffect(int id) { public void removeFixedEffect(int id) {
for (int i = this.fixedParticles.size() - 1; i >= 0; i--) for (int i = this.fixedParticles.size() - 1; i >= 0; i--)
if (this.fixedParticles.get(i).getId() == id) this.fixedParticles.remove(i); if (this.fixedParticles.get(i).getId() == id)
this.fixedParticles.remove(i);
} }
/** /**
* Gets the next Id for a player's fixed effects * Gets the next Id for a player's fixed effects
* *
* @param pplayerUUID The player to get the Id for
* @return The next available fixed effect id * @return The next available fixed effect id
*/ */
public int getNextFixedEffectId() { public int getNextFixedEffectId() {
@ -181,4 +195,17 @@ public class PPlayer {
return ParticleUtils.getSmallestPositiveInt(ids); return ParticleUtils.getSmallestPositiveInt(ids);
} }
/**
* Gets the next Id for a player's active particles
*
* @return The next available active particle id
*/
public int getNextActiveParticleId() {
List<ParticlePair> activeParticles = this.getActiveParticles();
int[] ids = new int[activeParticles.size()];
for (int i = 0; i < activeParticles.size(); i++)
ids[i] = activeParticles.get(i).getId();
return ParticleUtils.getSmallestPositiveInt(ids);
}
} }

View file

@ -54,12 +54,12 @@ style-list: '&eYou can use the following styles: &b{0}'
# Data # Data
data-usage-none: '&eYour current effect does not use any data!' data-usage-none: '&eYour current effect does not use any data!'
data-usage-block: '&eThe effect &b{0} requires &bblock &edata! &bFormat: <blockMaterialName>' data-usage-block: '&eThe effect &b{0} requires &bblock &edata! &bFormat: <blockName>'
data-usage-item: '&eThe effect &b{0} requires &bitem &edata! &bFormat: <itemMaterialName>' data-usage-item: '&eThe effect &b{0} requires &bitem &edata! &bFormat: <itemName>'
data-usage-color: '&eThe effect &b{0} requires &bcolor &edata! &bFormat: [<0-255> <0-255> <0-255>]|[<rainbow>]' data-usage-color: '&eThe effect &b{0} requires &bcolor &edata! &bFormat: [<0-255> <0-255> <0-255>]|[<rainbow>]'
data-usage-note: '&eThe effect &b{0} requires &bnote &edata! &bFormat: <0-23>/<rainbow>' data-usage-note: '&eThe effect &b{0} requires &bnote &edata! &bFormat: <0-23>/<rainbow>'
data-invalid-block: '&cThe &bblock &cdata you entered is invalid! &bFormat: <blockMaterialName>' data-invalid-block: '&cThe &bblock &cdata you entered is invalid! &bFormat: <blockName>'
data-invalid-item: '&cThe &bitem &cdata you entered is invalid! &bFormat: <itemMaterialName>' data-invalid-item: '&cThe &bitem &cdata you entered is invalid! &bFormat: <itemName>'
data-invalid-color: '&cThe &bcolor &cdata you entered is invalid! &bFormat: [<0-255> <0-255> <0-255>]|[<rainbow>]' data-invalid-color: '&cThe &bcolor &cdata you entered is invalid! &bFormat: [<0-255> <0-255> <0-255>]|[<rainbow>]'
data-invalid-note: '&cThe &bitem &cdata you entered is invalid! &bFormat: <0-23>/<rainbow>' data-invalid-note: '&cThe &bitem &cdata you entered is invalid! &bFormat: <0-23>/<rainbow>'
data-invalid-material-not-item: '&cThe &bitem &cmaterial &b{0} &cyou entered is not an item!' data-invalid-material-not-item: '&cThe &bitem &cmaterial &b{0} &cyou entered is not an item!'