refactored some code

This commit is contained in:
Butzlabben 2019-04-23 15:48:30 +02:00
parent 84890fec54
commit 5c032d0f49
3 changed files with 14 additions and 32 deletions

View File

@ -37,7 +37,7 @@ public class WorldConfig {
* Returns wether a worldconfig exists for this worldname * Returns wether a worldconfig exists for this worldname
* *
* @param worldname name of the world * @param worldname name of the world
* @return Wether this world has a worldconfig * @return Whether this world has a worldconfig
*/ */
public static boolean exists(String worldname) { public static boolean exists(String worldname) {
return getWorldFile(worldname).exists(); return getWorldFile(worldname).exists();
@ -69,7 +69,7 @@ public class WorldConfig {
private Location home = null; private Location home = null;
private WorldConfig(String worldname) { private WorldConfig(String worldname) {
if (exists(worldname) == false) if (!exists(worldname))
throw new IllegalArgumentException("WorldConfig doesn't exist"); throw new IllegalArgumentException("WorldConfig doesn't exist");
owner = UUID.fromString(worldname.substring(worldname.length() - 36)); owner = UUID.fromString(worldname.substring(worldname.length() - 36));
id = Integer.parseInt(worldname.split("-")[0].substring(2)); id = Integer.parseInt(worldname.split("-")[0].substring(2));
@ -111,11 +111,7 @@ public class WorldConfig {
public boolean addPermission(UUID player, WorldPerm perm) { public boolean addPermission(UUID player, WorldPerm perm) {
if (owner.equals(player)) if (owner.equals(player))
throw new IllegalArgumentException("Permissions of the owner cannot change"); throw new IllegalArgumentException("Permissions of the owner cannot change");
HashSet<WorldPerm> perms = permissions.get(player); HashSet<WorldPerm> perms = permissions.computeIfAbsent(player, k -> new HashSet<>());
if (perms == null) {
perms = new HashSet<>();
permissions.put(player, perms);
}
return perms.add(perm); return perms.add(perm);
} }
@ -159,11 +155,7 @@ public class WorldConfig {
public boolean addAllPermissions(UUID player) { public boolean addAllPermissions(UUID player) {
if (owner.equals(player)) if (owner.equals(player))
throw new IllegalArgumentException("Permissions of the owner cannot change"); throw new IllegalArgumentException("Permissions of the owner cannot change");
HashSet<WorldPerm> perms = permissions.get(player); HashSet<WorldPerm> perms = permissions.computeIfAbsent(player, k -> new HashSet<>());
if (perms == null) {
perms = new HashSet<>();
permissions.put(player, perms);
}
return perms.addAll(Sets.newHashSet(WorldPerm.values())); return perms.addAll(Sets.newHashSet(WorldPerm.values()));
} }
@ -297,7 +289,7 @@ public class WorldConfig {
* @return if the player has the permissions * @return if the player has the permissions
*/ */
public boolean setBuild(UUID player, UUID target, boolean allowed) { public boolean setBuild(UUID player, UUID target, boolean allowed) {
if (isAllowedToAdministrateMember(player, target) == false) if (!isAllowedToAdministrateMember(player, target))
return false; return false;
setBuild(target, allowed); setBuild(target, allowed);
return true; return true;
@ -333,7 +325,7 @@ public class WorldConfig {
} }
public boolean setGamemode(UUID player, UUID target, boolean allowed) { public boolean setGamemode(UUID player, UUID target, boolean allowed) {
if (isAllowedToAdministrateMember(player, target) == false) if (!isAllowedToAdministrateMember(player, target))
return false; return false;
setGamemode(target, allowed); setGamemode(target, allowed);
return true; return true;
@ -358,7 +350,7 @@ public class WorldConfig {
} }
public boolean setTeleport(UUID player, UUID target, boolean allowed) { public boolean setTeleport(UUID player, UUID target, boolean allowed) {
if (isAllowedToAdministrateMember(player, target) == false) if (!isAllowedToAdministrateMember(player, target))
return false; return false;
setTeleport(target, allowed); setTeleport(target, allowed);
return true; return true;
@ -523,7 +515,7 @@ public class WorldConfig {
* @return if the player has the permissions to change the value * @return if the player has the permissions to change the value
*/ */
public boolean setFire(UUID player, boolean fire) { public boolean setFire(UUID player, boolean fire) {
if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false) if (!hasPermission(player, WorldPerm.ADMINISTRATEWORLD))
return false; return false;
setFire(fire); setFire(fire);
return true; return true;
@ -545,7 +537,7 @@ public class WorldConfig {
* @return if the player has the permissions to change the value * @return if the player has the permissions to change the value
*/ */
public boolean setTnt(UUID player, boolean tnt) { public boolean setTnt(UUID player, boolean tnt) {
if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false) if (!hasPermission(player, WorldPerm.ADMINISTRATEWORLD))
return false; return false;
setTnt(tnt); setTnt(tnt);
return true; return true;

View File

@ -79,9 +79,7 @@ public class SystemWorld {
*/ */
public void directUnload(World w) { public void directUnload(World w) {
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> { Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> directUnload(w));
directUnload(w);
});
return; return;
} }
Preconditions.checkNotNull(w, "world must not be null"); Preconditions.checkNotNull(w, "world must not be null");
@ -120,7 +118,7 @@ public class SystemWorld {
* @param w the associated world * @param w the associated world
* @throws NullPointerException w == null * @throws NullPointerException w == null
*/ */
public void unloadLater(World w) { private void unloadLater(World w) {
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> unloadLater(w)); Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> unloadLater(w));
return; return;
@ -172,9 +170,7 @@ public class SystemWorld {
*/ */
public void load(Player p) { public void load(Player p) {
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> { Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> load(p));
load(p);
});
return; return;
} }
Preconditions.checkNotNull(p, "player must not be null"); Preconditions.checkNotNull(p, "player must not be null");
@ -354,10 +350,7 @@ public class SystemWorld {
return true; return true;
} }
worldAsDir = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); worldAsDir = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml");
if (worldAsDir.exists()) { return worldAsDir.exists();
return true;
}
return false;
} }
/** /**

View File

@ -181,10 +181,7 @@ public class WorldPlayer {
} }
if (worldconfig.exists()) { if (worldconfig.exists()) {
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig);
if (cfg.getString("Informations.Owner.PlayerUUID") == null) { return cfg.getString("Informations.Owner.PlayerUUID") != null;
return false;
}
return true;
} }
return false; return false;
} }