Search in sources :

Example 11 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method deleteRegion.

private void deleteRegion(CommandSender sender, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.GM_DELETE))
        return;
    if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Specify a region to delete! /region -d <RegionName>");
        return;
    }
    Region region = regionLoader.getRegionByName(args[1]);
    if (region == null) {
        sender.sendMessage(ChatColor.RED + "No region by that name exists!");
    } else {
        dragons.getGameObjectRegistry().removeFromDatabase(region);
        AUDIT_LOG.saveEntry(region, user(sender), "Deleted");
        sender.sendMessage(ChatColor.GREEN + "Removed region " + args[1] + " successfully. Changes may not fully take effect until a network-wide restart.");
    }
}
Also used : Region(mc.dragons.core.gameobject.region.Region)

Example 12 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method gotoRegion.

private void gotoRegion(CommandSender sender, String[] args) {
    if (!requirePlayer(sender))
        return;
    if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Specify a region to delete! /region -d <RegionName>");
        return;
    }
    Region region = regionLoader.getRegionByName(args[1]);
    if (region == null) {
        sender.sendMessage(ChatColor.RED + "No region by that name exists!");
    } else {
        Player player = player(sender);
        Location center = BlockUtil.getAirAboveXZ(region.getMin().add(region.getMax()).multiply(0.5));
        player.teleport(center);
        sender.sendMessage(ChatColor.GREEN + "Teleported to center of region " + region.getName());
    }
}
Also used : Player(org.bukkit.entity.Player) Region(mc.dragons.core.gameobject.region.Region) Location(org.bukkit.Location)

Example 13 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method createRegion.

private void createRegion(CommandSender sender, String[] args) {
    if (!requirePlayer(sender))
        return;
    if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Specify a name for the region! /region create <RegionName>");
    } else if (args.length > 2) {
        sender.sendMessage(ChatColor.RED + "The region name cannot contain spaces! /region create <RegionName>");
    }
    Region test = regionLoader.getRegionByName(args[1]);
    if (test != null) {
        sender.sendMessage(ChatColor.RED + "A region by that name already exists! Its database identifier is " + test.toString());
    } else {
        Player player = player(sender);
        Region region = (Region) regionLoader.registerNew(args[1], player.getLocation(), player.getLocation());
        // MetadataConstants.addBlankMetadata(region, user(sender));
        AUDIT_LOG.saveEntry(region, user(sender), "Created");
        sender.sendMessage(ChatColor.GREEN + "Created region " + args[1] + ". Its database identifier is " + region.getIdentifier().toString());
    }
}
Also used : Player(org.bukkit.entity.Player) Region(mc.dragons.core.gameobject.region.Region)

Example 14 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class User method updateState.

/**
 * Called periodically to update the user's cached data and dispatch context-based game events.
 *
 * @param applyQuestTriggers
 * @param notify
 */
