diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index 0d1e08c79..1f69a5c89 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -14,7 +14,6 @@ import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.managers.island.IslandsManager; import us.tastybento.bskyblock.generators.IslandWorld; import us.tastybento.bskyblock.listeners.JoinLeaveListener; -import us.tastybento.bskyblock.listeners.NetherPortals; import us.tastybento.bskyblock.listeners.PanelListener; import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.LocalesManager; @@ -130,7 +129,6 @@ public class BSkyBlock extends JavaPlugin implements BSModule { PluginManager manager = getServer().getPluginManager(); // Player join events manager.registerEvents(new JoinLeaveListener(this), this); - manager.registerEvents(new NetherPortals(this), this); manager.registerEvents(new PanelListener(this), this); } diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/User.java b/src/main/java/us/tastybento/bskyblock/api/commands/User.java index 9ce3f0d53..68cf7814d 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/User.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/User.java @@ -147,18 +147,23 @@ public class User { return sender.isOp(); } + public String getTranslation(String reference, String... variables) { + String translation = plugin.getLocalesManager().get(sender, reference); + if (variables.length > 1) { + for (int i = 0; i < variables.length; i+=2) { + translation.replace(variables[i], variables[i+1]); + } + } + return translation; + } + /** * Send a message to sender if message is not empty. Does not include color codes or spaces. * @param reference - language file reference * @param variables - CharSequence target, replacement pairs */ public void sendMessage(String reference, String... variables) { - String message = plugin.getLocalesManager().get(sender, reference); - if (variables.length > 1) { - for (int i = 0; i < variables.length; i+=2) { - message.replace(variables[i], variables[i+1]); - } - } + String message = getTranslation(reference, variables); if (!ChatColor.stripColor(message).trim().isEmpty()) { if (sender != null) { sender.sendMessage(message); diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java index 3d622084f..2f14ffdf5 100644 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -17,6 +17,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.material.Chest; import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings.GameType; import us.tastybento.bskyblock.database.objects.Island; @@ -478,8 +479,9 @@ public class IslandBuilder { blockToChange.setType(Material.SIGN_POST); if (this.playerUUID != null) { Sign sign = (Sign) blockToChange.getState(); + User user = User.getInstance(playerUUID); for (int i=0; i<4; i++) { - sign.setLine(i, BSkyBlock.getPlugin().getLocale(playerUUID).get("island.sign.line" + i).replace("[player]", playerName)); + sign.setLine(i, user.getTranslation("island.sign.line" + i, "[player]", playerName)); } ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); sign.update(); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java index 1caef8232..36fa2fbd6 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java @@ -39,7 +39,7 @@ public class JoinLeaveListener implements Listener { if (playerUUID == null) { return; } - User.getInstance(player); + User user = User.getInstance(player); if (plugin.getPlayers().isKnown(playerUUID)) { if (DEBUG) plugin.getLogger().info("DEBUG: known player"); @@ -76,7 +76,7 @@ public class JoinLeaveListener implements Listener { if (!currentIsland.getMembers().contains(playerUUID) && !player.hasPermission(Settings.PERMPREFIX + "mod.bypassprotect")) { if (DEBUG) plugin.getLogger().info("DEBUG: No bypass - teleporting"); - player.sendMessage(plugin.getLocale(player).get("locked.islandlocked")); + user.sendMessage("locked.islandlocked"); plugin.getIslands().homeTeleport(player); } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java deleted file mode 100644 index 02a0339e0..000000000 --- a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java +++ /dev/null @@ -1,278 +0,0 @@ -package us.tastybento.bskyblock.listeners; - -import java.util.UUID; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.World.Environment; -import org.bukkit.block.BlockState; -import org.bukkit.entity.Vehicle; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityPortalEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.world.StructureGrowEvent; - -import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.config.Settings; -import us.tastybento.bskyblock.database.managers.island.IslandsManager; -import us.tastybento.bskyblock.database.objects.Island; -import us.tastybento.bskyblock.database.objects.Island.SettingsFlag; -import us.tastybento.bskyblock.generators.IslandWorld; -import us.tastybento.bskyblock.island.builders.IslandBuilder; -import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; -import us.tastybento.bskyblock.util.SafeSpotTeleport; - -public class NetherPortals implements Listener { - private final BSkyBlock plugin; - private final static boolean DEBUG = true; - - public NetherPortals(BSkyBlock plugin) { - this.plugin = plugin; - } - - /** - * This handles non-player portal use - * Currently disables portal use by entities - * - * @param event - */ - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityPortal(EntityPortalEvent event) { - if (DEBUG) - plugin.getLogger().info("DEBUG: nether portal entity " + event.getFrom().getBlock().getType()); - // If the nether is disabled then quit immediately - if (!Settings.netherGenerate || IslandWorld.getNetherWorld() == null) { - return; - } - if (event.getEntity() == null) { - return; - } - if (event.getFrom() != null && event.getFrom().getBlock().getType().equals(Material.ENDER_PORTAL)) { - event.setCancelled(true); - // Same action for all worlds except the end itself - if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) { - if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) { - // The end exists - Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation(); - event.getEntity().teleport(end_place); - if (DEBUG) - plugin.getLogger().info("DEBUG: Result teleported " + event.getEntityType() + " to " + end_place); - return; - } - } - return; - } - Location currentLocation = event.getFrom().clone(); - String currentWorld = currentLocation.getWorld().getName(); - // Only operate if this is Island territory - if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether")) { - return; - } - // No entities may pass with the old nether - if (!Settings.netherIslands) { - event.setCancelled(true); - return; - } - // New nether - // Entities can pass only if there are adjoining portals - Location dest = event.getFrom().toVector().toLocation(IslandWorld.getIslandWorld()); - if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { - dest = event.getFrom().toVector().toLocation(IslandWorld.getNetherWorld()); - } - // Vehicles - if (event.getEntity() instanceof Vehicle) { - Vehicle vehicle = (Vehicle)event.getEntity(); - vehicle.eject(); - } - new SafeSpotTeleport(plugin, event.getEntity(), dest); - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerPortal(PlayerPortalEvent event) { - if (DEBUG) - plugin.getLogger().info("DEBUG: Player portal event - reason =" + event.getCause()); - UUID playerUUID = event.getPlayer().getUniqueId(); - // If the nether is disabled then quit immediately - if (!Settings.netherGenerate || IslandWorld.getNetherWorld() == null) { - return; - } - Location currentLocation = event.getFrom().clone(); - String currentWorld = currentLocation.getWorld().getName(); - if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether") - && !currentWorld.equalsIgnoreCase(Settings.worldName + "_the_end")) { - if (DEBUG) - plugin.getLogger().info("DEBUG: not right world"); - return; - } - // Check if player has permission - Island island = plugin.getIslands().getIslandAt(currentLocation); - // TODO: if ((island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PORTAL)) - if (island == null - || (island != null && !(island.getFlag(SettingsFlag.PORTAL) || island.getMembers().contains(event.getPlayer().getUniqueId())))) { - // Portals use is not allowed - if (DEBUG) - plugin.getLogger().info("DEBUG: Portal use not allowed"); - if (!event.getPlayer().hasPermission(Settings.PERMPREFIX + "mod.bypassprotect")) { - event.getPlayer().sendMessage(plugin.getLocale(event.getPlayer()).get("island.protected")); - event.setCancelled(true); - return; - } - } - // Determine what portal it is - switch (event.getCause()) { - case END_PORTAL: - if (DEBUG) - plugin.getLogger().info("DEBUG: End portal"); - // Same action for all worlds except the end itself - if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) { - if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) { - // The end exists - event.setCancelled(true); - Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation(); - if (IslandsManager.isSafeLocation(end_place)) { - event.getPlayer().teleport(end_place); - // event.getPlayer().sendBlockChange(end_place, - // end_place.getBlock().getType(),end_place.getBlock().getData()); - return; - } else { - event.getPlayer().sendMessage(plugin.getLocale(event.getPlayer()).get("warps.error.NotSafe")); - plugin.getIslands().homeTeleport(event.getPlayer()); - return; - } - } - } else { - event.setCancelled(true); - plugin.getIslands().homeTeleport(event.getPlayer()); - } - break; - case NETHER_PORTAL: - if (DEBUG) - plugin.getLogger().info("DEBUG: nether portal"); - // Get the home world of this player - World homeWorld = IslandWorld.getIslandWorld(); - Location home = plugin.getPlayers().getHomeLocation(event.getPlayer().getUniqueId()); - if (home != null) { - homeWorld = home.getWorld(); - } - if (!Settings.netherIslands) { - // Legacy action - if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { - // Going to Nether - if (homeWorld.getEnvironment().equals(Environment.NORMAL)) { - // Home world is over world - event.setTo(IslandWorld.getNetherWorld().getSpawnLocation()); - event.useTravelAgent(true); - } else { - // Home world is nether - going home - event.useTravelAgent(false); - Location dest = plugin.getIslands().getSafeHomeLocation(playerUUID,1); - if (dest != null) { - event.setTo(dest); - } else { - event.setCancelled(true); - new SafeSpotTeleport(plugin, event.getPlayer(), plugin.getIslands().getIslandLocation(playerUUID), 1); - } - } - } else { - // Going to Over world - if (homeWorld.getEnvironment().equals(Environment.NORMAL)) { - // Home world is over world - event.useTravelAgent(false); - Location dest = plugin.getIslands().getSafeHomeLocation(playerUUID,1); - if (dest != null) { - event.setTo(dest); - } else { - event.setCancelled(true); - new SafeSpotTeleport(plugin, event.getPlayer(), plugin.getIslands().getIslandLocation(playerUUID), 1); - } - } else { - // Home world is nether - event.setTo(IslandWorld.getIslandWorld().getSpawnLocation()); - event.useTravelAgent(true); - } - } - } else { - // Island Nether - if (DEBUG) - plugin.getLogger().info("DEBUG: Island nether"); - // Get location of the island where the player is at - if (island == null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: island is null"); - event.setCancelled(true); - return; - } - // Can go both ways now - Location overworldIsland = island.getCenter().toVector().toLocation(IslandWorld.getIslandWorld()); - Location netherIsland = island.getCenter().toVector().toLocation(IslandWorld.getNetherWorld()); - //Location dest = event.getFrom().toVector().toLocation(IslandWorld.getIslandWorld()); - if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) { - // Going to Nether - // Check that there is a nether island there. Due to legacy reasons it may not exist - if (DEBUG) - plugin.getLogger().info("DEBUG: island center = " + island.getCenter()); - if (netherIsland.getBlock().getType() != Material.BEDROCK) { - // Check to see if there is anything there - if (plugin.getIslands().bigScan(netherIsland, 20) == null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: big scan is null"); - plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName()); - new IslandBuilder(island) - .setPlayer(event.getPlayer()) - .setChestItems(Settings.chestItems) - .setType(IslandType.NETHER) - .build(); - } - } - if (DEBUG) - plugin.getLogger().info("DEBUG: Teleporting to " + event.getFrom().toVector().toLocation(IslandWorld.getNetherWorld())); - event.setCancelled(true); - // Teleport using the new safeSpot teleport - new SafeSpotTeleport(plugin, event.getPlayer(), netherIsland); - return; - } - // Going to the over world - if there isn't an island, do nothing - event.setCancelled(true); - // Teleport using the new safeSpot teleport - new SafeSpotTeleport(plugin, event.getPlayer(), overworldIsland); - } - break; - default: - break; - } - } - - /** - * Converts trees to gravel and glowstone - * - * @param e - */ - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onTreeGrow(final StructureGrowEvent e) { - if (DEBUG) - plugin.getLogger().info("DEBUG: " + e.getEventName()); - - if (!Settings.netherTrees) { - return; - } - if (!Settings.netherGenerate || IslandWorld.getNetherWorld() == null) { - return; - } - // Check world - if (!e.getLocation().getWorld().equals(IslandWorld.getNetherWorld())) { - return; - } - for (BlockState b : e.getBlocks()) { - if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) { - b.setType(Material.GRAVEL); - } else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) { - b.setType(Material.GLOWSTONE); - } - } - } - -} \ No newline at end of file