Merge pull request 'TntMode' (#163) from TntMode into master
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
a1ee1cfb01
@ -82,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
getCommand("reset").setExecutor(new CommandReset());
|
getCommand("reset").setExecutor(new CommandReset());
|
||||||
getCommand("speed").setExecutor(new CommandSpeed());
|
getCommand("speed").setExecutor(new CommandSpeed());
|
||||||
getCommand("tnt").setExecutor(new CommandTNT());
|
getCommand("tnt").setExecutor(new CommandTNT());
|
||||||
|
getCommand("tnt").setTabCompleter(new CommandTNTTabComplete());
|
||||||
getCommand("fire").setExecutor(new CommandFire());
|
getCommand("fire").setExecutor(new CommandFire());
|
||||||
getCommand("freeze").setExecutor(new CommandFreeze());
|
getCommand("freeze").setExecutor(new CommandFreeze());
|
||||||
getCommand("testblock").setExecutor(new CommandTestblock());
|
getCommand("testblock").setExecutor(new CommandTestblock());
|
||||||
|
@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
|
sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
|
||||||
sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN"));
|
sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName());
|
||||||
sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN"));
|
sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN"));
|
||||||
sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN"));
|
sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN"));
|
||||||
|
|
||||||
|
@ -19,34 +19,148 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.commands;
|
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 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.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
public class CommandTNT extends ToggleCommand {
|
public class CommandTNT implements CommandExecutor, Listener {
|
||||||
|
|
||||||
public CommandTNT(){
|
private static TNTMode tntMode = TNTMode.OFF;
|
||||||
super(true);
|
|
||||||
|
public static TNTMode getTntMode() {
|
||||||
|
return tntMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ToggleCommand getInstance(){
|
public enum TNTMode {
|
||||||
return getInstance(CommandTNT.class);
|
ON("§aan"),
|
||||||
|
ONLY_TB("§7nur §eTestblock"),
|
||||||
|
OFF("§caus");
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
TNTMode(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public CommandTNT() {
|
||||||
String getNoPermMessage() {
|
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNoPermMessage() {
|
||||||
return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren";
|
return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren";
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
String getEnableMessage(){
|
private String getEnableMessage() {
|
||||||
return "§cTNT-Schaden deaktiviert";
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
String getDisableMessage(){
|
|
||||||
return "§aTNT-Schaden aktiviert";
|
return "§aTNT-Schaden aktiviert";
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
private String getDisableMessage() {
|
||||||
public void onExplode(EntityExplodeEvent e) {
|
return "§cTNT-Schaden deaktiviert";
|
||||||
e.blockList().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTestblockEnableMessage() {
|
||||||
|
return "§aTNT-Schaden am Testblock aktiviert";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDamageMessage() {
|
||||||
|
return "§cEine Explosion hätte Blöcke im Baubereich zerstört";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String s, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 0) {
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "an":
|
||||||
|
case "on":
|
||||||
|
tntMode = TNTMode.ON;
|
||||||
|
sendToActionBar(getEnableMessage());
|
||||||
|
return false;
|
||||||
|
case "aus":
|
||||||
|
case "off":
|
||||||
|
tntMode = TNTMode.OFF;
|
||||||
|
sendToActionBar(getDisableMessage());
|
||||||
|
return false;
|
||||||
|
case "testblock":
|
||||||
|
case "tb":
|
||||||
|
if (!Region.buildAreaEnabled()) break;
|
||||||
|
tntMode = TNTMode.ONLY_TB;
|
||||||
|
sendToActionBar(getTestblockEnableMessage());
|
||||||
|
return false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.world.Region;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandTNTTabComplete implements TabCompleter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if(!(sender instanceof Player)) return new ArrayList<>();
|
||||||
|
return tntTabComplete(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> tntTabComplete(String[] args) {
|
||||||
|
List<String> tabComplete = new ArrayList<>();
|
||||||
|
tabComplete.add("an");
|
||||||
|
tabComplete.add("on");
|
||||||
|
tabComplete.add("aus");
|
||||||
|
tabComplete.add("off");
|
||||||
|
if (Region.buildAreaEnabled()) {
|
||||||
|
tabComplete.add("testblock");
|
||||||
|
tabComplete.add("tb");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length >= 2) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return manageList(tabComplete, args, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> manageList(List<String> strings, String[] args, int index) {
|
||||||
|
for (int i = strings.size() - 1; i >= 0; i--) {
|
||||||
|
if (!strings.get(i).startsWith(args[index])) {
|
||||||
|
strings.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -61,7 +61,7 @@ public class BauScoreboard implements Listener {
|
|||||||
strings.add("§1");
|
strings.add("§1");
|
||||||
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||||
strings.add("§2");
|
strings.add("§2");
|
||||||
strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"));
|
strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName());
|
||||||
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
|
strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"));
|
||||||
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
||||||
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
||||||
|
@ -37,6 +37,11 @@ import java.util.logging.Level;
|
|||||||
public class Region {
|
public class Region {
|
||||||
|
|
||||||
private static final List<Region> regions = new ArrayList<>();
|
private static final List<Region> regions = new ArrayList<>();
|
||||||
|
private static boolean buildArea = false;
|
||||||
|
|
||||||
|
public static boolean buildAreaEnabled() {
|
||||||
|
return buildArea;
|
||||||
|
}
|
||||||
|
|
||||||
static{
|
static{
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
@ -80,6 +85,14 @@ public class Region {
|
|||||||
return prototype.inRegion(this, l);
|
return prototype.inRegion(this, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasBuildRegion() {
|
||||||
|
return prototype.buildArea != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inBuildRegion(Location l) {
|
||||||
|
return prototype.buildArea.inRegion(this, l);
|
||||||
|
}
|
||||||
|
|
||||||
public void fastreset(){
|
public void fastreset(){
|
||||||
prototype.fastreset(this);
|
prototype.fastreset(this);
|
||||||
}
|
}
|
||||||
@ -119,6 +132,8 @@ public class Region {
|
|||||||
private final boolean rotate;
|
private final boolean rotate;
|
||||||
|
|
||||||
private final Prototype testblock; //nullable
|
private final Prototype testblock; //nullable
|
||||||
|
private final Prototype buildArea; //nullable
|
||||||
|
|
||||||
private final String protectSchematic; //nullable
|
private final String protectSchematic; //nullable
|
||||||
|
|
||||||
private Prototype(ConfigurationSection config){
|
private Prototype(ConfigurationSection config){
|
||||||
@ -133,9 +148,16 @@ public class Region {
|
|||||||
|
|
||||||
ConfigurationSection testblockSection = config.getConfigurationSection("testblock");
|
ConfigurationSection testblockSection = config.getConfigurationSection("testblock");
|
||||||
testblock = testblockSection != null ? new Prototype(testblockSection) : null;
|
testblock = testblockSection != null ? new Prototype(testblockSection) : null;
|
||||||
|
|
||||||
|
ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea");
|
||||||
|
buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null;
|
||||||
|
if (buildArea != null) {
|
||||||
|
Region.buildArea = true;
|
||||||
|
}
|
||||||
|
|
||||||
protectSchematic = config.getString("protection", null);
|
protectSchematic = config.getString("protection", null);
|
||||||
|
|
||||||
if(!config.getName().equals("testblock"))
|
if(!config.getName().equals("testblock") && !config.getName().equals("buildArea"))
|
||||||
prototypes.put(config.getName(), this);
|
prototypes.put(config.getName(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ public class ScriptListener implements Listener {
|
|||||||
case "trace":
|
case "trace":
|
||||||
return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0;
|
return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0;
|
||||||
case "tnt":
|
case "tnt":
|
||||||
return CommandTNT.getInstance().isOn() ? 1 : 0;
|
return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1;
|
||||||
case "freeze":
|
case "freeze":
|
||||||
return CommandFreeze.getInstance().isOn() ? 1 : 0;
|
return CommandFreeze.getInstance().isOn() ? 1 : 0;
|
||||||
case "fire":
|
case "fire":
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren