Code clean up.

This commit is contained in:
tastybento 2018-06-23 18:56:21 -07:00
parent 045855f6ad
commit 0e1ee335ea
17 changed files with 53 additions and 52 deletions

View File

@ -1490,7 +1490,7 @@ public class Settings implements DataObject, WorldSettings {
/**
* Set panel close on click outside
* @param closePanelOnClickOutside
* @param closePanelOnClickOutside - true means close panel when click is outside panel
*/
public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) {
this.closePanelOnClickOutside = closePanelOnClickOutside;

View File

@ -92,7 +92,7 @@ public class AdminRegisterCommand extends CompositeCommand {
/**
* This returns the coordinate of where an island should be on the grid.
*
* @param location
* @param location - location to check
* @return Location of where an island should be on a grid in this world
*/
public Location getClosestIsland(Location location) {

View File

@ -648,7 +648,7 @@ public class Island implements DataObject {
* Show info on the island
* @param plugin - plugin
* @param user - the user who is receiving the info
* @param world
* @param world - world to check
* @return true always
*/
public boolean showInfo(BSkyBlock plugin, User user, World world) {
@ -691,7 +691,7 @@ public class Island implements DataObject {
* Shows the members of this island
* @param plugin - plugin
* @param user - user who is requesting
* @param world
* @param world - world to check
*/
public void showMembers(BSkyBlock plugin, User user, World world) {
if (plugin.getIslands().inTeam(world, user.getUniqueId())) {

View File

@ -411,10 +411,9 @@ public class Clipboard {
/**
* Load a file to clipboard
* @param filename - filename in schems folder
* @return
* @throws IOException
* @throws InvalidConfigurationException
* @param fileName - filename in schems folder
* @throws IOException - if there's a load error with unziping or name
* @throws InvalidConfigurationException - the YAML of the schem is at fault
*/
public void load(String fileName) throws IOException, InvalidConfigurationException {
File zipFile = new File(schemFolder, fileName + ".schem");
@ -434,13 +433,13 @@ public class Clipboard {
Files.delete(file.toPath());
}
/**
* Load a file to clipboard
/*
Load a file to clipboard
*/
/**
* @param user - use trying to load
* @param fileName - filename
* @return
* @return - ture if load is successful, false if not
*/
public boolean load(User user, String fileName) {
try {

View File

@ -98,7 +98,7 @@ public class IslandBuilderNew {
/**
* Copies schems from the jar file
* @param schems2
* @param schems2 - file containing schem
*/
private void copySchems(File schems2) {
plugin.saveResource("schems/island.schem", false);

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags;
@ -24,7 +24,7 @@ public class EnderChestListener extends AbstractFlagListener {
/**
* Prevents opening ender chest unless player has permission
* @param e
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEnderChestOpen(PlayerInteractEvent e) {
@ -36,7 +36,7 @@ public class EnderChestListener extends AbstractFlagListener {
/**
* Prevents crafting of EnderChest unless the player has permission
*
* @param event
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCraft(CraftItemEvent e) {

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags;

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags;

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags;
@ -28,7 +28,7 @@ public class IslandRespawnListener extends AbstractFlagListener {
/**
* Tag players who die in island space and have an island
* @param e
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent e) {
@ -40,7 +40,7 @@ public class IslandRespawnListener extends AbstractFlagListener {
/**
* Place players back on their island if respawn on island is true and active
* @param e
* @param e - event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerRespawn(PlayerRespawnEvent e) {

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags;

View File

@ -83,11 +83,9 @@ public class PlaceBlocksListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onBlockForm(EntityBlockFormEvent e) {
if (e.getNewState().getType().equals(Material.FROSTED_ICE)) {
if (e.getEntity() instanceof Player) {
this.setUser(User.getInstance((Player)e.getEntity()));
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
}
if (e.getNewState().getType().equals(Material.FROSTED_ICE) && e.getEntity() instanceof Player) {
setUser(User.getInstance((Player)e.getEntity()));
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
}
}

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags;
@ -22,9 +22,11 @@ import us.tastybento.bskyblock.lists.Flags;
*
*/
public class RemoveMobsListener extends AbstractFlagListener {
private static Set<EntityType> keepers = new HashSet<>();
{
private static Set<EntityType> keepers;
public RemoveMobsListener() {
keepers = new HashSet<>();
keepers.add(EntityType.ZOMBIE_VILLAGER);
keepers.add(EntityType.PIG_ZOMBIE);
keepers.add(EntityType.WITHER);
@ -39,11 +41,11 @@ public class RemoveMobsListener extends AbstractFlagListener {
clearArea(e.getTo());
}
}
public static void clearArea(Location loc) {
loc.getWorld().getNearbyEntities(loc, 5D, 5D, 5D).stream()
.filter(en -> (en instanceof Monster))
.filter(en -> !keepers.contains(en.getType()))
.forEach(Entity::remove);
.forEach(Entity::remove);
}
}

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags.clicklisteners;

View File

@ -1,5 +1,5 @@
/**
*
/*
*/
package us.tastybento.bskyblock.listeners.flags.clicklisteners;

View File

@ -38,7 +38,7 @@ public class IslandCache {
return false;
}
islandsByLocation.put(island.getCenter(), island);
// Make world
// Make world
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
// Only add islands to this map if they are owned
if (island.getOwner() != null) {
@ -79,7 +79,7 @@ public class IslandCache {
* @return true if successful, false if not
*/
public boolean deleteIslandFromCache(Island island) {
if (!islandsByLocation.remove(island.getCenter(), island) || !islandsByUUID.containsKey(island.getWorld())) {
if (!islandsByLocation.remove(island.getCenter(), island) || !islandsByUUID.containsKey(island.getWorld())) {
return false;
}
islandsByUUID.get(island.getWorld()).entrySet().removeIf(en -> en.getValue().equals(island));
@ -179,7 +179,6 @@ public class IslandCache {
// Clear ownership and members
island.getMembers().clear();
island.setOwner(null);
//islandsByLocation.put(island.getCenter(), island);
} else {
// Remove player from the island membership
island.removeMember(uuid);
@ -190,7 +189,7 @@ public class IslandCache {
/**
* Get the number of islands in the cache
* @return the number of islands
* @return the number of islands
*/
public int size() {
return islandsByLocation.size();
@ -205,7 +204,7 @@ public class IslandCache {
island.setOwner(newOwnerUUID);
islandsByUUID.putIfAbsent(Util.getWorld(island.getWorld()), new HashMap<>());
islandsByUUID.get(Util.getWorld(island.getWorld())).put(newOwnerUUID, island);
islandsByLocation.put(island.getCenter(), island);
islandsByLocation.put(island.getCenter(), island);
}
}

View File

@ -10,12 +10,16 @@ import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User;
import java.util.Comparator;
/**
* Creates settings panels
* @author Poslovitch, tastybento
*/
public class SettingsPanel {
private static final String PROTECTION_PANEL = "protection.panel.";
private SettingsPanel() {}
/**
@ -26,13 +30,13 @@ public class SettingsPanel {
public static void openPanel(BSkyBlock plugin, User user, Flag.Type flagType) {
// Create the panel
PanelBuilder panelBuilder = new PanelBuilder()
.name(user.getTranslation("protection.panel." + flagType.toString() + ".title"))
.name(user.getTranslation(PROTECTION_PANEL + flagType.toString() + ".title"))
.size(54);
setupHeader(user, panelBuilder, flagType);
plugin.getFlagsManager().getFlags().stream().filter(f -> f.getType().equals(flagType))
.sorted((e1, e2) -> e1.getID().compareTo(e2.getID())).forEach((f -> panelBuilder.item(f.toPanelItem(plugin, user))));
.sorted(Comparator.comparing(Flag::getID)).forEach((f -> panelBuilder.item(f.toPanelItem(plugin, user))));
// Show it to the player
panelBuilder.build().open(user);
@ -43,8 +47,8 @@ public class SettingsPanel {
for (Flag.Type flagType : Flag.Type.values()) {
PanelItem panelItem = new PanelItemBuilder()
.icon(flagType.getIcon())
.name(user.getTranslation("protection.panel." + flagType.toString() + ".title"))
.description(user.getTranslation("protection.panel." + flagType.toString() + ".description"))
.name(user.getTranslation(PROTECTION_PANEL + flagType.toString() + ".title"))
.description(user.getTranslation(PROTECTION_PANEL + flagType.toString() + ".description"))
.glow(flagType.equals(currentFlagType))
.clickHandler((panel, user1, clickType, slot1) -> {
if (!flagType.equals(currentFlagType)) {

View File

@ -6,7 +6,6 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang.math.NumberUtils;