Skip to content

Commit

Permalink
Refactor configuration fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
leelawd committed Jul 24, 2018
1 parent 4726f7b commit d5e0a5b
Show file tree
Hide file tree
Showing 20 changed files with 478 additions and 630 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.moddedminecraft.betterchunkloader.menu.MenuListener;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.objectmapping.GuiceObjectMapperFactory;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
import org.slf4j.Logger;
Expand Down Expand Up @@ -71,9 +70,6 @@ public class BetterChunkLoader {
@ConfigDir(sharedRoot = false)
public Path Configdir;

@Inject
public GuiceObjectMapperFactory factory;

public Map<UUID, PlayerData> playersData;
public Map<UUID, ChunkLoader> chunkLoaderData;

Expand Down Expand Up @@ -115,7 +111,7 @@ public void onServerAboutStart(GameAboutToStartServerEvent event) throws IOExcep

@Listener
public void onServerStart(GameStartedServerEvent event) {
Sponge.getScheduler().createTaskBuilder().delay(config.getCore().chunkLoader.loadDelay, TimeUnit.SECONDS).execute(() -> {
Sponge.getScheduler().createTaskBuilder().delay(config.getCore().loadDelay, TimeUnit.SECONDS).execute(() -> {
int count = 0;
count = getChunkLoaderData().stream().filter((chunkLoader) -> (chunkLoader.isLoadable())).map((chunkLoader) -> {
getChunkManager().loadChunkLoader(chunkLoader);
Expand Down Expand Up @@ -202,8 +198,8 @@ public int getAvailableChunks(UUID uuid, Boolean alwayson) {
} else {
final List<ChunkLoader> chunks = new ArrayList<ChunkLoader>(getChunkLoaderData());
final PlayerData playerData = dataManager.getPlayerDataFor(uuid).get();
int alwaysonavailable = getConfig().getCore().chunkLoader.alwaysOn.defaultAlwaysOn + playerData.getAlwaysOnChunks();
int onlineavailable = getConfig().getCore().chunkLoader.online.defaultOnline + playerData.getOnlineChunks();
int alwaysonavailable = getConfig().getCore().defaultAlwaysOn + playerData.getAlwaysOnChunks();
int onlineavailable = getConfig().getCore().defaultOnline + playerData.getOnlineChunks();

for (ChunkLoader chunk : chunks) {
if (chunk.getOwner().equals(playerData.getUnqiueId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void showHelp(CommandSource sender) {
}

plugin.getPaginationService().builder()
.title(Utilities.parseMessage(plugin.getConfig().getMessages().commands.usage.title))
.title(Utilities.parseMessage(plugin.getConfig().getMessages().usageTitle))
.contents(contents)
.padding(Utilities.parseMessage(plugin.getConfig().getMessages().commands.usage.padding))
.padding(Utilities.parseMessage(plugin.getConfig().getMessages().usagePadding))
.sendTo(sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
if (chunksInfo(sender, playerName.get(),true)) {
return CommandResult.success();
} else {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.noPlayerExists));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().noPlayerExists));
return CommandResult.empty();
}
} else {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.balance.noPermission));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().balanceNoPermission));
return CommandResult.empty();
}
} else {
Expand All @@ -46,15 +46,15 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
return CommandResult.success();
}
}
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.balance.failure));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().balanceFailure));
return CommandResult.empty();
}

