Class SQLManager

java.lang.Object
com.plotsquared.core.database.SQLManager
All Implemented Interfaces:
AbstractDB

public class SQLManager extends Object implements AbstractDB
  • Field Details

  • Constructor Details

  • Method Details

    • isValid

      public boolean isValid()
    • reconnect

      public void reconnect()
    • getGlobalTasks

      public Queue<Runnable> getGlobalTasks()
    • getNotifyTasks

      public Queue<Runnable> getNotifyTasks()
    • addPlotTask

      public void addPlotTask(@NonNull Plot plot, SQLManager.UniqueStatement task)
    • addPlayerTask

      public void addPlayerTask(UUID uuid, SQLManager.UniqueStatement task)
    • addClusterTask

      public void addClusterTask(PlotCluster cluster, SQLManager.UniqueStatement task)
    • addGlobalTask

      public void addGlobalTask(Runnable task)
    • addNotifyTask

      public void addNotifyTask(Runnable task)
    • sendBatch

      public boolean sendBatch()
    • getConnection

      public Connection getConnection()
    • setOwner

      public void setOwner(Plot plot, UUID uuid)
      Set Plot owner
      Specified by:
      setOwner in interface AbstractDB
      Parameters:
      plot - Plot Object
      uuid - Owner UUID
    • createPlotsAndData

      public void createPlotsAndData(List<Plot> myList, Runnable whenDone)
      Description copied from interface: AbstractDB
      Creates all settings, and create default helpers, trusted + denied lists.
      Specified by:
      createPlotsAndData in interface AbstractDB
      Parameters:
      myList - Plots for which the default table entries should be created
      whenDone - the task to run when the method is finished executing
    • createTiers

      public void createTiers(ArrayList<com.plotsquared.core.database.SQLManager.UUIDPair> myList, String tier, Runnable whenDone)
      Create a plot
      Parameters:
      myList - list of plots to be created
    • createFlags

      public void createFlags(Map<PlotId,​Integer> ids, List<Plot> plots, Runnable whenDone)
    • createPlots

      public void createPlots(List<Plot> myList, Runnable whenDone)
      Create a plot
      Parameters:
      myList - list of plots to be created
    • setBulk

      public <T> void setBulk(List<T> objList, StmtMod<T> mod, Runnable whenDone)
    • createSettings

      public void createSettings(ArrayList<com.plotsquared.core.database.SQLManager.LegacySettings> myList, Runnable whenDone)
    • createEmptySettings

      public void createEmptySettings(ArrayList<Integer> myList, Runnable whenDone)
    • createPlotSafe

      public void createPlotSafe(Plot plot, Runnable success, Runnable failure)
      Description copied from interface: AbstractDB
      Creates a plot.
      Specified by:
      createPlotSafe in interface AbstractDB
      Parameters:
      plot - the plot to create
    • commit

      public void commit()
    • createPlotAndSettings

      public void createPlotAndSettings(Plot plot, Runnable whenDone)
      Specified by:
      createPlotAndSettings in interface AbstractDB
    • createTables

      public void createTables() throws SQLException
      Create tables.
      Specified by:
      createTables in interface AbstractDB
      Throws:
      SQLException
    • deleteSettings

      public void deleteSettings(Plot plot)
      Specified by:
      deleteSettings in interface AbstractDB
    • deleteHelpers

      public void deleteHelpers(Plot plot)
      Specified by:
      deleteHelpers in interface AbstractDB
    • deleteTrusted

      public void deleteTrusted(Plot plot)
      Specified by:
      deleteTrusted in interface AbstractDB
    • deleteDenied

      public void deleteDenied(Plot plot)
      Description copied from interface: AbstractDB
      Removes all denied players from the plot.
      Specified by:
      deleteDenied in interface AbstractDB
      Parameters:
      plot - the plot
    • deleteComments

      public void deleteComments(Plot plot)
      Description copied from interface: AbstractDB
      Deletes all comments from the plot.
      Specified by:
      deleteComments in interface AbstractDB
      Parameters:
      plot - the plot
    • deleteRatings

      public void deleteRatings(Plot plot)
      Specified by:
      deleteRatings in interface AbstractDB
    • delete

      public void delete(Plot plot)
      Delete a plot.
      Specified by:
      delete in interface AbstractDB
      Parameters:
      plot -
    • createPlotSettings

      public void createPlotSettings(int id, Plot plot)
      Creates plot settings
      Specified by:
      createPlotSettings in interface AbstractDB
      Parameters:
      id -
      plot -
    • getClusterId

      public int getClusterId(PlotCluster cluster)
      Description copied from interface: AbstractDB
      Gets the id of a given plot cluster.
      Specified by:
      getClusterId in interface AbstractDB
      Parameters:
      cluster - PlotCluster Object
      Returns:
      Integer = Cluster Entry Id
    • getId

      public int getId(Plot plot)
      Description copied from interface: AbstractDB
      Gets the table entry ID.
      Specified by:
      getId in interface AbstractDB
      Parameters:
      plot - the plot
      Returns:
      Integer = Plot Entry Id
    • updateTables

      public void updateTables(int[] oldVersion)
      Specified by:
      updateTables in interface AbstractDB
    • deleteRows

      public void deleteRows(ArrayList<Integer> rowIds, String table, String column)
    • convertFlags

      public boolean convertFlags()
      Specified by:
      convertFlags in interface AbstractDB
    • getPlots

      public HashMap<String,​HashMap<PlotId,​Plot>> getPlots()
      Load all plots, helpers, denied, trusted, and every setting from DB into a HashMap.
      Specified by:
      getPlots in interface AbstractDB
      Returns:
      A linked HashMap containing all plots
    • setMerged

      public void setMerged(Plot plot, boolean[] merged)
      Description copied from interface: AbstractDB
      Sets the merged status for a plot.
      Specified by:
      setMerged in interface AbstractDB
      Parameters:
      plot - The plot to set the merged status of
      merged - boolean[]
    • swapPlots

      public CompletableFuture<Boolean> swapPlots(Plot plot1, Plot plot2)
      Description copied from interface: AbstractDB
      Swaps the settings, helpers etc. of two plots.
      Specified by:
      swapPlots in interface AbstractDB
      Parameters:
      plot1 - Plot1
      plot2 - Plot2
    • movePlot

      public void movePlot(Plot original, Plot newPlot)
      Specified by:
      movePlot in interface AbstractDB
    • setFlag

      public void setFlag(Plot plot, PlotFlag<?,​?> flag)
      Description copied from interface: AbstractDB
      Sets plot flag.
      Specified by:
      setFlag in interface AbstractDB
      Parameters:
      plot - Plot Object
      flag - Flag to set
    • removeFlag

      public void removeFlag(Plot plot, PlotFlag<?,​?> flag)
      Description copied from interface: AbstractDB
      Remove a plot flag.
      Specified by:
      removeFlag in interface AbstractDB
      Parameters:
      plot - Plot Object
      flag - Flag to remove
    • setAlias

      public void setAlias(Plot plot, String alias)
      Description copied from interface: AbstractDB
      Sets the plot alias.
      Specified by:
      setAlias in interface AbstractDB
      Parameters:
      plot - Plot for which the alias should be set
      alias - Plot Alias
    • purgeIds

      public void purgeIds(Set<Integer> uniqueIds)
      Purge all plots with the following database IDs
      Specified by:
      purgeIds in interface AbstractDB
      Parameters:
      uniqueIds - list of plot id (db) to be purged
    • purge

      public void purge(PlotArea area, Set<PlotId> plots)
      Description copied from interface: AbstractDB
      Purges a whole world.
      Specified by:
      purge in interface AbstractDB
      Parameters:
      area - World in which the plots should be purged
      plots - the PlotIds of Plots to purge
    • setPosition

      public void setPosition(Plot plot, String position)
      Description copied from interface: AbstractDB
      Sets the plot home position.
      Specified by:
      setPosition in interface AbstractDB
      Parameters:
      plot - the plot
      position - the position of plot home
    • removeComment

      public void removeComment(Plot plot, PlotComment comment)
      Description copied from interface: AbstractDB
      Removes the specified comment from the given plot.
      Specified by:
      removeComment in interface AbstractDB
      Parameters:
      plot - the plot
      comment - the comment to remove
    • clearInbox

      public void clearInbox(Plot plot, String inbox)
      Description copied from interface: AbstractDB
      Clears the specified inbox on the given plot.
      Specified by:
      clearInbox in interface AbstractDB
      Parameters:
      plot - the plot
      inbox - the inbox to clear
    • getComments

      public void getComments(@NonNull Plot plot, String inbox, RunnableVal<List<PlotComment>> whenDone)
      Description copied from interface: AbstractDB
      Gets Plot comments.
      Specified by:
      getComments in interface AbstractDB
      Parameters:
      plot - The Plot to get comments from
    • setComment

      public void setComment(Plot plot, PlotComment comment)
      Description copied from interface: AbstractDB
      Adds the specified comment to the given plot.
      Specified by:
      setComment in interface AbstractDB
      Parameters:
      plot - the plot
      comment - the comment to add
    • removeTrusted

      public void removeTrusted(Plot plot, UUID uuid)
      Description copied from interface: AbstractDB
      Remove the specified player from the trust list of the specified plot.
      Specified by:
      removeTrusted in interface AbstractDB
      Parameters:
      plot - the plot
      uuid - the uuid of the player to remove
    • removeMember

      public void removeMember(Plot plot, UUID uuid)
      Specified by:
      removeMember in interface AbstractDB
      Parameters:
      plot - the plot
      uuid - Player that should be removed
    • setTrusted

      public void setTrusted(Plot plot, UUID uuid)
      Specified by:
      setTrusted in interface AbstractDB
      Parameters:
      plot - Plot Object
      uuid - Player that should be removed
    • setMember

      public void setMember(Plot plot, UUID uuid)
      Specified by:
      setMember in interface AbstractDB
      Parameters:
      plot - Plot Object
      uuid - Player that should be added
    • removeDenied

      public void removeDenied(Plot plot, UUID uuid)
      Description copied from interface: AbstractDB
      Removes the specified player from the denied list of the specified plot.
      Specified by:
      removeDenied in interface AbstractDB
      Parameters:
      plot - the plot
      uuid - the uuid of the player to remove
    • setDenied

      public void setDenied(Plot plot, UUID uuid)
      Description copied from interface: AbstractDB
      Denies the specified player from the given plot.
      Specified by:
      setDenied in interface AbstractDB
      Parameters:
      plot - the plot
      uuid - the uuid of the player to deny
    • getRatings

      public HashMap<UUID,​Integer> getRatings(Plot plot)
      Description copied from interface: AbstractDB
      Gets the ratings from the specified plot.
      Specified by:
      getRatings in interface AbstractDB
      Parameters:
      plot - the plot
      Returns:
      the plot ratings (pre-calculated)
    • setRating

      public void setRating(Plot plot, UUID rater, int value)
      Description copied from interface: AbstractDB
      Sets a rating for a plot.
      Specified by:
      setRating in interface AbstractDB
    • delete

      public void delete(PlotCluster cluster)
      Specified by:
      delete in interface AbstractDB
    • addPersistentMeta

      public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean replace)
      Specified by:
      addPersistentMeta in interface AbstractDB
    • removePersistentMeta

      public void removePersistentMeta(UUID uuid, String key)
      Specified by:
      removePersistentMeta in interface AbstractDB
    • getPersistentMeta

      public void getPersistentMeta(UUID uuid, RunnableVal<Map<String,​byte[]>> result)
      Specified by:
      getPersistentMeta in interface AbstractDB
    • getClusters

      public HashMap<String,​Set<PlotCluster>> getClusters()
      Specified by:
      getClusters in interface AbstractDB
      Returns:
      A HashMap containing all plot clusters
    • setClusterName

      public void setClusterName(PlotCluster cluster, String name)
      Description copied from interface: AbstractDB
      Renames a cluster to the given name.
      Specified by:
      setClusterName in interface AbstractDB
      Parameters:
      cluster - the cluster to rename
      name - the new cluster name
    • removeHelper

      public void removeHelper(PlotCluster cluster, UUID uuid)
      Specified by:
      removeHelper in interface AbstractDB
      Parameters:
      cluster - PlotCluster Object
      uuid - Player that should be removed
    • setHelper

      public void setHelper(PlotCluster cluster, UUID uuid)
      Specified by:
      setHelper in interface AbstractDB
      Parameters:
      cluster - PlotCluster Object
      uuid - Player that should be removed
    • createCluster

      public void createCluster(PlotCluster cluster)
      Specified by:
      createCluster in interface AbstractDB
    • resizeCluster

      public void resizeCluster(PlotCluster current, PlotId min, PlotId max)
      Specified by:
      resizeCluster in interface AbstractDB
    • setPosition

      public void setPosition(PlotCluster cluster, String position)
      Specified by:
      setPosition in interface AbstractDB
    • removeInvited

      public void removeInvited(PlotCluster cluster, UUID uuid)
      Specified by:
      removeInvited in interface AbstractDB
    • setInvited

      public void setInvited(PlotCluster cluster, UUID uuid)
      Specified by:
      setInvited in interface AbstractDB
    • deleteTables

      public boolean deleteTables()
      Description copied from interface: AbstractDB
      Don't use this method unless you want to ruin someone's server.
      Specified by:
      deleteTables in interface AbstractDB
      Returns:
      true if the tables were deleted, false when an error is encountered
    • validateAllPlots

      public void validateAllPlots(Set<Plot> toValidate)
      Specified by:
      validateAllPlots in interface AbstractDB
    • replaceWorld

      public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max)
      Specified by:
      replaceWorld in interface AbstractDB
    • replaceUUID

      public void replaceUUID(UUID old, UUID now)
      Description copied from interface: AbstractDB
      Replaces a old uuid with a new one in the database.
      • Useful for replacing a few uuids (not the entire database).
      • or entire conversion, the uuidconvert command scales better.
      Specified by:
      replaceUUID in interface AbstractDB
    • close

      public void close()
      Description copied from interface: AbstractDB
      Closes the database. Generally not recommended to be used by add-ons.
      Specified by:
      close in interface AbstractDB