コード例 #1
0
ファイル: BukkitServer.java プロジェクト: sct/BukkitForge
	@Override
	public PluginCommand getPluginCommand(String name) {
		Command command = commandMap.getCommand(name);

		if (command instanceof PluginCommand) {
			return (PluginCommand) command;
		} else {
			return null;
		}
	}
コード例 #2
0
ファイル: BukkitServer.java プロジェクト: sct/BukkitForge
	@Override
	public void reload() {
		bukkitConfig = YamlConfiguration.loadConfiguration(new File("bukkit.yml"));
		//

		if (theServer instanceof DedicatedServer) {
			PropertyManager config = new PropertyManager(theServer.getFile("server.properties"));
			((DedicatedServer) theServer).settings = config;
		}
		
		//

		boolean animals = theServer.getCanSpawnAnimals();
		boolean monsters = theServer.worldServerForDimension(0).difficultySetting > 0;
		int difficulty = theServer.worldServerForDimension(0).difficultySetting;

		//theServer.pro
		/*theServer.setOnlineMode(theServer.isServerInOnlineMode());
		theServer.setCanSpawnAnimals(config.getBooleanProperty("spawn-animals", theServer.getCanSpawnAnimals()));
		theServer.setAllowPvp(config.getBooleanProperty("pvp", theServer.isPVPEnabled()));
		theServer.setAllowFlight(config.getBooleanProperty("allow-flight", theServer.isFlightAllowed()));
		theServer.setMOTD(config.getProperty("motd", theServer.getMOTD()));*/
		monsterSpawn = bukkitConfig.getInt("spawn-limits.monsters");
		animalSpawn = bukkitConfig.getInt("spawn-limits.animals");
		waterAnimalSpawn = bukkitConfig.getInt("spawn-limits.water-animals");
		warningState = WarningState.value(bukkitConfig.getString("settings.deprecated-verbose"));
		// = bukkitConfig.getInt("ticks-per.autosave");

		for (WorldServer world : theServer.worldServers) {
			world.difficultySetting = difficulty;
			world.spawnHostileMobs = monsters;
			world.spawnPeacefulMobs = animals;
			/*if (this.getTicksPerAnimalSpawns() < 0) {
	                world.ticksPerAnimalSpawns = 400;
	            } else {
	                world.ticksPerAnimalSpawns = this.getTicksPerAnimalSpawns();
	            }

	            if (this.getTicksPerMonsterSpawns() < 0) {
	                world.ticksPerMonsterSpawns = 1;
	            } else {
	                world.ticksPerMonsterSpawns = this.getTicksPerMonsterSpawns();
	            }*/
		}

		pluginManager.clearPlugins();
		commandMap.clearCommands();
		resetRecipes();

		int pollCount = 0;

		// Wait for at most 2.5 seconds for plugins to close their threads
		while (pollCount < 50 && getScheduler().getActiveWorkers().size() > 0) {
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {}
			pollCount++;
		}

		List<BukkitWorker> overdueWorkers = getScheduler().getActiveWorkers();
		for (BukkitWorker worker : overdueWorkers) {
			Plugin plugin = worker.getOwner();
			String author = "<NoAuthorGiven>";
			if (plugin.getDescription().getAuthors().size() > 0) {
				author = plugin.getDescription().getAuthors().get(0);
			}
			getLogger().log(Level.SEVERE, String.format(
					"Nag author: '%s' of '%s' about the following: %s",
					author,
					plugin.getDescription().getName(),
					"This plugin is not properly shutting down its async tasks when it is being reloaded.  This may cause conflicts with the newly loaded version of the plugin"
					));
		}
		loadPlugins();
		enablePlugins(PluginLoadOrder.STARTUP);
		enablePlugins(PluginLoadOrder.POSTWORLD);

	}
コード例 #3
0
ファイル: BukkitServer.java プロジェクト: sct/BukkitForge
	public BukkitServer(MinecraftServer server) {
		instance = this;
		cbBuild = BukkitContainer.CRAFT_VERSION;
		configMan = server.getConfigurationManager();
		theServer = server;
		List<Integer> ids = Arrays.asList(DimensionManager.getIDs());
		Iterator<Integer> _ = ids.iterator();

		System.out.println("IS THE INSTANCE NULL? " + (instance == null ? "YES" : "NO"));
		this.pluginManager = new SimplePluginManager(this, commandMap);
		
		//pluginManager = new SimplePluginManager(this, commandMap);
		bukkitConfig = new YamlConfiguration();
		YamlConfiguration yml = new YamlConfiguration();
		try {
			yml.load(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml"));
			if (!new File("bukkit.yml").exists()) {
				new File("bukkit.yml").createNewFile();
				yml.save("bukkit.yml");
			}
			bukkitConfig.load("bukkit.yml");
			bukkitConfig.addDefaults(yml);
			bukkitConfig.save("bukkit.yml");

		}
		catch (Exception e) {
			e.printStackTrace();
		}

		String vanillaName = theServer.worldServerForDimension(0).getWorldInfo().getWorldName();
		
		while(_.hasNext()) {
			int i = _.next();
			WorldServer x = theServer.worldServerForDimension(i);
			BukkitWorld world = new BukkitWorld(x, this.getGenerator(x.getWorldInfo().getDimension()), this.wtToEnv(x));
			worlds.put(i, world);
			//if (!x.getWorldInfo().getWorldName().equals(vanillaName))
				pluginWorldMapping.put(x.getWorldInfo().getWorldName(), world);
		}
		this.theLogger = BukkitContainer.bukkitLogger;
		theLogger.info("Bukkit API for Vanilla, version " + apiVer + " starting up...");
		thePluginLoader = new BukkitClassLoader(getClass().getClassLoader());
		
		// I MAINTAIN THAT THIS WILL WORK EVENTUALLY
		/*try {
			System.out.println("This is a test of the SPM Loader!");
			// this *should* load simplepluginamanger via BukkitClassLoader
			Class<?> pluginMan = thePluginLoader.loadClass("org.bukkit.plugin.SimplePluginManager");
			System.out.println("Loaded class: " + pluginMan.getCanonicalName() + " via " + pluginMan.getClassLoader().getClass().getCanonicalName());
			Method insn = pluginMan.getMethod("newInstance", new Class[] { BukkitServer.class, SimpleCommandMap.class });
			insn.setAccessible(true);
			this.pluginManager = (PluginManager) insn.invoke(null, this, this.commandMap);


		} catch (Exception e1) {
			throw new RuntimeException("BukkitForge encountered an error (most likely it  was installed incorrectly!)", e1);
		}*/
		Bukkit.setServer(this);
		this.theHelpMap = new SimpleHelpMap(this);
		this.theMessenger = new StandardMessenger();
		//theLogger.info("Testing the bukkit Logger!");
		this.entityMetadata = new EntityMetadataStore();
		this.playerMetadata = new PlayerMetadataStore();
		this.worldMetadata = new WorldMetadataStore();
		this.warningState = Warning.WarningState.DEFAULT;
		this.console = (BukkitConsoleCommandSender) BukkitConsoleCommandSender.getInstance();
		// wait until server start

		/*try {
			Thread.currentThread().wait();
		} catch (InterruptedException e) {
			theLogger.log(Level.FINE, "The server was interrupted, it might explode!", e);
		}*/
		theLogger.info("Completing load...");
		// fix for the 'mod recipes disappear' bug
		BukkitModRecipeHelper.saveCraftingManagerRecipes();
		//configMan = theServer.getConfigurationManager();
		//theServer = (DedicatedServer) server;
		HelpTopic myHelp = new CommandHelpTopic("bexec", "Run a command forcibly bukkit aliases", "", "");
		Bukkit.getServer().getHelpMap().addTopic(myHelp);
		
		loadPlugins();
		enablePlugins(PluginLoadOrder.STARTUP);

		theLogger.info("Loading PostWorld plugins...");
		enablePlugins(PluginLoadOrder.POSTWORLD);
		theLogger.info("Loaded plugins: ");
		for (Plugin i : pluginManager.getPlugins()) {
			theLogger.info(i.getName() + "- Enabled: " +  i.isEnabled());
		}
		ForgeEventHandler.ready = true;
		commandMap.doneLoadingPlugins((ServerCommandManager) theServer.getCommandManager());
		if (!theServer.isDedicatedServer()) {
			EntityPlayer par0 = theServer.getConfigurationManager().getPlayerForUsername(theServer.getServerOwner());
			if (par0 != null) {
				par0.sendChatToPlayer(ChatColor.GREEN + "BukkitForge has finished loading! You may now enjoy a (relatively) lag-free game!");
				theServer.getCommandManager().executeCommand(par0, "/plugins");
				(new PlayerTracker()).onPlayerLogin(par0);
			}

		}

	}