/** * Creates the world and the tower of SkyBlock. * * @return world instance of SkyBlock */ public World getSkyBlockWorld() { if (this.skyBlockWorld == null) { boolean folderExists = new File(SkyBlockMultiplayer.getInstance().settings.getWorldName()).exists(); this.skyBlockWorld = WorldCreator.name(this.settings.getWorldName()) .type(WorldType.FLAT) .environment(Environment.NORMAL) .generator(new SkyBlockChunkGenerator()) .createWorld(); if (!folderExists) { File f = new File(this.settings.getIslandSchematic()); if (f.exists() && f.isFile()) { try { CreateIsland.createStructure( new Location(getSkyBlockWorld(), 0, this.settings.getTowerYPosition(), 0), f); this.skyBlockWorld.setSpawnLocation(0, this.skyBlockWorld.getHighestBlockYAt(0, 0), 0); return this.skyBlockWorld; } catch (Exception e) { e.printStackTrace(); SpawnTower.createSpawnTower(); this.skyBlockWorld.setSpawnLocation(1, this.skyBlockWorld.getHighestBlockYAt(1, 1), 1); return this.skyBlockWorld; } } f = new File( SkyBlockMultiplayer.getInstance().getDataFolder(), this.settings.getTowerSchematic()); if (f.exists() && f.isFile()) { try { CreateIsland.createStructure( new Location(getSkyBlockWorld(), 0, this.settings.getTowerYPosition(), 0), f); this.skyBlockWorld.setSpawnLocation(0, this.skyBlockWorld.getHighestBlockYAt(0, 0), 0); return this.skyBlockWorld; } catch (Exception e) { e.printStackTrace(); SpawnTower.createSpawnTower(); this.skyBlockWorld.setSpawnLocation(1, this.skyBlockWorld.getHighestBlockYAt(1, 1), 1); return this.skyBlockWorld; } } SpawnTower.createSpawnTower(); this.skyBlockWorld.setSpawnLocation(1, this.skyBlockWorld.getHighestBlockYAt(1, 1), 1); return this.skyBlockWorld; } } return this.skyBlockWorld; }
/** Loads the language file, that is setted in conig.yml */ public void loadLanguageConfig() throws Exception { if (!new File(this.getDataFolder() + File.separator + "language").exists()) { new File(this.getDataFolder() + File.separator + "language").mkdirs(); } String encoding = "UTF-8"; if (!this.fileLanguage.exists()) { this.fileLanguage.createNewFile(); // create file this.writeLanguageConfig(); // write standard language } else { Scanner scanner = new Scanner(new FileInputStream(this.fileLanguage), encoding); String contentToRead = ""; while (scanner.hasNextLine()) { contentToRead += scanner.nextLine() + System.getProperty("line.separator"); } scanner.close(); try { this.configLanguage.loadFromString(contentToRead); } catch (InvalidConfigurationException e) { encoding = "Cp1252"; scanner = new Scanner(new FileInputStream(this.fileLanguage), encoding); contentToRead = ""; while (scanner.hasNextLine()) { contentToRead += scanner.nextLine() + System.getProperty("line.separator"); } scanner.close(); this.configLanguage.loadFromString(contentToRead); } boolean missing = false; for (Language g : Language.values()) { String path = g.getPath(); if (!this.configLanguage.contains(path)) { this.configLanguage.set(path, g.getSentence()); missing = true; } else { g.setSentence(this.replaceColor(this.configLanguage.getString(path))); } } if (missing) { String contentToSave = this.configLanguage.saveToString(); Writer out = new OutputStreamWriter(new FileOutputStream(this.fileLanguage), encoding); out.write(contentToSave); out.flush(); out.close(); } } SkyBlockMultiplayer.getInstance().getSkyBlockWorld(); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerTeleport(PlayerTeleportEvent event) { Player player = event.getPlayer(); if (!Settings.skyBlockOnline) { return; } if (!event .getFrom() .getWorld() .getName() .equalsIgnoreCase(SkyBlockMultiplayer.getSkyBlockWorld().getName()) && event .getTo() .getWorld() .getName() .equalsIgnoreCase((SkyBlockMultiplayer.getSkyBlockWorld().getName()))) { if (!SkyBlockMultiplayer.getInstance().locationIsOnTower(event.getTo())) { event.setCancelled(true); player.sendMessage(Language.MSGS_ONLY_INSIDE_OF_SB.sentence); return; } } PlayerInfo pi = Settings.players.get(player.getName()); if (event.getCause().equals(TeleportCause.ENDER_PEARL)) { if (this.plugin.locationIsOnTower(event.getTo())) { event.setCancelled(true); return; } if (Settings.build_withProtectedArea) { if (SkyBlockMultiplayer.canPlayerDoThat(pi, event.getTo())) { return; } PlayerInfo owner = SkyBlockMultiplayer.getOwner(event.getTo()); if (owner == null) { event.setCancelled(true); return; } if (owner.getFriends().contains(player.getName())) { return; } event.setCancelled(true); return; } } if (event .getFrom() .getWorld() .getName() .equalsIgnoreCase(SkyBlockMultiplayer.getSkyBlockWorld().getName()) && !event .getTo() .getWorld() .getName() .equalsIgnoreCase(SkyBlockMultiplayer.getSkyBlockWorld().getName()) && !this.plugin.playerIsOnTower(player)) { event.setCancelled(true); player.sendMessage(this.plugin.pName + Language.MSGS_ONLY_ON_TOWER.sentence); } }