private boolean chunksInfo(CommandSource sender, User player, boolean other) {
Optional<PlayerData> playerData = plugin.dataManager.getPlayerDataFor(player.getUniqueId());
if (playerData.isPresent()) {
int defaultOnline = plugin.getConfig().getCore().chunkLoader.online.defaultOnline;
int defaultAlwayson = plugin.getConfig().getCore().chunkLoader.alwaysOn.defaultAlwaysOn;
int defaultOnline = plugin.getConfig().getCore().defaultOnline;
int defaultAlwayson = plugin.getConfig().getCore().defaultAlwaysOn;
int onlineUsed = plugin.getUsedChunks(playerData.get().getUnqiueId(), false);
int alwaysonUsed = plugin.getUsedChunks(playerData.get().getUnqiueId(), true);

Expand All @@ -65,13 +65,13 @@ private boolean chunksInfo(CommandSource sender, User player, boolean other) {
args.put("alwayson", String.valueOf(playerData.get().getAlwaysOnChunks() + defaultAlwayson));
args.put("alwaysonused", String.valueOf(alwaysonUsed));

String title = plugin.getConfig().getMessages().commands.balance.success.titleSelf;
if (other) title = plugin.getConfig().getMessages().commands.balance.success.titleOther;
String title = plugin.getConfig().getMessages().balanceTitleSelf;
if (other) title = plugin.getConfig().getMessages().balanceTitleOther;

plugin.getPaginationService().builder()
.contents(Utilities.parseMessageList(plugin.getConfig().getMessages().commands.balance.success.items, args))
.contents(Utilities.parseMessageList(plugin.getConfig().getMessages().balanceItems, args))
.title(Utilities.parseMessage(title, args))
.padding(Utilities.parseMessage(plugin.getConfig().getMessages().commands.balance.success.padding))
.padding(Utilities.parseMessage(plugin.getConfig().getMessages().balancePadding))
.sendTo(sender);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext

Optional<UUID> playerUUID = Utilities.getPlayerUUID(playerName.getName());
if (!playerUUID.isPresent()) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.noPlayerExists));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().noPlayerExists));
return CommandResult.empty();
}
Optional<PlayerData> playerData = plugin.dataManager.getPlayerDataFor(playerUUID.get());
if (!playerData.isPresent()) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.noPlayerExists));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().noPlayerExists));
return CommandResult.empty();
}

Expand All @@ -47,8 +47,8 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
put("targetUUID", playerData.get().getUnqiueId().toString());
put("online", String.valueOf(playerData.get().getOnlineChunks()));
put("alwayson", String.valueOf(playerData.get().getAlwaysOnChunks()));
put("maxOnline", String.valueOf(plugin.getConfig().getCore().chunkLoader.online.maxOnline));
put("maxAlwaysOn", String.valueOf(plugin.getConfig().getCore().chunkLoader.alwaysOn.maxAlwaysOn));
put("maxOnline", String.valueOf(plugin.getConfig().getCore().maxOnline));
put("maxAlwaysOn", String.valueOf(plugin.getConfig().getCore().maxAlwaysOn));
put("chunks", String.valueOf(changeValue));
}};

Expand All @@ -57,9 +57,9 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
switch (loaderTypeElement) {
case "alwayson": {
args.put("type", "Always On");
args.put("limit", String.valueOf(plugin.getConfig().getCore().chunkLoader.alwaysOn.maxAlwaysOn));
if (playerData.get().getAlwaysOnChunks() + changeValue < 0 || playerData.get().getAlwaysOnChunks() + changeValue > plugin.getConfig().getCore().chunkLoader.alwaysOn.maxAlwaysOn) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.add.failure, args));
args.put("limit", String.valueOf(plugin.getConfig().getCore().maxAlwaysOn));
if (playerData.get().getAlwaysOnChunks() + changeValue < 0 || playerData.get().getAlwaysOnChunks() + changeValue > plugin.getConfig().getCore().maxAlwaysOn) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksAddFailure, args));
return CommandResult.empty();
}

Expand All @@ -71,14 +71,14 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
e.printStackTrace();
}

sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.add.success, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksAddSuccess, args));
return CommandResult.success();
}
case "online": {
args.put("type", "Online Only");
args.put("limit", String.valueOf(plugin.getConfig().getCore().chunkLoader.online.maxOnline));
if (playerData.get().getOnlineChunks() + changeValue < 0 || playerData.get().getOnlineChunks() + changeValue > plugin.getConfig().getCore().chunkLoader.online.maxOnline) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.add.failure, args));
args.put("limit", String.valueOf(plugin.getConfig().getCore().maxOnline));
if (playerData.get().getOnlineChunks() + changeValue < 0 || playerData.get().getOnlineChunks() + changeValue > plugin.getConfig().getCore().maxOnline) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksAddFailure, args));
return CommandResult.empty();
}
playerData.get().addOnlineChunks(changeValue);
Expand All @@ -89,11 +89,11 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
e.printStackTrace();
}

sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.add.success, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksAddSuccess, args));
return CommandResult.success();
}
default: {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.usage, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksUsage, args));
return CommandResult.empty();
}
}
Expand All @@ -102,9 +102,9 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
switch (loaderTypeElement) {
case "alwayson": {
args.put("type", "Always On");
args.put("limit", String.valueOf(plugin.getConfig().getCore().chunkLoader.alwaysOn.maxAlwaysOn));
if (playerData.get().getAlwaysOnChunks() - changeValue < 0 || playerData.get().getAlwaysOnChunks() - changeValue > plugin.getConfig().getCore().chunkLoader.alwaysOn.maxAlwaysOn) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.remove.failure, args));
args.put("limit", String.valueOf(plugin.getConfig().getCore().maxAlwaysOn));
if (playerData.get().getAlwaysOnChunks() - changeValue < 0 || playerData.get().getAlwaysOnChunks() - changeValue > plugin.getConfig().getCore().maxAlwaysOn) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksRemoveFailure, args));
return CommandResult.empty();
}

Expand All @@ -116,14 +116,14 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
e.printStackTrace();
}

sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.remove.success, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksRemoveSuccess, args));
return CommandResult.success();
}
case "online": {
args.put("type", "Online Only");
args.put("limit", String.valueOf(plugin.getConfig().getCore().chunkLoader.online.maxOnline));
if (playerData.get().getOnlineChunks() - changeValue < 0 || playerData.get().getOnlineChunks() - changeValue > plugin.getConfig().getCore().chunkLoader.online.maxOnline) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.remove.failure, args));
args.put("limit", String.valueOf(plugin.getConfig().getCore().maxOnline));
if (playerData.get().getOnlineChunks() - changeValue < 0 || playerData.get().getOnlineChunks() - changeValue > plugin.getConfig().getCore().maxOnline) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksRemoveFailure, args));
return CommandResult.empty();
}
playerData.get().removeOnlineChunks(changeValue);
Expand All @@ -134,24 +134,24 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
e.printStackTrace();
}

sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.remove.success, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksRemoveSuccess, args));
return CommandResult.success();
}
default: {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.usage, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksUsage, args));
return CommandResult.empty();
}
}
}
case "set": {
if (changeValue < 0) {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.set.failure, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksSetFailure, args));
return CommandResult.empty();
}
switch (loaderTypeElement) {
case "alwayson": {
args.put("type", "Always On");
args.put("limit", String.valueOf(plugin.getConfig().getCore().chunkLoader.alwaysOn.maxAlwaysOn));
args.put("limit", String.valueOf(plugin.getConfig().getCore().maxAlwaysOn));
playerData.get().setAlwaysOnChunks(changeValue);

try {
Expand All @@ -160,12 +160,12 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
e.printStackTrace();
}

sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.set.success, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksSetSuccess, args));
return CommandResult.success();
}
case "online": {
args.put("type", "Online Only");
args.put("limit", String.valueOf(plugin.getConfig().getCore().chunkLoader.online.maxOnline));
args.put("limit", String.valueOf(plugin.getConfig().getCore().maxOnline));
playerData.get().setOnlineChunks(changeValue);

try {
Expand All @@ -174,17 +174,17 @@ public CommandResult execute(CommandSource sender, CommandContext commandContext
e.printStackTrace();
}

sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.set.success, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksSetSuccess, args));
return CommandResult.success();
}
default: {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.usage, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksUsage, args));
return CommandResult.empty();
}
}
}
default: {
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().commands.chunks.usage, args));
sender.sendMessage(Utilities.parseMessage(plugin.getConfig().getMessages().prefix + plugin.getConfig().getMessages().chunksUsage, args));
return CommandResult.empty();
}
}
Expand Down
Loading

0 comments on commit d5e0a5b

Please sign in to comment.