Skip to content

Commit

Permalink
Issue #135: Plugin doesnt work unless you delete the config and force…
Browse files Browse the repository at this point in the history
… reload and clearcache after startup
  • Loading branch information
Aleksey-Terzi committed Dec 4, 2016
1 parent ce1b92a commit 281497b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.2.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Orebfuscator4</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@

import java.io.IOException;

import net.md_5.bungee.api.ChatColor;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;

Expand Down Expand Up @@ -91,36 +97,43 @@ else if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("disable
if (args[0].equalsIgnoreCase("enable") && args.length == 1) {
Orebfuscator.configManager.setEnabled(true);
Orebfuscator.message(sender, "Enabled.");
return true;
}

else if (args[0].equalsIgnoreCase("disable") && args.length == 1) {
Orebfuscator.configManager.setEnabled(false);
Orebfuscator.message(sender, "Disabled.");
return true;
}

else if (args.length > 1) {
if (args[1].equalsIgnoreCase("op")) {
Orebfuscator.configManager.setNoObfuscationForOps(data);
Orebfuscator.message(sender, "Ops No-Obfuscation " + (data ? "enabled" : "disabled") + ".");
return true;
}
else if (args[1].equalsIgnoreCase("perms") || args[1].equalsIgnoreCase("permissions")) {
Orebfuscator.configManager.setNoObfuscationForPermission(data);
Orebfuscator.message(sender, "Permissions No-Obfuscation " + (data ? "enabled" : "disabled") + ".");
return true;
}
else if (args[1].equalsIgnoreCase("cache")) {
Orebfuscator.configManager.setUseCache(data);
Orebfuscator.message(sender, "Cache " + (data ? "enabled" : "disabled") + ".");
return true;
}
else if (args[1].equalsIgnoreCase("notification")) {
Orebfuscator.configManager.setLoginNotification(data);
Orebfuscator.message(sender, "Login Notification " + (data ? "enabled" : "disabled") + ".");
return true;
}
}
}

else if (args[0].equalsIgnoreCase("reload")) {
Orebfuscator.instance.reloadOrebfuscatorConfig();
Orebfuscator.message(sender, "Reload complete.");
return true;
}

else if (args[0].equalsIgnoreCase("status")) {
Expand Down Expand Up @@ -150,6 +163,8 @@ else if (args[0].equalsIgnoreCase("status")) {

Orebfuscator.message(sender, "Worlds: " + (worlds.equals("") ? "None" : worlds));
Orebfuscator.message(sender, "Use worlds as: " + (Orebfuscator.config.getDefaultWorld().isEnabled() ? "Blacklist" : "Whitelist"));

return true;
}

else if (args[0].equalsIgnoreCase("clearcache")) {
Expand All @@ -159,8 +174,50 @@ else if (args[0].equalsIgnoreCase("clearcache")) {
} catch (IOException e) {
e.printStackTrace();
}

return true;
}

else if (args[0].equalsIgnoreCase("obfuscateblocks")) {
if(args.length == 1) {
Orebfuscator.message(sender, ChatColor.RED + "World is required parameter.");
} else {
String worldName = args[1];
World world = Bukkit.getWorld(worldName);

if(world == null) {
Orebfuscator.message(sender, ChatColor.RED + "Specified world is not found.");
} else {
if(args.length > 2) {
Material material = Material.getMaterial(args[2]);

if(material == null) {
Orebfuscator.message(sender, ChatColor.RED + "Specified material is not found.");
} else {
int materialId = DeprecatedMethods.getMaterialId(material);

if(Orebfuscator.configManager.getWorld(world).isObfuscated(materialId))
Orebfuscator.message(sender, material.name() + ": " + ChatColor.GREEN + "obfuscate");
else
Orebfuscator.message(sender, material.name() + ": " + ChatColor.RED + "not obfuscate");
}
} else {
boolean[] blocks = Orebfuscator.configManager.getWorld(world).getObfuscateAndProximityBlocks();

Orebfuscator.message(sender, ChatColor.GREEN + "Obfuscate blocks:");

for(int i = 0; i < blocks.length; i++) {
if(blocks[i]) {
Orebfuscator.message(sender, " - " + DeprecatedMethods.getMaterial(i).name());
}
}
}
}
}

return true;
}

return true;
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ private void setObfuscateAndProximityBlocks() {
}
}

