|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package de.steamwar.bausystem.commands;
|
|
|
|
|
|
|
|
|
|
import de.steamwar.bausystem.BauSystem;
|
|
|
|
|
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
|
|
|
|
import de.steamwar.bausystem.tracer.record.RecordStatus;
|
|
|
|
|
import de.steamwar.bausystem.tracer.show.TraceShowManager;
|
|
|
|
|
import de.steamwar.bausystem.world.Detonator;
|
|
|
|
|
import de.steamwar.bausystem.world.Region;
|
|
|
|
|
import de.steamwar.inventory.SWAnvilInv;
|
|
|
|
@ -12,15 +15,20 @@ 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.block.Action;
|
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
public class CommandGUI implements CommandExecutor {
|
|
|
|
|
public class CommandGUI implements CommandExecutor, Listener {
|
|
|
|
|
|
|
|
|
|
private static final Set<Player> OPEN_INVS = new HashSet<>();
|
|
|
|
|
private static final Set<Player> OPEN_TRACER_INVS = new HashSet<>();
|
|
|
|
|
private static boolean isRefreshing = false;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -73,6 +81,13 @@ public class CommandGUI implements CommandExecutor {
|
|
|
|
|
anvilInv.setCallback(s -> player.performCommand("speed " + s));
|
|
|
|
|
anvilInv.open();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
inv.setItem(22, Material.OBSERVER, "§7Tracer", Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> {
|
|
|
|
|
player.closeInventory();
|
|
|
|
|
OPEN_TRACER_INVS.add(player);
|
|
|
|
|
traceGUI(player);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
inv.setItem(27, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> {
|
|
|
|
|
SWAnvilInv anvilInv = new SWAnvilInv(player, "Spielerköpfe");
|
|
|
|
|
anvilInv.setItem(Material.NAME_TAG);
|
|
|
|
@ -80,7 +95,7 @@ public class CommandGUI implements CommandExecutor {
|
|
|
|
|
anvilInv.open();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(region == null) {
|
|
|
|
|
if(region == Region.GlobalRegion.getInstance()) {
|
|
|
|
|
inv.setItem(17, Material.BARRIER, "§eKeine Region", clickType -> {});
|
|
|
|
|
inv.setItem(26, Material.BARRIER, "§eKeine Region", clickType -> {});
|
|
|
|
|
inv.setItem(35, Material.BARRIER, "§eKeine Region", clickType -> {});
|
|
|
|
@ -129,19 +144,19 @@ public class CommandGUI implements CommandExecutor {
|
|
|
|
|
|
|
|
|
|
switch (region.getTntMode()) {
|
|
|
|
|
case OFF:
|
|
|
|
|
inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> {
|
|
|
|
|
region.setTntMode(Region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON);
|
|
|
|
|
inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> {
|
|
|
|
|
region.setTntMode(region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON);
|
|
|
|
|
updateInventories();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case ONLY_TB:
|
|
|
|
|
inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> {
|
|
|
|
|
inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> {
|
|
|
|
|
region.setTntMode(CommandTNT.TNTMode.ON);
|
|
|
|
|
updateInventories();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> {
|
|
|
|
|
inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> {
|
|
|
|
|
region.setTntMode(CommandTNT.TNTMode.OFF);
|
|
|
|
|
updateInventories();
|
|
|
|
|
});
|
|
|
|
@ -174,9 +189,60 @@ public class CommandGUI implements CommandExecutor {
|
|
|
|
|
inv.open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void traceGUI(Player player) {
|
|
|
|
|
SWInventory inv = new SWInventory(player, 9, "Tracer");
|
|
|
|
|
inv.setCallback(-1, clickType -> {
|
|
|
|
|
if(!isRefreshing)
|
|
|
|
|
OPEN_TRACER_INVS.remove(player);
|
|
|
|
|
});
|
|
|
|
|
switch (RecordStateMachine.getRecordStatus()) {
|
|
|
|
|
case IDLE:
|
|
|
|
|
inv.setItem(0, getMaterial("SNOWBALL", "SNOW_BALL"), "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> {
|
|
|
|
|
RecordStateMachine.commandAuto();
|
|
|
|
|
updateInventories();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case IDLE_AUTO:
|
|
|
|
|
inv.setItem(0, Material.ENDER_PEARL, "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> {
|
|
|
|
|
RecordStateMachine.commandStart();
|
|
|
|
|
updateInventories();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case RECORD:
|
|
|
|
|
case RECORD_AUTO:
|
|
|
|
|
inv.setItem(0, getMaterial("ENDER_EYE", "EYE_OF_ENDER"), "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> {
|
|
|
|
|
RecordStateMachine.commandStop();
|
|
|
|
|
updateInventories();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if(TraceShowManager.hasActiveShow(player)) {
|
|
|
|
|
inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt"), false, clickType -> {
|
|
|
|
|
player.performCommand("trace hide");
|
|
|
|
|
traceGUI(player);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
inv.setItem(2, Material.GLASS, "§7Showstatus", Arrays.asList("§7Aktuell: §eVersteckt"), false, clickType -> {
|
|
|
|
|
player.performCommand("trace show");
|
|
|
|
|
traceGUI(player);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inv.setItem(4, Material.TNT_MINECART, "§7Trace GUI", Collections.singletonList("§8/§7trace show gui"), false, clickType -> {
|
|
|
|
|
player.closeInventory();
|
|
|
|
|
player.performCommand("trace show gui");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
inv.setItem(6, getMaterial("GRAY_STAINED_GLASS_PANE", "STAINED_GLASS_PANE"), (byte) 7, "§7Coming soon.", Collections.emptyList(), false, clickType -> {});
|
|
|
|
|
|
|
|
|
|
inv.setItem(8, Material.BARRIER, "§7Trace löschen", clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {}));
|
|
|
|
|
|
|
|
|
|
inv.open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void updateInventories() {
|
|
|
|
|
isRefreshing = true;
|
|
|
|
|
OPEN_INVS.forEach(CommandGUI::openBauGui);
|
|
|
|
|
OPEN_TRACER_INVS.forEach(CommandGUI::traceGUI);
|
|
|
|
|
isRefreshing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -196,10 +262,19 @@ public class CommandGUI implements CommandExecutor {
|
|
|
|
|
private static Material getMaterial(String... names) {
|
|
|
|
|
for (String name:names) {
|
|
|
|
|
try {
|
|
|
|
|
Material mat = Material.valueOf(name);
|
|
|
|
|
return mat;
|
|
|
|
|
return Material.valueOf(name);
|
|
|
|
|
}catch (NullPointerException ignored) {}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
|
|
|
if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
|
return;
|
|
|
|
|
if(event.getItem().getType() != Material.NETHER_STAR)
|
|
|
|
|
return;
|
|
|
|
|
openBauGui(event.getPlayer());
|
|
|
|
|
OPEN_INVS.add(event.getPlayer());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Separater PR.