SteamWar/BauSystem2.0
Archiviert
12
0

Optimize TNTCommand TabComplete

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-11 17:34:35 +02:00
Ursprung 0f1f8c055c
Commit 70becaa751
2 geänderte Dateien mit 32 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -81,15 +82,37 @@ public class TNTCommand extends SWCommand {
@ClassMapper(value = TNTMode.class, local = true)
public TypeMapper<TNTMode> tntModeTypeMapper() {
Map<String, TNTMode> tntModeMap = new HashMap<>();
tntModeMap.put("an", TNTMode.ALLOW);
tntModeMap.put("on", TNTMode.ALLOW);
tntModeMap.put("aus", TNTMode.DENY);
tntModeMap.put("off", TNTMode.DENY);
Map<String, TNTMode> tntModeMapReduced = new HashMap<>();
tntModeMapReduced.put("an", TNTMode.ALLOW);
tntModeMapReduced.put("on", TNTMode.ALLOW);
tntModeMapReduced.put("aus", TNTMode.DENY);
tntModeMapReduced.put("off", TNTMode.DENY);
Map<String, TNTMode> tntModeMap = new HashMap<>(tntModeMapReduced);
tntModeMap.put("testblock", TNTMode.ONLY_TB);
tntModeMap.put("tb", TNTMode.ONLY_TB);
List<String> tabCompletes = new ArrayList<>(tntModeMap.keySet());
return SWCommandUtils.createMapper(s -> tntModeMap.getOrDefault(s, null), s -> tabCompletes);
return new TypeMapper<TNTMode>() {
@Override
public List<String> tabCompletes(CommandSender sender, String[] strings, String s) {
Region region = Region.getRegion(((Player) sender).getLocation());
if (region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) {
return new ArrayList<>(tntModeMap.keySet());
} else {
return new ArrayList<>(tntModeMapReduced.keySet());
}
}
@Override
public TNTMode map(CommandSender sender, String[] previousArguments, String s) {
Region region = Region.getRegion(((Player) sender).getLocation());
if (region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) {
return tntModeMap.getOrDefault(s, null);
} else {
return tntModeMapReduced.getOrDefault(s, null);
}
}
};
}
private String getEnableMessage() {
@ -105,7 +128,7 @@ public class TNTCommand extends SWCommand {
}
private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) {
if (requestedMode != null && region.hasType(RegionType.TESTBLOCK)) {
if (requestedMode != null && region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) {
region.set(Flag.TNT, requestedMode);
RegionUtils.actionBar(region, requestedMessage);
return;
@ -117,7 +140,7 @@ public class TNTCommand extends SWCommand {
RegionUtils.actionBar(region, getDisableMessage());
break;
case DENY:
if (region.hasType(RegionType.TESTBLOCK)) {
if (region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) {
region.set(Flag.TNT, TNTMode.ONLY_TB);
RegionUtils.actionBar(region, getTestblockEnableMessage());
} else {

Datei anzeigen

@ -17,7 +17,6 @@
}
mwg{
displayName(MiniWarGear)
protection(sections3/MWGProtection.schem)
schematic(sections3/MWGArena.schem)
sizeX(63)
sizeY(256)
@ -34,7 +33,6 @@
}
wg{
displayName(WarGear)
protection(sections3/WGProtection.schem)
schematic(sections3/WGArena.schem)
sizeX(133)
sizeY(255)