@Subscribe public void onJoin(PlayerJoinEvent event) { final Player player = event.getUser(); SpongeUtil.removePlayer(player.getName()); final PlotPlayer pp = SpongeUtil.getPlayer(player); final String username = pp.getName(); final StringWrapper name = new StringWrapper(username); final UUID uuid = pp.getUUID(); UUIDHandler.add(name, uuid); ExpireManager.dates.put(uuid, System.currentTimeMillis()); // TODO worldedit bypass if (PS.get().update != null && pp.hasPermission("plots.admin")) { TaskManager.runTaskLater( new Runnable() { @Override public void run() { MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update"); } }, 20); } final Location loc = SpongeUtil.getLocation(player); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { return; } if (Settings.TELEPORT_ON_LOGIN) { MainUtil.teleportPlayer(pp, pp.getLocation(), plot); MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); } PlotListener.plotEntry(pp, plot); }
@Subscribe public void onWorldChange(EntityTeleportEvent event) { Entity entity = event.getEntity(); if (entity instanceof Player) { org.spongepowered.api.world.Location from = event.getOldLocation(); org.spongepowered.api.world.Location to = event.getNewLocation(); int x2; if (getInt(from.getX()) != (x2 = getInt(to.getX()))) { Player player = (Player) entity; PlotPlayer pp = SpongeUtil.getPlayer(player); Extent extent = to.getExtent(); if (!(extent instanceof World)) { pp.deleteMeta("location"); return; } pp.setMeta("location", SpongeUtil.getLocation(player)); World world = (World) extent; String worldname = ((World) extent).getName(); PlotWorld plotworld = PS.get().getPlotWorld(worldname); if (plotworld == null) { return; } PlotManager plotManager = PS.get().getPlotManager(worldname); PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); Plot lastPlot = (Plot) pp.getMeta("lastplot"); if (id == null) { if (lastPlot == null) { return; } if (!PlotListener.plotExit(pp, lastPlot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { event.setNewLocation(from); } else { event.setNewLocation(world.getSpawnLocation()); } return; } } else if (lastPlot != null && id.equals(lastPlot.id)) { return; } else { Plot plot = MainUtil.getPlot(worldname, id); if (!PlotListener.plotEntry(pp, plot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { event.setNewLocation(from); } else { event.setNewLocation(world.getSpawnLocation()); } return; } } Integer border = MainUtil.worldBorder.get(worldname); if (border != null) { if (x2 > border) { Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); event.setNewLocation(to); MainUtil.sendMessage(pp, C.BORDER); } else if (x2 < -border) { Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); event.setNewLocation(to); MainUtil.sendMessage(pp, C.BORDER); } } return; } int z2; if (getInt(from.getZ()) != (z2 = getInt(to.getZ()))) { Player player = (Player) entity; PlotPlayer pp = SpongeUtil.getPlayer(player); Extent extent = to.getExtent(); if (!(extent instanceof World)) { pp.deleteMeta("location"); return; } pp.setMeta("location", SpongeUtil.getLocation(player)); World world = (World) extent; String worldname = ((World) extent).getName(); PlotWorld plotworld = PS.get().getPlotWorld(worldname); if (plotworld == null) { return; } PlotManager plotManager = PS.get().getPlotManager(worldname); PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); Plot lastPlot = (Plot) pp.getMeta("lastplot"); if (id == null) { if (lastPlot == null) { return; } if (!PlotListener.plotExit(pp, lastPlot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { event.setNewLocation(from); } else { event.setNewLocation(player.getWorld().getSpawnLocation()); } return; } } else if (lastPlot != null && id.equals(lastPlot.id)) { return; } else { Plot plot = MainUtil.getPlot(worldname, id); if (!PlotListener.plotEntry(pp, plot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) { event.setNewLocation(from); } else { event.setNewLocation(player.getWorld().getSpawnLocation()); } return; } } Integer border = MainUtil.worldBorder.get(worldname); if (border != null) { if (z2 > border) { Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); event.setNewLocation(to); MainUtil.sendMessage(pp, C.BORDER); } else if (z2 < -border) { Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); event.setNewLocation(to); MainUtil.sendMessage(pp, C.BORDER); } } } } }