org.spongepowered.api.Game Java Examples
The following examples show how to use
org.spongepowered.api.Game.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MuteExecutor.java From EssentialCmds with MIT License | 6 votes |
@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.")); }
Example #2
Source File: PardonExecutor.java From EssentialCmds with MIT License | 6 votes |
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(); }
Example #3
Source File: TempBanExecutor.java From EssentialCmds with MIT License | 5 votes |
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(); }
Example #4
Source File: KitKeys.java From UltimateCore with MIT License | 5 votes |
@Override public List<Kit> load(Game arg) { List<Kit> kits = new ArrayList<>(); CommentedConfigurationNode node = Modules.KIT.get().getConfig().get().get(); for (CommentedConfigurationNode wnode : node.getNode("kits").getChildrenMap().values()) { try { kits.add(wnode.getValue(TypeToken.of(Kit.class))); } catch (ObjectMappingException e) { Messages.log(Messages.getFormatted("kit.command.kit.invalidkit", "%kit%", wnode.getNode("name").getString())); } } return kits; }
Example #5
Source File: SpongeMetrics.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Inject public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } this.game = game; this.plugin = plugin; loadConfiguration(); }
Example #6
Source File: KitKeys.java From UltimateCore with MIT License | 5 votes |
@Override public void save(Game arg, List<Kit> kits) { ModuleConfig loader = Modules.KIT.get().getConfig().get(); CommentedConfigurationNode node = loader.get(); node.getNode("kits").getChildrenMap().keySet().forEach(node.getNode("kits")::removeChild); for (Kit kit : kits) { try { node.getNode("kits", kit.getId()).setValue(TypeToken.of(Kit.class), kit); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to save kits key"); } } loader.save(node); }
Example #7
Source File: BanExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); User player = ctx.<User> getOne("player").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()).reason(TextSerializers.formattingCode('&').deserialize(reason)).build()); if (player.isOnline()) { player.getPlayer().get().kick(Text.builder() .append(Text.of(TextColors.DARK_RED, "You have been banned!\n ", TextColors.RED, "Reason: ")) .append(TextSerializers.formattingCode('&').deserialize(reason)) .build()); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned.")); return CommandResult.success(); }
Example #8
Source File: MailExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { String message = ctx.<String> getOne("message").get(); String playerName = ctx.<String> getOne("player").get(); if (src instanceof Player) { Player p = (Player) src; if(p.getName().equalsIgnoreCase(playerName)) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot send mail to yourself!")); return CommandResult.success(); } Game game = EssentialCmds.getEssentialCmds().getGame(); MailSendEvent event = new MailSendEvent(p, playerName, message); game.getEventManager().post(event); p.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Sent Mail to " + playerName)); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to send mail!")); } return CommandResult.success(); }
Example #9
Source File: MotdExecutor.java From EssentialCmds with MIT License | 5 votes |
@Override public void executeAsync(CommandSource src, CommandContext args) { Game game = EssentialCmds.getEssentialCmds().getGame(); Server server = game.getServer(); src.sendMessage(Text.of(TextColors.GOLD, "[MOTD]: ", server.getMotd())); }
Example #10
Source File: AsConsoleExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); String command = ctx.<String> getOne("command").get(); game.getCommandManager().process(game.getServer().getConsole().getCommandSource().get(), command); return CommandResult.success(); }
Example #11
Source File: KickExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); Server server = game.getServer(); Player player = ctx.<Player> getOne("player").get(); Optional<String> reason = ctx.<String> getOne("reason"); if (server.getPlayer(player.getUniqueId()).isPresent()) { Text finalKickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName()); if (reason.isPresent()) { Text reas = TextSerializers.formattingCode('&').deserialize(reason.get()); Text kickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName() + " for ", TextColors.RED); finalKickMessage = Text.builder().append(kickMessage).append(reas).build(); player.kick(reas); } else { player.kick(); } MessageChannel.TO_ALL.send(finalKickMessage); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player kicked.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Player doesn't appear to be online!")); } return CommandResult.success(); }
Example #12
Source File: SpongeMetrics.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Inject public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } this.game = game; this.plugin = plugin; loadConfiguration(); }
Example #13
Source File: WorldCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { Game game = this.plugin.getBootstrap().getGame(); if (!game.isServerAvailable()) { return ImmutableContextSetImpl.EMPTY; } Collection<World> worlds = game.getServer().getWorlds(); ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (World world : worlds) { builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase()); } return builder.build(); }
Example #14
Source File: GlobalKeyProvider.java From UltimateCore with MIT License | 5 votes |
@Override public E load(Game game) { GlobalDataFile config = new GlobalDataFile(filename); CommentedConfigurationNode node = config.get(); try { return node.getNode(key).getValue(token, def); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to save " + key + " key for global"); return def; } }
Example #15
Source File: PlanSpongeMocker.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
PlanSpongeMocker withGame() { Game game = Mockito.mock(Game.class); Platform platform = mockPlatform(); Server server = mockServer(); doReturn(platform).when(game).getPlatform(); doReturn(server).when(game).getServer(); doReturn(game).when(planMock).getGame(); return this; }
Example #16
Source File: GlobalKeyProvider.java From UltimateCore with MIT License | 5 votes |
@Override public void save(Game game, E data) { GlobalDataFile config = new GlobalDataFile(filename); CommentedConfigurationNode node = config.get(); try { node.getNode(key).setValue(token, data); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to save " + key + " key for global"); } config.save(node); }
Example #17
Source File: SpongeServerProperties.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
public SpongeServerProperties(Game game) { super( "Sponge", game.getServer().getBoundAddress().orElseGet(() -> new InetSocketAddress(25565)).getPort(), game.getPlatform().getMinecraftVersion().getName(), game.getPlatform().getMinecraftVersion().getName(), () -> game.getServer().getBoundAddress() .orElseGet(() -> new InetSocketAddress(25565)) .getAddress().getHostAddress(), game.getServer().getMaxPlayers() ); }
Example #18
Source File: EconomyLite.java From EconomyLite with MIT License | 4 votes |
public Game getGame() { return game; }
Example #19
Source File: PlotMe_Sponge.java From PlotMe-Core with GNU General Public License v3.0 | 4 votes |
public Game getGame() { return game; }
Example #20
Source File: Key.java From UltimateCore with MIT License | 4 votes |
public Optional<KeyProvider<C, Game>> getProvider() { return Optional.ofNullable((KeyProvider<C, Game>) provider); }
Example #21
Source File: SpongePlatformInfo.java From spark with GNU General Public License v3.0 | 4 votes |
public SpongePlatformInfo(Game game) { this.game = game; }
Example #22
Source File: SpongeMain.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public Game getGame() { return this.game; }
Example #23
Source File: SpongeMain.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public Game getGame() { return this.game; }
Example #24
Source File: EssentialCmds.java From EssentialCmds with MIT License | 4 votes |
public Game getGame() { return Sponge.getGame(); }
Example #25
Source File: LPSpongeBootstrap.java From LuckPerms with MIT License | 4 votes |
public Game getGame() { return this.game; }
Example #26
Source File: UChat.java From UltimateChat with GNU General Public License v3.0 | 4 votes |
public Game getGame() { return this.game; }
Example #27
Source File: PlanSponge.java From Plan with GNU Lesser General Public License v3.0 | 4 votes |
public Game getGame() { return Sponge.getGame(); }
Example #28
Source File: SpongeSparkPlugin.java From spark with GNU General Public License v3.0 | 4 votes |
@Inject public SpongeSparkPlugin(Game game, @ConfigDir(sharedRoot = false) Path configDirectory, @AsynchronousExecutor SpongeExecutorService asyncExecutor) { this.game = game; this.configDirectory = configDirectory; this.asyncExecutor = asyncExecutor; }
Example #29
Source File: KeyProvider.java From UltimateCore with MIT License | votes |
C load(Game game);
Example #30
Source File: KeyProvider.java From UltimateCore with MIT License | votes |
void save(Game game, C data);