mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-30 22:53:39 +01:00
Fixed a bunch of code smells (again)
This commit is contained in:
parent
85ea4af1ad
commit
3102195156
@ -23,7 +23,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
|||||||
private static final String HIDE = "hide";
|
private static final String HIDE = "hide";
|
||||||
|
|
||||||
// Map of users to which ranges must be displayed
|
// 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) {
|
public AdminRangeDisplayCommand(CompositeCommand parent) {
|
||||||
super(parent, DISPLAY, SHOW, HIDE);
|
super(parent, DISPLAY, SHOW, HIDE);
|
||||||
@ -43,7 +43,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
|||||||
// - show : only set on - and send "error" if already on
|
// - show : only set on - and send "error" if already on
|
||||||
// - hide : only set off - same if already off
|
// - hide : only set off - same if already off
|
||||||
|
|
||||||
if (!display.containsKey(user)) {
|
if (!displayRanges.containsKey(user)) {
|
||||||
switch (label) {
|
switch (label) {
|
||||||
case DISPLAY:
|
case DISPLAY:
|
||||||
case SHOW:
|
case SHOW:
|
||||||
@ -77,7 +77,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
|||||||
private void showZones(User user) {
|
private void showZones(User user) {
|
||||||
user.sendMessage("commands.admin.range.display.showing");
|
user.sendMessage("commands.admin.range.display.showing");
|
||||||
user.sendMessage("commands.admin.range.display.hint");
|
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()) {
|
if (!user.getPlayer().isOnline()) {
|
||||||
hideZones(user);
|
hideZones(user);
|
||||||
}
|
}
|
||||||
@ -99,8 +99,8 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
|||||||
|
|
||||||
private void hideZones(User user) {
|
private void hideZones(User user) {
|
||||||
user.sendMessage("commands.admin.range.display.hiding");
|
user.sendMessage("commands.admin.range.display.hiding");
|
||||||
Bukkit.getScheduler().cancelTask(display.get(user));
|
Bukkit.getScheduler().cancelTask(displayRanges.get(user));
|
||||||
display.remove(user);
|
displayRanges.remove(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawZone(User user, Particle particle, Particle.DustOptions dustOptions, Location center, int range) {
|
private void drawZone(User user, Particle particle, Particle.DustOptions dustOptions, Location center, int range) {
|
||||||
|
@ -19,7 +19,7 @@ public class AdminSchemCommand extends ConfirmableCommand {
|
|||||||
private Map<UUID, Clipboard> clipboards;
|
private Map<UUID, Clipboard> clipboards;
|
||||||
|
|
||||||
// Map containing selection cuboid display tasks
|
// 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 PARTICLE = Particle.REDSTONE;
|
||||||
private static final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F);
|
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);
|
setOnlyPlayer(true);
|
||||||
|
|
||||||
clipboards = new HashMap<>();
|
clipboards = new HashMap<>();
|
||||||
display = new HashMap<>();
|
displayClipboards = new HashMap<>();
|
||||||
|
|
||||||
new AdminSchemLoadCommand(this);
|
new AdminSchemLoadCommand(this);
|
||||||
new AdminSchemPasteCommand(this);
|
new AdminSchemPasteCommand(this);
|
||||||
@ -57,7 +57,7 @@ public class AdminSchemCommand extends ConfirmableCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void showClipboard(User user) {
|
void showClipboard(User user) {
|
||||||
display.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
|
displayClipboards.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
|
||||||
if (!user.getPlayer().isOnline()) {
|
if (!user.getPlayer().isOnline()) {
|
||||||
hideClipboard(user);
|
hideClipboard(user);
|
||||||
}
|
}
|
||||||
@ -107,8 +107,8 @@ public class AdminSchemCommand extends ConfirmableCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hideClipboard(User user) {
|
void hideClipboard(User user) {
|
||||||
Bukkit.getScheduler().cancelTask(display.get(user));
|
Bukkit.getScheduler().cancelTask(displayClipboards.get(user));
|
||||||
display.remove(user);
|
displayClipboards.remove(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
File getSchemsFolder() {
|
File getSchemsFolder() {
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.api.flags.clicklisteners;
|
package world.bentobox.bentobox.api.flags.clicklisteners;
|
||||||
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.api.flags.clicklisteners;
|
package world.bentobox.bentobox.api.flags.clicklisteners;
|
||||||
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
@ -75,10 +75,6 @@ public class PanelBuilder {
|
|||||||
*/
|
*/
|
||||||
public int nextSlot() {
|
public int nextSlot() {
|
||||||
return items.isEmpty() ? 0 : items.lastKey() + 1;
|
return items.isEmpty() ? 0 : items.lastKey() + 1;
|
||||||
//for (int i = 0 ; i < (size == 0 ? 54 : size) ; i++) {
|
|
||||||
// if (!slotOccupied(i)) return i;
|
|
||||||
//}
|
|
||||||
//return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,11 +177,10 @@ public class NetherPortals implements Listener {
|
|||||||
if (e.getCause().equals(TeleportCause.NETHER_PORTAL)
|
if (e.getCause().equals(TeleportCause.NETHER_PORTAL)
|
||||||
&& plugin.getIWM().inWorld(e.getFrom())
|
&& plugin.getIWM().inWorld(e.getFrom())
|
||||||
&& !plugin.getIWM().isNetherIslands(fromWorld)
|
&& !plugin.getIWM().isNetherIslands(fromWorld)
|
||||||
&& fromWorld.getEnvironment().equals(Environment.NETHER)) {
|
&& fromWorld.getEnvironment().equals(Environment.NETHER)
|
||||||
if (plugin.getPlayers().isKnown(e.getPlayer().getUniqueId())) {
|
&& plugin.getPlayers().isKnown(e.getPlayer().getUniqueId())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
|
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +72,11 @@ public class TNTListener extends AbstractFlagListener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onExplosion(final EntityExplodeEvent e) {
|
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 and if the entity was a TNT
|
||||||
// Remove any blocks from the explosion list if they are inside a protected area
|
if (e.getEntity() != null && e.getEntityType().equals(EntityType.PRIMED_TNT)
|
||||||
if (e.blockList().removeIf(b -> getIslands().getProtectedIslandAt(b.getLocation()).map(i -> !i.isAllowed(Flags.TNT)).orElse(false))) {
|
&& e.blockList().removeIf(b -> getIslands().getProtectedIslandAt(b.getLocation()).map(i -> !i.isAllowed(Flags.TNT)).orElse(false))) {
|
||||||
// If any were removed, then prevent damage too
|
// If any were removed, then prevent damage too
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,12 +174,8 @@ public class IslandsManager {
|
|||||||
if (!ground.getType().isSolid()) {
|
if (!ground.getType().isSolid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Cannot be submerged
|
// Cannot be submerged or water cannot be dangerous
|
||||||
if (space1.isLiquid() && space2.isLiquid()) {
|
if (space1.isLiquid() && (space2.isLiquid() || plugin.getIWM().isWaterNotSafe(l.getWorld()))) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Check if water is safe in this world
|
|
||||||
if (space1.isLiquid() && plugin.getIWM().isWaterNotSafe(l.getWorld())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +201,7 @@ public class IslandsManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check that the space is not solid
|
// Check that the space is not solid
|
||||||
// The isSolid function is not fully accurate (yet) so we have to
|
// The isSolid function is not fully accurate (yet) so we have to check a few other items
|
||||||
// check
|
|
||||||
// a few other items
|
|
||||||
// isSolid thinks that PLATEs and SIGNS are solid, but they are not
|
// 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));
|
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));
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,9 @@ public class PlayersManager {
|
|||||||
if (name.length() == 36 && name.contains("-")) {
|
if (name.length() == 36 && name.contains("-")) {
|
||||||
try {
|
try {
|
||||||
return UUID.fromString(name);
|
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
|
// Look in the name cache, then the data base and then give up
|
||||||
return playerCache.values().stream()
|
return playerCache.values().stream()
|
||||||
|
@ -19,6 +19,8 @@ public class SchemsManager {
|
|||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
private Map<World, Clipboard> islandSchems;
|
private Map<World, Clipboard> islandSchems;
|
||||||
|
|
||||||
|
private static final String SCHEM = ".schem";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plugin - plugin
|
* @param plugin - plugin
|
||||||
*/
|
*/
|
||||||
@ -37,16 +39,16 @@ public class SchemsManager {
|
|||||||
plugin.logError("Could not make schems folder!");
|
plugin.logError("Could not make schems folder!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File schem = new File(schems, name + ".schem");
|
File schem = new File(schems, name + SCHEM);
|
||||||
if (schem.exists()) {
|
if (schem.exists()) {
|
||||||
// No overwriting
|
// No overwriting
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Optional<Addon> addon = plugin.getIWM().getAddon(world);
|
Optional<Addon> addon = plugin.getIWM().getAddon(world);
|
||||||
if (addon.isPresent()) {
|
if (addon.isPresent()) {
|
||||||
addon.get().saveResource("schems/" + name + ".schem", false);
|
addon.get().saveResource("schems/" + name + SCHEM, false);
|
||||||
} else {
|
} else {
|
||||||
plugin.saveResource("schems/" + name + ".schem", false);
|
plugin.saveResource("schems/" + name + SCHEM, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ public class Clipboard {
|
|||||||
}
|
}
|
||||||
// Entities
|
// Entities
|
||||||
if (config.isConfigurationSection(ENTITY)) {
|
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
|
* Sets any entity that is in this location
|
||||||
* @param island - island
|
|
||||||
* @param location - locaton
|
* @param location - locaton
|
||||||
* @param config - config section
|
* @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);
|
ConfigurationSection en = config.getConfigurationSection(ENTITY);
|
||||||
en.getKeys(false).forEach(k -> {
|
en.getKeys(false).forEach(k -> {
|
||||||
ConfigurationSection ent = en.getConfigurationSection(k);
|
ConfigurationSection ent = en.getConfigurationSection(k);
|
||||||
|
Loading…
Reference in New Issue
Block a user