mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-22 07:55:06 +00:00
Merge https://github.com/AtlasMediaGroup/TF-PlotSquared into 1.16
This commit is contained in:
commit
72ca00e862
14 changed files with 168 additions and 274 deletions
46
.github/workflows/codacy-analysis.yml
vendored
Normal file
46
.github/workflows/codacy-analysis.yml
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
# This workflow checks out code, performs a Codacy security scan
|
||||
# and integrates the results with the
|
||||
# GitHub Advanced Security code scanning feature. For more information on
|
||||
# the Codacy security scan action usage and parameters, see
|
||||
# https://github.com/codacy/codacy-analysis-cli-action.
|
||||
# For more information on Codacy Analysis CLI in general, see
|
||||
# https://github.com/codacy/codacy-analysis-cli.
|
||||
|
||||
name: Codacy Security Scan
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ 1.16 ]
|
||||
pull_request:
|
||||
branches: [ 1.16 ]
|
||||
|
||||
jobs:
|
||||
codacy-security-scan:
|
||||
name: Codacy Security Scan
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Checkout the repository to the GitHub Actions runner
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@1.1.0
|
||||
with:
|
||||
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
|
||||
# You can also omit the token and run the tools that support default configurations
|
||||
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
||||
verbose: true
|
||||
output: results.sarif
|
||||
format: sarif
|
||||
# Adjust severity of non-security issues
|
||||
gh-code-scanning-compat: true
|
||||
# Force 0 exit code to allow SARIF file generation
|
||||
# This will handover control about PR rejection to the GitHub side
|
||||
max-allowed-issues: 2147483647
|
||||
|
||||
# Upload the SARIF file generated in the previous step
|
||||
- name: Upload SARIF results file
|
||||
uses: github/codeql-action/upload-sarif@v1
|
||||
with:
|
||||
sarif_file: results.sarif
|
67
.github/workflows/codeql-analysis.yml
vendored
Normal file
67
.github/workflows/codeql-analysis.yml
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ 1.16 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ 1.16 ]
|
||||
schedule:
|
||||
- cron: '33 5 * * 4'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'java' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
|
@ -15,7 +15,6 @@ repositories {
|
|||
maven { url = "https://mvn.intellectualsites.com/content/repositories/releases" }
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
maven { url = "http://repo.mvdw-software.be/content/groups/public/" }
|
||||
maven { url = "https://telesphoreo.me/repo/maven" }
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,7 @@ dependencies {
|
|||
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
|
||||
compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
|
||||
compile('be.maximvdw:MVdWPlaceholderAPI:3.1.1'){ transitive = false }
|
||||
implementation('me.totalfreedom:TotalFreedomMod:2020.11'){ transitive = false }
|
||||
implementation('com.github.AtlasMediaGroup:TotalFreedomMod:0be2aa7'){ transitive = false }
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -101,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"
|
||||
}
|
||||
|
@ -118,4 +119,4 @@ shadowJar.doLast {
|
|||
|
||||
build.dependsOn(shadowJar)
|
||||
build.finalizedBy(copyFiles)
|
||||
copyFiles.dependsOn(createPom)
|
||||
copyFiles.dependsOn(createPom)
|
|
@ -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>
|
||||
|
@ -147,9 +147,9 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<groupId>com.github.AtlasMediaGroup</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2020.11</version>
|
||||
<version>0be2aa7</version>
|
||||
<scope>runtime</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" :
|
||||
|
|
|
@ -2,9 +2,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/" }
|
||||
maven { url = "https://telesphoreo.me/repo/maven" }
|
||||
}
|
||||
def textVersion = "3.0.2"
|
||||
|
||||
|
@ -23,7 +20,8 @@ dependencies {
|
|||
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("me.totalfreedom:TotalFreedomMod:2020.11")
|
||||
implementation("com.github.AtlasMediaGroup:TotalFreedomMod:0be2aa7")
|
||||
implementation("com.intellectualsites.paster:Paster:1.0.1-SNAPSHOT"){ transitive = false }
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -82,11 +80,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 {
|
||||
|
|
16
Core/pom.xml
16
Core/pom.xml
|
@ -81,9 +81,9 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<groupId>com.github.AtlasMediaGroup</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2020.11</version>
|
||||
<version>0be2aa7</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -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>
|
||||
|
|
|
@ -161,7 +161,7 @@ public abstract class Command {
|
|||
|
||||
public boolean hasConfirmation(CommandCaller player) {
|
||||
// Confirmation message bypass
|
||||
return this.confirmation && !plotSquaredHandler.isStaff(player);
|
||||
return this.confirmation && !plotSquaredHandler.isAdmin(player);
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,21 +17,21 @@ public class PlotSquaredHandler
|
|||
public static final Logger LOGGER = Bukkit.getPluginManager().getPlugin("PlotSquared").getLogger();
|
||||
private static Function<Player, Boolean> adminProvider;
|
||||
|
||||
public boolean isStaff(CommandCaller commandCaller)
|
||||
public boolean isAdmin(CommandCaller commandCaller)
|
||||
{
|
||||
final Player player = getPlayer(commandCaller.toString());
|
||||
if (player == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return isStaff(player);
|
||||
return isAdmin(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isStaff(Player player)
|
||||
public boolean isAdmin(Player player)
|
||||
{
|
||||
TotalFreedomMod tfm = getTFM();
|
||||
return tfm.sl.isStaff(player);
|
||||
return tfm.al.isAdmin(player);
|
||||
}
|
||||
|
||||
public static Player getPlayer(CommandCaller commandCaller)
|
||||
|
@ -59,7 +59,7 @@ public class PlotSquaredHandler
|
|||
"plots.worldedit.bypass", "plots.area", "plots.grant.add", "plots.debugallowunsafe", "plots.debugroadgen", "plots.debugpaste",
|
||||
"plots.createroadschematic", "plots.merge", "plots.unlink", "plots.area", "plots.setup", "plots.set.flag.other", "plots.reload",
|
||||
"plots.backup", "plots.debug");
|
||||
if (!isStaff(player))
|
||||
if (!isAdmin(player))
|
||||
{
|
||||
return !permission.startsWith("plots.admin") && !adminOnlyPermissions.contains(permission);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ buildscript {
|
|||
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/" }
|
||||
maven { url = "https://telesphoreo.me/repo/maven" }
|
||||
maven { url = "https://jitpack.io" }
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.github.jengelman.gradle.plugins:shadow:5.0.0")
|
||||
|
@ -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")) {
|
||||
|
@ -91,7 +91,7 @@ subprojects {
|
|||
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
|
||||
testImplementation("junit:junit:4.13")
|
||||
implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT")
|
||||
implementation("me.totalfreedom:TotalFreedomMod:2020.11")
|
||||
implementation("com.github.AtlasMediaGroup:TotalFreedomMod:0be2aa7")
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
|
@ -143,4 +143,4 @@ task aggregatedJavadocs(type: Javadoc, description: "Generate javadocs from all
|
|||
includes += javadocTask.includes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue