TntMode #163
@ -82,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
getCommand("reset").setExecutor(new CommandReset());
|
||||
getCommand("speed").setExecutor(new CommandSpeed());
|
||||
getCommand("tnt").setExecutor(new CommandTNT());
|
||||
getCommand("tnt").setTabCompleter(new CommandTNTTabComplete());
|
||||
getCommand("fire").setExecutor(new CommandFire());
|
||||
getCommand("freeze").setExecutor(new CommandFreeze());
|
||||
getCommand("testblock").setExecutor(new CommandTestblock());
|
||||
|
@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor {
|
||||
@Override
|
||||
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 + "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 + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN"));
|
||||
|
||||
|
@ -19,34 +19,148 @@
|
||||
|
||||
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.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
public class CommandTNT extends ToggleCommand {
|
||||
public class CommandTNT implements CommandExecutor, Listener {
|
||||
|
||||
private static TNTMode tntMode = TNTMode.OFF;
|
||||
|
||||
public static TNTMode getTntMode() {
|
||||
return tntMode;
|
||||
}
|
||||
|
||||
public enum TNTMode {
|
||||
ON("§aan"),
|
||||
|
||||
ONLY_TB("§7nur §eTestblock"),
|
||||
OFF("§caus");
|
||||
|
||||
private String name;
|
||||
|
||||
TNTMode(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CommandTNT() {
|
||||
super(true);
|
||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
|
||||
}
|
||||
|
||||
public static ToggleCommand getInstance(){
|
||||
return getInstance(CommandTNT.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getNoPermMessage() {
|
||||
private String getNoPermMessage() {
|
||||
return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren";
|
||||
}
|
||||
@Override
|
||||
String getEnableMessage(){
|
||||
return "§cTNT-Schaden deaktiviert";
|
||||
}
|
||||
@Override
|
||||
String getDisableMessage(){
|
||||
|
||||
private String getEnableMessage() {
|
||||
return "§aTNT-Schaden aktiviert";
|
||||
}
|
||||
|
||||
private String getDisableMessage() {
|
||||
Lixfel
hat
am, nicht beim. am, nicht beim.
|
||||
return "§cTNT-Schaden deaktiviert";
|
||||
}
|
||||
|
||||
private String getTestblockEnableMessage() {
|
||||
Lixfel
hat
§cEine Explosion hätte Blöcke im Baubereich zerstört §cEine Explosion hätte Blöcke im Baubereich zerstört
|
||||
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());
|
||||
Lixfel
hat
Du registrierst den Command nirgends als Listener (weder implements noch registerEvents(). Du registrierst den Command nirgends als Listener (weder implements noch registerEvents().
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Lixfel
hat
Ich denke, ein switch-case würde sich besser lesen lassen als dieses If if else gedöns. Ich denke, ein switch-case würde sich besser lesen lassen als dieses If if else gedöns.
|
||||
}
|
||||
|
||||
switch (tntMode) {
|
||||
case ON:
|
||||
case ONLY_TB:
|
||||
tntMode = TNTMode.OFF;
|
||||
sendToActionBar(getDisableMessage());
|
||||
break;
|
||||
case OFF:
|
||||
Lixfel
hat
Die invertierung macht hier den Code etwas schwerer zu lesen, da dahinter eh nur eine Zeile kommt, kannst du dieses if zurückinvertieren und dann einfach sendToActionBar aufrufen. Dann hast du da weniger Probleme. Die invertierung macht hier den Code etwas schwerer zu lesen, da dahinter eh nur eine Zeile kommt, kannst du dieses if zurückinvertieren und dann einfach sendToActionBar aufrufen. Dann hast du da weniger Probleme.
|
||||
if (Region.buildAreaEnabled()) {
|
||||
tntMode = TNTMode.ONLY_TB;
|
||||
sendToActionBar(getTestblockEnableMessage());
|
||||
} else {
|
||||
tntMode = TNTMode.ON;
|
||||
sendToActionBar(getEnableMessage());
|
||||
}
|
||||
break;
|
||||
Lixfel
hat
Auch mal mit 1.12 kurz kompilieren (sollte funzen, bin mir aber nicht ganz sicher) Auch mal mit 1.12 kurz kompilieren (sollte funzen, bin mir aber nicht ganz sicher)
YoyoNow
hat
Ja tut. Auch wenn du das gleiche schon in ToggleCommand verwendet hast. Ja tut. Auch wenn du das gleiche schon in ToggleCommand verwendet hast.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExplode(EntityExplodeEvent e) {
|
||||
e.blockList().clear();
|
||||
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("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
|
||||
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("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName());
|
||||
strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus"));
|
||||
|
@ -37,6 +37,11 @@ import java.util.logging.Level;
|
||||
public class Region {
|
||||
|
||||
private static final List<Region> regions = new ArrayList<>();
|
||||
private static boolean buildArea = false;
|
||||
|
||||
public static boolean buildAreaEnabled() {
|
||||
return buildArea;
|
||||
}
|
||||
|
||||
static{
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
@ -80,6 +85,14 @@ public class Region {
|
||||
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(){
|
||||
prototype.fastreset(this);
|
||||
}
|
||||
@ -119,6 +132,8 @@ public class Region {
|
||||
private final boolean rotate;
|
||||
|
||||
private final Prototype testblock; //nullable
|
||||
private final Prototype buildArea; //nullable
|
||||
|
||||
private final String protectSchematic; //nullable
|
||||
|
||||
private Prototype(ConfigurationSection config){
|
||||
@ -133,9 +148,16 @@ public class Region {
|
||||
|
||||
ConfigurationSection testblockSection = config.getConfigurationSection("testblock");
|
||||
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);
|
||||
|
||||
if(!config.getName().equals("testblock"))
|
||||
if(!config.getName().equals("testblock") && !config.getName().equals("buildArea"))
|
||||
prototypes.put(config.getName(), this);
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ public class ScriptListener implements Listener {
|
||||
case "trace":
|
||||
return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0;
|
||||
case "tnt":
|
||||
return CommandTNT.getInstance().isOn() ? 1 : 0;
|
||||
return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1;
|
||||
case "freeze":
|
||||
return CommandFreeze.getInstance().isOn() ? 1 : 0;
|
||||
case "fire":
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Nur Testblock ist ja so nicht ganz richtig. Ist ja eher ein Nicht Baubereich (klingt aber beschissen). Evtl. fällt uns da noch was besseres ein.
Wie würdest du das dann nennen?