|
|
|
@ -23,48 +23,67 @@ import de.steamwar.bausystem.BauSystem;
|
|
|
|
|
import de.steamwar.bausystem.Permission;
|
|
|
|
|
import de.steamwar.bausystem.world.Region;
|
|
|
|
|
import de.steamwar.bausystem.world.Welt;
|
|
|
|
|
import de.steamwar.command.SWCommand;
|
|
|
|
|
import de.steamwar.sql.Schematic;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
|
|
|
|
|
public class CommandProtect implements CommandExecutor {
|
|
|
|
|
public class CommandProtect extends SWCommand {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
|
if (!(sender instanceof Player))
|
|
|
|
|
return false;
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
|
public CommandProtect() {
|
|
|
|
|
super("protect");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Register
|
|
|
|
|
public void genericTestblockCommand(Player p) {
|
|
|
|
|
if (!permissionCheck(p)) return;
|
|
|
|
|
Region region = regionCheck(p);
|
|
|
|
|
if (region == null) return;
|
|
|
|
|
try {
|
|
|
|
|
region.protect(null);
|
|
|
|
|
p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region");
|
|
|
|
|
Bukkit.getLogger().log(Level.WARNING, "Failed protect", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Register
|
|
|
|
|
public void schematicTestblockCommand(Player p, String s) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
region.protect(null);
|
|
|
|
|
p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region");
|
|
|
|
|
Bukkit.getLogger().log(Level.WARNING, "Failed protect", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean permissionCheck(Player player) {
|
|
|
|
|
if (Welt.noPermission(player, Permission.worldedit)) {
|
|
|
|
|
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Boden schützen");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Region regionCheck(Player player) {
|
|
|
|
|
Region region = Region.getRegion(player.getLocation());
|
|
|
|
|
if (region == null || !region.hasProtection()) {
|
|
|
|
|
if (!region.hasProtection()) {
|
|
|
|
|
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region");
|
|
|
|
|
return false;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Schematic schem = null;
|
|
|
|
|
if (args.length > 0) {
|
|
|
|
|
schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
|
|
|
|
|
if (schem == null) {
|
|
|
|
|
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
region.protect(schem);
|
|
|
|
|
player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region");
|
|
|
|
|
Bukkit.getLogger().log(Level.WARNING, "Failed protect", e);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
return region;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|