Skip to content

Commit

Permalink
add ParticleValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Maru32768 committed Jan 13, 2022
1 parent 6041bd2 commit 8078dbb
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/main/java/net/kunmc/lab/configlib/value/ParticleValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.kunmc.lab.configlib.value;

import dev.kotx.flylib.command.UsageBuilder;
import dev.kotx.flylib.command.arguments.StringArgument;
import net.kunmc.lab.configlib.command.SingleValue;
import org.bukkit.Particle;
import org.bukkit.command.CommandSender;

import java.util.Arrays;
import java.util.List;

public class ParticleValue extends SingleValue<Particle> {
private transient Boolean listable = true;
private transient boolean writable = true;

public ParticleValue(Particle value) {
super(value);
}

@Override
protected boolean writableByCommand() {
return writable;
}

public ParticleValue writableByCommand(boolean writable) {
this.writable = writable;
return this;
}

@Override
protected void appendArgument(UsageBuilder builder) {
builder.stringArgument("ParticleName", StringArgument.Type.WORD, sb -> {
Arrays.stream(Particle.values())
.map(Particle::name)
.map(String::toLowerCase)
.forEach(sb::suggest);
});
}

@Override
protected boolean isCorrectArgument(List<Object> argument, CommandSender sender) {
return Arrays.stream(Particle.values())
.anyMatch(m -> m.name().equals(argument.get(0).toString().toUpperCase()));
}

@Override
protected String incorrectArgumentMessage(List<Object> argument) {
return argument.get(0) + "は不明なParticleです.";
}

@Override
protected Particle argumentToValue(List<Object> argument, CommandSender sender) {
return Arrays.stream(Particle.values())
.filter(m -> m.name().equals(argument.get(0).toString().toUpperCase()))
.findFirst()
.get();
}

@Override
protected boolean validateOnSet(Particle newValue) {
return true;
}

@Override
protected String invalidValueMessage(String entryName, Particle newValue) {
return newValue.name() + "は不正な値です.";
}

@Override
protected boolean listable() {
return listable;
}

public ParticleValue listable(boolean listable) {
this.listable = listable;
return this;
}
}

0 comments on commit 8078dbb

Please sign in to comment.