TntMode #163
@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
getCommand("nightvision").setExecutor(new CommandNV());
|
getCommand("nightvision").setExecutor(new CommandNV());
|
||||||
getCommand("reset").setExecutor(new CommandReset());
|
getCommand("reset").setExecutor(new CommandReset());
|
||||||
getCommand("speed").setExecutor(new CommandSpeed());
|
getCommand("speed").setExecutor(new CommandSpeed());
|
||||||
getCommand("buildmode").setExecutor(new CommandBuildMode());
|
|
||||||
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());
|
||||||
|
@ -1,74 +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.world.Region;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
|
|
||||||
public class CommandBuildMode extends ToggleCommand {
|
|
||||||
|
|
||||||
public CommandBuildMode() {
|
|
||||||
super(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ToggleCommand getInstance() {
|
|
||||||
return getInstance(CommandBuildMode.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getNoPermMessage() {
|
|
||||||
return "§cDu darfst hier den Build mode nicht (de-)aktivieren";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getEnableMessage() {
|
|
||||||
return "§aBuild mode aktiviert";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getDisableMessage() {
|
|
||||||
return "§cBuild mode deaktiviert";
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
|
||||||
boolean blocksDestroyed = event.blockList().removeIf(block -> {
|
|
||||||
for (Region region : Region.getRegions()) {
|
|
||||||
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
if (!blocksDestroyed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört."));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -19,34 +19,118 @@
|
|||||||
|
|
||||||
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.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
public class CommandTNT extends ToggleCommand {
|
public class CommandTNT implements CommandExecutor {
|
||||||
|
|
||||||
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"),
|
||||||
Lixfel
hat
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. 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.
YoyoNow
hat
Wie würdest du das dann nennen? Wie würdest du das dann nennen?
|
|||||||
|
OFF("§caus");
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
TNTMode(String name) {
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String getName() {
|
||||||
String getNoPermMessage() {
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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";
|
return "§cTNT-Schaden deaktiviert";
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
String getDisableMessage(){
|
private String getDisableMessage() {
|
||||||
return "§aTNT-Schaden aktiviert";
|
return "§aTNT-Schaden aktiviert";
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
private String getTestblockEnableMessage() {
|
||||||
public void onExplode(EntityExplodeEvent e) {
|
return "§aTNT-Schaden beim Testblock aktiviert";
|
||||||
Lixfel
hat
am, nicht beim. am, nicht beim.
|
|||||||
e.blockList().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDamageMessage() {
|
||||||
|
return "§cEs ist etwas explodiert und hätte blöcke zerstört";
|
||||||
Lixfel
hat
§cEine Explosion hätte Blöcke im Baubereich zerstört §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 && args[0].equalsIgnoreCase("on")) {
|
||||||
|
tntMode = TNTMode.ON;
|
||||||
|
sendToActionBar(getEnableMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (tntMode) {
|
||||||
|
case ON:
|
||||||
|
case ONLY_TB:
|
||||||
|
tntMode = TNTMode.OFF;
|
||||||
|
sendToActionBar(getDisableMessage());
|
||||||
|
break;
|
||||||
|
case OFF:
|
||||||
|
tntMode = TNTMode.ONLY_TB;
|
||||||
|
sendToActionBar(getTestblockEnableMessage());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onExplode(EntityExplodeEvent event) {
|
||||||
Lixfel
hat
Du registrierst den Command nirgends als Listener (weder implements noch registerEvents(). Du registrierst den Command nirgends als Listener (weder implements noch registerEvents().
|
|||||||
|
if (tntMode == TNTMode.ON) return;
|
||||||
|
if (tntMode == TNTMode.OFF) {
|
||||||
|
event.blockList().clear();
|
||||||
|
} else {
|
||||||
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.
|
|||||||
|
boolean blocksDestroyed = event.blockList().removeIf(block -> {
|
||||||
|
for (Region region : Region.getRegions()) {
|
||||||
|
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (!blocksDestroyed) {
|
||||||
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.
|
|||||||
|
return;
|
||||||
|
}
|
||||||
|
sendToActionBar(getDamageMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendToActionBar(String message) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)));
|
||||||
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.
|
|||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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 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 detonaterTabComplete((Player) sender, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> detonaterTabComplete(Player player, String[] args) {
|
||||||
|
List<String> tabComplete = new ArrayList<>();
|
||||||
|
tabComplete.add("an");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.world;
|
package de.steamwar.bausystem.world;
|
||||||
|
|
||||||
import de.steamwar.bausystem.commands.CommandBuildMode;
|
|
||||||
import de.steamwar.bausystem.commands.CommandFreeze;
|
import de.steamwar.bausystem.commands.CommandFreeze;
|
||||||
import de.steamwar.bausystem.commands.CommandTNT;
|
import de.steamwar.bausystem.commands.CommandTNT;
|
||||||
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
||||||
@ -62,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: " + tntString());
|
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"));
|
||||||
@ -105,14 +104,4 @@ public class BauScoreboard implements Listener {
|
|||||||
return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit();
|
return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String tntString() {
|
|
||||||
if (!CommandTNT.getInstance().isOn()) {
|
|
||||||
if (CommandBuildMode.getInstance().isOn()) {
|
|
||||||
return "§7nur §eTestblock";
|
|
||||||
}
|
|
||||||
return "§aan";
|
|
||||||
}
|
|
||||||
return "§caus";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ commands:
|
|||||||
debugstick:
|
debugstick:
|
||||||
tnt:
|
tnt:
|
||||||
fire:
|
fire:
|
||||||
buildmode:
|
|
||||||
trace:
|
trace:
|
||||||
tpslimit:
|
tpslimit:
|
||||||
testblock:
|
testblock:
|
||||||
|
Finde das als Extracommand nicht so gut, da die Funktionalität mit dem TNT-Command kollidiert. Würde den Standard-TNT-Modus zum Buildmode setzen, und standardmäßig zwischen Aus und "Buildmode" (Bessere Wortwahl fehlt mir noch) zu toggeln, nur wenn "an" extra als Argument übergeben wird, in den alten An modus zu gehen.