Update BauSystem to new CommandFramework #217
@ -22,11 +22,14 @@ package de.steamwar.bausystem;
|
|||||||
import de.steamwar.bausystem.tracer.show.ShowModeParameterType;
|
import de.steamwar.bausystem.tracer.show.ShowModeParameterType;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import de.steamwar.sql.BauweltMember;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
public class Mapper {
|
public class Mapper {
|
||||||
|
|
||||||
@ -36,6 +39,7 @@ public class Mapper {
|
|||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
SWCommandUtils.addMapper(ShowModeParameterType.class, showModeParameterTypesTypeMapper());
|
SWCommandUtils.addMapper(ShowModeParameterType.class, showModeParameterTypesTypeMapper());
|
||||||
|
SWCommandUtils.addMapper(BauweltMember.class, bauweltMemberTypeMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() {
|
private static TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() {
|
||||||
@ -70,4 +74,13 @@ public class Mapper {
|
|||||||
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
|
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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,26 +50,25 @@ public class CommandBau extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register("togglebuild")
|
@Register("togglebuild")
|
||||||
public void toggleBuildCommand(Player p, LocalPlayer arg) {
|
public void toggleBuildCommand(Player p, SteamwarUser user) {
|
||||||
if (!permissionCheck(p)) return;
|
if (!permissionCheck(p)) return;
|
||||||
onToggleBD(p, arg.getName());
|
onToggleBD(p, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register("togglewe")
|
@Register("togglewe")
|
||||||
public void toggleWECommand(Player p, LocalPlayer arg) {
|
public void toggleWECommand(Player p, SteamwarUser user) {
|
||||||
if (!permissionCheck(p)) return;
|
if (!permissionCheck(p)) return;
|
||||||
onToggleWE(p, arg.getName());
|
onToggleWE(p, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register("toggleworld")
|
@Register("toggleworld")
|
||||||
public void toggleWorldCommand(Player p, LocalPlayer arg) {
|
public void toggleWorldCommand(Player p, SteamwarUser user) {
|
||||||
if (!permissionCheck(p)) return;
|
if (!permissionCheck(p)) return;
|
||||||
onToggleWorld(p, arg.getName());
|
onToggleWorld(p, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void onToggleBD(Player p, String arg) {
|
private void onToggleBD(Player p, SteamwarUser id) {
|
||||||
SteamwarUser id = SteamwarUser.get(arg);
|
|
||||||
if (negativeToggleCheck(p, id)) {
|
if (negativeToggleCheck(p, id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -78,8 +77,7 @@ public class CommandBau extends SWCommand {
|
|||||||
Welt.toggleBuild(p, target);
|
Welt.toggleBuild(p, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onToggleWE(Player p, String arg) {
|
private void onToggleWE(Player p, SteamwarUser id) {
|
||||||
SteamwarUser id = SteamwarUser.get(arg);
|
|
||||||
if (negativeToggleCheck(p, id)) {
|
if (negativeToggleCheck(p, id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -88,8 +86,7 @@ public class CommandBau extends SWCommand {
|
|||||||
Welt.toggleWE(p, target);
|
Welt.toggleWE(p, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onToggleWorld(Player p, String arg) {
|
private void onToggleWorld(Player p, SteamwarUser id) {
|
||||||
SteamwarUser id = SteamwarUser.get(arg);
|
|
||||||
if (negativeToggleCheck(p, id)) {
|
if (negativeToggleCheck(p, id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -123,23 +120,17 @@ public class CommandBau extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ClassMapper(value = LocalPlayer.class, local = true)
|
@ClassMapper(value = SteamwarUser.class, local = true)
|
||||||
private TypeMapper<LocalPlayer> mapCommandConfirmation() {
|
private TypeMapper<SteamwarUser> steamwarUserTypeMapper() {
|
||||||
return SWCommandUtils.createMapper(LocalPlayer::new,
|
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauSystem.getOwnerID())
|
||||||
(c, s) -> Bukkit.getOnlinePlayers().stream().map(Player::getName).filter(n -> !c.getName().equals(n)).collect(Collectors.toList()));
|
.stream()
|
||||||
}
|
.map(m -> SteamwarUser.get(m.getMemberID()))
|
||||||
|
.filter(u -> u.getUserName().equals(s))
|
||||||
|
.findFirst()
|
||||||
public class LocalPlayer {
|
.orElse(null),
|
||||||
|
s -> BauweltMember.getMembers(BauSystem.getOwnerID())
|
||||||
private String name;
|
.stream()
|
||||||
|
.map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
|
||||||
public LocalPlayer(String name) {
|
.collect(Collectors.toList()));
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren