org.spongepowered.api.entity.living.player.Player Java Examples
The following examples show how to use
org.spongepowered.api.entity.living.player.Player.
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: HomeArgument.java From UltimateCore with MIT License | 6 votes |
@Nullable @Override public Home parseValue(CommandSource src, CommandArgs args) throws ArgumentParseException { String value = args.next(); if (!(src instanceof Player)) { //This shouldnt happen return null; } Player p = (Player) src; UltimateUser up = UltimateCore.get().getUserService().getUser(p); List<Home> homes = up.get(HomeKeys.HOMES).get(); for (Home home : homes) { if (value.equalsIgnoreCase(home.getName())) { return home; } } throw args.createError(Messages.getFormatted(src, "home.command.home.notfound", "%home%", value.toLowerCase())); }
Example #2
Source File: CommandClaimSetSpawn.java From GriefDefender with MIT License | 6 votes |
@CommandAlias("claimsetspawn") @Description("Sets the spawn of claim.") @Subcommand("claim setspawn") public void execute(Player player) { final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation()); final Component result = claim.allowEdit(player); if (result != null) { GriefDefenderPlugin.sendMessage(player, result); return; } final Vector3i pos = VecHelper.toVector3i(player.getLocation()); claim.getInternalClaimData().setSpawnPos(pos); final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.SPAWN_SET_SUCCESS, ImmutableMap.of( "location", pos)); GriefDefenderPlugin.sendMessage(player, message); }
Example #3
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean canBuildNear(Player p, Location<World> loc) { if (RedProtect.get().config.configRoot().region_settings.deny_build_near <= 0) { return true; } int x = loc.getBlockX(); int y = loc.getBlockY(); int z = loc.getBlockZ(); int radius = RedProtect.get().config.configRoot().region_settings.deny_build_near; for (int ix = x - radius; ix <= x + radius; ++ix) { for (int iy = y - radius; iy <= y + radius; ++iy) { for (int iz = z - radius; iz <= z + radius; ++iz) { Region reg = RedProtect.get().rm.getTopRegion(new Location<>(p.getWorld(), ix, iy, iz), RedProtectUtil.class.getName()); if (reg != null && !reg.canBuild(p)) { RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("blocklistener.cantbuild.nearrp").replace("{distance}", "" + radius)); return false; } } } } return true; }
Example #4
Source File: CommonEntityEventHandler.java From GriefDefender with MIT License | 6 votes |
private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) { if (user == null) { return; } final Player player = user.getOnlinePlayer(); if (player == null || !player.get(Keys.INVULNERABLE).get()) { // Most likely NPC return; } if (!GDOptions.isOptionEnabled(Options.PLAYER_DENY_GODMODE)) { return; } final GDPlayerData playerData = user.getInternalPlayerData(); final GameMode gameMode = player.get(Keys.GAME_MODE).get(); if (gameMode == GameModes.CREATIVE || gameMode == GameModes.SPECTATOR || !player.get(Keys.INVULNERABLE).get()) { return; } final Boolean noGodMode = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), playerData.getSubject(), Options.PLAYER_DENY_GODMODE, toClaim); final boolean bypassOption = playerData.userOptionBypassPlayerDenyGodmode; if (!bypassOption && noGodMode) { player.offer(Keys.INVULNERABLE, false); GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_GODMODE); } }
Example #5
Source File: PokeListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onChat(MessageChannelEvent.Chat event) { String message = event.getRawMessage().toPlain(); for (Player p : Sponge.getServer().getOnlinePlayers()) { if (message.contains(p.getName())) { ModuleConfig config = Modules.POKE.get().getConfig().get(); CommentedConfigurationNode node = config.get(); String soundname = node.getNode("sound", "sound").getString(); String categoryname = node.getNode("sound", "category").getString(); Double volume = node.getNode("sound", "volume").getDouble(); Double pitch = node.getNode("sound", "pitch").getDouble(); Double minVolume = node.getNode("sound", "minVolume").getDouble(); SoundType type = Sponge.getRegistry().getType(CatalogTypes.SOUND_TYPE, soundname.toUpperCase()).get(); //TODO wait for CatalogTypes.SOUND_CATEGORY to be added SoundCategory category; try { category = Sponge.getRegistry().getType(CatalogTypes.SOUND_CATEGORY, categoryname.toUpperCase()).get(); } catch (Error ex) { category = SoundCategories.PLAYER; } p.playSound(type, category, p.getLocation().getPosition(), volume, pitch, minVolume); } } }
Example #6
Source File: VirtualChestCommandManager.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
private CommandResult processListCommand(CommandSource source, CommandContext args) throws CommandException { VirtualChestInventoryDispatcher dispatcher = this.plugin.getDispatcher(); if (source instanceof Player && !source.hasPermission("virtualchest.list")) { Text error = translation.take("virtualchest.list.noPermission", source.getName()); throw new CommandException(error); } Set<String> inventories = dispatcher.ids(); if (source instanceof Player) { Predicate<String> inventoryNamePredict = name -> dispatcher.hasPermission((Player) source, name); inventories = inventories.stream().filter(inventoryNamePredict).collect(Collectors.toSet()); } source.sendMessage(translation.take("virtualchest.list.overview", inventories.size())); source.sendMessage(Text.of(String.join(", ", inventories))); return CommandResult.success(); }
Example #7
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 6 votes |
@Listener(order = Order.FIRST) public void onPlayerJoin(ClientConnectionEvent.Join event) { GDTimings.PLAYER_JOIN_EVENT.startTimingIfSync(); Player player = event.getTargetEntity(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) { GDTimings.PLAYER_JOIN_EVENT.stopTimingIfSync(); return; } UUID playerID = player.getUniqueId(); final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID); final GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation()); if (claim.isInTown()) { playerData.inTown = true; } GDTimings.PLAYER_JOIN_EVENT.stopTimingIfSync(); }
Example #8
Source File: TPAAllExecutor.java From EssentialCmds with MIT License | 6 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { if (src instanceof Player) { Player player = (Player) src; for (Player p : Sponge.getServer().getOnlinePlayers()) { Sponge.getEventManager().post(new TPAHereEvent(player, p)); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Requested for all players to be teleported to you")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpaall!")); } }
Example #9
Source File: DeleteMailCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { checkIfPlayer(src); Player p = (Player) src; UltimateUser up = UltimateCore.get().getUserService().getUser(p); //Get mail UUID uuid = args.<UUID>getOne("mailid").get(); List<Mail> mails = up.get(MailKeys.MAILS_RECEIVED).get(); Mail mail = mails.stream().filter(m -> m.getMailid().equals(uuid)).findFirst().orElse(null); if (mail == null) { throw Messages.error(src, "core.invaliduuid", "%uuid%", uuid); } mails.remove(mail); up.offer(MailKeys.MAILS_RECEIVED, mails); Messages.send(src, "mail.command.mail.delete"); return CommandResult.success(); }
Example #10
Source File: ChatCaptureUtil.java From GriefDefender with MIT License | 6 votes |
private Consumer<CommandSource> createChatInfoConsumer(CommandSource src, GDClaim claim, String command) { return info -> { if (!(src instanceof Player)) { return; } final Player player = (Player) src; final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player); final GDPlayerData playerData = user.getInternalPlayerData(); final boolean isRecordingChat = playerData.isRecordingChat(); if (isRecordingChat) { playerData.recordChatTimestamp = null; } else { playerData.recordChatTimestamp = Instant.now(); playerData.chatLines.clear(); } if (command.equals("claiminfo")) { CommandHelper.executeCommand(src, command, claim.getUniqueId().toString()); } else { CommandHelper.executeCommand(src, command, ""); } }; }
Example #11
Source File: CommandHandlers.java From RedProtect with GNU General Public License v3.0 | 6 votes |
private static void SendFlagUsageMessage(Player p, String flag) { String message; if (flag.equalsIgnoreCase("effects") || flag.equalsIgnoreCase("view-distance") || flag.equalsIgnoreCase("deny-exit-items") || flag.equalsIgnoreCase("allow-enter-items") || flag.equalsIgnoreCase("deny-enter-items") || flag.equalsIgnoreCase("gamemode") || flag.equalsIgnoreCase("set-portal") || flag.equalsIgnoreCase("allow-cmds") || flag.equalsIgnoreCase("deny-cmds") || flag.equalsIgnoreCase("allow-break") || flag.equalsIgnoreCase("allow-place") || flag.equalsIgnoreCase("particles") || flag.equalsIgnoreCase("cmd-onhealth")) { message = RedProtect.get().lang.get("cmdmanager.region.flag.usage" + flag); } else { message = RedProtect.get().lang.get("cmdmanager.region.flag.usagetruefalse").replace("{flag}", flag); } p.sendMessage(RedProtect.get().getUtil().toText(message.replace("{cmd}", getCmd("flag")))); }
Example #12
Source File: NamesHandler.java From UltimateCore with MIT License | 6 votes |
public void resortNamesList() { //Resort LinkedHashMap<UUID, Tuples.Tri<Text, Text, Text>> tempnames = (LinkedHashMap<UUID, Tuples.Tri<Text, Text, Text>>) this.names.clone(); this.names.clear(); //Sort map by weight List<UUID> nameslist = new ArrayList<>(tempnames.keySet()); nameslist.sort((u1, u2) -> { Player p1 = Sponge.getServer().getPlayer(u1).get(); Player p2 = Sponge.getServer().getPlayer(u2).get(); Integer weight1 = TablistPermissions.UC_TABLIST_WEIGHT.getIntFor(p1); Integer weight2 = TablistPermissions.UC_TABLIST_WEIGHT.getIntFor(p2); return weight1.compareTo(weight2); }); //Add to global list nameslist.forEach(name -> this.names.put(name, tempnames.get(name))); }
Example #13
Source File: TutorialCommand.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to show tutorial on how to protect a region.")) .permission("redprotect.command.tutorial") .executor((src, args) -> { if (!(src instanceof Player)) { HandleHelpPage(src, 1); } else { Player player = (Player) src; RedProtect.get().lang.sendMessage(player, "cmdmanager.tutorial"); RedProtect.get().lang.sendMessage(player, "cmdmanager.tutorial1"); RedProtect.get().lang.sendMessage(player, "cmdmanager.tutorial2"); RedProtect.get().lang.sendMessage(player, "cmdmanager.tutorial3"); RedProtect.get().lang.sendMessage(player, "cmdmanager.tutorial4"); RedProtect.get().lang.sendMessage(player, "cmdmanager.tutorial5"); } return CommandResult.success(); }).build(); }
Example #14
Source File: SpyListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onWhisper(MessageChannelEvent e) { if (!Modules.PERSONALMESSAGE.isPresent()) { return; } if (e instanceof PersonalmessageEvent) { PersonalmessageEvent ev = (PersonalmessageEvent) e; CommandSource s = ev.getPMSender(); CommandSource t = ev.getPMTarget(); for (Player p : Sponge.getServer().getOnlinePlayers()) { if (!p.hasPermission(SpyPermissions.UC_SPY_MESSAGESPY_SEE.get())) { continue; } if (s.getIdentifier().equals(p.getIdentifier()) || t.getIdentifier().equals(p.getIdentifier())) { continue; } if (!UltimateCore.get().getUserService().getUser(p).get(SpyKeys.MESSAGESPY_ENABLED).get()) { continue; } Messages.send(p, "spy.format.messagespy", "%player%", s, "%target%", t, "%message%", ev.getPMUnformattedMessage()); } } }
Example #15
Source File: PermissionUtil.java From GriefDefender with MIT License | 6 votes |
public boolean canPlayerTeleport(Player player, GDClaim claim) { final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getPlayerData(player.getWorld(), player.getUniqueId()); if (!playerData.canIgnoreClaim(claim) && !playerData.canManageAdminClaims) { // if not owner of claim, validate perms if (!player.getUniqueId().equals(claim.getOwnerUniqueId())) { if (!player.hasPermission(GDPermissions.COMMAND_CLAIM_INFO_TELEPORT_OTHERS)) { return false; } if (!claim.isUserTrusted(player, TrustTypes.ACCESSOR)) { if (GriefDefenderPlugin.getInstance().economyService.orElse(null) != null) { // Allow non-trusted to TP to claims for sale if (!claim.getEconomyData().isForSale()) { return false; } } else { return false; } } } else if (!player.hasPermission(GDPermissions.COMMAND_CLAIM_INFO_TELEPORT_BASE)) { return false; } } return true; }
Example #16
Source File: BackCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkIfPlayer(sender); checkPermission(sender, BackPermissions.UC_BACK_BACK_BASE); Player p = (Player) sender; UltimateUser up = UltimateCore.get().getUserService().getUser(p); Optional<SerializableTransform> loc = up.get(BackKeys.BACK); if (!loc.isPresent() || !loc.get().isPresent()) { throw new DataFailedException(Messages.getFormatted(sender, "back.command.back.notfound")); } Teleportation tp = UltimateCore.get().getTeleportService().createTeleportation(sender, Arrays.asList(p), loc.get().get(), tel -> { Messages.send(sender, "back.command.back.success"); }, (tel, reason) -> { }, true, false); tp.start(); return CommandResult.success(); }
Example #17
Source File: BuildPermListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onPlayerChangeBlock(ChangeBlockEvent.Pre event, @First Player player) { if (player.hasPermission("nations.admin.bypass.perm.build")) { return; } if (Utils.isFakePlayer(event)) { return; } for (Location<World> loc : event.getLocations()) { if (ConfigHandler.getNode("worlds").getNode(loc.getExtent().getName()).getNode("enabled").getBoolean() && !ConfigHandler.isWhitelisted("break", loc.getBlock().getId()) && !DataHandler.getPerm("build", player.getUniqueId(), loc)) { event.setCancelled(true); try { player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD)); } catch (Exception e) {} return; } } }
Example #18
Source File: SetgroupspawnCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkIfPlayer(sender); checkPermission(sender, SpawnPermissions.UC_SPAWN_SETGROUPSPAWN_BASE); String group = args.<String>getOne("group").get(); Player p = (Player) sender; HashMap<String, SerializableTransform> groupspawns = GlobalData.get(SpawnKeys.GROUP_SPAWNS).get(); groupspawns.put(group, new SerializableTransform(p.getTransform())); GlobalData.offer(SpawnKeys.GROUP_SPAWNS, groupspawns); Messages.send(p, "spawn.command.setgroupspawn.success", "%group%", group); return CommandResult.success(); }
Example #19
Source File: CommandTrustList.java From GriefDefender with MIT License | 5 votes |
private static Consumer<CommandSource> createRemoveConsumer(Player src, GDClaim claim, GDPlayerData playerData, TrustType type, Component returnCommand, IClaimData data, List<UUID> trustList, UUID uuid) { return consumer -> { trustList.remove(uuid); data.setRequiresSave(true); data.save(); showTrustList(src, claim, playerData, type, new ArrayList<>(), returnCommand); }; }
Example #20
Source File: Pos1Command.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to set selected points.")) .permission("redprotect.command.pos1") .executor((src, args) -> { if (!(src instanceof Player)) { HandleHelpPage(src, 1); } else { Player player = (Player) src; String claimmode = RedProtect.get().config.getWorldClaimType(player.getWorld().getName()); if (!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH") && !RedProtect.get().ph.hasCommandPerm(player, "redefine")) { return CommandResult.success(); } Location<World> pl = player.getLocation(); RedProtect.get().firstLocationSelections.put(player, pl); player.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("playerlistener.wand1") + RedProtect.get().lang.get("general.color") + " (&6" + pl.getBlockX() + RedProtect.get().lang.get("general.color") + ", &6" + pl.getBlockY() + RedProtect.get().lang.get("general.color") + ", &6" + pl.getBlockZ() + RedProtect.get().lang.get("general.color") + ").")); //show preview border if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) { Location<World> loc1 = RedProtect.get().firstLocationSelections.get(player); Location<World> loc2 = RedProtect.get().secondLocationSelections.get(player); if (RedProtect.get().hooks.WE && RedProtect.get().config.configRoot().hooks.useWECUI) { WEHook.setSelectionRP(player, loc1, loc2); } if (loc1.getPosition().distanceSquared(loc2.getPosition()) > RedProtect.get().config.configRoot().region_settings.max_scan && !player.hasPermission("redprotect.bypass.define-max-distance")) { double dist = loc1.getPosition().distanceSquared(loc2.getPosition()); RedProtect.get().lang.sendMessage(player, String.format(RedProtect.get().lang.get("regionbuilder.selection.maxdefine"), RedProtect.get().config.configRoot().region_settings.max_scan, (int) dist)); } else { RedProtect.get().getUtil().addBorder(player, loc1, loc2); } } } return CommandResult.success(); }).build(); }
Example #21
Source File: Selector.java From UltimateCore with MIT License | 5 votes |
/** * Returns a list of all players which satisfy the string. * This can be empty if no players are found. * * @param s The string to search for * @return All players which statisfy the string */ public static List<Player> multiple(CommandSource source, String s) { List<Player> matches = new ArrayList<>(); multipleEntities(source, s).forEach(en -> { if (en instanceof Player) { matches.add((Player) en); } }); return matches; }
Example #22
Source File: UCMessages.java From UltimateChat with GNU General Public License v3.0 | 5 votes |
private static String mention(Object sender, Object receiver, String msg) { if (UChat.get().getConfig().root().mention.enable) { for (Player p : Sponge.getServer().getOnlinePlayers()) { if (!sender.equals(p) && Arrays.stream(msg.split(" ")).anyMatch(p.getName()::equalsIgnoreCase)) { if (receiver instanceof Player && receiver.equals(p)) { String mentionc = UChat.get().getConfig().root().mention.color_template.replace("{mentioned-player}", p.getName()); mentionc = formatTags("", mentionc, sender, p, "", new UCChannel("mention")); if (msg.contains(mentionc) || sender instanceof CommandSource && !UChat.get().getPerms().hasPerm((CommandSource) sender, "chat.mention")) { msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", p.getName()); continue; } Optional<SoundType> sound = Sponge.getRegistry().getType(SoundType.class, UChat.get().getConfig().root().mention.playsound); if (sound.isPresent() && !msg.contains(mentionc)) { p.playSound(sound.get(), p.getLocation().getPosition(), 1, 1); } msg = msg.replace(mentionc, p.getName()); msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", mentionc); } else { msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", p.getName()); } } } } return msg; }
Example #23
Source File: SpongeMain.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Listener public void onQuit(ClientConnectionEvent.Disconnect event) { Player player = event.getTargetEntity(); FawePlayer fp = FawePlayer.wrap(player); fp.unregister(); Fawe.get().unregister(player.getName()); }
Example #24
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPressPlateChange(CollideBlockEvent e, @First Player p) { if (e.getTargetBlock().getName().contains("pressure_plate")) { Location<World> loc = e.getTargetLocation(); Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName()); if (r != null && !r.allowPressPlate(p)) { e.setCancelled(true); RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantpressplate"); } } }
Example #25
Source File: CacheService.java From Web-API with MIT License | 5 votes |
/** * Updates the internal representation of the passed player and returns it. * @param player The player which will be updated. * @return The updated cached player. */ public CachedPlayer updatePlayer(Player player) { assert Sponge.getServer().isMainThread(); Timings.CACHE_PLAYER.startTiming(); CachedPlayer p = new CachedPlayer(player); players.put(p.getUUID(), p); Timings.CACHE_PLAYER.stopTiming(); return p; }
Example #26
Source File: ChatCaptureUtil.java From GriefDefender with MIT License | 5 votes |
public List<Component> generateChatSettings(Player player, GDClaim claim, String command, Component returnComponent) { final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); List<Component> textList = new ArrayList<>(); Component returnToClaimInfo = null; if (command.equals("claiminfo")) { returnToClaimInfo = TextComponent.builder() .append("[") .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.UI_CLICK_RETURN_COMMAND, ImmutableMap.of("command", command))) .append("]") .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(CommandHelper.createCommandConsumer(player, command, claim.getUniqueId().toString())))).build(); } else if (command.equals("trustlist")) { returnToClaimInfo = TextComponent.builder() .append("[") .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.UI_CLICK_RETURN_COMMAND, ImmutableMap.of("command", command))) .append("]") .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createTrustListConsumer(player, claim, playerData, TrustTypes.NONE, returnComponent)))).build(); } else { returnToClaimInfo = TextComponent.builder() .append("[") .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.UI_CLICK_RETURN_COMMAND, ImmutableMap.of("command", command))) .append("]") .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(CommandHelper.createCommandConsumer(player, command, "")))).build(); } textList.add(returnToClaimInfo); for (Component chatLine : playerData.chatLines) { textList.add(chatLine); } int fillSize = 20 - (textList.size() + 2); for (int i = 0; i < fillSize; i++) { textList.add(TextComponent.of(" ")); } return textList; }
Example #27
Source File: VirtualChestJavaScriptManager.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
private ScriptContext getContext(Player player) { try (Timing ignored = VirtualChestTimings.prepareRequirementBindings().startTiming()) { SimpleScriptContext context = this.tempContext; VirtualChestPlaceholderManager placeholderManager = this.plugin.getPlaceholderManager(); Function<String, Object> papi = s -> Text.of(placeholderManager.replacePlaceholder(player, s)).toPlain(); context.setAttribute("papi", papi, ScriptContext.ENGINE_SCOPE); context.setAttribute("player", player, ScriptContext.ENGINE_SCOPE); context.setAttribute("tick", this.getTickFromOpeningInventory(player), ScriptContext.ENGINE_SCOPE); return context; } }
Example #28
Source File: TPAExecutor.java From EssentialCmds with MIT License | 5 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { Player recipient = ctx.<Player> getOne("player").get(); if (src instanceof Player) { Player player = (Player) src; if (recipient == player) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport to yourself!")); } else { src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Requested to be teleported to " + recipient.getName() + ".")); game.getEventManager().post(new TPAEvent(player, recipient)); } } else if (src instanceof ConsoleSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpa!")); } else if (src instanceof CommandBlockSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpa!")); } }
Example #29
Source File: VirtualChestInventoryDispatcher.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean close(String id, Player player) { UUID uuid = player.getUniqueId(); if (inventories.containsKey(id)) { Tuple<String, WeakReference<Container>> tuple = containers.remove(uuid); if (!Objects.isNull(tuple) && this.isInventoryOpening(player, id, tuple)) { SpongeUnimplemented.closeInventory(player, plugin); return true; } } return false; }
Example #30
Source File: EventRunner.java From EagleFactions with MIT License | 5 votes |
/** * @return True if cancelled, false if not */ public static boolean runFactionLeaveEvent(final Player player, final Faction faction) { final EventContext eventContext = EventContext.builder() .add(EventContextKeys.OWNER, player) .add(EventContextKeys.PLAYER, player) .add(EventContextKeys.CREATOR, player) .build(); final Cause eventCause = Cause.of(eventContext, player, faction); final FactionLeaveEvent event = new FactionLeaveEventImpl(player, faction, eventCause); return Sponge.getEventManager().post(event); }