Allow changing all config options from UI

This commit is contained in:
Connor Monahan 2017-07-28 21:10:14 -05:00
parent f1caca70f5
commit f6b41bd015
6 changed files with 392 additions and 256 deletions

View File

@ -1,22 +1,20 @@
package com.tommytony.war.config;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
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 {
EnumMap<WarzoneConfig, Object> bag = new EnumMap<WarzoneConfig, Object>(WarzoneConfig.class);
private final Warzone warzone;
EnumMap<WarzoneConfig, Object> bag = new EnumMap<WarzoneConfig, Object>(WarzoneConfig.class);
public WarzoneConfigBag(Warzone warzone) {
this.warzone = warzone;
@ -27,6 +25,29 @@ public class WarzoneConfigBag {
this.warzone = null;
}
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();
}
}
public void put(WarzoneConfig config, Object value) {
bag.put(config, value);
}
@ -37,7 +58,7 @@ public class WarzoneConfigBag {
public Object getValue(WarzoneConfig config) {
if (bag.containsKey(config)) {
return bag.get(config);
return bag.get(config);
} else {
// use War default config
return War.war.getWarzoneDefaultConfig().getValue(config);
@ -46,16 +67,16 @@ public class WarzoneConfigBag {
public Integer getInt(WarzoneConfig config) {
if (bag.containsKey(config)) {
return (Integer)bag.get(config);
return (Integer) bag.get(config);
} else {
// use War default config
return War.war.getWarzoneDefaultConfig().getInt(config);
}
}
public Boolean getBoolean(WarzoneConfig config) {
if (bag.containsKey(config)) {
return (Boolean)bag.get(config);
return (Boolean) bag.get(config);
} else {
// use War default config
return War.war.getWarzoneDefaultConfig().getBoolean(config);
@ -71,6 +92,10 @@ public class WarzoneConfigBag {
}
}
public boolean contains(WarzoneConfig config) {
return this.bag.containsKey(config);
}
public void loadFrom(ConfigurationSection warzoneConfigSection) {
for (WarzoneConfig config : WarzoneConfig.values()) {
if (warzoneConfigSection.contains(config.toString())) {
@ -97,12 +122,12 @@ public class WarzoneConfigBag {
}
}
}
public String updateFromNamedParams(Map<String, String> namedParams) {
String returnMessage = "";
for (String namedParam : namedParams.keySet()) {
WarzoneConfig warzoneConfig = WarzoneConfig.warzoneConfigFromString(namedParam);
// param update
if (warzoneConfig != null) {
if (warzoneConfig.getConfigType().equals(Integer.class)) {
@ -119,11 +144,11 @@ public class WarzoneConfigBag {
String type = namedParams.get(namedParam);
this.bag.put(warzoneConfig, ScoreboardType.getFromString(type));
}
returnMessage += " " + warzoneConfig.toString() + " set to " + namedParams.get(namedParam);
returnMessage += " " + warzoneConfig.toString() + " set to " + namedParams.get(namedParam);
} else if (namedParam.equals("delete")) {
String toDelete = namedParams.get(namedParam);
warzoneConfig = WarzoneConfig.warzoneConfigFromString(toDelete);
// param delete (to restore inheritance)
if (warzoneConfig != null) {
this.bag.remove(warzoneConfig);
@ -133,27 +158,4 @@ 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

@ -1,21 +1,17 @@
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.
@ -71,39 +67,8 @@ public class EditTeamUI extends ChestUI {
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));
}
});
}
}
final TeamConfigBag config = team.getTeamConfig();
UIConfigHelper.addTeamConfigOptions(this, player, inv, config, team, team.getZone(), i);
}
@Override

View File

@ -1,20 +1,13 @@
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.
@ -33,39 +26,7 @@ public class EditZoneConfigUI extends ChestUI {
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));
}
});
}
}
i = UIConfigHelper.addWarzoneConfigOptions(this, player, inv, zone.getWarzoneConfig(), zone, i);
item = new ItemStack(Material.STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
@ -76,39 +37,7 @@ public class EditZoneConfigUI extends ChestUI {
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));
}
});
}
}
UIConfigHelper.addTeamConfigOptions(this, player, inv, zone.getTeamDefaultConfig(), null, zone, i);
}
@Override

View File

