Skip to content

Commit

Permalink
Fix config exception and release 0.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed Jul 23, 2019
1 parent ee7181c commit cbd3938
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![ClaimChunk Logo](imgs/icon64.png)![ClaimChunk Title](imgs/logo_carrier.png)

[![Version Info](https://img.shields.io/badge/Version-0.0.14-brightgreen.svg)](https://github.com/cjburkey01/ClaimChunk/releases)
[![Version Info](https://img.shields.io/badge/Version-0.0.15-brightgreen.svg)](https://github.com/cjburkey01/ClaimChunk/releases)
[![Download Info](https://img.shields.io/badge/Spigot-1.14.4-blue.svg)](https://www.spigotmc.org/resources/claimchunk.44458/)

**Join us on our [Discord server](https://discord.gg/zGYrqcq) (*zGYrqcq*) for bug reports, support, and general chatting!**
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'com.cjburkey'
version '0.0.14'
version '0.0.15'

project.ext.spigotVersion = '1.14.4-R0.1-SNAPSHOT'
project.ext.vaultApiVersion = '1.7'
Expand All @@ -12,6 +12,9 @@ project.ext.worldEditVersion = '7.0.1-SNAPSHOT'
project.ext.worldEditLegacyVersion = '7.0.0-SNAPSHOT'
project.ext.worldGuardVersion = '7.0.1-SNAPSHOT'

// Use `gradlew copyClaimChunkToPluginsDir` to build and copy the plugin into the /plugins/ directory
// Use `gradlew buildPluginAndRunServer` to execute `copyClaimChunkToPluginsDir` and run the server
// To use these tasks, download Spigot to this file.
project.ext.spigotFile = new File('./run/spigot-1.14.3.jar')

sourceCompatibility = 8
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/cjburkey/claimchunk/ChunkEventHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ private static boolean cannotEdit(World world, int x, int z, UUID player) {
if (Utils.hasPerm(Bukkit.getPlayer(player), false, "admin")) return false;
ChunkHandler ch = ClaimChunk.getInstance().getChunkHandler();
PlayerHandler ph = ClaimChunk.getInstance().getPlayerHandler();
if (!ch.isClaimed(world, x, z)) return Config.getBool("protection", "blockUnclaimedChunks", false);
if (!ch.isClaimed(world, x, z)) return Config.getBool("protection", "blockUnclaimedChunks");
if (ch.isOwner(world, x, z, player)) return false;
return !(ph.hasAccess(ch.getOwner(world, x, z), player)
|| (Config.getBool("protection", "disableOfflineProtect", false) && Bukkit.getPlayer(player) == null));
|| (Config.getBool("protection", "disableOfflineProtect") && Bukkit.getPlayer(player) == null));
}

private static void cancelEventIfNotOwned(Player ply, Chunk chunk, Cancellable e, String config) {
if (e != null
&& !e.isCancelled()
&& !Utils.hasPerm(ply, false, "admin")
&& Config.getBool("protection", config, true)
&& Config.getBool("protection", config)
&& cannotEdit(chunk.getWorld(), chunk.getX(), chunk.getZ(), ply.getUniqueId())) {
e.setCancelled(true);
Utils.toPlayer(ply, Config.errorColor(), Utils.getMsg("chunkNoEdit").replace("%%PLAYER%%",
Expand All @@ -49,8 +49,8 @@ public static void cancelExplosionIfConfig(EntityExplodeEvent e) {
if (e == null) return;
EntityType type = e.getEntityType();
if (!e.isCancelled()
&& (((type.equals(EntityType.PRIMED_TNT) || type.equals(EntityType.MINECART_TNT)) && Config.getBool("protection", "blockTnt", true))
|| (type.equals(EntityType.CREEPER) && Config.getBool("protection", "blockCreeper", true)))) {
&& (((type.equals(EntityType.PRIMED_TNT) || type.equals(EntityType.MINECART_TNT)) && Config.getBool("protection", "blockTnt"))
|| (type.equals(EntityType.CREEPER) && Config.getBool("protection", "blockCreeper")))) {
e.setYield(0);
e.setCancelled(true);
}
Expand All @@ -61,7 +61,7 @@ public static void cancelEntityEvent(Player ply, Entity ent, Chunk chunk, Cancel
if (e != null
&& !e.isCancelled()
&& !Utils.hasPerm(ply, false, "admin")
&& Config.getBool("protection", "protectAnimals", true)
&& Config.getBool("protection", "protectAnimals")
&& (cannotEdit(chunk.getWorld(), chunk.getX(), chunk.getZ(), ply.getUniqueId())
|| cannotEdit(entChunk.getWorld(), entChunk.getX(), entChunk.getZ(), ply.getUniqueId()))) {
e.setCancelled(true);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onEnable() {
Utils.debug("Spigot version: %s", getServer().getBukkitVersion());

// bStats: https://bstats.org/
if (Config.getBool("log", "anonymousMetrics", true)) {
if (Config.getBool("log", "anonymousMetrics")) {
try {
@SuppressWarnings("unused")
Metrics metrics = new Metrics(this);
Expand All @@ -73,7 +73,7 @@ public void onEnable() {

// Initialize the data handler if another plugin hasn't substituted one already
if (dataHandler == null) {
dataHandler = Config.getBool("database", "useDatabase", false)
dataHandler = Config.getBool("database", "useDatabase")
? new MySQLDataHandler<>(this::createJsonDataHandler, JsonDataHandler::deleteFiles)
: createJsonDataHandler();
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public void onEnable() {
*/

// Determine if the economy might exist
useEcon = (Config.getBool("economy", "useEconomy", true)
useEcon = (Config.getBool("economy", "useEconomy")
&& (getServer().getPluginManager().getPlugin("Vault") != null));

// Initialize the economy
Expand Down Expand Up @@ -148,7 +148,7 @@ public void onEnable() {
scheduleDataSaver();
Utils.debug("Scheduled data saving.");

int check = Config.getInt("chunks", "unclaimCheckIntervalTicks", 1200);
int check = Config.getInt("chunks", "unclaimCheckIntervalTicks");
getServer().getScheduler().scheduleSyncRepeatingTask(this, this::handleAutoUnclaim, check, check);
Utils.debug("Scheduled unclaimed chunk checker.");

Expand All @@ -163,7 +163,7 @@ private JsonDataHandler createJsonDataHandler() {
}

private void handleAutoUnclaim() {
int length = Config.getInt("chunks", "automaticUnclaimSeconds", -1);
int length = Config.getInt("chunks", "automaticUnclaimSeconds");
// Less than 1 will disable the check
if (length < 1) return;

Expand Down Expand Up @@ -207,7 +207,7 @@ public void onDisable() {

private void setupConfig() {
getConfig().options().copyDefaults(true);
saveDefaultConfig();
saveConfig();
}

private void setupEvents() {
Expand All @@ -227,7 +227,7 @@ private void setupCommands() {

private void scheduleDataSaver() {
// From minutes, calculate after how long in ticks to save data.
int saveTimeTicks = Config.getInt("data", "saveDataInterval", 5) * 60 * 20;
int saveTimeTicks = Config.getInt("data", "saveDataInterval") * 60 * 20;

// Async because possible lag when saving and loading.
getServer().getScheduler().runTaskTimerAsynchronously(this, this::reloadData, saveTimeTicks, saveTimeTicks);
Expand Down
34 changes: 13 additions & 21 deletions src/main/java/com/cjburkey/claimchunk/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,40 @@ private static FileConfiguration getConfig() {
return ClaimChunk.getInstance().getConfig();
}

public static boolean getBool(String section, String name, boolean def) {
boolean val = getConfig().getBoolean(full(section, name), def);
ClaimChunk.getInstance().saveConfig();
return val;
public static boolean getBool(String section, String name) {
return getConfig().getBoolean(full(section, name));
}

public static int getInt(String section, String name, int def) {
int val = getConfig().getInt(full(section, name), def);
ClaimChunk.getInstance().saveConfig();
return val;
public static int getInt(String section, String name) {
return getConfig().getInt(full(section, name));
}

public static double getDouble(String section, String name, double def) {
double val = getConfig().getDouble(full(section, name), def);
ClaimChunk.getInstance().saveConfig();
return val;
public static double getDouble(String section, String name) {
return getConfig().getDouble(full(section, name));
}

public static String getString(String section, String name, String def) {
String val = getConfig().getString(full(section, name), def);
ClaimChunk.getInstance().saveConfig();
return val;
public static String getString(String section, String name) {
return getConfig().getString(full(section, name));
}

public static List<String> getList(String section, String name) {
return getConfig().getStringList(full(section, name));
}

private static ChatColor getColor(String name, String def) {
return ChatColor.valueOf(getString("colors", name, def));
private static ChatColor getColor(String name) {
return ChatColor.valueOf(getString("colors", name));
}

public static ChatColor errorColor() {
return getColor("errorColor", "RED");
return getColor("errorColor");
}

public static ChatColor infoColor() {
return getColor("infoColor", "GOLD");
return getColor("infoColor");
}

public static ChatColor successColor() {
return getColor("successColor", "GREEN");
return getColor("successColor");
}

}
18 changes: 9 additions & 9 deletions src/main/java/com/cjburkey/claimchunk/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void log(String msg, Object... data) {
}

public static void debug(String msg, Object... data) {
if (Config.getBool("log", "debugSpam", false)) log.info(prepMsg(msg, data));
if (Config.getBool("log", "debugSpam")) log.info(prepMsg(msg, data));
}

public static void err(String msg, Object... data) {
Expand All @@ -30,7 +30,7 @@ private static String color(String in) {
}

public static String getMsg(String key) {
String out = Config.getString("messages", key, key);
String out = Config.getString("messages", key);
if (out == null) return "messages." + key;
return out;
}
Expand All @@ -44,14 +44,14 @@ public static void msg(CommandSender to, String msg) {
}

public static void toPlayer(Player ply, ChatColor color, String msg) {
if (Config.getBool("titles", "useTitlesInsteadOfChat", true)) {
if (Config.getBool("titles", "useTitlesInsteadOfChat")) {
try {
int in = Config.getInt("titles", "titleFadeInTime", 20);
int stay = Config.getInt("titles", "titleStayTime", 140);
int out = Config.getInt("titles", "titleFadeOutTime", 20);
int in = Config.getInt("titles", "titleFadeInTime");
int stay = Config.getInt("titles", "titleStayTime");
int out = Config.getInt("titles", "titleFadeOutTime");

TitleHandler.showTitle(ply, "", ChatColor.BLACK, in, stay, out);
if (Config.getBool("titles", "useActionBar", false)) {
if (Config.getBool("titles", "useActionBar")) {
TitleHandler.showActionbarTitle(ply, msg, color, in, stay, out);
TitleHandler.showSubTitle(ply, "", ChatColor.BLACK, in, stay, out);
} else {
Expand All @@ -71,7 +71,7 @@ public static boolean hasPerm(@Nullable CommandSender sender, boolean basic, Str
if (sender == null) return false;
boolean hasPerm = sender.hasPermission("claimchunk." + perm);
return (basic
? (Config.getBool("basic", "disablePermissions", false)
? (Config.getBool("basic", "disablePermissions")
|| hasPerm
|| sender.hasPermission("claimchunk.player"))
: hasPerm);
Expand All @@ -82,7 +82,7 @@ public static boolean hasPerm(CommandSender sender, boolean basic, Permission pe
if (sender == null) return false;
boolean hasPerm = sender.hasPermission(perm);
return (basic
? (Config.getBool("basic", "disablePermissions", false)
? (Config.getBool("basic", "disablePermissions")
|| hasPerm
|| sender.hasPermission("claimchunk.player"))
: hasPerm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ChunkPos[] getClaimedChunks(UUID ply) {

public boolean getHasAllFreeChunks(UUID ply) {
int total = 0;
int max = Config.getInt("economy", "firstFreeChunks", 0);
int max = Config.getInt("economy", "firstFreeChunks");
for (DataChunk chunk : dataHandler.getClaimedChunks()) {
if (chunk.player.equals(ply) && ++total >= max) return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/cjburkey/claimchunk/cmd/MainHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void claimChunk(Player p, Chunk loc) {
// Check if players can claim chunks here/in this world
boolean allowedToClaimWG = WorldGuardHandler.isAllowedClaim(loc);
boolean worldAllowsClaims = !Config.getList("chunks", "disabledWorlds").contains(loc.getWorld().getName());
boolean adminOverride = Config.getBool("worldguard", "allowAdminOverride", true);
boolean adminOverride = Config.getBool("worldguard", "allowAdminOverride");
boolean hasAdmin = Utils.hasPerm(p, false, "admin"); // UH OH THIS WAS BROKEN SINCE 0.0.8!!!
if (!(worldAllowsClaims || (hasAdmin && adminOverride)) || !(allowedToClaimWG || (hasAdmin && adminOverride))) {
Utils.toPlayer(p, Config.errorColor(), Utils.getMsg("claimLocationBlock"));
Expand All @@ -49,7 +49,7 @@ public static void claimChunk(Player p, Chunk loc) {
econFree = true;
} else {
e = ClaimChunk.getInstance().getEconomy();
double cost = Config.getDouble("economy", "claimPrice", 100);
double cost = Config.getDouble("economy", "claimPrice");
if (cost > 0 && !e.buy(p.getUniqueId(), cost)) {
Utils.toPlayer(p, Config.errorColor(), Utils.getMsg("claimNotEnoughMoney"));
return;
Expand All @@ -70,7 +70,7 @@ public static void claimChunk(Player p, Chunk loc) {

// Claim the chunk if nothing is wrong
ChunkPos pos = ch.claimChunk(loc.getWorld(), loc.getX(), loc.getZ(), p.getUniqueId());
if (pos != null && Config.getBool("chunks", "particlesWhenClaiming", true)) {
if (pos != null && Config.getBool("chunks", "particlesWhenClaiming")) {
pos.outlineChunk(p, 3);
}
Utils.toPlayer(p, Config.successColor(), Utils.getMsg(econFree ? "claimFree" : "claimSuccess")
Expand Down Expand Up @@ -114,9 +114,9 @@ public static boolean unclaimChunk(boolean adminOverride, boolean hideTitle, Pla
// Check if a refund is required
boolean refund = false;
if (!adminOverride && ClaimChunk.getInstance().useEconomy()
&& ch.getClaimed(p.getUniqueId()) > Config.getInt("economy", "firstFreeChunks", 0)) {
&& ch.getClaimed(p.getUniqueId()) > Config.getInt("economy", "firstFreeChunks")) {
Econ e = ClaimChunk.getInstance().getEconomy();
double reward = Config.getDouble("economy", "unclaimReward", 10);
double reward = Config.getDouble("economy", "unclaimReward");
if (reward > 0) {
e.addMoney(p.getUniqueId(), reward);
if (!hideTitle) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cjburkey/claimchunk/cmds/CmdList.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean onCall(String cmdUsed, Player executor, String[] args) {

ChunkPos[] chunks = chunkHandler.getClaimedChunks(ply);
int page = 0;
final int maxPerPage = Utils.clamp(Config.getInt("chunks", "maxPerListPage", 5), 2, 10);
final int maxPerPage = Utils.clamp(Config.getInt("chunks", "maxPerListPage"), 2, 10);
final int maxPage = Integer.max(0, (chunks.length - 1) / maxPerPage);
if (args.length == 1) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private void saveJsonFile(File file, Object data) throws Exception {
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
throw new IOException("Failed to create directory: " + file.getParentFile());
}
if (file.exists() && Config.getBool("data", "keepJsonBackups", true)) {
if (file.exists() && Config.getBool("data", "keepJsonBackups")) {
String filename = file.getName().substring(0, file.getName().lastIndexOf('.'));
File backupFolder = new File(file.getParentFile(), "/backups/" + filename);
if (!backupFolder.exists() && !backupFolder.mkdirs()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public MySQLDataHandler(Supplier<T> oldDataHandler, Consumer<T> onCleanOld) {
@Override
public void init() throws Exception {
// Initialize a connection to the specified MySQL database
String dbName = Config.getString("database", "database", "db_name");
connection = connect(Config.getString("database", "hostname", "127.0.0.1"),
Config.getInt("database", "port", 3306),
String dbName = Config.getString("database", "database");
connection = connect(Config.getString("database", "hostname"),
Config.getInt("database", "port"),
dbName,
Config.getString("database", "username", "root"),
Config.getString("database", "password", "root"));
Config.getString("database", "username"),
Config.getString("database", "password"));
if (connection == null) throw new IllegalStateException("Failed to initialize MySQL connection");

// Initialize the tables if they don't yet exist
Expand All @@ -88,7 +88,7 @@ public void init() throws Exception {
Utils.debug("Found access table");
}

if (oldDataHandler != null && Config.getBool("database", "convertOldData", true)) {
if (oldDataHandler != null && Config.getBool("database", "convertOldData")) {
this.oldDataHandler.init();
this.oldDataHandler.load();
IDataConverter.copyConvert(oldDataHandler, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onItemFramePlaced(EntityDamageByEntityEvent e) {
public void onEntityExplode(EntityExplodeEvent e) {
if (e != null
&& !(ClaimChunk.getInstance().getChunkHandler().isUnclaimed(e.getLocation().getChunk())
&& Config.getBool("protection", "blockUnclaimedChunks", false))) {
&& Config.getBool("protection", "blockUnclaimedChunks"))) {
ChunkEventHelper.cancelExplosionIfConfig(e);
}
}
Expand All @@ -107,7 +107,7 @@ public void onEntityDamage(EntityDamageByEntityEvent e) {
&& !ClaimChunk.getInstance().getChunkHandler().isUnclaimed(e.getEntity().getLocation().getChunk())
&& !ClaimChunk.getInstance().getChunkHandler().isUnclaimed(e.getDamager().getLocation().getChunk())
&& e.getDamager() instanceof Player
&& ((e.getEntity() instanceof Player && Config.getBool("protection", "blockPvp", false))
&& ((e.getEntity() instanceof Player && Config.getBool("protection", "blockPvp"))
|| e.getEntity() instanceof Animals)) {
ChunkEventHelper.cancelEntityEvent((Player) e.getDamager(), e.getEntity(), e.getDamager().getLocation().getChunk(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void showTitle(Player player, Chunk newChunk) {
}

private void showTitleRaw(boolean isOwnerDisplay, Player player, String msg) {
if (Config.getBool("chunks", "displayNameOfOwner", true) || !isOwnerDisplay) {
if (Config.getBool("chunks", "displayNameOfOwner") || !isOwnerDisplay) {
Utils.toPlayer(player, Config.infoColor(), msg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onJoin(Player ply) {
if (!dataHandler.hasPlayer(ply.getUniqueId())) {
dataHandler.addPlayer(ply.getUniqueId(),
ply.getName(),
Config.getBool("chunks", "defaultSendAlertsToOwner", false));
Config.getBool("chunks", "defaultSendAlertsToOwner"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int getMaxClaimsForPlayer(Player player) {
hadRank = true;
}
}
return hadRank ? maxClaims : Config.getInt("chunks", "maxChunksClaimed", 50);
return hadRank ? maxClaims : Config.getInt("chunks", "maxChunksClaimed");
}

}
Loading

0 comments on commit cbd3938

Please sign in to comment.