use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class PlayerEventListeners method onJoin.
@EventHandler
public void onJoin(PlayerJoinEvent event) {
LOGGER.debug("Join event on " + event.getPlayer().getName());
event.setJoinMessage(null);
Player player = event.getPlayer();
if (!plugin.isJoinable()) {
event.getPlayer().kickPlayer(ChatColor.YELLOW + "This server (" + plugin.getServerName() + ") is still loading and is not joinable yet.\n" + "Please try again in a few minutes.\n\n" + "This is not a punishment-related kick.");
return;
}
rollingAsync(() -> {
UUID uuid = player.getUniqueId();
User user = userLoader.loadObject(uuid);
boolean firstJoin = false;
if (user == null) {
firstJoin = true;
plugin.getLogger().info("Player " + player.getName() + " joined for the first time");
user = userLoader.registerNew(player);
user.sendToFloor("BeginnerTown");
int i = 1;
final User fUser = user;
for (ItemClass itemClass : DEFAULT_INVENTORY) {
sync(() -> fUser.giveItem(itemLoader.registerNew(itemClass), true, false, true), i);
i++;
}
}
Floor floor = FloorLoader.fromLocation(player.getLocation());
if (floor.isPlayerLocked() && !PermissionUtil.verifyActivePermissionLevel(user, PermissionLevel.GM, false)) {
sync(() -> player.kickPlayer(ChatColor.RED + "This floor (#" + floor.getLevelMin() + " " + floor.getDisplayName() + ") is currently locked for maintenance.\n" + "You will be allowed to re-join once the maintenance completes.\n\n" + "This is not a punishment-related kick.\n\n" + StringUtil.dateFormatNow()));
return;
}
if (user.getRank().isStaff()) {
GameMode restoreTo = user.getSavedGameMode();
final User fUser = user;
sync(() -> {
fUser.setGameMode(GameMode.ADVENTURE, true);
fUser.setGameMode(restoreTo, false);
fUser.sendToFloor("Staff");
player.setPlayerListName(ChatColor.DARK_GRAY + "" + ChatColor.MAGIC + "[Staff Joining]");
fUser.updatePrimaryNameTag();
});
player.sendMessage(ChatColor.AQUA + "Please login to your system profile or select \"Join as player\".");
} else {
user.handleJoin(firstJoin);
}
});
}
use of mc.dragons.core.gameobject.floor.Floor 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();
}
use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class User method sendToFloor.
public void sendToFloor(String floorName, boolean overrideLevelRequirement) {
// TODO still save the location?
if (player == null)
return;
Floor floor = FloorLoader.fromFloorName(floorName);
if (!overrideLevelRequirement && getLevel() < floor.getLevelMin()) {
return;
}
sync(() -> {
// Yes, again
if (player == null)
return;
player.teleport(floor.getWorld().getSpawnLocation());
});
}
use of mc.dragons.core.gameobject.floor.Floor 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("");
}
}
use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class FloorCommand method createFloor.
private void createFloor(CommandSender sender, String[] args) {
if (!requirePermission(sender, SystemProfileFlag.GM_FLOOR))
return;
if (args.length < 4) {
sender.sendMessage(ChatColor.RED + "Insufficient arguments! /floor create <FloorName> <WorldName> <LevelMin> [-superflat]");
return;
}
sender.sendMessage(ChatColor.GREEN + "Creating world " + args[2] + "...");
boolean superflat = false;
if (args.length > 4) {
if (args[4].equalsIgnoreCase("-superflat")) {
superflat = true;
}
}
Integer lvMinOpt = parseInt(sender, args[3]);
if (lvMinOpt == null)
return;
Floor floor = floorLoader.registerNew(args[1], args[2], args[2], lvMinOpt, superflat);
AUDIT_LOG.saveEntry(floor, user(sender), "Created");
sender.sendMessage(ChatColor.GREEN + "Created new floor successfully!");
}
Aggregations