Chest UI for War

This commit is contained in:
Connor Monahan 2017-07-27 15:55:10 -05:00
parent 994fec5a14
commit 9135e5bf22
28 changed files with 1323 additions and 126 deletions

View File

@ -501,7 +501,7 @@ public class Team {
}
}
public int getRemainingLifes() {
public int getRemainingLives() {
return this.remainingLives;
}

View File

@ -9,6 +9,7 @@ import java.util.logging.Formatter;
import java.util.logging.Level;
import com.tommytony.war.job.CapturePointTimer;
import com.tommytony.war.ui.UIManager;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
@ -115,6 +116,7 @@ public class War extends JavaPlugin {
private HubLobbyMaterials warhubMaterials = new HubLobbyMaterials(
new ItemStack(Material.GLASS), new ItemStack(Material.WOOD),
new ItemStack(Material.OBSIDIAN), new ItemStack(Material.GLOWSTONE));
private UIManager UIManager;
public War() {
super();
@ -159,6 +161,7 @@ public class War extends JavaPlugin {
this.getServer().getPluginManager().disablePlugin(this);
return;
}
this.UIManager = new UIManager(this);
// Register events
PluginManager pm = this.getServer().getPluginManager();
@ -166,6 +169,7 @@ public class War extends JavaPlugin {
pm.registerEvents(this.entityListener, this);
pm.registerEvents(this.blockListener, this);
pm.registerEvents(this.serverListener, this);
pm.registerEvents(this.UIManager, this);
if (pm.isPluginEnabled("TagAPI")) {
try {
Class.forName("org.kitteh.tag.TagAPI");
@ -212,7 +216,6 @@ public class War extends JavaPlugin {
warzoneDefaultConfig.put(WarzoneConfig.JOINMIDBATTLE, true);
warzoneDefaultConfig.put(WarzoneConfig.AUTOJOIN, false);
warzoneDefaultConfig.put(WarzoneConfig.SCOREBOARD, ScoreboardType.NONE);
warzoneDefaultConfig.put(WarzoneConfig.XPKILLMETER, false);
warzoneDefaultConfig.put(WarzoneConfig.SOUPHEALING, false);
warzoneDefaultConfig.put(WarzoneConfig.ALLOWENDER, true);
warzoneDefaultConfig.put(WarzoneConfig.RESETBLOCKS, true);
@ -1346,4 +1349,12 @@ public class War extends JavaPlugin {
public Economy getEconomy() {
return econ;
}
public UIManager getUIManager() {
return UIManager;
}
public void setUIManager(UIManager UIManager) {
this.UIManager = UIManager;
}
}

View File

@ -229,7 +229,7 @@ public class Warzone {
for (Team team : this.getTeams()) {
teamsMessage.append('\n');
teamsMessage.append(MessageFormat.format(War.war.getString("zone.teaminfo.format"),
team.getName(), team.getPoints(), team.getRemainingLifes(),
team.getName(), team.getPoints(), team.getRemainingLives(),
team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL), StringUtils.join(team.getPlayerNames().iterator(), ", ")));
}
}
@ -413,7 +413,7 @@ public class Warzone {
if (this.getScoreboardType() == ScoreboardType.POINTS) {
obj.getScore(teamName).setScore(team.getPoints());
} else if (this.getScoreboardType() == ScoreboardType.LIFEPOOL) {
obj.getScore(teamName).setScore(team.getRemainingLifes());
obj.getScore(teamName).setScore(team.getRemainingLives());
}
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
@ -1191,13 +1191,13 @@ public class Warzone {
} else {
this.respawnPlayer(playerTeam, player);
}
if (playerTeam.getRemainingLifes() <= 0) {
if (playerTeam.getRemainingLives() <= 0) {
handleTeamLoss(playerTeam, player);
} else {
this.dropAllStolenObjects(player, false);
playerTeam.setRemainingLives(playerTeam.getRemainingLifes() - 1);
playerTeam.setRemainingLives(playerTeam.getRemainingLives() - 1);
// Lifepool empty warning
if (playerTeam.getRemainingLifes() == 0) {
if (playerTeam.getRemainingLives() == 0) {
this.broadcast("zone.lifepool.empty", playerTeam.getName());
}
}
@ -1903,6 +1903,15 @@ public class Warzone {
return count;
}
public int getMaxPlayers() {
int zoneCap = 0;
for (Team t : this.getTeams()) {
zoneCap += t.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE);
}
return zoneCap;
}
/**
* Get the amount of players in all teams in this warzone. Same as
* {@link #getPlayerCount()}, except only checks teams that the specified

View File

@ -2,6 +2,7 @@ package com.tommytony.war.command;
import java.util.logging.Level;
import com.tommytony.war.config.TeamConfigBag;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -139,27 +140,7 @@ public class SetTeamConfigCommand extends AbstractOptionalZoneMakerCommand {
// We have a warzone, a team and indexed-from-0 arguments, let's update
String namedParamReturn = War.war.updateTeamFromNamedParams(team, player, this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarzoneYmlMapper.save(zone);
String zoneReset = "Some changes may require a /resetzone. ";
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
zone.reinitialize(); // bring back team spawns etc
zoneReset = "Zone reset. ";
}
if (wantsToPrint) {
this.msg("Team config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(team));
} else {
this.msg("Team config saved. " + zoneReset + namedParamReturn);
}
War.war.log(this.getSender().getName() + " updated team " + team.getName() + " configuration in warzone " + zone.getName() + "." + namedParamReturn, Level.INFO);
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
TeamConfigBag.afterUpdate(team, player, namedParamReturn, wantsToPrint);
} else if (namedParamReturn.equals("PARSE-ERROR")) {
this.badMsg("Failed to read named parameter(s).");
} else {

View File

@ -2,6 +2,7 @@ package com.tommytony.war.command;
import java.util.logging.Level;
import com.tommytony.war.config.WarConfigBag;
import org.bukkit.command.CommandSender;
@ -34,14 +35,7 @@ public class SetWarConfigCommand extends AbstractOptionalWarAdminCommand {
String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarYmlMapper.save();
if (wantsToPrint) {
String config = War.war.printConfig();
this.msg("War config saved. " + namedParamReturn + " " + config);
} else {
this.msg("War config saved. " + namedParamReturn);
}
War.war.log(this.getSender().getName() + " updated War configuration. " + namedParamReturn, Level.INFO);
WarConfigBag.afterUpdate(this.getSender(), namedParamReturn, wantsToPrint);
} else if (namedParamReturn.equals("PARSE-ERROR")) {
this.msg("Failed to read named parameters.");
} else {

View File

@ -2,6 +2,7 @@ package com.tommytony.war.command;
import java.util.logging.Level;
import com.tommytony.war.config.WarzoneConfigBag;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -100,27 +101,7 @@ public class SetZoneConfigCommand extends AbstractOptionalZoneMakerCommand {
// We have a warzone and indexed-from-0 arguments, let's update
String namedParamReturn = War.war.updateZoneFromNamedParams(zone, player, this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarzoneYmlMapper.save(zone);
String zoneReset = "Some changes may require a /resetzone. ";
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
zone.reinitialize(); // bring back team spawns etc
zoneReset = "Zone reset. ";
}
if (wantsToPrint) {
this.msg("Warzone config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(zone));
} else {
this.msg("Warzone config saved. " + zoneReset + namedParamReturn);
}
War.war.log(this.getSender().getName() + " updated warzone " + zone.getName() + " configuration." + namedParamReturn, Level.INFO);
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
WarzoneConfigBag.afterUpdate(zone, player, namedParamReturn, wantsToPrint);
} else if (namedParamReturn.equals("PARSE-ERROR")) {
this.badMsg("Failed to read named parameter(s).");
} else {

View File

@ -2,10 +2,12 @@ package com.tommytony.war.command;
import java.util.logging.Level;
import com.tommytony.war.ui.WarUI;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.tommytony.war.War;
import org.bukkit.entity.Player;
/**
@ -47,6 +49,9 @@ public class WarCommandHandler {
} else if (command.equals("war") || command.equals("War")) {
// show /war help
War.war.msg(sender, cmd.getUsage());
if (sender instanceof Player) {
War.war.getUIManager().assignUI((Player) sender, new WarUI());
}
return true;
} else {
arguments = args;

View File

@ -2,37 +2,49 @@ package com.tommytony.war.config;
public enum TeamConfig {
FLAGMUSTBEHOME (Boolean.class),
FLAGPOINTSONLY (Boolean.class),
FLAGRETURN (FlagReturn.class),
LIFEPOOL (Integer.class),
MAXSCORE (Integer.class),
NOHUNGER (Boolean.class),
PLAYERLOADOUTASDEFAULT (Boolean.class),
RESPAWNTIMER (Integer.class),
SATURATION (Integer.class),
SPAWNSTYLE (TeamSpawnStyle.class),
TEAMSIZE (Integer.class),
PERMISSION (String.class),
XPKILLMETER (Boolean.class),
KILLSTREAK (Boolean.class),
BLOCKWHITELIST (String.class),
PLACEBLOCK (Boolean.class),
APPLYPOTION(String.class),
ECOREWARD(Double.class),
INVENTORYDROP(Boolean.class),
BORDERDROP(Boolean.class);
FLAGMUSTBEHOME (Boolean.class, "Flag must be home", "If true, enemy flag cannot be captured if your flag is out"),
FLAGPOINTSONLY (Boolean.class, null, null), // obsolete
FLAGRETURN (FlagReturn.class, "Flag return destination", "Defines where the flag must be returned to capture"),
LIFEPOOL (Integer.class, "Lifepool", "Maximum team lives"),
MAXSCORE (Integer.class, "Max score", "When the team gets this many points, they win"),
NOHUNGER (Boolean.class, "No Hunger", "If true, player hunger will not decrease"),
PLAYERLOADOUTASDEFAULT (Boolean.class, "Player loadout as default", "If set, the default loadout will be the items the player brings into the zone"),
RESPAWNTIMER (Integer.class, "Respawn time", "Force players to wait in their spawn for this many seconds after each death"),
SATURATION (Integer.class, "Saturation", "Set player saturation to this level after each death"),
SPAWNSTYLE (TeamSpawnStyle.class, "Spawn style", "Choose from several different sizes for the spawn points"),
TEAMSIZE (Integer.class, "Team size", "Maximum players that may play on a team"),
PERMISSION (String.class, "Required permission", "Only allow players with a certain permission to join a team"),
XPKILLMETER (Boolean.class, "XP kill meter", "Use the XP bar to count kills"),
KILLSTREAK (Boolean.class, "Killstreak rewards", "Reward players for kills based on war.yml configuration"),
BLOCKWHITELIST (String.class, "Block whitelist", "Comma-separated list of blocks players may break or place. 'all' removes this limit"),
PLACEBLOCK (Boolean.class, "Place blocks", "If false, players cannot build. See unbreakable"),
APPLYPOTION(String.class, "Apply potion", "Give players a potion effect after each death. Format: EFFECT;DURATION;STRENGTH"),
ECOREWARD(Double.class, "Economy reward", "Give the winning team this much money. Requires Vault plugin"),
INVENTORYDROP(Boolean.class, "Drop inventory", "If false, players will not drop items on death"),
BORDERDROP(Boolean.class, "Drop near border", "If false, players cannot drop items near the border, to prevent duping");
private final Class<?> configType;
private final String title;
private final String description;
private TeamConfig(Class<?> configType) {
this.configType = configType;
TeamConfig(Class<?> configType, String title, String description) {
this.configType = configType;
this.title = title;
this.description = description;
}
public Class<?> getConfigType() {
return configType;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public static TeamConfig teamConfigFromString(String str) {
String lowered = str.toLowerCase();
for (TeamConfig config : TeamConfig.values()) {

View File

@ -2,7 +2,11 @@ package com.tommytony.war.config;
import java.util.EnumMap;
import java.util.Map;
import java.util.logging.Level;
import com.tommytony.war.Team;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
@ -247,4 +251,28 @@ public class TeamConfigBag {
}
return returnMessage;
}
public static void afterUpdate(Team team, CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
final Warzone zone = team.getZone();
WarzoneYmlMapper.save(zone);
String zoneReset = "Some changes may require a /resetzone. ";
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
zone.reinitialize(); // bring back team spawns etc
zoneReset = "Zone reset. ";
}
if (wantsToPrint) {
War.war.msg(sender, "Team config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(team));
} else {
War.war.msg(sender, "Team config saved. " + zoneReset + namedParamReturn);
}
War.war.log(sender.getName() + " updated team " + team.getName() + " configuration in warzone " + zone.getName() + "." + namedParamReturn, Level.INFO);
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
}
}

View File

@ -2,29 +2,41 @@ package com.tommytony.war.config;
public enum WarConfig {
BUILDINZONESONLY (Boolean.class),
DISABLEBUILDMESSAGE (Boolean.class),
DISABLEPVPMESSAGE (Boolean.class),
KEEPOLDZONEVERSIONS (Boolean.class),
MAXZONES (Integer.class),
PVPINZONESONLY (Boolean.class),
TNTINZONESONLY (Boolean.class),
RESETSPEED (Integer.class),
MAXSIZE (Integer.class),
LANGUAGE (String.class),
AUTOJOIN (String.class),
TPWARMUP(Integer.class);
BUILDINZONESONLY (Boolean.class, "Build in zones only", "Allow building in zones only"),
DISABLEBUILDMESSAGE (Boolean.class, "Disable build message", "Silently prevent building outside zones"),
DISABLEPVPMESSAGE (Boolean.class, "Disable PVP message", "Silently prevent PVP"),
KEEPOLDZONEVERSIONS (Boolean.class, "Keep old zone versions", "If true, archive the warzone on each save"),
MAXZONES (Integer.class, "Max zones", "Limit on number of zones that can be created"),
PVPINZONESONLY (Boolean.class, "PVP in zones only", "If true, limits PVP to warzones"),
TNTINZONESONLY (Boolean.class, "TNT in zones only", "If true, limits TNT to warzones"),
RESETSPEED (Integer.class, "Reset speed", "Number of blocks to reset per tick"),
MAXSIZE (Integer.class, "Max size", "Maximum volume of a warzone"),
LANGUAGE (String.class, "Language", "Preferred server language"),
AUTOJOIN (String.class, "Auto-join", "Name of warzone to send players to upon join"),
TPWARMUP(Integer.class, "TP warmup", "Amount of seconds a player must wait after requesting a teleport");
private final Class<?> configType;
private final String title;
private final String description;
private WarConfig(Class<?> configType) {
this.configType = configType;
WarConfig(Class<?> configType, String title, String description) {
this.configType = configType;
this.title = title;
this.description = description;
}
public Class<?> getConfigType() {
return configType;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public static WarConfig warConfigFromString(String str) {
String lowered = str.toLowerCase();
for (WarConfig config : WarConfig.values()) {

View File

@ -2,8 +2,11 @@ package com.tommytony.war.config;
import java.util.EnumMap;
import java.util.Map;
import java.util.logging.Level;
import com.tommytony.war.War;
import com.tommytony.war.mapper.WarYmlMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
public class WarConfigBag {
@ -92,4 +95,15 @@ public class WarConfigBag {
}
return returnMessage;
}
public static void afterUpdate(CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
WarYmlMapper.save();
if (wantsToPrint) {
String config = War.war.printConfig();
War.war.msg(sender, "War config saved. " + namedParamReturn + " " + config);
} else {
War.war.msg(sender, "War config saved. " + namedParamReturn);
}
War.war.log(sender.getName() + " updated War configuration. " + namedParamReturn, Level.INFO);
}
}

View File

@ -1,44 +1,55 @@
package com.tommytony.war.config;
public enum WarzoneConfig {
AUTOASSIGN (Boolean.class),
BLOCKHEADS (Boolean.class),
DEATHMESSAGES (Boolean.class),
DISABLED (Boolean.class),
FRIENDLYFIRE (Boolean.class),
GLASSWALLS (Boolean.class),
INSTABREAK (Boolean.class),
MINTEAMS (Integer.class),
MINPLAYERS (Integer.class),
MONUMENTHEAL (Integer.class),
NOCREATURES (Boolean.class),
NODROPS (Boolean.class),
PVPINZONE (Boolean.class),
REALDEATHS (Boolean.class),
RESETONEMPTY (Boolean.class),
RESETONCONFIGCHANGE (Boolean.class),
RESETONLOAD (Boolean.class),
RESETONUNLOAD (Boolean.class),
UNBREAKABLE (Boolean.class),
JOINMIDBATTLE (Boolean.class),
AUTOJOIN (Boolean.class),
SCOREBOARD (ScoreboardType.class),
XPKILLMETER (Boolean.class),
SOUPHEALING (Boolean.class),
ALLOWENDER (Boolean.class),
RESETBLOCKS (Boolean.class);
AUTOASSIGN (Boolean.class, "Auto-assign", "If true, distributes players across teams"),
BLOCKHEADS (Boolean.class, "Team helmets", "If true, players are given a team-colored hat"),
DEATHMESSAGES (Boolean.class, "Death notification", "If true, notify the zone when players are killed"),
DISABLED (Boolean.class, "Disabled", "If true, prevent players from joining the zone"),
FRIENDLYFIRE (Boolean.class, "Friendly fire", "If true, players are allowed to injure teammates"),
GLASSWALLS (Boolean.class, "Glass walls", "If true, use magic glass walls to keep players in/out of zones"),
INSTABREAK (Boolean.class, "Insta-break", "If true, players break blocks instantly (Spleef)"),
MINTEAMS (Integer.class, "Min teams", "Minimum number of active teams required to start the battle"),
MINPLAYERS (Integer.class, "Min players", "Minimum number of players required per team to start the battle"),
MONUMENTHEAL (Integer.class, "Monument heal", "Number of hearts given to players jumping on the monument"),
NOCREATURES (Boolean.class, "No creatures", "If true, prevent mob spawning"),
NODROPS (Boolean.class, "No drops", "If true, prevent players from dropping items"),
PVPINZONE (Boolean.class, "PVP", "Enable/disable PVP in the zone (Spleef)"),
REALDEATHS (Boolean.class, "Real deaths", "If true, send players to the real Minecraft death screen"),
RESETONEMPTY (Boolean.class, "Reset on empty", "If true, reset the zone when all players leave"),
RESETONCONFIGCHANGE (Boolean.class, "Reset on config change", "If true, reset every time the zone config is modified"),
RESETONLOAD (Boolean.class, "Reset on load", "If true, reset warzone when the server starts"),
RESETONUNLOAD (Boolean.class, "Reset on unload", "If true, reset warzone when the server stops"),
UNBREAKABLE (Boolean.class, "Unbreakable", "If true, prevent breaking blocks"),
JOINMIDBATTLE (Boolean.class, "Join mid battle", "If true, players are allowed to join during a battle"),
AUTOJOIN (Boolean.class, "Auto-join", "If true, bypass the zone lobby and auto-assign the player"),
SCOREBOARD (ScoreboardType.class, "Scoreboard type", "Type of scoreboard for this zone (none, points, lifepool, top kills)"),
SOUPHEALING (Boolean.class, "Soup healing", "If true, allow players to heal by consuming soup"),
ALLOWENDER (Boolean.class, "Allow ender chests", "Ender chests are usually blocked to prevent item duplication"),
RESETBLOCKS (Boolean.class, "Reset blocks", "If true, reset warzone blocks each battle");
private final Class<?> configType;
private final String title;
private final String description;
private WarzoneConfig(Class<?> configType) {
this.configType = configType;
WarzoneConfig(Class<?> configType, String title, String description) {
this.configType = configType;
this.title = title;
this.description = description;
}
public Class<?> getConfigType() {
return configType;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public static WarzoneConfig warzoneConfigFromString(String str) {
String lowered = str.toLowerCase();
for (WarzoneConfig config : WarzoneConfig.values()) {

View File

@ -2,11 +2,15 @@ package com.tommytony.war.config;
import java.util.EnumMap;
import java.util.Map;
import java.util.logging.Level;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import org.bukkit.entity.Player;
public class WarzoneConfigBag {
@ -129,4 +133,27 @@ public class WarzoneConfigBag {
}
return returnMessage;
}
public static void afterUpdate(Warzone zone, CommandSender sender, String namedParamReturn, boolean wantsToPrint) {
WarzoneYmlMapper.save(zone);
String zoneReset = "Some changes may require a /resetzone. ";
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
zone.reinitialize(); // bring back team spawns etc
zoneReset = "Zone reset. ";
}
if (wantsToPrint) {
War.war.msg(sender, "Warzone config saved. " + zoneReset + namedParamReturn + " " + War.war.printConfig(zone));
} else {
War.war.msg(sender, "Warzone config saved. " + zoneReset + namedParamReturn);
}
War.war.log(sender.getName() + " updated warzone " + zone.getName() + " configuration." + namedParamReturn, Level.INFO);
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
}
}

View File

@ -226,7 +226,7 @@ public class SpoutDisplayer {
// and finally, lives.
lineCounter = 1;
for (Team t : zone.getTeams()) {
line = new GenericLabel(t.getRemainingLifes() + "/" + t.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
line = new GenericLabel(t.getRemainingLives() + "/" + t.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
if (t.getPlayers().size() == 0) line.setTextColor(new Color(100, 100, 100));
line.setAnchor(WidgetAnchor.TOP_LEFT)
.setX(3 + teamMax + 4 + scoreMax + 4)

View File

@ -738,7 +738,7 @@ public class ZoneLobby {
team.getPoints(),
team.getTeamConfig().resolveInt(
TeamConfig.MAXSCORE),
team.getRemainingLifes(),
team.getRemainingLives(),
team.getTeamConfig().resolveInt(
TeamConfig.LIFEPOOL)).split("\n");
}

View File

@ -0,0 +1,36 @@
package com.tommytony.war.ui;
import com.tommytony.war.War;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Connor on 7/25/2017.
*/
public abstract class ChestUI {
private Map<ItemStack, Runnable> actions;
ChestUI() {
actions = new HashMap<ItemStack, Runnable>();
}
protected void addItem(Inventory inv, int slot, ItemStack item, Runnable action) {
inv.setItem(slot, item);
actions.put(item, action);
}
public abstract void build(Player player, Inventory inv);
public abstract String getTitle();
public abstract int getSize();
void processClick(ItemStack clicked) {
if (actions.containsKey(clicked)) {
War.war.getServer().getScheduler().runTask(War.war, actions.get(clicked));
}
}
}

View File

@ -0,0 +1,87 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.command.ZoneSetter;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.MessageFormat;
/**
* Created by Connor on 7/27/2017.
*/
public class EditOrCreateZoneUI extends ChestUI {
@Override
public void build(final Player player, Inventory inv) {
int i = 0;
ItemStack item = new ItemStack(Material.WOOD_AXE, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.YELLOW + "Create Warzone");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to create a " + ChatColor.AQUA + "Warzone"));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
if (!War.war.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
player.sendTitle("", ChatColor.RED + "This feature requires WorldEdit.", 10, 20, 10);
return;
}
War.war.getUIManager().getPlayerMessage(player, "Select zone region using WorldEdit and then type a name:", new StringRunnable() {
@Override
public void run() {
WorldEditPlugin worldEdit = (WorldEditPlugin) War.war.getServer().getPluginManager().getPlugin("WorldEdit");
Selection selection = worldEdit.getSelection(player);
if (selection != null && selection instanceof CuboidSelection) {
Location min = selection.getMinimumPoint();
Location max = selection.getMaximumPoint();
ZoneSetter setter = new ZoneSetter(player, this.getValue());
setter.placeCorner1(min.getBlock());
setter.placeCorner2(max.getBlock());
}
}
});
}
});
for (final Warzone zone : War.war.getEnabledWarzones()) {
if (!War.war.isWarAdmin(player) && !zone.isAuthor(player)) {
continue;
}
item = new ItemStack(Material.BOOK_AND_QUILL);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + zone.getName());
meta.setLore(ImmutableList.of(ChatColor.DARK_GRAY + "Click to edit"));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new EditZoneUI(zone));
}
});
}
}
@Override
public String getTitle() {
return ChatColor.RED + "Edit or Create Zones";
}
@Override
public int getSize() {
int zones = War.war.getEnabledWarzones().size() + 1;
if (zones % 9 == 0) {
return zones / 9;
} else {
return zones / 9 + 9;
}
}
}

View File

@ -0,0 +1,118 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamConfigBag;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.volume.Volume;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
/**
* Created by Connor on 7/27/2017.
*/
public class EditTeamUI extends ChestUI {
private final Team team;
public EditTeamUI(Team team) {
super();
this.team = team;
}
@Override
public void build(final Player player, Inventory inv) {
ItemStack item;
ItemMeta meta;
int i = 0;
item = new ItemStack(Material.GOLD_SPADE, 1);
meta = item.getItemMeta();
meta.setDisplayName("Add additional spawn");
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
if (team.getZone().getVolume().contains(player.getLocation())) {
team.addTeamSpawn(player.getLocation());
player.sendTitle("", "Additional spawn added", 10, 20, 10);
} else {
player.sendTitle("", ChatColor.RED + "Can't add a spawn outside of the zone!", 10, 20, 10);
}
}
});
item = new ItemStack(Material.TNT, 1);
meta = item.getItemMeta();
meta.setDisplayName("Delete");
item.setItemMeta(meta);
this.addItem(inv, 9*3-1, item, new Runnable() {
@Override
public void run() {
if (team.getFlagVolume() != null) {
team.getFlagVolume().resetBlocks();
}
for (Volume spawnVolume : team.getSpawnVolumes().values()) {
spawnVolume.resetBlocks();
}
final Warzone zone = team.getZone();
zone.getTeams().remove(team);
if (zone.getLobby() != null) {
zone.getLobby().setLocation(zone.getTeleport());
zone.getLobby().initialize();
}
WarzoneYmlMapper.save(zone);
War.war.msg(player, "Team " + team.getName() + " removed.");
}
});
for (final TeamConfig option : TeamConfig.values()) {
if (option.getTitle() == null) {
continue;
}
if (option.getConfigType() == Boolean.class) {
item = new Wool(team.getTeamConfig().resolveBoolean(option) ? DyeColor.LIME : DyeColor.RED).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
team.getTeamConfig().put(option, !team.getTeamConfig().resolveBoolean(option));
TeamConfigBag.afterUpdate(team, player, option.name() + " set to " + team.getTeamConfig().resolveBoolean(option), false);
War.war.getUIManager().assignUI(player, new EditTeamUI(team));
}
});
} else {
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.sendTitle(option.getTitle(), team.getTeamConfig().resolveValue(option).toString(), 10, 70, 20);
War.war.getUIManager().assignUI(player, new EditTeamUI(team));
}
});
}
}
}
@Override
public String getTitle() {
return ChatColor.RED + "Warzone \"" + team.getZone().getName() + "\": Team \"" + team.getName() + "\"";
}
@Override
public int getSize() {
return 9*3;
}
}

View File

@ -0,0 +1,85 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.WarzoneConfig;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.MessageFormat;
import java.util.Collections;
/**
* Created by Connor on 7/25/2017.
*/
public class EditTeamsListUI extends ChestUI {
private final Warzone warzone;
public EditTeamsListUI(Warzone warzone) {
super();
this.warzone = warzone;
}
@Override
public void build(final Player player, Inventory inv) {
int i = 0;
for (final TeamKind kind : TeamKind.values()) {
ItemStack item = kind.getBlockHead();
final Team team = warzone.getTeamByKind(kind);
ItemMeta meta = item.getItemMeta();
if (team == null) {
meta.setDisplayName("Create new team");
item.setItemMeta(meta);
this.addItem(inv, i, item, new Runnable() {
@Override
public void run() {
if (!warzone.getVolume().contains(player.getLocation())) {
player.sendTitle("", ChatColor.RED + "Can't add a spawn outside of the zone!", 10, 20, 10);
return;
}
Team newTeam = new Team(kind.toString(), kind, Collections.<Location>emptyList(), warzone);
newTeam.setRemainingLives(newTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
warzone.getTeams().add(newTeam);
if (warzone.getLobby() != null) {
warzone.getLobby().setLocation(warzone.getTeleport());
warzone.getLobby().initialize();
}
newTeam.addTeamSpawn(player.getLocation());
player.sendTitle("", "Team " + newTeam.getName() + " created with spawn here.", 10, 20, 10);
}
});
} else {
meta.setDisplayName("Edit team " + kind.getColor() + kind.name().toLowerCase());
item.setItemMeta(meta);
this.addItem(inv, i, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new EditTeamUI(team));
}
});
}
i++;
if (i == 9)
i++;
}
}
@Override
public String getTitle() {
return ChatColor.RED + "Warzone \"" + warzone.getName() + "\": Teams";
}
@Override
public int getSize() {
return 18;
}
}

View File

@ -0,0 +1,123 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamConfigBag;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.config.WarzoneConfigBag;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
/**
* Created by Connor on 7/27/2017.
*/
public class EditZoneConfigUI extends ChestUI {
private final Warzone zone;
public EditZoneConfigUI(Warzone zone) {
super();
this.zone = zone;
}
@Override
public void build(final Player player, Inventory inv) {
ItemStack item;
ItemMeta meta;
int i = 0;
for (final WarzoneConfig option : WarzoneConfig.values()) {
if (option.getTitle() == null) {
continue;
}
if (option.getConfigType() == Boolean.class) {
item = new Wool(zone.getWarzoneConfig().getBoolean(option) ? DyeColor.LIME : DyeColor.RED).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
zone.getWarzoneConfig().put(option, !zone.getWarzoneConfig().getBoolean(option));
WarzoneConfigBag.afterUpdate(zone, player, option.name() + " set to " + zone.getWarzoneConfig().getBoolean(option), false);
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(zone));
}
});
} else {
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.sendTitle(option.getTitle(), zone.getWarzoneConfig().getValue(option).toString(), 10, 70, 20);
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(zone));
}
});
}
}
item = new ItemStack(Material.STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(zone));
}
});
for (final TeamConfig option : TeamConfig.values()) {
if (option.getTitle() == null) {
continue;
}
if (option.getConfigType() == Boolean.class) {
item = new Wool(zone.getTeamDefaultConfig().resolveBoolean(option) ? DyeColor.LIME : DyeColor.RED).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
zone.getTeamDefaultConfig().put(option, !zone.getTeamDefaultConfig().resolveBoolean(option));
WarzoneConfigBag.afterUpdate(zone, player, option.name() + " set to " + zone.getTeamDefaultConfig().resolveBoolean(option), false);
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(zone));
}
});
} else {
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.sendTitle(option.getTitle(), zone.getTeamDefaultConfig().resolveValue(option).toString(), 10, 70, 20);
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(zone));
}
});
}
}
}
@Override
public String getTitle() {
return ChatColor.RED + "Warzone \"" + zone.getName() + "\": Config";
}
@Override
public int getSize() {
return 9*6;
}
}

