当前位置: 首页>>代码示例>>Java>>正文


Java Game类代码示例

本文整理汇总了Java中org.spongepowered.api.Game的典型用法代码示例。如果您正苦于以下问题:Java Game类的具体用法?Java Game怎么用?Java Game使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Game类属于org.spongepowered.api包,在下文中一共展示了Game类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hookChannels

import org.spongepowered.api.Game; //导入依赖的package包/类
@Listener
public void hookChannels(GameInitializationEvent event) {
    Game game = event.getGame();
    Server server = game.getServer();
    Method getNetworkSystem = null;
    for (Method m : server.getClass().getMethods()) {
        if ("net.minecraft.network.NetworkSystem".equals(m.getReturnType().getName())) {
            getNetworkSystem = m;
        }
    }
    if (getNetworkSystem == null) {
        throw new RuntimeException("Could not find getNetworkSystem in " + server);
    }
    try {
        Object networkSystem = getNetworkSystem.invoke(server);
        SpongeChannelInitializer channelInitializer = new SpongeChannelInitializer(game);
        @SuppressWarnings("unchecked")
        List<ChannelFuture> endpoints = (List) Reflection.getField(networkSystem.getClass(), "field_151274_e", networkSystem);
        for (ChannelFuture endpoint : endpoints) {
            endpoint.channel().pipeline().addFirst(channelInitializer);
        }
    } catch (IllegalAccessException | NoSuchFieldException | InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ReplayMod,项目名称:SpongeRecording,代码行数:26,代码来源:SpongeImplementation.java

示例2: RecordingPlugin

import org.spongepowered.api.Game; //导入依赖的package包/类
@Inject
public RecordingPlugin(Game game, PluginContainer container, Logger logger) {
    this.container = container;

    // Load all implementations using the java service provider api
    // We can't use the sponge services as the implementations aren't ever registered
    Implementation implementation = null;
    for (Implementation p : ServiceLoader.load(Implementation.class)) {
        if (p.isFunctional(game)) {
            implementation = p;
            break;
        }
    }
    if (implementation == null) {
        throw new UnsupportedOperationException("The current platform is not supported by SpongeRecording.");
    } else {
        logger.info("SpongeRecording loaded. Found active platform: " + implementation);
        this.implementation = implementation;
    }
}
 
开发者ID:ReplayMod,项目名称:SpongeRecording,代码行数:21,代码来源:RecordingPlugin.java

示例3: checkPlugin

import org.spongepowered.api.Game; //导入依赖的package包/类
/**
 * Ensures that an object reference passed as a parameter to the calling
 * method is a valid plugin container or plugin reference.
 * 
 * @param object an object reference
 * @param message the exception message to use if the check fails; will be
 *        converted to a string using {@link String.valueOf(Object)}.
 * @return the resulted plugin container
 * @throws NullPointerException - if reference is null
 * @throws IllegalArgumentException - if reference is invalid
 */
public static PluginContainer checkPlugin(Object object, @Nullable Object message) {
    // Make sure that the game and plugin manager is already loaded
    Game game = WeathersPlugin.game();

    checkState(game != null && game.getPluginManager() != null, NOT_AVAILABLE);
    checkNotNull(object, message);

    if (object instanceof PluginContainer) {
        return (PluginContainer) object;
    }

    Optional<PluginContainer> container = game.getPluginManager().fromInstance(object);
    checkArgument(container.isPresent(), (message != null ? message + ": " : "") + "invalid plugin (%s)", object);
    return container.get();
}
 
开发者ID:Cybermaxke,项目名称:Weathers,代码行数:27,代码来源:Conditions.java

示例4: getSpec

import org.spongepowered.api.Game; //导入依赖的package包/类
/**
 * Gets the spec of this branch containing all sub branches as childs
 * @return A new CommandSpec for this branch
 */
public CommandSpec getSpec(Game game) {
	DirectiveExecutor executor = new DirectiveExecutor(this.executor);
	CommandSpec.Builder spec = CommandSpec.builder();
	spec.executor(executor);
	
	if (this.executor != null) {
		Directive directive = this.executor.getAnnotation(Directive.class);
		spec.description(Texts.of(directive.description()));
		if (directive.permission() != "") {
			spec.permission(directive.permission());
		}
		ArgumentType[] args = directive.arguments();
		String[] labels = directive.argumentLabels();
		CommandElement[] elements = new CommandElement[args.length];
		for (int i = 0; i < args.length; i++) {
			elements[i] = args[i].construct(labels[i], game);
		}
		spec.arguments(elements);
	}
	
	for (DirectiveTree entry : this.subDirectives) {
		spec.child(entry.getSpec(game), entry.getLabel());
	}
	return spec.build();
}
 
开发者ID:mcardy,项目名称:Directive,代码行数:30,代码来源:DirectiveTree.java

示例5: execute

import org.spongepowered.api.Game; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();

	BanService srv = game.getServiceManager().provide(BanService.class).get();
	if (!srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player is not currently banned."));
		return CommandResult.empty();
	}

	srv.removeBan(srv.getBanFor(player.getProfile()).get());
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been unbanned."));
	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:17,代码来源:PardonExecutor.java

示例6: executeAsync

import org.spongepowered.api.Game; //导入依赖的package包/类
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Player p = ctx.<Player> getOne("player").get();

	// Uses the TimespanParser.
	Optional<Long> time = ctx.<Long> getOne("time");

	if (time.isPresent())
	{
		Task.Builder taskBuilder = game.getScheduler().createTaskBuilder();
		taskBuilder.execute(() -> {
			if (EssentialCmds.muteList.contains(p.getUniqueId()))
				EssentialCmds.muteList.remove(p.getUniqueId());
		}).delay(time.get(), TimeUnit.SECONDS).name("EssentialCmds - Remove previous mutes").submit(EssentialCmds.getEssentialCmds());
	}

	EssentialCmds.muteList.add(p.getUniqueId());
	Utils.addMute(p.getUniqueId());
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player muted."));
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:23,代码来源:MuteExecutor.java

示例7: giveTool

import org.spongepowered.api.Game; //导入依赖的package包/类
public void giveTool(Game game, final CommandSource cs, final String[] args) {
	BTRDebugger.DLog("giveTool - preAuth");
	if (BTRPT.isAuthed(cs)) {
		BTRDebugger.DLog("giveTool - isAuthed");
		BTRExecutorService.ThreadPool.execute(new Runnable() {
			public void run() {
				Thread.currentThread().setName("BTRTC");
				if (cs instanceof Player) {
					toggleTool(cs, ((Player) cs).getPlayer().get());
				} else {
					cs.sendMessage(Text.of(TextColors.RED, "Only a player can use the in-game tool!"));
				}
			}
		});
		/*
		 * ItemStack i = BTRIM.createCustomItem(game, "Log Block",
		 * ItemTypes.LOG); if (cs instanceof Player) { ((Player)
		 * cs).getInventory().offer(i); }
		 */
	} else {
		BTRDebugger.DLog("giveTool - notAuthed");
	}
}
 
开发者ID:Volition21,项目名称:BlockTrackR,代码行数:24,代码来源:BTRToolCommand.java

示例8: getCommand

import org.spongepowered.api.Game; //导入依赖的package包/类
public static CommandSpec getCommand(Game game) {
    Builder<List<String>, CommandCallable> builder = ImmutableMap.<List<String>, CommandCallable>builder();
    builder.put(ImmutableList.of("ban"), ChannelBanCommand.getCommand());
    builder.put(ImmutableList.of("force"), ChannelForceCommand.getCommand());
    builder.put(ImmutableList.of("join"), ChannelJoinCommand.getCommand());
    builder.put(ImmutableList.of("kick"), ChannelKickCommand.getCommand());
    builder.put(ImmutableList.of("leave"), ChannelLeaveCommand.getCommand());
    builder.put(ImmutableList.of("list"), ChannelListCommand.getCommand());
    builder.put(ImmutableList.of("unban"), ChannelUnbanCommand.getCommand());
    builder.put(ImmutableList.of("help", "?"), ChannelHelpCommand.getCommand());

    return CommandSpec.builder().executor((src, args) -> {
        src.sendMessage(Text.of(Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
                TextColors.GRAY, "Help: ", TextColors.WHITE, "/ch ?\n", TextColors.GRAY, "IRC: ",
                TextColors.WHITE, "irc.esper.net #helion3"));
        return CommandResult.empty();
    }).children(builder.build()).build();
}
 
开发者ID:prism,项目名称:Darmok,代码行数:19,代码来源:ChannelCommands.java

示例9: execute

import org.spongepowered.api.Game; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();
	String time = ctx.<String> getOne("time").get();
	String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!");

	BanService srv = game.getServiceManager().provide(BanService.class).get();

	if (srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player has already been banned."));
		return CommandResult.empty();
	}

	srv.addBan(Ban.builder()
		.type(BanTypes.PROFILE)
		.source(src).profile(player.getProfile())
		.expirationDate(getInstantFromString(time))
		.reason(TextSerializers.formattingCode('&').deserialize(reason))
		.build());

	if (player.isOnline())
	{
		player.getPlayer().get().kick(Text.builder()
			.append(Text.of(TextColors.DARK_RED, "You have been tempbanned!\n", TextColors.RED, "Reason: "))
			.append(TextSerializers.formattingCode('&').deserialize(reason), Text.of("\n"))
			.append(Text.of(TextColors.GOLD, "Time: ", TextColors.GRAY, getFormattedString(time)))
			.build());
	}

	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned."));
	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:35,代码来源:TempBanExecutor.java

示例10: AmicusCore

import org.spongepowered.api.Game; //导入依赖的package包/类
@Inject
public AmicusCore(@ConfigDir(sharedRoot = false) @Nonnull final Path configDir,
                  @Nonnull final Game game) {
    instance = this;
    this.configProfiles = Maps.newHashMap();
    this.configDir = configDir;
    this.game = game;

    this.configProfilesFile = this.loadConfig();
}
 
开发者ID:FerusTech,项目名称:Amicus,代码行数:11,代码来源:AmicusCore.java

示例11: SpongeTasket

import org.spongepowered.api.Game; //导入依赖的package包/类
public SpongeTasket(Object plugin, Game game) {
    Validate.notNull(game);
    Validate.notNull(plugin);

    this.plugin = plugin;
    this.game = game;
}
 
开发者ID:kacperduras,项目名称:Tasket,代码行数:8,代码来源:SpongeTasket.java

示例12: reloadMappings

import org.spongepowered.api.Game; //导入依赖的package包/类
private boolean reloadMappings()
{
    Game game = Sponge.getGame();
    PluginContainer puContainer = Sponge.getPluginManager().getPlugin("pixelupgrade").orElse(null);

    if (puContainer != null)
    {
        game.getCommandManager().getOwnedBy(puContainer).forEach(game.getCommandManager()::removeMapping);
        return ConfigOperations.registerCommands();
    }
    else return false;
}
 
开发者ID:xPXpanD,项目名称:PixelUpgrade,代码行数:13,代码来源:ReloadConfigs.java

示例13: CatClearLag

import org.spongepowered.api.Game; //导入依赖的package包/类
@Inject
public CatClearLag(Logger logger, Game game, @ConfigDir(sharedRoot = false) File configDir, GuiceObjectMapperFactory factory) {
    this.logger = logger;
    this.game = game;
    this.configDir = configDir;
    this.factory = factory;
    instance = this;
}
 
开发者ID:Time6628,项目名称:CatClearLag,代码行数:9,代码来源:CatClearLag.java

示例14: isFunctional

import org.spongepowered.api.Game; //导入依赖的package包/类
@Override
public boolean isFunctional(Game game) {
    try {
        return Class.forName("org.spongepowered.common.SpongeGame").isInstance(game);
    } catch (Throwable t) {
        t.printStackTrace();
        return false;
    }
}
 
开发者ID:ReplayMod,项目名称:SpongeRecording,代码行数:10,代码来源:SpongeImplementation.java

示例15: SpongeRecorder

import org.spongepowered.api.Game; //导入依赖的package包/类
public SpongeRecorder(Game game, SpongeConnection connection) {
    super(game, connection);

    ChannelPipeline pipeline = connection.getChannel().get().pipeline();
    pipeline.addLast("recorder_compression_order", new PipelineOrderHandler());
    pipeline.addBefore("encoder", "outbound_recorder", new OutboundPacketRecorder());
    pipeline.addBefore("decoder", "inbound_recorder", new InboundPacketRecorder());
}
 
开发者ID:ReplayMod,项目名称:SpongeRecording,代码行数:9,代码来源:SpongeRecorder.java


注:本文中的org.spongepowered.api.Game类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。