SteamWar/BauSystem
Archiviert
13
0

updated bau toggle-commands tab completion

Dieser Commit ist enthalten in:
Zeanon 2021-04-02 17:03:58 +02:00
Ursprung cccd0153dc
Commit 9b1f4433ca
2 geänderte Dateien mit 35 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -22,11 +22,14 @@ package de.steamwar.bausystem;
import de.steamwar.bausystem.tracer.show.ShowModeParameterType;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Mapper {
@ -36,6 +39,7 @@ public class Mapper {
public static void init() {
SWCommandUtils.addMapper(ShowModeParameterType.class, showModeParameterTypesTypeMapper());
SWCommandUtils.addMapper(BauweltMember.class, bauweltMemberTypeMapper());
}
private static TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() {
@ -70,4 +74,13 @@ public class Mapper {
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
}
private static TypeMapper<BauweltMember> bauweltMemberTypeMapper() {
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauSystem.getOwnerID())
.stream()
.filter(m -> SteamwarUser.get(m.getMemberID()).getUserName().equals(s)).findFirst().orElse(null),
s -> BauweltMember.getMembers(BauSystem.getOwnerID())
.stream()
.map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
.collect(Collectors.toList()));
}
}

Datei anzeigen

@ -50,26 +50,25 @@ public class CommandBau extends SWCommand {
}
@Register("togglebuild")
public void toggleBuildCommand(Player p, LocalPlayer arg) {
public void toggleBuildCommand(Player p, SteamwarUser user) {
if (!permissionCheck(p)) return;
onToggleBD(p, arg.getName());
onToggleBD(p, user);
}
@Register("togglewe")
public void toggleWECommand(Player p, LocalPlayer arg) {
public void toggleWECommand(Player p, SteamwarUser user) {
if (!permissionCheck(p)) return;
onToggleWE(p, arg.getName());
onToggleWE(p, user);
}
@Register("toggleworld")
public void toggleWorldCommand(Player p, LocalPlayer arg) {
public void toggleWorldCommand(Player p, SteamwarUser user) {
if (!permissionCheck(p)) return;
onToggleWorld(p, arg.getName());
onToggleWorld(p, user);
}
private void onToggleBD(Player p, String arg) {
SteamwarUser id = SteamwarUser.get(arg);
private void onToggleBD(Player p, SteamwarUser id) {
if (negativeToggleCheck(p, id)) {
return;
}
@ -78,8 +77,7 @@ public class CommandBau extends SWCommand {
Welt.toggleBuild(p, target);
}
private void onToggleWE(Player p, String arg) {
SteamwarUser id = SteamwarUser.get(arg);
private void onToggleWE(Player p, SteamwarUser id) {
if (negativeToggleCheck(p, id)) {
return;
}
@ -88,8 +86,7 @@ public class CommandBau extends SWCommand {
Welt.toggleWE(p, target);
}
private void onToggleWorld(Player p, String arg) {
SteamwarUser id = SteamwarUser.get(arg);
private void onToggleWorld(Player p, SteamwarUser id) {
if (negativeToggleCheck(p, id)) {
return;
}
@ -123,23 +120,17 @@ public class CommandBau extends SWCommand {
}
@ClassMapper(value = LocalPlayer.class, local = true)
private TypeMapper<LocalPlayer> mapCommandConfirmation() {
return SWCommandUtils.createMapper(LocalPlayer::new,
(c, s) -> Bukkit.getOnlinePlayers().stream().map(Player::getName).filter(n -> !c.getName().equals(n)).collect(Collectors.toList()));
}
public class LocalPlayer {
private String name;
public LocalPlayer(String name) {
this.name = name;
}
public String getName() {
return name;
}
@ClassMapper(value = SteamwarUser.class, local = true)
private TypeMapper<SteamwarUser> steamwarUserTypeMapper() {
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauSystem.getOwnerID())
.stream()
.map(m -> SteamwarUser.get(m.getMemberID()))
.filter(u -> u.getUserName().equals(s))
.findFirst()
.orElse(null),
s -> BauweltMember.getMembers(BauSystem.getOwnerID())
.stream()
.map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
.collect(Collectors.toList()));
}
}