Java Code Examples for org.spongepowered.api.entity.living.player.Player#offer()

The following examples show how to use org.spongepowered.api.entity.living.player.Player#offer() . 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: 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 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: FlyspeedCommand.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.FLYING_SPEED, speed / flymultiplier);
        Messages.send(p, "fly.command.flyspeed.success.self", "%speed%", speed);
        return CommandResult.success();
    } else {
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.FLYING_SPEED, speed / flymultiplier);
        Messages.send(sender, "fly.command.flyspeed.success.others.self", "%player%", VariableUtil.getNameEntity(t), "%speed%", speed);
        Messages.send(t, "fly.command.flyspeed.success.others.self", "%player%", sender, "%speed%", speed);
        return CommandResult.success();
    }
}
 
Example 4
Source File: AdventureCommand.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_ADVENTURE);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
        Messages.send(sender, "gamemode.command.gamemode.success", "%gamemode%", "adventure");
        return CommandResult.success();
    } else {
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_BASE);
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_ADVENTURE);
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
        Messages.send(t, "gamemode.command.gamemode.success.others", "%sender%", sender, "%gamemode%", "adventure");
        Messages.send(sender, "gamemode.command.gamemode.success.self", "%player%", t, "%gamemode%", "adventure");
        return CommandResult.success();
    }
}
 
Example 5
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 6
Source File: CreativeCommand.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_CREATIVE);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.GAME_MODE, GameModes.CREATIVE);
        Messages.send(sender, "gamemode.command.gamemode.success", "%gamemode%", "creative");
        return CommandResult.success();
    } else {
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_BASE);
        checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_CREATIVE);
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.GAME_MODE, GameModes.CREATIVE);
        Messages.send(t, "gamemode.command.gamemode.success.others", "%sender%", sender, "%gamemode%", "creative");
        Messages.send(sender, "gamemode.command.gamemode.success.self", "%player%", t, "%gamemode%", "creative");
        return CommandResult.success();
    }
}
 
Example 7
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 8
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 9
Source File: SpeedCommand.java    From UltimateCore with MIT License 5 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;
        if (p.get(Keys.IS_FLYING).orElse(false)) {
            p.offer(Keys.FLYING_SPEED, speed / flymultiplier);
            Messages.send(p, "fly.command.flyspeed.success.self", "%speed%", speed);
        } else {
            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();
        if (t.get(Keys.IS_FLYING).orElse(false)) {
            t.offer(Keys.FLYING_SPEED, speed / flymultiplier);
            Messages.send(sender, "fly.command.flyspeed.success.others.self", "%player%", VariableUtil.getNameEntity(t), "%speed%", speed);
            Messages.send(t, "fly.command.flyspeed.success.others.others", "%player%", sender, "%speed%", speed);
        } else {
            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.others", "%player%", sender, "%speed%", speed);
        }
        return CommandResult.success();
    }
}
 
Example 10
Source File: HealCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, HealPermissions.UC_HEAL_HEAL_BASE);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;

        p.offer(Keys.HEALTH, p.get(Keys.MAX_HEALTH).orElse(20.0));
        p.offer(Keys.POTION_EFFECTS, new ArrayList<>());
        p.offer(Keys.REMAINING_AIR, p.get(Keys.MAX_AIR).orElse(10));
        p.offer(Keys.FOOD_LEVEL, 20);
        p.offer(Keys.FIRE_TICKS, 0);

        Messages.send(sender, "heal.command.heal.success");
        return CommandResult.success();
    } else {
        checkPermission(sender, HealPermissions.UC_HEAL_HEAL_OTHERS);
        Player t = args.<Player>getOne("player").get();

        t.offer(Keys.HEALTH, t.get(Keys.MAX_HEALTH).orElse(20.0));
        t.offer(Keys.POTION_EFFECTS, new ArrayList<>());
        t.offer(Keys.REMAINING_AIR, t.get(Keys.MAX_AIR).orElse(10));
        t.offer(Keys.FOOD_LEVEL, 20);
        t.offer(Keys.FIRE_TICKS, 0);

        Messages.send(sender, "heal.command.heal.success.self", "%player%", VariableUtil.getNameEntity(t));
        Messages.send(t, "heal.command.heal.success.others", "%sender%", sender);
        return CommandResult.success();
    }
}
 
Example 11
Source File: BurnCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, BurnPermissions.UC_BURN_BURN_BASE);
    Player t = args.<Player>getOne("player").get();
    Double time = args.<Double>getOne("time").orElse(10.0);
    t.offer(Keys.FIRE_TICKS, Double.valueOf(time * 20).intValue());
    Messages.send(sender, "burn.command.burn.success", "%player%", t, "%time%", time);
    return CommandResult.success();
}
 
Example 12
Source File: HealExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Optional<Player> p = ctx.<Player> getOne("player");

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (player.hasPermission("essentialcmds.heal.others") && p.isPresent())
		{
			Player recipient = p.get();
			recipient.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
			recipient.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've been healed by " + player.getName()));
			src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've healed " + recipient.getName()));
		}
		else if (p.isPresent())
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to heal other players!"));
		}
		else
		{
			player.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
			src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've been healed."));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /heal!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /heal!"));
	}

	return CommandResult.success();
}
 
Example 13
Source File: KillExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Optional<Player> p = ctx.<Player> getOne("player");

	if (p.isPresent() && src.hasPermission("essentialcmds.kill.others"))
	{
		p.get().offer(Keys.HEALTH, 0d);
		Utils.setLastTeleportOrDeathLocation(p.get().getUniqueId(), p.get().getLocation());
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Killed player " + p.get().getName()));
		p.get().sendMessage(Text.of(TextColors.RED, "You have been killed by " + src.getName()));
	}
	else if (!p.isPresent())
	{
		if (src instanceof Player)
		{
			Player player = (Player) src;
			player.offer(Keys.HEALTH, 0d);
			Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Killed yourself."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot kill yourself, you are not a player!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to kill other players!"));
	}

	return CommandResult.success();
}
 
Example 14
Source File: ExpExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
	int expLevel = ctx.<Integer> getOne("exp").get();
	Player player = ctx.<Player> getOne("target").get();
	player.offer(Keys.TOTAL_EXPERIENCE, player.get(Keys.TOTAL_EXPERIENCE).get() - expLevel);
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Took " + expLevel + " experience from " + player.getName() + "."));
	return CommandResult.success();
}
 
Example 15
Source File: ExpExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
	int expLevel = ctx.<Integer> getOne("exp").get();
	Player player = ctx.<Player> getOne("target").get();
	player.offer(Keys.TOTAL_EXPERIENCE, expLevel);
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Set " + player.getName() + "'s experience level to " + expLevel + "."));
	return CommandResult.success();
}
 
Example 16
Source File: FlyListeners.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join event) {
    Player p = event.getTargetEntity();
    UltimateUser user = UltimateCore.get().getUserService().getUser(p);
    if (p.hasPermission(FlyPermissions.UC_FLY_FLY_BASE.get()) && user.get(FlyKeys.FLY).orElse(false)) {
        if (p.getLocation().add(0, -1, 0).getBlockType().equals(BlockTypes.AIR)) {
            p.offer(Keys.CAN_FLY, true);
            p.offer(Keys.IS_FLYING, true);
        }
    }
}
 
Example 17
Source File: CommonEntityEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
private void checkPlayerGameMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
    if (user == null) {
        return;
    }
    final Player player = user.getOnlinePlayer();
    if (player == null) {
        // Most likely Citizens NPC
        return;
    }
    if (!GDOptions.isOptionEnabled(Options.PLAYER_GAMEMODE)) {
        return;
    }

    final GDPlayerData playerData = user.getInternalPlayerData();
    final GameMode currentGameMode = player.get(Keys.GAME_MODE).get();
    final GameModeType gameModeType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(GameModeType.class), playerData.getSubject(), Options.PLAYER_GAMEMODE, toClaim);
    if (gameModeType == GameModeTypes.UNDEFINED && playerData.lastGameMode != GameModeTypes.UNDEFINED) {
        player.offer(Keys.GAME_MODE, PlayerUtil.GAMEMODE_MAP.get(playerData.lastGameMode));
        return;
    }

    final boolean bypassOption = playerData.userOptionBypassPlayerGamemode;
    if (!bypassOption && gameModeType != null && gameModeType != GameModeTypes.UNDEFINED) {
        final GameMode newGameMode = PlayerUtil.GAMEMODE_MAP.get(gameModeType);
        if (currentGameMode != newGameMode) {
            playerData.lastGameMode = PlayerUtil.GAMEMODE_MAP.inverse().get(gameModeType);
            player.offer(Keys.GAME_MODE, PlayerUtil.GAMEMODE_MAP.get(gameModeType));
            final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_GAMEMODE,
                    ImmutableMap.of(
                    "gamemode", gameModeType.getName()));
            GriefDefenderPlugin.sendMessage(player, message);
        }
    }
}
 
Example 18
Source File: PlayerMoveListener.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Listener
public void onPlayerMove(MoveEntityEvent event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player player = (Player) event.getTargetEntity();

		if (Utils.isTeleportCooldownEnabled() && EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
		{
			EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.RED, "Teleportation canceled due to movement."));
		}

		if (EssentialCmds.frozenPlayers.contains(player.getUniqueId()))
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot move while frozen."));
			event.setCancelled(true);
			return;
		}

		if (EssentialCmds.recentlyJoined.contains(player))
		{
			EssentialCmds.recentlyJoined.remove(player);

			if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
			{
				EssentialCmds.afkList.remove(player.getUniqueId());
			}
		}
		else
		{
			if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
			{
				AFK removeAFK = EssentialCmds.afkList.get(player.getUniqueId());

				if (removeAFK.getAFK())
				{
					if (Utils.shouldAnnounceAFK())
					{
						MessageChannel.TO_ALL.send(Text.of(TextColors.BLUE, player.getName(), TextColors.GOLD, " is no longer AFK."));
					}
				}

				EssentialCmds.afkList.remove(removeAFK);
			}

			AFK afk = new AFK(System.currentTimeMillis());
			EssentialCmds.afkList.put(player.getUniqueId(), afk);
		}

		if (!event.getFromTransform().getExtent().getUniqueId().equals(event.getToTransform().getExtent().getUniqueId()))
		{
			World oldWorld = event.getFromTransform().getExtent();
			World newWorld = event.getToTransform().getExtent();

			Utils.savePlayerInventory(player, oldWorld.getUniqueId());

			if (!Utils.doShareInventories(oldWorld.getName(), newWorld.getName()))
			{
				Utils.updatePlayerInventory(player, newWorld.getUniqueId());
			}

			player.offer(Keys.GAME_MODE, newWorld.getProperties().getGameMode());
		}
	}
}
 
