Add TestblockCommand
Dieser Commit ist enthalten in:
Ursprung
cf6947a081
Commit
0cb29d2795
@ -0,0 +1,116 @@
|
|||||||
|
package de.steamwar.bausystem.features.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.SWCommandUtils;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import de.steamwar.sql.Schematic;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Linked(LinkageType.COMMAND)
|
||||||
|
public class TestblockCommand extends SWCommand {
|
||||||
|
|
||||||
|
public TestblockCommand() {
|
||||||
|
super("testblock", "tb");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(help = true)
|
||||||
|
public void genericHelp(Player p, String... args) {
|
||||||
|
p.sendMessage("§8/§etestblock §8- §7Setzte den Testblock zurück");
|
||||||
|
p.sendMessage("§8/§etestblock §8[§7Schematic§8] §8- §7Setzte den Testblock mit einer Schematic zurück");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void genericTestblockCommand(Player p) {
|
||||||
|
genericTestblockCommand(p, RegionExtensionType.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void genericTestblockCommand(Player p, RegionExtensionType regionExtensionType) {
|
||||||
|
if (!permissionCheck(p)) return;
|
||||||
|
Region region = regionCheck(p);
|
||||||
|
if (region == null) return;
|
||||||
|
// TODO: implement this
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
region.resetTestblock(null, regionExtensionType == RegionExtensionType.EXTENSION);
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
|
||||||
|
} catch (IOException e) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void schematicTestblockCommand(Player p, String s) {
|
||||||
|
schematicTestblockCommand(p, s, RegionExtensionType.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, String s) {
|
||||||
|
schematicTestblockCommand(p, s, regionExtensionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void schematicTestblockCommand(Player p, String s, RegionExtensionType regionExtensionType) {
|
||||||
|
if (!permissionCheck(p)) return;
|
||||||
|
Region region = regionCheck(p);
|
||||||
|
if (region == null) return;
|
||||||
|
Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId());
|
||||||
|
if (schem == null) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: implement this
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
region.resetTestblock(schem, regionExtensionType == RegionExtensionType.EXTENSION);
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
|
||||||
|
} catch (IOException e) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClassMapper(value = RegionExtensionType.class, local = true)
|
||||||
|
private TypeMapper<RegionExtensionType> regionExtensionTypeTypeMapper() {
|
||||||
|
Map<String, RegionExtensionType> showModeParameterTypesMap = new HashMap<>();
|
||||||
|
showModeParameterTypesMap.put("-normal", RegionExtensionType.NORMAL);
|
||||||
|
showModeParameterTypesMap.put("-n", RegionExtensionType.NORMAL);
|
||||||
|
showModeParameterTypesMap.put("-extension", RegionExtensionType.EXTENSION);
|
||||||
|
showModeParameterTypesMap.put("-e", RegionExtensionType.EXTENSION);
|
||||||
|
|
||||||
|
List<String> tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet());
|
||||||
|
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player player) {
|
||||||
|
if (Permission.hasPermission(player, Permission.WORLDEDIT)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Testblock zurücksetzen");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Region regionCheck(Player player) {
|
||||||
|
Region region = Region.getRegion(player.getLocation());
|
||||||
|
if (!region.hasType(RegionType.TESTBLOCK)) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren