mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 04:04:43 +02:00
Move all files! Hahah
This commit is contained in:
@ -0,0 +1,347 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.plot.database;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public interface AbstractDB {
|
||||
// TODO MongoDB @Brandon
|
||||
/**
|
||||
* The UUID that will count as everyone
|
||||
*/
|
||||
public UUID everyone = UUID.fromString("1-1-3-3-7");
|
||||
|
||||
/**
|
||||
* Set Plot owner
|
||||
*
|
||||
* @param plot Plot in which the owner should be set
|
||||
* @param uuid The uuid of the new owner
|
||||
*/
|
||||
public void setOwner(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* Create all settings, and create default helpers, trusted + denied lists
|
||||
*
|
||||
* @param plots Plots for which the default table entries should be created
|
||||
*/
|
||||
public void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone);
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot That should be created
|
||||
*/
|
||||
public void createPlot(final Plot plot);
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
*
|
||||
* @param database Database in which the tables will be created
|
||||
*
|
||||
* @throws SQLException If the database manager is unable to create the tables
|
||||
*/
|
||||
public void createTables(final String database) throws Exception;
|
||||
|
||||
/**
|
||||
* Delete a plot
|
||||
*
|
||||
* @param plot Plot that should be deleted
|
||||
*/
|
||||
public void delete(final Plot plot);
|
||||
|
||||
public void delete(final PlotCluster cluster);
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
*
|
||||
* @param id Plot Entry ID
|
||||
* @param plot Plot Object
|
||||
*/
|
||||
public void createPlotSettings(final int id, final Plot plot);
|
||||
|
||||
/**
|
||||
* Get the table entry ID
|
||||
*
|
||||
* @param world Which the plot is located in
|
||||
* @param id2 Plot ID
|
||||
*
|
||||
* @return Integer = Plot Entry Id
|
||||
*/
|
||||
public int getId(final String world, final PlotId id2);
|
||||
|
||||
/**
|
||||
* Get the id of a given plot cluster
|
||||
*
|
||||
* @param world Which the plot is located in
|
||||
* @param id cluster id
|
||||
*
|
||||
* @return Integer = Cluster Entry Id
|
||||
*/
|
||||
public int getClusterId(final String world, final PlotClusterId id);
|
||||
|
||||
/**
|
||||
* @return A linked hashmap containing all plots
|
||||
*/
|
||||
public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots();
|
||||
|
||||
/**
|
||||
* @return A hashmap containing all plot clusters
|
||||
*/
|
||||
public HashMap<String, HashSet<PlotCluster>> getClusters();
|
||||
|
||||
/**
|
||||
* Set the merged status for a plot
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param merged boolean[]
|
||||
*/
|
||||
public void setMerged(final Plot plot, final boolean[] merged);
|
||||
|
||||
/**
|
||||
* Swap the settings, helpers etc. of two plots
|
||||
* @param p1 Plot1
|
||||
* @param p2 Plot2
|
||||
*/
|
||||
public void swapPlots(final Plot p1, final Plot p2);
|
||||
|
||||
/**
|
||||
* Set plot flags
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
public void setFlags(final Plot plot, final Collection<Flag> flags);
|
||||
|
||||
/**
|
||||
* Set cluster flags
|
||||
*
|
||||
* @param cluster PlotCluster Object
|
||||
* @param flags flags to set (flag[])
|
||||
*/
|
||||
public void setFlags(final PlotCluster cluster, final Collection<Flag> flags);
|
||||
|
||||
/**
|
||||
* Rename a cluster
|
||||
*/
|
||||
public void setClusterName(final PlotCluster cluster, final String name);
|
||||
|
||||
/**
|
||||
* Set the plot alias
|
||||
*
|
||||
* @param plot Plot for which the alias should be set
|
||||
* @param alias Plot Alias
|
||||
*/
|
||||
public void setAlias(final Plot plot, final String alias);
|
||||
|
||||
/**
|
||||
* Purgle a plot
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param uniqueIds list of plot id (db) to be purged
|
||||
*/
|
||||
public void purgeIds(final String world, final Set<Integer> uniqueIds);
|
||||
|
||||
/**
|
||||
* Purge a whole world
|
||||
*
|
||||
* @param world World in which the plots should be purged
|
||||
*/
|
||||
public void purge(final String world, final Set<PlotId> plotIds);
|
||||
|
||||
/**
|
||||
* Set Plot Home Position
|
||||
*
|
||||
* @param plot Plot Object
|
||||
* @param position Plot Home Position
|
||||
*/
|
||||
public void setPosition(final Plot plot, final String position);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cluster
|
||||
* @param position
|
||||
*/
|
||||
public void setPosition(final PlotCluster cluster, final String position);
|
||||
|
||||
/**
|
||||
* @param id Plot Entry ID
|
||||
*
|
||||
* @return Plot Settings
|
||||
*/
|
||||
public HashMap<String, Object> getSettings(final int id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return HashMap<String, Object>
|
||||
*/
|
||||
public HashMap<String, Object> getClusterSettings(final int id);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void removeTrusted(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param cluster PlotCluster Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void removeHelper(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void removeMember(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public void removeInvited(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void setTrusted(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param cluster PlotCluster Object
|
||||
* @param uuid Player that should be removed
|
||||
*/
|
||||
public void setHelper(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player that should be added
|
||||
*/
|
||||
public void setMember(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public void setInvited(final PlotCluster cluster, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player uuid
|
||||
*/
|
||||
public void removeDenied(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* @param plot Plot Object
|
||||
* @param uuid Player uuid that should be added
|
||||
*/
|
||||
public void setDenied(final Plot plot, final UUID uuid);
|
||||
|
||||
/**
|
||||
* Get Plots ratings
|
||||
*
|
||||
* @param plot Plot Object
|
||||
*
|
||||
* @return Plot Ratings (pre-calculated)
|
||||
*/
|
||||
public HashMap<UUID, Integer> getRatings(final Plot plot);
|
||||
|
||||
/**
|
||||
* Set a rating for a plot
|
||||
* @param plot
|
||||
* @param rater
|
||||
* @param value
|
||||
*/
|
||||
public void setRating(final Plot plot, UUID rater, int value);
|
||||
|
||||
/**
|
||||
* Remove a plot comment
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param comment Comment to remove
|
||||
*/
|
||||
public void removeComment(final Plot plot, final PlotComment comment);
|
||||
|
||||
/**
|
||||
* Clear an inbox
|
||||
* @param plot
|
||||
* @param inbox
|
||||
*/
|
||||
public void clearInbox(Plot plot, String inbox);
|
||||
|
||||
/**
|
||||
* Set a plot comment
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param comment Comment to add
|
||||
*/
|
||||
public void setComment(final Plot plot, final PlotComment comment);
|
||||
|
||||
/**
|
||||
* Get Plot Comments
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param plot Plot Object
|
||||
* @param tier Comment Tier
|
||||
*
|
||||
* @return Plot Comments within the specified tier
|
||||
*/
|
||||
public void getComments(final Plot plot, final String inbox, RunnableVal whenDone);
|
||||
|
||||
public void createPlotAndSettings(Plot plot);
|
||||
|
||||
public void createCluster(PlotCluster cluster);
|
||||
|
||||
public void resizeCluster(PlotCluster current, PlotClusterId resize);
|
||||
|
||||
public void movePlot(Plot originalPlot, Plot newPlot);
|
||||
|
||||
/**
|
||||
* Don't fuck with this one, unless you enjoy it rough
|
||||
*/
|
||||
public boolean deleteTables();
|
||||
}
|
431
src/main/java/com/intellectualcrafters/plot/database/DBFunc.java
Normal file
431
src/main/java/com/intellectualcrafters/plot/database/DBFunc.java
Normal file
@ -0,0 +1,431 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.plot.database;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
|
||||
/**
|
||||
* DB Functions
|
||||
*
|
||||
* @author Empire92
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DBFunc {
|
||||
/**
|
||||
* The "global" uuid
|
||||
*/
|
||||
public static final UUID everyone = UUID.fromString("1-1-3-3-7");
|
||||
/**
|
||||
* Abstract Database Manager
|
||||
*/
|
||||
public static AbstractDB dbManager;
|
||||
|
||||
public static void movePlot(final Plot originalPlot, final Plot newPlot) {
|
||||
if (originalPlot.temp || newPlot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.movePlot(originalPlot, newPlot);
|
||||
}
|
||||
/**
|
||||
* Check if a resultset contains a column
|
||||
* @param rs
|
||||
* @param columnName
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static boolean hasColumn(ResultSet r, String name) {
|
||||
try {
|
||||
ResultSetMetaData meta = r.getMetaData();
|
||||
int count = meta.getColumnCount();
|
||||
for (int x = 1; x <= count; x++) {
|
||||
if (name.equals(meta.getColumnName(x))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the owner of a plot
|
||||
*
|
||||
* @param plot Plot Object
|
||||
* @param uuid New Owner
|
||||
*/
|
||||
public static void setOwner(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setOwner(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all settings + (trusted, denied, members)
|
||||
*
|
||||
* @param plots List containing all plot objects
|
||||
*/
|
||||
public static void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone) {
|
||||
dbManager.createPlotsAndData(plots, whenDone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot Plot to create
|
||||
*/
|
||||
public static void createPlot(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.createPlot(plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a plot
|
||||
*
|
||||
* @param plot Plot to create
|
||||
*/
|
||||
public static void createPlotAndSettings(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.createPlotAndSettings(plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void createTables(final String database) throws Exception {
|
||||
dbManager.createTables(database);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a plot
|
||||
*
|
||||
* @param plot Plot to delete
|
||||
*/
|
||||
public static void delete(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.delete(plot);
|
||||
}
|
||||
|
||||
public static void delete(final PlotCluster toDelete) {
|
||||
dbManager.delete(toDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
*
|
||||
* @param id Plot ID
|
||||
* @param plot Plot Object
|
||||
*/
|
||||
public static void createPlotSettings(final int id, final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.createPlotSettings(id, plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot id
|
||||
*
|
||||
* @param world World
|
||||
* @param id2 Plot ID
|
||||
*
|
||||
* @return ID
|
||||
*/
|
||||
/*
|
||||
* public static int getId(String plotId id2) { Statement stmt =
|
||||
* null; try { stmt = connection.createStatement(); ResultSet r =
|
||||
* stmt.executeQuery("SELECT `id` FROM `plot` WHERE `plot_id_x` = '" + id2.x
|
||||
* + "' AND `plot_id_z` = '" + id2.y + "' AND `world` = '" + world +
|
||||
* "' ORDER BY `timestamp` ASC"); int id = Integer.MAX_VALUE;
|
||||
* while(r.next()) { id = r.getInt("id"); } stmt.close(); return id; }
|
||||
* catch(SQLException e) { e.printStackTrace(); } return Integer.MAX_VALUE;
|
||||
* }
|
||||
*/
|
||||
public static int getId(final String world, final PlotId id2) {
|
||||
return dbManager.getId(world, id2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Plots
|
||||
*/
|
||||
public static LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
|
||||
return dbManager.getPlots();
|
||||
}
|
||||
|
||||
public static void setMerged(final Plot plot, final boolean[] merged) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setMerged(plot, merged);
|
||||
}
|
||||
|
||||
public static void setFlags(final Plot plot, final Collection<Flag> flags) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setFlags(plot, flags);
|
||||
}
|
||||
|
||||
public static void setFlags(final PlotCluster cluster, final Collection<Flag> flags) {
|
||||
dbManager.setFlags(cluster, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param alias
|
||||
*/
|
||||
public static void setAlias(final Plot plot, final String alias) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setAlias(plot, alias);
|
||||
}
|
||||
|
||||
public static void purgeIds(final String world, final Set<Integer> uniqueIds) {
|
||||
dbManager.purgeIds(world, uniqueIds);
|
||||
}
|
||||
|
||||
public static void purge(final String world, final Set<PlotId> plotIds) {
|
||||
dbManager.purge(world, plotIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param position
|
||||
*/
|
||||
public static void setPosition(final Plot plot, final String position) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setPosition(plot, position);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return HashMap<String, Object>
|
||||
*/
|
||||
public static HashMap<String, Object> getSettings(final int id) {
|
||||
return dbManager.getSettings(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param comment
|
||||
*/
|
||||
public static void removeComment(final Plot plot, final PlotComment comment) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeComment(plot, comment);
|
||||
}
|
||||
|
||||
public static void clearInbox(final Plot plot, final String inbox) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.clearInbox(plot, inbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param comment
|
||||
*/
|
||||
public static void setComment(final Plot plot, final PlotComment comment) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setComment(plot, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
*/
|
||||
public static void getComments(final Plot plot, final String inbox, RunnableVal whenDone) {
|
||||
if (plot != null && plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.getComments(plot, inbox, whenDone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeTrusted(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeTrusted(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeHelper(final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.removeHelper(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param cluster
|
||||
*/
|
||||
public static void createCluster(final String world, final PlotCluster cluster) {
|
||||
dbManager.createCluster(cluster);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param current
|
||||
* @param resize
|
||||
*/
|
||||
public static void resizeCluster(final PlotCluster current, final PlotClusterId resize) {
|
||||
dbManager.resizeCluster(current, resize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeMember(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeMember(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cluster
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeInvited(final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.removeInvited(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void setTrusted(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setTrusted(plot, uuid);
|
||||
}
|
||||
|
||||
public static void setHelper(final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.setHelper(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void setMember(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setMember(plot, uuid);
|
||||
}
|
||||
|
||||
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) {
|
||||
dbManager.setInvited(cluster, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void removeDenied(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.removeDenied(plot, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param plot
|
||||
* @param uuid
|
||||
*/
|
||||
public static void setDenied(final Plot plot, final UUID uuid) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setDenied(plot, uuid);
|
||||
}
|
||||
|
||||
public static HashMap<UUID, Integer> getRatings(final Plot plot) {
|
||||
if (plot.temp) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return dbManager.getRatings(plot);
|
||||
}
|
||||
|
||||
public static void setRating(Plot plot, UUID rater, int value) {
|
||||
if (plot.temp) {
|
||||
return;
|
||||
}
|
||||
dbManager.setRating(plot, rater, value);
|
||||
}
|
||||
|
||||
public static HashMap<String, HashSet<PlotCluster>> getClusters() {
|
||||
return dbManager.getClusters();
|
||||
}
|
||||
|
||||
public static void setPosition(final PlotCluster cluster, final String position) {
|
||||
dbManager.setPosition(cluster, position);
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> getClusterSettings(final int id) {
|
||||
return dbManager.getClusterSettings(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.plot.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Abstract Database class, serves as a base for any connection method (MySQL, SQLite, etc.)
|
||||
*
|
||||
* @author -_Husky_-
|
||||
* @author tips48
|
||||
*/
|
||||
public abstract class Database {
|
||||
|
||||
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException ;
|
||||
|
||||
/**
|
||||
* Opens a connection with the database
|
||||
*
|
||||
* @return Opened connection
|
||||
*
|
||||
* @throws SQLException if the connection can not be opened
|
||||
* @throws ClassNotFoundException if the driver cannot be found
|
||||
*/
|
||||
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Checks if a connection is open with the database
|
||||
*
|
||||
* @return true if the connection is open
|
||||
*
|
||||
* @throws SQLException if the connection cannot be checked
|
||||
*/
|
||||
public abstract boolean checkConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Gets the connection with the database
|
||||
*
|
||||
* @return Connection with the database, null if none
|
||||
*/
|
||||
public abstract Connection getConnection();
|
||||
|
||||
/**
|
||||
* Closes the connection with the database
|
||||
*
|
||||
* @return true if successful
|
||||
*
|
||||
* @throws SQLException if the connection cannot be closed
|
||||
*/
|
||||
public abstract boolean closeConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Executes a SQL Query<br> If the connection is closed, it will be opened
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
* @return the results of the query
|
||||
*
|
||||
* @throws SQLException If the query cannot be executed
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public abstract ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* Executes an Update SQL Query<br> See {@link java.sql.Statement#executeUpdate(String)}<br> If the connection is
|
||||
* closed, it will be opened
|
||||
*
|
||||
* @param query Query to be run
|
||||
*
|
||||
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
|
||||
*
|
||||
* @throws SQLException If the query cannot be executed
|
||||
* @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()}
|
||||
*/
|
||||
public abstract int updateSQL(final String query) throws SQLException, ClassNotFoundException;
|
||||
}
|
113
src/main/java/com/intellectualcrafters/plot/database/MySQL.java
Normal file
113
src/main/java/com/intellectualcrafters/plot/database/MySQL.java
Normal file
@ -0,0 +1,113 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.plot.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Connects to and uses a MySQL database
|
||||
*
|
||||
* @author -_Husky_-
|
||||
* @author tips48
|
||||
*/
|
||||
public class MySQL extends Database {
|
||||
private final String user;
|
||||
private final String database;
|
||||
private final String password;
|
||||
private final String port;
|
||||
private final String hostname;
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Creates a new MySQL instance
|
||||
*
|
||||
* @param hostname Name of the host
|
||||
* @param port Port number
|
||||
* @param database Database name
|
||||
* @param username Username
|
||||
* @param password Password
|
||||
*/
|
||||
public MySQL(final String hostname, final String port, final String database, final String username, final String password) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
this.user = username;
|
||||
this.password = password;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
public Connection forceConnection() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeQuery(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeUpdate(query);
|
||||
}
|
||||
}
|
2258
src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
Normal file
2258
src/main/java/com/intellectualcrafters/plot/database/SQLManager.java
Normal file
File diff suppressed because it is too large
Load Diff
116
src/main/java/com/intellectualcrafters/plot/database/SQLite.java
Normal file
116
src/main/java/com/intellectualcrafters/plot/database/SQLite.java
Normal file
@ -0,0 +1,116 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.plot.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
/**
|
||||
* Connects to and uses a SQLite database
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author tips48
|
||||
*/
|
||||
public class SQLite extends Database {
|
||||
private final String dbLocation;
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Creates a new SQLite instance
|
||||
*
|
||||
* @param dbLocation Location of the Database (Must end in .db)
|
||||
*/
|
||||
public SQLite(final String dbLocation) {
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
if (!PS.get().IMP.getDirectory().exists()) {
|
||||
PS.get().IMP.getDirectory().mkdirs();
|
||||
}
|
||||
final File file = new File(this.dbLocation);
|
||||
if (!(file.exists())) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (final IOException e) {
|
||||
PS.log("&cUnable to create database!");
|
||||
}
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeQuery(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
final Statement statement = this.connection.createStatement();
|
||||
return statement.executeUpdate(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection forceConnection() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public abstract class StmtMod<T> {
|
||||
public abstract String getCreateMySQL(int size);
|
||||
|
||||
public String getCreateMySQL(int size, String query, int params) {
|
||||
final StringBuilder statement = new StringBuilder(query);
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + "),");
|
||||
}
|
||||
statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + ")");
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
public String getCreateSQLite(int size, String query, int params) {
|
||||
StringBuilder statement = new StringBuilder(query);
|
||||
String modParams = StringUtils.repeat(",?", params).substring(1);
|
||||
for (int i = 0; i < (size - 1); i++) {
|
||||
statement.append("UNION SELECT " + modParams + " ");
|
||||
}
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
public abstract String getCreateSQLite(int size);
|
||||
public abstract String getCreateSQL();
|
||||
|
||||
public abstract void setMySQL(PreparedStatement stmt, int i, T obj) throws SQLException;
|
||||
public abstract void setSQLite(PreparedStatement stmt, int i, T obj) throws SQLException;
|
||||
public abstract void setSQL(PreparedStatement stmt, T obj) throws SQLException;
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public abstract class APlotMeConnector {
|
||||
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
||||
|
||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;
|
||||
|
||||
public abstract boolean accepts(String version);
|
||||
|
||||
public String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public boolean isValidConnection(Connection connection) {
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) {
|
||||
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth);
|
||||
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize);
|
||||
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock);
|
||||
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Arrays.asList(floor));
|
||||
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Arrays.asList(filling));
|
||||
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.block", road);
|
||||
Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||
if (height == null) {
|
||||
height = 64;
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
}
|
||||
|
||||
public Location getPlotTopLocAbs(int path, int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 256, z);
|
||||
}
|
||||
|
||||
public Location getPlotBottomLocAbs(int path, int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 1, z);
|
||||
}
|
||||
|
||||
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
|
||||
HashMap<PlotId, boolean[]> plots = merges.get(world);
|
||||
PlotId id2;
|
||||
switch (direction) {
|
||||
case 0: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean[] merge1;
|
||||
boolean[] merge2;
|
||||
if (plots.containsKey(id)) {
|
||||
merge1 = plots.get(id);
|
||||
}
|
||||
else {
|
||||
merge1 = new boolean[]{false, false, false, false};
|
||||
}
|
||||
if (plots.containsKey(id2)) {
|
||||
merge2 = plots.get(id2);
|
||||
}
|
||||
else {
|
||||
merge2 = new boolean[]{false, false, false, false};
|
||||
}
|
||||
merge1[direction] = true;
|
||||
merge2[(direction + 2) % 4] = true;
|
||||
plots.put(id, merge1);
|
||||
plots.put(id2, merge1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class ClassicPlotMeConnector extends APlotMeConnector {
|
||||
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
final String user = plotConfig.getString("mySQLuname");
|
||||
final String password = plotConfig.getString("mySQLpass");
|
||||
final String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
// return new MySQL(plotsquared, hostname, port, database, username, password)
|
||||
} else {
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
final HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
final HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Plots`");
|
||||
r = stmt.executeQuery();
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
||||
boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("owner");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
plots.put(world, new HashMap<PlotId, Plot>());
|
||||
if (merge) {
|
||||
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId,boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
int tx = r.getInt("topX");
|
||||
int tz = r.getInt("topZ");
|
||||
int bx = r.getInt("bottomX") - 1;
|
||||
int bz = r.getInt("bottomZ") - 1;
|
||||
int path = roadWidth.get(world);
|
||||
int plot = plotWidth.get(world);
|
||||
Location top = getPlotTopLocAbs(path, plot, id);
|
||||
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
if (checkUUID){
|
||||
try {
|
||||
byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
if (owner != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
final Plot plot = new Plot(world, id, owner);
|
||||
plots.get(world).put(id, plot);
|
||||
}
|
||||
|
||||
for (Entry<String, HashMap<PlotId, boolean[]>> entry : merges.entrySet()) {
|
||||
String world = entry.getKey();
|
||||
for (Entry<PlotId, boolean[]> entry2 : entry.getValue().entrySet()) {
|
||||
HashMap<PlotId, Plot> newplots = plots.get(world);
|
||||
Plot plot = newplots.get(entry2.getKey());
|
||||
if (plot != null) {
|
||||
plot.settings.setMerged(entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
try {
|
||||
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "Denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID denied = UUIDHandler.getUUID(name);
|
||||
if (denied == null) {
|
||||
if (name.equals("*")) {
|
||||
denied = DBFunc.everyone;
|
||||
} else {
|
||||
MainUtil.sendConsoleMessage("&6Could not identify denied for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).denied.add(denied);
|
||||
}
|
||||
}
|
||||
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID helper = UUIDHandler.getUUID(name);
|
||||
if (helper == null) {
|
||||
if (name.equals("*")) {
|
||||
helper = DBFunc.everyone;
|
||||
} else {
|
||||
MainUtil.sendConsoleMessage("&6Could not identify helper for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).trusted.add(helper);
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return plots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(String version) {
|
||||
if (version == null) {
|
||||
return true;
|
||||
}
|
||||
return PS.get().canUpdate(version, "0.17.0");
|
||||
}
|
||||
}
|
@ -0,0 +1,323 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* Created 2014-08-17 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class LikePlotMeConverter {
|
||||
private String plugin;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin Plugin Used to run the converter
|
||||
*/
|
||||
public LikePlotMeConverter(String plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
private void sendMessage(final String message) {
|
||||
PS.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||
}
|
||||
|
||||
public String getPlotMePath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public String getAthionPlotsPath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||
if (!plotMeFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
}
|
||||
|
||||
public Set<String> getPlotMeWorlds(FileConfiguration plotConfig) {
|
||||
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
}
|
||||
|
||||
public void updateWorldYml(String plugin, String location) {
|
||||
try {
|
||||
Path path = Paths.get(location);
|
||||
File file = new File(location);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
String content = new String(Files.readAllBytes(path), charset);
|
||||
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
|
||||
content = content.replaceAll(plugin, "PlotSquared");
|
||||
Files.write(path, content.getBytes(charset));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean run(final APlotMeConnector connector) {
|
||||
try {
|
||||
String dataFolder = getPlotMePath();
|
||||
FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
||||
if (plotConfig == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String version = plotConfig.getString("Version");
|
||||
if (version == null) version = plotConfig.getString("version");
|
||||
if (!connector.accepts(version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PS.log("&3Using connector: " + connector.getClass().getCanonicalName());
|
||||
|
||||
Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
||||
|
||||
if (!connector.isValidConnection(connection)) {
|
||||
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
|
||||
sendMessage("Connecting to " + plugin + " DB");
|
||||
|
||||
int plotCount = 0;
|
||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||
|
||||
sendMessage("Collecting plot data");
|
||||
|
||||
String dbPrefix = plugin.toLowerCase();
|
||||
sendMessage(" - " + dbPrefix + "Plots");
|
||||
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
||||
|
||||
if (Settings.CONVERT_PLOTME) {
|
||||
sendMessage("Updating bukkit.yml");
|
||||
updateWorldYml(plugin, "bukkit.yml");
|
||||
updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
|
||||
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
|
||||
sendMessage("Copying config for: " + world);
|
||||
try {
|
||||
String actualWorldName = getWorld(world);
|
||||
connector.copyConfig(plotConfig, world, actualWorldName);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
|
||||
}
|
||||
}
|
||||
}
|
||||
HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||
plotCount += entry.getValue().size();
|
||||
}
|
||||
if (!Settings.CONVERT_PLOTME) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(" - " + dbPrefix + "Allowed");
|
||||
|
||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||
final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||
if (PLOTME_DG_FILE.exists()) {
|
||||
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
|
||||
try {
|
||||
for (final String world : plots.keySet()) {
|
||||
String actualWorldName = getWorld(world);
|
||||
final String plotMeWorldName = world.toLowerCase();
|
||||
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||
if (pathwidth == null) {
|
||||
pathwidth = 7;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.width", pathwidth);
|
||||
Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
|
||||
if (plotsize == null) {
|
||||
plotsize = 32;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.size", plotsize);
|
||||
String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
|
||||
if (wallblock == null) {
|
||||
wallblock = "44";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".wall.block", wallblock);
|
||||
String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
|
||||
if (floor == null) {
|
||||
floor = "2";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.floor", Arrays.asList(floor));
|
||||
String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
|
||||
if (filling == null) {
|
||||
filling = "3";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.filling", Arrays.asList(filling));
|
||||
String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
|
||||
if (road == null) {
|
||||
road = "5";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.block", road);
|
||||
Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||
if ((height == null) || (height == 0)) {
|
||||
height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
|
||||
if ((height == null) || (height == 0)) {
|
||||
height = 64;
|
||||
}
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
for (final String world : plots.keySet()) {
|
||||
int duplicate = 0;
|
||||
for (final Plot plot : plots.get(world).values()) {
|
||||
if (!PS.get().getPlots(world).containsKey(plot.id)) {
|
||||
createdPlots.add(plot);
|
||||
} else {
|
||||
duplicate++;
|
||||
}
|
||||
}
|
||||
if (duplicate > 0) {
|
||||
PS.log("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||
}
|
||||
}
|
||||
sendMessage("Creating plot DB");
|
||||
Thread.sleep(1000);
|
||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendMessage("&aDatabase conversion is now complete!");
|
||||
PS.log("&c - Stop the server");
|
||||
PS.log("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||
PS.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||
PS.log("&c - Start the server");
|
||||
PS.get().setAllPlotsRaw(DBFunc.getPlots());
|
||||
}
|
||||
});
|
||||
sendMessage("Saving configuration...");
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
sendMessage(" - &cFailed to save configuration.");
|
||||
}
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
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(getWorld(worldname));
|
||||
if (world == null) {
|
||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
|
||||
}
|
||||
final String actualWorldName = world.getName();
|
||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
||||
PS.get().removePlotWorld(actualWorldName);
|
||||
if (MV) {
|
||||
// unload world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
|
||||
} else if (MW) {
|
||||
// unload world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
||||
} else {
|
||||
// Load using Bukkit API
|
||||
// - User must set generator manually
|
||||
Bukkit.getServer().unloadWorld(world, true);
|
||||
final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen(actualWorldName)).createWorld();
|
||||
myworld.save();
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
PS.log("&/end/");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class PlotMeConnector_017 extends APlotMeConnector {
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
String user = plotConfig.getString("mySQLuname");
|
||||
String password = plotConfig.getString("mySQLpass");
|
||||
String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
} else {
|
||||
File file = new File(dataFolder + File.separator + "plotmecore.db");
|
||||
if (file.exists()) {
|
||||
return new SQLite(dataFolder + File.separator + "plotmecore.db").openConnection();
|
||||
}
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<Integer, Plot> plots = new HashMap<>();
|
||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`");
|
||||
r = stmt.executeQuery();
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerID");
|
||||
boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
PlotId id = new PlotId(r.getInt("plotX"), r.getInt("plotZ"));
|
||||
String name = r.getString("owner");
|
||||
String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
if (merge) {
|
||||
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId,boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
int tx = r.getInt("topX");
|
||||
int tz = r.getInt("topZ");
|
||||
int bx = r.getInt("bottomX") - 1;
|
||||
int bz = r.getInt("bottomZ") - 1;
|
||||
int path = roadWidth.get(world);
|
||||
int plot = plotWidth.get(world);
|
||||
Location top = getPlotTopLocAbs(path, plot, id);
|
||||
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
if (checkUUID){
|
||||
try {
|
||||
byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
if (owner != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
Plot plot = new Plot(world, id, owner);
|
||||
plots.put(key, plot);
|
||||
}
|
||||
for (Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.world);
|
||||
if (mergeMap != null) {
|
||||
if (mergeMap.containsKey(plot.id)) {
|
||||
plot.settings.setMerged(mergeMap.get(plot.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
try {
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "core_denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
MainUtil.sendConsoleMessage("&6Denied (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
UUID denied = UUID.fromString(r.getString("player"));
|
||||
plot.denied.add(denied);
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "core_allowed");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
MainUtil.sendConsoleMessage("&6Allowed (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
UUID allowed = UUID.fromString(r.getString("player"));
|
||||
plot.trusted.add(allowed);
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HashMap<String, HashMap<PlotId, Plot>> processed = new HashMap<>();
|
||||
|
||||
for (Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
HashMap<PlotId, Plot> map = processed.get(plot.world);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
processed.put(plot.world, map);
|
||||
}
|
||||
map.put(plot.id, plot);
|
||||
}
|
||||
return processed ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(String version) {
|
||||
if (version == null) {
|
||||
return false;
|
||||
}
|
||||
return !PS.get().canUpdate(version, "0.17");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user