Java Code Examples for org.spongepowered.api.entity.living.player.Player#getWorld()
The following examples show how to use
org.spongepowered.api.entity.living.player.Player#getWorld() .
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: MCClansEventHandler.java From GriefDefender with MIT License | 6 votes |
public void onClanCreate(ClanCreateEvent event) { if (!GriefDefenderPlugin.getGlobalConfig().getConfig().town.clanRequireTown) { return; } final Player player = Sponge.getServer().getPlayer(event.getOwner().getUUID()).orElse(null); if (player == null) { return; } final World world = player.getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) { return; } final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(world, player.getUniqueId()); for (Claim claim : playerData.getInternalClaims()) { if (claim.isTown()) { return; } } event.setCancelledWithMessage("You must own a town in order to create a clan."); }
Example 2
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 6 votes |
@Listener(order = Order.LAST, beforeModifications = true) public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) { if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) { return; } if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getTargetEntity(), player.getWorld().getProperties())) { return; } GDTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync(); final World world = player.getWorld(); GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId()); Location<World> location = player.getLocation(); GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location); if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) { event.setCancelled(true); } GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync(); }
Example 3
Source File: EconomyUtil.java From GriefDefender with MIT License | 6 votes |
public void economyCreateClaimConfirmation(Player player, GDPlayerData playerData, int height, Vector3i point1, Vector3i point2, ClaimType claimType, boolean cuboid, Claim parent) { GDClaim claim = new GDClaim(player.getWorld(), point1, point2, claimType, player.getUniqueId(), cuboid); claim.parent = (GDClaim) parent; final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player); final int claimCost = BlockUtil.getInstance().getClaimBlockCost(player.getWorld(), claim.lesserBoundaryCorner, claim.greaterBoundaryCorner, claim.cuboid); final Double economyBlockCost = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), user, Options.ECONOMY_BLOCK_COST, claim); final double requiredFunds = claimCost * economyBlockCost; final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_BUY_CONFIRMATION, ImmutableMap.of("amount", "$" + String.format("%.2f", requiredFunds))); final Component buyConfirmationText = TextComponent.builder() .append(message) .append(TextComponent.builder() .append("\n[") .append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN)) .append("]\n") .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(player, economyClaimBuyConfirmed(player, playerData, height, requiredFunds, point1, point2, claimType, cuboid, parent), true))).build()) .build(); GriefDefenderPlugin.sendMessage(player, buyConfirmationText); }
Example 4
Source File: TimeExecutor.java From EssentialCmds with MIT License | 6 votes |
private void addTime(CommandSource src, int ticks) { World world = null; if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else if (src instanceof CommandBlock) { CommandBlock commandBlock = (CommandBlock) src; world = commandBlock.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a in-game player to do /time!")); return; } world.getProperties().setWorldTime(world.getProperties().getWorldTime() + ticks); src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, world.getProperties().getWorldTime())); }
Example 5
Source File: ClaimCommand.java From EagleFactions with MIT License | 6 votes |
private CommandResult preformAdminClaim(final Player player, final Faction faction, final Vector3i chunk) throws CommandException { final World world = player.getWorld(); final boolean safeZoneWorld = this.protectionConfig.getSafeZoneWorldNames().contains(world.getName()); final boolean warZoneWorld = this.protectionConfig.getWarZoneWorldNames().contains(world.getName()); //Even admin cannot claim territories in safezone nor warzone world. if (safeZoneWorld || warZoneWorld) throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(TextColors.RED, Messages.YOU_CANNOT_CLAIM_TERRITORIES_IN_THIS_WORLD))); boolean isCancelled = EventRunner.runFactionClaimEvent(player, faction, player.getWorld(), chunk); if (isCancelled) return CommandResult.empty(); super.getPlugin().getFactionLogic().addClaim(faction, new Claim(player.getWorld().getUniqueId(), chunk)); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.LAND + " ", TextColors.GOLD, chunk.toString(), TextColors.WHITE, " " + Messages.HAS_BEEN_SUCCESSFULLY + " ", TextColors.GOLD, Messages.CLAIMED, TextColors.WHITE, "!")); return CommandResult.success(); }
Example 6
Source File: MCClansEventHandler.java From GriefPrevention with MIT License | 6 votes |
public void onClanCreate(ClanCreateEvent event) { if (!GriefPreventionPlugin.getGlobalConfig().getConfig().town.clanRequireTown) { return; } final Player player = Sponge.getServer().getPlayer(event.getOwner().getUUID()).orElse(null); if (player == null) { return; } final World world = player.getWorld(); if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return; } final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(world, player.getUniqueId()); for (Claim claim : playerData.getInternalClaims()) { if (claim.isTown()) { return; } } event.setCancelledWithMessage("You must own a town in order to create a clan."); }
Example 7
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteractItem(InteractItemEvent event, @Root Player player) { if (event instanceof InteractItemEvent.Primary) { lastInteractItemPrimaryTick = Sponge.getServer().getRunningTimeTicks(); } else { lastInteractItemSecondaryTick = Sponge.getServer().getRunningTimeTicks(); } final World world = player.getWorld(); final HandInteractEvent handEvent = (HandInteractEvent) event; final ItemStack itemInHand = player.getItemInHand(handEvent.getHandType()).orElse(ItemStack.empty()); handleItemInteract(handEvent, player, world, itemInHand); }
Example 8
Source File: TPChunkExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { int x = ctx.<Integer> getOne("x").get(); int z = ctx.<Integer> getOne("z").get(); if (src instanceof Player) { Player player = (Player) src; Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation()); if (Sponge.getServer().getChunkLayout().isValidChunk(new Vector3i(x, 0, z))) { Location<World> location = new Location<World>(player.getWorld(), Sponge.getServer().getChunkLayout().forceToWorld(new Vector3i(x, 0, z))); player.setLocation(location); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to chunk.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Invalid chunk!")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport, you are not a player!")); } return CommandResult.success(); }
Example 9
Source File: WorldsBase.java From EssentialCmds with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { GameMode gamemode = ctx.<GameMode> getOne("gamemode").get(); Optional<String> worldName = ctx.<String> getOne("world"); World world = null; if (worldName.isPresent()) { world = Sponge.getServer().getWorld(worldName.get()).orElse(null); } else { if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player or specify the world name to set its gamemode!")); } } if (world != null) { world.getProperties().setGameMode(gamemode); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Set gamemode of world.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!")); } return CommandResult.success(); }
Example 10
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteractItem(InteractItemEvent event, @Root Player player) { final World world = player.getWorld(); final HandInteractEvent handEvent = (HandInteractEvent) event; final ItemStack itemInHand = player.getItemInHand(handEvent.getHandType()).orElse(ItemStack.empty()); handleItemInteract(event, player, world, itemInHand); }
Example 11
Source File: PlayerInteractListener.java From EagleFactions with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onItemUse(final InteractItemEvent event, @Root final Player player) { if (event.getItemStack() == ItemStackSnapshot.NONE) return; final Vector3d interactionPoint = event.getInteractionPoint().orElse(player.getLocation().getPosition()); Location<World> location = new Location<>(player.getWorld(), interactionPoint); //Handle hitting entities boolean hasHitEntity = event.getContext().containsKey(EventContextKeys.ENTITY_HIT); if(hasHitEntity) { final Entity hitEntity = event.getContext().get(EventContextKeys.ENTITY_HIT).get(); if (hitEntity instanceof Living && !(hitEntity instanceof ArmorStand)) return; location = hitEntity.getLocation(); } final ProtectionResult protectionResult = super.getPlugin().getProtectionManager().canUseItem(location, player, event.getItemStack(), true); if (!protectionResult.hasAccess()) { event.setCancelled(true); return; } }
Example 12
Source File: ParticlesUtil.java From EagleFactions with MIT License | 5 votes |
public HomeParticles(final Player player) { this.player = player; this.world = player.getWorld(); this.location = player.getLocation(); this.lastBlockPosition = player.getLocation().getBlockPosition(); }
Example 13
Source File: ClaimCommand.java From EagleFactions with MIT License | 5 votes |
private CommandResult preformNormalClaim(final Player player, final Faction faction, final Vector3i chunk) throws CommandException { final World world = player.getWorld(); final boolean isClaimableWorld = this.protectionConfig.getClaimableWorldNames().contains(world.getName()); if(!isClaimableWorld) throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(TextColors.RED, Messages.YOU_CANNOT_CLAIM_TERRITORIES_IN_THIS_WORLD))); //If not admin then check faction perms for player if (!this.getPlugin().getPermsManager().canClaim(player.getUniqueId(), faction)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PLAYERS_WITH_YOUR_RANK_CANT_CLAIM_LANDS)); //Check if faction has enough power to claim territory if (super.getPlugin().getPowerManager().getFactionMaxClaims(faction) <= faction.getClaims().size()) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOUR_FACTION_DOES_NOT_HAVE_POWER_TO_CLAIM_MORE_LANDS)); //If attacked then It should not be able to claim territories if (EagleFactionsPlugin.ATTACKED_FACTIONS.containsKey(faction.getName())) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOUR_FACTION_IS_UNDER_ATTACK + " " + MessageLoader.parseMessage(Messages.YOU_NEED_TO_WAIT_NUMBER_MINUTES_TO_BE_ABLE_TO_CLAIM_AGAIN, TextColors.RED, Collections.singletonMap(Placeholders.NUMBER, Text.of(TextColors.GOLD, EagleFactionsPlugin.ATTACKED_FACTIONS.get(faction.getName())))))); if (this.factionsConfig.requireConnectedClaims() && !super.getPlugin().getFactionLogic().isClaimConnected(faction, new Claim(world.getUniqueId(), chunk))) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.CLAIMS_NEED_TO_BE_CONNECTED)); boolean isCancelled = EventRunner.runFactionClaimEvent(player, faction, world, chunk); if (isCancelled) return CommandResult.empty(); super.getPlugin().getFactionLogic().startClaiming(player, faction, world.getUniqueId(), chunk); return CommandResult.success(); }
Example 14
Source File: ClaimCommand.java From EagleFactions with MIT License | 5 votes |
private CommandResult preformClaimByFaction(final Player player, final Faction faction, final Vector3i chunk) throws CommandException { final World world = player.getWorld(); final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId()); final boolean isClaimableWorld = this.protectionConfig.getClaimableWorldNames().contains(world.getName()); if(!optionalPlayerFaction.isPresent() || !optionalPlayerFaction.get().getName().equals(faction.getName())) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_DONT_HAVE_ACCESS_TO_DO_THIS)); if(!isClaimableWorld) throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(TextColors.RED, Messages.YOU_CANNOT_CLAIM_TERRITORIES_IN_THIS_WORLD))); return preformNormalClaim(player, faction, chunk); }
Example 15
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.LAST, beforeModifications = true) public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) { if (!GPFlags.ITEM_PICKUP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) { return; } if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_PICKUP.toString(), event.getTargetEntity(), player.getWorld().getProperties())) { return; } GPTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync(); final World world = player.getWorld(); GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId()); Location<World> location = player.getLocation(); GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location); if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_PICKUP, player, event.getTargetEntity(), player, TrustType.ACCESSOR, true) == Tristate.FALSE) { event.setCancelled(true); GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync(); return; } // the rest of this code is specific to pvp worlds if (claim.pvpRulesApply()) { // if we're preventing spawn camping and the player was previously empty handed... if (GriefPreventionPlugin.getActiveConfig(world.getProperties()).getConfig().pvp.protectFreshSpawns && PlayerUtils.hasItemInOneHand(player, ItemTypes.NONE)) { // if that player is currently immune to pvp if (playerData.pvpImmune) { // if it's been less than 10 seconds since the last time he spawned, don't pick up the item long now = Calendar.getInstance().getTimeInMillis(); long elapsedSinceLastSpawn = now - playerData.lastSpawn; if (elapsedSinceLastSpawn < 10000) { event.setCancelled(true); GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync(); return; } // otherwise take away his immunity. he may be armed now. at least, he's worth killing for some loot playerData.pvpImmune = false; GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.pvpImmunityEnd.toText()); } } } GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync(); }
Example 16
Source File: WorldsBase.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Optional<String> worldName = ctx.<String> getOne("world"); World world; if (worldName.isPresent()) { if (Sponge.getServer().getWorld(worldName.get()).isPresent()) { world = Sponge.getServer().getWorld(worldName.get()).get(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!")); return CommandResult.empty(); } } else { if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /world difficulty!")); return CommandResult.empty(); } } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); ArrayList<Text> gameruleText = Lists.newArrayList(); for (Entry<String, String> gamerule : world.getGameRules().entrySet()) { Text item = Text.builder(gamerule.getKey()) .onHover(TextActions.showText(Text.of(TextColors.WHITE, "Value ", TextColors.GOLD, gamerule.getValue()))) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); gameruleText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(gameruleText).title(Text.of(TextColors.GREEN, "Showing Gamerules")).padding(Text.of("-")); paginationBuilder.sendTo(src); return CommandResult.success(); }
Example 17
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteract(InteractEvent e, @Root Player p) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is InteractEvent event! Cancelled? " + false); if (!e.getInteractionPoint().isPresent()) { return; } Location<World> loc = new Location<>(p.getWorld(), e.getInteractionPoint().get()); Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName()); if (!canUse(p, r)) { e.setCancelled(true); return; } if (r != null) { return; } if (e instanceof InteractBlockEvent) { BlockSnapshot blockSnapshot = ((InteractBlockEvent) e).getTargetBlock(); if (RedProtect.get().config.needClaimToInteract(p, blockSnapshot)) { e.setCancelled(true); return; } } if (e instanceof InteractEntityEvent) { Entity ent = ((InteractEntityEvent) e).getTargetEntity(); RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener - Entity: " + ent.getType().getName()); if (ent instanceof Minecart || ent instanceof Boat) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); return; } } if (ent instanceof Hanging || ent instanceof ArmorStand) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); return; } } if (ent instanceof Monster && !RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).if_interact_false.entity_monsters && !p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); return; } if (ent instanceof Animal || ent instanceof Golem || ent instanceof Ambient || ent instanceof Aquatic) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).if_interact_false.entity_passives && !p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); return; } } if ((loc.getBlock().getType().equals(BlockTypes.PUMPKIN_STEM) || loc.getBlock().getType().equals(BlockTypes.MELON_STEM) || loc.getBlock().getType().getName().contains("chorus_") || loc.getBlock().getType().getName().contains("beetroot_") || loc.getBlock().getType().getName().contains("sugar_cane")) && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).allow_crop_trample && !p.hasPermission("redprotect.bypass.world")) { e.setCancelled(true); return; } if (!RedProtect.get().config.globalFlagsRoot().worlds.get(ent.getWorld().getName()).interact) { if (!p.hasPermission("redprotect.world.bypass") && !(ent instanceof Player)) { if (!canInteractEntitiesList(p.getWorld(), ent.getType().getName())) { e.setCancelled(true); return; } } } } if (e instanceof InteractBlockEvent) { InteractBlockEvent eb = (InteractBlockEvent) e; String bname = eb.getTargetBlock().getState().getType().getName(); RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Block: " + bname); if (bname.contains("rail") || bname.contains("water")) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); } } else { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).interact) { if (!p.hasPermission("redprotect.world.bypass")) { if (!canInteractBlocksList(p.getWorld(), bname)) { e.setCancelled(true); return; } } } if ((!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).build && !p.hasPermission("redprotect.world.bypass")) && bname.contains("leaves")) { e.setCancelled(true); } } } }
Example 18
Source File: SetHomeCommand.java From EagleFactions with MIT License | 4 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException { if(!(source instanceof Player)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND)); final Player player = (Player)source; final Optional<Faction> optionalPlayerFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId()); if (!optionalPlayerFaction.isPresent()) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND)); final Faction playerFaction = optionalPlayerFaction.get(); final World world = player.getWorld(); final FactionHome newHome = new FactionHome(world.getUniqueId(), new Vector3i(player.getLocation().getBlockPosition())); if(super.getPlugin().getPlayerManager().hasAdminMode(player)) { super.getPlugin().getFactionLogic().setHome(playerFaction, newHome); source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HOME_HAS_BEEN_SET)); return CommandResult.success(); } if(playerFaction.getLeader().equals(player.getUniqueId()) || playerFaction.getOfficers().contains(player.getUniqueId())) { final Optional<Faction> chunkFaction = super.getPlugin().getFactionLogic().getFactionByChunk(world.getUniqueId(), player.getLocation().getChunkPosition()); if (!chunkFaction.isPresent() && this.factionsConfig.canPlaceHomeOutsideFactionClaim()) { super.getPlugin().getFactionLogic().setHome(playerFaction, newHome); source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HOME_HAS_BEEN_SET)); } else if (!chunkFaction.isPresent() && !this.factionsConfig.canPlaceHomeOutsideFactionClaim()) { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.FACTION_HOME_MUST_BE_PLACED_INSIDE_FACTION_TERRITORY)); } else if(chunkFaction.isPresent() && chunkFaction.get().getName().equals(playerFaction.getName())) { super.getPlugin().getFactionLogic().setHome(playerFaction, newHome); source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HOME_HAS_BEEN_SET)); } else { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.THIS_LAND_BELONGS_TO_SOMEONE_ELSE)); } } else { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS)); } return CommandResult.success(); }
Example 19
Source File: MapCommand.java From EagleFactions with MIT License | 4 votes |
private Consumer<CommandSource> claimByMap(Player player, Vector3i chunk) { return consumer -> { //Because faction could have changed we need to get it again here. final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId()); final World world = player.getWorld(); final Claim claim = new Claim(player.getWorld().getUniqueId(), chunk); final boolean hasFactionsAdminMode = super.getPlugin().getPlayerManager().hasAdminMode(player); if(!optionalPlayerFaction.isPresent()) { player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND)); return; } final Faction playerFaction = optionalPlayerFaction.get(); final boolean hasClaimPermission = super.getPlugin().getPermsManager().canClaim(player.getUniqueId(), playerFaction); final boolean isFactionAttacked = EagleFactionsPlugin.ATTACKED_FACTIONS.containsKey(playerFaction.getName()); if(!hasFactionsAdminMode && !hasClaimPermission) { player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PLAYERS_WITH_YOUR_RANK_CANT_CLAIM_LANDS)); return; } //If claimed then unclaim if(super.getPlugin().getFactionLogic().isClaimed(world.getUniqueId(), chunk)) { //Check if faction's home was set in this claim. If yes then remove it. if (playerFaction.getHome() != null) { if (world.getUniqueId().equals(playerFaction.getHome().getWorldUUID())) { final Location<World> homeLocation = world.getLocation(playerFaction.getHome().getBlockPosition()); if (homeLocation.getChunkPosition().toString().equals(player.getLocation().getChunkPosition().toString())) { super.getPlugin().getFactionLogic().setHome(playerFaction, null); } } } super.getPlugin().getFactionLogic().removeClaim(playerFaction, new Claim(world.getUniqueId(), chunk)); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.LAND_HAS_BEEN_SUCCESSFULLY_UNCLAIMED)); } else { if(isFactionAttacked) { player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOUR_FACTION_IS_UNDER_ATTACK + " " + MessageLoader.parseMessage(Messages.YOU_NEED_TO_WAIT_NUMBER_MINUTES_TO_BE_ABLE_TO_CLAIM_AGAIN, TextColors.RED, Collections.singletonMap(Placeholders.NUMBER, Text.of(TextColors.GOLD, EagleFactionsPlugin.ATTACKED_FACTIONS.get(playerFaction.getName())))))); return; } if(super.getPlugin().getPowerManager().getFactionMaxClaims(playerFaction) <= playerFaction.getClaims().size()) { player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOUR_FACTION_DOES_NOT_HAVE_POWER_TO_CLAIM_MORE_LANDS)); return; } if (playerFaction.isSafeZone() || playerFaction.isWarZone()) { super.getPlugin().getFactionLogic().addClaim(playerFaction, claim); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.LAND + " ", TextColors.GOLD, chunk.toString(), TextColors.WHITE, " " + Messages.HAS_BEEN_SUCCESSFULLY + " ", TextColors.GOLD, Messages.CLAIMED, TextColors.WHITE, "!")); } else { if(this.factionsConfig.requireConnectedClaims()) { if(super.getPlugin().getFactionLogic().isClaimConnected(playerFaction, claim)) { super.getPlugin().getFactionLogic().startClaiming(player, playerFaction, world.getUniqueId(), chunk); } else { player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.CLAIMS_NEED_TO_BE_CONNECTED)); } } else { super.getPlugin().getFactionLogic().startClaiming(player, playerFaction, world.getUniqueId(), chunk); } } } generateMap(player); }; }
Example 20
Source File: TimeExecutor.java From EssentialCmds with MIT License | 4 votes |
public static void setTime(CommandSource src, CommandContext ctx) { Optional<String> timeString = ctx.<String> getOne("time"); Optional<Integer> timeTicks = ctx.<Integer> getOne("ticks"); World world = null; if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else if (src instanceof CommandBlock) { CommandBlock commandBlock = (CommandBlock) src; world = commandBlock.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a in-game player to do /time!")); return; } if (timeTicks.isPresent()) { world.getProperties().setWorldTime(timeTicks.get()); src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeTicks.get())); } else if (timeString.isPresent()) { if (timeString.get().toLowerCase().equals("dawn") || timeString.get().toLowerCase().equals("morning")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(0); } else if (timeString.get().toLowerCase().equals("day")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(1000); } else if (timeString.get().toLowerCase().equals("afternoon") || timeString.get().toLowerCase().equals("noon")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(6000); } else if (timeString.get().toLowerCase().equals("dusk")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(12000); } else if (timeString.get().toLowerCase().equals("night")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(14000); } else if (timeString.get().toLowerCase().equals("midnight")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(18000); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not understand input.")); } } }