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

The following examples show how to use org.spongepowered.api.entity.living.player.Player#isOnline() . 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: Visualization.java    From GriefPrevention with MIT License 6 votes vote down vote up
public void apply(Player player, boolean resetActive) {
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());

    // if he has any current visualization, clear it first
    //playerData.revertActiveVisual(player);
    
    boolean hideBorders = GriefPreventionPlugin.instance.worldEditProvider != null &&
            GriefPreventionPlugin.instance.worldEditProvider.hasCUISupport(player) &&
            GriefPreventionPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.hideBorders;
    if (!hideBorders) {
        // if he's online, create a task to send him the visualization
        if (player.isOnline() && this.elements.size() > 0
                && this.elements.get(0).getOriginal().getLocation().get().getExtent().equals(player.getWorld())) {
            Sponge.getGame().getScheduler().createTaskBuilder().delayTicks(1L)
                    .execute(new VisualizationApplicationTask(player, playerData, this, resetActive)).submit(GriefPreventionPlugin.instance);
            //GriefPreventionPlugin.instance.executor.execute(new VisualizationApplicationTask(player, playerData, this, resetActive));
        }
    }
}
 
Example 2
Source File: Visualization.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void revert(Player player) {
    if (!player.isOnline()) {
        return;
    }

    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());

    int minx = player.getLocation().getBlockX() - 100;
    int minz = player.getLocation().getBlockZ() - 100;
    int maxx = player.getLocation().getBlockX() + 100;
    int maxz = player.getLocation().getBlockZ() + 100;

    // remove any elements which are too far away
    if (!this.cuboidVisual) {
        this.removeElementsOutOfRange(this.elements, minx, minz, maxx, maxz);
    }

    // send real block information for any remaining elements
    for (int i = 0; i < this.elements.size(); i++) {
        BlockSnapshot snapshot = this.elements.get(i).getOriginal();

        // check player still in world where visualization exists
        if (i == 0) {
            if (!player.getWorld().equals(snapshot.getLocation().get().getExtent())) {
                return;
            }
        }

        player.sendBlockChange(snapshot.getPosition(), snapshot.getState());
    }

    playerData.visualBlocks = null;
    if (playerData.visualRevertTask != null) {
        playerData.visualRevertTask.cancel();
        playerData.visualRevertTask = null;
    }
}
 
Example 3
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public static void handleRemoveAdmin(CommandSource src, String sVictim, Region r) {
    if (src instanceof Player) {
        Player p = (Player) src;
        r = RedProtect.get().rm.getTopRegion(p.getLocation(), CommandHandlers.class.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
    }

    if (RedProtect.get().ph.hasRegionPermAdmin(src, "removeadmin", r)) {
        Player pVictim = null;
        if (RedProtect.get().getServer().getPlayer(sVictim).isPresent()) {
            pVictim = RedProtect.get().getServer().getPlayer(sVictim).get();
        }

        if (RedProtect.get().getUtil().PlayerToUUID(sVictim) == null) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }

        if (r.isAdmin(sVictim)) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.member.added") + " " + r.getName());
            r.removeAdmin(sVictim);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " DEMOTED TO MEMBER " + sVictim + " to region " + r.getName());
            if (pVictim != null && pVictim.isOnline() && !pVictim.equals(src)) {
                RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.admin.youdemoted").replace("{region}", r.getName()) + " " + src.getName());
            }
        } else {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.admin.notadmin"));
        }
    } else if (src instanceof Player) {
        RedProtect.get().lang.sendMessage(src, "no.permission");
    }
}
 
Example 4
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public static void handleRemoveMember(CommandSource src, String sVictim, Region r) {
    if (src instanceof Player) {
        Player p = (Player) src;
        r = RedProtect.get().rm.getTopRegion(p.getLocation(), CommandHandlers.class.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
    }

    if (RedProtect.get().ph.hasRegionPermAdmin(src, "removemember", r)) {
        Player pVictim = null;
        if (RedProtect.get().getServer().getPlayer(sVictim).isPresent()) {
            pVictim = RedProtect.get().getServer().getPlayer(sVictim).get();
        }

        if (RedProtect.get().getUtil().PlayerToUUID(sVictim) == null) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }

        if ((r.isMember(sVictim) || r.isAdmin(sVictim)) && !r.isLeader(sVictim)) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.member.removed") + " " + r.getName());
            r.removeMember(sVictim);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " REMOVED MEMBER " + sVictim + " to region " + r.getName());
            if (pVictim != null && pVictim.isOnline() && !pVictim.equals(src)) {
                RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.member.youremoved").replace("{region}", r.getName()) + " " + src.getName());
            }
        } else {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.member.notmember"));
        }
    } else if (src instanceof Player) {
        RedProtect.get().lang.sendMessage(src, "no.permission");
    }
}
 
Example 5
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handleAddLeader(CommandSource src, String sVictim, Region r) {
    if (src instanceof Player) {
        Player p = (Player) src;
        r = RedProtect.get().rm.getTopRegion(p.getLocation(), CommandHandlers.class.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
    }

    if (RedProtect.get().ph.hasRegionPermLeader(src, "addleader", r)) {

        Player pVictim = null;
        if (RedProtect.get().getServer().getPlayer(sVictim).isPresent()) {
            pVictim = RedProtect.get().getServer().getPlayer(sVictim).get();
        }

        if ((pVictim == null || !pVictim.isOnline()) && !src.hasPermission("redprotect.command.admin.addleader")) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.noplayer.online").replace("{player}", sVictim));
            return;
        }

        if (!src.hasPermission("redprotect.command.admin.addleader")) {
            int claimLimit = RedProtect.get().ph.getPlayerClaimLimit(pVictim);
            int claimused = RedProtect.get().rm.getPlayerRegions(pVictim.getName(), pVictim.getWorld().getName());
            boolean claimUnlimited = RedProtect.get().ph.hasPerm(src, "redprotect.limits.claim.unlimited");
            if (claimused >= claimLimit && claimLimit >= 0 && !claimUnlimited) {
                RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.region.addleader.limit").replace("{player}", pVictim.getName()));
                return;
            }
        }

        if (!r.isLeader(sVictim)) {
            if (src.hasPermission("redprotect.command.admin.addleader")) {
                r.addLeader(sVictim);
                RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " ADDED LEADER " + sVictim + " to region " + r.getName());
                RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.leader.added") + " " + r.getName());
                if (pVictim != null && pVictim.isOnline() && !pVictim.equals(src)) {
                    RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.leader.youadded").replace("{region}", r.getName()) + " " + src.getName());
                }
                return;
            }

            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.region.leader.yousendrequest").replace("{player}", pVictim.getName()));
            RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.leader.sendrequestto").replace("{region}", r.getName()).replace("{player}", src.getName()));

            RedProtect.get().alWait.put(pVictim, r.getID() + "@" + src.getName());
            final Player pVictimf = pVictim;
            Sponge.getScheduler().createSyncExecutor(RedProtect.get().container).schedule(() -> {
                if (RedProtect.get().alWait.containsKey(pVictimf)) {
                    RedProtect.get().alWait.remove(pVictimf);
                    if (src instanceof Player && ((Player) src).isOnline()) {
                        RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.region.leader.requestexpired").replace("{player}", pVictimf.getName()));
                    }
                }
            }, RedProtect.get().config.configRoot().region_settings.leadership_request_time, TimeUnit.SECONDS);
        } else {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.leader.already"));
        }
    } else if (src instanceof Player) {
        RedProtect.get().lang.sendMessage(src, "no.permission");
    }
}
 
Example 6
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handleRemoveLeader(CommandSource src, String sVictim, Region r) {
    Region rLow = null;
    Map<Integer, Region> regions = new HashMap<>();
    if (src instanceof Player) {
        Player p = (Player) src;
        r = RedProtect.get().rm.getTopRegion(p.getLocation(), CommandHandlers.class.getName());
        rLow = RedProtect.get().rm.getLowRegion(p.getLocation());
        regions = RedProtect.get().rm.getGroupRegion(p.getLocation());
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
    }

    if (RedProtect.get().ph.hasRegionPermLeader(src, "removeleader", r)) {
        Player pVictim = null;
        if (RedProtect.get().getServer().getPlayer(sVictim).isPresent()) {
            pVictim = RedProtect.get().getServer().getPlayer(sVictim).get();
        }

        if (RedProtect.get().getUtil().PlayerToUUID(sVictim) == null) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }

        if (rLow != null && rLow != r && ((!RedProtect.get().ph.hasRegionPermLeader(src, "removeleader", rLow) || (regions.size() > 1 && rLow.isLeader(sVictim))))) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.region.leader.cantremove.lowregion").replace("{player}", sVictim) + " " + rLow.getName());
            return;
        }
        if (r.isLeader(sVictim)) {
            if (r.leaderSize() > 1) {
                RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.admin.added") + " " + r.getName());
                r.removeLeader(sVictim);
                RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " DEMOTED TO ADMIN " + sVictim + " to region " + r.getName());
                if (pVictim != null && pVictim.isOnline() && !pVictim.equals(src)) {
                    RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.leader.youdemoted").replace("{region}", r.getName()) + " " + src.getName());
                }
            } else {
                RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.region.leader.cantremove").replace("{player}", sVictim));
            }
        } else {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.leader.notleader"));
        }
    } else if (src instanceof Player) {
        RedProtect.get().lang.sendMessage(src, "no.permission");
    }
}
 
Example 7
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handleAddAdmin(CommandSource src, String sVictim, Region r) {
    if (src instanceof Player) {
        Player p = (Player) src;
        r = RedProtect.get().rm.getTopRegion(p.getLocation(), CommandHandlers.class.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
    }

    if (RedProtect.get().ph.hasRegionPermAdmin(src, "addadmin", r)) {

        Player pVictim = null;
        if (RedProtect.get().getServer().getPlayer(sVictim).isPresent()) {
            pVictim = RedProtect.get().getServer().getPlayer(sVictim).get();
        }

        if (RedProtect.get().getUtil().PlayerToUUID(sVictim) == null) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }

        if (r.isLeader(sVictim)) {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.leader.already"));
            return;
        }

        if (!r.isAdmin(sVictim)) {
            r.addAdmin(sVictim);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " ADDED ADMIN " + sVictim + " to region " + r.getName());
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.admin.added") + " " + r.getName());
            if (pVictim != null && pVictim.isOnline() && !pVictim.equals(src)) {
                RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.admin.youadded").replace("{region}", r.getName()) + " " + src.getName());
            }
        } else {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.admin.already"));
        }
    } else if (src instanceof Player) {
        RedProtect.get().lang.sendMessage(src, "no.permission");
    }
}
 
Example 8
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handleAddMember(CommandSource src, String sVictim, Region r) {
    if (src instanceof Player) {
        Player p = (Player) src;
        r = RedProtect.get().rm.getTopRegion(p.getLocation(), CommandHandlers.class.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
    }

    if (RedProtect.get().ph.hasRegionPermAdmin(src, "addmember", r)) {

        if (RedProtect.get().getUtil().PlayerToUUID(sVictim) == null) {
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }

        Player pVictim = null;
        if (RedProtect.get().getServer().getPlayer(sVictim).isPresent()) {
            pVictim = RedProtect.get().getServer().getPlayer(sVictim).get();
        }

        if (r.isAdmin(sVictim)) {
            r.addMember(sVictim);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " ADDED MEMBER " + sVictim + " to region " + r.getName());
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.member.demoted") + " " + r.getName());
            if (pVictim != null && pVictim.isOnline()) {
                RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.admin.youdemoted").replace("{region}", r.getName()) + " " + src.getName());
            }
        } else if (!r.isMember(sVictim)) {
            r.addMember(sVictim);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + src.getName() + " ADDED MEMBER " + sVictim + " to region " + r.getName());
            RedProtect.get().lang.sendMessage(src, RedProtect.get().lang.get("general.color") + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.member.added") + " " + r.getName());
            if (pVictim != null && pVictim.isOnline() && !pVictim.equals(src)) {
                RedProtect.get().lang.sendMessage(pVictim, RedProtect.get().lang.get("cmdmanager.region.member.youadded").replace("{region}", r.getName()) + " " + src.getName());
            }
        } else {
            RedProtect.get().lang.sendMessage(src, "&c" + sVictim + " " + RedProtect.get().lang.get("cmdmanager.region.member.already"));
        }
    } else if (src instanceof Player) {
        RedProtect.get().lang.sendMessage(src, "no.permission");
    }
}