Skip to content

Commit

Permalink
Merge pull request #373 from KisaragiEffective/feature/better-config
Browse files Browse the repository at this point in the history
Config.javaの掃除
  • Loading branch information
kory33 authored Dec 1, 2019
2 parents d2db05e + bfccb3a commit d4bfba0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
75 changes: 39 additions & 36 deletions src/main/scala/com/github/unchama/seichiassist/Config.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
package com.github.unchama.seichiassist;

import com.github.unchama.seichiassist.util.TypeConverter;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.List;

public class Config {
public final class Config {
private static FileConfiguration config;
private SeichiAssist plugin;
private final SeichiAssist plugin = SeichiAssist.instance();

//コンストラクタ
Config(SeichiAssist _plugin) {
plugin = _plugin;
Config() {
saveDefaultConfig();
}

//コンフィグのロード
public void loadConfig() {
config = getConfig();
}

//コンフィグのリロード
public void reloadConfig() {
plugin.reloadConfig();
config = getConfig();
}

//コンフィグのセーブ
public void saveConfig() {
plugin.saveConfig();
}
Expand Down Expand Up @@ -90,7 +84,7 @@ public int getMultipleIDBlockBreaklevel() {
return TypeConverter.toInt(config.getString("multipleidblockbreaklevel"));
}

public double getDropExplevel(int i) {
public double getDropExplevel(final int i) {
return TypeConverter.toDouble(config.getString("dropexplevel" + i, ""));
}

Expand All @@ -102,7 +96,7 @@ public int getDokodemoEnderlevel() {
return TypeConverter.toInt(config.getString("dokodemoenderlevel"));
}

public int getMineStacklevel(int i) {
public int getMineStacklevel(final int i) {
return TypeConverter.toInt(config.getString("minestacklevel" + i, ""));
}

Expand Down Expand Up @@ -131,7 +125,7 @@ public String getURL() {
return url;
}

public String getLvMessage(int i) {
public String getLvMessage(final int i) {
return config.getString("lv" + i + "message", "");
}

Expand Down Expand Up @@ -159,15 +153,24 @@ public int rateGiganticToRingo() {

/**
* 木の棒メニュー内のグリッド式保護メニューによる保護が許可されたワールドか
*
* @deprecated 判定の対象はWorldなので意味論的におかしい
* @param player
* @return
* @return 許可されているならtrue、許可されていないならfalse
*/
public boolean isGridProtectEnable(Player player) {
List<String> worldlist = config.getStringList("GridProtectEnableWorld");
@Deprecated
public boolean isGridProtectionEnabled(final Player player) {
return isGridProtectionEnabled(player.getWorld());
}

return worldlist.stream()
.anyMatch(name -> player.getWorld().getName().equalsIgnoreCase(name));
/**
* 木の棒メニュー内のグリッド式保護メニューによる保護が許可されたワールドか
* @param world 対象のワールド
* @return 許可されているならtrue、許可されていないならfalse
*/
public boolean isGridProtectionEnabled(final World world) {
return config.getStringList("GridProtectEnableWorld")
.parallelStream()
.anyMatch(name -> world.getName().equalsIgnoreCase(name));
}

/**
Expand All @@ -176,7 +179,7 @@ public boolean isGridProtectEnable(Player player) {
* @param world
* @return
*/
public int getGridLimitPerWorld(String world) {
public int getGridLimitPerWorld(final String world) {
return TypeConverter.toInt(config.getString("GridLimitPerWorld." + world, config.getString("GridLimitDefault")));
}

Expand Down Expand Up @@ -216,24 +219,24 @@ public String getLimitedLoginEventEnd() {
return config.getString("LimitedLoginEvent.EventEnd");
}

public String getLimitedLoginEventItem(int i) {
String forreturn;
if (config.getString("LimitedLoginEvent.DAY" + i + "_Item", "").equals("")) {
forreturn = "0";
public String getLimitedLoginEventItem(final int i) {
final String ret;
if (config.getString("LimitedLoginEvent.DAY" + i + "_Item", "").isEmpty()) {
ret = "0";
} else {
forreturn = config.getString("LimitedLoginEvent.DAY" + i + "_Item", "");
ret = config.getString("LimitedLoginEvent.DAY" + i + "_Item", "");
}
return forreturn;
return ret;
}

public String getLimitedLoginEventAmount(int i) {
String forreturn;
if (config.getString("LimitedLoginEvent.DAY" + i + "_Amount", "").equals("")) {
forreturn = "0";
public String getLimitedLoginEventAmount(final int i) {
final String ret;
if (config.getString("LimitedLoginEvent.DAY" + i + "_Amount", "").isEmpty()) {
ret = "0";
} else {
forreturn = config.getString("LimitedLoginEvent.DAY" + i + "_Amount", "");
ret = config.getString("LimitedLoginEvent.DAY" + i + "_Amount", "");
}
return forreturn;
return ret;
}


Expand Down Expand Up @@ -278,10 +281,10 @@ public int getGiganticFeverMinutes() {
}

public String getGiganticFeverDisplayTime() {
int minute = getGiganticFeverMinutes();
final int minute = getGiganticFeverMinutes();

int hours = minute / 60;
int minutes = minute - 60 * hours;
final int hours = minute / 60;
final int minutes = minute - 60 * hours;

return hours + "時間" + minutes + "分";
}
Expand All @@ -296,7 +299,7 @@ public int getGiganticBerserkLimit() {
* @param typeName Url以下の項目名
* @return 該当URL.ただし, typeNameが誤っていた場合は""を返します.
*/
public String getUrl(String typeName) {
public String getUrl(final String typeName) {
return config.getString("Url." + typeName, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SeichiAssist extends JavaPlugin() {


//コンフィグ系の設定は全てConfig.javaに移動
SeichiAssist.seichiAssistConfig = new Config(this)
SeichiAssist.seichiAssistConfig = new Config()
SeichiAssist.seichiAssistConfig.loadConfig()

if (SeichiAssist.seichiAssistConfig.getDebugMode == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import scala.Int;
import scala.jdk.CollectionConverters;

import java.text.NumberFormat;
Expand Down Expand Up @@ -136,7 +135,7 @@ public static Inventory getGridWorldGuardMenu(Player player) {
gridInv.setItem(7, menuicon7);

//8マス目
if (!config.isGridProtectEnable(player)) {
if (!config.isGridProtectionEnabled(player)) {
List<String> lore8 = new ArrayList<>();
lore8.add(ChatColor.RED + "" + ChatColor.UNDERLINE + "このワールドでは保護を作成できません");
ItemStack menuicon8 = Util.getMenuIcon(Material.WOOL, 1, 14, ChatColor.RED + "保護作成",
Expand Down

0 comments on commit d4bfba0

Please sign in to comment.