org.spongepowered.api.data.key.Keys Java Examples

The following examples show how to use org.spongepowered.api.data.key.Keys. 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: StatVariable.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public Text replace(Text text, @Nullable Object player) {
    if (player instanceof Player) {
        Player p = (Player) player;
        for (String var : TextUtil.getVariables(text)) {
            if (var.startsWith("%stat:")) {
                try {
                    String stat = var.replace("%", "").split(":")[1];
                    Long value = p.get(Keys.STATISTICS).get().get(Sponge.getRegistry().getType(Statistic.class, stat).get());
                    if (value == null) value = 0L;
                    text = TextUtil.replace(text, var, Messages.toText(value + ""));
                } catch (Exception ex) {
                    text = TextUtil.replace(text, var, Text.of());
                }
            }
        }
    }
    return text;
}
 
Example #2
Source File: WalkspeedCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    Double speed = args.<Double>getOne("speed").get();
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.WALKING_SPEED, speed / walkmultiplier);
        Messages.send(p, "fly.command.walkspeed.success.self", "%speed%", speed);
        return CommandResult.success();
    } else {
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.WALKING_SPEED, speed / walkmultiplier);
        Messages.send(sender, "fly.command.walkspeed.success.others.self", "%player%", VariableUtil.getNameEntity(t), "%speed%", speed);
        Messages.send(t, "fly.command.walkspeed.success.others.self", "%player%", sender, "%speed%", speed);
        return CommandResult.success();
    }
}
 
Example #3
Source File: SurvivalCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_BASE);
    checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_SELF_SURVIVAL);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
        Messages.send(sender, "gamemode.command.gamemode.success", "%gamemode%", "survival");
        return CommandResult.success();
    } else {
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_BASE);
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_SURVIVAL);
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
        Messages.send(t, "gamemode.command.gamemode.success.others", "%sender%", sender, "%gamemode%", "survival");
        Messages.send(sender, "gamemode.command.gamemode.success.self", "%player%", t, "%gamemode%", "survival");
        return CommandResult.success();
    }
}
 
Example #4
Source File: VersionHelper56.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public long getInvValue(Iterable<Inventory> inv) {
    long value = 0;
    for (Inventory item : inv) {
        if (!item.peek().isPresent()) {
            continue;
        }
        ItemStack stack = item.peek().get();
        value += ((RedProtect.get().config.ecoRoot().items.values.get(stack.getItem().getName()) * stack.getQuantity()));
        if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()) {
            for (ItemEnchantment enchant : stack.get(Keys.ITEM_ENCHANTMENTS).get()) {
                value += ((RedProtect.get().config.ecoRoot().enchantments.values.get(enchant.getEnchantment().getName()) * enchant.getLevel()));
            }
        }
    }
    return value;
}
 
Example #5
Source File: WandCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to get wand tool"))
            .permission("redprotect.command.wand")
            .executor((src, args) -> {
                if (!(src instanceof Player)) {
                    HandleHelpPage(src, 1);
                } else {
                    Player player = (Player) src;
                    if (RedProtect.get().config.getWorldClaimType(player.getWorld().getName()).equalsIgnoreCase("BLOCK") && !RedProtect.get().ph.hasPerm(player, "redprotect.command.admin.wand"))
                        return CommandResult.success();

                    Inventory inv = player.getInventory();
                    ItemType mat = Sponge.getRegistry().getType(ItemType.class, RedProtect.get().config.configRoot().wands.adminWandID).orElse(ItemTypes.GLASS_BOTTLE);
                    ItemStack item = ItemStack.of(mat, 1);
                    item.offer(Keys.ITEM_ENCHANTMENTS, new ArrayList<>());

                    if (inv.query(Hotbar.class).offer(item).getType().equals(InventoryTransactionResult.Type.SUCCESS)) {
                        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.given").replace("{item}", mat.getName()));
                    } else {
                        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName()));
                    }
                }
                return CommandResult.success();
            }).build();
}
 
Example #6
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
private void applyFlag(String flag, ItemStack item, ClickInventoryEvent event) {
    if (this.region.setFlag(RedProtect.get().getVersionHelper().getCause(this.player), flag, !this.region.getFlagBool(flag))) {
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + flag + "'") + " " + this.region.getFlagBool(flag));

        if (!this.region.getFlagBool(flag)) {
            item.remove(Keys.ITEM_ENCHANTMENTS);
        } else {
            item = RedProtect.get().getVersionHelper().offerEnchantment(item);
        }
        item.offer(Keys.HIDE_ENCHANTMENTS, true);
        item.offer(Keys.HIDE_ATTRIBUTES, true);

        List<Text> lore = new ArrayList<>(Arrays.asList(
                Text.joinWith(Text.of(" "), RedProtect.get().guiLang.getFlagString("value"), RedProtect.get().guiLang.getFlagString(region.getFlags().get(flag).toString())),
                RedProtect.get().getUtil().toText("&0" + flag)));
        lore.addAll(RedProtect.get().guiLang.getFlagDescription(flag));
        item.offer(Keys.ITEM_LORE, lore);

        event.getCursorTransaction().setCustom(ItemStackSnapshot.NONE);
        event.getTransactions().get(0).getSlot().offer(item);

        RedProtect.get().getVersionHelper().removeGuiItem(this.player);

        RedProtect.get().logger.addLog("(World " + this.region.getWorld() + ") Player " + player.getName() + " CHANGED flag " + flag + " of region " + this.region.getName() + " to " + this.region.getFlagString(flag));
    }
}
 
Example #7
Source File: VersionHelper7.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public long getInvValue(Iterable<Inventory> inv) {
    long value = 0;
    for (Inventory item : inv) {
        if (!item.peek().isPresent()) {
            continue;
        }
        ItemStack stack = item.peek().get();
        value += ((RedProtect.get().config.ecoRoot().items.values.get(stack.getType().getName()) * stack.getQuantity()));
        if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()) {
            for (Enchantment enchant : stack.get(Keys.ITEM_ENCHANTMENTS).get()) {
                value += ((RedProtect.get().config.ecoRoot().enchantments.values.get(enchant.getType().getName()) * enchant.getLevel()));
            }
        }
    }
    return value;
}
 
Example #8
Source File: VersionHelper8.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public long getInvValue(Iterable<Inventory> inv) {
    long value = 0;
    for (Inventory item : inv) {
        if (item.peek().isEmpty()) {
            continue;
        }
        ItemStack stack = item.peek();
        value += ((RedProtect.get().config.ecoRoot().items.values.get(stack.getType().getName()) * stack.getQuantity()));
        if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()) {
            for (Enchantment enchant : stack.get(Keys.ITEM_ENCHANTMENTS).get()) {
                value += ((RedProtect.get().config.ecoRoot().enchantments.values.get(enchant.getType().getName()) * enchant.getLevel()));
            }
        }
    }
    return value;
}
 
Example #9
Source File: SigneditCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    Player p = (Player) sender;

    int line = args.<Integer>getOne("line").get();
    Text text = VariableUtil.replaceVariables(Messages.toText(args.<String>getOne("text").get()), sender);

    try {
        BlockSelectionTask task = new BlockSelectionTask();
        task.select(p,
                (loc) -> loc.getTileEntity().isPresent() && loc.getTileEntity().get() instanceof Sign,
                (loc) -> {
                    Sign sign = (Sign) loc.getTileEntity().get();
                    sign.offer(Keys.SIGN_LINES, sign.getSignData().lines().set(line - 1, text).get());
                    Messages.send(sender, "sign.command.signedit.success", "%line%", line, "%text%", text);
                });
        return CommandResult.success();
    } catch (Exception ex) {
        throw Messages.error(sender, "sign.command.signedit.nosign");
    }
}
 
Example #10
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onSignCreate(ChangeSignEvent event, @Root Player p) {
    //Sign colors
    List<Text> lines = event.getText().lines().get();
    lines.set(0, TextUtil.replaceColors(lines.get(0), p, "uc.sign"));
    lines.set(1, TextUtil.replaceColors(lines.get(1), p, "uc.sign"));
    lines.set(2, TextUtil.replaceColors(lines.get(2), p, "uc.sign"));
    lines.set(3, TextUtil.replaceColors(lines.get(3), p, "uc.sign"));
    event.getText().setElements(lines);

    //Registered signs
    for (UCSign sign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
        if (event.getText().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + sign.getIdentifier() + "]")) {
            if (!p.hasPermission(sign.getCreatePermission().get())) {
                Messages.send(p, "core.nopermissions");
            }
            SignCreateEvent cevent = new SignCreateEvent(sign, event.getTargetTile().getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
            Sponge.getEventManager().post(cevent);
            if (!cevent.isCancelled() && sign.onCreate(p, event)) {
                //Color sign
                event.getTargetTile().offer(Keys.SIGN_LINES, event.getText().setElement(0, Text.of(TextColors.AQUA, "[" + StringUtil.firstUpperCase(sign.getIdentifier()) + "]")).asList());
                Messages.send(p, "sign.create", "%sign%", sign.getIdentifier());
            }
        }
    }
}
 
Example #11
Source File: ItemcanplaceonCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMCANPLACEON_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    Set<BlockType> types = new HashSet<>(args.<BlockType>getAll("blocktypes"));

    stack.offer(Keys.PLACEABLE_BLOCKS, types);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Text items = Text.joinWith(Text.of(", "), types.stream().map(type -> Text.of(type.getName())).collect(Collectors.toList()));
    Messages.send(sender, "item.command.itemcanplaceon.success", "%arg%", items);
    return CommandResult.success();
}
 
Example #12
Source File: ItemnameCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMNAME_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    Text name = Messages.toText(args.<String>getOne("name").get());
    stack.offer(Keys.DISPLAY_NAME, name);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemname.success", "%arg%", name);
    return CommandResult.success();
}
 
Example #13
Source File: ItemhidetagsCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandElement[] getArguments() {
    HashMap<String, Key<Value<Boolean>>> choices = new HashMap<>();
    choices.put("attribute", Keys.HIDE_ATTRIBUTES);
    choices.put("attributes", Keys.HIDE_ATTRIBUTES);
    choices.put("candestroy", Keys.HIDE_CAN_DESTROY);
    choices.put("canbreak", Keys.HIDE_CAN_DESTROY);
    choices.put("canplace", Keys.HIDE_CAN_PLACE);
    choices.put("canplaceon", Keys.HIDE_CAN_PLACE);
    choices.put("ench", Keys.HIDE_ENCHANTMENTS);
    choices.put("enchantment", Keys.HIDE_ENCHANTMENTS);
    choices.put("enchantments", Keys.HIDE_ENCHANTMENTS);
    choices.put("misc", Keys.HIDE_MISCELLANEOUS);
    choices.put("miscellaneous", Keys.HIDE_MISCELLANEOUS);
    choices.put("unbreakable", Keys.HIDE_UNBREAKABLE);

    return new CommandElement[]{
            Arguments.builder(new ChoicesArgument(Text.of("tag"), choices)).onlyOne().usage("attributes/candestroy/canplaceon/enchantments/miscellaneous/unbreakable").build(),
            Arguments.builder(new BooleanArgument(Text.of("enabled"))).usageKey("Enable/Disable").onlyOne().build()
    };
}
 
Example #14
Source File: ItemunbreakableCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMUNBREAKABLE_BASE);
    Player p = (Player) sender;

    Boolean value = args.<Boolean>getOne("enabled/disabled").get();

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    if (!stack.supports(Keys.UNBREAKABLE)) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.command.itemunbreakable.notsupported"));
    }

    stack.offer(Keys.UNBREAKABLE, value);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemunbreakable.success", "%arg%", value);
    return CommandResult.success();
}
 
Example #15
Source File: ItemloreCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMLORE_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    Text unsplitlore = Messages.toText(args.<String>getOne("lore").get());
    stack.offer(Keys.ITEM_LORE, unsplitlore.toPlain().contains("|") ? TextUtil.split(unsplitlore, "|") : Arrays.asList(unsplitlore));
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemlore.success", "%arg%", unsplitlore);
    return CommandResult.success();
}
 
Example #16
Source File: FoodCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, FoodPermissions.UC_FOOD_FOOD_BASE);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.FOOD_LEVEL, p.get(FoodData.class).get().foodLevel().getMaxValue());
        p.offer(Keys.SATURATION, ItemStack.builder().itemType(ItemTypes.COOKED_BEEF).build().getProperty(SaturationProperty.class).get().getValue());
        Messages.send(p, "food.command.food.success.self");
        return CommandResult.success();
    } else {
        checkPermission(sender, FoodPermissions.UC_FOOD_FOOD_OTHERS);
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.FOOD_LEVEL, t.get(FoodData.class).get().foodLevel().getMaxValue());
        t.offer(Keys.SATURATION, ItemStack.builder().itemType(ItemTypes.COOKED_BEEF).build().getProperty(SaturationProperty.class).get().getValue());
        Messages.send(sender, "food.command.food.success.others.self", "%player%", t);
        Messages.send(t, "food.command.food.success.others.others", "%player%", sender);
        return CommandResult.success();
    }
}
 
Example #17
Source File: SpectatorCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_BASE);
    checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_SELF_SPECTATOR);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
        Messages.send(sender, "gamemode.command.gamemode.success", "%gamemode%", "spectator");
        return CommandResult.success();
    } else {
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_BASE);
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_SPECTATOR);
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
        Messages.send(t, "gamemode.command.gamemode.success.others", "%sender%", sender, "%gamemode%", "spectator");
        Messages.send(sender, "gamemode.command.gamemode.success.self", "%player%", t, "%gamemode%", "spectator");
        return CommandResult.success();
    }
}
 
Example #18
Source File: ItemdurabilityCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMDURABILITY_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    int durability = args.<Integer>getOne("durability").get();

    if (!stack.supports(DurabilityData.class)) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.command.itemdurability.notsupported"));
    }

    if (durability < stack.get(DurabilityData.class).get().durability().getMinValue() || durability > stack.get(DurabilityData.class).get().durability().getMaxValue()) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.numberinvalid", "%number%", durability));
    }

    stack.offer(Keys.ITEM_DURABILITY, durability);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemdurability.success", "%arg%", durability);
    return CommandResult.success();
}
 
Example #19
Source File: CommonEntityEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
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 #20
Source File: NamesHandler.java    From UltimateCore with MIT License 5 votes vote down vote up
public void update() {
    ModuleConfig config = Modules.TABLIST.get().getConfig().get();
    boolean enablenames = config.get().getNode("names", "enable").getBoolean();
    boolean compatibility = config.get().getNode("names", "compatibility-mode").getBoolean();
    boolean showvanished = config.get().getNode("names", "show-vanished").getBoolean(false);
    boolean updated = false;
    HeaderFooterHandler.handleHeaderFooter();
    if (!enablenames) {
        return;
    }

    //Add new players
    for (Player p : Sponge.getServer().getOnlinePlayers()) {
        if(p.get(Keys.VANISH).orElse(false) && !showvanished){
            continue;
        }
        if (!this.names.containsKey(p.getUniqueId())) {
            this.names.put(p.getUniqueId(), getDetails(p));
            updated = true;
        }
    }

    //Remove old players
    List<UUID> removenames = this.names.keySet().stream().filter(uuid -> !Sponge.getServer().getPlayer(uuid).isPresent()).collect(Collectors.toList());
    removenames.forEach(this::removeCache);

    //Resort map if needed
    if (updated) {
        resortNamesList();
    }

    //Update tablists
    if (compatibility) {
        refreshCompat();
    } else {
        refreshNormal();
    }
}
 
Example #21
Source File: Region.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public boolean cmdOnHealth(Player p) {
    if (!flagExists("cmd-onhealth")) {
        return false;
    }

    boolean run = false;
    //rp flag cmd-onhealth health:<number> cmd:<cmd>, ...
    for (String group : getFlagString("cmd-onhealth").split(",")) {
        int health = Integer.parseInt(group.split(" ")[0].substring(7));
        String cmd = group.replace(group.split(" ")[0] + " ", "").substring(4);
        if (cmd.startsWith("/")) {
            cmd = cmd.substring(1);
        }
        boolean waiting = false;
        if (p.get(Keys.HEALTH).get() <= health && !waiting) {
            Sponge.getGame().getCommandManager().process(RedProtect.get().getServer().getConsole(), cmd.replace("{player}", p.getName()));
			/*waiting = true;
			Bukkit.getScheduler().runTaskLater(RedProtect.get().plugin, new Runnable(){
	@Override
	public void run() {
		waiting = false;
	}    				
			}, 20);*/
            run = true;
        }
    }
    return run;
}
 
Example #22
Source File: GriefPreventionPlugin.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void checkPvpProtectionNeeded(Player player) {
    // if anti spawn camping feature is not enabled, do nothing
    if (!GriefPreventionPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().pvp.protectFreshSpawns) {
        return;
    }

    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    // if pvp rules are disabled in claim, do nothing
    if (!claim.pvpRulesApply()) {
        return;
    }

    // if player is in creative mode, do nothing
    if (player.get(Keys.GAME_MODE).get() == GameModes.CREATIVE) {
        return;
    }

    // if the player has the damage any player permission enabled, do nothing
    if (player.hasPermission(GPPermissions.NO_PVP_IMMUNITY)) {
        return;
    }

    // check inventory for well, anything
    if (GriefPreventionPlugin.isInventoryEmpty(player)) {
        // if empty, apply immunity
        playerData.pvpImmune = true;

        // inform the player after he finishes respawning
        GriefPreventionPlugin.sendMessage(player, this.messageData.pvpImmunityStart.toText());

        // start a task to re-check this player's inventory every minute
        // until his immunity is gone
        PvPImmunityValidationTask task = new PvPImmunityValidationTask(player);
        Sponge.getGame().getScheduler().createTaskBuilder().delay(1, TimeUnit.MINUTES).execute(task).submit(this);
    }
}
 
Example #23
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event) {
    if (event.getTargetInventory().getName().get().equals(this.inv.getName().get())) {
        if (this.editable) {
            for (int i = 0; i < this.size; i++) {
                try {
                    int line = 0;
                    int slot = i;
                    if (i > 8) {
                        line = i / 9;
                        slot = i - (line * 9);
                    }
                    if (RedProtect.get().getVersionHelper().query(event.getTargetInventory(), slot, line).peek().isPresent()) {
                        final int fi = i;
                        ItemStack stack = RedProtect.get().getVersionHelper().query(event.getTargetInventory(), slot, line).peek().get();
                        stack.get(Keys.ITEM_LORE).ifPresent(ls -> {
                            String flag = ls.get(1).toPlain().replace("ยง0", "");
                            if (RedProtect.get().config.getDefFlags().contains(flag))
                                RedProtect.get().config.setGuiSlot(flag, fi);
                        });
                    }
                } catch (Exception e) {
                    RedProtect.get().lang.sendMessage(this.player, "gui.edit.error");
                    close(false);
                    CoreUtil.printJarVersion();
                    e.printStackTrace();
                    return;
                }
            }
            RedProtect.get().config.saveGui();
            RedProtect.get().lang.sendMessage(this.player, "gui.edit.ok");
        }
        close(false);
    }
}
 
Example #24
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerTrownPotion(LaunchProjectileEvent e) {

    Entity ent = e.getTargetEntity();
    RedProtect.get().logger.debug(LogLevel.PLAYER, "Is PotionSplashEvent event.");

    Region r = RedProtect.get().rm.getTopRegion(ent.getLocation(), this.getClass().getName());
    if (ent instanceof ThrownPotion) {

        ThrownPotion potion = (ThrownPotion) e.getTargetEntity();
        ProjectileSource thrower = potion.getShooter();

        if (thrower instanceof Player) {
            if (r != null && !r.usePotions((Player) thrower)) {
                RedProtect.get().lang.sendMessage((Player) thrower, "playerlistener.region.cantuse");
                e.setCancelled(true);
                return;
            }
        }

        List<PotionEffect> pottypes = potion.get(Keys.POTION_EFFECTS).get();
        //deny potion
        List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).deny_potions;
        if (!Pots.isEmpty()) {
            for (PotionEffect t : pottypes) {
                if (Pots.contains(t.getType().getName().toUpperCase())) {
                    e.setCancelled(true);
                    if (thrower instanceof Player) {
                        RedProtect.get().lang.sendMessage((Player) thrower, RedProtect.get().lang.get("playerlistener.denypotion"));
                    }
                    break;
                }
            }
        }

    }
}
 
Example #25
Source File: VersionHelper7.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkHorseOwner(Entity ent, Player p) {
    if (ent instanceof RideableHorse && ((RideableHorse) ent).getHorseData().get(Keys.TAMED_OWNER).isPresent()) {
        RideableHorse tam = (RideableHorse) ent;
        Player owner = RedProtect.get().getServer().getPlayer(tam.getHorseData().get(Keys.TAMED_OWNER).get().get()).get();
        return owner.getName().equals(p.getName());
    }
    return false;
}
 
Example #26
Source File: UCVHelper7.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
@Override
public StringBuilder getEnchantments(StringBuilder str, ItemStack item) {
    for (Enchantment enchant : item.get(Keys.ITEM_ENCHANTMENTS).get()) {
        str.append("\n ").append(enchant.getType().getTranslation().get()).append(": ").append(enchant.getLevel());
    }
    return str;
}
 
Example #27
Source File: VersionHelper8.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkHorseOwner(Entity ent, Player p) {
    if (ent instanceof RideableHorse && ((RideableHorse) ent).getHorseData().get(Keys.TAMED_OWNER).isPresent()) {
        RideableHorse tam = (RideableHorse) ent;
        Player owner = RedProtect.get().getServer().getPlayer(tam.getHorseData().get(Keys.TAMED_OWNER).get().get()).get();
        return owner.getName().equals(p.getName());
    }
    return false;
}
 
Example #28
Source File: UCVHelper8.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
@Override
public StringBuilder getEnchantments(StringBuilder str, ItemStack item) {
    for (Enchantment enchant : item.get(Keys.ITEM_ENCHANTMENTS).get()) {
        str.append("\n ").append(enchant.getType().getTranslation().get()).append(": ").append(enchant.getLevel());
    }
    return str;
}
 
Example #29
Source File: SkinApplier.java    From ChangeSkin with MIT License 5 votes vote down vote up
private void sendUpdate() {
    sendUpdateSelf();

    //triggers an update for others player to see the new skin
    receiver.offer(Keys.VANISH, true);
    receiver.offer(Keys.VANISH, false);
}
 
Example #30
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onConsume(UseItemStackEvent.Start e, @First Player p) {
    ItemStack stack = e.getItemStackInUse().createStack();
    RedProtect.get().logger.debug(LogLevel.PLAYER, "Is UseItemStackEvent.Start event. Item: " + RedProtect.get().getVersionHelper().getItemType(stack).getName());

    //deny potion
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_potions;

    if (stack.get(Keys.POTION_EFFECTS).isPresent() && Pots.size() > 0) {
        List<PotionEffect> pot = stack.get(Keys.POTION_EFFECTS).get();
        for (PotionEffect pots : pot) {
            if (Pots.contains(pots.getType().getName().toUpperCase()) && !p.hasPermission("redprotect.bypass")) {
                e.setCancelled(true);
                RedProtect.get().lang.sendMessage(p, "playerlistener.denypotion");
            }
        }
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation(), this.getClass().getName());

    if (r != null && RedProtect.get().getVersionHelper().getItemType(stack).equals(ItemTypes.POTION) && !r.usePotions(p)) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
        e.setCancelled(true);
    }

    if (r != null && RedProtect.get().getVersionHelper().getItemType(stack).getName().equals("minecraft:chorus_fruit") && !r.canTeleport(p)) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
        e.setCancelled(true);
    }
}