001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.database; 020 021import com.plotsquared.core.plot.Plot; 022import com.plotsquared.core.plot.PlotArea; 023import com.plotsquared.core.plot.PlotCluster; 024import com.plotsquared.core.plot.PlotId; 025import com.plotsquared.core.plot.comment.PlotComment; 026import com.plotsquared.core.plot.flag.PlotFlag; 027import com.plotsquared.core.util.task.RunnableVal; 028import org.checkerframework.checker.nullness.qual.NonNull; 029 030import java.util.HashMap; 031import java.util.List; 032import java.util.Map; 033import java.util.Set; 034import java.util.UUID; 035import java.util.concurrent.CompletableFuture; 036 037public interface AbstractDB { 038 039 /** 040 * The UUID that will count as EVERYONE. 041 */ 042 UUID everyone = UUID.fromString("1-1-3-3-7"); 043 044 /** 045 * Sets Plot owner. 046 * 047 * @param plot the plot 048 * @param uuid the uuid of the new owner 049 */ 050 void setOwner(Plot plot, UUID uuid); 051 052 /** 053 * Creates all settings, and create default helpers, trusted + denied lists. 054 * 055 * @param plots Plots for which the default table entries should be created 056 * @param whenDone the task to run when the method is finished executing 057 */ 058 void createPlotsAndData(List<Plot> plots, Runnable whenDone); 059 060 /** 061 * Creates a plot. 062 * 063 * @param plot the plot to create 064 */ 065 void createPlotSafe(final Plot plot, final Runnable success, final Runnable failure); 066 067 /** 068 * Create tables. 069 * 070 * @throws Exception If the database manager is unable to create the tables 071 */ 072 void createTables() throws Exception; 073 074 /** 075 * Deletes a plot. 076 * 077 * @param plot the plot to delete 078 */ 079 void delete(Plot plot); 080 081 void deleteSettings(Plot plot); 082 083 void deleteHelpers(Plot plot); 084 085 void deleteTrusted(Plot plot); 086 087 /** 088 * Removes all denied players from the plot. 089 * 090 * @param plot the plot 091 */ 092 void deleteDenied(Plot plot); 093 094 /** 095 * Deletes all comments from the plot. 096 * 097 * @param plot the plot 098 */ 099 void deleteComments(Plot plot); 100 101 void deleteRatings(Plot plot); 102 103 void delete(PlotCluster cluster); 104 105 void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete); 106 107 void removePersistentMeta(UUID uuid, String key); 108 109 void getPersistentMeta(UUID uuid, RunnableVal<Map<String, byte[]>> result); 110 111 /** 112 * Creates the plot settings. 113 * 114 * @param id the plot entry id 115 * @param plot the plot 116 */ 117 void createPlotSettings(int id, Plot plot); 118 119 /** 120 * Gets the table entry ID. 121 * 122 * @param plot the plot 123 * @return {@link Integer} = Plot Entry Id 124 */ 125 int getId(Plot plot); 126 127 /** 128 * Gets the id of a given plot cluster. 129 * 130 * @param cluster PlotCluster Object 131 * @return Integer = Cluster Entry Id 132 */ 133 int getClusterId(PlotCluster cluster); 134 135 boolean convertFlags(); 136 137 /** 138 * @return A linked HashMap containing all plots 139 */ 140 HashMap<String, HashMap<PlotId, Plot>> getPlots(); 141 142 /** 143 * @param toValidate 144 */ 145 void validateAllPlots(Set<Plot> toValidate); 146 147 /** 148 * @return A HashMap containing all plot clusters 149 */ 150 HashMap<String, Set<PlotCluster>> getClusters(); 151 152 /** 153 * Sets the merged status for a plot. 154 * 155 * @param plot The plot to set the merged status of 156 * @param merged boolean[] 157 */ 158 void setMerged(Plot plot, boolean[] merged); 159 160 /** 161 * Swaps the settings, helpers etc. of two plots. 162 * 163 * @param plot1 Plot1 164 * @param plot2 Plot2 165 */ 166 CompletableFuture<Boolean> swapPlots(Plot plot1, Plot plot2); 167 168 /** 169 * Sets plot flag. 170 * 171 * @param plot Plot Object 172 * @param flag Flag to set 173 */ 174 void setFlag(Plot plot, PlotFlag<?, ?> flag); 175 176 /** 177 * Remove a plot flag. 178 * 179 * @param plot Plot Object 180 * @param flag Flag to remove 181 */ 182 void removeFlag(Plot plot, PlotFlag<?, ?> flag); 183 184 /** 185 * Renames a cluster to the given name. 186 * 187 * @param cluster the cluster to rename 188 * @param name the new cluster name 189 */ 190 void setClusterName(PlotCluster cluster, String name); 191 192 /** 193 * Sets the plot alias. 194 * 195 * @param plot Plot for which the alias should be set 196 * @param alias Plot Alias 197 */ 198 void setAlias(Plot plot, String alias); 199 200 /** 201 * Purges a plot. 202 * 203 * @param uniqueIds list of plot id (db) to be purged 204 */ 205 void purgeIds(Set<Integer> uniqueIds); 206 207 /** 208 * Purges a whole world. 209 * 210 * @param area World in which the plots should be purged 211 * @param plotIds the {@link PlotId}s of {@link Plot}s to purge 212 */ 213 void purge(PlotArea area, Set<PlotId> plotIds); 214 215 /** 216 * Sets the plot home position. 217 * 218 * @param plot the plot 219 * @param position the position of plot home 220 */ 221 void setPosition(Plot plot, String position); 222 223 /** 224 * @param cluster 225 * @param position 226 */ 227 void setPosition(PlotCluster cluster, String position); 228 229 /** 230 * Remove the specified player from the trust list of the specified plot. 231 * 232 * @param plot the plot 233 * @param uuid the uuid of the player to remove 234 */ 235 void removeTrusted(Plot plot, UUID uuid); 236 237 /** 238 * @param cluster PlotCluster Object 239 * @param uuid Player that should be removed 240 */ 241 void removeHelper(PlotCluster cluster, UUID uuid); 242 243 /** 244 * @param plot the plot 245 * @param uuid Player that should be removed 246 */ 247 void removeMember(Plot plot, UUID uuid); 248 249 /** 250 * @param cluster 251 * @param uuid 252 */ 253 void removeInvited(PlotCluster cluster, UUID uuid); 254 255 /** 256 * @param plot Plot Object 257 * @param uuid Player that should be removed 258 */ 259 void setTrusted(Plot plot, UUID uuid); 260 261 /** 262 * @param cluster PlotCluster Object 263 * @param uuid Player that should be removed 264 */ 265 void setHelper(PlotCluster cluster, UUID uuid); 266 267 /** 268 * @param plot Plot Object 269 * @param uuid Player that should be added 270 */ 271 void setMember(Plot plot, UUID uuid); 272 273 /** 274 * @param cluster 275 * @param uuid 276 */ 277 void setInvited(PlotCluster cluster, UUID uuid); 278 279 /** 280 * Removes the specified player from the denied list of the specified plot. 281 * 282 * @param plot the plot 283 * @param uuid the uuid of the player to remove 284 */ 285 void removeDenied(Plot plot, UUID uuid); 286 287 /** 288 * Denies the specified player from the given plot. 289 * 290 * @param plot the plot 291 * @param uuid the uuid of the player to deny 292 */ 293 void setDenied(Plot plot, UUID uuid); 294 295 /** 296 * Gets the ratings from the specified plot. 297 * 298 * @param plot the plot 299 * @return the plot ratings (pre-calculated) 300 */ 301 HashMap<UUID, Integer> getRatings(Plot plot); 302 303 /** 304 * Sets a rating for a plot. 305 * 306 * @param plot 307 * @param rater 308 * @param value 309 */ 310 void setRating(Plot plot, UUID rater, int value); 311 312 /** 313 * Removes the specified comment from the given plot. 314 * 315 * @param plot the plot 316 * @param comment the comment to remove 317 */ 318 void removeComment(Plot plot, PlotComment comment); 319 320 /** 321 * Clears the specified inbox on the given plot. 322 * 323 * @param plot the plot 324 * @param inbox the inbox to clear 325 */ 326 void clearInbox(Plot plot, String inbox); 327 328 /** 329 * Adds the specified comment to the given plot. 330 * 331 * @param plot the plot 332 * @param comment the comment to add 333 */ 334 void setComment(Plot plot, PlotComment comment); 335 336 /** 337 * Gets Plot comments. 338 * 339 * @param plot The Plot to get comments from 340 */ 341 void getComments(@NonNull Plot plot, String inbox, RunnableVal<List<PlotComment>> whenDone); 342 343 void createPlotAndSettings(Plot plot, Runnable whenDone); 344 345 void createCluster(PlotCluster cluster); 346 347 void resizeCluster(PlotCluster current, PlotId min, PlotId max); 348 349 void movePlot(Plot originalPlot, Plot newPlot); 350 351 /** 352 * Replaces a old uuid with a new one in the database. 353 * 354 * <ul> 355 * <li> Useful for replacing a few uuids (not the entire database).</li> 356 * <li>or entire conversion, the uuidconvert command scales better.</li> 357 * </ul> 358 * 359 * @param old 360 * @param now 361 */ 362 void replaceUUID(UUID old, UUID now); 363 364 /** 365 * Don't use this method unless you want to ruin someone's server. 366 * 367 * @return {@code true} if the tables were deleted, {@code false} when an error is encountered 368 */ 369 boolean deleteTables(); 370 371 /** 372 * Closes the database. Generally not recommended to be used by add-ons. 373 */ 374 void close(); 375 376 void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max); 377 378 void updateTables(int[] oldVersion); 379 380}