Add BauCommand
Dieser Commit ist enthalten in:
Ursprung
0528f77ce5
Commit
0aa3a8ec6c
133
BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java
Normale Datei
133
BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java
Normale Datei
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 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.bau;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.SWCommandUtils;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import de.steamwar.sql.BauweltMember;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Linked(LinkageType.COMMAND)
|
||||||
|
public class BauCommand extends SWCommand {
|
||||||
|
|
||||||
|
public BauCommand() {
|
||||||
|
super("bau", "b", "gs");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(help = true)
|
||||||
|
public void genericHelp(Player p, String... args) {
|
||||||
|
p.sendMessage("§8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers");
|
||||||
|
p.sendMessage("§8/§ebau toggleworld §8[§7Player§8] §8- §7Editiere die Werlt Rechte eines Spielers");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("info")
|
||||||
|
public void infoCommand(Player p) {
|
||||||
|
// TODO: Implement this
|
||||||
|
// CommandInfo.sendBauInfo(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("togglewe")
|
||||||
|
public void toggleWECommand(Player p, SteamwarUser user) {
|
||||||
|
if (!permissionCheck(p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onToggleWE(p, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("toggleworld")
|
||||||
|
public void toggleWorldCommand(Player p, SteamwarUser user) {
|
||||||
|
if (!permissionCheck(p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onToggleWorld(p, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onToggleWE(Player p, SteamwarUser id) {
|
||||||
|
if (negativeToggleCheck(p, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
|
||||||
|
Permission.WORLDEDIT.toggle(p, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onToggleWorld(Player p, SteamwarUser id) {
|
||||||
|
if (negativeToggleCheck(p, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
|
||||||
|
Permission.WORLD.toggle(p, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean negativeToggleCheck(Player p, SteamwarUser id) {
|
||||||
|
if (id == null) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spieler");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
|
||||||
|
if (target == null) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player p) {
|
||||||
|
if (!BauServer.getInstance().getOwner().equals(p.getUniqueId())) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ClassMapper(value = SteamwarUser.class, local = true)
|
||||||
|
private TypeMapper<SteamwarUser> steamwarUserTypeMapper() {
|
||||||
|
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauServer.getInstance().getOwnerID())
|
||||||
|
.stream()
|
||||||
|
.map(m -> SteamwarUser.get(m.getMemberID()))
|
||||||
|
.filter(u -> u.getUserName().equals(s))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null),
|
||||||
|
(c, s) -> {
|
||||||
|
if (!(c instanceof Player)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Player p = (Player) c;
|
||||||
|
return BauweltMember.getMembers(SteamwarUser.get(p.getUniqueId()).getId())
|
||||||
|
.stream()
|
||||||
|
.map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren