Commits vergleichen

...

1 Commits

Autor SHA1 Nachricht Datum
yoyosource
a3a42799d8 Add GradientCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: yoyosource <yoyosource@nidido.de>
2022-09-13 17:19:47 +02:00

Datei anzeigen

@ -0,0 +1,120 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.worldedit;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.factory.MaskFactory;
import com.sk89q.worldedit.extension.factory.PatternFactory;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Direction;
import de.steamwar.bausystem.features.world.WorldEditListener;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.linkage.MinVersion;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import lombok.SneakyThrows;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
@Linked(LinkageType.COMMAND)
@MinVersion(19)
public class GradientCommand extends SWCommand {
private PatternFactory patternFactory = WorldEdit.getInstance().getPatternFactory();
private MaskFactory maskFactory = WorldEdit.getInstance().getMaskFactory();
public GradientCommand() {
super("/gradient", "/gr");
}
{
WorldEditListener.addOtherCommand("//gradient");
WorldEditListener.addOtherCommand("//gr");
}
@Register
public void genericCommand(Player player, Pattern pattern, Mask mask, @OptionalValue("0") int fromPercent, @OptionalValue("100") int toPercent, @OptionalValue("") Direction direction) {
player.sendMessage("Gradient " + pattern.toString() + " " + mask.toString() + " " + fromPercent + " " + toPercent + " " + direction.toString());
}
@ClassMapper(value = Pattern.class, local = true)
private TypeMapper<Pattern> patternTypeMapper() {
return new TypeMapper<Pattern>() {
@Override
@SneakyThrows
public Pattern map(CommandSender commandSender, String[] previousArguments, String s) {
return patternFactory.parseFromInput(s, null);
}
@Override
@SneakyThrows
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return patternFactory.getSuggestions(s);
}
};
}
@ClassMapper(value = Mask.class, local = true)
private TypeMapper<Mask> maskTypeMapper() {
return new TypeMapper<Mask>() {
@Override
@SneakyThrows
public Mask map(CommandSender commandSender, String[] previousArguments, String s) {
return maskFactory.parseFromInput(s, null);
}
@Override
@SneakyThrows
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return maskFactory.getSuggestions(s);
}
};
}
@ClassMapper(value = Direction.class, local = true)
private TypeMapper<Direction> directionTypeMapper() {
return new TypeMapper<Direction>() {
@Override
public Direction map(CommandSender commandSender, String[] previousArguments, String s) {
if (commandSender == null) return null;
if (s.equals("")) {
Vector directionVector = ((Player) commandSender).getLocation().getDirection();
Direction.findClosest(Vector3.at(directionVector.getX(), directionVector.getY(), directionVector.getZ()), Direction.Flag.ALL);
}
return Direction.valueOf(s.toUpperCase());
}
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return Arrays.stream(Direction.values()).map(Direction::name).map(String::toLowerCase).collect(Collectors.toSet());
}
};
}
}