@ -0,0 +1,338 @@
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.*;
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.Dye;
/**
* Created by Connor on 7/28/2017.
*/
public class UIConfigHelper {
static int addTeamConfigOptions(final ChestUI ui, final Player player, Inventory inv, final TeamConfigBag config, final Team team, final Warzone warzone, int i) {
ItemStack item;
ItemMeta meta;
for (final TeamConfig option : TeamConfig.values()) {
if (option.getTitle() == null) {
continue;
}
String inheritance = "";
if (!config.contains(option) && warzone != null) {
if (warzone.getTeamDefaultConfig().contains(option)) {
inheritance = ChatColor.DARK_GRAY + "Inherited from warzone config defaults";
} else {
inheritance = ChatColor.DARK_GRAY + "Inherited from War config defaults";
}
}
String name = ChatColor.RESET + "" + ChatColor.YELLOW + option.getTitle();
String status = ChatColor.GRAY + "Currently: ";
String[] desc = option.getDescription().split("\n");
for (int j = 0; j < desc.length; j++) {
desc[j] = ChatColor.RESET + "" + ChatColor.GRAY + desc[j];
}
if (option.getConfigType() == Boolean.class) {
status += config.resolveBoolean(option) ? ChatColor.GREEN + "true" : ChatColor.DARK_GRAY + "false";
item = new Dye(config.resolveBoolean(option) ? DyeColor.LIME : DyeColor.GRAY).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
config.put(option, !config.resolveBoolean(option));
onTeamConfigUpdate(player, option, config, team, warzone);
}
});
} else if (option.getConfigType() == Integer.class || option.getConfigType() == Double.class || option.getConfigType() == String.class) {
status += ChatColor.LIGHT_PURPLE + config.resolveValue(option).toString();
item = new Dye(DyeColor.PURPLE).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().getPlayerMessage(player, "Type a new value for option " + option.name().toLowerCase() + ": ", new StringRunnable() {
@Override
public void run() {
if (option.getConfigType() == Integer.class) {
config.put(option, Integer.parseInt(this.getValue()));
} else if (option.getConfigType() == Double.class) {
config.put(option, Double.parseDouble(this.getValue()));
} else {
config.put(option, this.getValue());
}
onTeamConfigUpdate(player, option, config, team, warzone);
}
});
}
});
} else if (option.getConfigType() == FlagReturn.class) {
status += ChatColor.YELLOW + config.resolveValue(option).toString();
item = new Dye(DyeColor.PINK).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
FlagReturn next = FlagReturn.BOTH;
FlagReturn[] values = FlagReturn.values();
for (int i1 = 0; i1 < values.length; i1++) {
FlagReturn flagReturn = values[i1];
if (flagReturn == config.resolveFlagReturn() && i1 != values.length - 1) {
next = values[i1 + 1];
break;
}
}
config.put(option, next);
onTeamConfigUpdate(player, option, config, team, warzone);
}
});
} else if (option.getConfigType() == TeamSpawnStyle.class) {
status += ChatColor.YELLOW + config.resolveValue(option).toString();
item = new Dye(DyeColor.PINK).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
TeamSpawnStyle next = TeamSpawnStyle.INVISIBLE;
TeamSpawnStyle[] values = TeamSpawnStyle.values();
for (int i1 = 0; i1 < values.length; i1++) {
TeamSpawnStyle tss = values[i1];
if (tss == config.resolveSpawnStyle() && i1 != values.length - 1) {
next = values[i1 + 1];
break;
}
}
config.put(option, next);
onTeamConfigUpdate(player, option, config, team, warzone);
}
});
} else {
status += ChatColor.RED + config.resolveValue(option).toString();
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
}
});
}
}
return i;
}
private static void onTeamConfigUpdate(Player player, TeamConfig option, TeamConfigBag config, Team team, Warzone warzone) {
if (team != null) {
TeamConfigBag.afterUpdate(team, player, option.name() + " set to " + config.resolveValue(option).toString(), false);
War.war.getUIManager().assignUI(player, new EditTeamUI(team));
} else if (warzone != null) {
WarzoneConfigBag.afterUpdate(warzone, player, option.name() + " set to " + config.resolveValue(option).toString(), false);
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(warzone));
} else {
WarConfigBag.afterUpdate(player, option.name() + " set to " + config.resolveValue(option).toString(), false);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
}
static int addWarzoneConfigOptions(final ChestUI ui, final Player player, Inventory inv, final WarzoneConfigBag config, final Warzone warzone, int i) {
ItemStack item;
ItemMeta meta;
for (final WarzoneConfig option : WarzoneConfig.values()) {
if (option.getTitle() == null) {
continue;
}
String inheritance = "";
if (!config.contains(option)) {
inheritance = ChatColor.DARK_GRAY + "Inherited from War config defaults";
}
String name = ChatColor.RESET + "" + ChatColor.YELLOW + option.getTitle();
String status = ChatColor.GRAY + "Currently: ";
String[] desc = option.getDescription().split("\n");
for (int j = 0; j < desc.length; j++) {
desc[j] = ChatColor.RESET + "" + ChatColor.GRAY + desc[j];
}
if (option.getConfigType() == Boolean.class) {
status += config.getBoolean(option) ? ChatColor.GREEN + "true" : ChatColor.DARK_GRAY + "false";
item = new Dye(config.getBoolean(option) ? DyeColor.LIME : DyeColor.GRAY).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
config.put(option, !config.getBoolean(option));
onWarzoneConfigUpdate(player, option, config, warzone);
}
});
} else if (option.getConfigType() == Integer.class || option.getConfigType() == Double.class || option.getConfigType() == String.class) {
status += ChatColor.LIGHT_PURPLE + config.getValue(option).toString();
item = new Dye(DyeColor.PURPLE).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().getPlayerMessage(player, "Type a new value for option " + option.name().toLowerCase() + ": ", new StringRunnable() {
@Override
public void run() {
if (option.getConfigType() == Integer.class) {
config.put(option, Integer.parseInt(this.getValue()));
} else if (option.getConfigType() == Double.class) {
config.put(option, Double.parseDouble(this.getValue()));
} else {
config.put(option, this.getValue());
}
onWarzoneConfigUpdate(player, option, config, warzone);
}
});
}
});
} else if (option.getConfigType() == ScoreboardType.class) {
status += ChatColor.YELLOW + config.getValue(option).toString();
item = new Dye(DyeColor.PINK).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
ScoreboardType next = ScoreboardType.NONE;
ScoreboardType[] values = ScoreboardType.values();
for (int i1 = 0; i1 < values.length; i1++) {
ScoreboardType st = values[i1];
if (st == config.getScoreboardType(option) && i1 != values.length - 1) {
next = values[i1 + 1];
break;
}
}
config.put(option, next);
onWarzoneConfigUpdate(player, option, config, warzone);
}
});
} else {
status += ChatColor.RED + config.getValue(option).toString();
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
}
});
}
}
return i;
}
private static void onWarzoneConfigUpdate(Player player, WarzoneConfig option, WarzoneConfigBag config, Warzone warzone) {
if (warzone != null) {
WarzoneConfigBag.afterUpdate(warzone, player, option.name() + " set to " + config.getValue(option).toString(), false);
War.war.getUIManager().assignUI(player, new EditZoneConfigUI(warzone));
} else {
WarConfigBag.afterUpdate(player, option.name() + " set to " + config.getValue(option).toString(), false);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
}
static int addWarConfigOptions(final ChestUI ui, final Player player, Inventory inv, final WarConfigBag config, int i) {
ItemStack item;
ItemMeta meta;
for (final WarConfig option : WarConfig.values()) {
if (option.getTitle() == null) {
continue;
}
String name = ChatColor.RESET + "" + ChatColor.YELLOW + option.getTitle();
String status = ChatColor.GRAY + "Currently: ";
String[] desc = option.getDescription().split("\n");
for (int j = 0; j < desc.length; j++) {
desc[j] = ChatColor.RESET + "" + ChatColor.GRAY + desc[j];
}
if (option.getConfigType() == Boolean.class) {
status += config.getBoolean(option) ? ChatColor.GREEN + "true" : ChatColor.DARK_GRAY + "false";
item = new Dye(config.getBoolean(option) ? DyeColor.LIME : DyeColor.GRAY).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
config.put(option, !config.getBoolean(option));
onWarConfigUpdate(player, option, config);
}
});
} else if (option.getConfigType() == Integer.class || option.getConfigType() == Double.class || option.getConfigType() == String.class) {
status += ChatColor.LIGHT_PURPLE + config.getValue(option).toString();
item = new Dye(DyeColor.PURPLE).toItemStack(1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
War.war.getUIManager().getPlayerMessage(player, "Type a new value for option " + option.name().toLowerCase() + ": ", new StringRunnable() {
@Override
public void run() {
if (option.getConfigType() == Integer.class) {
config.put(option, Integer.parseInt(this.getValue()));
} else if (option.getConfigType() == Double.class) {
config.put(option, Double.parseDouble(this.getValue()));
} else {
config.put(option, this.getValue());
}
onWarConfigUpdate(player, option, config);
}
});
}
});
} else {
status += ChatColor.RED + config.getValue(option).toString();
item = new ItemStack(Material.COMPASS, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).build());
item.setItemMeta(meta);
ui.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
}
});
}
}
return i;
}
private static void onWarConfigUpdate(Player player, WarConfig option, WarConfigBag config) {
WarConfigBag.afterUpdate(player, option.name() + " set to " + config.getValue(option).toString(), false);
War.war.getUIManager().assignUI(player, new WarAdminUI());
}
}

View File

@ -1,19 +1,12 @@
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.
@ -25,39 +18,7 @@ public class WarAdminUI extends ChestUI {
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());
}
});
}
}
i = UIConfigHelper.addWarConfigOptions(this, player, inv, War.war.getWarConfig(), i);
item = new ItemStack(Material.STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Warzone Default Config >>>>");
@ -68,39 +29,7 @@ public class WarAdminUI extends ChestUI {
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());
}
});
}
}
i = UIConfigHelper.addWarzoneConfigOptions(this, player, inv, War.war.getWarzoneDefaultConfig(), null, i);
item = new ItemStack(Material.STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
@ -111,39 +40,7 @@ public class WarAdminUI extends ChestUI {
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());
}
});
}
}
UIConfigHelper.addTeamConfigOptions(this, player, inv, War.war.getTeamDefaultConfig(), null, null, i);
}
@Override

View File

@ -91,6 +91,10 @@ zone.battle.resetprogress = Progression: {0}%, {1} secondes pass\u00e9...
zone.battle.resetcomplete = Carte r\u00e9initialis\u00e9e en {0} secondes. Une nouvelle bataille va commencer !
zone.bomb.broadcast = {0} a explos\u00e9 la base de l''\u00e9quipe {1}. L''\u00e9quipe {2} gagne 1 point.
zone.cake.broadcast = {0} a ramen\u00e9 le g\u00e2teau {1} \u00e0 sa base. L''\u00e9quipe {2} gagne un point et r\u00e9cup\u00e8re toutes ses vies.
zone.capturepoint.addpoint=L''\u00e9quipe {0} gagne 1 point pour prot\u00e9ger du cap {1}.
zone.capturepoint.lose=L''\u00e9quipe {0} a perdu le contr\u00f4le du cap {1}.
zone.capturepoint.contest=L''\u00e9quipe {1} conteste le cap {0} !
zone.capturepoint.capture=L''\u00e9quipe {0} s''est empar\u00e9e du cap {1}, gagnant 1 point.
zone.flagcapture.broadcast = {0} a ramen\u00e9 le drapeau de l''\u00e9quipe {1} \u00e0 sa base ! L''\u00e9quipe {2} gagne 1 point.
zone.flagreturn.deadlock = Vous ne pouvez pas rapporter un drapeau ennemi alors que votre propre drapeau a \u00e9t\u00e9 vol\u00e9 !
zone.flagreturn.flag = Vous devez captuer le drapeau enemie \u00e0 votre drapeau d'\u00e9quipe.
@ -108,6 +112,7 @@ zone.score.board404 = Le tableau des scores n'est pas activ\u00e9 dans cette zon
zone.score.empty = Vous ne pourrez pas marquer de point tant qu'aucun joueur n'aura rejoint une autre \u00e9quipe.
zone.spawn.minplayers = Vous ne pouvez pas quitter votre base s''il n''y a pas au moins {0} joueurs dans au moins {1} \u00e9quipes.
zone.spawn.timer = Vous devez attendre {0} secondes pour quitter votre base !
zone.spawn.timer.title=Attendez {0} secondes...
zone.steal.bomb.broadcast = {0} s''est empar\u00e9 de la bombe {1} !
zone.steal.bomb.notice = Vous avez la bombe {0}. Atteignez la base d''une \u00e9quipe ennemie pour gagner des points. Si vous vous faites toucher, vous exploserez !
zone.steal.bomb.prevent = Emp\u00eachez {0} d''atteindre votre base avec la bombe !