View File

@ -0,0 +1,66 @@
package com.tommytony.war.ui;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Created by Connor on 7/27/2017.
*/
public class EditZoneUI extends ChestUI {
private final Warzone zone;
public EditZoneUI(Warzone zone) {
super();
this.zone = zone;
}
@Override
public void build(final Player player, Inventory inv) {
ItemStack item;
ItemMeta meta;
item = new ItemStack(Material.CHEST);
meta = item.getItemMeta();
meta.setDisplayName("Options");
item.setItemMeta(meta);
this.addItem(inv, 0, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(zone));
}
});
item = new ItemStack(Material.CHEST);
meta = item.getItemMeta();
meta.setDisplayName("Teams");
item.setItemMeta(meta);
this.addItem(inv, 1, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new EditTeamsListUI(zone));
}
});
item = new ItemStack(Material.CHEST);
meta = item.getItemMeta();
meta.setDisplayName("Loadouts");
item.setItemMeta(meta);
item = new ItemStack(Material.CHEST);
meta = item.getItemMeta();
meta.setDisplayName("Structures");
item.setItemMeta(meta);
}
@Override
public String getTitle() {
return ChatColor.RED + "Warzone \"" + zone.getName() + "\"";
}
@Override
public int getSize() {
return 9;
}
}

View File

@ -0,0 +1,91 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.WarzoneConfig;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.MessageFormat;
/**
* Created by Connor on 7/25/2017.
*/
public class JoinTeamUI extends ChestUI {
private final Warzone warzone;
public JoinTeamUI(Warzone warzone) {
super();
this.warzone = warzone;
}
@Override
public void build(final Player player, Inventory inv) {
UIFormatter formatter = new UIFormatter(warzone.getTeams().size());
for (final TeamKind kind : TeamKind.values()) {
ItemStack item = kind.getBlockHead();
Team team = warzone.getTeamByKind(kind);
ItemMeta meta = item.getItemMeta();
if (team != null) {
meta.setDisplayName(ChatColor.BOLD + "" + kind.getColor() + "Team " + kind.name().toLowerCase());
meta.setLore(ImmutableList.of(MessageFormat.format(ChatColor.GRAY + "{0}/{1} players", team.getPlayers().size(), team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)),
MessageFormat.format(ChatColor.GRAY + "{0}/{1} pts", team.getPoints(), team.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)),
MessageFormat.format(ChatColor.GRAY + "{0} lives left", team.getRemainingLives()),
ChatColor.DARK_GRAY + "Click to join team"));
item.setItemMeta(meta);
this.addItem(inv, formatter.next(), item, new Runnable() {
@Override
public void run() {
if (warzone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
War.war.badMsg(player, "join.disabled");
} else if (warzone.isReinitializing()) {
War.war.badMsg(player, "join.disabled");
} else if (warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
War.war.badMsg(player, "join.aarequired");
} else if (!warzone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && warzone.isEnoughPlayers()) {
War.war.badMsg(player, "join.progress");
} else {
Team team = warzone.getTeamByKind(kind);
if (team == null) {
War.war.badMsg(player, "join.team404");
} else if (!War.war.canPlayWar(player, team)) {
War.war.badMsg(player, "join.permission.single");
} else if (team.isFull()) {
War.war.badMsg(player, "join.full.single", team.getName());
} else {
Team previousTeam = Team.getTeamByPlayerName(player.getName());
if (previousTeam != null) {
if (previousTeam == team) {
War.war.badMsg(player, "join.selfteam");
return;
}
previousTeam.removePlayer(player);
previousTeam.resetSign();
}
warzone.assign(player, team);
}
}
}
});
}
}
}
@Override
public String getTitle() {
return ChatColor.RED + "Warzone \"" + warzone.getName() + "\": Teams";
}
@Override
public int getSize() {
return 18;
}
}

