SteamWar/BauSystem2.0
Archiviert
12
0

Add ProtectCommand

Add ProtectListener
Dieser Commit ist enthalten in:
yoyosource 2021-04-19 17:32:16 +02:00
Ursprung e3987386b1
Commit 34344dadae
3 geänderte Dateien mit 109 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,67 @@
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.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.logging.Level;
@Linked(LinkageType.COMMAND)
public class ProtectCommand extends SWCommand {
public ProtectCommand() {
super("protect");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
p.sendMessage("§8/§eprotect §8- §7Schütze die Region");
p.sendMessage("§8/§eprotect §8[§7Schematic§8] §8- §7Schütze die Region mit einer Schematic");
}
@Register
public void genericProtectCommand(Player p) {
if (!permissionCheck(p)) return;
Region region = regionCheck(p);
if (region == null) return;
switch (region.getPlain(Flag.PROTECT, ProtectMode.class)) {
case ACTIVE:
region.set(Flag.PROTECT, ProtectMode.INACTIVE);
RegionUtils.actionBar(region, "§cBoden Schutz aufgehoben");
break;
default:
case INACTIVE:
region.set(Flag.PROTECT, ProtectMode.ACTIVE);
RegionUtils.actionBar(region, "§cBoden Schutz aufgehoben");
break;
}
}
private boolean permissionCheck(Player player) {
if (!Permission.hasPermission(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.getFloorLevel() == 0) {
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region");
return null;
}
return region;
}
}

Datei anzeigen

@ -0,0 +1,27 @@
package de.steamwar.bausystem.features.region;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
@Linked(LinkageType.LISTENER)
public class ProtectListener implements Listener {
@EventHandler
public void onExplode(EntityExplodeEvent event) {
Region region = Region.getRegion(event.getLocation());
if (region.getFloorLevel() == 0) {
return;
}
if (region.getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.INACTIVE) {
return;
}
event.blockList().removeIf(block -> block.getY() < region.getFloorLevel());
}
}

Datei anzeigen

@ -73,6 +73,9 @@ public class Region {
private Point minPointBuildExtension; private Point minPointBuildExtension;
private Point maxPointBuildExtension; private Point maxPointBuildExtension;
private int floorLevel;
private int waterLevel;
private String linkedRegionName = null; // Nullable private String linkedRegionName = null; // Nullable
private Region linkedRegion = null; // Nullable private Region linkedRegion = null; // Nullable
@ -136,6 +139,18 @@ public class Region {
this.minPointBuildExtension = this.minPointBuild.substract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); this.minPointBuildExtension = this.minPointBuild.substract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
} }
if (prototype.getFloorOffset() != 0) {
floorLevel = minPoint.getY() + prototype.getFloorOffset();
} else {
floorLevel = 0;
}
if (prototype.getWaterOffset() != 0) {
waterLevel = minPoint.getY() + prototype.getWaterOffset();
} else {
waterLevel = 0;
}
} }
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {