Removing unused folder

This commit is contained in:
boy0001 2015-01-13 04:03:15 +11:00
parent f2b5f1d224
commit 77c62c535f
12 changed files with 0 additions and 1476 deletions

View File

@ -1,31 +0,0 @@
package com.intellectualcrafters.unused;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
public class DefaultUUIDWrapper extends UUIDWrapper {
@Override
public UUID getUUID(final Player player) {
return player.getUniqueId();
}
@Override
public UUID getUUID(final OfflinePlayer player) {
return player.getUniqueId();
}
@Override
public OfflinePlayer getOfflinePlayer(final UUID uuid) {
return Bukkit.getOfflinePlayer(uuid);
}
@Override
public Player getPlayer(final UUID uuid) {
return Bukkit.getPlayer(uuid);
}
}

View File

@ -1,215 +0,0 @@
package com.intellectualcrafters.unused;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
/**
* @author Empire92
*/
@SuppressWarnings({"unused", "deprecation"}) public class EntityListener implements Listener {
public final static HashMap<String, HashMap<Plot, HashSet<Integer>>> entityMap = new HashMap<>();
public EntityListener() {
final BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() {
@Override
public void run() {
final Iterator<Entry<String, HashMap<Plot, HashSet<Integer>>>> worldIt = entityMap.entrySet().iterator();
final Set<Plot> plots = PlotMain.getPlots();
while (worldIt.hasNext()) {
final Entry<String, HashMap<Plot, HashSet<Integer>>> entry = worldIt.next();
final String worldname = entry.getKey();
if (!PlotMain.isPlotWorld(worldname)) {
worldIt.remove();
continue;
}
final World world = Bukkit.getWorld(worldname);
if ((world == null) || (entry.getValue().size() == 0)) {
worldIt.remove();
continue;
}
final Iterator<Entry<Plot, HashSet<Integer>>> it = entry.getValue().entrySet().iterator();
while (it.hasNext()) {
final Entry<Plot, HashSet<Integer>> plotEntry = it.next();
final Plot plot = plotEntry.getKey();
if (!plots.contains(plot)) {
it.remove();
continue;
}
boolean loaded = false;
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
try {
loops:
for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) {
for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) {
final Chunk chunk = world.getChunkAt(i, j);
if (chunk.isLoaded()) {
loaded = true;
break loops;
}
}
}
} catch (final Exception e) {
it.remove();
continue;
}
if (!loaded) {
it.remove();
}
}
}
}
}, 24000L, 48000L);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onPlayerInteract(final PlayerInteractEvent e) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
final Player p = e.getPlayer();
final World w = p.getWorld();
final String n = w.getName();
if ((e.getMaterial() == Material.MONSTER_EGG) || (e.getMaterial() == Material.MONSTER_EGGS)) {
if (entityMap.containsKey(n)) {
final Location l = e.getClickedBlock().getLocation();
final Plot plot = PlotHelper.getCurrentPlot(l);
if ((plot != null) && plot.hasRights(p)) {
int mobs;
if (entityMap.get(n).containsKey(plot)) {
mobs = entityMap.get(n).get(plot).size();
} else {
mobs = 0;
}
if (!(PlotMain.hasPermissionRange(p, "plots.mobcap", Settings.MOB_CAP) > mobs)) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.mobcap." + (mobs + 1));
e.setCancelled(true);
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public static void onCreatureSpawn(final CreatureSpawnEvent e) {
final Location l = e.getLocation();
final String w = l.getWorld().getName();
if (PlotMain.isPlotWorld(w)) {
final Plot plot = PlotHelper.getCurrentPlot(l);
if ((plot != null) && plot.hasOwner()) {
addEntity(e.getEntity(), plot);
}
}
}
@EventHandler
public static void onChunkLoad(final ChunkLoadEvent e) {
if (PlotMain.isPlotWorld(e.getWorld())) {
for (final Entity entity : e.getChunk().getEntities()) {
if (entity instanceof LivingEntity) {
if (!(entity instanceof Player)) {
final Plot plot = PlotHelper.getCurrentPlot(entity.getLocation());
if (plot != null) {
if (plot.hasOwner()) {
addEntity(entity, plot);
}
}
}
}
}
}
}
public static void addEntity(final Entity entity, final Plot plot) {
if (!entityMap.containsKey(plot.world)) {
entityMap.put(plot.world, new HashMap<Plot, HashSet<Integer>>());
}
if (!entityMap.containsKey(plot.world)) {
entityMap.put(plot.world, new HashMap<Plot, HashSet<Integer>>());
}
final HashMap<Plot, HashSet<Integer>> section = entityMap.get(plot.world);
if (!section.containsKey(plot)) {
section.put(plot, new HashSet<Integer>());
}
section.get(plot).add(entity.getEntityId());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public static void onEntityDeath(final EntityDeathEvent e) {
final Entity entity = e.getEntity();
final Location l = entity.getLocation();
final String w = l.getWorld().getName();
remove(w, entity);
}
public static void remove(String w, Entity entity) {
if (entityMap.containsKey(w)) {
final int id = entity.getEntityId();
final Plot plot = PlotHelper.getCurrentPlot(entity.getLocation());
if (plot != null) {
if (entityMap.get(w).containsKey(plot)) {
entityMap.get(w).get(plot).remove(id);
}
} else {
for (final Entry<Plot, HashSet<Integer>> n : entityMap.get(w).entrySet()) {
n.getValue().remove(id);
}
}
}
}
@EventHandler
public static void onChunkDespawn(final ChunkUnloadEvent e) {
final String w = e.getWorld().getName();
if (entityMap.containsKey(w)) {
for (final Entity entity : e.getChunk().getEntities()) {
if (entity instanceof LivingEntity) {
if (!(entity instanceof Player)) {
final Plot plot = PlotHelper.getCurrentPlot(entity.getLocation());
if (plot != null) {
if (plot.hasOwner()) {
if (entityMap.get(w).containsKey(plot)) {
if (entityMap.get(w).get(plot).size() == 1) {
entityMap.get(w).remove(plot);
} else {
entityMap.get(w).get(plot).remove(entity.getEntityId());
}
}
}
}
}
}
}
}
}
}

View File

@ -1,71 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import com.google.common.collect.ImmutableList;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
/**
* Name Fetcher Class From Bukkit
*/
public class NameFetcher implements Callable<Map<UUID, String>> {
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
private final JSONParser jsonParser = new JSONParser();
private final List<UUID> uuids;
public NameFetcher(final List<UUID> uuids) {
this.uuids = ImmutableList.copyOf(uuids);
}
@Override
public Map<UUID, String> call() throws Exception {
final Map<UUID, String> uuidStringMap = new HashMap<>();
for (final UUID uuid : this.uuids) {
if (uuidStringMap.containsKey(uuid)) {
continue;
}
final HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL + uuid.toString().replace("-", "")).openConnection();
final JSONObject response = (JSONObject) this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
final String name = (String) response.get("name");
if (name == null) {
continue;
}
final String cause = (String) response.get("cause");
final String errorMessage = (String) response.get("errorMessage");
if ((cause != null) && (cause.length() > 0)) {
throw new IllegalStateException(errorMessage);
}
uuidStringMap.put(uuid, name);
}
return uuidStringMap;
}
}

View File

@ -1,56 +0,0 @@
package com.intellectualcrafters.unused;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
public class OfflineUUIDWrapper extends UUIDWrapper {
@Override
public UUID getUUID(final Player player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
}
@Override
public UUID getUUID(final OfflinePlayer player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
}
@Override
public OfflinePlayer getOfflinePlayer(final UUID uuid) {
final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
String name;
try {
name = map.get(uuid).value;
} catch (NullPointerException e) {
name = null;
}
if (name != null) {
return Bukkit.getOfflinePlayer(name);
} else {
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (getUUID(player).equals(uuid)) {
return player;
}
}
}
return Bukkit.getOfflinePlayer(uuid.toString());
}
@Override
public Player getPlayer(final UUID uuid) {
for (final Player player : Bukkit.getOnlinePlayers()) {
if (getUUID(player).equals(uuid)) {
return player;
}
}
return null;
}
}

View File

@ -1,43 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
/**
* @author Citymonstret
*/
public enum PlotHomePosition {
CENTER("Center", 'c'),
DEFAULT("Default", 'd');
private final String string;
private final char ch;
PlotHomePosition(final String string, final char ch) {
this.string = string;
this.ch = ch;
}
public boolean isMatching(final String string) {
return ((string.length() < 2) && (string.charAt(0) == this.ch)) || string.equalsIgnoreCase(this.string);
}
}

View File

@ -1,284 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import com.google.common.base.Charsets;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.PlotHomePosition;
import com.intellectualcrafters.plot.object.PlotId;
import com.worldcretornica.plotme.PlayerList;
import com.worldcretornica.plotme.Plot;
import com.worldcretornica.plotme.PlotManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;
/**
* Created 2014-08-17 for PlotSquared
*
* @author Citymonstret
* @author Empire92
*/
public class PlotMeConverter_0_13 {
/**
* PlotMain Object
*/
private final PlotMain plugin;
/**
* Constructor
*
* @param plugin Plugin Used to run the converter
*/
public PlotMeConverter_0_13(final PlotMain plugin) {
this.plugin = plugin;
}
private void sendMessage(final String message) {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: " + message);
}
public void runAsync() throws Exception {
// We have to make it wait a couple of seconds
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
@Override
public void run() {
sendMessage("&7Conversion has started");
sendMessage("&7Caching playerdata...");
final ArrayList<com.intellectualcrafters.plot.object.Plot> createdPlots = new ArrayList<>();
// Online Mode
final boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE;
// PlotMe Plugin
final Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe");
// PlotMe Configuration
final FileConfiguration plotConfig = plotMePlugin.getConfig();
// Plot Worlds
final Set<String> worlds = new HashSet<>();
// Loop through the worlds
int duplicate;
HashMap<String, Plot> plots;
for (World world : Bukkit.getWorlds()) {
duplicate = 0;
plots = PlotManager.getPlots(world);
if (plots != null) {
worlds.add(world.getName());
sendMessage("&7Converting configuration for world '" + world.getName() + "'...");
try {
final Integer pathwidth = plotConfig.getInt("worlds." + world.getName() + ".PathWidth"); //
PlotMain.config.set("worlds." + world.getName() + ".road.width", pathwidth);
final Integer plotsize = plotConfig.getInt("worlds." + world.getName() + ".PlotSize"); //
PlotMain.config.set("worlds." + world.getName() + ".plot.size", plotsize);
final String wallblock = plotConfig.getString("worlds." + world.getName() + ".WallBlockId"); //
PlotMain.config.set("worlds." + world.getName() + ".wall.block", wallblock);
final String floor = plotConfig.getString("worlds." + world.getName() + ".PlotFloorBlockId"); //
PlotMain.config.set("worlds." + world.getName() + ".plot.floor", Arrays.asList(floor));
final String filling = plotConfig.getString("worlds." + world.getName() + ".PlotFillingBlockId"); //
PlotMain.config.set("worlds." + world.getName() + ".plot.filling", Arrays.asList(filling));
final String road = plotConfig.getString("worlds." + world.getName() + ".RoadMainBlockId");
PlotMain.config.set("worlds." + world.getName() + ".road.block", road);
final String road_stripe = plotConfig.getString("worlds." + world.getName() + ".RoadStripeBlockId");
PlotMain.config.set("worlds." + world.getName() + ".road.stripes", road_stripe);
final Integer height = plotConfig.getInt("worlds." + world.getName() + ".RoadHeight"); //
PlotMain.config.set("worlds." + world.getName() + ".road.height", height);
final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); //
PlotMain.config.set("worlds." + world.getName() + ".plot.auto_merge", auto_link);
} catch (final Exception e) {
sendMessage("&c-- &lFailed to save configuration for world '" + world.getName() + "'\nThis will need to be done using the setup command, or manually");
}
sendMessage("&7Processing '" + plots.size() + "' plots for world '" + world.getName() + "'");
ArrayList<UUID> psAdded, psTrusted, psDenied;
for (final Plot plot : plots.values()) {
psAdded = new ArrayList<>();
psTrusted = new ArrayList<>();
psDenied = new ArrayList<>();
if (world == null) {
world = Bukkit.getWorld("world");
}
try {
if (online) {
PlayerList denied;
PlayerList added;
final Field fAdded = plot.getClass().getDeclaredField("allowed");
final Field fDenied = plot.getClass().getDeclaredField("denied");
fAdded.setAccessible(true);
fDenied.setAccessible(true);
added = (PlayerList) fAdded.get(plot);
denied = (PlayerList) fDenied.get(plot);
for (final Map.Entry<String, UUID> set : added.getAllPlayers().entrySet()) {
if ((set.getValue() != null) || set.getKey().equals("*")) {
if (set.getKey().equalsIgnoreCase("*") || set.getValue().toString().equals("*")) {
psAdded.add(DBFunc.everyone);
continue;
}
}
if (set.getValue() != null) {
psAdded.add(set.getValue());
}
}
for (final Map.Entry<String, UUID> set : denied.getAllPlayers().entrySet()) {
if ((set.getValue() != null) || set.getKey().equals("*")) {
if (set.getKey().equals("*") || set.getValue().toString().equals("*")) {
psDenied.add(DBFunc.everyone);
continue;
}
}
if (set.getValue() != null) {
psDenied.add(set.getValue());
}
}
} else {
for (final String user : plot.getAllowed().split(",")) {
if (user.equals("*")) {
psAdded.add(DBFunc.everyone);
} else {
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
psAdded.add(uuid);
}
}
try {
for (final String user : plot.getDenied().split(",")) {
if (user.equals("*")) {
psDenied.add(DBFunc.everyone);
} else {
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
psDenied.add(uuid);
}
}
} catch (final Throwable e) {
// Okay, this is evil.
}
}
} catch (final Throwable e) {
e.printStackTrace();
}
final PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
com.intellectualcrafters.plot.object.Plot pl;
if (online) {
pl = new com.intellectualcrafters.plot.object.Plot(id, plot.getOwnerId(), psAdded, psTrusted, psDenied,
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false});
} else {
final String owner = plot.getOwner();
pl = new com.intellectualcrafters.plot.object.Plot(id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), psAdded, psTrusted, psDenied,
"", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false});
}
if (pl != null) {
if (!PlotMain.getPlots(world).containsKey(id)) {
createdPlots.add(pl);
} else {
duplicate++;
}
}
}
if (duplicate > 0) {
PlotMain.sendConsoleSenderMessage("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world.getName() + "'. Have you run the converter already?");
}
}
}
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating plot DB");
DBFunc.createPlots(createdPlots);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB");
// TODO createPlot doesn't add denied users
DBFunc.createAllSettingsAndHelpers(createdPlots);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration...");
try {
PlotMain.config.save(PlotMain.configFile);
} catch (final IOException e) {
PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration.");
}
boolean MV = false;
boolean MW = false;
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
MV = true;
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
MW = true;
}
for (final String worldname : worlds) {
final World world = Bukkit.getWorld(worldname);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Reloading generator for world: '" + worldname + "'...");
PlotMain.removePlotWorld(worldname);
if (MV) {
// unload
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
// load
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
} else if (MW) {
// unload
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
// load
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared");
} else {
Bukkit.getServer().unloadWorld(world, true);
final World myworld = WorldCreator.name(worldname).generator(new HybridGen(worldname)).createWorld();
myworld.save();
}
}
PlotMain.setAllPlotsRaw(DBFunc.getPlots());
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Disabling PlotMe...");
Bukkit.getPluginManager().disablePlugin(plotMePlugin);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Conversion has finished");
PlotMain.sendConsoleSenderMessage("&cAlthough the server may be functional in it's current state, it is recommended that you restart the server and remove PlotMe to finalize the installation. Please make careful note of any warning messages that may have showed up during conversion.");
}
}, 20);
}
}

View File

@ -1,120 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.json.JSONObject;
import com.intellectualcrafters.json.JSONTokener;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
/**
* Plot UUID Saver/Fetcher
*
* @author Citymonstret
* @author Empire92
*/
public class PlotUUIDSaver implements UUIDSaver {
@Override
public void globalPopulate() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
@Override
public void run() {
final OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
final int length = offlinePlayers.length;
final long start = System.currentTimeMillis();
String name;
UUID uuid;
for (final OfflinePlayer player : offlinePlayers) {
uuid = UUIDHandler.getUUID(player);
if (!UUIDHandler.uuidExists(uuid)) {
name = player.getName();
if (name != null) {
UUIDHandler.add(new StringWrapper(name), uuid);
}
}
}
final long time = System.currentTimeMillis() - start;
final int size = UUIDHandler.getUuidMap().size();
double ups;
if ((time == 0l) || (size == 0)) {
ups = size;
} else {
ups = size / time;
}
// Plot Squared Only...
PlotMain.sendConsoleSenderMessage("&cFinished caching of offline player UUIDs! Took &6" + time + "&cms (&6" + ups + "&c per millisecond), &6" + length + " &cUUIDs were cached" + " and there is now a grand total of &6" + size + " &ccached.");
}
});
}
@Override
public void globalSave(final BiMap<StringWrapper, UUID> map) {
}
@Override
public void save(final UUIDSet set) {
}
@Override
public UUID mojangUUID(final String name) throws Exception {
final URLConnection connection = new URL(Settings.API_URL + "?user=" + name).openConnection();
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
final JSONTokener tokener = new JSONTokener(connection.getInputStream());
final JSONObject root = new JSONObject(tokener);
final String uuid = root.getJSONObject(name).getString("dashed");
return UUID.fromString(uuid);
}
@Override
public String mojangName(final UUID uuid) throws Exception {
final URLConnection connection = new URL(Settings.API_URL + "?user=" + uuid.toString().replace("-", "")).openConnection();
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
final JSONTokener tokener = new JSONTokener(connection.getInputStream());
final JSONObject root = new JSONObject(tokener);
return root.getJSONObject(uuid.toString().replace("-", "")).getString("username");
}
@Override
public UUIDSet get(final String name) {
return null;
}
@Override
public UUIDSet get(final UUID uuid) {
return null;
}
}

View File

@ -1,124 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import com.google.common.collect.ImmutableList;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.Callable;
/**
* UUID Fetcher From Bukkit
*/
public class UUIDFetcher implements Callable<Map<String, UUID>> {
private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
private final boolean rateLimiting;
public UUIDFetcher(final List<String> names, final boolean rateLimiting) {
this.names = ImmutableList.copyOf(names);
this.rateLimiting = rateLimiting;
}
public UUIDFetcher(final List<String> names) {
this(names, true);
}
private static void writeBody(final HttpURLConnection connection, final String body) throws Exception {
final OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
}
private static HttpURLConnection createConnection() throws Exception {
final URL url = new URL(PROFILE_URL);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
return connection;
}
public static UUID getUUID(final String id) {
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
}
@SuppressWarnings("unused")
public static byte[] toBytes(final UUID uuid) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
@SuppressWarnings("unused")
public static UUID fromBytes(final byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
final ByteBuffer byteBuffer = ByteBuffer.wrap(array);
final long mostSignificant = byteBuffer.getLong();
final long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
@SuppressWarnings("unused")
public static UUID getUUIDOf(final String name) throws Exception {
return new UUIDFetcher(Arrays.asList(name)).call().get(name);
}
@Override
public Map<String, UUID> call() throws Exception {
final Map<String, UUID> uuidMap = new HashMap<>();
final int requests = (int) Math.ceil(this.names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++) {
final HttpURLConnection connection = createConnection();
final String body = JSONArray.toJSONString(this.names.subList(i * 100, Math.min((i + 1) * 100, this.names.size())));
writeBody(connection, body);
final JSONArray array = (JSONArray) this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (final Object profile : array) {
final JSONObject jsonProfile = (JSONObject) profile;
final String id = (String) jsonProfile.get("id");
final String name = (String) jsonProfile.get("name");
final UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name, uuid);
}
if (this.rateLimiting && (i != (requests - 1))) {
Thread.sleep(100L);
}
}
return uuidMap;
}
}

View File

@ -1,355 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.uuid.*;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
/**
* This class can be used to efficiently translate UUIDs and names back and forth. It uses three primary methods of
* achieving this: - Read From Cache - Read from OfflinePlayer objects - Read from (if onlinemode: mojang api) (else:
* playername hashing) All UUIDs/Usernames will be stored in a map (cache) until the server is restarted.
* <p/>
* You can use getUuidMap() to save the uuids/names to a file (SQLite db for example). Primary methods: getUUID(String
* name) & getName(UUID uuid) <-- You should ONLY use these. Call startFetch(JavaPlugin plugin) in your onEnable().
* <p/>
* Originally created by:
*
* @author Citymonstret
* @author Empire92 for PlotSquared.
*/
@SuppressWarnings("unused") public class UUIDHandler {
public static UUIDWrapper uuidWrapper = null;
/**
* Online mode
*
* @see org.bukkit.Server#getOnlineMode()
*/
private final static boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE;
/**
* Map containing names and UUIDs
*
* @see com.google.common.collect.BiMap
*/
private final static BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
/**
* Get the map containing all names/uuids
*
* @return map with names + uuids
*
* @see com.google.common.collect.BiMap
*/
public static BiMap<StringWrapper, UUID> getUuidMap() {
return uuidMap;
}
/**
* Check if a uuid is cached
*
* @param uuid to check
*
* @return true of the uuid is cached
*
* @see com.google.common.collect.BiMap#containsValue(Object)
*/
public static boolean uuidExists(final UUID uuid) {
return uuidMap.containsValue(uuid);
}
/**
* Check if a name is cached
*
* @param name to check
*
* @return true of the name is cached
*
* @see com.google.common.collect.BiMap#containsKey(Object)
*/
public static boolean nameExists(final StringWrapper name) {
return uuidMap.containsKey(name);
}
/**
* Add a set to the cache
*
* @param name to cache
* @param uuid to cache
*/
public static void add(final StringWrapper name, final UUID uuid) {
if (uuid == null || name == null) {
return;
}
if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) {
uuidMap.put(name, uuid);
}
}
/**
* @param name to use as key
*
* @return uuid
*/
public static UUID getUUID(final String name) {
final StringWrapper nameWrap = new StringWrapper(name);
if (uuidMap.containsKey(nameWrap)) {
return uuidMap.get(nameWrap);
}
@SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(name);
if (player != null) {
final UUID uuid = getUUID(player);
add(nameWrap, uuid);
return uuid;
}
UUID uuid;
if (online) {
if (Settings.CUSTOM_API) {
if ((uuid = getUuidOnlinePlayer(nameWrap)) != null) {
return uuid;
}
try {
return PlotMain.getUUIDSaver().mojangUUID(name);
} catch (final Exception e) {
try {
final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name);
add(nameWrap, uuid);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
} else {
try {
final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name);
add(nameWrap, uuid);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
} else {
return getUuidOfflineMode(nameWrap);
}
return null;
}
/**
* @param uuid to use as key
*
* @return name (cache)
*/
private static StringWrapper loopSearch(final UUID uuid) {
return uuidMap.inverse().get(uuid);
}
/**
* @param uuid to use as key
*
* @return Name
*/
public static String getName(final UUID uuid) {
if (uuidExists(uuid)) {
return loopSearch(uuid).value;
}
String name;
if ((name = getNameOnlinePlayer(uuid)) != null) {
return name;
}
if (!Settings.UUID_FROM_DISK) {
return null;
}
if ((name = getNameOfflinePlayer(uuid)) != null) {
return name;
}
if (online && !Settings.OFFLINE_MODE) {
if (!Settings.UUID_FECTHING) {
name = getNameOfflineFromOnlineUUID(uuid);
return name;
}
if (!Settings.CUSTOM_API) {
try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid);
return name;
} catch (final Exception ex) {
ex.printStackTrace();
}
} else {
try {
return PlotMain.getUUIDSaver().mojangName(uuid);
} catch (final Exception e) {
try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid);
return name;
} catch (final Exception ex) {
e.printStackTrace();
}
}
}
try {
return PlotMain.getUUIDSaver().mojangName(uuid);
} catch (final Exception e) {
try {
final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(new StringWrapper(name), uuid);
return name;
} catch (final Exception ex) {
ex.printStackTrace();
}
}
} else {
return "unknown";
}
return "";
}
/**
* @param name to use as key
*
* @return UUID (name hash)
*/
private static UUID getUuidOfflineMode(final StringWrapper name) {
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
add(name, uuid);
return uuid;
}
/**
* @param uuid to use as key
*
* @return String - name
*/
private static String getNameOnlinePlayer(final UUID uuid) {
final Player player = uuidWrapper.getPlayer(uuid);
if ((player == null) || !player.isOnline()) {
return null;
}
final String name = player.getName();
add(new StringWrapper(name), uuid);
return name;
}
/**
* @param uuid to use as key
*
* @return String - name
*/
private static String getNameOfflinePlayer(final UUID uuid) {
final OfflinePlayer player = uuidWrapper.getOfflinePlayer(uuid);
if ((player == null) || !player.hasPlayedBefore()) {
return null;
}
final String name = player.getName();
add(new StringWrapper(name), uuid);
return name;
}
private static UUID getUuidOnlineFromOfflinePlayer(final StringWrapper name) {
return getUUID(Bukkit.getOfflinePlayer(name.toString()));
}
private static String getNameOfflineFromOnlineUUID(final UUID uuid) {
return uuidWrapper.getOfflinePlayer(uuid).getName();
}
/**
* @param name to use as key
*
* @return UUID
*/
private static UUID getUuidOnlinePlayer(final StringWrapper name) {
@SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(name.value);
if (player == null) {
return null;
}
final UUID uuid = getUUID(player);
add(name, uuid);
return uuid;
}
/**
* Handle saving of uuids
*
* @see com.intellectualcrafters.plot.uuid.UUIDSaver#globalSave(com.google.common.collect.BiMap)
*/
@SuppressWarnings("unused")
public static void handleSaving() {
final UUIDSaver saver = PlotMain.getUUIDSaver();
saver.globalSave(getUuidMap());
}
public static UUID getUUID(final Player player) {
if (uuidWrapper == null) {
try {
getUUID(player);
uuidWrapper = new DefaultUUIDWrapper();
} catch (final Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
}
}
return uuidWrapper.getUUID(player);
}
/**
* Safely provide the correct UUID provider. Ignores user preference if not possible rather than break the plugin.
*/
public static UUID getUUID(final OfflinePlayer player) {
if (uuidWrapper == null) {
if (Settings.OFFLINE_MODE) {
uuidWrapper = new OfflineUUIDWrapper();
} else {
try {
getUUID(player);
uuidWrapper = new DefaultUUIDWrapper();
} catch (final Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
}
}
}
try {
return uuidWrapper.getUUID(player);
} catch (final Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
return uuidWrapper.getUUID(player);
}
}
}

View File

@ -1,92 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.object.StringWrapper;
import java.util.UUID;
/**
* @author Citymonstret
*/
public interface UUIDSaver {
/**
* Populate the default list
*/
public void globalPopulate();
/**
* Save the UUIDs
*
* @param biMap Map containing names and UUIDs
*/
public void globalSave(final BiMap<StringWrapper, UUID> biMap);
/**
* Save a single UUIDSet
*
* @param set Set to save
*/
public void save(final UUIDSet set);
/**
* Get a single UUIDSet
*
* @param name Username
*
* @return UUID Set
*/
public UUIDSet get(final String name);
/**
* Get a single UUIDSet
*
* @param uuid UUID
*
* @return UUID Set
*/
public UUIDSet get(final UUID uuid);
/**
* Fetch uuid from mojang servers
*
* @param name Username
*
* @return uuid
*
* @throws Exception
*/
public UUID mojangUUID(final String name) throws Exception;
/**
* Fetch username from mojang servers
*
* @param uuid UUID
*
* @return username
*
* @throws Exception
*/
public String mojangName(final UUID uuid) throws Exception;
}

View File

@ -1,69 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.unused;
import java.util.UUID;
/**
* @author Citymonstret
*/
public class UUIDSet {
/**
* Player Name
*/
private final String name;
/**
* Player UUID
*/
private final UUID uuid;
/**
* Constructor
*
* @param name Username
* @param uuid UUID
*/
public UUIDSet(final String name, final UUID uuid) {
this.name = name;
this.uuid = uuid;
}
@Override
public String toString() {
return getName();
}
/**
* Return the name
*
* @return Name
*/
public String getName() {
return this.name;
}
public UUID getUUID() {
return this.uuid;
}
}

View File

@ -1,16 +0,0 @@
package com.intellectualcrafters.unused;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
public abstract class UUIDWrapper {
public abstract UUID getUUID(Player player);
public abstract UUID getUUID(OfflinePlayer player);
public abstract OfflinePlayer getOfflinePlayer(UUID uuid);
public abstract Player getPlayer(UUID uuid);
}