SteamWar/BauSystem2.0
Archiviert
12
0

Add RegionUtils

Add FireCommand
Add FireListener
Add FreezeCommand
Add FreezeListener
Add TNTCommand
Add TNTListener
Dieser Commit ist enthalten in:
yoyosource 2021-04-19 17:22:15 +02:00
Ursprung 469c06d7ec
Commit e3987386b1
9 geänderte Dateien mit 431 neuen und 0 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,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

@ -219,6 +219,14 @@ public class Region {
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) {
if (!hasType(regionType)) {
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)));
}
}