Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites
* Copyright (C) IntellectualSites team and contributors
*
* 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, see .
*/
package com.plotsquared.core;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.MemorySection;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.Storage;
import com.plotsquared.core.configuration.caption.CaptionMap;
import com.plotsquared.core.configuration.caption.DummyCaptionMap;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.configuration.caption.load.CaptionLoader;
import com.plotsquared.core.configuration.caption.load.DefaultCaptionProvider;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.configuration.serialization.ConfigurationSerialization;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.database.Database;
import com.plotsquared.core.database.MySQL;
import com.plotsquared.core.database.SQLManager;
import com.plotsquared.core.database.SQLite;
import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.HybridPlotWorld;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotCluster;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.expiration.ExpiryTask;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.FileUtils;
import com.plotsquared.core.util.LegacyConverter;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.ReflectionUtils;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.util.eventbus.EventHandler;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* An implementation of the core, with a static getter for easy access.
*/
@SuppressWarnings({"WeakerAccess"})
public class PlotSquared {
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + PlotSquared.class.getSimpleName());
private static @MonotonicNonNull PlotSquared instance;
// Implementation
private final PlotPlatform> platform;
// Current thread
private final Thread thread;
// UUID pipelines
private final UUIDPipeline impromptuUUIDPipeline =
new UUIDPipeline(Executors.newCachedThreadPool());
private final UUIDPipeline backgroundUUIDPipeline =
new UUIDPipeline(Executors.newSingleThreadExecutor());
// Localization
private final Map captionMaps = new HashMap<>();
public HashMap> plots_tmp;
private CaptionLoader captionLoader;
// WorldEdit instance
private WorldEdit worldedit;
private File configFile;
private File worldsFile;
private YamlConfiguration worldConfiguration;
// Temporary hold the plots/clusters before the worlds load
private HashMap> clustersTmp;
private YamlConfiguration config;
// Platform / Version / Update URL
private PlotVersion version;
// Files and configuration
private File jarFile = null; // This file
private File storageFile;
private EventDispatcher eventDispatcher;
private PlotListener plotListener;
private boolean weInitialised;
/**
* Initialize PlotSquared with the desired Implementation class.
*
* @param iPlotMain Implementation of {@link PlotPlatform} used
* @param platform The platform being used
*/
public PlotSquared(
final @NonNull PlotPlatform> iPlotMain,
final @NonNull String platform
) {
if (instance != null) {
throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton");
}
instance = this;
this.thread = Thread.currentThread();
this.platform = iPlotMain;
Settings.PLATFORM = platform;
// Initialize the class
PlayerMetaDataKeys.load();
//
// Register configuration serializable classes
//
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
// load configs before reading from settings
if (!setupConfigs()) {
return;
}
this.captionLoader = CaptionLoader.of(
Locale.ENGLISH,
CaptionLoader.patternExtractor(Pattern.compile("messages_(.*)\\.json")),
DefaultCaptionProvider.forClassLoaderFormatString(
this.getClass().getClassLoader(),
"lang/messages_%s.json" // the path in our jar file
),
TranslatableCaption.DEFAULT_NAMESPACE
);
// Load caption map
try {
this.loadCaptionMap();
} catch (final Exception e) {
LOGGER.error("Failed to load caption map", e);
LOGGER.error("Shutting down server to prevent further issues");
this.platform.shutdownServer();
throw new RuntimeException("Abort loading PlotSquared");
}
// Setup the global flag container
GlobalFlagContainer.setup();
try {
new ReflectionUtils(this.platform.serverNativePackage());
try {
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
this.jarFile = new File(
URI.create(
logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
.getPath());
} catch (URISyntaxException | SecurityException e) {
e.printStackTrace();
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
if (!this.jarFile.exists()) {
this.jarFile = new File(
this.platform.getDirectory().getParentFile(),
"PlotSquared-" + platform + ".jar"
);
}
}
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WEPlatformReadyListener());
// Create Event utility class
this.eventDispatcher = new EventDispatcher(this.worldedit);
// Create plot listener
this.plotListener = new PlotListener(this.eventDispatcher);
// Copy files
copyFile("town.template", Settings.Paths.TEMPLATES);
copyFile("bridge.template", Settings.Paths.TEMPLATES);
copyFile("skyblock.template", Settings.Paths.TEMPLATES);
showDebug();
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* Gets an instance of PlotSquared.
*
* @return instance of PlotSquared
*/
public static @NonNull PlotSquared get() {
return PlotSquared.instance;
}
/**
* Get the platform specific implementation of PlotSquared
*
* @return Platform implementation
*/
public static @NonNull PlotPlatform> platform() {
if (instance != null && instance.platform != null) {
return instance.platform;
}
throw new IllegalStateException("Plot platform implementation is missing");
}
public void loadCaptionMap() throws Exception {
this.platform.copyCaptionMaps();
// Setup localization
CaptionMap captionMap;
if (Settings.Enabled_Components.PER_USER_LOCALE) {
captionMap = this.captionLoader.loadAll(this.platform.getDirectory().toPath().resolve("lang"));
} else {
String fileName = "messages_" + Settings.Enabled_Components.DEFAULT_LOCALE + ".json";
captionMap = this.captionLoader.loadOrCreateSingle(this.platform
.getDirectory()
.toPath()
.resolve("lang")
.resolve(fileName));
}
this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap);
LOGGER.info(
"Loaded caption map for namespace 'plotsquared': {}",
this.captionMaps.get(TranslatableCaption.DEFAULT_NAMESPACE).getClass().getCanonicalName()
);
}
/**
* Get the platform specific {@link PlotAreaManager} instance
*
* @return Plot area manager
*/
public @NonNull PlotAreaManager getPlotAreaManager() {
return this.platform.plotAreaManager();
}
public void startExpiryTasks() {
if (Settings.Enabled_Components.PLOT_EXPIRY) {
ExpireManager expireManager = PlotSquared.platform().expireManager();
expireManager.runAutomatedTask();
for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) {
ExpiryTask task = new ExpiryTask(settings, this.getPlotAreaManager());
expireManager.addTask(task);
}
}
}
public boolean isMainThread(final @NonNull Thread thread) {
return this.thread == thread;
}
/**
* Check if `version` is >= `version2`.
*
* @param version First version
* @param version2 Second version
* @return {@code true} if `version` is >= `version2`
*/
public boolean checkVersion(
final int[] version,
final int... version2
) {
return version[0] > version2[0] || version[0] == version2[0] && version[1] > version2[1]
|| version[0] == version2[0] && version[1] == version2[1] && version[2] >= version2[2];
}
/**
* Gets the current PlotSquared version.
*
* @return current version in config or null
*/
public @NonNull PlotVersion getVersion() {
return this.version;
}
/**
* Gets the server platform this plugin is running on this is running on.
*
*
This will be either Bukkit or Sponge
*
* @return the server implementation
*/
public @NonNull String getPlatform() {
return Settings.PLATFORM;
}
/**
* Add a global reference to a plot world.
*
* You can remove the reference by calling {@link #removePlotArea(PlotArea)}
*
*
* @param plotArea the {@link PlotArea} to add.
*/
@SuppressWarnings("unchecked")
public void addPlotArea(final @NonNull PlotArea plotArea) {
HashMap plots;
if (plots_tmp == null || (plots = plots_tmp.remove(plotArea.toString())) == null) {
if (plotArea.getType() == PlotAreaType.PARTIAL) {
plots = this.plots_tmp != null ? this.plots_tmp.get(plotArea.getWorldName()) : null;
if (plots != null) {
Iterator> iterator = plots.entrySet().iterator();
while (iterator.hasNext()) {
Entry next = iterator.next();
PlotId id = next.getKey();
if (plotArea.contains(id)) {
next.getValue().setArea(plotArea);
iterator.remove();
}
}
}
}
} else {
for (Plot entry : plots.values()) {
entry.setArea(plotArea);
}
}
Set clusters;
if (clustersTmp == null || (clusters = clustersTmp.remove(plotArea.toString())) == null) {
if (plotArea.getType() == PlotAreaType.PARTIAL) {
clusters = this.clustersTmp != null ?
this.clustersTmp.get(plotArea.getWorldName()) :
null;
if (clusters != null) {
Iterator iterator = clusters.iterator();
while (iterator.hasNext()) {
PlotCluster next = iterator.next();
if (next.intersects(plotArea.getMin(), plotArea.getMax())) {
next.setArea(plotArea);
iterator.remove();
}
}
}
}
} else {
for (PlotCluster cluster : clusters) {
cluster.setArea(plotArea);
}
}
getPlotAreaManager().addPlotArea(plotArea);
plotArea.setupBorder();
if (!Settings.Enabled_Components.PERSISTENT_ROAD_REGEN) {
return;
}
File file = new File(
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
+ "_" + plotArea.getWorldName());
if (!file.exists()) {
return;
}
TaskManager.runTaskAsync(() -> {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
List