public boolean add(final StringWrapper name, final UUID uuid) { if ((uuid == null)) { return false; } if (name == null) { try { unknown.add(uuid); } catch (Exception e) { PS.log("&c(minor) Invalid UUID mapping: " + uuid); e.printStackTrace(); } return false; } /* * lazy UUID conversion: * - Useful if the person misconfigured the database, or settings before PlotMe conversion */ if (!Settings.OFFLINE_MODE) { UUID offline = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); if (!unknown.contains(offline) && !name.value.equals(name.value.toLowerCase())) { offline = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8)); if (!unknown.contains(offline)) { offline = null; } } if (offline != null) { unknown.remove(offline); Set<Plot> plots = PS.get().getPlots(offline); if (plots.size() > 0) { for (Plot plot : PS.get().getPlots(offline)) { plot.owner = uuid; } DBFunc.replaceUUID(offline, uuid); PS.debug("&cDetected invalid UUID stored for: " + name.value); PS.debug( "&7 - Did you recently switch to online-mode storage without running `uuidconvert`?"); PS.debug( "&6PlotSquared will update incorrect entries when the user logs in, or you can reconstruct your database."); } } } try { UUID offline = uuidMap.put(name, uuid); if (offline != null && !offline.equals(uuid)) { Set<Plot> plots = PS.get().getPlots(offline); if (plots.size() > 0) { for (Plot plot : PS.get().getPlots(offline)) { plot.owner = uuid; } DBFunc.replaceUUID(offline, uuid); PS.debug("&cDetected invalid UUID stored for (1): " + name.value); PS.debug( "&7 - Did you recently switch to online-mode storage without running `uuidconvert`?"); PS.debug( "&6PlotSquared will update incorrect entries when the user logs in, or you can reconstruct your database."); } } } catch (Exception e) { BiMap<UUID, StringWrapper> inverse = uuidMap.inverse(); if (inverse.containsKey(uuid)) { if (uuidMap.containsKey(name)) { return false; } rename(uuid, name); return false; } uuidMap.put(name, uuid); } return true; }
@Override public boolean execute(final PlotPlayer plr, final String... args) { if (plr == null) { if (args.length < 3) { return !MainUtil.sendMessage( null, "如果你删除了你的数据库, 这个指令将可以识别地皮牌子来恢复数据库. \n\n&c缺失地皮世界参数 /plot debugclaimtest {世界名称} {最小地皮ID} {最大地皮ID}"); } final String world = args[0]; if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { return !MainUtil.sendMessage(null, "&c无效的地皮世界!"); } PlotId min, max; try { final String[] split1 = args[1].split(";"); final String[] split2 = args[2].split(";"); min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1])); max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1])); } catch (final Exception e) { return !MainUtil.sendMessage( null, "&c无效的最大最小地皮ID参数. &7地皮ID参数格式 &cX;Y &7这个 X,Y 是地皮的坐标\n加入这个参数后, 数据恢复将在所选区域进行."); } MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: &7正在开始地皮数据恢复. 该过程需要一些时间..."); MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: 发现超过 25000 区块. 请限制半径... (~3.8 分钟)"); final PlotManager manager = PS.get().getPlotManager(world); final PlotWorld plotworld = PS.get().getPlotWorld(world); final ArrayList<Plot> plots = new ArrayList<>(); for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) { final Plot plot = MainUtil.getPlot(world, id); final boolean contains = PS.get().getPlots(world).containsKey(plot.id); if (contains) { MainUtil.sendMessage(null, " - &c数据库已存在: " + plot.id); continue; } final Location loc = manager.getSignLoc(plotworld, plot); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); final boolean result = ChunkManager.manager.loadChunk(world, chunk); if (!result) { continue; } final String[] lines = BlockManager.manager.getSign(loc); if (lines != null) { String line = lines[2]; if ((line != null) && (line.length() > 2)) { line = line.substring(2); final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap(); UUID uuid = (map.get(new StringWrapper(line))); if (uuid == null) { for (final StringWrapper string : map.keySet()) { if (string.value.toLowerCase().startsWith(line.toLowerCase())) { uuid = map.get(string); break; } } } if (uuid == null) { uuid = UUIDHandler.getUUID(line); } if (uuid != null) { MainUtil.sendMessage(null, " - &a发现了地皮: " + plot.id + " : " + line); plot.owner = uuid; plot.hasChanged = true; plots.add(plot); } else { MainUtil.sendMessage(null, " - &c无效的玩家名称: " + plot.id + " : " + line); } } } } if (plots.size() > 0) { MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: &7更新了 '" + plots.size() + "' 块地皮!"); DBFunc.createPlotsAndData( plots, new Runnable() { @Override public void run() { MainUtil.sendMessage(null, "&6数据库更新成功!"); } }); for (final Plot plot : plots) { PS.get().updatePlot(plot); } MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: &7已完成!"); } else { MainUtil.sendMessage(null, "给出的搜索条件已经没有未恢复地图了."); } } else { MainUtil.sendMessage(plr, "&6这个指令只能通过控制台使用."); } return true; }