Fixed a bunch of code smells (again)

This commit is contained in:
Florian CUNY 2018-10-20 10:59:19 +02:00
parent 85ea4af1ad
commit 3102195156
11 changed files with 32 additions and 47 deletions

View File

@ -23,7 +23,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
private static final String HIDE = "hide";
// Map of users to which ranges must be displayed
private Map<User, Integer> display = new HashMap<>();
private Map<User, Integer> displayRanges = new HashMap<>();
public AdminRangeDisplayCommand(CompositeCommand parent) {
super(parent, DISPLAY, SHOW, HIDE);
@ -43,7 +43,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
// - show : only set on - and send "error" if already on
// - hide : only set off - same if already off
if (!display.containsKey(user)) {
if (!displayRanges.containsKey(user)) {
switch (label) {
case DISPLAY:
case SHOW:
@ -77,7 +77,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
private void showZones(User user) {
user.sendMessage("commands.admin.range.display.showing");
user.sendMessage("commands.admin.range.display.hint");
display.put(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
displayRanges.put(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
if (!user.getPlayer().isOnline()) {
hideZones(user);
}
@ -99,8 +99,8 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
private void hideZones(User user) {
user.sendMessage("commands.admin.range.display.hiding");
Bukkit.getScheduler().cancelTask(display.get(user));
display.remove(user);
Bukkit.getScheduler().cancelTask(displayRanges.get(user));
displayRanges.remove(user);
}
private void drawZone(User user, Particle particle, Particle.DustOptions dustOptions, Location center, int range) {

View File

@ -19,7 +19,7 @@ public class AdminSchemCommand extends ConfirmableCommand {
private Map<UUID, Clipboard> clipboards;
// Map containing selection cuboid display tasks
private Map<User, Integer> display;
private Map<User, Integer> displayClipboards;
private static final Particle PARTICLE = Particle.REDSTONE;
private static final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F);
@ -35,7 +35,7 @@ public class AdminSchemCommand extends ConfirmableCommand {
setOnlyPlayer(true);
clipboards = new HashMap<>();
display = new HashMap<>();
displayClipboards = new HashMap<>();
new AdminSchemLoadCommand(this);
new AdminSchemPasteCommand(this);
@ -57,7 +57,7 @@ public class AdminSchemCommand extends ConfirmableCommand {
}
void showClipboard(User user) {
display.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
displayClipboards.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
if (!user.getPlayer().isOnline()) {
hideClipboard(user);
}
@ -107,8 +107,8 @@ public class AdminSchemCommand extends ConfirmableCommand {
}
void hideClipboard(User user) {
Bukkit.getScheduler().cancelTask(display.get(user));
display.remove(user);
Bukkit.getScheduler().cancelTask(displayClipboards.get(user));
displayClipboards.remove(user);
}
File getSchemsFolder() {

View File

@ -1,6 +1,3 @@
/*
*/
package world.bentobox.bentobox.api.flags.clicklisteners;
import org.bukkit.Sound;

View File

@ -1,6 +1,3 @@
/*
*/
package world.bentobox.bentobox.api.flags.clicklisteners;
import org.bukkit.Sound;

View File

@ -75,10 +75,6 @@ public class PanelBuilder {
*/
public int nextSlot() {
return items.isEmpty() ? 0 : items.lastKey() + 1;
//for (int i = 0 ; i < (size == 0 ? 54 : size) ; i++) {
// if (!slotOccupied(i)) return i;
//}
//return -1;
}
/**

View File

@ -177,11 +177,10 @@ public class NetherPortals implements Listener {
if (e.getCause().equals(TeleportCause.NETHER_PORTAL)
&& plugin.getIWM().inWorld(e.getFrom())
&& !plugin.getIWM().isNetherIslands(fromWorld)
&& fromWorld.getEnvironment().equals(Environment.NETHER)) {
if (plugin.getPlayers().isKnown(e.getPlayer().getUniqueId())) {
e.setCancelled(true);
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
}
&& fromWorld.getEnvironment().equals(Environment.NETHER)
&& plugin.getPlayers().isKnown(e.getPlayer().getUniqueId())) {
e.setCancelled(true);
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
}
}

View File

@ -72,12 +72,11 @@ public class TNTListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) {
if (e.getEntity() != null && e.getEntityType().equals(EntityType.PRIMED_TNT)) {
// Remove any blocks from the explosion list if they are inside a protected area
if (e.blockList().removeIf(b -> getIslands().getProtectedIslandAt(b.getLocation()).map(i -> !i.isAllowed(Flags.TNT)).orElse(false))) {
// If any were removed, then prevent damage too
e.setCancelled(true);
}
// Remove any blocks from the explosion list if they are inside a protected area and if the entity was a TNT
if (e.getEntity() != null && e.getEntityType().equals(EntityType.PRIMED_TNT)
&& e.blockList().removeIf(b -> getIslands().getProtectedIslandAt(b.getLocation()).map(i -> !i.isAllowed(Flags.TNT)).orElse(false))) {
// If any were removed, then prevent damage too
e.setCancelled(true);
}
}

View File

@ -174,12 +174,8 @@ public class IslandsManager {
if (!ground.getType().isSolid()) {
return false;
}
// Cannot be submerged
if (space1.isLiquid() && space2.isLiquid()) {
return false;
}
// Check if water is safe in this world
if (space1.isLiquid() && plugin.getIWM().isWaterNotSafe(l.getWorld())) {
// Cannot be submerged or water cannot be dangerous
if (space1.isLiquid() && (space2.isLiquid() || plugin.getIWM().isWaterNotSafe(l.getWorld()))) {
return false;
}
@ -205,9 +201,7 @@ public class IslandsManager {
return false;
}
// Check that the space is not solid
// The isSolid function is not fully accurate (yet) so we have to
// check
// a few other items
// The isSolid function is not fully accurate (yet) so we have to check a few other items
// isSolid thinks that PLATEs and SIGNS are solid, but they are not
return (!space1.getType().isSolid() || space1.getType().equals(Material.SIGN) || space1.getType().equals(Material.WALL_SIGN)) && (!space2.getType().isSolid() || space2.getType().equals(Material.SIGN) || space2.getType().equals(Material.WALL_SIGN));
}

View File

@ -227,7 +227,9 @@ public class PlayersManager {
if (name.length() == 36 && name.contains("-")) {
try {
return UUID.fromString(name);
} catch (Exception ignored) {}
} catch (Exception ignored) {
// Not used
}
}
// Look in the name cache, then the data base and then give up
return playerCache.values().stream()

View File

@ -19,6 +19,8 @@ public class SchemsManager {
private BentoBox plugin;
private Map<World, Clipboard> islandSchems;
private static final String SCHEM = ".schem";
/**
* @param plugin - plugin
*/
@ -37,16 +39,16 @@ public class SchemsManager {
plugin.logError("Could not make schems folder!");
return;
}
File schem = new File(schems, name + ".schem");
File schem = new File(schems, name + SCHEM);
if (schem.exists()) {
// No overwriting
return;
}
Optional<Addon> addon = plugin.getIWM().getAddon(world);
if (addon.isPresent()) {
addon.get().saveResource("schems/" + name + ".schem", false);
addon.get().saveResource("schems/" + name + SCHEM, false);
} else {
plugin.saveResource("schems/" + name + ".schem", false);
plugin.saveResource("schems/" + name + SCHEM, false);
}
}

View File

@ -250,7 +250,7 @@ public class Clipboard {
}
// Entities
if (config.isConfigurationSection(ENTITY)) {
setEntity(island, block.getLocation(), config);
setEntity(block.getLocation(), config);
}
}
@ -263,11 +263,10 @@ public class Clipboard {
/**
* Sets any entity that is in this location
* @param island - island
* @param location - locaton
* @param config - config section
*/
private void setEntity(Island island, Location location, ConfigurationSection config) {
private void setEntity(Location location, ConfigurationSection config) {
ConfigurationSection en = config.getConfigurationSection(ENTITY);
en.getKeys(false).forEach(k -> {
ConfigurationSection ent = en.getConfigurationSection(k);