public boolean[] getObfuscateAndProximityBlocks() {
return this.obfuscateAndProximityBlocks;
}

public boolean[] getDarknessBlocks() {
return this.darknessBlocks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.utils.Globals;

public class WorldReader {
Expand Down Expand Up @@ -102,7 +104,7 @@ private WorldConfig readWorldByType(Set<String> keys, WorldType worldType, World
world.setDefaults();
}

world = readWorld(worldPath, world, worldType == WorldType.Default);
world = readWorld(worldPath, world, worldType, worldType == WorldType.Default);
break;
}
}
Expand Down Expand Up @@ -140,7 +142,7 @@ private void readWorldsByName(String worldPath) {
String key = name.toLowerCase();

if(!this.worlds.containsKey(key)) {
this.worlds.put(key, readWorld(worldPath, null, false));
this.worlds.put(key, readWorld(worldPath, null, WorldType.Default, false));
}
}
}
Expand Down Expand Up @@ -170,7 +172,7 @@ private List<WorldType> parseWorldTypes(List<String> types) {
return parsedTypes;
}

private WorldConfig readWorld(String worldPath, WorldConfig cfg, boolean withSave) {
private WorldConfig readWorld(String worldPath, WorldConfig cfg, WorldType worldType, boolean withSave) {
if(cfg == null) {
cfg = new WorldConfig();
}
Expand All @@ -183,6 +185,20 @@ private WorldConfig readWorld(String worldPath, WorldConfig cfg, boolean withSav
Integer mode1Block = this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", cfg.getMode1BlockId(), withSave);
Integer[] randomBlocks = this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", cfg.getRandomBlocks(), withSave);
boolean[] obfuscateBlocks = readBlockMatrix(cfg.getObfuscateBlocks(), cfg.getObfuscateBlockIds(), worldPath + ".ObfuscateBlocks", withSave);

switch(worldType) {
case Normal:
obfuscateBlocks[DeprecatedMethods.getMaterialId(Material.STONE)] = true;
break;
case TheEnd:
obfuscateBlocks[DeprecatedMethods.getMaterialId(Material.ENDER_STONE)] = true;
break;
case Nether:
obfuscateBlocks[DeprecatedMethods.getMaterialId(Material.NETHERRACK)] = true;
break;
default:
break;
}

readProximityHider(worldPath, cfg, withSave);

Expand Down Expand Up @@ -277,7 +293,7 @@ private WorldConfig createDefaultWorld(String worldPath) {
WorldConfig world = new WorldConfig();
world.setDefaults();

return readWorld(worldPath, world, true);
return readWorld(worldPath, world, WorldType.Default, true);
}

private WorldConfig createNormalWorld(String worldPath) {
Expand All @@ -294,8 +310,6 @@ private WorldConfig createNormalWorld(String worldPath) {

setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);

obfuscateBlocks[1] = true;

WorldConfig cfg = new WorldConfig();
cfg.setObfuscateBlocks(obfuscateBlocks);
cfg.setRandomBlocks(randomBlocks);
Expand All @@ -318,8 +332,6 @@ private WorldConfig createEndWorld(String worldPath) {

setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);

obfuscateBlocks[121] = true;

WorldConfig cfg = new WorldConfig();
cfg.setRandomBlocks(randomBlocks);
cfg.setObfuscateBlocks(obfuscateBlocks);
Expand All @@ -342,8 +354,6 @@ private WorldConfig createNetherWorld(String worldPath) {

setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);

obfuscateBlocks[87] = true;

WorldConfig cfg = new WorldConfig();
cfg.setRandomBlocks(randomBlocks);
cfg.setObfuscateBlocks(obfuscateBlocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static byte[] obfuscate(ChunkData chunkData, Player player, ArrayList<Bl
}
}
}

// Check if the block should be obfuscated because of proximity check
if (!obfuscate && proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockState.id)) {
BlockCoord block = new BlockCoord(x, y, z);
Expand Down

0 comments on commit 281497b

Please sign in to comment.