/TravelGates/src/com/ghomerr/travelgates/TravelGates.java
Java | 1684 lines | 1381 code | 263 blank | 40 comment | 218 complexity | 3779aabd0a42aef35dccb0fa4d469b51 MD5 | raw file
- package com.ghomerr.travelgates;
-
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FilenameFilter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Properties;
- import java.util.logging.Logger;
-
- import org.bukkit.ChatColor;
- import org.bukkit.Chunk;
- import org.bukkit.DyeColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.TreeSpecies;
- import org.bukkit.World;
- import org.bukkit.WorldCreator;
- import org.bukkit.block.BlockFace;
- import org.bukkit.command.PluginCommand;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
-
- import ru.tehkode.permissions.PermissionManager;
- import ru.tehkode.permissions.bukkit.PermissionsEx;
-
- import com.ghomerr.travelgates.constants.TravelGatesConstants;
- import com.ghomerr.travelgates.enums.TravelGatesCommands;
- import com.ghomerr.travelgates.enums.TravelGatesConfigurations;
- import com.ghomerr.travelgates.enums.TravelGatesOptions;
- import com.ghomerr.travelgates.enums.TravelGatesPermissionsNodes;
- import com.ghomerr.travelgates.enums.TravelGatesWorldType;
- import com.ghomerr.travelgates.listeners.TravelGatesCommandExecutor;
- import com.ghomerr.travelgates.listeners.TravelGatesPlayerListener;
- import com.ghomerr.travelgates.listeners.TravelGatesPortalListener;
- import com.ghomerr.travelgates.listeners.TravelGatesSignListener;
- import com.ghomerr.travelgates.messages.TravelGatesMessages;
- import com.ghomerr.travelgates.messages.TravelGatesMessagesManager;
- import com.ghomerr.travelgates.objects.TravelGatesOptionsContainer;
- import com.ghomerr.travelgates.objects.TravelGatesTeleportBlock;
- import com.ghomerr.travelgates.utils.TravelGatesUtils;
- import com.nijiko.permissions.PermissionHandler;
- import com.nijikokun.bukkit.Permissions.Permissions;
-
- public class TravelGates extends JavaPlugin
- {
- private static final Logger _LOGGER = Logger.getLogger(TravelGatesConstants.MINECRAFT);
-
- // Misc
- private boolean _pluginEnabled = false;
- private PluginManager _pm = null;
-
- // config
- private String _language = TravelGatesConstants.DEFAULT_LANGUAGE;
- private boolean _usePermissions = false;
- private boolean _teleportWithSign = true;
- private boolean _teleportWithPortal = false;
- private boolean _clearAllInventory = false;
- private boolean _protectAdminInventory = false;
- private boolean _autosave = false;
- private boolean _isDebugEnabled = false;
- private boolean _isDisplayTeleportMessage = true;
- private TravelGatesTeleportBlock _tpBlock = new TravelGatesTeleportBlock();
-
- // messages
- private TravelGatesMessagesManager _messages = null;
- private String _portalSignOnState = null;
- private String _portalSignOffState = null;
-
- // Cache
- private HashMap<String, String> _mapShortLocationsByDest = new HashMap<String, String>();
- private HashMap<String, Location> _mapLocationsByDest = new HashMap<String, Location>();
- private HashMap<String, String> _mapDestinationsByShortLoc = new HashMap<String, String>();
- private HashMap<String, TravelGatesOptionsContainer> _mapOptionsByDest = new HashMap<String, TravelGatesOptionsContainer>();
- private HashMap<String, Integer> _mapMaterialIdByName = new HashMap<String, Integer>();
- private HashMap<String, DyeColor> _mapDyeColorByName = new HashMap<String, DyeColor>();
- private HashMap<String, TreeSpecies> _mapTreeSpeciesByName = new HashMap<String, TreeSpecies>();
- private HashSet<String> _setAdditionalWorlds = new HashSet<String>();
-
- // Files and data
- private Properties _configData = new Properties();
- private File _configFile = null;
- private Properties _destinationsData = new Properties();
- private File _destinationsFile = null;
- private Properties _restrictionsData = new Properties();
- private File _restrictionsFile = null;
-
- // Permissions
- private boolean _useNativePermissions = false;
- private boolean _usePermissionsBukkit = false;
- private boolean _usePermissionsEx = false;
- private PermissionHandler _permHandler = null;
- private PermissionManager _permManager = null;
-
- // Listeners
- public TravelGatesPlayerListener playerListener = null;
- public TravelGatesPortalListener portalListener = null;
- public TravelGatesSignListener portalSignListener = null;
-
- // Constants
- private final String _tag = TravelGatesConstants.PLUGIN_TAG;
- private final String _debug = TravelGatesConstants.DEBUG_TAG;
-
- public void onEnable()
- {
- super.onEnable();
-
- // Must be done before loadXXX() methods !
- _pm = getServer().getPluginManager();
-
- // Load Configuration
- _pluginEnabled = loadConfiguration();
- if (_pluginEnabled)
- {
- // Must be loaded before loadConfiguration()
- _pluginEnabled = _pluginEnabled && loadAdditionalWorld();
- _pluginEnabled = _pluginEnabled && loadMessages();
- _pluginEnabled = _pluginEnabled && loadPermissions();
- _pluginEnabled = _pluginEnabled && loadDestinations();
- }
-
- if (!_pluginEnabled)
- {
- _LOGGER.severe(_tag + " Plugin loading failed. All commands are disabled.");
- }
- else
- {
- playerListener = new TravelGatesPlayerListener(this);
- portalListener = new TravelGatesPortalListener(this);
- portalSignListener = new TravelGatesSignListener(this);
-
- final TravelGatesCommandExecutor commandeExecutor = new TravelGatesCommandExecutor(this);
-
- // Register commands
- for (final String cmd : TravelGatesCommands.TRAVELGATES.list())
- {
- final PluginCommand pluginCmd = this.getCommand(cmd);
- if (pluginCmd != null)
- {
- pluginCmd.setExecutor(commandeExecutor);
- }
- else
- {
- _LOGGER.severe(_tag + " Command " + cmd + " could not be added.");
- }
- }
- }
-
- // End
- _LOGGER.info(_tag + " Plugin loading done. There are " + _mapShortLocationsByDest.size() + " destinations loaded.");
- }
-
- public void onDisable()
- {
- super.onDisable();
-
- saveAll();
-
- _LOGGER.info(_tag + " Plugin unloading done.");
- }
-
- public boolean saveConfiguration()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start saveConfiguration()");
- }
-
- boolean saveSuccess = saveFile(_configFile, _configData, TravelGatesConstants.CONFIG_FILE_NAME);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End saveConfiguration : " + saveSuccess);
- }
- return saveSuccess;
- }
-
- public boolean saveDestinations()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start saveDestinations()");
- }
-
- boolean saveSuccess = saveFile(_destinationsFile, _destinationsData, TravelGatesConstants.DEST_FILE_NAME);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End saveDestinations : " + saveSuccess);
- }
- return saveSuccess;
- }
-
- public boolean saveRestrictions()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start saveRestrictions()");
- }
-
- boolean saveSuccess = saveFile(_restrictionsFile, _restrictionsData, TravelGatesConstants.RESTRICTIONS_FILE_NAME);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End saveRestrictions : " + saveSuccess);
- }
- return saveSuccess;
- }
-
- public boolean saveData()
- {
- return saveDestinations() && saveRestrictions();
- }
-
- public boolean saveAll()
- {
- return saveConfiguration() && saveData();
- }
-
- private boolean saveFile(final File file, final Properties data, final String fileName)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start saveFile : " + fileName);
- }
-
- boolean ret = false;
-
- if (file != null && file.exists())
- {
- if (data != null && !data.isEmpty())
- {
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(file);
- }
- catch (final FileNotFoundException ex)
- {
- _LOGGER.severe(_tag + " File " + fileName + " not found. ");
- ex.printStackTrace();
- }
-
- try
- {
- data.store(out, null);
- out.close();
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End saveFile : " + true);
- }
- ret = true;
- }
- catch (final IOException ex)
- {
- _LOGGER.severe(_tag + " " + fileName + " file update failed !");
- ex.printStackTrace();
- }
- }
- else
- {
- _LOGGER.info(_tag + " No data to save in " + fileName);
- ret = true;
- }
- }
- else
- {
- _LOGGER.severe(_tag + " File " + fileName + " doesn't exist !");
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End saveFile : " + ret);
- }
- return ret;
- }
-
- public boolean isPluginEnabled()
- {
- return _pluginEnabled;
- }
-
- public void addDestination(final Player player, final String destination, final Location loc, final TravelGatesOptionsContainer container)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start addDestination(destination=" + destination + ", container=" + container + ", player=" + player + ")");
- }
-
- final String shortLoc = TravelGatesUtils.locationToShortString(loc);
- String fullLoc = TravelGatesUtils.locationToFullString(loc);
-
- final String lowerCaseDest = destination.toLowerCase();
-
- _mapShortLocationsByDest.put(lowerCaseDest, shortLoc);
- _mapLocationsByDest.put(lowerCaseDest, TravelGatesUtils.shortStringToLocation(shortLoc, getServer().getWorlds()));
- _mapDestinationsByShortLoc.put(shortLoc, lowerCaseDest);
-
- fullLoc = fullLoc + TravelGatesConstants.DELIMITER + container.getOptionsForData();
-
- _destinationsData.put(lowerCaseDest, fullLoc);
- if (container.has(TravelGatesOptions.RESTRICTION))
- {
- _restrictionsData.put(destination, container.getRestrictionsListString());
- }
-
- if (container.has(TravelGatesOptions.SAVE) || _autosave)
- {
- final boolean saved = saveData();
- if (saved)
- {
- player.sendMessage(ChatColor.GREEN + _messages.get(TravelGatesMessages.SAVE_DONE));
- }
- else
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.SAVE_FAILED));
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End addDestination");
- }
- }
-
- public Location getLocationFromPosition(final Player player, final Location playerLoc, final String position)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getLocationFromPosition(player=" + player + ", playerLoc=" + playerLoc + ", position=" + position + ")");
- }
-
- Location destinationLocation = null;
-
- if (TravelGatesUtils.stringIsBlank(position))
- {
- destinationLocation = playerLoc;
- }
- else
- {
- final String[] positionData = position.split(TravelGatesConstants.DELIMITER);
- final int numberOfItems = positionData.length;
-
- if (numberOfItems == 3)
- {
- try
- {
- final World world = player.getWorld();
-
- destinationLocation = TravelGatesUtils.getDestinationLocation(world, positionData, playerLoc,
- TravelGatesConstants.POSITION_WITHOUT_WORLD);
- }
- catch (final Throwable th)
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.WRONG_POSITION_VALUE));
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Exception caught : ");
- }
- th.printStackTrace();
- }
- }
- else if (numberOfItems == 4)
- {
- try
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " World name : " + positionData[0]);
- }
- final World world = getServer().getWorld(positionData[0]);
-
- destinationLocation = TravelGatesUtils.getDestinationLocation(world, positionData, playerLoc,
- TravelGatesConstants.POSITION_WITH_WORLD);
- }
- catch (final Throwable th)
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.WRONG_POSITION_VALUE));
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Exception caught : ");
- }
- th.printStackTrace();
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.WRONG_POSITION_VALUE));
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getLocationFromPosition : " + destinationLocation);
- }
-
- return destinationLocation;
- }
-
- public void deleteDestination(final String destination, final boolean save, final Player player)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start deleteDestination(destination=" + destination + ")");
- }
-
- final String lowerCaseDest = destination.toLowerCase();
-
- _destinationsData.remove(lowerCaseDest);
- _restrictionsData.remove(lowerCaseDest);
-
- _mapDestinationsByShortLoc.remove(_mapShortLocationsByDest.get(lowerCaseDest));
- _mapLocationsByDest.remove(lowerCaseDest);
- _mapShortLocationsByDest.remove(lowerCaseDest);
-
- _mapOptionsByDest.get(lowerCaseDest).clear();
- _mapOptionsByDest.remove(lowerCaseDest);
-
- if (save || _autosave)
- {
- final boolean saved = saveData();
- if (saved)
- {
- player.sendMessage(ChatColor.GREEN + _messages.get(TravelGatesMessages.SAVE_DONE));
- }
- else
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.SAVE_FAILED));
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End deleteDestination");
- }
- }
-
- public boolean hasDestination(final String destination)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start hasDestination(destination=" + destination + ")");
- }
-
- final boolean hasDest = _mapShortLocationsByDest.containsKey(destination.toLowerCase());
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End hasDestination : " + hasDest);
- }
-
- return hasDest;
- }
-
- public boolean hasLocation(final Location loc)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start hasLocation(loc=" + loc + ")");
- }
-
- final String shortLoc = TravelGatesUtils.locationToShortString(loc);
- final boolean hasLoc = hasShortLocation(shortLoc); // _shortLocations.containsValue(shortLoc);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End hasLocation : " + hasLoc);
- }
- return hasLoc;
- }
-
- public boolean hasShortLocation(final String shortLoc)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start hasShortLocation(loc=" + shortLoc + ")");
- }
-
- final boolean hasShortLoc = _mapDestinationsByShortLoc.containsKey(shortLoc);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End hasShortLocation : " + hasShortLoc);
- }
- return hasShortLoc;
- }
-
- public String getDestinationsList()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start destList()");
- }
-
- final StringBuilder strBuild = new StringBuilder();
-
- strBuild.append(_messages.get(TravelGatesMessages.AVAILABLE_DESTINATIONS));
-
- final int initLength = strBuild.length();
-
- for (final String dest : _mapShortLocationsByDest.keySet())
- {
- strBuild.append(" ").append(ChatColor.AQUA).append(dest).append(ChatColor.YELLOW).append(TravelGatesConstants.DELIMITER);
- }
-
- final int endLength = strBuild.length();
-
- if (initLength < endLength)
- {
- strBuild.deleteCharAt(endLength - 1);
- }
- else
- {
- strBuild.append(ChatColor.AQUA).append(_messages.get(TravelGatesMessages.NONE));
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End destList : " + strBuild.toString());
- }
-
- return strBuild.toString();
- }
-
- public String getRestrictionsList(final String destination)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start restrictionsList(destination=" + destination + ")");
- }
-
- final String lowerCaseDest = destination.toLowerCase();
-
- final StringBuilder strBuild = new StringBuilder();
-
- strBuild.append(_messages.get(TravelGatesMessages.RESTRICTED_DESTINATIONS_ARE, ChatColor.AQUA + lowerCaseDest + ChatColor.YELLOW));
-
- final int initLength = strBuild.length();
-
- final HashSet<String> restrictedDests = _mapOptionsByDest.get(destination).getRestrictionsList();
-
- if (restrictedDests != null)
- {
- for (final String dest : restrictedDests)
- {
- strBuild.append(" ").append(ChatColor.AQUA).append(dest).append(ChatColor.YELLOW).append(TravelGatesConstants.DELIMITER);
- }
- }
-
- final int endLength = strBuild.length();
-
- if (initLength < endLength)
- {
- strBuild.deleteCharAt(endLength - 1);
- }
- else
- {
- strBuild.append(ChatColor.AQUA).append(" ").append(_messages.get(TravelGatesMessages.ALL));
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End restrictionsList : " + strBuild.toString());
- }
-
- return strBuild.toString();
- }
-
- public String getDestinationsDetailsList()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start destDetailedList()");
- }
-
- final StringBuilder strBuild = new StringBuilder();
-
- strBuild.append(_messages.get(TravelGatesMessages.AVAILABLE_DESTINATIONS));
-
- final int initLength = strBuild.length();
-
- for (final String dest : _mapShortLocationsByDest.keySet())
- {
- strBuild.append(getDestinationDetails(dest));
- }
-
- final int endLength = strBuild.length();
-
- if (initLength == endLength)
- {
- strBuild.append(ChatColor.AQUA).append(_messages.get(TravelGatesMessages.NONE));
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End destDetailedList : " + strBuild.toString());
- }
-
- return strBuild.toString();
- }
-
- public String getDestinationDetails(final String dest)
- {
- final StringBuilder strBuild = new StringBuilder();
-
- if (strBuild.length() > 0)
- {
- strBuild.append(TravelGatesConstants.DELIMITER).append(" ");
- }
-
- final boolean inventoryCleared = getOptionOfDestination(dest, TravelGatesOptions.INVENTORY);
- final String msgInventory = (inventoryCleared) ? ChatColor.RED + _messages.get(TravelGatesMessages.INVENTORY_CLEAR) : ChatColor.GREEN
- + _messages.get(TravelGatesMessages.INVENTORY_KEEP);
-
- final boolean isAdminTP = getOptionOfDestination(dest, TravelGatesOptions.ADMINTP);
- final String msgAdmin = (isAdminTP) ? ChatColor.RED + _messages.get(TravelGatesMessages.ADMIN_TP) : ChatColor.GREEN
- + _messages.get(TravelGatesMessages.FREE_TP);
-
- final boolean isRestricted = getOptionOfDestination(dest, TravelGatesOptions.RESTRICTION);
- final String msgRestrictions = (isRestricted) ? ChatColor.RED + _messages.get(TravelGatesMessages.DEST_RESTRICTED) : ChatColor.GREEN
- + _messages.get(TravelGatesMessages.DEST_FREE);
-
- strBuild.append(ChatColor.AQUA).append(dest).append(ChatColor.YELLOW).append("=(").append(ChatColor.GREEN)
- .append(_mapShortLocationsByDest.get((String) dest).toLowerCase()).append(ChatColor.YELLOW).append(")[").append(msgAdmin)
- .append(ChatColor.YELLOW).append(TravelGatesConstants.DELIMITER).append(msgInventory).append(ChatColor.YELLOW)
- .append(TravelGatesConstants.DELIMITER).append(msgRestrictions).append(ChatColor.YELLOW).append("]");
-
- return strBuild.toString();
- }
-
- public String getCurrentConfiguration()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getCurrentConfiguration()");
- }
-
- final StringBuilder strBuild = new StringBuilder();
- strBuild.append(ChatColor.YELLOW).append(_messages.get(TravelGatesMessages.CURRENT_CONFIG));
-
- for (final Object o : _configData.keySet())
- {
- final String key = o.toString();
- final String value = _configData.getProperty(key);
- final Boolean boolValue = new Boolean(value);
-
- if (TravelGatesConfigurations.LANGUAGE.value().equalsIgnoreCase(key))
- {
- strBuild.append(" ").append(ChatColor.AQUA).append(TravelGatesConfigurations.LANGUAGE.value()).append(ChatColor.YELLOW).append("=")
- .append(ChatColor.WHITE).append(_language);
- }
- else if (TravelGatesConfigurations.TPBLOCK.value().equalsIgnoreCase(key))
- {
- strBuild.append(" ").append(ChatColor.AQUA).append(TravelGatesConfigurations.TPBLOCK.value()).append(ChatColor.YELLOW).append("=")
- .append(ChatColor.WHITE).append(_tpBlock);
- }
- else if (TravelGatesConfigurations.WORLDS.value().equalsIgnoreCase(key))
- {
- strBuild.append(" ").append(ChatColor.AQUA).append(TravelGatesConfigurations.WORLDS.value()).append(ChatColor.YELLOW).append("=")
- .append(ChatColor.WHITE).append(getListOfAdditionnalWorld());
- }
- else
- {
- strBuild.append(" ").append(ChatColor.AQUA).append(key).append(ChatColor.YELLOW).append("=")
- .append((boolValue.booleanValue()) ? ChatColor.GREEN : ChatColor.RED).append(value);
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getCurrentConfiguration : " + strBuild.toString());
- }
-
- return strBuild.toString();
- }
-
- public TravelGatesOptionsContainer getOptionsOfDestination(final String destination)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getOptionsOfDestination(destination=" + destination + ")");
- }
-
- final TravelGatesOptionsContainer container = _mapOptionsByDest.get(destination.toLowerCase());
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getOptionsOfDestination : " + container);
- }
-
- return container;
- }
-
- public boolean getOptionOfDestination(final String destination, final TravelGatesOptions option)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getOptionOfDestination(destination=" + destination + ", option=" + option + ")");
- }
-
- String lowerDest = null;
- boolean optionValue = false;
-
- try
- {
- lowerDest = destination.toLowerCase();
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Exception caught while getting lower case of destination : " + destination);
- th.printStackTrace();
- }
-
- if (lowerDest != null)
- {
- final TravelGatesOptionsContainer container = _mapOptionsByDest.get(lowerDest);
-
- optionValue = container.has(option);
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getOptionOfDestination : " + optionValue);
- }
-
- return optionValue;
- }
-
- public void setOptionOfDestination(final String destination, final TravelGatesOptions option, final boolean newValue)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start setOptionOfDestination(destination=" + destination + ", option=" + option + ", newValue=" + newValue + ")");
- }
-
- final TravelGatesOptionsContainer container = _mapOptionsByDest.get(destination.toLowerCase());
-
- container.set(option, newValue);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End setOptionOfDestination");
- }
- }
-
- public String getShortLoc(final String destination)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getShortLoc(destination=" + destination + ")");
- }
-
- final String shortLoc = _mapShortLocationsByDest.get(destination.toLowerCase());
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getShortLoc : " + shortLoc);
- }
-
- return shortLoc;
- }
-
- public Location getLocation(final String destination)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getLocation(destination=" + destination + ")");
- }
-
- final Location loc = _mapLocationsByDest.get(destination.toLowerCase());
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getLocation : " + loc);
- }
-
- return loc;
- }
-
- public String getFullLoc(final String destination)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getFullLoc(destination=" + destination + ")");
- }
-
- final String fullLoc = _destinationsData.getProperty(destination.toLowerCase());
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getFullLoc : " + fullLoc);
- }
-
- return fullLoc;
- }
-
- public String getDestination(final Location location)
- {
- String dest = null;
-
- final String shortLoc = TravelGatesUtils.locationToShortString(location);
-
- dest = getDestination(shortLoc);
-
- return dest;
- }
-
- public String getDestination(final String shortLoc)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start getDestination(shortLoc=" + shortLoc + ")");
- }
-
- String dest = null;
-
- dest = _mapDestinationsByShortLoc.get(shortLoc);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End getDestination : " + dest);
- }
-
- return dest;
- }
-
- public String getDestPattern()
- {
- return TravelGatesConstants.DESTINATION_NAME_PATTERN;
- }
-
- public boolean teleportPlayerToDest(final String dest, final Player player, final boolean destHasBeenChecked,
- final boolean ignorePlayerLocation, final String portalDestinationShortLoc)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start teleportPlayerToDest(dest=" + dest + ", player=" + player + ", destHasBeenChecked=" + destHasBeenChecked
- + ", ignorePlayerLocation=" + ignorePlayerLocation + ")");
- }
-
- final String destination = dest.toLowerCase();
-
- if (ignorePlayerLocation || destHasBeenChecked || hasDestination(destination))
- {
- final String fullLoc = getFullLoc(destination);
- final String shortLoc = getShortLoc(destination);
-
- if (getOptionOfDestination(destination, TravelGatesOptions.ADMINTP))
- {
- if (!hasPermission(player, TravelGatesPermissionsNodes.ADMINTP))
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.ONLY_ADMIN_TP));
- return false;
- }
- }
-
- final Location playerLocation = player.getLocation();
- final String playerShortLoc = TravelGatesUtils.locationToShortString(playerLocation);
-
- final boolean targetAndCurrentLocationAreDifferent = !shortLoc.equalsIgnoreCase(playerShortLoc);
- final boolean playerIsOnExistingDestination = hasShortLocation(playerShortLoc);
- boolean playerNotOnTeleportBlock = false;
-
- String nearestDestinationShortLocation = null;
-
- if (!ignorePlayerLocation)
- {
- if (playerIsOnExistingDestination || portalDestinationShortLoc != null)
- {
- if (portalDestinationShortLoc == null && _tpBlock.isEnabled() && !_tpBlock.isTPBlock(player.getWorld().getBlockAt(playerLocation).getRelative(BlockFace.DOWN)))
- {
- playerNotOnTeleportBlock = true;
- }
-
- if (playerIsOnExistingDestination)
- {
- nearestDestinationShortLocation = playerShortLoc;
- }
- else if (portalDestinationShortLoc != null)
- {
- nearestDestinationShortLocation = portalDestinationShortLoc;
- }
- }
- else
- {
- if (_tpBlock.isEnabled())
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info("#0 : Not on dest and tp block enabled");
- }
-
- final World currWorld = player.getWorld();
- if (_isDebugEnabled)
- {
- _LOGGER.info("#0-bis : currWorld = " + currWorld);
- _LOGGER.info("#0-ters : type block = " + currWorld.getBlockAt(playerLocation).getRelative(BlockFace.DOWN).getType());
- }
-
- playerNotOnTeleportBlock = !_tpBlock.isTPBlock(currWorld.getBlockAt(playerLocation).getRelative(BlockFace.DOWN));
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#1 : playerNotOnTeleportBlock = " + playerNotOnTeleportBlock);
- }
-
- if (!playerNotOnTeleportBlock)
- {
- // Search the locations in the current player's
- // world
- ArrayList<Location> rightWorldsList = new ArrayList<Location>();
- for (final Object key : _mapLocationsByDest.keySet())
- {
- final Location loc = _mapLocationsByDest.get(key);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#1bis : key = " + key + " ; playerLocation.getWorld()=" + playerLocation.getWorld()
- + " ; loc.getWorld()= " + loc.getWorld());
- }
-
- if (playerLocation.getWorld() == loc.getWorld())
- {
- rightWorldsList.add(loc);
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#2 : rightWorldsList size = " + rightWorldsList.size());
- }
-
- if (!rightWorldsList.isEmpty())
- {
- // Search the locations at the same height
- ArrayList<Location> rightHeightList = new ArrayList<Location>();
- for (final Location loc : rightWorldsList)
- {
- if (loc.getBlockY() == playerLocation.getBlockY())
- {
- rightHeightList.add(loc);
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#3 : rightHeightList size = " + rightHeightList.size());
- }
-
- if (!rightHeightList.isEmpty())
- {
- // Search the nearest destination from
- // the
- // Player's location
- Location nearestDestinationLocation = null;
- int lastMinX = TravelGatesConstants.MAX_COORDINATE;
- int lastMinZ = TravelGatesConstants.MAX_COORDINATE;
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#3-a : nearestDestinationLocation = " + nearestDestinationLocation);
- }
-
- for (final Location loc : rightHeightList)
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info("#3-b : loc = " + loc);
- }
-
- if (nearestDestinationLocation == null)
- {
- lastMinX = TravelGatesUtils.getCoordinateDiff(loc.getBlockX(), playerLocation.getBlockX());
- lastMinZ = TravelGatesUtils.getCoordinateDiff(loc.getBlockZ(), playerLocation.getBlockZ());
- nearestDestinationLocation = loc;
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#3-c : lastMinX = " + lastMinX + " ; lastMinZ = " + lastMinZ);
- }
- }
- else
- {
- final int xDiff = TravelGatesUtils.getCoordinateDiff(loc.getBlockX(), playerLocation.getBlockX());
- final int zDiff = TravelGatesUtils.getCoordinateDiff(loc.getBlockZ(), playerLocation.getBlockZ());
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#3-d : xDiff = " + xDiff + " ; zDiff = " + zDiff);
- _LOGGER.info("#3-e : lastMinX = " + lastMinX + " ; lastMinZ = " + lastMinZ);
- }
-
- if (xDiff + zDiff <= lastMinX + lastMinZ)
- {
- lastMinX = xDiff;
- lastMinZ = zDiff;
- nearestDestinationLocation = loc;
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#3-f : nearestDestinationLocation = " + nearestDestinationLocation);
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#4 : nearestDestinationLocation = " + nearestDestinationLocation);
- }
-
- if (nearestDestinationLocation != null)
- {
- int pX = playerLocation.getBlockX();
- int pZ = playerLocation.getBlockZ();
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#5 : pX = " + pX + " ; pZ = " + pZ);
- }
-
- final int dX = nearestDestinationLocation.getBlockX();
- final int dZ = nearestDestinationLocation.getBlockZ();
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#6 : dX = " + dX + " ; dZ = " + dZ);
- }
-
- int xDiff = TravelGatesUtils.getCoordinateDiff(dX, pX);
- int zDiff = TravelGatesUtils.getCoordinateDiff(dZ, pZ);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#7 : xDiff = " + xDiff + " ; zDiff = " + zDiff);
- }
-
- // The nearest destination is at 5
- // blocks max from the player
- if (xDiff <= TravelGatesConstants.MAX_TARGET_RANGE && zDiff <= TravelGatesConstants.MAX_TARGET_RANGE)
- {
- final int offsetX = ((pX - dX) > 0) ? -1 : 1;
- final int offsetZ = ((pZ - dZ) > 0) ? -1 : 1;
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#8 : offsetX = " + offsetX + " ; offsetZ = " + offsetZ);
- }
-
- final int heightOfBeneathBlock = playerLocation.getBlockY() - 1;
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#9 : heightOfBeneathBlock = " + heightOfBeneathBlock);
- }
-
- // Is blocks between player and
- // the
- // nearest destination are TP
- // blocks
- // ?
- while (xDiff > 0 && !playerNotOnTeleportBlock)
- {
- pX += offsetX;
- playerNotOnTeleportBlock = !_tpBlock.isTPBlock(currWorld.getBlockAt(pX, heightOfBeneathBlock, pZ));
- xDiff = TravelGatesUtils.getCoordinateDiff(dX, pX);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#10 : pX = " + pX + " ; xDiff = " + xDiff + " ; playerNotOnTeleportBlock = "
- + playerNotOnTeleportBlock);
- }
- }
-
- if (!playerNotOnTeleportBlock)
- {
- while (zDiff > 0 && !playerNotOnTeleportBlock)
- {
- pZ += offsetZ;
- playerNotOnTeleportBlock = !_tpBlock
- .isTPBlock(currWorld.getBlockAt(pX, heightOfBeneathBlock, pZ));
- zDiff = TravelGatesUtils.getCoordinateDiff(dZ, pZ);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#11 : pZ = " + pZ + " ; zDiff = " + zDiff + " ; playerNotOnTeleportBlock = "
- + playerNotOnTeleportBlock);
- }
- }
-
- // Get the short loc of the
- // nearest destination
- if (!playerNotOnTeleportBlock)
- {
- nearestDestinationShortLocation = TravelGatesUtils
- .locationToShortString(nearestDestinationLocation);
- }
- }
- }
- else
- {
- playerNotOnTeleportBlock = true;
- }
- }
- else
- {
- playerNotOnTeleportBlock = true;
- }
- }
- else
- {
- playerNotOnTeleportBlock = true;
- }
- }
- else
- {
- playerNotOnTeleportBlock = true;
- }
- }
- }
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#12 : playerNotOnTeleportBlock = " + playerNotOnTeleportBlock);
- _LOGGER.info("#13 : nearestDestinationShortLocation = " + nearestDestinationShortLocation);
- }
- if (_tpBlock.isEnabled() && playerNotOnTeleportBlock)
- {
- player.sendMessage(ChatColor.RED
- + _messages.get(TravelGatesMessages.NOT_STANDING_ON_TPBLOCK, ChatColor.YELLOW + _tpBlock.toString() + ChatColor.RED));
- return false;
- }
-
- if (ignorePlayerLocation || targetAndCurrentLocationAreDifferent
- && (nearestDestinationShortLocation != null || !playerNotOnTeleportBlock && _tpBlock.isEnabled()))
- {
- final String currentDest = _mapDestinationsByShortLoc.get(nearestDestinationShortLocation);
-
- if (_isDebugEnabled)
- {
- _LOGGER.info("#14 : currentDest = " + currentDest);
- }
-
- if (!ignorePlayerLocation)
- {
- if (currentDest != null && getOptionOfDestination(currentDest, TravelGatesOptions.RESTRICTION))
- {
- final TravelGatesOptionsContainer container = _mapOptionsByDest.get(currentDest);
-
- if (container != null && !container.isDestinationAllowed(destination))
- {
- player.sendMessage(ChatColor.RED
- + _messages.get(TravelGatesMessages.DESTINATION_IS_RESTRICTED, ChatColor.AQUA + currentDest + ChatColor.RED,
- ChatColor.AQUA + destination + ChatColor.RED));
- return false;
- }
- }
- else if (currentDest == null)
- {
- player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.NO_STANDING_ON_DESTINATION));
- return false;
- }
- }
-
- final Location targetLocation = TravelGatesUtils.fullStringToLocation(fullLoc, player.getServer().getWorlds());
-
- if (targetLocation.getWorld() != null)
- {
- player.teleport(targetLocation);
- }
- else
- {
- player.sendMessage(ChatColor.RED
- + _messages.get(TravelGatesMessages.TELEPORT_CANCELLED_WORLD_UNLOADED, ChatColor.AQUA + destination + ChatColor.RED));
- return false;
- }
-
- if (ignorePlayerLocation)
- {
- _LOGGER.info(_tag + " " + player.getName() + " has forced the travel from " + playerShortLoc + " to " + destination);
- }
- else
- {
- _LOGGER.info(_tag + " " + player.getName() + " has travelled from " + currentDest + " to " + destination);
- }
-
- final boolean inventoryCleared = getOptionOfDestination(destination, TravelGatesOptions.INVENTORY);
- // System.out.println("inventoryCleared=" + inventoryCleared + "; _protectAdminInventory=" + _protectAdminInventory
- // + "; perm=" + hasPermission(player, TravelGatesPermissionsNodes.PROTECTADMININV));
- if (!inventoryCleared || isProtectedInventory(player))
- {
- if (_isDisplayTeleportMessage)
- {
- player.sendMessage(ChatColor.YELLOW
- + _messages.get(TravelGatesMessages.YOU_ARE_ARRIVED_AT, ChatColor.AQUA + destination + ChatColor.YELLOW)
- + ChatColor.GREEN + _messages.get(TravelGatesMessages.INVENTORY_KEPT));
- }
- }
- else
- {
- String inventoryMessage = "";
- final PlayerInventory inventory = player.getInventory();
-
- if (_clearAllInventory)
- {
- inventory.setArmorContents(null);
- inventoryMessage = _messages.get(TravelGatesMessages.ALL_INVENTORY_LOST);
- }
- else
- {
- inventoryMessage = _messages.get(TravelGatesMessages.INVENTORY_LOST);
- }
-
- inventory.clear();
-
- if (_isDisplayTeleportMessage)
- {
- player.sendMessage(ChatColor.YELLOW
- + _messages.get(TravelGatesMessages.YOU_ARE_ARRIVED_AT, ChatColor.AQUA + destination + ChatColor.YELLOW) + ChatColor.RED
- + inventoryMessage);
- }
- }
-
- // If the arrival chunk is unloaded, it will be forced to load
- final Chunk arrivalChunk = player.getWorld().getChunkAt(targetLocation);
- if (!arrivalChunk.isLoaded())
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " The " + destination + "'s chunk was not loaded at " + targetLocation);
- }
-
- arrivalChunk.load();
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End teleportPlayerToDest : true");
- }
-
- return true;
- }
- else
- {
- if (!targetAndCurrentLocationAreDifferent)
- {
- player.sendMessage(ChatColor.RED
- + _messages.get(TravelGatesMessages.YOURE_ALREADY_AT, ChatColor.AQUA + destination + ChatColor.RED));
- }
- else if (!playerIsOnExistingDestination)
- {
- player.sendMessage(ChatColor.RED
- + _messages.get(TravelGatesMessages.YOU_CANT_GO_THERE, ChatColor.AQUA + destination + ChatColor.RED));
- }
- }
- }
- else
- {
- player.sendMessage(ChatColor.RED
- + _messages.get(TravelGatesMessages.DESTINATION_DOESNT_EXIST, ChatColor.AQUA + destination + ChatColor.RED));
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End teleportPlayerToDest : false");
- }
-
- return false;
- }
-
- public String getMessage(final TravelGatesMessages message, final String... vars)
- {
- return _messages.get(message, vars);
- }
-
- public boolean usePermissions()
- {
- return _usePermissions;
- }
-
- private boolean loadDestinations()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start loadDestinations()");
- }
-
- boolean ret = false;
- boolean isfileCreated = false;
-
- _destinationsFile = new File(TravelGatesConstants.PLUGIN_FILE_PATH);
-
- if (!_destinationsFile.exists())
- {
- try
- {
- final File rootDir = new File(TravelGatesConstants.PLUGIN_ROOT_PATH);
- isfileCreated = rootDir.mkdir();
-
- isfileCreated &= _destinationsFile.createNewFile();
- _destinationsFile.setReadable(true, false);
- _destinationsFile.setWritable(true, false);
- _destinationsFile.setExecutable(true, false);
- }
- catch (final IOException ioex)
- {
- _LOGGER.severe(_tag + " Destinations file creation failed !");
- ioex.printStackTrace();
- }
- }
- else
- {
- isfileCreated = true;
- }
-
- if (!isfileCreated)
- {
- _LOGGER.severe(_tag + " Destinations file creation failed !");
- }
- else
- {
- FileInputStream in = null;
- try
- {
- in = new FileInputStream(_destinationsFile);
- }
- catch (final FileNotFoundException ex)
- {
- _LOGGER.info(_tag + " Destinations file failed to be read : ");
- ex.printStackTrace();
- }
-
- if (in != null)
- {
- try
- {
- _destinationsData.load(in);
- in.close();
- }
- catch (final IOException ex)
- {
- _LOGGER.severe(_tag + " Error while reading the Destinations file.");
- ex.printStackTrace();
- }
-
- if (!_destinationsData.isEmpty())
- {
- for (final Object key : _destinationsData.keySet())
- {
- final String dest = String.valueOf(key).toLowerCase();
-
- final String fullString = _destinationsData.getProperty(dest);
- final String shortLoc = TravelGatesUtils.fullStringToShortString(fullString);
-
- _mapShortLocationsByDest.put(dest, shortLoc);
- _mapLocationsByDest.put(dest, TravelGatesUtils.shortStringToLocation(shortLoc, getServer().getWorlds()));
- _mapDestinationsByShortLoc.put(shortLoc, dest);
- final TravelGatesOptionsContainer container = new TravelGatesOptionsContainer(this, fullString.substring(1 + fullString
- .lastIndexOf(TravelGatesConstants.DELIMITER)));
- _mapOptionsByDest.put(dest, container);
- }
-
- loadRestrictions();
- }
-
- ret = true;
- }
- else
- {
- _LOGGER.info(_tag + " Destinations file could not be loaded.");
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End loadDestinations : " + ret);
- }
-
- return ret;
- }
-
- private void loadRestrictions()
- {
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " Start loadRestrictions()");
- }
-
- _restrictionsFile = new File(TravelGatesConstants.PLUGIN_RESTRICTIONS_FILE_PATH);
-
- if (_restrictionsFile.exists())
- {
- FileInputStream in = null;
- try
- {
- in = new FileInputStream(_restrictionsFile);
- }
- catch (final FileNotFoundException ex)
- {
- _LOGGER.info(_tag + " Restrictions file not found.");
- ex.printStackTrace();
- return;
- }
-
- if (in != null)
- {
- try
- {
- _restrictionsData.load(in);
- in.close();
- }
- catch (final IOException ex)
- {
- _LOGGER.severe(_tag + " Error while reading the Restrictions file.");
- ex.printStackTrace();
- }
-
- if (!_restrictionsData.isEmpty())
- {
- for (final Object key : _restrictionsData.keySet())
- {
- final String dest = String.valueOf(key).toLowerCase();
- final TravelGatesOptionsContainer optionsContainer = _mapOptionsByDest.get(dest);
-
- if (optionsContainer.has(TravelGatesOptions.RESTRICTION))
- {
- optionsContainer.setRestrictionsList(_restrictionsData.getProperty(dest));
- }
- }
- }
- }
- }
- else
- {
- _LOGGER.info(_tag + " Restrictions file not found. New file created with the name : " + TravelGatesConstants.RESTRICTIONS_FILE_NAME);
-
- try
- {
- _restrictionsFile.createNewFile();
- _restrictionsFile.setReadable(true, false);
- _restrictionsFile.setWritable(true, false);
- _restrictionsFile.setExecutable(true, false);
- }
- catch (final IOException e)
- {
- _LOGGER.severe(_tag + " Unable to create Restriction file: ");
- e.printStackTrace();
- }
- }
-
- if (_isDebugEnabled)
- {
- _LOGGER.info(_debug + " End loadRestrictions");
- }
- }
-
- private boolean loadConfiguration()
- {
- _configFile = new File(TravelGatesConstants.PLUGIN_CONFIG_PATH);
-
- if (_configFile.exists())
- {
- FileInputStream in = null;
- try
- {
- in = new FileInputStream(_configFile);
- }
- catch (final Throwable ex)
- {
- _LOGGER.severe(_tag + " Unable to create a stream to read the configuration file.");
- ex.printStackTrace();
- return false;
- }
-
- if (in != null)
- {
- // LOAD CONFIGURATIONS
- try
- {
- _configData.load(in);
- in.close();
- }
- catch (final IOException ex)
- {
- _LOGGER.severe(_tag + " Error while loading the Configuration file.");
- ex.printStackTrace();
- return false;
- }
-
- // DEBUG
- try
- {
- final String debugEnabled = _configData.getProperty(TravelGatesConfigurations.DEBUG.value());
-
- if (TravelGatesUtils.stringIsNotBlank(debugEnabled))
- {
- _isDebugEnabled = Boolean.parseBoolean(debugEnabled.toLowerCase());
- TravelGatesUtils.setDebugState(_isDebugEnabled);
- }
- else
- {
- _LOGGER.warning(_tag + " Debug configuration not found.");
- }
-
- _LOGGER.info(_tag + " Debug configuration set to : " + _isDebugEnabled);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Debug configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // DISPLAY TELEPORT MESSAGE
- try
- {
- final String displayTeleportMessage =
- _configData.getProperty(TravelGatesConfigurations.DISPLAYTELEPORTMESSAGE.value());
-
- if (TravelGatesUtils.stringIsNotBlank(displayTeleportMessage))
- {
- _isDisplayTeleportMessage = Boolean.parseBoolean(displayTeleportMessage.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Display teleport message configuration not found.");
- }
-
- _LOGGER.info(_tag + " Display teleport message configuration set to : " + _isDisplayTeleportMessage);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Display teleport message configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // LANGUAGE
- try
- {
- final String language = _configData.getProperty(TravelGatesConfigurations.LANGUAGE.value());
-
- if (TravelGatesUtils.stringIsNotBlank(language))
- {
- _language = language.toLowerCase();
- }
- else
- {
- _LOGGER.warning(_tag + " Language configuration not found.");
- }
-
- _LOGGER.info(_tag + " Language configuration set to : " + _language);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Language configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // USE PERMISSIONS
- try
- {
- final String usePermissions = _configData.getProperty(TravelGatesConfigurations.USEPERMISSIONS.value());
-
- if (TravelGatesUtils.stringIsNotBlank(usePermissions))
- {
- _usePermissions = Boolean.parseBoolean(usePermissions.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Permissions configuration not found.");
- }
-
- _LOGGER.info(_tag + " Permissions configuration set to : " + _usePermissions);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Permissions configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // TELEPORT MODES
- try
- {
- final String teleportWithSign = _configData.getProperty(TravelGatesConfigurations.TELEPORTWITHSIGN.value());
- final String teleportWithPortal = _configData.getProperty(TravelGatesConfigurations.TELEPORTWITHPORTAL.value());
-
- if (TravelGatesUtils.stringIsNotBlank(teleportWithSign))
- {
- _teleportWithSign = Boolean.parseBoolean(teleportWithSign.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Sign teleportation configuration not found.");
- }
-
- if (TravelGatesUtils.stringIsNotBlank(teleportWithPortal))
- {
- _teleportWithPortal = Boolean.parseBoolean(teleportWithPortal.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Portal teleportation configuration not found.");
- }
-
- _LOGGER.info(_tag + " Teleport modes configuration set to : sign=" + _teleportWithSign + ", portal=" + _teleportWithPortal);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Teleport modes configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // CLEAR ALL INVENTORY
- try
- {
- final String clearAllInventory = _configData.getProperty(TravelGatesConfigurations.CLEARALLINVENTORY.value());
-
- if (TravelGatesUtils.stringIsNotBlank(clearAllInventory))
- {
- _clearAllInventory = Boolean.parseBoolean(clearAllInventory.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Clear all inventory configuration not found.");
- }
-
- _LOGGER.info(_tag + " Clear all inventory configuration set to : " + _clearAllInventory);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Clear all inventory configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // PROTECT ADMIN INVENTORY
- try
- {
- final String protectAdminInventory =
- _configData.getProperty(TravelGatesConfigurations.PROTECTADMININVENTORY.value());
-
- if (TravelGatesUtils.stringIsNotBlank(protectAdminInventory))
- {
- _protectAdminInventory = Boolean.parseBoolean(protectAdminInventory.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Protect admin inventory configuration not found.");
- }
-
- _LOGGER.info(_tag + " Protect admin inventory configuration set to : " + _protectAdminInventory);
- }
- catch (final Throwable th)
- {
- _LOGGER.severe(_tag + " Protect admin inventory configuration reading failed.");
- th.printStackTrace();
- return false;
- }
-
- // AUTO SAVE
- try
- {
- final String autosave = _configData.getProperty(TravelGatesConfigurations.AUTOSAVE.value());
-
- if (TravelGatesUtils.stringIsNotBlank(autosave))
- {
- _autosave = Boolean.parseBoolean(autosave.toLowerCase());
- }
- else
- {
- _LOGGER.warning(_tag + " Autosav