use of mc.dragons.core.gameobject.GameObjectType in project DragonsOnline by UniverseCraft.
the class ObjectMetadataCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!requirePermission(sender, PermissionLevel.GM))
return true;
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/objmeta <gameobject type> <gameobject uuid>");
return true;
}
GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0]);
UUID uuid = parseUUID(sender, args[1]);
if (type == null || uuid == null)
return true;
GameObject gameObject = type.getLoader().loadObject(dragons.getPersistentStorageManager().getStorageAccess(type, uuid));
if (gameObject == null) {
sender.sendMessage(ChatColor.RED + "No game object was found matching these criteria!");
return true;
}
// MetadataConstants.displayMetadata(sender, gameObject);
List<AuditLogEntry> entries = AUDIT_LOG.getEntries(gameObject.getIdentifier());
int count = entries.size();
if (count == 0) {
sender.sendMessage(ChatColor.RED + "There is no metadata for this game object!");
return true;
}
AuditLogEntry first = entries.get(0);
AuditLogEntry last = entries.get(entries.size() - 1);
AuditLogEntry lastPush = AUDIT_LOG.getLastPush(gameObject.getIdentifier());
if (first != null && first.getLine().equals("Created")) {
sender.sendMessage(ChatColor.GRAY + "Created By: " + ChatColor.GREEN + ObjectUtil.get(first.getBy(), () -> first.getBy().getName(), UNKNOWN));
sender.sendMessage(ChatColor.GRAY + "Created On: " + ChatColor.GREEN + ObjectUtil.get(first.getDate(), () -> StringUtil.DATE_FORMAT.format(first.getDate()), UNKNOWN));
}
sender.sendMessage(ChatColor.GRAY + "Revision Count: " + ChatColor.GREEN + count);
if (last != null) {
sender.sendMessage(ChatColor.GRAY + "Last Revised By: " + ChatColor.GREEN + ObjectUtil.get(last.getBy(), () -> last.getBy().getName(), UNKNOWN));
sender.sendMessage(ChatColor.GRAY + "Last Revised On: " + ChatColor.GREEN + ObjectUtil.get(last.getDate(), () -> StringUtil.DATE_FORMAT.format(last.getDate()), UNKNOWN));
}
if (lastPush != null) {
sender.sendMessage(ChatColor.GRAY + "Last Pushed On: " + ChatColor.GREEN + StringUtil.DATE_FORMAT.format(lastPush.getDate()));
}
if (last == null || lastPush == null) {
sender.sendMessage(ChatColor.GRAY + "Sync Status: " + UNKNOWN);
} else if (last.getId() == lastPush.getId()) {
sender.sendMessage(ChatColor.GRAY + "Sync Status: " + ChatColor.GREEN + "Matched in production");
} else if (last.getId() > lastPush.getId()) {
sender.sendMessage(ChatColor.GRAY + "Sync Status: " + ChatColor.YELLOW + "Changes made since last push");
} else {
sender.sendMessage(ChatColor.GRAY + "Sync Status: " + ChatColor.RED + "Behind production (SYNC ERROR)");
}
return true;
}
use of mc.dragons.core.gameobject.GameObjectType in project DragonsOnline by UniverseCraft.
the class ObjectCommands method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!requirePermission(sender, SystemProfileFlag.DEVELOPMENT))
return true;
GameObjectRegistry registry = dragons.getGameObjectRegistry();
StorageManager localStorageManager = dragons.getLocalStorageManager();
if (label.equalsIgnoreCase("autosave")) {
Dragons.getInstance().getGameObjectRegistry().executeAutoSave(true);
sender.sendMessage(ChatColor.GREEN + "Auto-save executed successfully.");
} else if (label.equalsIgnoreCase("invalidate")) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "/invalidate <type> <uuid>");
return true;
}
GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
UUID uuid = StringUtil.parseUUID(sender, args[1]);
if (type == null || uuid == null)
return true;
boolean result = registry.getRegisteredObjects().removeIf(obj -> obj.getType() == type && obj.getUUID().equals(uuid));
if (result) {
sender.sendMessage(ChatColor.GREEN + "Invalidated game object " + type + "#" + uuid + ".");
} else {
sender.sendMessage(ChatColor.RED + "Unable to locate game object (is it registered properly?)");
}
} else if (label.equalsIgnoreCase("invalidateall")) {
registry.getRegisteredObjects().clear();
sender.sendMessage(ChatColor.GREEN + "Invalidated all game objects.");
} else if (label.equalsIgnoreCase("invalidatetype")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/invalidatetype <type>");
return true;
}
GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
if (type == null)
return true;
registry.getRegisteredObjects().removeIf(obj -> obj.getType() == type);
sender.sendMessage(ChatColor.GREEN + "Invalidated all game objects of type " + type);
} else if (label.equalsIgnoreCase("invalidateuser")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/invalidateuser <player>");
return true;
}
boolean result = UserLoader.allUsers().removeIf(u -> u.getName().equalsIgnoreCase(args[0]));
result &= registry.getRegisteredObjects(GameObjectType.USER).removeIf(u -> ((User) u).getName().equalsIgnoreCase(args[0]));
if (result) {
sender.sendMessage(ChatColor.GREEN + "Invalidated user " + args[0]);
} else {
sender.sendMessage(ChatColor.RED + "That user was not found locally!");
}
} else if (label.equalsIgnoreCase("localize")) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "/localize <type> <uuid>");
return true;
}
GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
UUID uuid = StringUtil.parseUUID(sender, args[1]);
if (type == null || uuid == null)
return true;
registry.getRegisteredObjects().stream().filter(obj -> obj.getType() == type && obj.getUUID().equals(uuid)).forEach(obj -> obj.replaceStorageAccess(localStorageManager.getNewStorageAccess(type, obj.getData())));
sender.sendMessage(ChatColor.GREEN + "Localized game object " + type + "#" + uuid + ".");
} else if (label.equalsIgnoreCase("localizeall")) {
registry.getRegisteredObjects().forEach(obj -> obj.replaceStorageAccess(localStorageManager.getNewStorageAccess(obj.getType(), obj.getData())));
sender.sendMessage(ChatColor.GREEN + "Localized all game objects.");
} else if (label.equalsIgnoreCase("localizetype")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/localizetype <type>");
return true;
}
GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
if (type == null)
return true;
registry.getRegisteredObjects().stream().filter(obj -> obj.getType() == type).forEach(obj -> obj.replaceStorageAccess(localStorageManager.getNewStorageAccess(type, obj.getData())));
sender.sendMessage(ChatColor.GREEN + "Localized all game objects of type " + type);
} else if (label.equalsIgnoreCase("localizeuser")) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/localizeuser <player>");
return true;
}
UserLoader.allUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args[0])).forEach(u -> u.replaceStorageAccess(localStorageManager.getNewStorageAccess(GameObjectType.USER, u.getData())));
sender.sendMessage(ChatColor.GREEN + "Localized user " + args[0]);
}
return true;
}
Aggregations