View File

@ -0,0 +1,66 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.MessageFormat;
/**
* Created by Connor on 7/25/2017.
*/
public class JoinZoneUI extends ChestUI {
@Override
public void build(final Player player, Inventory inv) {
ItemStack item = new ItemStack(Material.TNT, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.RED + "Warhub");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Teleports you to the " + ChatColor.RED + "Warhub" + ChatColor.GRAY + " lobby",
ChatColor.DARK_GRAY + "Warzone doors located here"));
item.setItemMeta(meta);
int i = 0;
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.teleport(War.war.getWarHub().getLocation());
}
});
for (final Warzone zone : War.war.getEnabledWarzones()) {
item = new ItemStack(Material.ENDER_PEARL);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + zone.getName());
meta.setLore(ImmutableList.of(MessageFormat.format(ChatColor.GRAY + "{0}/{1} players", zone.getPlayerCount(), zone.getMaxPlayers()),
MessageFormat.format(ChatColor.GRAY + "{0} teams", zone.getTeams().size()),
ChatColor.DARK_GRAY + "Click to teleport"));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new JoinTeamUI(zone));
}
});
}
}
@Override
public String getTitle() {
return ChatColor.RED + "Pick a Warzone";
}
@Override
public int getSize() {
int zones = War.war.getEnabledWarzones().size() + 1;
if (zones % 9 == 0) {
return zones / 9;
} else {
return zones / 9 + 9;
}
}
}

View File

@ -0,0 +1,16 @@
package com.tommytony.war.ui;
/**
* Created by Connor on 7/27/2017.
*/
public abstract class StringRunnable implements Runnable {
private String value;
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,70 @@
package com.tommytony.war.ui;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by Connor on 7/27/2017.
*/
public class UIFormatter {
private int i;
private List<Integer> pattern;
UIFormatter(int slots) {
this.i = 0;
this.pattern = new ArrayList<Integer>();
int row = 0;
while (slots > 9) {
List<Integer> pattern = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8);
for (int i = 0; i < pattern.size(); i++) {
pattern.set(i, pattern.get(i) + row * 9);
}
this.pattern.addAll(pattern);
row++;
}
List<Integer> pattern;
switch (slots) {
case 0:
pattern = Arrays.asList(0);
break;
case 1:
pattern = Arrays.asList(4);
break;
case 2:
pattern = Arrays.asList(2, 6);
break;
case 3:
pattern = Arrays.asList(1, 4, 7);
break;
case 4:
pattern = Arrays.asList(1, 3, 5, 7);
break;
case 5:
pattern = Arrays.asList(0, 2, 4, 6, 8);
break;
case 6:
pattern = Arrays.asList(1, 2, 3, 5, 6, 7);
break;
case 7:
pattern = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
break;
case 8:
pattern = Arrays.asList(0, 1, 2, 3, 5, 6, 7, 8);
break;
case 9:
pattern = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8);
break;
default:
throw new IllegalStateException();
}
for (int i = 0; i < pattern.size(); i++) {
pattern.set(i, pattern.get(i) + row * 9);
}
this.pattern.addAll(pattern);
}
int next() {
return this.pattern.get(i++);
}
}

View File

@ -0,0 +1,109 @@
package com.tommytony.war.ui;
import com.tommytony.war.War;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
/**
* Created by Connor on 7/25/2017.
*/
public class UIManager implements Listener {
private final War plugin;
private Map<Player, ChestUI> uiMap;
private Map<Player, StringRunnable> messageMap;
public UIManager(War plugin) {
this.plugin = plugin;
this.uiMap = new HashMap<Player, ChestUI>();
this.messageMap = new HashMap<Player, StringRunnable>();
}
public void assignUI(Player player, ChestUI ui) {
Inventory inv = Bukkit.getServer().createInventory(null, ui.getSize(), ui.getTitle());
ui.build(player, inv);
uiMap.put(player, ui);
player.closeInventory();
player.openInventory(inv);
}
public void getPlayerMessage(Player player, String prompt, StringRunnable action) {
messageMap.put(player, action);
player.sendMessage("CHAT DISABLED WHILE WAITING FOR RESPONSE");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage("|");
player.sendMessage(prompt);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ItemStack clicked = event.getCurrentItem();
Inventory inventory = event.getInventory();
if (uiMap.containsKey(player)) {
ChestUI ui = uiMap.get(player);
if (inventory.getName().equals(ui.getTitle())) {
event.setCancelled(true);
ui.processClick(clicked);
player.closeInventory();
}
uiMap.remove(player);
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = event.getItem();
if (item != null && item.getType() == Material.TNT
&& (item.getDurability() == 7 ||
(item.hasItemMeta() && item.getItemMeta().hasDisplayName()
&& item.getItemMeta().getDisplayName().contains("War")))) {
event.setCancelled(true);
this.assignUI(player, new WarUI());
}
}
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
if (messageMap.containsKey(event.getPlayer())) {
event.setCancelled(true);
StringRunnable exe = messageMap.remove(event.getPlayer());
exe.setValue(event.getMessage());
War.war.getServer().getScheduler().runTask(War.war, exe);
return;
}
for (Player p : messageMap.keySet()) {
if (event.getRecipients().contains(p)) {
event.getRecipients().remove(p);
}
}
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
this.uiMap.remove(event.getPlayer());
this.messageMap.remove(event.getPlayer());
}
}

