本文整理汇总了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();
}
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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."));
}
示例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");
}
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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());
}