@Command(aliases = {"g", "global", "shout"}, desc = "Talk in global chat.", usage = "<message>") @CommandPermissions("cardinal.chat.global") public static void global(final CommandContext cmd, CommandSender sender) throws CommandException { String locale = ChatUtils.getLocale(sender); if (sender instanceof Player) { if (cmd.argsLength() == 0) { ((Player) sender).setMetadata("default-channel", new LazyMetadataValue(GameHandler.getGameHandler().getPlugin(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new Channel(ChatUtils.ChannelType.GLOBAL))); sender.sendMessage(ChatColor.YELLOW + new LocalizedChatMessage(ChatConstant.UI_DEFAULT_CHANNEL_GLOBAL).getMessage(locale)); } if (cmd.argsLength() > 0) { if (GameHandler.getGameHandler().getGlobalMute() && !PermissionModule.isStaff(((Player) sender))) throw new CommandException(ChatConstant.ERROR_GLOBAL_MUTE_ENABLED.asMessage().getMessage(ChatUtils.getLocale(sender))); String message = assembleMessage(cmd); if (message.trim().equals("")) return; ChatUtils.getGlobalChannel().sendMessage("<" + TeamUtils.getTeamColorByPlayer((Player) sender) + ((Player) sender).getDisplayName() + ChatColor.RESET + ">: " + message); } } else throw new CommandException("Console cannot use this command."); }
@Command(aliases = {"a", "admin"}, desc = "Talk in admin chat.", usage = "<message>") @CommandPermissions("cardinal.chat.admin") public static void admin(final CommandContext cmd, CommandSender sender) throws CommandException { String locale = ChatUtils.getLocale(sender); if (sender instanceof Player) { if (cmd.argsLength() == 0) { ((Player) sender).setMetadata("default-channel", new LazyMetadataValue(GameHandler.getGameHandler().getPlugin(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new Channel(ChatUtils.ChannelType.ADMIN))); sender.sendMessage(ChatColor.YELLOW + new LocalizedChatMessage(ChatConstant.UI_DEFAULT_CHANNEL_ADMIN).getMessage(locale)); } if (cmd.argsLength() > 0) { String message = assembleMessage(cmd); if (message.trim().equals("")) return; ChatUtils.getAdminChannel().sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + TeamUtils.getTeamColorByPlayer((Player) sender) + ((Player) sender).getDisplayName() + ChatColor.RESET + ": " + message); Bukkit.getLogger().info("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + TeamUtils.getTeamColorByPlayer((Player) sender) + ((Player) sender).getDisplayName() + ChatColor.RESET + ": " + message); } } else throw new CommandException("Console cannot use this command."); }
@EventHandler(priority = EventPriority.LOW,ignoreCancelled = true) public void playerCheck(PlayerInteractEvent event) { if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { final Player player = event.getPlayer(); if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.AREAWAND.getName())) { event.setCancelled(true); final Loc loc = new Loc(event.getClickedBlock().getLocation(),false); Callable<Object> b = new Callable<Object>(){ @Override public Object call() throws Exception { return loc; }}; if(event.getAction() == Action.LEFT_CLICK_BLOCK) { player.setMetadata("A.Loc1", new LazyMetadataValue(AnnihilationMain.getInstance(),b)); player.sendMessage(ChatColor.LIGHT_PURPLE+"Corner "+ChatColor.GOLD+"1 "+ChatColor.LIGHT_PURPLE+"set."); } else { player.setMetadata("A.Loc2", new LazyMetadataValue(AnnihilationMain.getInstance(),b)); player.sendMessage(ChatColor.LIGHT_PURPLE+"Corner "+ChatColor.GOLD+"2 "+ChatColor.LIGHT_PURPLE+"set."); } } } }
private void setPlayerMeta(Player player, String key, final Object meta) { Callable<Object> b = new Callable<Object>(){ @Override public Object call() throws Exception { return meta; }}; player.setMetadata(key, new LazyMetadataValue(AnnihilationMain.getInstance(),b)); }
@EventHandler public void onPlayerKill(CardinalDeathEvent event) { if (event.getKiller() != null && event.getKiller().getHealth() > 0) { int old = event.getKiller().getMetadata("killstreak").get(0).asInt(); event.getKiller().removeMetadata("killstreak", Cardinal.getInstance()); event.getKiller().setMetadata("killstreak", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new KillStreak(old + 1))); } }
@EventHandler public void onPgmSpawn(CardinalSpawnEvent event) { try { event.getPlayer().removeMetadata("killstreak", Cardinal.getInstance()); } catch (NullPointerException e) { } event.getPlayer().setMetadata("killstreak", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new KillStreak(0))); }
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); TeamModule team = TeamUtils.getTeamByPlayer(player); if (team != null && !team.isObserver()) { int oldMeta = this.getLives(player); player.removeMetadata("lives", Cardinal.getInstance()); player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(oldMeta - 1))); if (this.getLives(player) == 0) { TeamUtils.getTeamById("observers").add(player, true); player.removeMetadata("lives", Cardinal.getInstance()); } } }
@EventHandler public void onPgmSpawn(CardinalSpawnEvent event) { if (event.isCancelled()) return; try { event.getPlayer().removeMetadata("killstreak", Cardinal.getInstance()); } catch (NullPointerException e) { } event.getPlayer().setMetadata("killstreak", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new KillStreak(0))); }
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); Optional<TeamModule> team = Teams.getTeamByPlayer(player); if (team.isPresent() && !team.get().isObserver()) { int oldMeta = this.getLives(player); player.removeMetadata("lives", Cardinal.getInstance()); player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(oldMeta - 1))); if (this.getLives(player) == 0) { Teams.getTeamById("observers").get().add(player, true, false); player.removeMetadata("lives", Cardinal.getInstance()); } } }
public GameLazyMetadata(GameBase game, LazyMetadataValue.CacheStrategy cacheStrategy, Callable<Object> lazyValue) { super(game.fakePlugin, cacheStrategy, lazyValue); }
public static MetadataValue makeValue(Object data) { return new LazyMetadataValue(StoaPlugin.getInst(), new MetaCallable(data)); }
public LazyMetadataValue(Plugin owningPlugin, Callable<Object> lazyValue) { super(owningPlugin); }
public LazyMetadataValue(Plugin owningPlugin, LazyMetadataValue.CacheStrategy cacheStrategy, Callable<Object> lazyValue) { super(owningPlugin); }
protected LazyMetadataValue(Plugin owningPlugin) { super(owningPlugin); }