Expanding Inventory
Dieser Commit ist enthalten in:
Ursprung
080d810bc4
Commit
0b95df4bda
@ -2,7 +2,8 @@ package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.world.Detonator;
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import de.steamwar.bausystem.world.Region;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
@ -11,100 +12,184 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CommandGUI implements CommandExecutor {
|
||||
|
||||
private static final Set<Player> OPEN_INVS = new HashSet<>();
|
||||
private static boolean isRefreshing = false;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
if(!(commandSender instanceof Player))
|
||||
return false;
|
||||
Player player = ((Player) commandSender);
|
||||
openBauGui(player);
|
||||
OPEN_INVS.add(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void openBauGui(Player player) {
|
||||
Region region = Region.getRegionIn(player.getLocation());
|
||||
SWInventory inv = new SWInventory(player, 5*9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau");
|
||||
|
||||
inv.setItem(3, Detonator.WAND, clickType -> {
|
||||
player.closeInventory();
|
||||
player.getInventory().setItemInMainHand(Detonator.WAND);
|
||||
inv.setCallback(-1, clickType -> {
|
||||
if(!isRefreshing)
|
||||
OPEN_INVS.remove(player);
|
||||
});
|
||||
|
||||
inv.setItem(4, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", clickType -> {
|
||||
inv.setItem(2, Material.GLASS_PANE, "§7Platzhalter", clickType -> {});
|
||||
|
||||
ItemStack dtWand = Detonator.WAND.clone();
|
||||
ItemMeta meta = dtWand.getItemMeta();
|
||||
List<String> lore = meta.getLore();
|
||||
lore.add("§8/§7dt wand");
|
||||
meta.setLore(lore);
|
||||
dtWand.setItemMeta(meta);
|
||||
inv.setItem(3, dtWand, clickType -> {
|
||||
player.closeInventory();
|
||||
player.performCommand("dt wand");
|
||||
});
|
||||
|
||||
inv.setItem(4, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", Arrays.asList("§8//§7wand"), false, clickType -> {
|
||||
player.closeInventory();
|
||||
player.performCommand("/wand");
|
||||
});
|
||||
inv.setItem(5, Material.GLASS_PANE, "§7Platzhalter", clickType -> {});
|
||||
inv.setItem(6, Material.GLASS_PANE, "§7Platzhalter", clickType -> {});
|
||||
|
||||
if(CommandFreeze.getInstance().isOn()) {
|
||||
inv.setItem(30, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", clickType -> {
|
||||
CommandFreeze.getInstance().toggle();
|
||||
openBauGui(player);
|
||||
inv.setItem(9, Material.COMPASS, "§7TPS Limitieren", Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), false, clickType -> {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren");
|
||||
anvilInv.setItem(Material.COMPASS);
|
||||
anvilInv.setCallback(s -> player.performCommand("tpslimit " + s));
|
||||
anvilInv.open();
|
||||
});
|
||||
inv.setItem(18, Material.FEATHER, "§7Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + player.getFlySpeed() * 10, "§8/§7speed §8[§e1 - 10§8]"), false, clickType -> {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "Geschwindigkeit");
|
||||
anvilInv.setItem(Material.FEATHER);
|
||||
anvilInv.setCallback(s -> player.performCommand("speed " + s));
|
||||
anvilInv.open();
|
||||
});
|
||||
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);
|
||||
anvilInv.setCallback(s -> player.performCommand("skull " + s));
|
||||
anvilInv.open();
|
||||
});
|
||||
|
||||
if(region == null) {
|
||||
inv.setItem(17, Material.BARRIER, "§eKeine Region", clickType -> {});
|
||||
inv.setItem(26, Material.BARRIER, "§eKeine Region", clickType -> {});
|
||||
inv.setItem(35, Material.BARRIER, "§eKeine Region", clickType -> {});
|
||||
}else {
|
||||
inv.setItem(30, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", clickType -> {
|
||||
CommandFreeze.getInstance().toggle();
|
||||
openBauGui(player);
|
||||
});
|
||||
inv.setItem(17, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", Arrays.asList("§8/§7reset"), false, clickType ->
|
||||
confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player)));
|
||||
|
||||
if(region.hasProtection()) {
|
||||
inv.setItem(26, Material.OBSIDIAN, "§eRegion Protecten", Arrays.asList("§8/§7protect"), false, clickType ->
|
||||
confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player)));
|
||||
} else {
|
||||
inv.setItem(26, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {});
|
||||
}
|
||||
|
||||
switch (CommandTNT.getTntMode()) {
|
||||
case OFF:
|
||||
inv.setItem(31, Material.MINECART, "§7TNT: §eAusgeschaltet", clickType -> {
|
||||
CommandTNT.setTntMode(CommandTNT.TNTMode.ONLY_TB);
|
||||
openBauGui(player);
|
||||
});
|
||||
break;
|
||||
case ONLY_TB:
|
||||
inv.setItem(31, Material.TNT_MINECART, "§7TNT: §enur Testblock", clickType -> {
|
||||
CommandTNT.setTntMode(CommandTNT.TNTMode.ON);
|
||||
openBauGui(player);
|
||||
});
|
||||
break;
|
||||
default:
|
||||
inv.setItem(31, Material.TNT, "§7TNT: §eEingeschaltet", clickType -> {
|
||||
CommandTNT.setTntMode(CommandTNT.TNTMode.OFF);
|
||||
openBauGui(player);
|
||||
});
|
||||
}
|
||||
|
||||
if(CommandFire.getInstance().isOn()) {
|
||||
inv.setItem(32, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", clickType -> {
|
||||
CommandFire.getInstance().toggle();
|
||||
openBauGui(player);
|
||||
});
|
||||
if(region.hasTestblock()) {
|
||||
inv.setItem(35, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", Arrays.asList("§8/§7testblock"), false, clickType ->
|
||||
confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player)));
|
||||
} else {
|
||||
inv.setItem(32, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", clickType -> {
|
||||
CommandFire.getInstance().toggle();
|
||||
openBauGui(player);
|
||||
});
|
||||
inv.setItem(35, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {});
|
||||
}
|
||||
}
|
||||
|
||||
if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
|
||||
inv.setItem(38, Material.POTION, "§7Nightvision: §eEingeschaltet", clickType -> {
|
||||
inv.setItem(38, Material.POTION, "§7Nightvision: §eEingeschaltet", Arrays.asList("§8/§7nv"), false, clickType -> {
|
||||
CommandNV.toggleNightvision(player);
|
||||
openBauGui(player);
|
||||
});
|
||||
} else {
|
||||
inv.setItem(38, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", clickType -> {
|
||||
inv.setItem(38, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", Arrays.asList("§8/§7nv"), false, clickType -> {
|
||||
CommandNV.toggleNightvision(player);
|
||||
openBauGui(player);
|
||||
});
|
||||
}
|
||||
|
||||
if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) {
|
||||
inv.setItem(40, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", clickType -> {
|
||||
inv.setItem(39, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Arrays.asList("§8/§7wv"), false, clickType -> {
|
||||
CommandGills.toggleGills(player);
|
||||
openBauGui(player);
|
||||
});
|
||||
} else {
|
||||
inv.setItem(40, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", clickType -> {
|
||||
inv.setItem(39, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", Arrays.asList("§8/§7wv"), false, clickType -> {
|
||||
CommandGills.toggleGills(player);
|
||||
openBauGui(player);
|
||||
});
|
||||
}
|
||||
|
||||
switch (CommandTNT.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 -> {
|
||||
CommandTNT.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 -> {
|
||||
CommandTNT.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 -> {
|
||||
CommandTNT.setTntMode(CommandTNT.TNTMode.OFF);
|
||||
updateInventories();
|
||||
});
|
||||
}
|
||||
|
||||
if(CommandFreeze.getInstance().isOn()) {
|
||||
inv.setItem(41, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> {
|
||||
CommandFreeze.getInstance().toggle();
|
||||
updateInventories();
|
||||
});
|
||||
} else {
|
||||
inv.setItem(41, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> {
|
||||
CommandFreeze.getInstance().toggle();
|
||||
updateInventories();
|
||||
});
|
||||
}
|
||||
|
||||
if(CommandFire.getInstance().isOn()) {
|
||||
inv.setItem(42, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> {
|
||||
CommandFire.getInstance().toggle();
|
||||
updateInventories();
|
||||
});
|
||||
} else {
|
||||
inv.setItem(42, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> {
|
||||
CommandFire.getInstance().toggle();
|
||||
updateInventories();
|
||||
});
|
||||
}
|
||||
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private static void updateInventories() {
|
||||
isRefreshing = true;
|
||||
OPEN_INVS.forEach(CommandGUI::openBauGui);
|
||||
isRefreshing = false;
|
||||
}
|
||||
|
||||
private static void confirmationInventory(Player player, String title, Runnable confirm, Runnable decline) {
|
||||
SWInventory inv = new SWInventory(player, 9, title);
|
||||
inv.setItem(0, SWItem.getDye(1), "§cAbbrechen", clickType -> {
|
||||
player.closeInventory();
|
||||
decline.run();
|
||||
});
|
||||
inv.setItem(8, SWItem.getDye(10), "§aBestätigen", clickType -> {
|
||||
player.closeInventory();
|
||||
confirm.run();
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,15 @@ public class Region {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public static Region getRegionIn(Location location) {
|
||||
for(Region region : Region.getRegions()) {
|
||||
if (region.inRegion(location)) {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final int minX;
|
||||
private final int minY;
|
||||
private final int minZ;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren