Skip to content

Commit

Permalink
v2.5.7.4
Browse files Browse the repository at this point in the history
AbilityFactory.isRegistered 추가
능력 블랙리스트 최적화
능력별 기본템 기능 추가

Config - Cacher 추가
능력 부여 GUI 제목 변경
능력 목록 GUI 추가 (/aw abilities)

플레이어 탈락 후 유령 플레이어가 남아있는 문제의 원인으로 추정되는 코드 수정
DefaultKitHandler.giveDefaultKit(Player) -> DefaultKitHandler.giveDefaultKit(Participant)
Circle.infiniteIteratorOf 추가
ItemBuilder.unbreakable 추가
ItemLib.addItem, ItemLib.removeItem 추가
능력 설명 메시지 개선 (/aw help)
  • Loading branch information
Daybreak365 committed Apr 13, 2020
1 parent 246c2ca commit e4d3063
Show file tree
Hide file tree
Showing 19 changed files with 706 additions and 220 deletions.
43 changes: 28 additions & 15 deletions modules/Plugin/src/daybreak/abilitywar/MainCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package daybreak.abilitywar;

import daybreak.abilitywar.ability.AbilityBase;
import daybreak.abilitywar.ability.AbilityFactory;
import daybreak.abilitywar.config.ability.wizard.AbilitySettingWizard;
import daybreak.abilitywar.config.wizard.DeathWizard;
import daybreak.abilitywar.config.wizard.GameWizard;
Expand All @@ -11,6 +12,7 @@
import daybreak.abilitywar.game.AbstractGame.Participant;
import daybreak.abilitywar.game.GameManager;
import daybreak.abilitywar.game.decorator.TeamGame;
import daybreak.abilitywar.game.manager.gui.AbilityListGUI;
import daybreak.abilitywar.game.manager.gui.BlackListGUI;
import daybreak.abilitywar.game.manager.gui.GameModeGUI;
import daybreak.abilitywar.game.manager.gui.InstallGUI;
Expand Down Expand Up @@ -197,6 +199,12 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
} else {
Messager.sendErrorMessage(sender, ChatColor.translateAlternateColorCodes('&', "&c콘솔에서 사용할 수 없는 명령어입니다!"));
}
} else if (split[0].equalsIgnoreCase("abilities")) {
if (sender instanceof Player) {
new AbilityListGUI((Player) sender, AbilityWar.getPlugin()).openGUI(1);
} else {
Messager.sendErrorMessage(sender, ChatColor.translateAlternateColorCodes('&', "&c콘솔에서 사용할 수 없는 명령어입니다!"));
}
} else if (split[0].equalsIgnoreCase("skip")) {
if (sender.isOp()) {
if (GameManager.isGameOf(AbilitySelect.Handler.class) && ((AbilitySelect.Handler) GameManager.getGame()).getAbilitySelect() != null) {
Expand Down Expand Up @@ -342,7 +350,16 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

private void parseConfigCommand(Player p, String label, String[] args) {
if (args[0].equalsIgnoreCase("kit")) {
new KitWizard(p, plugin).Show();
if (args.length > 1) {
String name = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
if (AbilityFactory.isRegistered(name)) {
new KitWizard(p, plugin, AbilityFactory.getRegistration(AbilityFactory.getByName(name))).Show();
} else {
p.sendMessage(ChatColor.RED + name + KoreanUtil.getJosa(name, Josa.은는) + " 존재하지 않는 능력입니다.");
}
} else {
new KitWizard(p, plugin).Show();
}
} else if (args[0].equalsIgnoreCase("spawn")) {
new SpawnWizard(p, plugin).Show();
} else if (args[0].equalsIgnoreCase("inv")) {
Expand Down Expand Up @@ -442,7 +459,7 @@ private void parseUtilCommand(Player p, String label, String[] args) {
Player target = Bukkit.getPlayerExact(args[1]);
if (target != null) {
if (GameManager.getGame().isParticipating(target)) {
handler.giveDefaultKit(target);
handler.giveDefaultKit(GameManager.getGame().getParticipant(target));
SoundLib.ENTITY_EXPERIENCE_ORB_PICKUP.playSound(target);
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',
"&f" + p.getName() + "&a님이 &f" + target.getName() + "&a님에게 기본템을 다시 지급하였습니다."));
Expand Down Expand Up @@ -596,7 +613,7 @@ private void parseTeamUtilCommand(AbstractGame game, TeamGame teamGame, Player p
}

private void sendHelpCommand(CommandSender sender, String label, int page) {
int allPage = 3;
int allPage = 2;

switch (page) {
case 1:
Expand All @@ -608,7 +625,10 @@ private void sendHelpCommand(CommandSender sender, String label, int page) {
Formatter.formatCommand(label, "stop", "능력자 전쟁을 중지시킵니다.", true),
Formatter.formatCommand(label, "check", "자신의 능력을 확인합니다.", false),
Formatter.formatCommand(label, "yes", "자신의 능력을 확정합니다.", false),
Formatter.formatCommand(label, "no", "자신의 능력을 변경합니다.", false)});
Formatter.formatCommand(label, "no", "자신의 능력을 변경합니다.", false),
Formatter.formatCommand(label, "abilities", "능력자 전쟁 능력 목록을 확인합니다.", false),
Formatter.formatCommand(label, "team", "팀 게임의 명령어 목록을 확인합니다.", false),
Formatter.formatCommand(label, "specialthanks", "능력자 전쟁 플러그인에 기여한 사람들을 확인합니다.", false)});
break;
case 2:
sender.sendMessage(new String[]{Formatter.formatTitle(ChatColor.GOLD, ChatColor.YELLOW, "능력자 전쟁"),
Expand All @@ -619,17 +639,9 @@ private void sendHelpCommand(CommandSender sender, String label, int page) {
Formatter.formatCommand(label, "anew", "모든 유저의 능력을 새로 뽑습니다.", true),
Formatter.formatCommand(label, "config", "능력자 전쟁 콘피그 명령어를 확인합니다.", true),
Formatter.formatCommand(label, "util", "능력자 전쟁 유틸 명령어를 확인합니다.", true),
Formatter.formatCommand(label, "script", "능력자 전쟁 스크립트 편집을 시작합니다.", true)});
break;
case 3:
sender.sendMessage(new String[]{Formatter.formatTitle(ChatColor.GOLD, ChatColor.YELLOW, "능력자 전쟁"),
ChatColor.translateAlternateColorCodes('&',
"&b/" + label + " help <페이지> &7로 더 많은 명령어를 확인하세요! ( &b" + page + " 페이지 &7/ &b" + allPage
+ " 페이지 &7)"),
Formatter.formatCommand(label, "script", "능력자 전쟁 스크립트 편집을 시작합니다.", true),
Formatter.formatCommand(label, "gamemode", "능력자 전쟁 게임 모드를 설정합니다.", true),
Formatter.formatCommand(label, "team", "팀 게임의 명령어 목록을 확인합니다.", false),
Formatter.formatCommand(label, "install", "새로운 버전의 다운로드를 시도합니다.", true),
Formatter.formatCommand(label, "specialthanks", "능력자 전쟁 플러그인에 기여한 사람들을 확인합니다.", false)});
Formatter.formatCommand(label, "install", "새로운 버전의 다운로드를 시도합니다.", true)});
break;
default:
Messager.sendErrorMessage(sender, "존재하지 않는 페이지입니다.");
Expand All @@ -648,6 +660,7 @@ private void sendHelpConfigCommand(CommandSender sender, String label, int page)
"&b/" + label + " config <페이지> &7로 더 많은 명령어를 확인하세요! ( &b" + page + " 페이지 &7/ &b" + allPage
+ " 페이지 &7)"),
Formatter.formatCommand(label + " config", "kit", "능력자 전쟁 기본템을 설정합니다.", true),
Formatter.formatCommand(label + " config", "kit <능력 이름>", "능력별 기본템을 설정합니다.", true),
Formatter.formatCommand(label + " config", "spawn", "능력자 전쟁 스폰을 설정합니다.", true),
Formatter.formatCommand(label + " config", "inv", "초반 무적을 설정합니다.", true),
Formatter.formatCommand(label + " config", "game", "게임의 전반적인 부분들을 설정합니다.", true),
Expand Down Expand Up @@ -736,7 +749,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
|| label.equalsIgnoreCase("va") || label.equalsIgnoreCase("능력자")) {
switch (args.length) {
case 1:
List<String> subCommands = Messager.asList("start", "stop", "check", "yes", "no", "skip", "anew",
List<String> subCommands = Messager.asList("start", "stop", "check", "yes", "no", "abilities", "skip", "anew",
"config", "util", "script", "gamemode", "install", "team", "specialthanks");
if (args[0].isEmpty()) {
return subCommands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public static boolean isRegistered(Class<? extends AbilityBase> clazz) {
return registeredAbilities.containsKey(clazz);
}

public static boolean isRegistered(String name) {
return usedNames.containsKey(name);
}

static {
registerAbility(Assassin.class);
registerAbility(Feather.class);
Expand Down
9 changes: 9 additions & 0 deletions modules/Plugin/src/daybreak/abilitywar/config/Cacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package daybreak.abilitywar.config;

public interface Cacher {

Object toCache(Object object);

Object revertCache(Object object);

}
95 changes: 64 additions & 31 deletions modules/Plugin/src/daybreak/abilitywar/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import daybreak.abilitywar.config.enums.ConfigNodes;
import daybreak.abilitywar.config.enums.OnDeath;
import daybreak.abilitywar.config.serializable.AbilityKit;
import daybreak.abilitywar.game.AbstractGame;
import daybreak.abilitywar.game.list.standard.DefaultGame;
import daybreak.abilitywar.utils.base.io.FileUtil;
Expand All @@ -17,6 +18,7 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -53,22 +55,37 @@ public static void update() throws IOException, InvalidConfigurationException {
config.load();

for (Entry<ConfigNodes, Cache> entry : cache.entrySet()) {
ConfigNodes node = entry.getKey();
Cache cache = entry.getValue();
if (cache.isModifiedValue()) {
config.set(entry.getKey().getPath(), cache.getValue());
if (node.hasCacher()) {
config.set(node.getPath(), node.getCacher().revertCache(cache.getValue()));
} else {
config.set(node.getPath(), cache.getValue());
}
}
}

cache.clear();
for (ConfigNodes node : ConfigNodes.values()) {
Object value = config.get(node.getPath());
config.addComment(node.getPath(), node.getComments());
if (value != null) {
cache.put(node, new Cache(false, value));
if (node.hasCacher()) {
Cacher handler = node.getCacher();
if (config.isSet(node.getPath())) {
cache.put(node, new Cache(false, handler.toCache(config.get(node.getPath()))));
} else {
config.set(node.getPath(), node.getDefault());
cache.put(node, new Cache(false, handler.toCache(node.getDefault())));
}
} else {
config.set(node.getPath(), node.getDefault());
cache.put(node, new Cache(false, node.getDefault()));
Object value = config.get(node.getPath());
if (value != null) {
cache.put(node, new Cache(false, value));
} else {
config.set(node.getPath(), node.getDefault());
cache.put(node, new Cache(false, node.getDefault()));
}
}
config.addComment(node.getPath(), node.getComments());
}
config.save();
lastModified = file.lastModified();
Expand All @@ -77,7 +94,7 @@ public static void update() throws IOException, InvalidConfigurationException {
private static final EnumMap<ConfigNodes, Cache> cache = new EnumMap<>(ConfigNodes.class);

@SuppressWarnings("unchecked") // private only method
private static <T> T get(ConfigNodes configNode, Class<T> clazz) throws IllegalStateException {
private static <T> T get(ConfigNodes configNode) throws IllegalStateException {
if (!error) {
if (!isLoaded()) {
try {
Expand All @@ -88,7 +105,7 @@ private static <T> T get(ConfigNodes configNode, Class<T> clazz) throws IllegalS
} catch (IOException | InvalidConfigurationException e) {
error = true;
}
return get(configNode, clazz);
return get(configNode);
}
if (lastModified != file.lastModified()) {
try {
Expand All @@ -105,7 +122,7 @@ private static <T> T get(ConfigNodes configNode, Class<T> clazz) throws IllegalS

@SuppressWarnings("unchecked") // private only method
private static <T> List<T> getList(ConfigNodes configNode, Class<T> clazz) throws IllegalStateException {
List<?> list = (List<?>) get(configNode, List.class);
List<?> list = get(configNode);
List<T> newList = new ArrayList<>();
for (Object object : list) {
if (object != null && clazz.isAssignableFrom(object.getClass())) {
Expand All @@ -115,28 +132,36 @@ private static <T> List<T> getList(ConfigNodes configNode, Class<T> clazz) throw
return newList;
}

private static <T> Set<T> getSet(ConfigNodes configNode) throws IllegalStateException {
return get(configNode);
}

public static void modifyProperty(ConfigNodes node, Object value) {
cache.put(node, new Cache(true, value));
}

public static void updateProperty(ConfigNodes node) {
cache.put(node, new Cache(true, cache.get(node).getValue()));
}

public static class Settings {

private Settings() {
}

public static String getString(ConfigNodes node) {
return get(node, String.class);
return get(node);
}

public static int getInt(ConfigNodes node) {
return get(node, Integer.class);
return get(node);
}

public static boolean getBoolean(ConfigNodes node) {
return get(node, Boolean.class);
return get(node);
}
public static Location getLocation(ConfigNodes node) {
return get(node, Location.class);
return get(node);
}
public static List<String> getStringList(ConfigNodes node) {
return getList(node, String.class);
Expand All @@ -148,25 +173,35 @@ public static List<ItemStack> getItemStackList(ConfigNodes node) {
public static boolean getNoHunger() {
return getBoolean(ConfigNodes.GAME_NO_HUNGER);
}

public static int getStartLevel() {
return getInt(ConfigNodes.GAME_START_LEVEL);
}

public static boolean getInventoryClear() {
return getBoolean(ConfigNodes.GAME_INVENTORY_CLEAR);
}

public static List<ItemStack> getDefaultKit() {
return getItemStackList(ConfigNodes.GAME_KIT);
}

public static AbilityKit getAbilityKit() {
return get(ConfigNodes.GAME_ABILITY_KIT);
}

public static boolean getDrawAbility() {
return getBoolean(ConfigNodes.GAME_DRAW_ABILITY);
}

public static boolean getInfiniteDurability() {
return getBoolean(ConfigNodes.GAME_INFINITE_DURABILITY);
}

public static boolean getFirewall() {
return getBoolean(ConfigNodes.GAME_FIREWALL);
}

public static boolean getClearWeather() {
return getBoolean(ConfigNodes.GAME_CLEAR_WEATHER);
}
Expand All @@ -176,6 +211,7 @@ public static Location getSpawnLocation() {
public static boolean getSpawnEnable() {
return getBoolean(ConfigNodes.GAME_SPAWN_ENABLE);
}

public static boolean getVisualEffect() {
return getBoolean(ConfigNodes.GAME_VISUAL_EFFECT);
}
Expand All @@ -184,38 +220,35 @@ public static boolean isBlackListed(String abilityName) {
return getBlackList().contains(abilityName);
}

public static List<String> getBlackList() {
return getStringList(ConfigNodes.GAME_BLACKLIST);
public static Set<String> getBlackList() {
return getSet(ConfigNodes.GAME_BLACKLIST);
}

public static void addBlackListAll(Collection<String> abilityNames) {
List<String> list = getStringList(ConfigNodes.GAME_BLACKLIST);
if (!list.containsAll(abilityNames)) {
list.addAll(abilityNames);
modifyProperty(ConfigNodes.GAME_BLACKLIST, list);
Set<String> set = getBlackList();
if (set.addAll(abilityNames)) {
modifyProperty(ConfigNodes.GAME_BLACKLIST, set);
}
}

public static void addBlackList(String abilityName) {
List<String> list = getStringList(ConfigNodes.GAME_BLACKLIST);
if (!list.contains(abilityName)) {
list.add(abilityName);
modifyProperty(ConfigNodes.GAME_BLACKLIST, list);
Set<String> set = getBlackList();
if (set.add(abilityName)) {
modifyProperty(ConfigNodes.GAME_BLACKLIST, set);
}
}

public static void removeBlackListAll(Collection<String> abilityNames) {
List<String> list = getStringList(ConfigNodes.GAME_BLACKLIST);
if (list.removeAll(abilityNames)) {
modifyProperty(ConfigNodes.GAME_BLACKLIST, list);
Set<String> set = getBlackList();
if (set.removeAll(abilityNames)) {
modifyProperty(ConfigNodes.GAME_BLACKLIST, set);
}
}

public static void removeBlackList(String abilityName) {
List<String> list = getStringList(ConfigNodes.GAME_BLACKLIST);
if (list.contains(abilityName)) {
list.remove(abilityName);
modifyProperty(ConfigNodes.GAME_BLACKLIST, list);
Set<String> set = getBlackList();
if (set.remove(abilityName)) {
modifyProperty(ConfigNodes.GAME_BLACKLIST, set);
}
}

Expand Down
Loading

0 comments on commit e4d3063

Please sign in to comment.