Example 19
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order= Order.LAST)
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_QUIT_EVENT.startTimingIfSync();
    UUID playerID = player.getUniqueId();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);
    boolean isBanned = false;
    if (playerData.wasKicked) {
        isBanned = this.banService.isBanned(player.getProfile()) || (playerData.ipAddress != null && this.banService.isBanned(playerData.ipAddress));
    }

    // if banned, add IP to the temporary IP ban list
    if (isBanned && playerData.ipAddress != null) {
        long now = Calendar.getInstance().getTimeInMillis();
        this.tempBannedIps.add(new IpBanInfo(playerData.ipAddress, now + this.MILLISECONDS_IN_DAY, player.getName()));
    }

    // silence notifications when they're coming too fast, or the player is banned
    if (this.shouldSilenceNotification() || isBanned) {
        event.setMessage(Text.of());
    } else {
        // make sure his data is all saved - he might have accrued some claim
        // blocks while playing that were not saved immediately
        playerData.saveAllData();
    }

    // FEATURE: players in pvp combat when they log out will die
    if (GriefPreventionPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().pvp.punishPvpLogout && playerData.inPvpCombat(player.getWorld())) {
        player.offer(Keys.HEALTH, 0d);
    }

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtils.removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getProperties(), playerID);
    }

    // reduce count of players with that player's IP address
    // TODO: re-enable when achievement data is implemented
    /*if (GriefPrevention.instance.config_ipLimit > 0 && !player.getAchievementData().achievements().contains(Achievements.MINE_WOOD)) {
        InetAddress ipAddress = playerData.ipAddress;
        if (ipAddress != null) {
            String ipAddressString = ipAddress.toString();
            Integer count = this.ipCountHash.get(ipAddressString);
            if (count == null)
                count = 1;
            this.ipCountHash.put(ipAddressString, count - 1);
        }
    }*/
    GPTimings.PLAYER_QUIT_EVENT.stopTimingIfSync();
}
 
Example 20
Source File: PlayerTickTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@Override
public void run() {
    for (World world : Sponge.getServer().getWorlds()) {
        for (Player player : world.getPlayers()) {
            if (player.isRemoved()) {
                continue;
            }
            final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
            final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
            // send queued visuals
            int count = 0;
            final Iterator<BlockSnapshot> iterator = playerData.queuedVisuals.iterator();
            while (iterator.hasNext()) {
                final BlockSnapshot snapshot = iterator.next();
                if (count > GriefDefenderPlugin.getGlobalConfig().getConfig().visual.clientVisualsPerTick) {
                    break;
                }
                player.sendBlockChange(snapshot.getPosition(), snapshot.getState());
                iterator.remove();
                count++;
            }

            // chat capture
            playerData.updateRecordChat();
            // health regen
            if (world.getProperties().getTotalTime() % 100 == 0L) {
                final GameMode gameMode = player.get(Keys.GAME_MODE).get();
                // Handle player health regen
                if (gameMode != GameModes.CREATIVE && gameMode != GameModes.SPECTATOR && GDOptions.isOptionEnabled(Options.PLAYER_HEALTH_REGEN)) {
                    final double maxHealth = player.get(Keys.MAX_HEALTH).get();
                    final double currentHealth = player.get(Keys.HEALTH).get();
                    if (currentHealth < maxHealth) {
                        final double regenAmount = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_HEALTH_REGEN, claim);
                        if (regenAmount > 0) {
                            final double newHealth = currentHealth + regenAmount;
                            if (newHealth > maxHealth) {
                                player.offer(Keys.MAX_HEALTH, maxHealth);
                            } else {
                                player.offer(Keys.HEALTH, newHealth);
                            }
                        }
                    }
                }
            }
            // teleport delay
            if (world.getProperties().getTotalTime() % 20 == 0L) {
                if (playerData.teleportDelay > 0) {
                    final int delay = playerData.teleportDelay - 1;
                    if (delay == 0) {
                        player.setLocation(playerData.teleportLocation);
                        playerData.teleportDelay = 0;
                        playerData.teleportLocation = null;
                        playerData.teleportSourceLocation = null;
                        continue;
                    }
                    TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.TELEPORT_DELAY_NOTICE, 
                            ImmutableMap.of("delay", TextComponent.of(delay, TextColor.GOLD))));
                    playerData.teleportDelay = delay;
                }
            }
        }
    }
}