public void addOverlayBlock( short x, final short y, short z, final short id, byte data, final boolean rotate) { if (z < 0) { z += SIZE; } if (x < 0) { x += SIZE; } if (rotate) { final byte newdata = rotate(id, data); if ((data == 0) && (newdata == 0)) { return; } data = newdata; } int pair = MathMan.pair(x, y); HashMap<Integer, PlotBlock> v = G_SCH.putIfAbsent(pair, new HashMap<Integer, PlotBlock>()); if (v != null) { v.put((int) y, new PlotBlock(id, data)); } }
@Override public boolean hasPermission(final String node) { if (Settings.PERMISSION_CACHING) { if (this.noPerm.contains(node)) { return false; } if (this.hasPerm.contains(node)) { return true; } } if (offline && EconHandler.manager != null) { return EconHandler.manager.hasPermission(getName(), node); } boolean value = this.player.hasPermission(node); if (!value) { final String[] nodes = node.split("\\."); if (!MathMan.isInteger(nodes[nodes.length - 1])) { final StringBuilder n = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { n.append(nodes[i] + (".")); if (!node.equals(n + C.PERMISSION_STAR.s())) { value = player.hasPermission(n + C.PERMISSION_STAR.s()); if (value) { break; } } } value = this.player.hasPermission(node); } } if (Settings.PERMISSION_CACHING) { if (value) { this.hasPerm.add(node); } else { this.noPerm.add(node); } } return value; }
public void setupSchematics() { G_SCH = new HashMap<>(); final String schem1Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/sideroad"; final String schem2Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/intersection"; final String schem3Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/plot"; final Schematic schem1 = SchematicHandler.manager.getSchematic(schem1Str); final Schematic schem2 = SchematicHandler.manager.getSchematic(schem2Str); final Schematic schem3 = SchematicHandler.manager.getSchematic(schem3Str); final int shift = ROAD_WIDTH / 2; int oddshift = 0; if ((ROAD_WIDTH & 1) != 0) { oddshift = 1; } if (schem3 != null) { PLOT_SCHEMATIC = true; final short[] ids = schem3.getIds(); final byte[] datas = schem3.getDatas(); final Dimension d3 = schem3.getSchematicDimension(); final short w3 = (short) d3.getX(); final short l3 = (short) d3.getZ(); final short h3 = (short) d3.getY(); int center_shift_x = 0; int center_shift_z = 0; if (l3 < PLOT_WIDTH) { center_shift_z = (PLOT_WIDTH - l3) / 2; } if (w3 < PLOT_WIDTH) { center_shift_x = (PLOT_WIDTH - w3) / 2; } for (short x = 0; x < w3; x++) { for (short z = 0; z < l3; z++) { for (short y = 0; y < h3; y++) { final int index = (y * w3 * l3) + (z * w3) + x; final short id = ids[index]; final byte data = datas[index]; if (id != 0) { addOverlayBlock( (short) (x + shift + oddshift + center_shift_x), (y), (short) (z + shift + oddshift + center_shift_z), id, data, false); } } } } final HashSet<PlotItem> items = schem3.getItems(); if (items != null) { G_SCH_STATE = new HashMap<>(); for (final PlotItem item : items) { item.x += shift + oddshift + center_shift_x; item.z += shift + oddshift + center_shift_z; item.y += PLOT_HEIGHT; final short x = (short) item.x; final short z = (short) item.z; int pair = MathMan.pair(x, z); HashSet<PlotItem> v = G_SCH_STATE.putIfAbsent(pair, new HashSet<PlotItem>()); if (v != null) { v.add(item); } } } } if ((schem1 == null) || (schem2 == null) || (ROAD_WIDTH == 0)) { PS.debug(C.PREFIX.s() + "&3 - schematic: &7false"); return; } ROAD_SCHEMATIC_ENABLED = true; // Do not populate road if using schematic population ROAD_BLOCK = new PlotBlock(ROAD_BLOCK.id, (byte) 0); final short[] ids1 = schem1.getIds(); final byte[] datas1 = schem1.getDatas(); final short[] ids2 = schem2.getIds(); final byte[] datas2 = schem2.getDatas(); final Dimension d1 = schem1.getSchematicDimension(); final short w1 = (short) d1.getX(); final short l1 = (short) d1.getZ(); final short h1 = (short) d1.getY(); final Dimension d2 = schem2.getSchematicDimension(); final short w2 = (short) d2.getX(); final short l2 = (short) d2.getZ(); final short h2 = (short) d2.getY(); SCHEMATIC_HEIGHT = (short) Math.max(h2, h1); for (short x = 0; x < w1; x++) { for (short z = 0; z < l1; z++) { for (short y = 0; y < h1; y++) { final int index = (y * w1 * l1) + (z * w1) + x; final short id = ids1[index]; final byte data = datas1[index]; if (id != 0) { addOverlayBlock( (short) (x - (shift)), (y), (short) (z + shift + oddshift), id, data, false); addOverlayBlock( (short) (z + shift + oddshift), (y), (short) (x - shift), id, data, true); } } } } for (short x = 0; x < w2; x++) { for (short z = 0; z < l2; z++) { for (short y = 0; y < h2; y++) { final int index = (y * w2 * l2) + (z * w2) + x; final short id = ids2[index]; final byte data = datas2[index]; if (id != 0) { addOverlayBlock((short) (x - shift), (y), (short) (z - shift), id, data, false); } } } } }
@Override public boolean onCommand(PlotPlayer player, String... args) { if (args.length == 1) { if ("next".equalsIgnoreCase(args[0])) { ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots()); Collections.sort( plots, (p1, p2) -> { double v1 = 0; if (!p1.getRatings().isEmpty()) { for (Map.Entry<UUID, Rating> entry : p1.getRatings().entrySet()) { v1 -= 11 - entry.getValue().getAverageRating(); } } double v2 = 0; if (!p2.getRatings().isEmpty()) { for (Map.Entry<UUID, Rating> entry : p2.getRatings().entrySet()) { v2 -= 11 - entry.getValue().getAverageRating(); } } if (v1 == v2) { return -0; } return v2 > v1 ? 1 : -1; }); UUID uuid = player.getUUID(); for (Plot p : plots) { if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p.isBasePlot() && (p.hasRatings() || !p.getRatings().containsKey(uuid)) && !p.isAdded(uuid)) { p.teleportPlayer(player); MainUtil.sendMessage(player, C.RATE_THIS); return true; } } MainUtil.sendMessage(player, C.FOUND_NO_PLOTS); return false; } } Plot plot = player.getCurrentPlot(); if (plot == null) { return !this.sendMessage(player, C.NOT_IN_PLOT); } if (!plot.hasOwner()) { this.sendMessage(player, C.RATING_NOT_OWNED); return false; } if (plot.isOwner(player.getUUID())) { this.sendMessage(player, C.RATING_NOT_YOUR_OWN); return false; } if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) { this.sendMessage(player, C.RATING_NOT_DONE); return false; } if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) { Runnable run = new Runnable() { @Override public void run() { if (plot.getRatings().containsKey(player.getUUID())) { Rate.this.sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } MutableInt index = new MutableInt(0); MutableInt rating = new MutableInt(0); String title = Settings.Ratings.CATEGORIES.get(0); PlotInventory inventory = new PlotInventory(player, 1, title) { @Override public boolean onClick(int i) { rating.add((i + 1) * Math.pow(10, index.getValue())); index.increment(); if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) { int rV = rating.getValue(); Rating result = EventUtil.manager.callRating(this.player, plot, new Rating(rV)); plot.addRating(this.player.getUUID(), result); Rate.this.sendMessage( this.player, C.RATING_APPLIED, plot.getId().toString()); if (Permissions.hasPermission(this.player, "plots.comment")) { Command command = MainCommand.getInstance().getCommand(Comment.class); if (command != null) { MainUtil.sendMessage(this.player, C.COMMENT_THIS, command.getUsage()); } } return false; } this.setTitle(Settings.Ratings.CATEGORIES.get(index.getValue())); return true; } }; inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8")); inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8")); inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8")); inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8")); inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8")); inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8")); inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8")); inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8")); inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8")); inventory.openInventory(); } }; if (plot.getSettings().ratings == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync( () -> { plot.getSettings().ratings = DBFunc.getRatings(plot); run.run(); }); return true; } plot.getSettings().ratings = new HashMap<>(); } run.run(); return true; } if (args.length < 1) { this.sendMessage(player, C.RATING_NOT_VALID); return true; } String arg = args[0]; int rating; if (MathMan.isInteger(arg) && arg.length() < 3 && !arg.isEmpty()) { rating = Integer.parseInt(arg); if (rating > 10 || rating < 1) { this.sendMessage(player, C.RATING_NOT_VALID); return false; } } else { this.sendMessage(player, C.RATING_NOT_VALID); return false; } UUID uuid = player.getUUID(); Runnable run = () -> { if (plot.getRatings().containsKey(uuid)) { this.sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating)); plot.addRating(uuid, result); this.sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); }; if (plot.getSettings().ratings == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync( () -> { plot.getSettings().ratings = DBFunc.getRatings(plot); run.run(); }); return true; } plot.getSettings().ratings = new HashMap<>(); } run.run(); return true; }