-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/net/kunmc/lab/configlib/value/ParticleValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |