SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-19 18:46:47 +02:00
Commit 10b5d9d3c1
12 geänderte Dateien mit 539 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,69 @@
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.FireMode;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
@Linked(LinkageType.COMMAND)
public class FireCommand extends SWCommand {
public FireCommand() {
super("fire");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
p.sendMessage("§8/§efire §8- §7Toggle Feuerschaden");
}
@Register
public void toggleCommand(Player p) {
if (!permissionCheck(p)) return;
Region region = Region.getRegion(p.getLocation());
if (toggle(region)) {
RegionUtils.actionBar(region, getEnableMessage());
} else {
RegionUtils.actionBar(region, getDisableMessage());
}
}
private String getNoPermMessage() {
return "§cDu darfst hier nicht Feuerschaden (de-)aktivieren";
}
private String getEnableMessage() {
return "§cRegions Feuerschaden deaktiviert";
}
private String getDisableMessage() {
return "§aRegions Feuerschaden aktiviert";
}
private boolean toggle(Region region) {
switch (region.getPlain(Flag.FIRE, FireMode.class)) {
case ALLOW:
region.set(Flag.FIRE, FireMode.DENY);
return true;
default:
case DENY:
region.set(Flag.FIRE, FireMode.ALLOW);
return false;
}
}
private boolean permissionCheck(Player player) {
if (!Permission.hasPermission(player, Permission.WORLD)) {
player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
return false;
}
return true;
}
}

Datei anzeigen

@ -0,0 +1,26 @@
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.FireMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockSpreadEvent;
@Linked(LinkageType.LISTENER)
public class FireListener implements Listener {
@EventHandler
public void onFireDamage(BlockBurnEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.DENY) e.setCancelled(true);
}
@EventHandler
public void onFireSpread(BlockSpreadEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.DENY) e.setCancelled(true);
}
}

Datei anzeigen

@ -0,0 +1,69 @@
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.FreezeMode;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
@Linked(LinkageType.COMMAND)
public class FreezeCommand extends SWCommand {
public FreezeCommand() {
super("freeze", "stoplag");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
p.sendMessage("§8/§efreeze §8- §7Toggle Freeze");
}
@Register
public void toggleCommand(Player p) {
if (!permissionCheck(p)) return;
Region region = Region.getRegion(p.getLocation());
if (toggle(region)) {
RegionUtils.actionBar(region, getEnableMessage());
} else {
RegionUtils.actionBar(region, getDisableMessage());
}
}
private String getNoPermMessage() {
return "§cDu darfst diese Welt nicht einfrieren";
}
private String getEnableMessage(){
return "§cRegion eingefroren";
}
private String getDisableMessage(){
return "§aRegion aufgetaut";
}
private boolean toggle(Region region) {
switch (region.getPlain(Flag.FREEZE, FreezeMode.class)) {
case ACTIVE:
region.set(Flag.FREEZE, FreezeMode.INACTIVE);
return false;
default:
case INACTIVE:
region.set(Flag.FREEZE, FreezeMode.ACTIVE);
return true;
}
}
private boolean permissionCheck(Player player) {
if (!Permission.hasPermission(player, Permission.WORLD)) {
player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
return false;
}
return true;
}
}

Datei anzeigen

@ -0,0 +1,85 @@
package de.steamwar.bausystem.features.region;
import de.steamwar.bausystem.BauSystem;
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.FreezeMode;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
@Linked(LinkageType.LISTENER)
public class FreezeListener implements Listener {
@EventHandler
public void onEntitySpawn(EntitySpawnEvent e) {
if (Region.getRegion(e.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.INACTIVE) {
return;
}
e.setCancelled(true);
if (e.getEntityType() == EntityType.PRIMED_TNT) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
e.getLocation().getBlock().setType(Material.TNT, false);
}, 1L);
}
}
@EventHandler
public void onBlockCanBuild(BlockCanBuildEvent e) {
if (!e.isBuildable()) return;
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.INACTIVE) return;
if (e.getMaterial() == Material.TNT) {
e.setBuildable(false);
e.getBlock().setType(Material.TNT, false);
}
}
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
@EventHandler
public void onPhysicsEvent(BlockPhysicsEvent e){
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e){
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e){
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
@EventHandler
public void onBlockGrow(BlockGrowEvent e){
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
@EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setNewCurrent(e.getOldCurrent());
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
@EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
if (Region.getRegion(e.getDestination().getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) e.setCancelled(true);
}
}

Datei anzeigen

@ -0,0 +1,62 @@
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 org.bukkit.entity.Player;
@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, "§aBoden geschützt");
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

@ -0,0 +1,119 @@
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.TNTMode;
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.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Linked(LinkageType.COMMAND)
public class TNTCommand extends SWCommand {
public TNTCommand() {
super("tnt");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
p.sendMessage("§8/§etnt §8- §7Ändere das TNT verhalten");
p.sendMessage("§8/§etnt §8[§7Mode§8] §8- §7Setzte das TNT verhalten auf einen Modus");
}
@Register
public void toggleCommand(Player p) {
if (!permissionCheck(p)) return;
Region region = Region.getRegion(p.getLocation());
tntToggle(region, null, null);
}
@Register
public void setCommand(Player p, TNTMode tntMode) {
if (!permissionCheck(p)) return;
Region region = Region.getRegion(p.getLocation());
String requestedMessage = null;
switch (tntMode) {
case ALLOW:
requestedMessage = getEnableMessage();
break;
case DENY:
requestedMessage = getDisableMessage();
break;
case ONLY_TB:
requestedMessage = getTestblockEnableMessage();
break;
}
tntToggle(region, tntMode, requestedMessage);
}
@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);
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);
}
private String getEnableMessage() {
return "§aTNT-Schaden aktiviert";
}
private String getDisableMessage() {
return "§cTNT-Schaden deaktiviert";
}
private String getTestblockEnableMessage() {
return "§aTNT-Schaden außerhalb Baurahmen aktiviert";
}
private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) {
if (requestedMode != null && region.hasType(RegionType.TESTBLOCK)) {
region.set(Flag.TNT, requestedMode);
RegionUtils.actionBar(region, requestedMessage);
return;
}
switch (region.getPlain(Flag.TNT, TNTMode.class)) {
case ALLOW:
case ONLY_TB:
region.set(Flag.TNT, TNTMode.DENY);
RegionUtils.actionBar(region, getDisableMessage());
break;
case DENY:
if (region.hasType(RegionType.TESTBLOCK)) {
region.set(Flag.TNT, TNTMode.ONLY_TB);
RegionUtils.actionBar(region, getTestblockEnableMessage());
} else {
region.set(Flag.TNT, TNTMode.ALLOW);
RegionUtils.actionBar(region, getEnableMessage());
}
break;
}
}
private boolean permissionCheck(Player p) {
if (!Permission.hasPermission(p, Permission.WORLD)) {
p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren");
return false;
}
return true;
}
}

Datei anzeigen

@ -0,0 +1,38 @@
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.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import org.bukkit.block.data.type.TNT;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
@Linked(LinkageType.LISTENER)
public class TNTListener implements Listener {
@EventHandler
public void onExplode(EntityExplodeEvent event) {
event.blockList().removeIf(block -> {
Region region = Region.getRegion(block.getLocation());
TNTMode value = region.getPlain(Flag.TNT);
if (value == TNTMode.ALLOW) {
return false;
}
if (region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.NORMAL)) {
RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört");
return true;
}
if (region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) {
RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört");
return true;
}
return value == TNTMode.DENY;
});
}
}

Datei anzeigen

@ -29,7 +29,7 @@ import java.util.Map;
@YAPIONData @YAPIONData
public class FlagStorage { public class FlagStorage {
protected final Map<Flag, Flag.Value<?>> flags; protected Map<Flag, Flag.Value<?>> flags;
public FlagStorage() { public FlagStorage() {
flags = new EnumMap<>(Flag.class); flags = new EnumMap<>(Flag.class);
@ -38,6 +38,7 @@ public class FlagStorage {
@YAPIONPreDeserialization @YAPIONPreDeserialization
private void preDeserializer() { private void preDeserializer() {
flags = new EnumMap<>(Flag.class);
readKeys(); readKeys();
} }

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.region;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.shared.SizedStack;
@ -73,6 +74,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 +140,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) {
@ -211,6 +227,7 @@ public class Region {
public void set(Flag flagType, Flag.Value<?> value) { public void set(Flag flagType, Flag.Value<?> value) {
if (flagStorage.set(flagType, value)) { if (flagStorage.set(flagType, value)) {
regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage)); regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage));
RegionLoader.save();
} }
setLinkedRegion(region -> region.set(flagType, value)); setLinkedRegion(region -> region.set(flagType, value));
} }
@ -219,6 +236,14 @@ public class Region {
return flagStorage.get(flagType); return flagStorage.get(flagType);
} }
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) {
return (T) flagStorage.get(flagType).getValue();
}
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) {
return (T) flagStorage.get(flagType).getValue();
}
public void reset(RegionType regionType) { public void reset(RegionType regionType) {
if (!hasType(regionType)) { if (!hasType(regionType)) {
return; return;

Datei anzeigen

@ -0,0 +1,17 @@
package de.steamwar.bausystem.region;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@UtilityClass
public class RegionUtils {
public void actionBar(Region region, String s) {
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
}
}