當前位置: 首頁>>代碼示例>>Java>>正文


Java Sponge類代碼示例

本文整理匯總了Java中org.spongepowered.api.Sponge的典型用法代碼示例。如果您正苦於以下問題:Java Sponge類的具體用法?Java Sponge怎麽用?Java Sponge使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Sponge類屬於org.spongepowered.api包,在下文中一共展示了Sponge類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onServerStart

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Listener
public void onServerStart(GameStartedServerEvent event) {
	instance = this;
	
	ConfigBuilder.configPath = Paths.get(configDir.toString(), "config.json");
	
	RText.impl(new RTextSponge());
	RColour.impl(new RColourSponge());
	Travellers.impl(new SpongeTravellers());
	
	CommandSpec camCommandSpec = CommandSpec.builder()
			.arguments(GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("cmd"))))
			.executor(new SpongeCommandManager())
			.build();

	Sponge.getCommandManager().register(this, camCommandSpec, "cam", "camerastudio");
}
 
開發者ID:redstone,項目名稱:RCameraStudio,代碼行數:18,代碼來源:RCameraStudioSponge.java

示例2: onServerInitialization

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Listener
public void onServerInitialization(GameInitializationEvent event)
{
    eagleFactions = this;

   //Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.AQUA, "EagleFactions is loading..."));
   Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.AQUA, "Preparing wings..."));

   SetupConfigs();

   Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.AQUA, "Configs loaded..."));

   InitializeCommands();

   Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.AQUA, "Commands loaded..."));

   RegisterListeners();

    //Display some info text in the console.
    Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.GREEN,"=========================================="));
    Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.AQUA, "EagleFactions", TextColors.WHITE, " is ready to use!"));
    Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.WHITE,"Thank you for choosing this plugin!"));
    Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.WHITE,"Current version: " + PluginInfo.Version));
    Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.WHITE,"Have a great time with EagleFactions! :D"));
    Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.GREEN,"=========================================="));
}
 
開發者ID:Aquerr,項目名稱:EagleFactions,代碼行數:27,代碼來源:EagleFactions.java

示例3: onAboutToStart

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Listener
public void onAboutToStart(GameAboutToStartServerEvent event) {
	if (!enabled)
		return;

	// Initialize configs
	config = new StickyChunkConfig();
	pluginConfigManager = new ConfigManager(configManager);
	pluginConfigManager.save();

	database = new SqliteDatabase();
	dataStore = new DataStore();
	ticketManager = new TicketManager();

	dataStore.addPlayerRegions(database.loadRegionData());
	dataStore.addUsers(database.loadUserData());

	logger.info("registering callback");

	// Register callbacks
	Sponge.getServer().getChunkTicketManager().registerCallback(this, new ChunkLoadCallback());

	// Register events
	Sponge.getGame().getEventManager().registerListeners(this, new PlayerConnectionListener());
	Sponge.getGame().getEventManager().registerListeners(this, new RegionAreaListener());
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:27,代碼來源:StickyChunk.java

示例4: validateSpongeVersion

import org.spongepowered.api.Sponge; //導入依賴的package包/類
private boolean validateSpongeVersion() {
	PluginContainer container = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION);
	if (container.getName().equals("SpongeForge")) {
		try {
			String version = container.getVersion().orElseThrow(Exception::new);
			version = version.substring(Math.max(version.length() - 4, 0));
			int spongeVersion = Integer.parseInt(version);
			if (spongeVersion < 2132) {
				this.logger.error(String.format("Failed to initialize StickyChunk due to outdated SpongeForge (%s). StickyChunk requires SF 2132+", spongeVersion));
				return false;
			}
		} catch (Exception ignored) {
		}
	}
	return true;
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:17,代碼來源:StickyChunk.java

示例5: performRemoval

import org.spongepowered.api.Sponge; //導入依賴的package包/類
private void performRemoval(LookupLine line) {
	World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
	if (w == null) return;
	
	if (line.getTarget() instanceof ItemType) {
		
		Optional<TileEntity> te = w.getTileEntity(line.getPos());
		if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
			TileEntityCarrier c = (TileEntityCarrier) te.get();
			Inventory i = c.getInventory();
			
			Inventory slot = i.query(new SlotIndex(line.getSlot()));
			slot.set(ItemStack.of(ItemTypes.NONE, 0));
		}
		
	} else if (line.getTarget() instanceof BlockType) {
		
		BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
		w.setBlock(line.getPos(), block, Cause.source(container).build());
		
	}
}
 
開發者ID:Karanum,項目名稱:AdamantineShield,代碼行數:23,代碼來源:RollbackManager.java

示例6: getDefaultGameMode

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Override
public GameMode getDefaultGameMode() {
    if (!Sponge.isServerAvailable()) {
        return GameMode.SURVIVAL;
    }
    Optional<WorldProperties>properties = Sponge.getServer().getDefaultWorld();
    if (!properties.isPresent()) {
        return GameMode.SURVIVAL;
    }
    org.spongepowered.api.entity.living.player.gamemode.GameMode gameMode = properties.get().getGameMode();

    if (gameMode == GameModes.SURVIVAL) {
        return GameMode.SURVIVAL;
    } else if (gameMode == GameModes.ADVENTURE) {
        return GameMode.ADVENTURE;
    } else if (gameMode == GameModes.CREATIVE) {
        return GameMode.CREATIVE;
    } else if (gameMode == GameModes.SPECTATOR) {
        return GameMode.SPECTATOR;
    }

    return GameMode.SURVIVAL; // Unimplemented gamemode's and NOT_SET
}
 
開發者ID:Proximyst,項目名稱:Bukkit2Sponge,代碼行數:24,代碼來源:FakeServer.java

示例7: releaseExample

import org.spongepowered.api.Sponge; //導入依賴的package包/類
public List<String> releaseExample()
{
    String defaultMenuDir = "menu/";
    File menuDir = this.plugin.getConfigDir().resolve(defaultMenuDir).toFile();
    if (menuDir.isDirectory() || menuDir.mkdirs())
    {
        try
        {
            AssetManager assetManager = Sponge.getAssetManager();
            Optional<Asset> example = assetManager.getAsset(this.plugin, "examples/example.conf");
            Optional<Asset> example2 = assetManager.getAsset(this.plugin, "examples/example2.conf");
            example.orElseThrow(IOException::new).copyToDirectory(menuDir.toPath());
            example2.orElseThrow(IOException::new).copyToDirectory(menuDir.toPath());
        }
        catch (IOException e)
        {
            this.logger.warn("Cannot extract default chest GUI configurations", e);
        }
    }
    return Collections.singletonList(defaultMenuDir);
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:22,代碼來源:VirtualChestInventoryDispatcher.java

示例8: clanCoordsCommand

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Command(name = "coords", description = "Посмотреть координаты ваших соклановцев", isPlayerOnly = true, isClanOnly = true, clanPermission = "coords", spongePermission = "mcclans.user.coords")
public void clanCoordsCommand(CommandSource commandSource, ClanPlayerImpl clanPlayer, @PageParameter int page) {
    ClanImpl clan = clanPlayer.getClan();
    List<Player> onlineMembers = new ArrayList<Player>();
    List<ClanPlayerImpl> members = clan.getMembersImpl();
    for (ClanPlayerImpl member : members) {
        Optional<Player> playerOpt = Sponge.getServer().getPlayer(member.getUUID());
        if (playerOpt.isPresent() && playerOpt.get().isOnline()) {
            onlineMembers.add(playerOpt.get());
        }
    }
    java.util.Collections.sort(members, new MemberComparator());

    HorizontalTable<Player> table = new HorizontalTable<Player>("Clan coordinates " + clan.getName(), 10, (row, player, index) -> {
        if (player.isOnline()) {
            Location<World> location = player.getLocation();
            row.setValue("Player", Text.of(player.getName()));
            row.setValue("Location", Utils.formatLocation(location));

        }
    });
    table.defineColumn("Player", 30);
    table.defineColumn("Location", 30);

    table.draw(onlineMembers, page, commandSource);
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:27,代碼來源:ClanCommands.java

示例9: loadedClan

import org.spongepowered.api.Sponge; //導入依賴的package包/類
protected void loadedClan(int clanID, String clanTag, String clanName, int ownerID, String tagColorId, boolean allowAllyInvites,
                          boolean ffProtection, long creationTime, String homeWorld, double homeX, double homeY, double homeZ, float homeYaw, float homePitch,
                          int homeSetTimes, long homeLastSetTimeStamp, String bankId) {
    ClanImpl clan = new ClanImpl.Builder(clanID, clanTag, clanName).tagColor(Utils.getTextColorById(tagColorId, Config.getColor(Config.CLAN_TAG_DEFAULT_COLOR))).acceptAllyInvites(allowAllyInvites)
            .ffProtection(ffProtection).creationTime(creationTime).homeSetTimes(homeSetTimes).homeLastSetTimeStamp(homeLastSetTimeStamp).bankId(bankId).build();
    if (homeWorld != null && Sponge.getServer().getWorld(UUID.fromString(homeWorld)).isPresent()) {
        // TODO SPONGE homeYaw, homePitch
        clan.setHomeInternal(new Location<>(Sponge.getServer().getWorld(UUID.fromString(homeWorld)).get(), homeX, homeY, homeZ));
    }

    clan.addRank(RankFactory.getInstance().createOwner());
    clan.addRank(RankFactory.getInstance().createRecruit());

    clanOwners.put(clanID, ownerID);
    clans.put(clanID, clan);

    checkHighestUsedClanID(clanID);
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:19,代碼來源:DataLoader.java

示例10: SpongeStats

import org.spongepowered.api.Sponge; //導入依賴的package包/類
public SpongeStats(MCMarketApi marketApi, PluginContainer plugin) {
    super(marketApi);

    Sponge.getEventManager().registerListeners(plugin, this);

    Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            if (!Sponge.getPluginManager().isLoaded(plugin.getId())) {
                timer.cancel();
                return;
            }

            Sponge.getScheduler().createTaskBuilder().execute(() -> runEventsSender()).submit(plugin);
        }
    }, 1000 * 10, 1000 * 60);
}
 
開發者ID:MinecraftMarket,項目名稱:MinecraftMarket-Plugin,代碼行數:20,代碼來源:SpongeStats.java

示例11: onReload

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Listener
public void onReload(GameReloadEvent event)
{
    try
    {
        MessageReceiver src = event.getCause().first(CommandSource.class).orElse(Sponge.getServer().getConsole());
        src.sendMessage(this.translation.take("virtualchest.reload.start"));
        this.loadConfig();
        this.saveConfig();
        src.sendMessage(this.translation.take("virtualchest.reload.finish"));
    }
    catch (IOException e)
    {
        throw Throwables.propagate(e);
    }
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:17,代碼來源:VirtualChestPlugin.java

示例12: registerDatabasePollingTask

import org.spongepowered.api.Sponge; //導入依賴的package包/類
private void registerDatabasePollingTask() {
    int delayInSeconds = 3600;
    int delayInTicks = delayInSeconds * 20;

    Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
    taskBuilder.execute(new Runnable() {
        @Override
        public void run() {
            if (!DatabaseConnectionOwner.getInstance().isValid()) {
                DatabaseConnectionOwner.getInstance().setupConnection();
            }
        }
    });
    taskBuilder.delayTicks(delayInTicks).intervalTicks(delayInTicks).submit(MCClans.getPlugin());

    getLogger().info("Registered database polling task to run every " + delayInSeconds + "s (" + delayInSeconds / 3600 + "h)", false);
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:18,代碼來源:MCClans.java

示例13: initEconomyService

import org.spongepowered.api.Sponge; //導入依賴的package包/類
private boolean initEconomyService() {
    Optional<ProviderRegistration<EconomyService>> economyServiceOpt = Sponge.getServiceManager().getRegistration(EconomyService.class);
    if (economyServiceOpt.isPresent()) {
        economyService = economyServiceOpt.get().getProvider();
        String currencyName = Config.getString(Config.CURRENCY);
        if (currencyName.equalsIgnoreCase("default")) {
            currency = economyService.getDefaultCurrency();
        } else {
            for (Currency checkCurrency : economyService.getCurrencies()) {
                if (currencyName.equalsIgnoreCase(checkCurrency.getDisplayName().toPlain())) {
                    currency = checkCurrency;
                    break;
                }
            }
            if (currency == null) {
                currency = economyService.getDefaultCurrency();
                getPlugin().getLogger().warn("Currency " + currencyName + " not found, falling back to default currency", false);
            }
        }
        return true;
    } else {
        return false;
    }
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:25,代碼來源:MCClans.java

示例14: complete

import org.spongepowered.api.Sponge; //導入依賴的package包/類
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
    try {
        String arg = args.peek().toLowerCase();
        return Sponge.getRegistry().getAllOf(this.type).stream()
            .filter(x ->
                x.getId().startsWith(arg)
                || x.getId().startsWith("happytrails:" + arg)
            )
            .filter(x -> {
                final String trimmedId = x.getId().contains(":") ? x.getId().split(":")[1] : x.getId();
                return src.hasPermission(this.permissionPrefix + trimmedId);
            })
            .map(CatalogType::getId)
            .collect(Collectors.toList());
    } catch (Exception e) {
        return Sponge.getRegistry().getAllOf(this.type).stream().map(CatalogType::getId).collect(Collectors.toList());
    }
}
 
開發者ID:gabizou,項目名稱:HappyTrails,代碼行數:20,代碼來源:TrailCommands.java

示例15: startSubmitting

import org.spongepowered.api.Sponge; //導入依賴的package包/類
private void startSubmitting() {
    // We use a timer cause want to be independent from the server tps
    final Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            // Plugin was disabled, e.g. because of a reload (is this even possible in Sponge?)
            if (!Sponge.getPluginManager().isLoaded(plugin.getId())) {
                timer.cancel();
                return;
            }
            // The data collection (e.g. for custom graphs) is done sync
            // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
            Scheduler scheduler = Sponge.getScheduler();
            Task.Builder taskBuilder = scheduler.createTaskBuilder();
            taskBuilder.execute(() -> submitData()).submit(plugin);
        }
    }, 1000*60*5, 1000*60*30);
    // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
    // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
    // WARNING: Just don't do it!
}
 
開發者ID:Lergin,項目名稱:Vigilate,代碼行數:23,代碼來源:Metrics.java


注:本文中的org.spongepowered.api.Sponge類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。