public void updateState(boolean applyQuestTriggers, boolean notify) {
    LOGGER.verbose("Update user state: " + getName() + " (applyQuestTriggers=" + applyQuestTriggers + ", notify=" + notify + ")");
    String worldName = player.getWorld().getName();
    boolean privilegedWorld = !worldName.equals("staff_verification") && !worldName.equals("trials") && !worldName.equalsIgnoreCase("trial-" + player.getName());
    if (PermissionUtil.verifyActiveProfileFlag(this, SystemProfileFlag.TRIAL_BUILD_ONLY, false) && privilegedWorld) {
        player.sendMessage(ChatColor.RED + "Trial builders can only access the trial world!");
        if (cachedLocation.getWorld().getName().equals("trials") || cachedLocation.getWorld().getName().equalsIgnoreCase("trial-" + player.getName())) {
            player.teleport(cachedLocation);
        } else if (Bukkit.getWorld("trial-" + player.getName()) != null) {
            player.teleport(Bukkit.getWorld("trial-" + player.getName()).getSpawnLocation());
        } else {
            player.teleport(Bukkit.getWorld("trials").getSpawnLocation());
        }
    }
    Set<Region> regions = regionLoader.getRegionsByLocation(player.getLocation());
    if (cachedLocation != null && cachedLocation.getWorld() != player.getLocation().getWorld()) {
        Floor floor = FloorLoader.fromWorldName(player.getLocation().getWorld().getName());
        cachedLocation = player.getLocation();
        cachedRegions = regions;
        if (notify) {
            if (floor == null) {
                sendActionBar(ChatColor.DARK_RED + "- Unofficial World -");
                player.sendMessage(ChatColor.RED + "WARNING: This is an unofficial world and is not associated with a floor.");
            } else {
                player.sendMessage(ChatColor.GRAY + "Floor " + floor.getLevelMin() + ": " + floor.getDisplayName());
                player.sendTitle(ChatColor.DARK_GRAY + "Floor " + floor.getLevelMin(), ChatColor.GRAY + floor.getDisplayName(), 20, 40, 20);
            }
        }
        return;
    }
    for (Region region : cachedRegions) {
        if (regions.contains(region))
            continue;
        continuousWalkDistance.remove(region);
        if (Boolean.valueOf(region.getFlags().getString(Region.FLAG_HIDDEN))) {
            continue;
        }
        if (notify) {
            player.sendMessage(ChatColor.GRAY + "Leaving " + region.getFlags().getString(Region.FLAG_FULLNAME));
        }
    }
    for (Region region : regions) {
        continuousWalkDistance.put(region, continuousWalkDistance.getOrDefault(region, 0.0) + User.MIN_DISTANCE_TO_UPDATE_STATE);
        if (!cachedRegions.contains(region)) {
            int lvMin = Integer.parseInt(region.getFlags().getString(Region.FLAG_LVMIN));
            if (getLevel() < lvMin) {
                player.setVelocity(cachedLocation.toVector().subtract(player.getLocation().toVector()).multiply(2.0D));
                if (notify) {
                    player.sendMessage(ChatColor.RED + "This region requires level " + lvMin + " to enter");
                }
            }
            if (Boolean.valueOf(region.getFlags().getString(Region.FLAG_HIDDEN))) {
                continue;
            }
            if (notify) {
                if (Boolean.parseBoolean(region.getFlags().getString("showtitle"))) {
                    player.sendTitle("", ChatColor.GRAY + "Entering " + region.getFlags().getString(Region.FLAG_FULLNAME), 20, 40, 20);
                }
                player.sendMessage(ChatColor.GRAY + "Entering " + region.getFlags().getString(Region.FLAG_FULLNAME));
                if (!region.getFlags().getString(Region.FLAG_DESC).equals("")) {
                    player.sendMessage(ChatColor.DARK_GRAY + "   " + ChatColor.ITALIC + region.getFlags().getString(Region.FLAG_DESC));
                }
            }
            int lvRec = Integer.parseInt(region.getFlags().getString(Region.FLAG_LVREC));
            if (getLevel() < lvRec && notify) {
                player.sendMessage(ChatColor.YELLOW + " Caution: The recommended level for this region is " + lvRec);
            }
        }
    }
    if (applyQuestTriggers) {
        updateQuests(null);
    }
    userHookRegistry.getHooks().forEach(h -> h.onUpdateState(this, cachedLocation));
    cachedLocation = player.getLocation();
    cachedRegions = regions;
    updateEffectiveWalkSpeed();
}
Also used : Floor(mc.dragons.core.gameobject.floor.Floor) Region(mc.dragons.core.gameobject.region.Region)

Example 15 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class SidebarManager method updateScoreboard.

public void updateScoreboard(Player player) {
    if (player == null) {
        return;
    }
    Scoreboard scoreboard = player.getScoreboard();
    if (scoreboard == null) {
        instance.getLogger().warning("Attempted to update scoreboard for " + player.getName() + " but they did not have a scoreboard");
        return;
    }
    RegionLoader regionLoader = GameObjectType.REGION.getLoader();
    User user = UserLoader.fromPlayer(player);
    if (user == null || !user.isInitialized()) {
        instance.getLogger().verbose("Skipping scoreboard update for uninitialized player " + player.getName());
        return;
    }
    Team floor = scoreboard.getTeam("FLOOR");
    floor.setPrefix(ChatColor.GRAY + "Floor: ");
    Floor currentFloor = FloorLoader.fromWorld(player.getWorld());
    String floorName = currentFloor == null ? ChatColor.RED + "Unknown" : currentFloor.getDisplayName();
    floor.setSuffix(getScrolledFrameAndIncrement(player, "Floor", floorName));
    Team server = scoreboard.getTeam("SERVER");
    server.setPrefix(ChatColor.GRAY + "Server: " + ChatColor.WHITE);
    server.setSuffix(instance.getServerName());
    Team online = scoreboard.getTeam("ONLINE");
    online.setPrefix(ChatColor.GRAY + "Online: " + ChatColor.WHITE);
    online.setSuffix(String.valueOf(Bukkit.getOnlinePlayers().stream().filter(p -> p.canSee(p)).count()) + " / " + Bukkit.getMaxPlayers());
    Team level = scoreboard.getTeam("LEVEL");
    level.setPrefix(ChatColor.GRAY + "Level: " + ChatColor.WHITE);
    level.setSuffix((user.getLevelColor() == ChatColor.GRAY ? "" : user.getLevelColor().toString()) + user.getLevel());
    Team xp = scoreboard.getTeam("XP");
    xp.setPrefix(ChatColor.GRAY + "XP: " + ChatColor.WHITE);
    xp.setSuffix(String.valueOf(user.getXP()) + " (" + (int) Math.floor(user.getLevelProgress() * 100.0F) + "%)");
    Team rank = scoreboard.getTeam("RANK");
    rank.setPrefix(ChatColor.GRAY + "Rank: " + ChatColor.WHITE);
    rank.setSuffix((user.getRank().getNameColor() == ChatColor.GRAY ? "" : user.getRank().getNameColor()) + user.getRank().getShortName());
    Team gold = scoreboard.getTeam("GOLD");
    gold.setPrefix(ChatColor.GRAY + "Gold: " + ChatColor.WHITE);
    gold.setSuffix(ChatColor.GOLD + "" + user.getGold());
    Team location = scoreboard.getTeam("LOCATION");
    location.setPrefix(ChatColor.GRAY + "Location: " + ChatColor.WHITE);
    location.setSuffix(String.valueOf(player.getLocation().getBlockX()) + ", " + player.getLocation().getBlockZ());
    Team region = scoreboard.getTeam("REGION");
    Region smallestRegion = regionLoader.getSmallestRegionByLocation(player.getLocation(), false);
    String regionName = smallestRegion == null ? "None" : smallestRegion.getFlags().getString("fullname");
    region.setPrefix(ChatColor.GRAY + "Region: " + ChatColor.WHITE);
    region.setSuffix(getScrolledFrameAndIncrement(player, "Region", regionName));
    Team staffStatus = scoreboard.getTeam("STAFF_STATUS");
    if (user.getSystemProfile() != null) {
        staffStatus.setPrefix(ChatColor.DARK_GREEN + "- " + ChatColor.GREEN + "ON DUTY");
        staffStatus.setSuffix(ChatColor.DARK_GREEN + " -");
    } else {
        staffStatus.setPrefix("");
        staffStatus.setSuffix("");
    }
}
Also used : DisplaySlot(org.bukkit.scoreboard.DisplaySlot) Team(org.bukkit.scoreboard.Team) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) Score(org.bukkit.scoreboard.Score) Objective(org.bukkit.scoreboard.Objective) Dragons(mc.dragons.core.Dragons) Scoreboard(org.bukkit.scoreboard.Scoreboard) Floor(mc.dragons.core.gameobject.floor.Floor) GameObjectType(mc.dragons.core.gameobject.GameObjectType) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader) Map(java.util.Map) Region(mc.dragons.core.gameobject.region.Region) ChatColor(org.bukkit.ChatColor) Bukkit(org.bukkit.Bukkit) Floor(mc.dragons.core.gameobject.floor.Floor) Scoreboard(org.bukkit.scoreboard.Scoreboard) Region(mc.dragons.core.gameobject.region.Region) Team(org.bukkit.scoreboard.Team) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader)

Aggregations

Region (mc.dragons.core.gameobject.region.Region)16 Player (org.bukkit.entity.Player)8 User (mc.dragons.core.gameobject.user.User)5 Document (org.bson.Document)5 GameObject (mc.dragons.core.gameobject.GameObject)4 NPC (mc.dragons.core.gameobject.npc.NPC)4 Location (org.bukkit.Location)4 Dragons (mc.dragons.core.Dragons)3 GameObjectType (mc.dragons.core.gameobject.GameObjectType)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Floor (mc.dragons.core.gameobject.floor.Floor)2 Item (mc.dragons.core.gameobject.item.Item)2 RegionLoader (mc.dragons.core.gameobject.region.RegionLoader)2 BlockUtil (mc.dragons.core.util.BlockUtil)2 Bukkit (org.bukkit.Bukkit)2 ChatColor (org.bukkit.ChatColor)2