Removal of code smells.

Removed a lot of debug code.

Refactored some loops into lambas.
This commit is contained in:
Tastybento 2018-04-18 19:07:20 -07:00
parent 01aef76eb5
commit e881a5bd2b
28 changed files with 25 additions and 367 deletions

View File

@ -66,7 +66,6 @@ public class BSkyBlock extends JavaPlugin {
settings = settings.loadSettings();
} catch (Exception e) {
getLogger().severe("Settings could not be loaded " + e.getMessage());
e.printStackTrace();
}
// Save a backup of settings to the database so it can be checked next time

View File

@ -27,7 +27,6 @@ import us.tastybento.bskyblock.managers.PlayersManager;
public abstract class Addon implements AddonInterface {
private static final String ADDON_CONFIG_FILENAME = "config.yml";
private static final boolean DEBUG = false;
private boolean enabled;
private AddonDescription description;
private FileConfiguration config;
@ -188,10 +187,6 @@ public abstract class Addon implements AddonInterface {
}
// Make any dirs that need to be made
outFile.getParentFile().mkdirs();
if (DEBUG) {
Bukkit.getLogger().info("DEBUG: outFile = " + outFile.getAbsolutePath());
Bukkit.getLogger().info("DEBUG: outFile name = " + outFile.getName());
}
if (!outFile.exists() || replace) {
java.nio.file.Files.copy(in, outFile.toPath());
}

View File

@ -70,7 +70,6 @@ public class BSBLocale {
YamlConfiguration toBeMerged = YamlConfiguration.loadConfiguration(language);
for (String key : toBeMerged.getKeys(true)) {
if (!config.contains(key)) {
//Bukkit.getLogger().info("Merging in key " + key );
config.set(key, toBeMerged.get(key));
}
}

View File

@ -237,8 +237,8 @@ public class User {
*/
public void notify(String reference, String... variables) {
String message = getTranslation(reference, variables);
if (!ChatColor.stripColor(message).trim().isEmpty()) {
if (sender != null || !plugin.getNotifier().notify(this, message)) sendRawMessage(message);
if (!ChatColor.stripColor(message).trim().isEmpty() && (sender != null || !plugin.getNotifier().notify(this, message))) {
sendRawMessage(message);
}
}

View File

@ -3,7 +3,6 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -29,8 +28,6 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
@Override
public boolean execute(User user, List<String> args) {
Bukkit.getLogger().info("DEBUG: accept - " + inviteList.toString());
UUID playerUUID = user.getUniqueId();
if(!inviteList.containsKey(playerUUID)) {
return false;
@ -52,9 +49,6 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
inviteList.remove(playerUUID);
return false;
}
if (DEBUG) {
getPlugin().getLogger().info("DEBUG: Invite is valid");
}
// Fire event so add-ons can run commands, etc.
IslandBaseEvent event = TeamEvent.builder()
.island(getIslands()
@ -67,9 +61,6 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
return true;
}
// Remove the invite
if (DEBUG) {
getPlugin().getLogger().info("DEBUG: Removing player from invite list");
}
inviteList.remove(playerUUID);
// Put player into Spectator mode
user.setGameMode(GameMode.SPECTATOR);
@ -105,9 +96,6 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName());
}
getIslands().save(false);
if (DEBUG) {
getPlugin().getLogger().info(() -> "DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMemberSet().toString());
}
return true;
}

View File

@ -2,8 +2,6 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List;
import org.bukkit.Bukkit;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.user.User;
@ -57,10 +55,8 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
private boolean change(User user, User target) {
int currentRank = getIslands().getIsland(user.getUniqueId()).getRank(target);
Bukkit.getLogger().info("DEBUG: current rank = " + currentRank);
if (this.getLabel().equals("promote")) {
int nextRank = getPlugin().getRanksManager().getNextRankValue(currentRank);
Bukkit.getLogger().info("DEBUG: next rank = " + nextRank);
if (nextRank > currentRank) {
getIslands().getIsland(user.getUniqueId()).setRank(target, nextRank);
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank));
@ -73,7 +69,6 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
} else {
// Demote
int prevRank = getPlugin().getRanksManager().getPreviousRankValue(currentRank);
Bukkit.getLogger().info("DEBUG: Rev rank = " + prevRank);
if (prevRank < currentRank) {
getIslands().getIsland(user.getUniqueId()).setRank(target, prevRank);
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank));

View File

@ -60,7 +60,6 @@ public class BSBDatabase<T> {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| ClassNotFoundException | IntrospectionException e) {
logger.severe(() -> "Could not load object from database! " + e.getMessage());
e.printStackTrace();
}
return null;

View File

@ -50,8 +50,8 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
private static final String DATABASE_FOLDER_NAME = "database";
protected boolean configFlag;
public FlatFileDatabaseHandler(Plugin plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
super(plugin, type, databaseConnecter);
public FlatFileDatabaseHandler(Plugin plugin, Class<T> type, DatabaseConnecter dbConnecter) {
super(plugin, type, dbConnecter);
}
/* (non-Javadoc)
@ -351,7 +351,6 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
if (object == null) {
return "null";
}
//plugin.getLogger().info("DEBUG: serializing " + object.getClass().getTypeName());
if (object instanceof UUID) {
return ((UUID)object).toString();
}

View File

@ -34,8 +34,7 @@ public class MongoDBDatabaseConnecter implements DatabaseConnecter {
@Override
public MongoDatabase createConnection() {
MongoDatabase database = client.getDatabase(dbSettings.getDatabaseName());
return database;
return client.getDatabase(dbSettings.getDatabaseName());
}
@Override

View File

@ -48,7 +48,7 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
*/
private MongoDatabase database = null;
private MongoCollection<Document> collection;
private DatabaseConnecter databaseConnecter;
private DatabaseConnecter dbConnecter;
private BSkyBlock bskyblock;
@ -57,13 +57,13 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* the class that will be stored.
* @param plugin - BSkyBlock plugin object
* @param type - the type of class to be stored in the database. Must inherit DataObject
* @param databaseConnecter - authentication details for the database
* @param dbConnecter - authentication details for the database
*/
public MongoDBDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
super(plugin, type, databaseConnecter);
public MongoDBDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter dbConnecter) {
super(plugin, type, dbConnecter);
this.bskyblock = plugin;
this.databaseConnecter = databaseConnecter;
database = (MongoDatabase)databaseConnecter.createConnection();
this.dbConnecter = dbConnecter;
database = (MongoDatabase)dbConnecter.createConnection();
collection = database.getCollection(dataObject.getCanonicalName());
IndexOptions indexOptions = new IndexOptions().unique(true);
collection.createIndex(Indexes.text(UNIQUEID), indexOptions);
@ -160,7 +160,7 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
@Override
public void close() {
databaseConnecter.closeConnection();
dbConnecter.closeConnection();
}

View File

@ -48,12 +48,12 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
* the class that will be stored.
* @param plugin - BSkyBlock plugin object
* @param type - the type of class to be stored in the database. Must inherit DataObject
* @param databaseConnecter - authentication details for the database
* @param dbConnecter - authentication details for the database
*/
public MySQLDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
super(plugin, type, databaseConnecter);
public MySQLDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter dbConnecter) {
super(plugin, type, dbConnecter);
this.bskyblock = plugin;
connection = (Connection)databaseConnecter.createConnection();
connection = (Connection)dbConnecter.createConnection();
// Check if the table exists in the database and if not, create it
createSchema();
}

View File

@ -315,7 +315,6 @@ public class Island implements DataObject {
for (int x = getMinProtectedX() /16; x <= (getMinProtectedX() + getProtectionRange() - 1)/16; x++) {
for (int z = getMinProtectedZ() /16; z <= (getMinProtectedZ() + getProtectionRange() - 1)/16; z++) {
for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) {
//plugin.getLogger().info("DEBUG: tile entity: " + holder.getType());
if (onIsland(holder.getLocation())) {
if (holder.getType() == material) {
result++;
@ -339,7 +338,6 @@ public class Island implements DataObject {
}
}
for (Entity holder : world.getChunkAt(x, z).getEntities()) {
//plugin.getLogger().info("DEBUG: entity: " + holder.getType());
if (holder.getType().toString().equals(material.toString()) && onIsland(holder.getLocation())) {
result++;
}

View File

@ -227,26 +227,21 @@ public class Players implements DataObject {
public long getInviteCoolDownTime(Location location) {
// Check the hashmap
if (location != null && kickedList.containsKey(location)) {
// plugin.getLogger().info("DEBUG: Location is known");
// The location is in the list
// Check the date/time
Date kickedDate = new Date(kickedList.get(location));
// plugin.getLogger().info("DEBUG: kicked date = " + kickedDate);
Calendar coolDownTime = Calendar.getInstance();
coolDownTime.setTime(kickedDate);
// coolDownTime.add(Calendar.HOUR_OF_DAY, Settings.inviteWait);
coolDownTime.add(Calendar.MINUTE, getPlugin().getSettings().getInviteWait());
// Add the invite cooldown period
Calendar timeNow = Calendar.getInstance();
// plugin.getLogger().info("DEBUG: date now = " + timeNow);
if (coolDownTime.before(timeNow)) {
// The time has expired
kickedList.remove(location);
return 0;
} else {
// Still not there yet
// long hours = (coolDownTime.getTimeInMillis() -
// timeNow.getTimeInMillis())/(1000 * 60 * 60);
// Temp minutes
return (coolDownTime.getTimeInMillis() - timeNow.getTimeInMillis()) / (1000 * 60);
}

View File

@ -78,8 +78,6 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
// Do the ceiling
// Bukkit.getLogger().info("debug: " + x + ", " +
// (world.getMaxHeight()-1) + ", " + z);
int maxHeight = world.getMaxHeight();
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
// Next three layers are a mix of bedrock and netherrack

View File

@ -112,9 +112,7 @@ public class NetherPopulator extends BlockPopulator {
world.generateTree(source.getBlock(x, y + 1, z).getLocation(), TreeType.BROWN_MUSHROOM);
b.setType(Material.SOUL_SAND);
} else if (b.getType().equals(Material.SOUL_SAND) && b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
//Bukkit.getLogger().info("DEBUG: soul sand found!");
if (random.nextInt(9) == 1) {
//Bukkit.getLogger().info("DEBUG: Setting to NETHER_WARTS");
b.getRelative(BlockFace.UP).setType(Material.NETHER_WARTS);
}
}

View File

@ -16,7 +16,6 @@ import us.tastybento.bskyblock.managers.PlayersManager;
public class JoinLeaveListener implements Listener {
private static final boolean DEBUG = false;
private BSkyBlock plugin;
private PlayersManager players;
@ -39,56 +38,31 @@ public class JoinLeaveListener implements Listener {
}
UUID playerUUID = user.getUniqueId();
if (plugin.getPlayers().isKnown(playerUUID)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: known player");
}
// Load player
players.addPlayer(playerUUID);
// Reset resets if the admin changes it to or from unlimited
if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) {
players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit());
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: Setting player's name");
}
// Set the player's name (it may have changed), but only if it isn't empty
if (!user.getName().isEmpty()) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: Player name is " + user.getName());
}
players.setPlayerName(user);
if (DEBUG) {
plugin.getLogger().info("DEBUG: Saving player");
}
players.save(playerUUID);
} else {
plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString());
}
if (plugin.getSettings().isRemoveMobsOnLogin()) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: Removing mobs");
}
plugin.getIslands().removeMobs(user.getLocation());
}
// Check if they logged in to a locked island and expel them or if they are banned
Island currentIsland = plugin.getIslands().getIslandAt(user.getLocation()).orElse(null);
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
}
if (!currentIsland.getMemberSet().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: No bypass - teleporting");
}
user.sendMessage("locked.islandlocked");
plugin.getIslands().homeTeleport(user.getPlayer());
}
}
} else {
if (DEBUG) {
plugin.getLogger().info("DEBUG: not a known player");
}
}
}

View File

@ -112,7 +112,6 @@ public class FireListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public boolean onTNTPrimed(EntityChangeBlockEvent e) {
//Bukkit.getLogger().info("DEBUG: " + e.getBlock().getType());
return e.getBlock().getType().equals(Material.TNT) && checkFire(e, e.getBlock().getLocation(), Flags.FIRE);
}

View File

@ -30,7 +30,6 @@ import us.tastybento.bskyblock.util.Util;
*/
public class FlyingMobEvents implements Listener {
private final BSkyBlock plugin;
private final static boolean DEBUG = false;
private WeakHashMap<Entity, Island> mobSpawnInfo;
/**
@ -41,24 +40,19 @@ public class FlyingMobEvents implements Listener {
mobSpawnInfo = new WeakHashMap<>();
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
//Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size());
Iterator<Entry<Entity, Island>> it = mobSpawnInfo.entrySet().iterator();
while (it.hasNext()) {
Entry<Entity, Island> entry = it.next();
if (entry.getKey() == null) {
//Bukkit.getLogger().info("DEBUG: removing null entity");
it.remove();
} else {
if (entry.getKey() instanceof LivingEntity) {
if (!entry.getValue().inIslandSpace(entry.getKey().getLocation())) {
//Bukkit.getLogger().info("DEBUG: removing entity outside of island");
it.remove();
// Kill mob
LivingEntity mob = (LivingEntity)entry.getKey();
mob.setHealth(0);
entry.getKey().remove();
} else {
//Bukkit.getLogger().info("DEBUG: entity " + entry.getKey().getName() + " is in island space");
}
} else {
// Not living entity
@ -82,32 +76,20 @@ public class FlyingMobEvents implements Listener {
if (!e.getEntityType().equals(EntityType.WITHER) && !e.getEntityType().equals(EntityType.BLAZE) && !e.getEntityType().equals(EntityType.GHAST)) {
return;
}
if (DEBUG) {
plugin.getLogger().info("Flying mobs " + e.getEventName());
}
// Store where this mob originated
plugin.getIslands().getIslandAt(e.getLocation()).ifPresent(island->mobSpawnInfo.put(e.getEntity(),island));
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void mobExplosion(EntityExplodeEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Only cover in the island world
if (e.getEntity() == null || !Util.inWorld(e.getEntity())) {
return;
}
if (mobSpawnInfo.containsKey(e.getEntity())) {
// We know about this mob
if (DEBUG) {
plugin.getLogger().info("DEBUG: We know about this mob");
}
if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getLocation())) {
// Cancel the explosion and block damage
if (DEBUG) {
plugin.getLogger().info("DEBUG: cancel flying mob explosion");
}
e.blockList().clear();
e.setCancelled(true);
}
@ -119,50 +101,32 @@ public class FlyingMobEvents implements Listener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void witherExplode(ExplosionPrimeEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Only cover withers in the island world
if (!Util.inWorld(e.getEntity()) || e.getEntity() == null) {
return;
}
// The wither or wither skulls can both blow up
if (e.getEntityType() == EntityType.WITHER) {
//plugin.getLogger().info("DEBUG: Wither");
// Check the location
if (mobSpawnInfo.containsKey(e.getEntity())) {
// We know about this wither
if (DEBUG) {
plugin.getLogger().info("DEBUG: We know about this wither");
}
if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) {
// Cancel the explosion
if (DEBUG) {
plugin.getLogger().info("DEBUG: cancelling wither pre-explosion");
}
e.setCancelled(true);
}
}
// Testing only e.setCancelled(true);
}
if (e.getEntityType() == EntityType.WITHER_SKULL) {
//plugin.getLogger().info("DEBUG: Wither skull");
// Get shooter
Projectile projectile = (Projectile)e.getEntity();
if (projectile.getShooter() instanceof Wither) {
//plugin.getLogger().info("DEBUG: shooter is wither");
Wither wither = (Wither)projectile.getShooter();
// Check the location
if (mobSpawnInfo.containsKey(wither)) {
// We know about this wither
if (DEBUG) {
plugin.getLogger().info("DEBUG: We know about this wither");
}
if (!mobSpawnInfo.get(wither).inIslandSpace(e.getEntity().getLocation())) {
if (!mobSpawnInfo.get(wither).inIslandSpace(e.getEntity().getLocation())) {
// Cancel the explosion
if (DEBUG) {
plugin.getLogger().info("DEBUG: cancel wither skull explosion");
}
e.setCancelled(true);
}
}
@ -177,23 +141,14 @@ public class FlyingMobEvents implements Listener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void witherChangeBlocks(EntityChangeBlockEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Only cover withers in the island world
if (e.getEntityType() != EntityType.WITHER || !Util.inWorld(e.getEntity()) ) {
return;
}
if (mobSpawnInfo.containsKey(e.getEntity())) {
// We know about this wither
if (DEBUG) {
plugin.getLogger().info("DEBUG: We know about this wither");
}
if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) {
// Cancel the block changes
if (DEBUG) {
plugin.getLogger().info("DEBUG: cancelled wither block change");
}
e.setCancelled(true);
}
}

View File

@ -28,7 +28,6 @@ public class InventorySave {
* @param player - the player
*/
public void savePlayerInventory(Player player) {
//plugin.getLogger().info("DEBUG: Saving inventory");
// Save the player's armor and things
inventories.put(player.getUniqueId(),new InventoryStore(player.getInventory().getContents(), player.getInventory().getArmorContents()));
}
@ -38,7 +37,6 @@ public class InventorySave {
* @param player - the player
*/
public void clearSavedInventory(Player player) {
//plugin.getLogger().info("DEBUG: Clearing inventory");
inventories.remove(player.getUniqueId());
}
/**
@ -47,11 +45,9 @@ public class InventorySave {
* @param player - the player
*/
public void loadPlayerInventory(Player player) {
//plugin.getLogger().info("DEBUG: Loading inventory");
// Get the info for this player
if (inventories.containsKey(player.getUniqueId())) {
InventoryStore inv = inventories.get(player.getUniqueId());
//plugin.getLogger().info("DEBUG: player is known");
player.getInventory().setContents(inv.getInventory());
player.getInventory().setArmorContents(inv.getArmor());
inventories.remove(player.getUniqueId());

View File

@ -114,7 +114,6 @@ public final class AddonsManager {
// Open a reader to the jar
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
// Grab the description in the addon.yml file
//Map<String, String> data = data(reader);
YamlConfiguration data = new YamlConfiguration();
data.load(reader);
// Load the addon
@ -256,7 +255,6 @@ public final class AddonsManager {
continue;
}
//plugin.getLogger().info("DEBUG: jar filename = " + entry.getName());
if (entry.getName().endsWith(".yml")) {
result.add(entry.getName());
}

View File

@ -10,13 +10,9 @@ import us.tastybento.bskyblock.api.commands.CompositeCommand;
public final class CommandsManager {
private static final boolean DEBUG = false;
private HashMap<String, CompositeCommand> commands = new HashMap<>();
public void registerCommand(CompositeCommand command) {
if (DEBUG) {
Bukkit.getLogger().info("DEBUG: registering command - " + command.getLabel());
}
commands.put(command.getLabel(), command);
// Use reflection to obtain the commandMap method in Bukkit's server. It used to be visible, but isn't anymore.
try{

View File

@ -20,7 +20,6 @@ public class LocalesManager {
private BSkyBlock plugin;
private HashMap<Locale, BSBLocale> languages = new HashMap<>();
private static final String LOCALE_FOLDER = "locales";
private static final boolean DEBUG = false;
public LocalesManager(BSkyBlock plugin) {
this.plugin = plugin;
@ -51,26 +50,17 @@ public class LocalesManager {
* TODO: Make more robust. The file filter is fragile.
*/
public void loadLocales(String parent) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: loading locale for " + parent);
}
// Describe the filter - we only want files that are correctly named
FilenameFilter ymlFilter = (dir, name) -> {
// Files must be 9 chars long
if (name.toLowerCase().endsWith(".yml") && name.length() == 9) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: bsb locale filename = " + name);
}
return true;
return true;
}
return false;
};
// Run through the files and store the locales
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
if (DEBUG) {
plugin.getLogger().info("DEBUG: localeDir = " + localeDir.getAbsolutePath());
}
// If the folder does not exist, then make it and fill with the locale files from the jar
// If it does exist, then new files will NOT be written!
if (!localeDir.exists()) {
@ -82,9 +72,6 @@ public class LocalesManager {
// Get the last part of the name
int lastIndex = name.lastIndexOf('/');
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length()));
if (DEBUG) {
plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath());
}
copyFile(name, targetFile);
}
} catch (IOException e) {
@ -95,23 +82,11 @@ public class LocalesManager {
// Store all the locales available
for (File language : localeDir.listFiles(ymlFilter)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: parent = " + parent + " language = " + language.getName().substring(0, language.getName().length() - 4));
}
Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4));
if (DEBUG) {
plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry());
}
if (languages.containsKey(localeObject)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: this locale is known");
}
// Merge into current language
languages.get(localeObject).merge(language);
} else {
if (DEBUG) {
plugin.getLogger().info("DEBUG: this locale is not known - new language");
}
// New language
languages.put(localeObject, new BSBLocale(localeObject, language));
}

View File

@ -22,7 +22,6 @@ import us.tastybento.bskyblock.database.objects.Players;
public class PlayersManager{
private static final boolean DEBUG = false;
private BSkyBlock plugin;
private BSBDatabase<Players> handler;
@ -51,13 +50,7 @@ public class PlayersManager{
public void load(){
playerCache.clear();
inTeleport.clear();
try {
for (Players player : handler.loadObjects()) {
playerCache.put(player.getPlayerUUID(), player);
}
} catch (Exception e) {
plugin.getLogger().severe("Could not load players from the database!" + e.getMessage());
}
handler.loadObjects().forEach(p -> playerCache.put(p.getPlayerUUID(), p));
}
/**
@ -65,35 +58,12 @@ public class PlayersManager{
* @param async - if true, save async
*/
public void save(boolean async){
if (DEBUG) {
plugin.getLogger().info("DEBUG: saving " + async);
}
Collection<Players> set = Collections.unmodifiableCollection(playerCache.values());
if(async){
Runnable save = () -> {
for(Players player : set){
if (DEBUG) {
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
}
try {
handler.saveObject(player);
} catch (Exception e) {
plugin.getLogger().severe("Could not save player " + player.getPlayerName() + " "+ player.getUniqueId() + " " + e.getMessage());
}
}
};
if(async) {
Runnable save = () -> set.forEach(handler::saveObject);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save);
} else {
for(Players player : set){
if (DEBUG) {
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
}
try {
handler.saveObject(player);
} catch (Exception e) {
plugin.getLogger().severe("Could not save player " + player.getPlayerName() + " "+ player.getUniqueId() + " " + e.getMessage());
}
}
set.forEach(handler::saveObject);
}
}
@ -122,37 +92,16 @@ public class PlayersManager{
if (playerUUID == null) {
return;
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding player " + playerUUID);
}
if (!playerCache.containsKey(playerUUID)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: player not in cache");
}
Players player = null;
// If the player is in the database, load it, otherwise create a new player
if (handler.objectExists(playerUUID.toString())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: player in database");
}
try {
player = handler.loadObject(playerUUID.toString());
} catch (Exception e) {
plugin.getLogger().severe("Could not load player " + playerUUID + " " + e.getMessage());
}
} else {
if (DEBUG) {
plugin.getLogger().info("DEBUG: new player");
}
player = new Players(plugin, playerUUID);
}
playerCache.put(playerUUID, player);
return;
} else {
if (DEBUG) {
plugin.getLogger().info("DEBUG: known player");
}
return;
}
}
@ -171,9 +120,7 @@ public class PlayersManager{
* Saves all players on the server and clears the cache
*/
public void removeAllPlayers() {
for (UUID pl : playerCache.keySet()) {
save(pl);
}
playerCache.keySet().forEach(this::save);
playerCache.clear();
}
@ -244,7 +191,6 @@ public class PlayersManager{
public void setHomeLocation(UUID playerUUID, Location location, int number) {
addPlayer(playerUUID);
playerCache.get(playerUUID).setHomeLocation(location,number);
//this.save(true);
}
/**
@ -255,7 +201,6 @@ public class PlayersManager{
public void setHomeLocation(UUID playerUUID, Location location) {
addPlayer(playerUUID);
playerCache.get(playerUUID).setHomeLocation(location,1);
//this.save(true);
}
/**
@ -319,9 +264,6 @@ public class PlayersManager{
* @param user - the User
*/
public void setPlayerName(User user) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: Setting player name to " + user.getName() + " for " + user.getUniqueId());
}
addPlayer(user.getUniqueId());
playerCache.get(user.getUniqueId()).setPlayerName(user.getName());
}
@ -334,16 +276,10 @@ public class PlayersManager{
* @return String - playerName
*/
public String getName(UUID playerUUID) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: Geting player name");
}
if (playerUUID == null) {
return "";
}
addPlayer(playerUUID);
if (DEBUG) {
plugin.getLogger().info("DEBUG: name is " + playerCache.get(playerUUID).getPlayerName());
}
return playerCache.get(playerUUID).getPlayerName();
}

View File

@ -21,8 +21,6 @@ import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;
public class IslandCache {
private static final boolean DEBUG2 = false;
private static final boolean DEBUG = false;
private BSkyBlock plugin = BSkyBlock.getInstance();
private BiMap<Location, Island> islandsByLocation;
/**
@ -43,17 +41,8 @@ public class IslandCache {
*/
public void addIsland(Island island) {
islandsByLocation.put(island.getCenter(), island);
if (DEBUG) {
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
}
islandsByUUID.put(island.getOwner(), island);
if (DEBUG) {
plugin.getLogger().info("DEBUG: island has " + island.getMemberSet().size() + " members");
}
for (UUID member: island.getMemberSet()) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: " + member);
}
islandsByUUID.put(member, island);
}
addToGrid(island);
@ -69,14 +58,8 @@ public class IslandCache {
*/
private void addToGrid(Island newIsland) {
if (islandGrid.containsKey(newIsland.getMinX())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: min x is in the grid :" + newIsland.getMinX());
}
TreeMap<Integer, Island> zEntry = islandGrid.get(newIsland.getMinX());
if (zEntry.containsKey(newIsland.getMinZ())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: min z is in the grid :" + newIsland.getMinZ());
}
// Island already exists
Island conflict = islandGrid.get(newIsland.getMinX()).get(newIsland.getMinZ());
plugin.getLogger().warning("*** Duplicate or overlapping islands! ***");
@ -99,18 +82,11 @@ public class IslandCache {
return;
} else {
// Add island
if (DEBUG) {
plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ());
}
zEntry.put(newIsland.getMinZ(), newIsland);
islandGrid.put(newIsland.getMinX(), zEntry);
// plugin.getLogger().info("Debug: " + newIsland.toString());
}
} else {
// Add island
if (DEBUG) {
plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ());
}
TreeMap<Integer, Island> zEntry = new TreeMap<>();
zEntry.put(newIsland.getMinZ(), newIsland);
islandGrid.put(newIsland.getMinX(), zEntry);
@ -145,9 +121,6 @@ public class IslandCache {
* @param owner - the island owner UUID
*/
public Island createIsland(Location location, UUID owner){
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location);
}
Island island = new Island(location, owner, plugin.getSettings().getIslandProtectionRange());
islandsByLocation.put(location, island);
if (owner != null) {
@ -173,31 +146,15 @@ public class IslandCache {
}
}
// Remove from grid
if (DEBUG) {
plugin.getLogger().info("DEBUG: deleting island at " + island.getCenter());
}
if (island != null) {
int x = island.getMinX();
int z = island.getMinZ();
if (DEBUG) {
plugin.getLogger().info("DEBUG: x = " + x + " z = " + z);
}
if (islandGrid.containsKey(x)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: x found");
}
TreeMap<Integer, Island> zEntry = islandGrid.get(x);
if (zEntry.containsKey(z)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: z found - deleting the island");
}
// Island exists - delete it
zEntry.remove(z);
islandGrid.put(x, zEntry);
} else {
if (DEBUG) {
plugin.getLogger().info("DEBUG: could not find z");
}
}
}
}
@ -229,10 +186,6 @@ public class IslandCache {
* @return Island or null
*/
public Island getIslandAt(int x, int z) {
if (DEBUG2) {
plugin.getLogger().info("DEBUG: getting island at " + x + "," + z);
plugin.getLogger().info("DEBUG: island grid is " + islandGrid.size());
}
Entry<Integer, TreeMap<Integer, Island>> en = islandGrid.floorEntry(x);
if (en != null) {
Entry<Integer, Island> ent = en.getValue().floorEntry(z);
@ -240,14 +193,8 @@ public class IslandCache {
// Check if in the island range
Island island = ent.getValue();
if (island.inIslandSpace(x, z)) {
if (DEBUG2) {
plugin.getLogger().info("DEBUG: In island space");
}
return island;
}
if (DEBUG2) {
plugin.getLogger().info("DEBUG: not in island space");
}
}
}
return null;
@ -262,12 +209,10 @@ public class IslandCache {
*/
public Island getIslandAt(Location location) {
if (location == null) {
//plugin.getLogger().info("DEBUG: location is null");
return null;
}
// World check
if (!Util.inWorld(location)) {
//plugin.getLogger().info("DEBUG: not in right world");
return null;
}
return getIslandAt(location.getBlockX(), location.getBlockZ());
@ -327,52 +272,20 @@ public class IslandCache {
* @return true if player has island and owns it
*/
public boolean hasIsland(UUID playerUUID) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: checking if " + playerUUID + " has an island");
plugin.getLogger().info("DEBUG: islandsByUUID : " + islandsByUUID.toString());
if (!islandsByUUID.containsKey(playerUUID)) {
plugin.getLogger().info("DEBUG: player is not in islandsByUUID");
} else {
plugin.getLogger().info("DEBUG: owner = " + islandsByUUID.get(playerUUID).getOwner());
}
}
if (islandsByUUID.containsKey(playerUUID) && islandsByUUID.get(playerUUID).getOwner() != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: checking for equals");
}
if (islandsByUUID.get(playerUUID).getOwner().equals(playerUUID)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: has island");
}
return true;
}
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: doesn't have island");
}
return false;
return (islandsByUUID.containsKey(playerUUID) && islandsByUUID.get(playerUUID).getOwner() != null
&& (islandsByUUID.get(playerUUID).getOwner().equals(playerUUID))) ? true : false;
}
public void removePlayer(UUID playerUUID) {
Island island = islandsByUUID.get(playerUUID);
if (island != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: island found");
}
if (island.getOwner() != null && island.getOwner().equals(playerUUID)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: player is the owner of this island");
}
// Clear ownership and members
island.getMembers().clear();
island.setOwner(null);
}
island.removeMember(playerUUID);
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: removing reference to island by UUID");
}
islandsByUUID.remove(playerUUID);
}

View File

@ -20,7 +20,6 @@ import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType;
*
*/
public class NewIsland {
private static final boolean DEBUG = false;
private BSkyBlock plugin;
private Island island;
private final Player player;
@ -92,51 +91,25 @@ public class NewIsland {
* Makes an island.
*/
public void newIsland() {
if (DEBUG) {
plugin.getLogger().info("DEBUG: new island");
}
//long time = System.nanoTime();
final UUID playerUUID = player.getUniqueId();
/*
boolean firstTime = false;
if (!plugin.getPlayers().hasIsland(playerUUID)) {
firstTime = true;
}*/
if (DEBUG) {
plugin.getLogger().info("DEBUG: finding island location");
}
Location next = getNextIsland();
if (DEBUG) {
plugin.getLogger().info("DEBUG: found " + next);
}
// Add to the grid
island = plugin.getIslands().createIsland(next, playerUUID);
// Save the player so that if the server is reset weird things won't happen
//plugin.getPlayers().save(true);
//plugin.getIslands().save(true);
// Clear any old home locations (they should be clear, but just in case)
plugin.getPlayers().clearHomeLocations(playerUUID);
// Set the biome
//BiomesPanel.setIslandBiome(next, schematic.getBiome());
// Set home loction
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
// Fire event
if (DEBUG) {
plugin.getLogger().info("DEBUG: firing event");
}
IslandBaseEvent event = IslandEvent.builder()
.involvedPlayer(player.getUniqueId())
.reason(reason)
.island(island)
.location(island.getCenter())
.build();
if (DEBUG) {
plugin.getLogger().info("DEBUG: event cancelled status = " + event.isCancelled());
}
if (!event.isCancelled()) {
// Create island
new IslandBuilder(plugin, island)
@ -187,31 +160,16 @@ public class NewIsland {
*/
private Location getNextIsland() {
Location last = plugin.getIslands().getLast();
if (DEBUG) {
plugin.getLogger().info("DEBUG: last = " + last);
// Find the next free spot
}
if (last == null) {
last = new Location(plugin.getIslandWorldManager().getIslandWorld(), plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(),
plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ());
}
Location next = last.clone();
if (DEBUG) {
plugin.getLogger().info("DEBUG: last 2 = " + last);
}
while (plugin.getIslands().isIsland(next)) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: getting next loc");
}
next = nextGridLocation(next);
}
// Make the last next, last
last = next.clone();
if (DEBUG) {
plugin.getLogger().info("DEBUG: last 3 = " + last);
}
return next;
}

View File

@ -24,7 +24,6 @@ public class DeleteIslandChunks {
* @param island
*/
public DeleteIslandChunks(final BSkyBlock plugin, final Island island) {
//plugin.getLogger().info("DEBUG: deleting the island");
// Fire event
IslandBaseEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
if (event.isCancelled()) {

View File

@ -74,7 +74,6 @@ public class FileLister{
continue;
}
//plugin.getLogger().info("DEBUG: jar filename = " + entry.getName());
if (entry.getName().endsWith(".yml")) {
result.add(entry.getName());
}
@ -119,7 +118,6 @@ public class FileLister{
continue;
}
//plugin.getLogger().info("DEBUG: jar filename = " + entry.getName());
if (entry.getName().endsWith(".yml")) {
result.add(entry.getName());
}

View File

@ -66,7 +66,6 @@ public class HeadGetter {
requester.setHead(panelItem);
} else {
// Get the name
//Bukkit.getLogger().info("DEBUG:Not in cache. Adding");
headRequesters.putIfAbsent(panelItem.getName(), new HashSet<>());
Set<HeadRequester> requesters = headRequesters.get(panelItem.getName());
requesters.add(requester);