Add Region section Support for /tnt /fire /freeze #168
@ -19,18 +19,15 @@
|
||||
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.world.Region;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
|
||||
public class CommandFire extends ToggleCommand {
|
||||
public class CommandFire extends RegionToggleCommand {
|
||||
|
||||
public CommandFire(){
|
||||
super(true);
|
||||
}
|
||||
|
||||
public static ToggleCommand getInstance(){
|
||||
return getInstance(CommandFire.class);
|
||||
public CommandFire() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,15 +42,29 @@ public class CommandFire extends ToggleCommand {
|
||||
String getDisableMessage(){
|
||||
return "§aFeuerschaden aktiviert";
|
||||
}
|
||||
@Override
|
||||
String getNoRegionMessage() {
|
||||
return "§cDu befindest dich derzeit in keiner Region";
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean toggle(Region region) {
|
||||
region.setFire(!region.isFire());
|
||||
return region.isFire();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFireDamage(BlockBurnEvent e) {
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFire()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFireSpread(BlockSpreadEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFire()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,36 +1,41 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.world.Region;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
|
||||
public class CommandFreeze extends ToggleCommand {
|
||||
public class CommandFreeze extends RegionToggleCommand {
|
||||
|
||||
public CommandFreeze(){
|
||||
super(false);
|
||||
}
|
||||
|
||||
public static ToggleCommand getInstance(){
|
||||
return getInstance(CommandFreeze.class);
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,39 +50,75 @@ public class CommandFreeze extends ToggleCommand {
|
||||
String getDisableMessage(){
|
||||
return "§aWelt aufgetaut";
|
||||
}
|
||||
@Override
|
||||
String getNoRegionMessage() {
|
||||
return "§cDu befindest dich derzeit in keiner Region";
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean toggle(Region region) {
|
||||
region.setFreeze(!region.isFreeze());
|
||||
return region.isFreeze();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent e) {
|
||||
Region.getRegion(e.getLocation(), region -> {
|
||||
if (!region.isFreeze()) {
|
||||
return;
|
||||
}
|
||||
if (e.getEntityType() == EntityType.FALLING_BLOCK) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPhysicsEvent(BlockPhysicsEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPistonExtend(BlockPistonExtendEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPistonRetract(BlockPistonRetractEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockGrow(BlockGrowEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRedstoneEvent(BlockRedstoneEvent e){
|
||||
e.setNewCurrent(e.getOldCurrent());
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockDispense(BlockDispenseEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getBlock().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
|
||||
e.setCancelled(true);
|
||||
Region.getRegion(e.getDestination().getLocation(), region -> {
|
||||
if (region.isFreeze()) e.setCancelled(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,14 @@
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.world.Region;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -33,10 +35,17 @@ public class CommandInfo implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
|
||||
sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName());
|
||||
sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN"));
|
||||
sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN"));
|
||||
Region.getRegion(player.getLocation(), region -> {
|
||||
sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS"));
|
||||
}, () -> {
|
||||
sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region.");
|
||||
});
|
||||
|
||||
List<BauweltMember> members = BauweltMember.getMembers(BauSystem.getOwnerID());
|
||||
StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: ");
|
||||
|
@ -45,28 +45,26 @@ public class CommandProtect implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Region region : Region.getRegions()){
|
||||
if(region.inRegion(player.getLocation()) && region.hasProtection()){
|
||||
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;
|
||||
}
|
||||
Region region = Region.getRegion(player);
|
||||
if (region == null || !region.hasProtection()) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region");
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -45,29 +45,27 @@ public class CommandReset implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Region region : Region.getRegions()){
|
||||
if(region.inRegion(player.getLocation())){
|
||||
try {
|
||||
if(args.length > 0){
|
||||
Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
|
||||
if(schem == null){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
|
||||
return false;
|
||||
}
|
||||
region.reset(schem);
|
||||
}else{
|
||||
region.fastreset();
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt");
|
||||
}catch(Exception e){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region");
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed reset", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Region region = Region.getRegion(player);
|
||||
if (region == null) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if(args.length > 0){
|
||||
Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
|
||||
if(schem == null){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
|
||||
return false;
|
||||
}
|
||||
region.reset(schem);
|
||||
}else{
|
||||
region.fastreset();
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt");
|
||||
}catch(Exception e){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region");
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed reset", e);
|
||||
}
|
||||
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -36,12 +36,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class CommandTNT implements CommandExecutor, Listener {
|
||||
|
||||
private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
|
||||
|
||||
public static TNTMode getTntMode() {
|
||||
return tntMode;
|
||||
}
|
||||
|
||||
public enum TNTMode {
|
||||
ON("§aan"),
|
||||
ONLY_TB("§7nur §eTestblock"),
|
||||
@ -83,6 +77,10 @@ public class CommandTNT implements CommandExecutor, Listener {
|
||||
return "§cEine Explosion hätte Blöcke im Baubereich zerstört";
|
||||
}
|
||||
|
||||
private String getNoRegionMessage() {
|
||||
return "§cDu befindest dich derzeit in keiner Region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (!(sender instanceof Player)) return false;
|
||||
@ -93,74 +91,72 @@ public class CommandTNT implements CommandExecutor, Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
TNTMode requestedMode = null;
|
||||
String requestedMessage = null;
|
||||
if (args.length != 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "an":
|
||||
case "on":
|
||||
tntMode = TNTMode.ON;
|
||||
sendToActionBar(getEnableMessage());
|
||||
return false;
|
||||
requestedMode = TNTMode.ON;
|
||||
requestedMessage = getEnableMessage();
|
||||
break;
|
||||
case "aus":
|
||||
case "off":
|
||||
tntMode = TNTMode.OFF;
|
||||
sendToActionBar(getDisableMessage());
|
||||
return false;
|
||||
requestedMode = TNTMode.OFF;
|
||||
requestedMessage = getDisableMessage();
|
||||
break;
|
||||
case "testblock":
|
||||
case "tb":
|
||||
if (!Region.buildAreaEnabled()) break;
|
||||
tntMode = TNTMode.ONLY_TB;
|
||||
sendToActionBar(getTestblockEnableMessage());
|
||||
return false;
|
||||
requestedMode = TNTMode.ONLY_TB;
|
||||
requestedMessage = getTestblockEnableMessage();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (tntMode) {
|
||||
case ON:
|
||||
case ONLY_TB:
|
||||
tntMode = TNTMode.OFF;
|
||||
sendToActionBar(getDisableMessage());
|
||||
break;
|
||||
case OFF:
|
||||
if (Region.buildAreaEnabled()) {
|
||||
tntMode = TNTMode.ONLY_TB;
|
||||
sendToActionBar(getTestblockEnableMessage());
|
||||
} else {
|
||||
tntMode = TNTMode.ON;
|
||||
sendToActionBar(getEnableMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
TNTMode finalRequestedMode = requestedMode;
|
||||
String finalRequestedMessage = requestedMessage;
|
||||
Region.getRegion(player.getLocation(), region -> {
|
||||
if (finalRequestedMode != null) {
|
||||
region.setTntMode(finalRequestedMode);
|
||||
RegionToggleCommand.actionBar(region, finalRequestedMessage);
|
||||
return;
|
||||
}
|
||||
switch (region.getTntMode()) {
|
||||
case ON:
|
||||
case ONLY_TB:
|
||||
region.setTntMode(TNTMode.OFF);
|
||||
RegionToggleCommand.actionBar(region, getDisableMessage());
|
||||
break;
|
||||
case OFF:
|
||||
if (Region.buildAreaEnabled()) {
|
||||
region.setTntMode(TNTMode.ONLY_TB);
|
||||
RegionToggleCommand.actionBar(region, getTestblockEnableMessage());
|
||||
} else {
|
||||
region.setTntMode(TNTMode.ON);
|
||||
RegionToggleCommand.actionBar(region, getEnableMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, () -> RegionToggleCommand.actionBar(player, getNoRegionMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExplode(EntityExplodeEvent event) {
|
||||
switch (tntMode) {
|
||||
case ON:
|
||||
break;
|
||||
case OFF:
|
||||
event.blockList().clear();
|
||||
break;
|
||||
case ONLY_TB:
|
||||
boolean blocksDestroyed = event.blockList().removeIf(block -> {
|
||||
for (Region region : Region.getRegions()) {
|
||||
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (blocksDestroyed) {
|
||||
sendToActionBar(getDamageMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendToActionBar(String message) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)));
|
||||
event.blockList().removeIf(block -> {
|
||||
Region region = Region.getRegion(block.getLocation());
|
||||
if (region == null) return false;
|
||||
if (region.getTntMode() == TNTMode.OFF) return true;
|
||||
if (region.getTntMode() == TNTMode.ON) return false;
|
||||
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
|
||||
RegionToggleCommand.actionBar(region, getDamageMessage());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,28 +45,26 @@ public class CommandTestblock implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Region region : Region.getRegions()){
|
||||
if(region.inRegion(player.getLocation()) && region.hasTestblock()){
|
||||
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.resetTestblock(schem);
|
||||
player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
|
||||
}catch(Exception e){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Region region = Region.getRegion(player);
|
||||
if (region == null || !region.hasTestblock()) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
|
||||
return false;
|
||||
}
|
||||
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.resetTestblock(schem);
|
||||
player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
|
||||
}catch(Exception e){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
|
||||
}
|
||||
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* /
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.world.Region;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.minecraft.server.v1_15_R1.BlockCactus;
|
||||
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 org.bukkit.event.Listener;
|
||||
|
||||
public abstract class RegionToggleCommand implements CommandExecutor, Listener {
|
||||
|
||||
RegionToggleCommand() {
|
||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player))
|
||||
return false;
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (Welt.noPermission(player, Permission.world)){
|
||||
player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
Region.getRegion(player.getLocation(), region -> {
|
||||
if (toggle(region)) {
|
||||
actionBar(region, getEnableMessage());
|
||||
} else {
|
||||
actionBar(region, getDisableMessage());
|
||||
}
|
||||
}, () -> actionBar(player, getNoRegionMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void actionBar(Region region, String s) {
|
||||
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
|
||||
}
|
||||
|
||||
public static void actionBar(Player player, String s) {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s));
|
||||
}
|
||||
|
||||
abstract String getNoRegionMessage();
|
||||
abstract String getNoPermMessage();
|
||||
abstract String getEnableMessage();
|
||||
abstract String getDisableMessage();
|
||||
|
||||
/**
|
||||
* {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()}
|
||||
*/
|
||||
abstract boolean toggle(Region region);
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
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 org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ToggleCommand implements CommandExecutor, Listener {
|
||||
|
||||
private static Map<Class<? extends ToggleCommand>, Boolean> enabled = new HashMap<>();
|
||||
private static Map<Class<? extends ToggleCommand>, ToggleCommand> instance = new HashMap<>();
|
||||
|
||||
ToggleCommand(boolean on){
|
||||
enabled.put(getClass(), false);
|
||||
if(on)
|
||||
toggle();
|
||||
instance.put(getClass(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player))
|
||||
return false;
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (Welt.noPermission(player, Permission.world)){
|
||||
player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
toggle();
|
||||
return false;
|
||||
}
|
||||
|
||||
static ToggleCommand getInstance(Class<? extends ToggleCommand> clazz){
|
||||
return instance.get(clazz);
|
||||
}
|
||||
|
||||
abstract String getNoPermMessage();
|
||||
abstract String getEnableMessage();
|
||||
abstract String getDisableMessage();
|
||||
|
||||
public boolean isOn(){
|
||||
return enabled.get(getClass());
|
||||
}
|
||||
|
||||
public void toggle(){
|
||||
enabled.compute(getClass(), (clazz, value) -> !value);
|
||||
if(enabled.get(getClass())){
|
||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getEnableMessage())));
|
||||
}else{
|
||||
HandlerList.unregisterAll(this);
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getDisableMessage())));
|
||||
}
|
||||
}
|
||||
}
|
@ -19,8 +19,6 @@
|
||||
|
||||
package de.steamwar.bausystem.world;
|
||||
|
||||
import de.steamwar.bausystem.commands.CommandFreeze;
|
||||
import de.steamwar.bausystem.commands.CommandTNT;
|
||||
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||
import de.steamwar.core.TPSWatcher;
|
||||
@ -61,8 +59,12 @@ public class BauScoreboard implements Listener {
|
||||
strings.add("§1");
|
||||
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||
strings.add("§2");
|
||||
strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName());
|
||||
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
|
||||
Region region = Region.getRegion(p);
|
||||
if (region != null) {
|
||||
strings.add("§eTNT§8: " + region.getTntMode().getName());
|
||||
strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus"));
|
||||
strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can"));
|
||||
}
|
||||
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
||||
|
||||
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.world;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.commands.CommandTNT.TNTMode;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.Schematic;
|
||||
@ -28,10 +29,12 @@ import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Region {
|
||||
@ -39,10 +42,6 @@ public class Region {
|
||||
private static final List<Region> regions = new ArrayList<>();
|
||||
private static boolean buildArea = false;
|
||||
|
||||
Lixfel
hat
Statt der Klasse wäre es eleganter gewesen, einfach public static globalTnt etc. zu haben, durch die Klasse gewinnst du schließlich nix (es sei denn, sie wäre eine Region, die immer zurückgegeben worden wäre, wenn man in keiner Region wäre, was allerdings Probleme bei einigen Befehlen verursachen würde). Statt der Klasse wäre es eleganter gewesen, einfach public static globalTnt etc. zu haben, durch die Klasse gewinnst du schließlich nix (es sei denn, sie wäre eine Region, die immer zurückgegeben worden wäre, wenn man in keiner Region wäre, was allerdings Probleme bei einigen Befehlen verursachen würde).
YoyoNow
hat
Baue ich um. Wollte halt damit das ganze abkapseln deswegen. Baue ich um. Wollte halt damit das ganze abkapseln deswegen.
YoyoNow
hat
Ich glaube ich finde es weiterhin besser, wenn man Klassen mäßig abgekapselt ist. Das ist glaube doch noch eleganter, weil dann nicht einfach 3 Fields in der Region Klasse static drin stehen. Deswegen so gelöst. Ich glaube ich finde es weiterhin besser, wenn man Klassen mäßig abgekapselt ist. Das ist glaube doch noch eleganter, weil dann nicht einfach 3 Fields in der Region Klasse static drin stehen. Deswegen so gelöst.
|
||||
public static boolean buildAreaEnabled() {
|
||||
return buildArea;
|
||||
}
|
||||
|
||||
static{
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
try {
|
||||
@ -64,23 +63,125 @@ public class Region {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean buildAreaEnabled() {
|
||||
return buildArea;
|
||||
}
|
||||
|
||||
public static Region getRegion(Player player) {
|
||||
return getRegion(player.getLocation());
|
||||
}
|
||||
|
||||
public static Region getRegion(Location location) {
|
||||
for (Region region : regions) {
|
||||
if (region.inRegion(location)) return region;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void getRegion(Location location, Consumer<Region> regionConsumer) {
|
||||
getRegion(location, regionConsumer, () -> {});
|
||||
}
|
||||
|
||||
public static void getRegion(Location location, Consumer<Region> regionConsumer, Runnable noRegion) {
|
||||
boolean b = true;
|
||||
for (Region region : regions) {
|
||||
if (region.inRegion(location)) {
|
||||
regionConsumer.accept(region);
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
if (b) {
|
||||
noRegion.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Region> getRegions(){
|
||||
return regions;
|
||||
}
|
||||
|
||||
private static Region getRegionByName(String name) {
|
||||
for (Region region : regions) {
|
||||
if (region.name.equals(name)) return region;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final int minX;
|
||||
private final int minY;
|
||||
private final int minZ;
|
||||
private final Prototype prototype;
|
||||
private final String optionsLinkedWith; // nullable
|
||||
private Region linkedRegion = null; // nullable
|
||||
|
||||
private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
|
||||
private boolean freeze = false;
|
||||
private boolean fire = false;
|
||||
|
||||
private Region(ConfigurationSection config){
|
||||
name = config.getName();
|
||||
minX = config.getInt("minX");
|
||||
minY = config.getInt("minY");
|
||||
minZ = config.getInt("minZ");
|
||||
prototype = Prototype.prototypes.get(config.getString("prototype"));
|
||||
optionsLinkedWith = config.getString("optionsLinkedWith", null);
|
||||
regions.add(this);
|
||||
}
|
||||
|
||||
private void link() {
|
||||
if (optionsLinkedWith != null && linkedRegion == null) {
|
||||
linkedRegion = getRegionByName(optionsLinkedWith);
|
||||
}
|
||||
}
|
||||
|
||||
public TNTMode getTntMode() {
|
||||
return tntMode;
|
||||
}
|
||||
|
||||
public void setTntMode(TNTMode tntMode) {
|
||||
this.tntMode = tntMode;
|
||||
link();
|
||||
if (linkedRegion != null) {
|
||||
linkedRegion.setTntModeOther(tntMode);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTntModeOther(TNTMode tntMode) {
|
||||
this.tntMode = tntMode;
|
||||
}
|
||||
|
||||
public boolean isFreeze() {
|
||||
return freeze;
|
||||
}
|
||||
|
||||
public void setFreeze(boolean freeze) {
|
||||
this.freeze = freeze;
|
||||
link();
|
||||
if (linkedRegion != null) {
|
||||
linkedRegion.setFreezeOther(freeze);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFreezeOther(boolean freeze) {
|
||||
this.freeze = freeze;
|
||||
}
|
||||
|
||||
public boolean isFire() {
|
||||
return fire;
|
||||
}
|
||||
|
||||
public void setFire(boolean fire) {
|
||||
this.fire = fire;
|
||||
link();
|
||||
if (linkedRegion != null) {
|
||||
linkedRegion.setFireOther(fire);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFireOther(boolean fire) {
|
||||
this.fire = fire;
|
||||
}
|
||||
|
||||
public boolean inRegion(Location l){
|
||||
return prototype.inRegion(this, l);
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
package de.steamwar.bausystem.world;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.commands.CommandFire;
|
||||
import de.steamwar.bausystem.commands.CommandFreeze;
|
||||
import de.steamwar.bausystem.commands.CommandScript;
|
||||
import de.steamwar.bausystem.commands.CommandTNT;
|
||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||
@ -153,6 +151,8 @@ public class ScriptListener implements Listener {
|
||||
index = ifJumpIndex;
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
|
||||
@ -235,6 +235,8 @@ public class ScriptListener implements Listener {
|
||||
case "--":
|
||||
add(scriptExecutor, args[0], -1);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
setValue(scriptExecutor, args[0], args[1]);
|
||||
}
|
||||
@ -280,17 +282,19 @@ public class ScriptListener implements Listener {
|
||||
}
|
||||
|
||||
private static int getValue(ScriptExecutor scriptExecutor, String key) {
|
||||
Region region = Region.getRegion(scriptExecutor.player);
|
||||
switch (key) {
|
||||
case "trace":
|
||||
return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0;
|
||||
case "tnt":
|
||||
return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1;
|
||||
return region == null || region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1;
|
||||
case "freeze":
|
||||
return CommandFreeze.getInstance().isOn() ? 1 : 0;
|
||||
return region == null || !region.isFreeze() ? 0 : 1;
|
||||
case "fire":
|
||||
return CommandFire.getInstance().isOn() ? 1 : 0;
|
||||
return region == null || !region.isFire() ? 0 : 1;
|
||||
default:
|
||||
return scriptExecutor.variables.getOrDefault(key, 0);
|
||||
}
|
||||
return scriptExecutor.variables.getOrDefault(key, 0);
|
||||
}
|
||||
|
||||
private static boolean isVariable(ScriptExecutor scriptExecutor, String key) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Nur Testblock hat viele Spieler verwirrt/ist zu verwirrend: Alternative (etwas länger:) Nur außerhalb Baurahmen (kürzer:) Außerhalb Rahmen evtl. dürfte reichen "Baurahmen"? Einfach mal kurz User fragen, ob die das verstehen würden (A'la: Wenn im Scoreboard bei TNT: Baurahmen stehen würde, was denkst du, dass der TNT-Modus dann macht?
den Baurahmen zerstören also 'Außerhalb Baurahmen ist glaube besser'
Dieser Text ist viel zu lang. gibt es noch einen griffigeren Begriff oder Halbsatz?
TNT an/aus je nachdem, ob man sich derzeit im Baubereich befindet?
Weiß nicht. Macht das das ganze nicht noch langsamer mit dem Region zeug? und dann verwirrt das nur wieder, weil man das ganze nicht versteht und so.