View File

@ -0,0 +1,158 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.War;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.config.WarConfigBag;
import com.tommytony.war.config.WarzoneConfig;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
/**
* Created by Connor on 7/27/2017.
*/
public class WarAdminUI extends ChestUI {
@Override
public void build(final Player player, Inventory inv) {
ItemStack item;
ItemMeta meta;
int i = 0;
for (final WarConfig option : WarConfig.values()) {
if (option.getTitle() == null) {
continue;
}
if (option.getConfigType() == Boolean.class) {
item = new Wool(War.war.getWarConfig().getBoolean(option) ? DyeColor.LIME : DyeColor.RED).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getWarConfig().put(option, !War.war.getWarConfig().getBoolean(option));
WarConfigBag.afterUpdate(player, option.name() + " set to " + War.war.getWarConfig().getBoolean(option), false);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
} else {
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.sendTitle(option.getTitle(), War.war.getWarConfig().getValue(option).toString(), 10, 70, 20);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
}
}
item = new ItemStack(Material.STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Warzone Default Config >>>>");
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
for (final WarzoneConfig option : WarzoneConfig.values()) {
if (option.getTitle() == null) {
continue;
}
if (option.getConfigType() == Boolean.class) {
item = new Wool(War.war.getWarzoneDefaultConfig().getBoolean(option) ? DyeColor.LIME : DyeColor.RED).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getWarzoneDefaultConfig().put(option, !War.war.getWarzoneDefaultConfig().getBoolean(option));
WarConfigBag.afterUpdate(player, option.name() + " set to " + War.war.getWarzoneDefaultConfig().getBoolean(option), false);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
} else {
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.sendTitle(option.getTitle(), War.war.getWarzoneDefaultConfig().getValue(option).toString(), 10, 70, 20);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
}
}
item = new ItemStack(Material.STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
for (final TeamConfig option : TeamConfig.values()) {
if (option.getTitle() == null) {
continue;
}
if (option.getConfigType() == Boolean.class) {
item = new Wool(War.war.getTeamDefaultConfig().resolveBoolean(option) ? DyeColor.LIME : DyeColor.RED).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getTeamDefaultConfig().put(option, !War.war.getTeamDefaultConfig().resolveBoolean(option));
WarConfigBag.afterUpdate(player, option.name() + " set to " + War.war.getTeamDefaultConfig().resolveBoolean(option), false);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
} else {
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(option.getTitle());
meta.setLore(ImmutableList.of(option.getDescription()));
item.setItemMeta(meta);
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.sendTitle(option.getTitle(), War.war.getTeamDefaultConfig().resolveValue(option).toString(), 10, 70, 20);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
});
}
}
}
@Override
public String getTitle() {
return ChatColor.DARK_RED + "" + ChatColor.BOLD + "War Admin";
}
@Override
public int getSize() {
return 9*9;
}
}

View File

@ -0,0 +1,87 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.War;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Created by Connor on 7/26/2017.
*/
public class WarUI extends ChestUI {
@Override
public void build(final Player player, Inventory inv) {
Runnable joinZoneAction = new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new JoinZoneUI());
}
};
Runnable createZoneAction = new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new EditOrCreateZoneUI());
}
};
Runnable warAdminAction = new Runnable() {
@Override
public void run() {
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
};
if (War.war.isWarAdmin(player)) {
this.addItem(inv, 2, getWarAdminItem(), warAdminAction);
this.addItem(inv, 4, getCreateWarzoneItem(), createZoneAction);
this.addItem(inv, 6, getJoinWarzoneItem(), joinZoneAction);
} else if (War.war.isZoneMaker(player)) {
this.addItem(inv, 2, getCreateWarzoneItem(), createZoneAction);
this.addItem(inv, 6, getJoinWarzoneItem(), joinZoneAction);
} else {
this.addItem(inv, 4, getJoinWarzoneItem(), joinZoneAction);
}
}
private ItemStack getCreateWarzoneItem() {
ItemStack item = new ItemStack(Material.WOOD_AXE, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.YELLOW + "Create Warzone");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to create, or edit a " + ChatColor.AQUA + "Warzone"));
item.setItemMeta(meta);
return item;
}
private ItemStack getJoinWarzoneItem() {
ItemStack item = new ItemStack(Material.IRON_SWORD, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.RED + "Join Warzone");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to access " + ChatColor.AQUA + "Warzones",
ChatColor.DARK_GRAY + "Play in PVP areas, with multiple gamemodes here."));
item.setItemMeta(meta);
return item;
}
private ItemStack getWarAdminItem() {
ItemStack item = new ItemStack(Material.EYE_OF_ENDER, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.DARK_RED + "Manage War");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to display " + ChatColor.DARK_RED + "Admin" + ChatColor.GRAY + " access panel",
ChatColor.DARK_GRAY + "Play in PVP areas, with multiple gamemodes here."));
item.setItemMeta(meta);
return item;
}
@Override
public String getTitle() {
return ChatColor.RED + "War";
}
@Override
public int getSize() {
return 9;
}
}