mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-22 16:05:02 +00:00
Merge branch 'pr/4' into 1.16
This commit is contained in:
commit
800a3373d8
14 changed files with 68 additions and 295 deletions
|
@ -100,12 +100,14 @@ shadowJar {
|
|||
include(dependency("org.bstats:bstats-bukkit:1.7"))
|
||||
include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
|
||||
include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT"))
|
||||
include(dependency("com.intellectualsites.paster:Paster:1.0.1-SNAPSHOT"))
|
||||
}
|
||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||
relocate("io.papermc.paperlib", "com.plotsquared.bukkit.paperlib")
|
||||
relocate("org.bstats", "com.plotsquared.metrics")
|
||||
relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid')
|
||||
relocate('org.khelekore.prtree', 'com.plotsquared.prtree')
|
||||
relocate('com.intellectualsites.paster', 'com.plotsquared.core.paster')
|
||||
archiveFileName = "${project.name}-${parent.version}.jar"
|
||||
destinationDirectory = file "../target"
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<dependency>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-Core</artifactId>
|
||||
<version>5.13.9</version>
|
||||
<version>5.13.10</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -74,6 +74,7 @@ import com.plotsquared.core.configuration.ChatFormatter;
|
|||
import com.plotsquared.core.configuration.ConfigurationNode;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.Storage;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.generator.HybridGen;
|
||||
|
@ -1018,6 +1019,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
|||
}));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("premium",
|
||||
() -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("worlds", () -> Settings.Enabled_Components.WORLDS ? "true" : "false"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("economy", () -> Settings.Enabled_Components.ECONOMY ? "true" : "false"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("plot_expiry", () -> Settings.Enabled_Components.PLOT_EXPIRY ? "true" : "false"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("database_type", () -> Storage.MySQL.USE ? "MySQL" : "SQLite"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("worldedit_implementation",
|
||||
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ?
|
||||
"FastAsyncWorldEdit" :
|
||||
|
|
|
@ -187,17 +187,24 @@ public class BlockEventListener implements Listener {
|
|||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPhysicsEvent(BlockPhysicsEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (event.getChangedType().hasGravity() && plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
sendBlockChange(event.getBlock().getLocation(), event.getBlock().getBlockData());
|
||||
plot.debug("Prevented block physics and resent block change because disable-physics = true");
|
||||
return;
|
||||
}
|
||||
switch (event.getChangedType()) {
|
||||
case COMPARATOR: {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
if (location.isPlotArea()) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlotAbs();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (!plot.getFlag(RedstoneFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Prevented comparator update because redstone = false");
|
||||
|
@ -211,16 +218,6 @@ public class BlockEventListener implements Listener {
|
|||
case TURTLE_EGG:
|
||||
case TURTLE_HELMET:
|
||||
case TURTLE_SPAWN_EGG: {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Prevented block physics because disable-physics = true");
|
||||
|
@ -229,21 +226,11 @@ public class BlockEventListener implements Listener {
|
|||
}
|
||||
default:
|
||||
if (Settings.Redstone.DETECT_INVALID_EDGE_PISTONS) {
|
||||
Block block = event.getBlock();
|
||||
switch (block.getType()) {
|
||||
case PISTON:
|
||||
case STICKY_PISTON:
|
||||
org.bukkit.block.data.Directional piston =
|
||||
(org.bukkit.block.data.Directional) block.getBlockData();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
switch (piston.getFacing()) {
|
||||
case EAST:
|
||||
location.setX(location.getX() + 1);
|
||||
|
@ -261,8 +248,7 @@ public class BlockEventListener implements Listener {
|
|||
Plot newPlot = area.getOwnedPlotAbs(location);
|
||||
if (!plot.equals(newPlot)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug(
|
||||
"Prevented piston update because of invalid edge piston detection");
|
||||
plot.debug("Prevented piston update because of invalid edge piston detection");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,6 +201,9 @@ public class EntityEventListener implements Listener {
|
|||
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
if (plot != null) {
|
||||
if (block.getType().hasGravity()) {
|
||||
BlockEventListener.sendBlockChange(block.getLocation(), block.getBlockData());
|
||||
}
|
||||
plot.debug("Falling block event was cancelled because disable-physics = true");
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
repositories {
|
||||
maven { url = "https://jitpack.io" }
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
maven { url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||
maven { url = "https://rayzr.dev/repo/" }
|
||||
maven { url = "https://repo.dmulloy2.net/nexus/repository/public/" }
|
||||
}
|
||||
def textVersion = "3.0.2"
|
||||
|
||||
|
@ -21,8 +18,7 @@ dependencies {
|
|||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.4.0")
|
||||
implementation("org.jetbrains:annotations:20.1.0")
|
||||
implementation("org.khelekore:prtree:1.7.0-SNAPSHOT")
|
||||
implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT")
|
||||
implementation("com.github.AtlasMediaGroup:TotalFreedomMod:0be2aa7")
|
||||
implementation("com.intellectualsites.paster:Paster:1.0.1-SNAPSHOT"){ transitive = false }
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -81,11 +77,13 @@ shadowJar {
|
|||
include(dependency("net.kyori:text-serializer-legacy:3.0.2"))
|
||||
include(dependency("net.kyori:text-serializer-plain:3.0.2"))
|
||||
include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
|
||||
include(dependency("com.intellectualsites.paster:Paster:1.0.1-SNAPSHOT"))
|
||||
}
|
||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||
relocate("org.json", "com.plotsquared.json") {
|
||||
exclude "org/json/simple/**"
|
||||
}
|
||||
relocate('com.intellectualsites.paster', 'com.plotsquared.core.paster')
|
||||
}
|
||||
|
||||
shadowJar.doLast {
|
||||
|
@ -96,4 +94,4 @@ shadowJar.doLast {
|
|||
build.dependsOn(shadowJar)
|
||||
|
||||
build.finalizedBy(copyFiles)
|
||||
copyFiles.dependsOn(createPom)
|
||||
copyFiles.dependsOn(createPom)
|
||||
|
|
12
Core/pom.xml
12
Core/pom.xml
|
@ -110,6 +110,18 @@
|
|||
<version>1.7.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intellectualsites.paster</groupId>
|
||||
<artifactId>Paster</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>*</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -27,13 +27,13 @@ package com.plotsquared.core.command;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.intellectualsites.paster.IncendoPaster;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
import com.plotsquared.core.util.net.IncendoPaster;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import lombok.NonNull;
|
||||
|
||||
|
@ -59,22 +59,9 @@ import java.util.stream.Collectors;
|
|||
requiredType = RequiredType.NONE)
|
||||
public class DebugPaste extends SubCommand {
|
||||
|
||||
private static String readFile(@NonNull final File file) throws IOException {
|
||||
final List<String> lines;
|
||||
try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
lines = reader.lines().collect(Collectors.toList());
|
||||
}
|
||||
final StringBuilder content = new StringBuilder();
|
||||
for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) {
|
||||
content.append(lines.get(i)).append("\n");
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(
|
||||
"# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your "
|
||||
|
@ -128,28 +115,24 @@ public class DebugPaste extends SubCommand {
|
|||
if (Files.size(logFile.toPath()) > 14_000_000) {
|
||||
throw new IOException("Too big...");
|
||||
}
|
||||
incendoPaster
|
||||
.addFile(new IncendoPaster.PasteFile("latest.log", readFile(logFile)));
|
||||
incendoPaster.addFile(logFile);
|
||||
} catch (IOException ignored) {
|
||||
MainUtil
|
||||
.sendMessage(player, "&clatest.log is too big to be pasted, will ignore");
|
||||
}
|
||||
|
||||
try {
|
||||
incendoPaster.addFile(new IncendoPaster.PasteFile("settings.yml",
|
||||
readFile(PlotSquared.get().configFile)));
|
||||
incendoPaster.addFile(PlotSquared.get().configFile);
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
MainUtil.sendMessage(player, "&cSkipping settings.yml because it's empty");
|
||||
}
|
||||
try {
|
||||
incendoPaster.addFile(new IncendoPaster.PasteFile("worlds.yml",
|
||||
readFile(PlotSquared.get().worldsFile)));
|
||||
incendoPaster.addFile(PlotSquared.get().worldsFile);
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
MainUtil.sendMessage(player, "&cSkipping worlds.yml because it's empty");
|
||||
}
|
||||
try {
|
||||
incendoPaster.addFile(new IncendoPaster.PasteFile("PlotSquared.use_THIS.yml",
|
||||
readFile(PlotSquared.get().translationFile)));
|
||||
incendoPaster.addFile(PlotSquared.get().translationFile);
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
"&cSkipping PlotSquared.use_THIS.yml because it's empty");
|
||||
|
@ -158,8 +141,7 @@ public class DebugPaste extends SubCommand {
|
|||
try {
|
||||
final File MultiverseWorlds = new File(PlotSquared.get().IMP.getDirectory(),
|
||||
"../Multiverse-Core/worlds.yml");
|
||||
incendoPaster.addFile(new IncendoPaster.PasteFile("MultiverseCore/worlds.yml",
|
||||
readFile(MultiverseWorlds)));
|
||||
incendoPaster.addFile(MultiverseWorlds);
|
||||
} catch (final IOException ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
"&cSkipping Multiverse worlds.yml because the plugin is not in use");
|
||||
|
|
|
@ -95,7 +95,7 @@ public class Deny extends SubCommand {
|
|||
}
|
||||
plot.addDenied(uuidMapping.getUuid());
|
||||
PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuidMapping.getUuid(), true);
|
||||
if (!uuidMapping.equals(DBFunc.EVERYONE)) {
|
||||
if (!uuidMapping.getUuid().equals(DBFunc.EVERYONE)) {
|
||||
handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()), plot);
|
||||
} else {
|
||||
for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.plotsquared.core.plot.PlotArea;
|
|||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -95,19 +96,21 @@ public class Purge extends SubCommand {
|
|||
break;
|
||||
case "owner":
|
||||
case "o":
|
||||
owner = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(split[1], Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (owner == null) {
|
||||
UUIDMapping ownerMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
|
||||
if (ownerMapping == null) {
|
||||
Captions.INVALID_PLAYER.send(player, split[1]);
|
||||
return false;
|
||||
}
|
||||
owner = ownerMapping.getUuid();
|
||||
break;
|
||||
case "shared":
|
||||
case "s":
|
||||
added = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(split[1], Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (added == null) {
|
||||
UUIDMapping addedMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(split[1]);
|
||||
if (addedMapping == null) {
|
||||
Captions.INVALID_PLAYER.send(player, split[1]);
|
||||
return false;
|
||||
}
|
||||
added = addedMapping.getUuid();
|
||||
break;
|
||||
case "clear":
|
||||
case "c":
|
||||
|
|
|
@ -275,8 +275,8 @@ public abstract class SchematicHandler {
|
|||
}
|
||||
for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) {
|
||||
for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) {
|
||||
int xx = p1x + xOffset + rx;
|
||||
int zz = p1z + zOffset + rz;
|
||||
int xx = p1x + rx;
|
||||
int zz = p1z + rz;
|
||||
BaseBlock id = blockArrayClipboard
|
||||
.getFullBlock(BlockVector3.at(rx, ry, rz));
|
||||
queue.setBlock(xx, yy, zz, id);
|
||||
|
@ -537,7 +537,7 @@ public abstract class SchematicHandler {
|
|||
schematic.put("Palette", new CompoundTag(paletteTag));
|
||||
schematic.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
|
||||
schematic
|
||||
.put("TileEntities", new ListTag(CompoundTag.class, tileEntities));
|
||||
.put("BlockEntities", new ListTag(CompoundTag.class, tileEntities));
|
||||
|
||||
schematic.put("BiomePaletteMax", new IntTag(biomePalette.size()));
|
||||
|
||||
|
@ -602,8 +602,6 @@ public abstract class SchematicHandler {
|
|||
values.put(entry.getKey(),
|
||||
entry.getValue());
|
||||
}
|
||||
// Remove 'id' if it exists. We want 'Id'
|
||||
values.remove("id");
|
||||
|
||||
// Positions are kept in NBT, we don't want that.
|
||||
values.remove("x");
|
||||
|
@ -612,6 +610,11 @@ public abstract class SchematicHandler {
|
|||
|
||||
values.put("Id",
|
||||
new StringTag(block.getNbtId()));
|
||||
|
||||
// Remove 'id' if it exists. We want 'Id'.
|
||||
// Do this after we get "getNbtId" cos otherwise "getNbtId" doesn't work.
|
||||
// Dum.
|
||||
values.remove("id");
|
||||
values.put("Pos", new IntArrayTag(
|
||||
new int[] {rx, ry, rz}));
|
||||
|
||||
|
|
|
@ -1,222 +0,0 @@
|
|||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util.net;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Single class paster for the Incendo paste service
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public final class IncendoPaster {
|
||||
|
||||
/**
|
||||
* Upload service URL
|
||||
*/
|
||||
public static final String UPLOAD_PATH = "https://athion.net/ISPaster/paste/upload";
|
||||
/**
|
||||
* Valid paste applications
|
||||
*/
|
||||
public static final Collection<String> VALID_APPLICATIONS =
|
||||
Arrays.asList("plotsquared", "fastasyncworldedit", "incendopermissions", "kvantum");
|
||||
|
||||
private final Collection<PasteFile> files = new ArrayList<>();
|
||||
private final String pasteApplication;
|
||||
|
||||
/**
|
||||
* Construct a new paster
|
||||
*
|
||||
* @param pasteApplication The application that is sending the paste
|
||||
*/
|
||||
public IncendoPaster(final String pasteApplication) {
|
||||
if (pasteApplication == null || pasteApplication.isEmpty()) {
|
||||
throw new IllegalArgumentException("paste application cannot be null, nor empty");
|
||||
}
|
||||
if (!VALID_APPLICATIONS.contains(pasteApplication.toLowerCase(Locale.ENGLISH))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown application name: %s", pasteApplication));
|
||||
}
|
||||
this.pasteApplication = pasteApplication;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an immutable collection containing all the files that have been added to this paster
|
||||
*
|
||||
* @return Unmodifiable collection
|
||||
*/
|
||||
public final Collection<PasteFile> getFiles() {
|
||||
return Collections.unmodifiableCollection(this.files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file to the paster
|
||||
*
|
||||
* @param file File to paste
|
||||
*/
|
||||
public void addFile(final PasteFile file) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
// Check to see that no duplicate files are submitted
|
||||
for (final PasteFile pasteFile : this.files) {
|
||||
if (pasteFile.fileName.equalsIgnoreCase(file.getFileName())) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Found duplicate file with name %s", file.getFileName()));
|
||||
}
|
||||
}
|
||||
this.files.add(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a JSON string from the submitted information
|
||||
*
|
||||
* @return compiled JSON string
|
||||
*/
|
||||
private String toJsonString() {
|
||||
final StringBuilder builder = new StringBuilder("{\n");
|
||||
builder.append("\"paste_application\": \"").append(this.pasteApplication)
|
||||
.append("\",\n\"files\": \"");
|
||||
Iterator<PasteFile> fileIterator = this.files.iterator();
|
||||
while (fileIterator.hasNext()) {
|
||||
final PasteFile file = fileIterator.next();
|
||||
builder.append(file.getFileName());
|
||||
if (fileIterator.hasNext()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
builder.append("\",\n");
|
||||
fileIterator = this.files.iterator();
|
||||
while (fileIterator.hasNext()) {
|
||||
final PasteFile file = fileIterator.next();
|
||||
builder.append("\"file-").append(file.getFileName()).append("\": \"")
|
||||
.append(file.getContent().replaceAll("\"", "\\\\\"")).append("\"");
|
||||
if (fileIterator.hasNext()) {
|
||||
builder.append(",\n");
|
||||
}
|
||||
}
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload the paste and return the status message
|
||||
*
|
||||
* @return Status message
|
||||
* @throws Throwable any and all exceptions
|
||||
*/
|
||||
public final String upload() throws Throwable {
|
||||
final URL url = new URL(UPLOAD_PATH);
|
||||
final URLConnection connection = url.openConnection();
|
||||
final HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
httpURLConnection.setDoOutput(true);
|
||||
final byte[] content = toJsonString().getBytes(Charsets.UTF_8);
|
||||
httpURLConnection.setFixedLengthStreamingMode(content.length);
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
httpURLConnection.setRequestProperty("Accept", "*/*");
|
||||
httpURLConnection.connect();
|
||||
try (final OutputStream stream = httpURLConnection.getOutputStream()) {
|
||||
stream.write(content);
|
||||
}
|
||||
if (!httpURLConnection.getResponseMessage().contains("OK")) {
|
||||
if (httpURLConnection.getResponseCode() == 413) {
|
||||
final long size = content.length;
|
||||
PlotSquared.debug(String.format("Paste Too Big > Size: %dMB", size / 1_000_000));
|
||||
}
|
||||
throw new IllegalStateException(String
|
||||
.format("Server returned status: %d %s", httpURLConnection.getResponseCode(),
|
||||
httpURLConnection.getResponseMessage()));
|
||||
}
|
||||
final StringBuilder input = new StringBuilder();
|
||||
try (final BufferedReader inputStream = new BufferedReader(
|
||||
new InputStreamReader(httpURLConnection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = inputStream.readLine()) != null) {
|
||||
input.append(line).append("\n");
|
||||
}
|
||||
}
|
||||
return input.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple class that represents a paste file
|
||||
*/
|
||||
public static class PasteFile {
|
||||
|
||||
private final String fileName;
|
||||
private final String content;
|
||||
|
||||
/**
|
||||
* Construct a new paste file
|
||||
*
|
||||
* @param fileName File name, cannot be empty, nor null
|
||||
* @param content File content, cannot be empty, nor null
|
||||
*/
|
||||
public PasteFile(final String fileName, final String content) {
|
||||
if (fileName == null || fileName.isEmpty()) {
|
||||
throw new IllegalArgumentException("file name cannot be null, nor empty");
|
||||
}
|
||||
if (content == null || content.isEmpty()) {
|
||||
throw new IllegalArgumentException("content cannot be null, nor empty");
|
||||
}
|
||||
this.fileName = fileName;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file name
|
||||
*
|
||||
* @return File name
|
||||
*/
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file content as a single string
|
||||
*
|
||||
* @return File content
|
||||
*/
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@ is to provide a lag-free and smooth experience.
|
|||
* [Discord](https://discord.gg/KxkjDVg)
|
||||
* [Wiki](https://wiki.intellectualsites.com/plotsquared/home)
|
||||
* [Issues](https://issues.intellectualsites.com/projects/ps)
|
||||
* [Translations](https://intellectualsites.crowdin.com/plotsquared/)
|
||||
|
||||
### Developer Resources
|
||||
* [API Documentation](https://wiki.intellectualsites.com/en/plotsquared/developer/development-portal)
|
||||
|
|
|
@ -34,7 +34,7 @@ ext {
|
|||
git = Grgit.open(dir: new File(rootDir.toString() + "/.git"))
|
||||
}
|
||||
|
||||
def ver = "5.13.9"
|
||||
def ver = "5.13.10"
|
||||
def versuffix = ""
|
||||
ext {
|
||||
if (project.hasProperty("versionsuffix")) {
|
||||
|
|
Loading…
Reference in a new issue