mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Merge branch 'v5' into features/v5/road-respect-flags
# Conflicts: # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
This commit is contained in:
commit
82a887fd3b
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
custom: https://www.paypal.me/AlexanderBrandes # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
|
1
.github/ISSUE_TEMPLATE.md
vendored
1
.github/ISSUE_TEMPLATE.md
vendored
@ -28,6 +28,7 @@ assignees: ''
|
||||
<!--- Issue /plot debugpaste in game or in your console and copy the supplied URL here -->
|
||||
<!--- If you cannot perform the above, we require logs/latest.log; settings.yml; worlds.yml and possibly PlotSquared.use_THIS.yml -->
|
||||
<!--- If you are unwilling to supply the information we need, we reserve the right to not assist you. Redact IP addresses if you need to. -->
|
||||
**/plot debugpaste:**
|
||||
|
||||
### Server type:
|
||||
**Select one**
|
||||
|
@ -1,101 +0,0 @@
|
||||
---
|
||||
name: Bug/Issue report for PlotSquared
|
||||
about: Bug / Issue report about this plugin
|
||||
title: ''
|
||||
labels: "[?] Testing Required"
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--- READ THIS BEFORE SUBMITTING AN ISSUE REPORT!!! -->
|
||||
|
||||
<!--- ##### DO NOT REMOVE THIS TEMPLATE! YOUR ISSUE *WILL* FIT IN IT! ##### -->
|
||||
|
||||
<!--- # NOTICE:
|
||||
|
||||
**Feature requests & Suggestions are to be submitted at the [PlotSquared Suggestions tracker](https://github.com/IntellectualSites/PlotSquaredSuggestions)**
|
||||
|
||||
**Code contributions are to be done through [PRs](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request), tagging the specific issue ticket(s) if applicable.**
|
||||
|
||||
**[DISCORD INVITE LINK](https://discord.gg/KxkjDVg)**
|
||||
-->
|
||||
|
||||
# Bug Report Template:
|
||||
<!--- Incomplete reports will most likely be marked as invalid, and closed, with few exceptions.-->
|
||||
## Required Information section:
|
||||
> ALL FIELDS IN THIS SECTION ARE REQUIRED, and must contain appropriate information
|
||||
### Server config info (/plot debugpaste / file paste links):
|
||||
<!--- Issue /plot debugpaste in game or in your console and copy the supplied URL here -->
|
||||
<!--- If you cannot perform the above, we require logs/latest.log; settings.yml; worlds.yml and possibly PlotSquared.use_THIS.yml -->
|
||||
<!--- If you are unwilling to supply the information we need, we reserve the right to not assist you. Redact IP addresses if you need to. -->
|
||||
**/plot debugpaste:**
|
||||
|
||||
### Server type:
|
||||
**Select one**
|
||||
<!-- Select the type you are reporting the issue for (put an "X" between of brackets): -->
|
||||
- [] Spigot / Paper *(CraftBukkit should not be used, re-test with Spigot first!)*
|
||||
- [] Sponge
|
||||
- [] NukkitX
|
||||
|
||||
### PlotSquared version:
|
||||
<!-- Run /plot plugin in-game or in console & paste the full output here: -->
|
||||
```
|
||||
Paste the output here, between the tick marks, replacing this text
|
||||
```
|
||||
|
||||
### Minecraft Version:
|
||||
**Select one**
|
||||
<!-- Select the type you are reporting the issue for (put an "X" between of brackets) -->
|
||||
- [] Minecraft 1.15.2
|
||||
- [] Minecraft 1.14.4
|
||||
- [] Minecraft 1.13.2
|
||||
- [] Minecraft 1.12.2
|
||||
- [] Minecraft 1.11.2
|
||||
- [] Minecraft 1.10.2
|
||||
- [] Minecraft 1.9.4
|
||||
- [] Minecraft 1.8.8
|
||||
- [] Minecraft Java Edition *other versions, please specify*:
|
||||
- [] Minecraft Bedrock Edition *specify version*:
|
||||
- [] Minecraft Sponge *specify version*:
|
||||
|
||||
### Server build info:
|
||||
<!--- Run /version in-game or in console & paste the full output here: -->
|
||||
```
|
||||
Paste the output here, between the tick marks, replacing this text
|
||||
```
|
||||
|
||||
### WorldEdit/FAWE versions:
|
||||
<!--- Specify which plugin you are using, and add its version. Either use /fawe version or /we version -->
|
||||
- [] FAWE version:
|
||||
- [] WorldEdit version:
|
||||
|
||||
### Description of the problem:
|
||||
<!--- Be as specific as possible. Don't lie, redact information, or use false names/situations. -->
|
||||
<!--- Who, What, When, Where, Why, How, Expected behavior, Resultant behavior, etc -->
|
||||
|
||||
### How to replicate:
|
||||
<!--- If you can reproduce the issue please tell us as detailed as possible step by step how to do that -->
|
||||
|
||||
## Additional Information:
|
||||
> The information here is optional for you to provide, however it may help us to more readily diagnose any compatibility and bug issues.
|
||||
|
||||
### Other plugins being used on the server:
|
||||
<!--- Optional but recommended - issue "/plugins" in-game or in console and copy/paste the list -->
|
||||
|
||||
### Relevant console output, log lines, and/or screenshots:
|
||||
<!--- Please use in-line code insertion
|
||||
```
|
||||
like this
|
||||
```
|
||||
for short (20 lines or less) text blobs, or a paste service for large blobs -->
|
||||
|
||||
### Additional relevant comments/remarks:
|
||||
<!--- Use this space to give us any additional information which may be relevant to this issue, such as: if you are using a Minecraft hosting provider; unusual installation environment; etc -->
|
||||
|
||||
# AFFIRMATION OF COMPLETION:
|
||||
<!-- Make sure you have completed the following steps (put an "X" between of brackets): -->
|
||||
- [] I included all information required in the sections above
|
||||
- [] I made sure there are no duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues?utf8=%E2%9C%93&q=is%3Aissue)
|
||||
- [] I made sure I am using an up-to-date version of PlotSquared
|
||||
- [] I made sure the bug/error is not caused by any other plugin
|
||||
- [x] I didn't read but checked everything above.
|
3
.github/ISSUE_TEMPLATE/config.yml
vendored
3
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,5 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: PlotSquared Issue Tracker
|
||||
url: https://issues.intellectualsites.com/projects/ps
|
||||
about: Click here to move to our new issue tracker
|
||||
- name: PlotSquared Suggestions
|
||||
url: https://github.com/IntellectualSites/PlotSquaredSuggestions
|
||||
about: If you want to submit feature or suggestion ideas, do that here
|
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -2,10 +2,10 @@
|
||||
<!-- Please describe which issue this Pull Request targets
|
||||
|
||||
If there is no issue, please create one so we can look into it before approving your PR.
|
||||
You can do so here: https://github.com/IntellectualSites/PlotSquared/issues/new/choose
|
||||
You can do so here: https://issues.intellectualsites.com/projects/ps
|
||||
-->
|
||||
|
||||
**Fixes #{issue number}**
|
||||
**Fixes {Link to issue}**
|
||||
|
||||
## Description
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -142,3 +142,4 @@ p2error.txt
|
||||
*.bat
|
||||
Nukkit/build/resources/main/plugin.yml
|
||||
docs/
|
||||
build/
|
||||
|
@ -11,7 +11,9 @@ repositories {
|
||||
name = "papermc"
|
||||
url = "https://papermc.io/repo/repository/maven-public/"
|
||||
}
|
||||
maven { url = "https://ci.ender.zone/plugin/repository/everything/" }
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
maven { url = "https://repo.wea-ondara.net/repository/public/" }
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
@ -20,17 +22,24 @@ dependencies {
|
||||
implementation(project(":PlotSquared-Core"))
|
||||
compile("org.bstats:bstats-bukkit:1.7")
|
||||
compile(project(":PlotSquared-Core"))
|
||||
compile("com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT")
|
||||
compile("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT")
|
||||
//implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT'
|
||||
implementation("org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT")
|
||||
compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.0.1")
|
||||
implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT")
|
||||
compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.1.0") {
|
||||
exclude(module: "bukkit")
|
||||
|
||||
}
|
||||
compile("io.papermc:paperlib:1.0.2")
|
||||
implementation("net.kyori:text-adapter-bukkit:3.0.3")
|
||||
compile("com.github.MilkBowl:VaultAPI:1.7") {
|
||||
exclude(module: "bukkit")
|
||||
}
|
||||
implementation("me.clip:placeholderapi:2.10.4")
|
||||
implementation("me.clip:placeholderapi:2.10.6")
|
||||
implementation("net.luckperms:api:5.1")
|
||||
implementation("net.ess3:EssentialsX:2.17.2")
|
||||
implementation("net.alpenblock:BungeePerms:4.0-dev-106")
|
||||
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
|
||||
compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
@ -87,10 +96,14 @@ shadowJar {
|
||||
include(dependency("io.papermc:paperlib:1.0.2"))
|
||||
include(dependency("net.kyori:text-adapter-bukkit:3.0.3"))
|
||||
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"))
|
||||
}
|
||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||
relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib")
|
||||
relocate("org.bstats", "com.plotsquared.metrics")
|
||||
relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid')
|
||||
relocate('org.khelekore.prtree', 'com.plotsquared.prtree')
|
||||
archiveFileName = "${project.name}-${parent.version}.jar"
|
||||
destinationDirectory = file "../target"
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20190722</version>
|
||||
<version>20200518</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -21,20 +21,26 @@
|
||||
<dependency>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-Core</artifactId>
|
||||
<version>5.11.2</version>
|
||||
<version>5.12.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.1</version>
|
||||
<version>7.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
@ -59,6 +65,24 @@
|
||||
<artifactId>Core</artifactId>
|
||||
<version>0.6.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>*</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>squirrelid</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>*</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
@ -113,7 +137,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -125,7 +149,25 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<version>2.10.6</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.17.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.alpenblock</groupId>
|
||||
<artifactId>BungeePerms</artifactId>
|
||||
<version>4.0-dev-106</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit;
|
||||
|
||||
import com.plotsquared.bukkit.command.DebugUUID;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.command.MainCommand;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
@ -46,10 +45,6 @@ import java.util.List;
|
||||
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
public BukkitCommand() {
|
||||
new DebugUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel,
|
||||
String[] args) {
|
||||
@ -83,6 +78,6 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
for (com.plotsquared.core.command.Command o : objects) {
|
||||
result.add(o.toString());
|
||||
}
|
||||
return result.isEmpty() ? null : result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -38,23 +38,27 @@ import com.plotsquared.bukkit.managers.HyperverseWorldManager;
|
||||
import com.plotsquared.bukkit.managers.MultiverseWorldManager;
|
||||
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
||||
import com.plotsquared.bukkit.placeholder.Placeholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
||||
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitPermHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitRegionManager;
|
||||
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
||||
import com.plotsquared.bukkit.util.BukkitTaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.SetGenCB;
|
||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||
import com.plotsquared.bukkit.util.uuid.DefaultUUIDWrapper;
|
||||
import com.plotsquared.bukkit.util.uuid.FileUUIDHandler;
|
||||
import com.plotsquared.bukkit.util.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.bukkit.util.uuid.OfflineUUIDWrapper;
|
||||
import com.plotsquared.bukkit.util.uuid.SQLUUIDHandler;
|
||||
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.EssentialsUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.LuckPermsUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.PaperUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.SQLiteUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService;
|
||||
import com.plotsquared.core.IPlotMain;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.backup.BackupManager;
|
||||
@ -65,6 +69,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.database.DBFunc;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.generator.HybridGen;
|
||||
import com.plotsquared.core.generator.HybridUtils;
|
||||
@ -77,19 +82,22 @@ import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.SetupObject;
|
||||
import com.plotsquared.core.plot.message.PlainChatManager;
|
||||
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.queue.QueueProvider;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.setup.SettingsNodesWrapper;
|
||||
import com.plotsquared.core.util.ChatManager;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.ConsoleColors;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.InventoryUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.PermHandler;
|
||||
import com.plotsquared.core.util.PlatformWorldManager;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
import com.plotsquared.core.util.ReflectionUtils;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
@ -98,9 +106,9 @@ import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
import com.plotsquared.core.uuid.CacheUUIDService;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -117,6 +125,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -134,17 +143,24 @@ import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.plotsquared.core.util.PremiumVerification.getDownloadID;
|
||||
import static com.plotsquared.core.util.PremiumVerification.getResourceID;
|
||||
import static com.plotsquared.core.util.PremiumVerification.getUserID;
|
||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<Player> {
|
||||
|
||||
private static final int BSTATS_ID = 1404;
|
||||
@Getter private static WorldEdit worldEdit;
|
||||
@ -163,7 +179,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
private boolean methodUnloadSetup = false;
|
||||
private boolean metricsStarted;
|
||||
@Getter private BackupManager backupManager;
|
||||
@Getter private PlatformWorldManager worldManager;
|
||||
@Getter private PlatformWorldManager<World> worldManager;
|
||||
private final BukkitPlayerManager playerManager = new BukkitPlayerManager();
|
||||
private EconHandler econ;
|
||||
private PermHandler perm;
|
||||
|
||||
@Override public int[] getServerVersion() {
|
||||
if (this.version == null) {
|
||||
@ -221,6 +240,122 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :(");
|
||||
}
|
||||
|
||||
final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline();
|
||||
final UUIDPipeline backgroundPipeline = PlotSquared.get().getBackgroundUUIDPipeline();
|
||||
|
||||
// Services are accessed in order
|
||||
final CacheUUIDService cacheUUIDService =
|
||||
new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE);
|
||||
impromptuPipeline.registerService(cacheUUIDService);
|
||||
backgroundPipeline.registerService(cacheUUIDService);
|
||||
impromptuPipeline.registerConsumer(cacheUUIDService);
|
||||
backgroundPipeline.registerConsumer(cacheUUIDService);
|
||||
|
||||
// Now, if the server is in offline mode we can only use profiles and direct UUID
|
||||
// access, and so we skip the player profile stuff as well as SquirrelID (Mojang lookups)
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
final OfflineModeUUIDService offlineModeUUIDService = new OfflineModeUUIDService();
|
||||
impromptuPipeline.registerService(offlineModeUUIDService);
|
||||
backgroundPipeline.registerService(offlineModeUUIDService);
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service");
|
||||
}
|
||||
|
||||
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
|
||||
impromptuPipeline.registerService(offlinePlayerUUIDService);
|
||||
backgroundPipeline.registerService(offlinePlayerUUIDService);
|
||||
|
||||
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
||||
|
||||
final SQLiteUUIDService legacyUUIDService;
|
||||
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil
|
||||
.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db").exists()) {
|
||||
legacyUUIDService = new SQLiteUUIDService("usercache.db");
|
||||
} else {
|
||||
legacyUUIDService = null;
|
||||
}
|
||||
|
||||
final LuckPermsUUIDService luckPermsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
luckPermsUUIDService = new LuckPermsUUIDService();
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using LuckPerms as a complementary UUID service");
|
||||
} else {
|
||||
luckPermsUUIDService = null;
|
||||
}
|
||||
|
||||
final BungeePermsUUIDService bungeePermsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
|
||||
bungeePermsUUIDService = new BungeePermsUUIDService();
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using BungeePerms as a complementary UUID service");
|
||||
} else {
|
||||
bungeePermsUUIDService = null;
|
||||
}
|
||||
|
||||
final EssentialsUUIDService essentialsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("Essentials") != null) {
|
||||
essentialsUUIDService = new EssentialsUUIDService();
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using Essentials as a complementary UUID service");
|
||||
} else {
|
||||
essentialsUUIDService = null;
|
||||
}
|
||||
|
||||
if (!Settings.UUID.OFFLINE) {
|
||||
// If running Paper we'll also try to use their profiles
|
||||
if (PaperLib.isPaper()) {
|
||||
final PaperUUIDService paperUUIDService = new PaperUUIDService();
|
||||
impromptuPipeline.registerService(paperUUIDService);
|
||||
backgroundPipeline.registerService(paperUUIDService);
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
|
||||
}
|
||||
|
||||
impromptuPipeline.registerService(sqLiteUUIDService);
|
||||
backgroundPipeline.registerService(sqLiteUUIDService);
|
||||
impromptuPipeline.registerConsumer(sqLiteUUIDService);
|
||||
backgroundPipeline.registerConsumer(sqLiteUUIDService);
|
||||
|
||||
if (legacyUUIDService != null) {
|
||||
impromptuPipeline.registerService(legacyUUIDService);
|
||||
backgroundPipeline.registerService(legacyUUIDService);
|
||||
}
|
||||
|
||||
// Plugin providers
|
||||
if (luckPermsUUIDService != null) {
|
||||
impromptuPipeline.registerService(luckPermsUUIDService);
|
||||
backgroundPipeline.registerService(luckPermsUUIDService);
|
||||
}
|
||||
if (bungeePermsUUIDService != null) {
|
||||
impromptuPipeline.registerService(bungeePermsUUIDService);
|
||||
backgroundPipeline.registerService(bungeePermsUUIDService);
|
||||
}
|
||||
if (essentialsUUIDService != null) {
|
||||
impromptuPipeline.registerService(essentialsUUIDService);
|
||||
backgroundPipeline.registerService(essentialsUUIDService);
|
||||
}
|
||||
|
||||
final SquirrelIdUUIDService impromptuMojangService =
|
||||
new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
|
||||
impromptuPipeline.registerService(impromptuMojangService);
|
||||
final SquirrelIdUUIDService backgroundMojangService =
|
||||
new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
|
||||
backgroundPipeline.registerService(backgroundMojangService);
|
||||
} else {
|
||||
impromptuPipeline.registerService(sqLiteUUIDService);
|
||||
backgroundPipeline.registerService(sqLiteUUIDService);
|
||||
impromptuPipeline.registerConsumer(sqLiteUUIDService);
|
||||
backgroundPipeline.registerConsumer(sqLiteUUIDService);
|
||||
|
||||
if (legacyUUIDService != null) {
|
||||
impromptuPipeline.registerService(legacyUUIDService);
|
||||
backgroundPipeline.registerService(legacyUUIDService);
|
||||
}
|
||||
}
|
||||
|
||||
impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);
|
||||
this.startUuidCatching(sqLiteUUIDService, cacheUUIDService);
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new Placeholders().register();
|
||||
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
||||
@ -259,8 +394,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
this.worldManager = new BukkitWorldManager();
|
||||
}
|
||||
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated() + "Using platform world manager: " +
|
||||
this.worldManager.getName());
|
||||
PlotSquared.log(
|
||||
Captions.PREFIX.getTranslated() + "Using platform world manager: " + this.worldManager
|
||||
.getName());
|
||||
|
||||
// Clean up potential memory leak
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
||||
try {
|
||||
for (final PlotPlayer<? extends Player> player : this.getPlayerManager().getPlayers()) {
|
||||
if (player.getPlatformPlayer() == null || !player.getPlatformPlayer().isOnline()) {
|
||||
this.getPlayerManager().removePlayer(player);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
getLogger().warning("Failed to clean up players: " + e.getMessage());
|
||||
}
|
||||
}, 100L, 100L);
|
||||
}
|
||||
|
||||
private void unload() {
|
||||
@ -342,6 +491,77 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
}
|
||||
|
||||
private void startUuidCatching(@NotNull final SQLiteUUIDService sqLiteUUIDService,
|
||||
@NotNull final CacheUUIDService cacheUUIDService) {
|
||||
// Load all uuids into a big chunky boi queue
|
||||
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>();
|
||||
PlotSquared.get().forEachPlotRaw(plot -> {
|
||||
final Set<UUID> uuids = new HashSet<>();
|
||||
uuids.add(plot.getOwnerAbs());
|
||||
uuids.addAll(plot.getMembers());
|
||||
uuids.addAll(plot.getTrusted());
|
||||
uuids.addAll(plot.getDenied());
|
||||
for (final UUID uuid : uuids) {
|
||||
if (!uuidQueue.contains(uuid)) {
|
||||
uuidQueue.add(uuid);
|
||||
}
|
||||
}
|
||||
});
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated() + "(UUID) " + uuidQueue.size()
|
||||
+ " UUIDs will be cached.");
|
||||
|
||||
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
|
||||
// Begin by reading all the SQLite cache at once
|
||||
cacheUUIDService.accept(sqLiteUUIDService.getAll());
|
||||
// Now fetch names for all known UUIDs
|
||||
final int totalSize = uuidQueue.size();
|
||||
int read = 0;
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated()
|
||||
+ "(UUID) PlotSquared will fetch UUIDs in groups of "
|
||||
+ Settings.UUID.BACKGROUND_LIMIT);
|
||||
final List<UUID> uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT);
|
||||
|
||||
// Used to indicate that the second retrieval has been attempted
|
||||
boolean secondRun = false;
|
||||
|
||||
while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) {
|
||||
if (!uuidList.isEmpty() && secondRun) {
|
||||
PlotSquared.log("Giving up on last batch. Fetching new batch instead.");
|
||||
uuidList.clear();
|
||||
}
|
||||
if (uuidList.isEmpty()) {
|
||||
// Retrieve the secondRun variable to indicate that we're retrieving a
|
||||
// fresh batch
|
||||
secondRun = false;
|
||||
// Populate the request list
|
||||
for (int i = 0;
|
||||
i < Settings.UUID.BACKGROUND_LIMIT && !uuidQueue.isEmpty(); i++) {
|
||||
uuidList.add(uuidQueue.poll());
|
||||
read++;
|
||||
}
|
||||
} else {
|
||||
// If the list isn't empty then this is a second run for
|
||||
// an old batch, so we re-use the patch
|
||||
secondRun = true;
|
||||
}
|
||||
try {
|
||||
PlotSquared.get().getBackgroundUUIDPipeline().getNames(uuidList).get();
|
||||
// Clear the list if we successfully index all the names
|
||||
uuidList.clear();
|
||||
// Print progress
|
||||
final double percentage = ((double) read / (double) totalSize) * 100.0D;
|
||||
PlotSquared.log(Captions.PREFIX.getTranslated() + String
|
||||
.format("(UUID) PlotSquared has cached %.1f%% of UUIDs", percentage));
|
||||
} catch (final InterruptedException | ExecutionException e) {
|
||||
PlotSquared.log("Failed to retrieve that batch. Will try again.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX.getTranslated() + "(UUID) PlotSquared has cached all UUIDs");
|
||||
}, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override public void onDisable() {
|
||||
PlotSquared.get().disable();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
@ -411,46 +631,46 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
Iterator<Entity> iterator = entities.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entity entity = iterator.next();
|
||||
switch (entity.getType()) {
|
||||
case EGG:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
case FIREWORK:
|
||||
case LIGHTNING:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case PLAYER:
|
||||
switch (entity.getType().toString()) {
|
||||
case "EGG":
|
||||
case "FISHING_HOOK":
|
||||
case "ENDER_SIGNAL":
|
||||
case "AREA_EFFECT_CLOUD":
|
||||
case "EXPERIENCE_ORB":
|
||||
case "LEASH_HITCH":
|
||||
case "FIREWORK":
|
||||
case "LIGHTNING":
|
||||
case "WITHER_SKULL":
|
||||
case "UNKNOWN":
|
||||
case "PLAYER":
|
||||
// non moving / unmovable
|
||||
continue;
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case SPLASH_POTION:
|
||||
case SNOWBALL:
|
||||
case SHULKER_BULLET:
|
||||
case SPECTRAL_ARROW:
|
||||
case ENDER_PEARL:
|
||||
case ARROW:
|
||||
case LLAMA_SPIT:
|
||||
case TRIDENT:
|
||||
case "THROWN_EXP_BOTTLE":
|
||||
case "SPLASH_POTION":
|
||||
case "SNOWBALL":
|
||||
case "SHULKER_BULLET":
|
||||
case "SPECTRAL_ARROW":
|
||||
case "ENDER_PEARL":
|
||||
case "ARROW":
|
||||
case "LLAMA_SPIT":
|
||||
case "TRIDENT":
|
||||
// managed elsewhere | projectile
|
||||
continue;
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
case "ITEM_FRAME":
|
||||
case "PAINTING":
|
||||
// Not vehicles
|
||||
continue;
|
||||
case ARMOR_STAND:
|
||||
case "ARMOR_STAND":
|
||||
// Temporarily classify as vehicle
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case ENDER_CRYSTAL:
|
||||
case MINECART_TNT:
|
||||
case BOAT:
|
||||
case "MINECART":
|
||||
case "MINECART_CHEST":
|
||||
case "MINECART_COMMAND":
|
||||
case "MINECART_FURNACE":
|
||||
case "MINECART_HOPPER":
|
||||
case "MINECART_MOB_SPAWNER":
|
||||
case "ENDER_CRYSTAL":
|
||||
case "MINECART_TNT":
|
||||
case "BOAT":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
com.plotsquared.core.location.Location location =
|
||||
BukkitUtil.getLocation(entity.getLocation());
|
||||
@ -479,10 +699,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case SMALL_FIREBALL:
|
||||
case FIREBALL:
|
||||
case DRAGON_FIREBALL:
|
||||
case DROPPED_ITEM:
|
||||
case "SMALL_FIREBALL":
|
||||
case "FIREBALL":
|
||||
case "DRAGON_FIREBALL":
|
||||
case "DROPPED_ITEM":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea
|
||||
.getOwnedPlotAbs(BukkitUtil.getLocation(entity.getLocation()))
|
||||
== null) {
|
||||
@ -490,11 +710,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
// dropped item
|
||||
continue;
|
||||
case PRIMED_TNT:
|
||||
case FALLING_BLOCK:
|
||||
case "PRIMED_TNT":
|
||||
case "FALLING_BLOCK":
|
||||
// managed elsewhere
|
||||
continue;
|
||||
case SHULKER:
|
||||
case "SHULKER":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
List<MetadataValue> meta = entity.getMetadata("shulkerPlot");
|
||||
@ -542,71 +762,76 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case LLAMA:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case ZOMBIE_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
case HUSK:
|
||||
case ELDER_GUARDIAN:
|
||||
case WITHER_SKELETON:
|
||||
case STRAY:
|
||||
case ZOMBIE_VILLAGER:
|
||||
case EVOKER:
|
||||
case EVOKER_FANGS:
|
||||
case VEX:
|
||||
case VINDICATOR:
|
||||
case POLAR_BEAR:
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case CAVE_SPIDER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case CREEPER:
|
||||
case ENDERMAN:
|
||||
case ENDERMITE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case GIANT:
|
||||
case GUARDIAN:
|
||||
case HORSE:
|
||||
case IRON_GOLEM:
|
||||
case MAGMA_CUBE:
|
||||
case MUSHROOM_COW:
|
||||
case OCELOT:
|
||||
case PIG:
|
||||
case PIG_ZOMBIE:
|
||||
case RABBIT:
|
||||
case SHEEP:
|
||||
case SILVERFISH:
|
||||
case SKELETON:
|
||||
case SLIME:
|
||||
case SNOWMAN:
|
||||
case SPIDER:
|
||||
case SQUID:
|
||||
case VILLAGER:
|
||||
case WITCH:
|
||||
case WITHER:
|
||||
case WOLF:
|
||||
case ZOMBIE:
|
||||
case PARROT:
|
||||
case SALMON:
|
||||
case DOLPHIN:
|
||||
case TROPICAL_FISH:
|
||||
case DROWNED:
|
||||
case COD:
|
||||
case TURTLE:
|
||||
case PUFFERFISH:
|
||||
case PHANTOM:
|
||||
case ILLUSIONER:
|
||||
case CAT:
|
||||
case PANDA:
|
||||
case FOX:
|
||||
case PILLAGER:
|
||||
case TRADER_LLAMA:
|
||||
case WANDERING_TRADER:
|
||||
case RAVAGER:
|
||||
//case BEE:
|
||||
case "ZOMBIFIED_PIGLIN":
|
||||
case "LLAMA":
|
||||
case "DONKEY":
|
||||
case "MULE":
|
||||
case "ZOMBIE_HORSE":
|
||||
case "SKELETON_HORSE":
|
||||
case "HUSK":
|
||||
case "ELDER_GUARDIAN":
|
||||
case "WITHER_SKELETON":
|
||||
case "STRAY":
|
||||
case "ZOMBIE_VILLAGER":
|
||||
case "EVOKER":
|
||||
case "EVOKER_FANGS":
|
||||
case "VEX":
|
||||
case "VINDICATOR":
|
||||
case "POLAR_BEAR":
|
||||
case "BAT":
|
||||
case "BLAZE":
|
||||
case "CAVE_SPIDER":
|
||||
case "CHICKEN":
|
||||
case "COW":
|
||||
case "CREEPER":
|
||||
case "ENDERMAN":
|
||||
case "ENDERMITE":
|
||||
case "ENDER_DRAGON":
|
||||
case "GHAST":
|
||||
case "GIANT":
|
||||
case "GUARDIAN":
|
||||
case "HORSE":
|
||||
case "IRON_GOLEM":
|
||||
case "MAGMA_CUBE":
|
||||
case "MUSHROOM_COW":
|
||||
case "OCELOT":
|
||||
case "PIG":
|
||||
case "PIG_ZOMBIE":
|
||||
case "RABBIT":
|
||||
case "SHEEP":
|
||||
case "SILVERFISH":
|
||||
case "SKELETON":
|
||||
case "SLIME":
|
||||
case "SNOWMAN":
|
||||
case "SPIDER":
|
||||
case "SQUID":
|
||||
case "VILLAGER":
|
||||
case "WITCH":
|
||||
case "WITHER":
|
||||
case "WOLF":
|
||||
case "ZOMBIE":
|
||||
case "PARROT":
|
||||
case "SALMON":
|
||||
case "DOLPHIN":
|
||||
case "TROPICAL_FISH":
|
||||
case "DROWNED":
|
||||
case "COD":
|
||||
case "TURTLE":
|
||||
case "PUFFERFISH":
|
||||
case "PHANTOM":
|
||||
case "ILLUSIONER":
|
||||
case "CAT":
|
||||
case "PANDA":
|
||||
case "FOX":
|
||||
case "PILLAGER":
|
||||
case "TRADER_LLAMA":
|
||||
case "WANDERING_TRADER":
|
||||
case "RAVAGER":
|
||||
case "BEE":
|
||||
case "HOGLIN":
|
||||
case "PIGLIN":
|
||||
case "ZOGLIN":
|
||||
break;
|
||||
default: {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
Location location = entity.getLocation();
|
||||
@ -687,8 +912,16 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
|
||||
@Override public EconHandler getEconomyHandler() {
|
||||
if (econ != null) {
|
||||
if (econ.init() /* is inited */) {
|
||||
return econ;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BukkitEconHandler econ = new BukkitEconHandler();
|
||||
econ = new BukkitEconHandler();
|
||||
if (econ.init()) {
|
||||
return econ;
|
||||
}
|
||||
@ -698,6 +931,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public PermHandler getPermissionHandler() {
|
||||
if (perm != null) {
|
||||
if (perm.init() /* is inited */) {
|
||||
return perm;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
perm = new BukkitPermHandler();
|
||||
if (perm.init()) {
|
||||
return perm;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
PlotSquared.debug("No permissions detected!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public QueueProvider initBlockQueue() {
|
||||
//TODO Figure out why this code is still here yet isn't being called anywhere.
|
||||
// try {
|
||||
@ -715,8 +968,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return new BukkitUtil();
|
||||
}
|
||||
|
||||
@Override @Nullable
|
||||
public GeneratorWrapper<?> getGenerator(@NonNull final String world,
|
||||
@Override @Nullable public GeneratorWrapper<?> getGenerator(@NonNull final String world,
|
||||
@Nullable final String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
@ -767,7 +1019,9 @@ 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("worldedit_implementation",
|
||||
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ? "FastAsyncWorldEdit" : "WorldEdit"));
|
||||
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ?
|
||||
"FastAsyncWorldEdit" :
|
||||
"WorldEdit"));
|
||||
}
|
||||
|
||||
@Override public ChunkManager initChunkManager() {
|
||||
@ -779,7 +1033,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
|
||||
@Override public void unregister(@NonNull final PlotPlayer player) {
|
||||
BukkitUtil.removePlayer(player.getName());
|
||||
BukkitUtil.removePlayer(player.getUUID());
|
||||
}
|
||||
|
||||
@Override public void registerChunkProcessor() {
|
||||
@ -798,39 +1052,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return new BukkitInventoryUtil();
|
||||
}
|
||||
|
||||
@Override public UUIDHandlerImplementation initUUIDHandler() {
|
||||
final UUIDWrapper wrapper;
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
wrapper = new LowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
wrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
Settings.UUID.OFFLINE = true;
|
||||
} else {
|
||||
wrapper = new DefaultUUIDWrapper();
|
||||
Settings.UUID.OFFLINE = false;
|
||||
}
|
||||
if (!Bukkit.getVersion().contains("git-Spigot")) {
|
||||
if (wrapper instanceof DefaultUUIDWrapper
|
||||
|| wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
||||
}
|
||||
}
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
PlotSquared.log(Captions.PREFIX + "&6" + getPluginName()
|
||||
+ " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
||||
+ "Bukkit");
|
||||
} else {
|
||||
PlotSquared.log(Captions.PREFIX + "&6" + getPluginName() + " is using online UUIDs");
|
||||
}
|
||||
if (Settings.UUID.USE_SQLUUIDHANDLER) {
|
||||
return new SQLUUIDHandler(wrapper);
|
||||
} else {
|
||||
return new FileUUIDHandler(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setGenerator(@NonNull final String worldName) {
|
||||
World world = BukkitUtil.getWorld(worldName);
|
||||
if (world == null) {
|
||||
@ -838,14 +1059,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
ConfigurationSection worldConfig =
|
||||
PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
|
||||
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
||||
SetupObject setup = new SetupObject();
|
||||
setup.plotManager = manager;
|
||||
setup.setupGenerator = worldConfig.getString("generator.init", manager);
|
||||
setup.type = MainUtil.getType(worldConfig);
|
||||
setup.terrain = MainUtil.getTerrain(worldConfig);
|
||||
setup.step = new ConfigurationNode[0];
|
||||
setup.world = worldName;
|
||||
SetupUtils.manager.setupWorld(setup);
|
||||
PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager)
|
||||
.generatorName(worldConfig.getString("generator.init", manager))
|
||||
.plotAreaType(MainUtil.getType(worldConfig))
|
||||
.terrainType(MainUtil.getTerrain(worldConfig))
|
||||
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
|
||||
.worldName(worldName);
|
||||
SetupUtils.manager.setupWorld(builder);
|
||||
world = Bukkit.getWorld(worldName);
|
||||
} else {
|
||||
try {
|
||||
@ -873,7 +1093,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return new BukkitSchematicHandler();
|
||||
}
|
||||
|
||||
@Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
|
||||
/**
|
||||
* Attempt to retrieve a {@link PlotPlayer} from a player identifier.
|
||||
* This method accepts:
|
||||
* - {@link Player} objects,
|
||||
* - {@link OfflinePlayer} objects,
|
||||
* - {@link String} usernames for online players, and
|
||||
* - {@link UUID} UUIDs for online players
|
||||
* <p>
|
||||
* In the case of offline players, a fake {@link Player} instance will be created.
|
||||
* This is a rather expensive operation, and should be avoided if possible.
|
||||
*
|
||||
* @param player The player to convert to a PlotPlayer
|
||||
* @return The plot player instance that corresponds to the identifier, or null
|
||||
* if no such player object could be created
|
||||
*/
|
||||
@Override @Nullable public PlotPlayer<Player> wrapPlayer(final Object player) {
|
||||
if (player instanceof Player) {
|
||||
return BukkitUtil.getPlayer((Player) player);
|
||||
}
|
||||
@ -881,10 +1116,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return BukkitUtil.getPlayer((OfflinePlayer) player);
|
||||
}
|
||||
if (player instanceof String) {
|
||||
return UUIDHandler.getPlayer((String) player);
|
||||
return (PlotPlayer<Player>) PlotSquared.imp().getPlayerManager()
|
||||
.getPlayerIfExists((String) player);
|
||||
}
|
||||
if (player instanceof UUID) {
|
||||
return UUIDHandler.getPlayer((UUID) player);
|
||||
return (PlotPlayer<Player>) PlotSquared.imp().getPlayerManager()
|
||||
.getPlayerIfExists((UUID) player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -902,8 +1139,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
||||
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
||||
@NonNull final IndependentPlotGenerator generator) {
|
||||
return new BukkitPlotGenerator(world, generator);
|
||||
}
|
||||
@ -925,4 +1161,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return wePlugin.wrapCommandSender(console);
|
||||
}
|
||||
|
||||
@Override @NotNull
|
||||
public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> getPlayerManager() {
|
||||
return this.playerManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,323 +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.bukkit.command;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.plotsquared.bukkit.util.uuid.DatFileFilter;
|
||||
import com.plotsquared.bukkit.util.uuid.DefaultUUIDWrapper;
|
||||
import com.plotsquared.bukkit.util.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.bukkit.util.uuid.OfflineUUIDWrapper;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.command.Argument;
|
||||
import com.plotsquared.core.command.CommandCategory;
|
||||
import com.plotsquared.core.command.CommandDeclaration;
|
||||
import com.plotsquared.core.command.RequiredType;
|
||||
import com.plotsquared.core.command.SubCommand;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(command = "uuidconvert",
|
||||
permission = "plots.admin",
|
||||
description = "Debug UUID conversion",
|
||||
usage = "/plot uuidconvert <lower|offline|online>",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.DEBUG)
|
||||
public class DebugUUID extends SubCommand {
|
||||
|
||||
public DebugUUID() {
|
||||
super(Argument.String);
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||
final UUIDWrapper newWrapper;
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "lower":
|
||||
newWrapper = new LowerOfflineUUIDWrapper();
|
||||
break;
|
||||
case "offline":
|
||||
newWrapper = new OfflineUUIDWrapper();
|
||||
break;
|
||||
case "online":
|
||||
newWrapper = new DefaultUUIDWrapper();
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
Class<?> clazz = Class.forName(args[0]);
|
||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
|
||||
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
|
||||
"/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length != 2 || !"-o".equals(args[1])) {
|
||||
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
|
||||
"/plot uuidconvert " + args[0] + " -o");
|
||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||
MainUtil.sendMessage(player,
|
||||
"&8 - &cUse the database command or another method to backup your plots beforehand");
|
||||
MainUtil.sendMessage(player,
|
||||
"&8 - &cIf the process is interrupted, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
||||
MainUtil
|
||||
.sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
||||
MainUtil.sendMessage(player,
|
||||
"&7Retype the command with the override parameter when ready :)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentUUIDWrapper.getClass().getCanonicalName()
|
||||
.equals(newWrapper.getClass().getCanonicalName())) {
|
||||
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
|
||||
MainUtil.sendMessage(player, "&7 - Disconnecting players");
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
entry.getValue()
|
||||
.kick("UUID conversion has been initiated. You may reconnect when finished.");
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Initializing map");
|
||||
|
||||
final HashMap<UUID, UUID> uCMap = new HashMap<>();
|
||||
final HashMap<UUID, UUID> uCReverse = new HashMap<>();
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Collecting playerdata");
|
||||
|
||||
HashSet<String> worlds = Sets.newHashSet(WorldUtil.IMP.getMainWorld(), "world");
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
for (String worldName : worlds) {
|
||||
File playerDataFolder = new File(worldName + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
if (dat != null) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.PREFIX + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
File playersFolder = new File(worldName + File.separator + "players");
|
||||
dat = playersFolder.list(new DatFileFilter());
|
||||
if (dat != null) {
|
||||
for (String current : dat) {
|
||||
names.add(current.replaceAll(".dat$", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Populating map");
|
||||
UUID uuid2;
|
||||
UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
||||
for (UUID uuid : uuids) {
|
||||
try {
|
||||
OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||
uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse
|
||||
.containsKey(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (String name : names) {
|
||||
UUID uuid = currentUUIDWrapper.getUUID(name);
|
||||
uuid2 = newWrapper.getUUID(name);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
if (uCMap.isEmpty()) {
|
||||
MainUtil.sendMessage(player, "&c - Error! Attempting to repopulate");
|
||||
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
||||
if (op.getLastPlayed() != 0) {
|
||||
// String name = op.getPluginName();
|
||||
// StringWrapper wrap = new StringWrapper(name);
|
||||
UUID uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uCMap.isEmpty()) {
|
||||
MainUtil.sendMessage(player, "&cError. Failed to collect UUIDs!");
|
||||
return false;
|
||||
} else {
|
||||
MainUtil.sendMessage(player, "&a - Successfully repopulated");
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||
String name = UUIDHandler.getName(entry.getKey());
|
||||
if (name != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
|
||||
|
||||
File file = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
String[] split = line.split("\\|");
|
||||
String name = split[0];
|
||||
if (name.isEmpty() || name.length() > 16 || !StringMan
|
||||
.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
UUID old = currentUUIDWrapper.getUUID(name);
|
||||
if (old == null) {
|
||||
continue;
|
||||
}
|
||||
UUID now = newWrapper.getUUID(name);
|
||||
UUIDHandler.add(new StringWrapper(name), now);
|
||||
uCMap.put(old, now);
|
||||
uCReverse.put(now, old);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing wrapper");
|
||||
UUIDHandler.setUUIDWrapper(newWrapper);
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
||||
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
UUID value = uCMap.get(plot.getOwnerAbs());
|
||||
if (value != null) {
|
||||
plot.setOwnerAbs(value);
|
||||
}
|
||||
plot.getTrusted().clear();
|
||||
plot.getMembers().clear();
|
||||
plot.getDenied().clear();
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Deleting database");
|
||||
boolean result = DBFunc.deleteTables();
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Creating tables");
|
||||
|
||||
try {
|
||||
DBFunc.createTables();
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
UUID value = uCReverse.get(plot.getOwnerAbs());
|
||||
if (value != null) {
|
||||
plot.setOwnerAbs(value);
|
||||
}
|
||||
}
|
||||
DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()),
|
||||
() -> MainUtil.sendMessage(player, "&6Recovery was successful!"));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||
PlotSquared.get().worlds.set("UUID.offline", true);
|
||||
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||
PlotSquared.get().worlds.set("UUID.offline", false);
|
||||
}
|
||||
try {
|
||||
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||
} catch (IOException ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
"Could not save configuration. It will need to be manual set!");
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Populating tables");
|
||||
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||
DBFunc.createPlotsAndData(plots,
|
||||
() -> MainUtil.sendMessage(player, "&aConversion complete!"));
|
||||
});
|
||||
|
||||
MainUtil.sendMessage(player, "&aIt is now safe for players to join");
|
||||
MainUtil.sendMessage(player,
|
||||
"&cConversion is still in progress, you will be notified when it is complete");
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -103,51 +103,51 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
if (!entity.hasGravity()) {
|
||||
this.noGravity = true;
|
||||
}
|
||||
switch (entity.getType()) {
|
||||
case BOAT:
|
||||
switch (entity.getType().toString()) {
|
||||
case "BOAT":
|
||||
Boat boat = (Boat) entity;
|
||||
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
|
||||
return;
|
||||
case ARROW:
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_PEARL:
|
||||
case ENDER_SIGNAL:
|
||||
case EXPERIENCE_ORB:
|
||||
case FALLING_BLOCK:
|
||||
case FIREBALL:
|
||||
case FIREWORK:
|
||||
case FISHING_HOOK:
|
||||
case LEASH_HITCH:
|
||||
case LIGHTNING:
|
||||
case MINECART:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
case PLAYER:
|
||||
case PRIMED_TNT:
|
||||
case SLIME:
|
||||
case SMALL_FIREBALL:
|
||||
case SNOWBALL:
|
||||
case MINECART_FURNACE:
|
||||
case SPLASH_POTION:
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case SPECTRAL_ARROW:
|
||||
case SHULKER_BULLET:
|
||||
case DRAGON_FIREBALL:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case TRIDENT:
|
||||
case LLAMA_SPIT:
|
||||
case "ARROW":
|
||||
case "EGG":
|
||||
case "ENDER_CRYSTAL":
|
||||
case "ENDER_PEARL":
|
||||
case "ENDER_SIGNAL":
|
||||
case "EXPERIENCE_ORB":
|
||||
case "FALLING_BLOCK":
|
||||
case "FIREBALL":
|
||||
case "FIREWORK":
|
||||
case "FISHING_HOOK":
|
||||
case "LEASH_HITCH":
|
||||
case "LIGHTNING":
|
||||
case "MINECART":
|
||||
case "MINECART_COMMAND":
|
||||
case "MINECART_MOB_SPAWNER":
|
||||
case "MINECART_TNT":
|
||||
case "PLAYER":
|
||||
case "PRIMED_TNT":
|
||||
case "SLIME":
|
||||
case "SMALL_FIREBALL":
|
||||
case "SNOWBALL":
|
||||
case "MINECART_FURNACE":
|
||||
case "SPLASH_POTION":
|
||||
case "THROWN_EXP_BOTTLE":
|
||||
case "WITHER_SKULL":
|
||||
case "UNKNOWN":
|
||||
case "SPECTRAL_ARROW":
|
||||
case "SHULKER_BULLET":
|
||||
case "DRAGON_FIREBALL":
|
||||
case "AREA_EFFECT_CLOUD":
|
||||
case "TRIDENT":
|
||||
case "LLAMA_SPIT":
|
||||
// Do this stuff later
|
||||
return;
|
||||
// MISC //
|
||||
case DROPPED_ITEM:
|
||||
case "DROPPED_ITEM":
|
||||
Item item = (Item) entity;
|
||||
this.stack = item.getItemStack();
|
||||
return;
|
||||
case ITEM_FRAME:
|
||||
case "ITEM_FRAME":
|
||||
this.x = Math.floor(this.x);
|
||||
this.y = Math.floor(this.y);
|
||||
this.z = Math.floor(this.z);
|
||||
@ -155,7 +155,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
|
||||
this.stack = itemFrame.getItem().clone();
|
||||
return;
|
||||
case PAINTING:
|
||||
case "PAINTING":
|
||||
this.x = Math.floor(this.x);
|
||||
this.y = Math.floor(this.y);
|
||||
this.z = Math.floor(this.z);
|
||||
@ -170,18 +170,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
return;
|
||||
// END MISC //
|
||||
// INVENTORY HOLDER //
|
||||
case MINECART_CHEST:
|
||||
case MINECART_HOPPER:
|
||||
case "MINECART_CHEST":
|
||||
case "MINECART_HOPPER":
|
||||
storeInventory((InventoryHolder) entity);
|
||||
return;
|
||||
// START LIVING ENTITY //
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case HORSE:
|
||||
case DONKEY:
|
||||
case LLAMA:
|
||||
case MULE:
|
||||
case SKELETON_HORSE:
|
||||
case "HORSE":
|
||||
case "DONKEY":
|
||||
case "LLAMA":
|
||||
case "MULE":
|
||||
case "SKELETON_HORSE":
|
||||
AbstractHorse horse = (AbstractHorse) entity;
|
||||
this.horse = new HorseStats();
|
||||
this.horse.jump = horse.getJumpStrength();
|
||||
@ -199,15 +199,15 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
storeInventory(horse);
|
||||
return;
|
||||
// END INVENTORY HOLDER //
|
||||
case WOLF:
|
||||
case OCELOT:
|
||||
case "WOLF":
|
||||
case "OCELOT":
|
||||
storeTameable((Tameable) entity);
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END TAMEABLE //
|
||||
//todo fix sheep
|
||||
case SHEEP:
|
||||
case "SHEEP":
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (sheep.isSheared()) {
|
||||
this.dataByte = (byte) 1;
|
||||
@ -218,23 +218,23 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
storeAgeable(sheep);
|
||||
storeLiving(sheep);
|
||||
return;
|
||||
case VILLAGER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case MUSHROOM_COW:
|
||||
case PIG:
|
||||
case TURTLE:
|
||||
case POLAR_BEAR:
|
||||
case "VILLAGER":
|
||||
case "CHICKEN":
|
||||
case "COW":
|
||||
case "MUSHROOM_COW":
|
||||
case "PIG":
|
||||
case "TURTLE":
|
||||
case "POLAR_BEAR":
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
case RABBIT:
|
||||
case "RABBIT":
|
||||
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END AGEABLE //
|
||||
case ARMOR_STAND:
|
||||
case "ARMOR_STAND":
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
this.inventory =
|
||||
new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(),
|
||||
@ -286,42 +286,45 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
this.stand.small = true;
|
||||
}
|
||||
return;
|
||||
case ENDERMITE:
|
||||
case "ENDERMITE":
|
||||
return;
|
||||
case BAT:
|
||||
case "BAT":
|
||||
if (((Bat) entity).isAwake()) {
|
||||
this.dataByte = (byte) 1;
|
||||
} else {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
return;
|
||||
case ENDER_DRAGON:
|
||||
case "ENDER_DRAGON":
|
||||
EnderDragon entity1 = (EnderDragon) entity;
|
||||
this.dataByte = (byte) entity1.getPhase().ordinal();
|
||||
return;
|
||||
case SKELETON:
|
||||
case WITHER_SKELETON:
|
||||
case GUARDIAN:
|
||||
case ELDER_GUARDIAN:
|
||||
case GHAST:
|
||||
case MAGMA_CUBE:
|
||||
case SQUID:
|
||||
case PIG_ZOMBIE:
|
||||
case ZOMBIE:
|
||||
case WITHER:
|
||||
case WITCH:
|
||||
case SPIDER:
|
||||
case CAVE_SPIDER:
|
||||
case SILVERFISH:
|
||||
case GIANT:
|
||||
case ENDERMAN:
|
||||
case CREEPER:
|
||||
case BLAZE:
|
||||
case SHULKER:
|
||||
case SNOWMAN:
|
||||
case "SKELETON":
|
||||
case "WITHER_SKELETON":
|
||||
case "GUARDIAN":
|
||||
case "ELDER_GUARDIAN":
|
||||
case "GHAST":
|
||||
case "MAGMA_CUBE":
|
||||
case "SQUID":
|
||||
case "PIG_ZOMBIE":
|
||||
case "HOGLIN":
|
||||
case "ZOMBIFIED_PIGLIN":
|
||||
case "PIGLIN":
|
||||
case "ZOMBIE":
|
||||
case "WITHER":
|
||||
case "WITCH":
|
||||
case "SPIDER":
|
||||
case "CAVE_SPIDER":
|
||||
case "SILVERFISH":
|
||||
case "GIANT":
|
||||
case "ENDERMAN":
|
||||
case "CREEPER":
|
||||
case "BLAZE":
|
||||
case "SHULKER":
|
||||
case "SNOWMAN":
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
case IRON_GOLEM:
|
||||
case "IRON_GOLEM":
|
||||
if (((IronGolem) entity).isPlayerCreated()) {
|
||||
this.dataByte = (byte) 1;
|
||||
} else {
|
||||
@ -463,16 +466,16 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
return null;
|
||||
}
|
||||
Entity entity;
|
||||
switch (this.getType()) {
|
||||
case DROPPED_ITEM:
|
||||
switch (this.getType().toString()) {
|
||||
case "DROPPED_ITEM":
|
||||
return world.dropItem(location, this.stack);
|
||||
case PLAYER:
|
||||
case LEASH_HITCH:
|
||||
case "PLAYER":
|
||||
case "LEASH_HITCH":
|
||||
return null;
|
||||
case ITEM_FRAME:
|
||||
case "ITEM_FRAME":
|
||||
entity = world.spawn(location, ItemFrame.class);
|
||||
break;
|
||||
case PAINTING:
|
||||
case "PAINTING":
|
||||
entity = world.spawn(location, Painting.class);
|
||||
break;
|
||||
default:
|
||||
@ -504,73 +507,73 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
if (this.noGravity) {
|
||||
entity.setGravity(false);
|
||||
}
|
||||
switch (entity.getType()) {
|
||||
case BOAT:
|
||||
switch (entity.getType().toString()) {
|
||||
case "BOAT":
|
||||
Boat boat = (Boat) entity;
|
||||
boat.setWoodType(TreeSpecies.values()[dataByte]);
|
||||
return entity;
|
||||
case SLIME:
|
||||
case "SLIME":
|
||||
((Slime) entity).setSize(this.dataByte);
|
||||
return entity;
|
||||
case ARROW:
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_PEARL:
|
||||
case ENDER_SIGNAL:
|
||||
case DROPPED_ITEM:
|
||||
case EXPERIENCE_ORB:
|
||||
case FALLING_BLOCK:
|
||||
case FIREBALL:
|
||||
case FIREWORK:
|
||||
case FISHING_HOOK:
|
||||
case LEASH_HITCH:
|
||||
case LIGHTNING:
|
||||
case MINECART:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
case PLAYER:
|
||||
case PRIMED_TNT:
|
||||
case SMALL_FIREBALL:
|
||||
case SNOWBALL:
|
||||
case SPLASH_POTION:
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case SPECTRAL_ARROW:
|
||||
case SHULKER_BULLET:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case DRAGON_FIREBALL:
|
||||
case WITHER_SKULL:
|
||||
case MINECART_FURNACE:
|
||||
case LLAMA_SPIT:
|
||||
case TRIDENT:
|
||||
case UNKNOWN:
|
||||
case "ARROW":
|
||||
case "EGG":
|
||||
case "ENDER_CRYSTAL":
|
||||
case "ENDER_PEARL":
|
||||
case "ENDER_SIGNAL":
|
||||
case "DROPPED_ITEM":
|
||||
case "EXPERIENCE_ORB":
|
||||
case "FALLING_BLOCK":
|
||||
case "FIREBALL":
|
||||
case "FIREWORK":
|
||||
case "FISHING_HOOK":
|
||||
case "LEASH_HITCH":
|
||||
case "LIGHTNING":
|
||||
case "MINECART":
|
||||
case "MINECART_COMMAND":
|
||||
case "MINECART_MOB_SPAWNER":
|
||||
case "MINECART_TNT":
|
||||
case "PLAYER":
|
||||
case "PRIMED_TNT":
|
||||
case "SMALL_FIREBALL":
|
||||
case "SNOWBALL":
|
||||
case "SPLASH_POTION":
|
||||
case "THROWN_EXP_BOTTLE":
|
||||
case "SPECTRAL_ARROW":
|
||||
case "SHULKER_BULLET":
|
||||
case "AREA_EFFECT_CLOUD":
|
||||
case "DRAGON_FIREBALL":
|
||||
case "WITHER_SKULL":
|
||||
case "MINECART_FURNACE":
|
||||
case "LLAMA_SPIT":
|
||||
case "TRIDENT":
|
||||
case "UNKNOWN":
|
||||
// Do this stuff later
|
||||
return entity;
|
||||
// MISC //
|
||||
case ITEM_FRAME:
|
||||
case "ITEM_FRAME":
|
||||
ItemFrame itemframe = (ItemFrame) entity;
|
||||
itemframe.setRotation(Rotation.values()[this.dataByte]);
|
||||
itemframe.setItem(this.stack);
|
||||
return entity;
|
||||
case PAINTING:
|
||||
case "PAINTING":
|
||||
Painting painting = (Painting) entity;
|
||||
painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
|
||||
painting.setArt(Art.getByName(this.dataString), true);
|
||||
return entity;
|
||||
// END MISC //
|
||||
// INVENTORY HOLDER //
|
||||
case MINECART_CHEST:
|
||||
case MINECART_HOPPER:
|
||||
case "MINECART_CHEST":
|
||||
case "MINECART_HOPPER":
|
||||
restoreInventory((InventoryHolder) entity);
|
||||
return entity;
|
||||
// START LIVING ENTITY //
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case HORSE:
|
||||
case LLAMA:
|
||||
case SKELETON_HORSE:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case "HORSE":
|
||||
case "LLAMA":
|
||||
case "SKELETON_HORSE":
|
||||
case "DONKEY":
|
||||
case "MULE":
|
||||
AbstractHorse horse = (AbstractHorse) entity;
|
||||
horse.setJumpStrength(this.horse.jump);
|
||||
if (horse instanceof ChestedHorse) {
|
||||
@ -586,14 +589,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
restoreInventory(horse);
|
||||
return entity;
|
||||
// END INVENTORY HOLDER //
|
||||
case WOLF:
|
||||
case OCELOT:
|
||||
case "WOLF":
|
||||
case "OCELOT":
|
||||
restoreTameable((Tameable) entity);
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
// END AGEABLE //
|
||||
case SHEEP:
|
||||
case "SHEEP":
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (this.dataByte == 1) {
|
||||
sheep.setSheared(true);
|
||||
@ -604,25 +607,25 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
restoreAgeable(sheep);
|
||||
restoreLiving(sheep);
|
||||
return sheep;
|
||||
case VILLAGER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case TURTLE:
|
||||
case POLAR_BEAR:
|
||||
case MUSHROOM_COW:
|
||||
case PIG:
|
||||
case "VILLAGER":
|
||||
case "CHICKEN":
|
||||
case "COW":
|
||||
case "TURTLE":
|
||||
case "POLAR_BEAR":
|
||||
case "MUSHROOM_COW":
|
||||
case "PIG":
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
// END AGEABLE //
|
||||
case RABBIT:
|
||||
case "RABBIT":
|
||||
if (this.dataByte != 0) {
|
||||
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
|
||||
}
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case ARMOR_STAND:
|
||||
case "ARMOR_STAND":
|
||||
// CHECK positions
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
if (this.inventory[0] != null) {
|
||||
@ -688,42 +691,45 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
}
|
||||
restoreLiving(stand);
|
||||
return stand;
|
||||
case BAT:
|
||||
case "BAT":
|
||||
if (this.dataByte != 0) {
|
||||
((Bat) entity).setAwake(true);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case ENDER_DRAGON:
|
||||
case "ENDER_DRAGON":
|
||||
if (this.dataByte != 0) {
|
||||
((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case ENDERMITE:
|
||||
case GHAST:
|
||||
case MAGMA_CUBE:
|
||||
case SQUID:
|
||||
case PIG_ZOMBIE:
|
||||
case ZOMBIE:
|
||||
case WITHER:
|
||||
case WITCH:
|
||||
case SPIDER:
|
||||
case CAVE_SPIDER:
|
||||
case SILVERFISH:
|
||||
case GIANT:
|
||||
case ENDERMAN:
|
||||
case CREEPER:
|
||||
case BLAZE:
|
||||
case SNOWMAN:
|
||||
case SHULKER:
|
||||
case GUARDIAN:
|
||||
case ELDER_GUARDIAN:
|
||||
case SKELETON:
|
||||
case WITHER_SKELETON:
|
||||
case "ENDERMITE":
|
||||
case "GHAST":
|
||||
case "MAGMA_CUBE":
|
||||
case "SQUID":
|
||||
case "PIG_ZOMBIE":
|
||||
case "HOGLIN":
|
||||
case "PIGLIN":
|
||||
case "ZOMBIFIED_PIGLIN":
|
||||
case "ZOMBIE":
|
||||
case "WITHER":
|
||||
case "WITCH":
|
||||
case "SPIDER":
|
||||
case "CAVE_SPIDER":
|
||||
case "SILVERFISH":
|
||||
case "GIANT":
|
||||
case "ENDERMAN":
|
||||
case "CREEPER":
|
||||
case "BLAZE":
|
||||
case "SNOWMAN":
|
||||
case "SHULKER":
|
||||
case "GUARDIAN":
|
||||
case "ELDER_GUARDIAN":
|
||||
case "SKELETON":
|
||||
case "WITHER_SKELETON":
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case IRON_GOLEM:
|
||||
case "IRON_GOLEM":
|
||||
if (this.dataByte != 0) {
|
||||
((IronGolem) entity).setPlayerCreated(true);
|
||||
}
|
||||
|
@ -100,15 +100,15 @@ public class EntitySpawnListener implements Listener {
|
||||
if (!originWorld.equals(world)) {
|
||||
if (!ignoreTP) {
|
||||
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
|
||||
if (entity.getType() == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ignoreTP = true;
|
||||
PaperLib.teleportAsync(entity, origin);
|
||||
} finally {
|
||||
ignoreTP = false;
|
||||
}
|
||||
if (entity.getType() == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
if (entity.getLocation().getWorld().equals(world)) {
|
||||
entity.remove();
|
||||
}
|
||||
|
@ -31,8 +31,11 @@ import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
|
||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.command.Command;
|
||||
import com.plotsquared.core.command.MainCommand;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
@ -56,6 +59,12 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Events specific to Paper. Some toit nups here
|
||||
*/
|
||||
@ -270,7 +279,7 @@ public class PaperListener implements Listener {
|
||||
}
|
||||
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
||||
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
||||
final PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||
final PlotPlayer<?> plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||
Captions.TILE_ENTITY_CAP_REACHED.send(plotPlayer, Settings.Chunk_Processor.MAX_TILES);
|
||||
event.setCancelled(true);
|
||||
event.setBuild(false);
|
||||
@ -299,11 +308,50 @@ public class PaperListener implements Listener {
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
||||
if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
|
||||
return;
|
||||
}
|
||||
String buffer = event.getBuffer();
|
||||
if (!(event.getSender() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) {
|
||||
return;
|
||||
}
|
||||
if (buffer.startsWith("/")) {
|
||||
buffer = buffer.substring(1);
|
||||
}
|
||||
final String[] unprocessedArgs = buffer.split(Pattern.quote(" "));
|
||||
if (unprocessedArgs.length == 1) {
|
||||
return; // We don't do anything in this case
|
||||
} else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES
|
||||
.contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
|
||||
return;
|
||||
}
|
||||
final String[] args = new String[unprocessedArgs.length - 1];
|
||||
System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
|
||||
try {
|
||||
final PlotPlayer<?> player = BukkitUtil.getPlayer((Player) event.getSender());
|
||||
final Collection<Command> objects = MainCommand.getInstance().tab(player, args, buffer.endsWith(" "));
|
||||
if (objects == null) {
|
||||
return;
|
||||
}
|
||||
final List<String> result = new ArrayList<>();
|
||||
for (final com.plotsquared.core.command.Command o : objects) {
|
||||
result.add(o.toString());
|
||||
}
|
||||
event.setCompletions(result);
|
||||
event.setHandled(true);
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.destroystokyo.paper.MaterialTags;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||
@ -104,10 +105,8 @@ import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
import com.plotsquared.core.util.RegExUtil;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import io.papermc.lib.PaperLib;
|
||||
@ -179,6 +178,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
@ -216,7 +216,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -254,8 +253,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
int x = bloc.getBlockX();
|
||||
int z = bloc.getBlockZ();
|
||||
int distance = Bukkit.getViewDistance() * 16;
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer player = entry.getValue();
|
||||
|
||||
for (final PlotPlayer<?> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
Location location = player.getLocation();
|
||||
if (location.getWorld().equals(world)) {
|
||||
if (16 * Math.abs(location.getX() - x) / 16 > distance
|
||||
@ -315,7 +314,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Location location = BukkitUtil.getLocation(e.getEntity());
|
||||
if (location.isPlotArea()) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity());
|
||||
PlotPlayer<Player> player = BukkitUtil.getPlayer((Player) e.getEntity());
|
||||
Plot plot = player.getCurrentPlot();
|
||||
if (plot != null) {
|
||||
if (!plot.isAdded(player.getUUID())) {
|
||||
@ -352,6 +351,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
if (!plot.getFlag(RedstoneFlag.class)) {
|
||||
event.setNewCurrent(0);
|
||||
plot.debug("Redstone event was cancelled because redstone = false");
|
||||
return;
|
||||
}
|
||||
if (Settings.Redstone.DISABLE_OFFLINE) {
|
||||
@ -360,31 +360,35 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (plot.isMerged()) {
|
||||
disable = true;
|
||||
for (UUID owner : plot.getOwners()) {
|
||||
if (UUIDHandler.getPlayer(owner) != null) {
|
||||
if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner) != null) {
|
||||
disable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
disable = UUIDHandler.getPlayer(plot.guessOwner()) == null;
|
||||
disable =
|
||||
PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs())
|
||||
== null;
|
||||
}
|
||||
}
|
||||
if (disable) {
|
||||
for (UUID trusted : plot.getTrusted()) {
|
||||
if (UUIDHandler.getPlayer(trusted) != null) {
|
||||
if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(trusted) != null) {
|
||||
disable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (disable) {
|
||||
event.setNewCurrent(0);
|
||||
plot.debug(
|
||||
"Redstone event was cancelled because no trusted player was in the plot");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Settings.Redstone.DISABLE_UNOCCUPIED) {
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
if (plot.equals(entry.getValue().getCurrentPlot())) {
|
||||
for (final PlotPlayer<?> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
if (plot.equals(player.getCurrentPlot())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -407,6 +411,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
if (!plot.getFlag(RedstoneFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Prevented comparator update because redstone = false");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -429,6 +434,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
if (plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Prevented block physics because disable-physics = true");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -466,6 +472,8 @@ public class PlayerEvents extends PlotListener 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");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -487,7 +495,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
@ -508,7 +516,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Plot plot = area.getPlot(location);
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_UNOWNED)) {
|
||||
entity.remove();
|
||||
@ -550,7 +558,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
PlotPlayer<Player> plotPlayer = BukkitUtil.getPlayer(player);
|
||||
Location location = plotPlayer.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -638,17 +646,28 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPreLoin(final AsyncPlayerPreLoginEvent event) {
|
||||
final UUID uuid;
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
uuid = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + event.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
} else {
|
||||
uuid = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
} else {
|
||||
uuid = event.getUniqueId();
|
||||
}
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().storeImmediately(event.getName(), uuid);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onConnect(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
UUIDHandler.getPlayers().remove(player.getName());
|
||||
BukkitUtil.removePlayer(player.getName());
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
// Now
|
||||
String name = pp.getName();
|
||||
StringWrapper sw = new StringWrapper(name);
|
||||
UUID uuid = pp.getUUID();
|
||||
UUIDHandler.add(sw, uuid);
|
||||
BukkitUtil.removePlayer(player.getUniqueId());
|
||||
final PlotPlayer<Player> pp = BukkitUtil.getPlayer(player);
|
||||
|
||||
Location location = pp.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -687,14 +706,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void playerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer(player);
|
||||
PlotSquared.get().getEventDispatcher().doRespawnTask(pp);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onTeleport(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
|
||||
org.bukkit.Location to = event.getTo();
|
||||
//noinspection ConstantConditions
|
||||
@ -804,7 +823,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
int x2;
|
||||
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
// Cancel teleport
|
||||
TaskManager.TELEPORT_QUEUE.remove(pp.getName());
|
||||
// Set last location
|
||||
@ -864,7 +883,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
int z2;
|
||||
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
// Cancel teleport
|
||||
TaskManager.TELEPORT_QUEUE.remove(pp.getName());
|
||||
// Set last location
|
||||
@ -928,7 +947,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||
Location location = plotPlayer.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -954,8 +973,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Set<Player> recipients = event.getRecipients();
|
||||
recipients.clear();
|
||||
Set<Player> spies = new HashSet<>();
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer pp = entry.getValue();
|
||||
for (final PlotPlayer<?> pp : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
if (pp.getAttribute("chatspy")) {
|
||||
spies.add(((BukkitPlayer) pp).player);
|
||||
} else {
|
||||
@ -979,9 +997,6 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
.replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender)
|
||||
.replace("%msg%", message);
|
||||
for (Player player : spies) {
|
||||
if (player.equals(event.getPlayer())) {
|
||||
continue;
|
||||
}
|
||||
player.sendMessage(spyMessage);
|
||||
}
|
||||
}
|
||||
@ -997,7 +1012,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot != null) {
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
if (event.getBlock().getY() == 0) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
|
||||
@ -1046,7 +1061,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
return;
|
||||
}
|
||||
@ -1106,6 +1121,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
plot.debug("Explosion was cancelled because explosion = false");
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
@ -1114,7 +1131,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWorldChanged(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
// Delete last location
|
||||
Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
||||
pp.deleteMeta(PlotPlayer.META_LOCATION);
|
||||
@ -1150,6 +1167,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (area != null) {
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null && plot.getFlag(MobPlaceFlag.class)) {
|
||||
plot.debug(e.getType() + " could not change block because mob-place = false");
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
@ -1177,16 +1195,18 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
if (!plot.hasOwner()) {
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
if (plot.getFlag(IceFormFlag.class)) {
|
||||
plot.debug("Ice could not be formed because ice-form = false");
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
if (plot.getFlag(IceFormFlag.class)) {
|
||||
plot.debug("Ice could not be formed because ice-form = false");
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
@ -1216,23 +1236,27 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
switch (event.getSource().getType()) {
|
||||
case GRASS:
|
||||
case GRASS_BLOCK:
|
||||
if (!plot.getFlag(GrassGrowFlag.class)) {
|
||||
plot.debug("Grass could not grow because grass-grow = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case MYCELIUM:
|
||||
if (!plot.getFlag(MycelGrowFlag.class)) {
|
||||
plot.debug("Mycelium could not grow because mycel-grow = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case VINE:
|
||||
if (!plot.getFlag(VineGrowFlag.class)) {
|
||||
plot.debug("Vine could not grow because vine-grow = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case KELP:
|
||||
if (!plot.getFlag(KelpGrowFlag.class)) {
|
||||
plot.debug("Kelp could not grow because kelp-grow = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
@ -1259,6 +1283,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
case SNOW:
|
||||
case SNOW_BLOCK:
|
||||
if (!plot.getFlag(SnowFormFlag.class)) {
|
||||
plot.debug("Snow could not form because snow-form = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
@ -1266,6 +1291,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
case FROSTED_ICE:
|
||||
case PACKED_ICE:
|
||||
if (!plot.getFlag(IceFormFlag.class)) {
|
||||
plot.debug("Ice could not form because ice-form = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -1297,7 +1323,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
if (Permissions
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||
return;
|
||||
@ -1305,7 +1331,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
List<BlockTypeWrapper> destroy = plot.getFlag(BreakFlag.class);
|
||||
Block block = event.getBlock();
|
||||
@ -1315,12 +1341,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||
return;
|
||||
}
|
||||
plot.debug(player.getName() + " could not break " + block.getType()
|
||||
+ " because it was not in the break flag");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
return;
|
||||
}
|
||||
@ -1343,16 +1371,19 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
switch (block.getType()) {
|
||||
case ICE:
|
||||
if (!plot.getFlag(IceMeltFlag.class)) {
|
||||
plot.debug("Ice could not melt because ice-melt = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case SNOW:
|
||||
if (!plot.getFlag(SnowMeltFlag.class)) {
|
||||
plot.debug("Snow could not melt because snow-melt = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case FARMLAND:
|
||||
if (!plot.getFlag(SoilDryFlag.class)) {
|
||||
plot.debug("Soil could not dry because soil-dry = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
@ -1371,7 +1402,13 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
case BUBBLE_CORAL_FAN:
|
||||
case FIRE_CORAL_FAN:
|
||||
case HORN_CORAL_FAN:
|
||||
case BRAIN_CORAL_WALL_FAN:
|
||||
case BUBBLE_CORAL_WALL_FAN:
|
||||
case FIRE_CORAL_WALL_FAN:
|
||||
case HORN_CORAL_WALL_FAN:
|
||||
case TUBE_CORAL_WALL_FAN:
|
||||
if (!plot.getFlag(CoralDryFlag.class)) {
|
||||
plot.debug("Coral could not dry because coral-dry = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
@ -1390,6 +1427,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (plot != null
|
||||
&& plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
|
||||
.getBlock().isLiquid()) {
|
||||
plot.debug("Liquid could now flow because liquid-flow = disabled");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1413,11 +1451,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
plot.debug(event.getBlock().getType()
|
||||
+ " could not update because disable-physics = true");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
|
||||
.getBlock().isLiquid()) {
|
||||
plot.debug("Liquid could not flow because liquid-flow = disabled");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
|
||||
@ -1671,7 +1712,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) clicker;
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp);
|
||||
if (inventory != null && event.getRawSlot() == event.getSlot()) {
|
||||
if (!inventory.onClick(event.getSlot())) {
|
||||
@ -1699,6 +1740,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
final ItemStack newStack =
|
||||
new ItemStack(newItem.getType(), newItem.getAmount());
|
||||
event.setCursor(newStack);
|
||||
plot.debug(player.getName()
|
||||
+ " could not creative-copy an item because prevent-creative-copy = true");
|
||||
}
|
||||
} else {
|
||||
PlotArea area = pp.getPlotAreaAbs();
|
||||
@ -1707,6 +1750,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
final ItemStack newStack =
|
||||
new ItemStack(newItem.getType(), newItem.getAmount());
|
||||
event.setCursor(newStack);
|
||||
plot.debug(player.getName()
|
||||
+ " could not creative-copy an item because prevent-creative-copy = true");
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -1822,7 +1867,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
EntitySpawnListener.testNether(entity);
|
||||
Plot plot = location.getPlotAbs();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
||||
if (plot == null) {
|
||||
if (!area.isRoadRespectingGlobalFlags() && !area.getFlag(MiscInteractFlag.class)
|
||||
&& !Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
||||
@ -1857,6 +1902,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.interact.other");
|
||||
e.setCancelled(true);
|
||||
plot.debug(pp.getName() + " could not interact with " + entity.getType()
|
||||
+ " bcause misc-interact = false");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1884,6 +1931,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot == null || !plot.getFlag(ExplosionFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
if (plot != null) {
|
||||
plot.debug("Explosion was cancelled because explosion = false");
|
||||
}
|
||||
}
|
||||
event.blockList().removeIf(
|
||||
blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation()))));
|
||||
@ -1893,7 +1943,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
public void onCancelledInteract(PlayerInteractEvent event) {
|
||||
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
PlotArea area = pp.getPlotAreaAbs();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1930,7 +1980,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
PlotArea area = pp.getPlotAreaAbs();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2149,6 +2199,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Falling block event was cancelled because disable-physics = true");
|
||||
return;
|
||||
}
|
||||
if (event.getTo().hasGravity()) {
|
||||
@ -2184,6 +2235,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null || !plot.getFlag(BlockBurnFlag.class)) {
|
||||
plot.debug("Block burning was cancelled because block-burn = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -2207,7 +2259,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
Plot plot = area.getOwnedPlot(location1);
|
||||
if (player != null) {
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
@ -2237,6 +2289,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (ignitingEntity != null) {
|
||||
if (!plot.getFlag(BlockIgnitionFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Block ignition was cancelled because block-ignition = false");
|
||||
return;
|
||||
}
|
||||
if (igniteCause == BlockIgniteEvent.IgniteCause.FIREBALL) {
|
||||
@ -2283,7 +2336,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -2334,7 +2387,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
|
||||
TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
pp.unregister();
|
||||
PlotListener.logout(pp.getUUID());
|
||||
}
|
||||
@ -2348,7 +2401,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -2421,7 +2474,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -2465,7 +2518,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
@ -2487,6 +2540,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_DESTROY_OTHER);
|
||||
event.setCancelled(true);
|
||||
plot.debug(p.getName()
|
||||
+ " could not break hanging entity because hanging-break = false");
|
||||
}
|
||||
}
|
||||
} else if (remover instanceof Projectile) {
|
||||
@ -2498,7 +2553,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer player = BukkitUtil.getPlayer(shooter);
|
||||
BukkitPlayer player = BukkitUtil.getPlayer(shooter);
|
||||
Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity()));
|
||||
if (plot != null) {
|
||||
if (!plot.hasOwner()) {
|
||||
@ -2515,6 +2570,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_DESTROY_OTHER);
|
||||
event.setCancelled(true);
|
||||
plot.debug(player.getName()
|
||||
+ " could not break hanging entity because hanging-break = false");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2533,7 +2590,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null && !area.isRoadRespectingGlobalFlags()) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||
@ -2616,7 +2673,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Entity attacker = event.getAttacker();
|
||||
if (attacker instanceof Player) {
|
||||
Player p = (Player) attacker;
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
|
||||
@ -2642,6 +2699,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.vehicle.break.other");
|
||||
event.setCancelled(true);
|
||||
plot.debug(pp.getName()
|
||||
+ " could not break vehicle because vehicle-break = false");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2805,7 +2864,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
player = null;
|
||||
}
|
||||
if (player != null) {
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType;
|
||||
|
||||
@ -2842,6 +2901,10 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.destroy." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName()
|
||||
+ " could not break armor stand because misc-break = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
@ -2857,6 +2920,10 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR hostile-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
||||
@ -2872,6 +2939,10 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR tamned-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
@ -2880,6 +2951,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pvp." + stub);
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@ -2893,16 +2966,20 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
||||
if (isPlot) {
|
||||
<<<<<<<HEAD if (isPlot) {
|
||||
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getFlag(AnimalAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
=======
|
||||
if (plot != null && (plot.getFlag(AnimalAttackFlag.class) || plot
|
||||
.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID()))) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR animal-attack = false");
|
||||
>>>>>>>v5 return true;
|
||||
} if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
return false;
|
||||
@ -2921,12 +2998,15 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} return true;
|
||||
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
||||
.equals(dplot.guessOwner(), vplot.guessOwner()))) {
|
||||
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||
return vplot != null && vplot.getFlag(PveFlag.class);
|
||||
}
|
||||
//disable the firework damage. too much of a headache to support at the moment.
|
||||
@ -2944,14 +3024,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
||||
public void onPlayerEggThrow (PlayerEggThrowEvent event){
|
||||
Location location = BukkitUtil.getLocation(event.getEgg().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) {
|
||||
@ -2975,14 +3055,14 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void blockCreate(BlockPlaceEvent event) {
|
||||
public void blockCreate (BlockPlaceEvent event){
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot != null) {
|
||||
if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
|
||||
@ -3012,6 +3092,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_BUILD_OTHER);
|
||||
event.setCancelled(true);
|
||||
plot.debug(
|
||||
player.getName() + " could not place " + event.getBlock().getType()
|
||||
+ " because of the place flag");
|
||||
return;
|
||||
}
|
||||
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
@ -3026,6 +3109,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
Block block = event.getBlockPlaced();
|
||||
if (block.getType().hasGravity()) {
|
||||
sendBlockChange(block.getLocation(), block.getBlockData());
|
||||
plot.debug(event.getBlock().getType()
|
||||
+ " did not fall because of disable-physics = true");
|
||||
}
|
||||
}
|
||||
} else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -3035,7 +3120,7 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onDamage (EntityDamageEvent event){
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
@ -3052,20 +3137,25 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(InvincibleFlag.class)) {
|
||||
plot.debug(event.getEntity().getName()
|
||||
+ " could not take damage because invincible = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onItemDrop(PlayerDropItemEvent event) {
|
||||
@EventHandler public void onItemDrop (PlayerDropItemEvent event){
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
<<<<<<<HEAD PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Location location = pp.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
=======
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
>>>>>>>v5 if (plot == null) {
|
||||
if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -3074,37 +3164,45 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
UUID uuid = pp.getUUID();
|
||||
if (!plot.isAdded(uuid)) {
|
||||
if (!plot.getFlag(ItemDropFlag.class)) {
|
||||
plot.debug(
|
||||
player.getName() + " could not drop item because of item-drop = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
|
||||
@EventHandler public void onItemPickup (EntityPickupItemEvent event){
|
||||
LivingEntity ent = event.getEntity();
|
||||
if (ent instanceof Player) {
|
||||
Player player = (Player) ent;
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
<<<<<<<HEAD PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Location location = pp.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) {
|
||||
=======
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
>>>>>>>v5 if (plot == null) {
|
||||
if (area.isRoadRespectingGlobalFlags() && area
|
||||
.getFlag(DropProtectionFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
UUID uuid = pp.getUUID();
|
||||
if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) {
|
||||
plot.debug(player.getName()
|
||||
+ " could not pick up item because of drop-protection = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onDeath(final PlayerDeathEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
@EventHandler public void onDeath ( final PlayerDeathEvent event){
|
||||
<<<<<<<HEAD Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -3117,8 +3215,13 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(KeepInventoryFlag.class)) {
|
||||
event.setKeepInventory(true);
|
||||
=======
|
||||
final Plot plot = BukkitUtil.getPlayer(event.getEntity()).getCurrentPlot();
|
||||
if (plot != null && plot.getFlag(KeepInventoryFlag.class)) {
|
||||
plot.debug(event.getEntity().getName()
|
||||
+ " kept their inventory because of keep-inventory = true");
|
||||
>>>>>>>v5 event.setKeepInventory(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Default Bukkit world manager. It will handle world creation by
|
||||
@ -76,4 +79,13 @@ public class BukkitWorldManager implements PlatformWorldManager<World> {
|
||||
return "bukkit";
|
||||
}
|
||||
|
||||
@Override public Collection<String> getWorlds() {
|
||||
final List<World> worlds = Bukkit.getWorlds();
|
||||
final List<String> worldNames = new ArrayList<>();
|
||||
for (final World world : worlds) {
|
||||
worldNames.add(world.getName());
|
||||
}
|
||||
return worldNames;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,12 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -58,31 +61,31 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
@Override public String getVersion() {
|
||||
return "2.4";
|
||||
return "2.5";
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer pl = PlotPlayer.get(p.getName());
|
||||
final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (identifier.startsWith("has_plot_")) {
|
||||
if (identifier.split("has_plot_").length != 2)
|
||||
identifier = identifier.substring("has_plot_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
identifier = identifier.split("has_plot_")[1];
|
||||
return pl.getPlotCount(identifier) > 0 ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("plot_count_")) {
|
||||
if (identifier.split("plot_count_").length != 2)
|
||||
identifier = identifier.substring("plot_count_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
identifier = identifier.split("plot_count_")[1];
|
||||
return String.valueOf(pl.getPlotCount(identifier));
|
||||
}
|
||||
|
||||
@ -122,7 +125,9 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
if (uid == null) {
|
||||
return "";
|
||||
}
|
||||
String name = UUIDHandler.getName(uid);
|
||||
|
||||
String name = PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
|
||||
if (name != null) {
|
||||
return name;
|
||||
@ -178,6 +183,39 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (identifier.startsWith("currentplot_localflag_")) {
|
||||
return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
|
||||
false);
|
||||
}
|
||||
if (identifier.startsWith("currentplot_flag_")) {
|
||||
return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the flag value from its name on the current plot.
|
||||
* If the flag doesn't exist it returns an empty string.
|
||||
* If the flag exists but it is not set on current plot and the parameter inherit is set to true,
|
||||
* it returns the default value.
|
||||
*
|
||||
* @param plot Current plot where the player is
|
||||
* @param flagName Name of flag to get from current plot
|
||||
* @param inherit Define if it returns only the flag set on currentplot or also inherited flag
|
||||
* @return The value of flag serialized in string
|
||||
*/
|
||||
private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
|
||||
if (flagName.isEmpty())
|
||||
return "";
|
||||
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
|
||||
if (flag == null)
|
||||
return "";
|
||||
|
||||
if (inherit) {
|
||||
return plot.getFlag(flag).toString();
|
||||
} else {
|
||||
final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
|
||||
return (plotFlag != null) ? plotFlag.getValue().toString() : "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,11 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.player;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -35,7 +37,6 @@ import com.plotsquared.core.plot.PlotWeather;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
@ -62,12 +63,11 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.CREATIVE;
|
||||
import static com.sk89q.worldedit.world.gamemode.GameModes.SPECTATOR;
|
||||
import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
|
||||
|
||||
public class BukkitPlayer extends PlotPlayer {
|
||||
public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
|
||||
private static boolean CHECK_EFFECTIVE = true;
|
||||
public final Player player;
|
||||
private boolean offline;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
@ -77,30 +77,45 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
* @param player Bukkit player instance
|
||||
*/
|
||||
public BukkitPlayer(@NotNull final Player player) {
|
||||
this.player = player;
|
||||
super.populatePersistentMetaMap();
|
||||
this(player, false);
|
||||
}
|
||||
|
||||
public BukkitPlayer(@NotNull final Player player, final boolean offline) {
|
||||
this(player, offline, true);
|
||||
}
|
||||
|
||||
public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) {
|
||||
this.player = player;
|
||||
this.offline = offline;
|
||||
if (realPlayer) {
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public Actor toActor() {
|
||||
return BukkitAdapter.adapt(player);
|
||||
}
|
||||
|
||||
@Override public Player getPlatformPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@NotNull @Override public Location getLocation() {
|
||||
final Location location = super.getLocation();
|
||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||
}
|
||||
|
||||
@NotNull @Override public UUID getUUID() {
|
||||
if (this.uuid == null) {
|
||||
this.uuid = UUIDHandler.getUUID(this);
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
} else {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
return this.uuid;
|
||||
}
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override public long getLastPlayed() {
|
||||
@ -140,8 +155,8 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(final String permission) {
|
||||
if (this.offline && EconHandler.manager != null) {
|
||||
return EconHandler.manager.hasPermission(getName(), permission);
|
||||
if (this.offline && EconHandler.getEconHandler() != null) {
|
||||
return EconHandler.getEconHandler().hasPermission(getName(), permission);
|
||||
}
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
@ -23,44 +23,46 @@
|
||||
* 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.bukkit.util.uuid;
|
||||
package com.plotsquared.bukkit.player;
|
||||
|
||||
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||
/**
|
||||
* Player manager providing {@link BukkitPlayer Bukkit players}
|
||||
*/
|
||||
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
||||
|
||||
@NotNull @Override public UUID getUUID(PlotPlayer player) {
|
||||
return ((BukkitPlayer) player).player.getUniqueId();
|
||||
@NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) {
|
||||
try {
|
||||
return getPlayer(object.getUniqueId());
|
||||
} catch (final NoSuchPlayerException exception) {
|
||||
return new BukkitPlayer(object, object.isOnline(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||
return player.getUUID();
|
||||
@Override @NotNull public BukkitPlayer createPlayer(@NotNull final UUID uuid) {
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) {
|
||||
throw new NoSuchPlayerException(uuid);
|
||||
}
|
||||
return new BukkitPlayer(player);
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(String name) {
|
||||
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
||||
@NotNull @Override public BukkitOfflinePlayer getOfflinePlayer(@NotNull final String username) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||
return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.queue.BasicLocalBlockQueue;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -50,7 +51,6 @@ import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
@ -117,9 +117,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
@Override public final void setComponents(LocalChunk lc)
|
||||
throws ExecutionException, InterruptedException {
|
||||
setBaseBlocks(lc);
|
||||
if (setBiome() && lc.biomes != null) {
|
||||
setBiomes(lc);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBaseBlocks(LocalChunk localChunk) {
|
||||
@ -165,6 +162,22 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (setBiome() && localChunk.biomes != null) {
|
||||
for (int x = 0; x < localChunk.biomes.length; x++) {
|
||||
BiomeType[] biomeZ = localChunk.biomes[x];
|
||||
if (biomeZ != null) {
|
||||
for (int z = 0; z < biomeZ.length; z++) {
|
||||
if (biomeZ[z] != null) {
|
||||
BiomeType biomeType = biomeZ[z];
|
||||
|
||||
Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
worldObj.setBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z,
|
||||
biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (isForceSync()) {
|
||||
chunkConsumer.accept(getChunk(worldObj, localChunk));
|
||||
|
@ -27,49 +27,39 @@ package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.PermHandler;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class BukkitEconHandler extends EconHandler {
|
||||
|
||||
private Economy econ;
|
||||
private Permission perms;
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
if (this.econ == null || this.perms == null) {
|
||||
setupPermissions();
|
||||
if (this.econ == null) {
|
||||
setupEconomy();
|
||||
}
|
||||
return this.econ != null && this.perms != null;
|
||||
return this.econ != null;
|
||||
}
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
this.perms = permissionProvider.getProvider();
|
||||
}
|
||||
return this.perms != null;
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
private void setupEconomy() {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> economyProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
this.econ = economyProvider.getProvider();
|
||||
}
|
||||
return this.econ != null;
|
||||
}
|
||||
|
||||
@Override public double getMoney(PlotPlayer player) {
|
||||
@Override public double getMoney(PlotPlayer<?> player) {
|
||||
double bal = super.getMoney(player);
|
||||
if (Double.isNaN(bal)) {
|
||||
return this.econ.getBalance(((BukkitPlayer) player).player);
|
||||
@ -77,11 +67,11 @@ public class BukkitEconHandler extends EconHandler {
|
||||
return bal;
|
||||
}
|
||||
|
||||
@Override public void withdrawMoney(PlotPlayer player, double amount) {
|
||||
@Override public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
||||
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@Override public void depositMoney(PlotPlayer player, double amount) {
|
||||
@Override public void depositMoney(PlotPlayer<?> player, double amount) {
|
||||
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@ -89,20 +79,19 @@ public class BukkitEconHandler extends EconHandler {
|
||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(String world, String player, String perm) {
|
||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||
/**
|
||||
* @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
|
||||
*/
|
||||
@Deprecated @Override public boolean hasPermission(String world, String player, String perm) {
|
||||
if (PlotSquared.imp().getPermissionHandler() != null) {
|
||||
return PlotSquared.imp().getPermissionHandler().hasPermission(world, player, perm);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public double getBalance(PlotPlayer player) {
|
||||
@Override public double getBalance(PlotPlayer<?> player) {
|
||||
return this.econ.getBalance(player.getName());
|
||||
}
|
||||
|
||||
public void setPermission(String world, String player, String perm, boolean value) {
|
||||
if (value) {
|
||||
this.perms.playerAdd(world, player, perm);
|
||||
} else {
|
||||
this.perms.playerRemove(world, player, perm);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.util;
|
||||
|
||||
import com.plotsquared.core.util.PermHandler;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class BukkitPermHandler extends PermHandler {
|
||||
|
||||
private Permission perms;
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
if (this.perms == null) {
|
||||
setupPermissions();
|
||||
}
|
||||
return this.perms != null;
|
||||
}
|
||||
|
||||
private void setupPermissions() {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return;
|
||||
}
|
||||
RegisteredServiceProvider<Permission> permissionProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
this.perms = permissionProvider.getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(String world, String player, String perm) {
|
||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||
}
|
||||
}
|
@ -348,7 +348,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
CuboidRegion currentPlotClear = RegionUtil
|
||||
.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.manager
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager
|
||||
.setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||
@Override public void run(ScopedLocalBlockQueue value) {
|
||||
Location min = value.getMin();
|
||||
|
@ -33,6 +33,7 @@ import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.SetupObject;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -97,7 +98,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
Bukkit.unloadWorld(world, false);
|
||||
}
|
||||
|
||||
@Override public String setupWorld(SetupObject object) {
|
||||
@Deprecated @Override public String setupWorld(SetupObject object) {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
||||
String world = object.world;
|
||||
@ -209,6 +210,119 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
return object.world;
|
||||
}
|
||||
|
||||
@Override public String setupWorld(PlotAreaBuilder builder) {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ?
|
||||
new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes();
|
||||
String world = builder.worldName();
|
||||
PlotAreaType type = builder.plotAreaType();
|
||||
String worldPath = "worlds." + builder.worldName();
|
||||
switch (type) {
|
||||
case PARTIAL: {
|
||||
if (builder.areaName() != null) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
String areaName = builder.areaName() + "-" + builder.minimumId() + "-" + builder.maximumId();
|
||||
String areaPath = "areas." + areaName;
|
||||
if (!worldSection.contains(areaPath)) {
|
||||
worldSection.createSection(areaPath);
|
||||
}
|
||||
ConfigurationSection areaSection =
|
||||
worldSection.getConfigurationSection(areaPath);
|
||||
HashMap<String, Object> options = new HashMap<>();
|
||||
for (ConfigurationNode step : steps) {
|
||||
options.put(step.getConstant(), step.getValue());
|
||||
}
|
||||
options.put("generator.type", builder.plotAreaType().toString());
|
||||
options.put("generator.terrain", builder.terrainType().toString());
|
||||
options.put("generator.plugin", builder.plotManager());
|
||||
if (builder.generatorName() != null && !builder.generatorName()
|
||||
.equals(builder.plotManager())) {
|
||||
options.put("generator.init", builder.generatorName());
|
||||
}
|
||||
for (Entry<String, Object> entry : options.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (worldSection.contains(key)) {
|
||||
Object current = worldSection.get(key);
|
||||
if (!Objects.equals(value, current)) {
|
||||
areaSection.set(key, value);
|
||||
}
|
||||
} else {
|
||||
worldSection.set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
GeneratorWrapper<?> gen = SetupUtils.generators.get(builder.generatorName());
|
||||
if (gen != null && gen.isFull()) {
|
||||
builder.generatorName(null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AUGMENTED: {
|
||||
if (!builder.plotManager().endsWith(":single")) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
}
|
||||
if (steps.length != 0) {
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
}
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.type", builder.plotAreaType().toString());
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.terrain", builder.terrainType().toString());
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.plugin", builder.plotManager());
|
||||
if (builder.generatorName() != null && !builder.generatorName()
|
||||
.equals(builder.plotManager())) {
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.init", builder.generatorName());
|
||||
}
|
||||
}
|
||||
GeneratorWrapper<?> gen = SetupUtils.generators.get(builder.generatorName());
|
||||
if (gen != null && gen.isFull()) {
|
||||
builder.generatorName(null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NORMAL: {
|
||||
if (steps.length != 0) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Objects.requireNonNull(PlotSquared.imp()).getWorldManager()
|
||||
.handleWorldCreation(builder.worldName(), builder.generatorName());
|
||||
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
return world;
|
||||
}
|
||||
|
||||
return builder.worldName();
|
||||
}
|
||||
|
||||
@Override public String getGenerator(PlotArea plotArea) {
|
||||
if (SetupUtils.generators.isEmpty()) {
|
||||
updateGenerators();
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.location.Location;
|
||||
@ -35,11 +36,11 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
@ -113,14 +114,16 @@ public class BukkitUtil extends WorldUtil {
|
||||
private static World lastWorld = null;
|
||||
|
||||
private static Player lastPlayer = null;
|
||||
private static PlotPlayer lastPlotPlayer = null;
|
||||
private static BukkitPlayer lastPlotPlayer = null;
|
||||
|
||||
public static void removePlayer(String player) {
|
||||
public static void removePlayer(UUID uuid) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
// Make sure that it's removed internally
|
||||
PlotSquared.imp().getPlayerManager().removePlayer(uuid);
|
||||
}
|
||||
|
||||
public static PlotPlayer getPlayer(@NonNull final OfflinePlayer op) {
|
||||
public static PlotPlayer<Player> getPlayer(@NonNull final OfflinePlayer op) {
|
||||
if (op.isOnline()) {
|
||||
return getPlayer(op.getPlayer());
|
||||
}
|
||||
@ -165,7 +168,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public static PlotPlayer wrapPlayer(OfflinePlayer player) {
|
||||
public static PlotPlayer<?> wrapPlayer(OfflinePlayer player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
@ -177,7 +180,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public static PlotPlayer wrapPlayer(Player player) {
|
||||
public static PlotPlayer<?> wrapPlayer(Player player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
@ -189,7 +192,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
@Override public PlotPlayer wrapPlayer(UUID uuid) {
|
||||
@Override public PlotPlayer<?> wrapPlayer(UUID uuid) {
|
||||
return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
@ -200,7 +203,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @return the number of allowed plots
|
||||
*/
|
||||
public static int getAllowedPlots(Player player) {
|
||||
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
||||
PlotPlayer<?> plotPlayer = PlotPlayer.wrap(player);
|
||||
return plotPlayer.getAllowedPlots();
|
||||
}
|
||||
|
||||
@ -226,7 +229,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return PlotPlayer.wrap(player).getPlots(world);
|
||||
return BukkitPlayer.wrap(player).getPlots(world);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,19 +267,12 @@ public class BukkitUtil extends WorldUtil {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
||||
}
|
||||
|
||||
public static PlotPlayer getPlayer(@NonNull final Player player) {
|
||||
public static BukkitPlayer getPlayer(@NonNull final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final String name = player.getName();
|
||||
final PlotPlayer plotPlayer = UUIDHandler.getPlayer(name);
|
||||
if (plotPlayer != null) {
|
||||
return plotPlayer;
|
||||
}
|
||||
lastPlotPlayer = new BukkitPlayer(player);
|
||||
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
||||
lastPlayer = player;
|
||||
return lastPlotPlayer;
|
||||
final PlayerManager<?, ?> playerManager = PlotSquared.imp().getPlayerManager();
|
||||
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
||||
}
|
||||
|
||||
public static Location getLocation(@NonNull final org.bukkit.Location location) {
|
||||
|
@ -1,167 +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.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefClass;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefConstructor;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefField;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefMethod;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
/**
|
||||
* An utility that can be used to send chunks, rather than using bukkit code
|
||||
* to do so (uses heavy NMS).
|
||||
*/
|
||||
public class SendChunk {
|
||||
|
||||
private final RefMethod methodGetHandlePlayer;
|
||||
private final RefMethod methodGetHandleChunk;
|
||||
private final RefConstructor mapChunk;
|
||||
private final RefField connection;
|
||||
private final RefMethod send;
|
||||
private final RefMethod methodInitLighting;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
|
||||
RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
||||
this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||
this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
|
||||
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||
this.connection = classEntityPlayer.getField("playerConnection");
|
||||
RefClass classPacket = getRefClass("{nms}.Packet");
|
||||
RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
||||
this.send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
|
||||
}
|
||||
|
||||
public void sendChunk(Collection<Chunk> input) {
|
||||
HashSet<Chunk> chunks = new HashSet<>(input);
|
||||
HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
||||
int view = Bukkit.getServer().getViewDistance();
|
||||
for (Chunk chunk : chunks) {
|
||||
String world = chunk.getWorld().getName();
|
||||
ArrayList<Chunk> list = map.computeIfAbsent(world, k -> new ArrayList<>());
|
||||
list.add(chunk);
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
}
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer pp = entry.getValue();
|
||||
Plot plot = pp.getCurrentPlot();
|
||||
Location location = null;
|
||||
String world;
|
||||
if (plot != null) {
|
||||
world = plot.getWorldName();
|
||||
} else {
|
||||
location = pp.getLocation();
|
||||
world = location.getWorld();
|
||||
}
|
||||
ArrayList<Chunk> list = map.get(world);
|
||||
if (list == null) {
|
||||
continue;
|
||||
}
|
||||
if (location == null) {
|
||||
location = pp.getLocation();
|
||||
}
|
||||
int chunkX = location.getX() >> 4;
|
||||
int chunkZ = location.getZ() >> 4;
|
||||
Player player = ((BukkitPlayer) pp).player;
|
||||
Object entity = this.methodGetHandlePlayer.of(player).call();
|
||||
|
||||
for (Chunk chunk : list) {
|
||||
int dx = Math.abs(chunkX - chunk.getX());
|
||||
int dz = Math.abs(chunkZ - chunk.getZ());
|
||||
if ((dx > view) || (dz > view)) {
|
||||
continue;
|
||||
}
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
chunks.remove(chunk);
|
||||
Object con = this.connection.of(entity).get();
|
||||
Object packet = null;
|
||||
try {
|
||||
packet = this.mapChunk.create(c, 65535);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (packet == null) {
|
||||
PlotSquared.debug("Error with PacketPlayOutMapChunk reflection.");
|
||||
}
|
||||
this.send.of(con).call(packet);
|
||||
}
|
||||
}
|
||||
for (final Chunk chunk : chunks) {
|
||||
TaskManager.runTask(() -> {
|
||||
try {
|
||||
chunk.unload(true);
|
||||
} catch (Throwable ignored) {
|
||||
String worldName = chunk.getWorld().getName();
|
||||
PlotSquared.debug(
|
||||
"$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";" + chunk
|
||||
.getZ());
|
||||
PlotSquared.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||
PlotSquared.debug("$3 - $4" + worldName + "/level.dat or " + worldName
|
||||
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void sendChunk(String worldName, Collection<BlockVector2> chunkLocations) {
|
||||
World myWorld = Bukkit.getWorld(worldName);
|
||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
for (BlockVector2 loc : chunkLocations) {
|
||||
if (myWorld.isChunkLoaded(loc.getX(), loc.getZ())) {
|
||||
PaperLib.getChunkAtAsync(myWorld, loc.getX(), loc.getZ()).thenAccept(chunks::add);
|
||||
}
|
||||
}
|
||||
sendChunk(chunks);
|
||||
}
|
||||
}
|
@ -1,289 +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.bukkit.util.uuid;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
||||
|
||||
public FileUUIDHandler(UUIDWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override public boolean startCaching(Runnable whenDone) {
|
||||
return super.startCaching(whenDone) && cache(whenDone);
|
||||
}
|
||||
|
||||
private Tag readTag(File file) throws IOException {
|
||||
// Don't chain the creation of the GZIP stream and the NBT stream, because their
|
||||
// constructors may throw an IOException.
|
||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
|
||||
NBTInputStream nbtInputStream = new NBTInputStream(gzipInputStream)) {
|
||||
return nbtInputStream.readNamedTag().getTag();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean cache(final Runnable whenDone) {
|
||||
final File container = Bukkit.getWorldContainer();
|
||||
List<World> worlds = Bukkit.getWorlds();
|
||||
final String world;
|
||||
if (worlds.isEmpty()) {
|
||||
world = "world";
|
||||
} else {
|
||||
world = worlds.get(0).getName();
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
PlotSquared.debug(Captions.PREFIX + "Starting player data caching for: " + world);
|
||||
File uuidFile = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (uuidFile.exists()) {
|
||||
try {
|
||||
List<String> lines =
|
||||
Files.readAllLines(uuidFile.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
String[] split = line.split("\\|");
|
||||
String name = split[0];
|
||||
if (name.isEmpty() || (name.length() > 16) || !StringMan
|
||||
.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
if (uuid == null) {
|
||||
continue;
|
||||
}
|
||||
UUIDHandler.add(new StringWrapper(name), uuid);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<>());
|
||||
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
||||
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
||||
PlotSquared.debug("Fast mode UUID caching enabled!");
|
||||
File playerDataFolder = new File(container, world + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
boolean check = all.isEmpty();
|
||||
if (dat != null) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if (check || all.remove(uuid)) {
|
||||
File file = new File(playerDataFolder, current);
|
||||
CompoundTag compound = (CompoundTag) readTag(file);
|
||||
if (!compound.containsKey("bukkit")) {
|
||||
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||
+ ".dat) does not contain the the key \"bukkit\"");
|
||||
} else {
|
||||
Map<String, Tag> compoundMap = compound.getValue();
|
||||
CompoundTag bukkit = (CompoundTag) compoundMap.get("bukkit");
|
||||
Map<String, Tag> bukkitMap = bukkit.getValue();
|
||||
String name =
|
||||
(String) bukkitMap.get("lastKnownName").getValue();
|
||||
long last = (long) bukkitMap.get("lastPlayed").getValue();
|
||||
long first = (long) bukkitMap.get("firstPlayed").getValue();
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
ExpireManager.IMP.storeAccountAge(uuid, last - first);
|
||||
}
|
||||
toAdd.put(new StringWrapper(name), uuid);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PlotSquared.debug(Captions.PREFIX + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
if (all.isEmpty()) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
PlotSquared.debug(
|
||||
"Failed to cache: " + all.size() + " uuids - slowly processing all files");
|
||||
}
|
||||
}
|
||||
HashSet<String> worlds1 = Sets.newHashSet(world, "world");
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
File playerDataFolder = null;
|
||||
for (String worldName : worlds1) {
|
||||
// Getting UUIDs
|
||||
playerDataFolder = new File(container, worldName + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
if ((dat != null) && (dat.length != 0)) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
PlotSquared.debug(Captions.PREFIX + "Invalid PlayerData: " + current);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Getting names
|
||||
File playersFolder = new File(worldName + File.separator + "players");
|
||||
dat = playersFolder.list(new DatFileFilter());
|
||||
if ((dat != null) && (dat.length != 0)) {
|
||||
for (String current : dat) {
|
||||
names.add(current.replaceAll(".dat$", ""));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
try {
|
||||
File file =
|
||||
new File(playerDataFolder + File.separator + uuid.toString() + ".dat");
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
CompoundTag compound = (CompoundTag) readTag(file);
|
||||
if (!compound.containsKey("bukkit")) {
|
||||
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||
+ ".dat) does not contain the the key \"bukkit\"");
|
||||
} else {
|
||||
Map<String, Tag> compoundMap = compound.getValue();
|
||||
CompoundTag bukkit = (CompoundTag) compoundMap.get("bukkit");
|
||||
Map<String, Tag> bukkitMap = bukkit.getValue();
|
||||
String name = (String) bukkitMap.get("lastKnownName").getValue();
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
if (!toAdd.containsKey(wrap)) {
|
||||
long last = (long) bukkitMap.get("lastPlayed").getValue();
|
||||
long first = (long) bukkitMap.get("firstPlayed").getValue();
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase()
|
||||
.equals(name)) {
|
||||
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
} else {
|
||||
long most = (long) compoundMap.get("UUIDMost").getValue();
|
||||
long least = (long) compoundMap.get("UUIDLeast").getValue();
|
||||
uuid = new UUID(most, least);
|
||||
}
|
||||
}
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
ExpireManager.IMP.storeAccountAge(uuid, last - first);
|
||||
}
|
||||
toAdd.put(wrap, uuid);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (String name : names) {
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
StringWrapper nameWrap = new StringWrapper(name);
|
||||
toAdd.put(nameWrap, uuid);
|
||||
}
|
||||
|
||||
if (getUUIDMap().isEmpty()) {
|
||||
for (OfflinePlotPlayer offlinePlotPlayer : FileUUIDHandler.this.uuidWrapper
|
||||
.getOfflinePlayers()) {
|
||||
long last = offlinePlotPlayer.getLastPlayed();
|
||||
if (last != 0) {
|
||||
String name = offlinePlotPlayer.getName();
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
if (!toAdd.containsKey(wrap)) {
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(offlinePlotPlayer);
|
||||
if (toAdd.containsValue(uuid)) {
|
||||
StringWrapper duplicate = toAdd.inverse().get(uuid);
|
||||
PlotSquared.debug(
|
||||
"The UUID: " + uuid.toString() + " is already mapped to "
|
||||
+ duplicate
|
||||
+ "\n It cannot be added to the Map with a key of " + wrap);
|
||||
}
|
||||
toAdd.putIfAbsent(wrap, uuid);
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
TaskManager.runTask(ifFetch);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,131 +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.bukkit.util.uuid;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
private final Object[] arg = new Object[0];
|
||||
private Method getOnline = null;
|
||||
|
||||
public OfflineUUIDWrapper() {
|
||||
try {
|
||||
this.getOnline = Server.class.getMethod("getOnlinePlayers");
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull @Override public UUID getUUID(PlotPlayer player) {
|
||||
return UUID
|
||||
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||
return UUID
|
||||
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
public UUID getUUID(OfflinePlayer player) {
|
||||
return UUID
|
||||
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||
String name = null;
|
||||
if (map.containsKey(uuid)) {
|
||||
name = map.get(uuid).value;
|
||||
}
|
||||
if (name != null) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
||||
if (op.hasPlayedBefore()) {
|
||||
return new BukkitOfflinePlayer(op);
|
||||
}
|
||||
}
|
||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||
if (getUUID(player).equals(uuid)) {
|
||||
return new BukkitOfflinePlayer(player);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Player[] getOnlinePlayers() {
|
||||
if (this.getOnline == null) {
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[0]);
|
||||
}
|
||||
try {
|
||||
Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
|
||||
if (players instanceof Player[]) {
|
||||
return (Player[]) players;
|
||||
} else {
|
||||
@SuppressWarnings("unchecked") Collection<? extends Player> p =
|
||||
(Collection<? extends Player>) players;
|
||||
return p.toArray(new Player[0]);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
|
||||
PlotSquared.debug("Failed to resolve online players");
|
||||
this.getOnline = null;
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||
return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
}
|
@ -1,270 +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.bukkit.util.uuid;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.database.SQLite;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||
|
||||
final int MAX_REQUESTS = 500;
|
||||
private final String PROFILE_URL =
|
||||
"https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
private final JSONParser jsonParser = new JSONParser();
|
||||
private final SQLite sqlite;
|
||||
|
||||
public SQLUUIDHandler(UUIDWrapper wrapper) {
|
||||
super(wrapper);
|
||||
this.sqlite =
|
||||
new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db"));
|
||||
try {
|
||||
this.sqlite.openConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try (PreparedStatement stmt = getConnection().prepareStatement(
|
||||
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid, username))")) {
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
startCaching(null);
|
||||
}
|
||||
|
||||
private Connection getConnection() {
|
||||
synchronized (this.sqlite) {
|
||||
return this.sqlite.getConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean startCaching(final Runnable whenDone) {
|
||||
if (!super.startCaching(whenDone)) {
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<>());
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
||||
ResultSet resultSet = statement.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
StringWrapper username = new StringWrapper(resultSet.getString("username"));
|
||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||
toAdd.put(new StringWrapper(username.value), uuid);
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
// This should be called as long as there are some unknown plots
|
||||
final ArrayDeque<UUID> toFetch = new ArrayDeque<>();
|
||||
for (UUID u : UUIDHandler.getAllUUIDS()) {
|
||||
if (!uuidExists(u)) {
|
||||
toFetch.add(u);
|
||||
}
|
||||
}
|
||||
if (toFetch.isEmpty()) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
||||
fileHandler.startCaching(() -> {
|
||||
// If the file based UUID handler didn't cache it, then we can't cache offline mode
|
||||
// Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
while (!toFetch.isEmpty()) {
|
||||
try {
|
||||
for (int i = 0; i < Math.min(MAX_REQUESTS, toFetch.size()); i++) {
|
||||
UUID uuid = toFetch.pop();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(
|
||||
SQLUUIDHandler.this.PROFILE_URL + uuid.toString()
|
||||
.replace("-", "")).openConnection();
|
||||
try (InputStream con = connection.getInputStream()) {
|
||||
InputStreamReader reader = new InputStreamReader(con);
|
||||
JSONObject response =
|
||||
(JSONObject) SQLUUIDHandler.this.jsonParser
|
||||
.parse(reader);
|
||||
String name = (String) response.get("name");
|
||||
if (name != null) {
|
||||
add(new StringWrapper(name), uuid);
|
||||
}
|
||||
}
|
||||
connection.disconnect();
|
||||
}
|
||||
} catch (IOException | ParseException e) {
|
||||
PlotSquared.debug(
|
||||
"Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
||||
}
|
||||
try {
|
||||
//Mojang allows requests every 10 minutes according to https://wiki.vg/Mojang_API
|
||||
//15 Minutes is chosen here since system timers are not always precise
|
||||
//and it should provide enough time where Mojang won't block requests.
|
||||
TimeUnit.MINUTES.sleep(15);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
throw new SQLUUIDHandlerException("Couldn't select :s", e);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||
PlotSquared.debug(Captions.PREFIX + "UUID for '" + name
|
||||
+ "' was null. We'll cache this from the Mojang servers!");
|
||||
if (ifFetch == null) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
String body = JSONArray.toJSONString(Collections.singletonList(name));
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser
|
||||
.parse(new InputStreamReader(connection.getInputStream()));
|
||||
JSONObject jsonProfile = (JSONObject) array.get(0);
|
||||
String id = (String) jsonProfile.get("id");
|
||||
String name1 = (String) jsonProfile.get("name");
|
||||
ifFetch.value = UUID.fromString(
|
||||
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16)
|
||||
+ '-' + id.substring(16, 20) + '-' + id.substring(20, 32));
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
TaskManager.runTask(ifFetch);
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void handleShutdown() {
|
||||
super.handleShutdown();
|
||||
try {
|
||||
getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new SQLUUIDHandlerException("Couldn't close database connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is useful for name changes
|
||||
*/
|
||||
@Override public void rename(final UUID uuid, final StringWrapper name) {
|
||||
super.rename(uuid, name);
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
||||
statement.setString(1, name.value);
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.execute();
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean add(final StringWrapper name, final UUID uuid) {
|
||||
// Ignoring duplicates
|
||||
if (super.add(name, uuid)) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, name.toString());
|
||||
statement.execute();
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class SQLUUIDHandlerException extends RuntimeException {
|
||||
|
||||
SQLUUIDHandlerException(String s, Throwable c) {
|
||||
super("SQLUUIDHandler caused an exception: " + s, c);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.alpenblock.bungeeperms.BungeePerms;
|
||||
import net.alpenblock.bungeeperms.io.UUIDPlayerDB;
|
||||
|
||||
/**
|
||||
* UUID service that uses the BungeePerms API
|
||||
*/
|
||||
public class BungeePermsUUIDService implements UUIDService {
|
||||
|
||||
private final BungeePerms bp;
|
||||
|
||||
public BungeePermsUUIDService() {
|
||||
final RegisteredServiceProvider<BungeePerms> provider = Bukkit.getServicesManager().getRegistration(BungeePerms.class);
|
||||
if (provider != null) {
|
||||
this.bp = provider.getProvider();
|
||||
} else {
|
||||
throw new IllegalStateException("BungeePerms is not available");
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UUIDPlayerDB uuiddb = BungeePerms.getInstance().getPermissionsManager().getUUIDPlayerDB();
|
||||
for (final UUID uuid : uuids) {
|
||||
try {
|
||||
final String username = uuiddb.getPlayerName(uuid);
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
final UUIDPlayerDB uuiddb = BungeePerms.getInstance().getPermissionsManager().getUUIDPlayerDB();
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
final UUID uuid = uuiddb.getUUID(username);
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service using the EssentialsX API
|
||||
*/
|
||||
public class EssentialsUUIDService implements UUIDService {
|
||||
|
||||
private final Essentials essentials;
|
||||
|
||||
public EssentialsUUIDService() {
|
||||
this.essentials = Essentials.getPlugin(Essentials.class);
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
final User user = essentials.getUser(username);
|
||||
if (user != null) {
|
||||
final UUID uuid = user.getConfigUUID();
|
||||
if (uuid != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
}
|
||||
} catch (final Exception ignored){}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service that uses the LuckPerms API
|
||||
*/
|
||||
public class LuckPermsUUIDService implements UUIDService {
|
||||
|
||||
private final LuckPerms luckPerms;
|
||||
|
||||
public LuckPermsUUIDService() {
|
||||
final RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
|
||||
if (provider != null) {
|
||||
this.luckPerms = provider.getProvider();
|
||||
} else {
|
||||
throw new IllegalStateException("LuckPerms not available");
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final UUID uuid : uuids) {
|
||||
try {
|
||||
final String username = userManager.lookupUsername(uuid).get();
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
final UUID uuid = userManager.lookupUniqueId(username).get();
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service that use {@link org.bukkit.OfflinePlayer offline players}
|
||||
*/
|
||||
public class OfflinePlayerUUIDService implements UUIDService {
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE || Bukkit.getWorlds().isEmpty()) {
|
||||
return Collections.emptyList(); // This is useless now
|
||||
}
|
||||
final List<UUIDMapping> wrappers = new ArrayList<>(uuids.size());
|
||||
for (final UUID uuid : uuids) {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
try {
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
wrappers.add(new UUIDMapping(uuid, offlinePlayer.getName()));
|
||||
}
|
||||
} catch (final Exception ignored) {} /* This can be safely ignored. If this happens, it is
|
||||
probably because it's called before the worlds have
|
||||
been loaded. This is bad, but does not break anything */
|
||||
}
|
||||
return wrappers;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
username.toLowerCase()).getBytes(Charsets.UTF_8)), username));
|
||||
} else {
|
||||
wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
username).getBytes(Charsets.UTF_8)), username));
|
||||
}
|
||||
} else {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return wrappers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service that uses the Paper profile API
|
||||
*/
|
||||
public class PaperUUIDService implements UUIDService {
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
for (final UUID uuid : uuids) {
|
||||
final PlayerProfile playerProfile = Bukkit.createProfile(uuid);
|
||||
if ((playerProfile.isComplete() || playerProfile.completeFromCache()) && playerProfile.getId() != null) {
|
||||
mappings.add(new UUIDMapping(playerProfile.getId(), playerProfile.getName()));
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
final PlayerProfile playerProfile = Bukkit.createProfile(username);
|
||||
if ((playerProfile.isComplete() || playerProfile.completeFromCache()) && playerProfile.getId() != null) {
|
||||
mappings.add(new UUIDMapping(playerProfile.getId(), playerProfile.getName()));
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.database.SQLite;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* UUID service that uses the (legacy) SQL UUID cache
|
||||
*/
|
||||
public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping>> {
|
||||
|
||||
private final SQLite sqlite;
|
||||
|
||||
public SQLiteUUIDService(final String fileName) {
|
||||
this.sqlite =
|
||||
new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), fileName));
|
||||
try {
|
||||
this.sqlite.openConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try (PreparedStatement stmt = getConnection().prepareStatement(
|
||||
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() {
|
||||
synchronized (this.sqlite) {
|
||||
return this.sqlite.getConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
|
||||
for (final UUID uuid : uuids) {
|
||||
statement.setString(1, uuid.toString());
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
mappings.add(new UUIDMapping(uuid, resultSet.getString("username")));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
|
||||
for (final String username : usernames) {
|
||||
statement.setString(1, username);
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")),
|
||||
username));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override public void accept(final List<UUIDMapping> uuidWrappers) {
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
|
||||
for (final UUIDMapping mapping : uuidWrappers) {
|
||||
statement.setString(1, mapping.getUuid().toString());
|
||||
statement.setString(2, mapping.getUsername());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the entire cache at once
|
||||
*
|
||||
* @return All read mappings
|
||||
*/
|
||||
@NotNull public List<UUIDMapping> getAll() {
|
||||
final List<UUIDMapping> mappings = new LinkedList<>();
|
||||
try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")), resultSet.getString("username")));
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.bukkit.uuid;
|
||||
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import com.sk89q.squirrelid.Profile;
|
||||
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
|
||||
import com.sk89q.squirrelid.resolver.ProfileService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service using SquirrelID
|
||||
*/
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class SquirrelIdUUIDService implements UUIDService {
|
||||
|
||||
private final ProfileService profileService;
|
||||
private final RateLimiter rateLimiter;
|
||||
|
||||
/**
|
||||
* Create a new SquirrelID UUID service
|
||||
*
|
||||
* @param rateLimit Mojangs rate limit is 600 requests per 10 minutes.
|
||||
* This parameter specifies how many of those requests
|
||||
* we can use before our internal rate limit kicks in.
|
||||
*/
|
||||
public SquirrelIdUUIDService(final int rateLimit) {
|
||||
this.profileService = HttpRepositoryService.forMinecraft();
|
||||
// RateLimiter uses request per seconds. The constructor
|
||||
// parameter rateLimit is requests per 600 seconds
|
||||
this.rateLimiter = RateLimiter.create(rateLimit / 600.0D);
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(uuids.size());
|
||||
this.rateLimiter.acquire(uuids.size());
|
||||
try {
|
||||
for (final Profile profile : this.profileService.findAllById(uuids)) {
|
||||
results.add(new UUIDMapping(profile.getUniqueId(), profile.getName()));
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(usernames.size());
|
||||
this.rateLimiter.acquire(usernames.size());
|
||||
try {
|
||||
for (final Profile profile : this.profileService.findAllByName(usernames)) {
|
||||
results.add(new UUIDMapping(profile.getUniqueId(), profile.getName()));
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
@ -5,8 +5,8 @@ version: "${version}"
|
||||
load: STARTUP
|
||||
description: "Easy, yet powerful Plot World generation and management."
|
||||
authors: [Citymonstret, Empire92, MattBDev, dordsor21, NotMyFault, SirYwell]
|
||||
website: https://github.com/IntellectualSites/
|
||||
softdepend: [Vault, PlaceholderAPI]
|
||||
website: https://www.spigotmc.org/resources/77506/
|
||||
softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms]
|
||||
loadbefore: [MultiWorld, Multiverse-Core]
|
||||
depend: [WorldEdit]
|
||||
database: false
|
||||
|
@ -1,5 +1,6 @@
|
||||
repositories {
|
||||
maven { url = "https://jitpack.io" }
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
}
|
||||
def textVersion = "3.0.2"
|
||||
|
||||
@ -16,6 +17,7 @@ dependencies {
|
||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
|
||||
implementation("org.jetbrains:annotations:19.0.0")
|
||||
implementation("org.khelekore:prtree:1.7.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
@ -73,6 +75,7 @@ shadowJar {
|
||||
include(dependency("net.kyori:text-serializer-gson:3.0.2"))
|
||||
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"))
|
||||
}
|
||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||
relocate("org.json", "com.plotsquared.json") {
|
||||
|
@ -9,7 +9,7 @@
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20190722</version>
|
||||
<version>20200518</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -92,6 +92,12 @@
|
||||
<version>1.3.72</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.khelekore</groupId>
|
||||
<artifactId>prtree</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -35,22 +35,29 @@ import com.plotsquared.core.util.ChatManager;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.InventoryUtil;
|
||||
import com.plotsquared.core.util.PermHandler;
|
||||
import com.plotsquared.core.util.PlatformWorldManager;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.logger.ILogger;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IPlotMain extends ILogger {
|
||||
/**
|
||||
* PlotSquared main utility class
|
||||
*
|
||||
* @param <P> Player type
|
||||
*/
|
||||
public interface IPlotMain<P> extends ILogger {
|
||||
|
||||
/**
|
||||
* Logs a message to console.
|
||||
@ -79,7 +86,7 @@ public interface IPlotMain extends ILogger {
|
||||
* @param player The player to convert to a PlotPlayer
|
||||
* @return A PlotPlayer
|
||||
*/
|
||||
PlotPlayer wrapPlayer(Object player);
|
||||
@Nullable PlotPlayer<P> wrapPlayer(Object player);
|
||||
|
||||
/**
|
||||
* Completely shuts down the plugin.
|
||||
@ -168,11 +175,18 @@ public interface IPlotMain extends ILogger {
|
||||
boolean initWorldEdit();
|
||||
|
||||
/**
|
||||
* Gets the economy provider.
|
||||
* Gets the economy provider, if there is one
|
||||
*
|
||||
* @return the PlotSquared economy manager
|
||||
*/
|
||||
EconHandler getEconomyHandler();
|
||||
@Nullable EconHandler getEconomyHandler();
|
||||
|
||||
/**
|
||||
* Gets the permission provider, if there is one
|
||||
*
|
||||
* @return the PlotSquared permission manager
|
||||
*/
|
||||
@Nullable PermHandler getPermissionHandler();
|
||||
|
||||
/**
|
||||
* Gets the {@link QueueProvider} class.
|
||||
@ -220,12 +234,6 @@ public interface IPlotMain extends ILogger {
|
||||
*/
|
||||
void setGenerator(String world);
|
||||
|
||||
/**
|
||||
* Gets the {@link UUIDHandlerImplementation} which will cache and
|
||||
* provide UUIDs.
|
||||
*/
|
||||
UUIDHandlerImplementation initUUIDHandler();
|
||||
|
||||
/**
|
||||
* Gets the {@link InventoryUtil} class (used for implementation specific
|
||||
* inventory guis).
|
||||
@ -285,6 +293,13 @@ public interface IPlotMain extends ILogger {
|
||||
*
|
||||
* @return World manager
|
||||
*/
|
||||
@NotNull PlatformWorldManager getWorldManager();
|
||||
@NotNull PlatformWorldManager<?> getWorldManager();
|
||||
|
||||
/**
|
||||
* Get the player manager implementation for the platform
|
||||
*
|
||||
* @return Player manager
|
||||
*/
|
||||
@NotNull PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager();
|
||||
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
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.PlotFilter;
|
||||
@ -79,17 +80,18 @@ import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.logger.ILogger;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -116,6 +118,7 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -123,6 +126,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@ -137,9 +141,14 @@ public class PlotSquared {
|
||||
private static final Set<Plot> EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet());
|
||||
private static PlotSquared instance;
|
||||
// Implementation
|
||||
public final IPlotMain IMP;
|
||||
public final IPlotMain<?> IMP;
|
||||
// Current thread
|
||||
private final Thread thread;
|
||||
// UUID pipelines
|
||||
@Getter private final UUIDPipeline impromptuUUIDPipeline =
|
||||
new UUIDPipeline(Executors.newCachedThreadPool());
|
||||
@Getter private final UUIDPipeline backgroundUUIDPipeline =
|
||||
new UUIDPipeline(Executors.newSingleThreadExecutor());
|
||||
// WorldEdit instance
|
||||
public WorldEdit worldedit;
|
||||
public File styleFile;
|
||||
@ -252,15 +261,6 @@ public class PlotSquared {
|
||||
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
||||
this.IMP.registerChunkProcessor();
|
||||
}
|
||||
// create UUIDWrapper
|
||||
UUIDHandler.implementation = this.IMP.initUUIDHandler();
|
||||
if (Settings.Enabled_Components.UUID_CACHE) {
|
||||
startUuidCatching();
|
||||
} else {
|
||||
// Start these separately
|
||||
UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
|
||||
startExpiryTasks();
|
||||
}
|
||||
// Create Event utility class
|
||||
eventDispatcher = new EventDispatcher();
|
||||
// create Hybrid utility class
|
||||
@ -270,7 +270,8 @@ public class PlotSquared {
|
||||
// create setup util class
|
||||
SetupUtils.manager = this.IMP.initSetupUtils();
|
||||
// Set block
|
||||
GlobalBlockQueue.IMP = new GlobalBlockQueue(IMP.initBlockQueue(), 1);
|
||||
GlobalBlockQueue.IMP =
|
||||
new GlobalBlockQueue(IMP.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME);
|
||||
GlobalBlockQueue.IMP.runTask();
|
||||
// Set chunk
|
||||
ChunkManager.manager = this.IMP.initChunkManager();
|
||||
@ -303,8 +304,7 @@ public class PlotSquared {
|
||||
}
|
||||
// Economy
|
||||
if (Settings.Enabled_Components.ECONOMY) {
|
||||
TaskManager
|
||||
.runTask(() -> EconHandler.manager = PlotSquared.this.IMP.getEconomyHandler());
|
||||
TaskManager.runTask(() -> EconHandler.initializeEconHandler());
|
||||
}
|
||||
|
||||
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
|
||||
@ -385,11 +385,11 @@ public class PlotSquared {
|
||||
return PlotSquared.instance;
|
||||
}
|
||||
|
||||
public static IPlotMain imp() {
|
||||
if (instance != null) {
|
||||
@NotNull public static IPlotMain<?> imp() {
|
||||
if (instance != null && instance.IMP != null) {
|
||||
return instance.IMP;
|
||||
}
|
||||
return null;
|
||||
throw new IllegalStateException("Plot main implementation is missing");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -427,23 +427,6 @@ public class PlotSquared {
|
||||
}
|
||||
}
|
||||
|
||||
private void startUuidCatching() {
|
||||
TaskManager.runTaskLater(() -> {
|
||||
debug("Starting UUID caching");
|
||||
UUIDHandler.startCaching(() -> {
|
||||
UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
|
||||
forEachPlotRaw(plot -> {
|
||||
if (plot.hasOwner() && plot.temp != -1) {
|
||||
if (UUIDHandler.getName(plot.getOwnerAbs()) == null) {
|
||||
UUIDHandler.implementation.unknown.add(plot.getOwnerAbs());
|
||||
}
|
||||
}
|
||||
});
|
||||
startExpiryTasks();
|
||||
});
|
||||
}, 20);
|
||||
}
|
||||
|
||||
private void startExpiryTasks() {
|
||||
if (Settings.Enabled_Components.PLOT_EXPIRY) {
|
||||
ExpireManager.IMP = new ExpireManager();
|
||||
@ -640,17 +623,7 @@ public class PlotSquared {
|
||||
* @return Set of base Plots
|
||||
*/
|
||||
public Set<Plot> getBasePlots() {
|
||||
int size = getPlotCount();
|
||||
final Set<Plot> result = new HashSet<>(size);
|
||||
forEachPlotArea(value -> {
|
||||
for (Plot plot : value.getPlots()) {
|
||||
if (!plot.isBasePlot()) {
|
||||
continue;
|
||||
}
|
||||
result.add(plot);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(result);
|
||||
return PlotQuery.newQuery().whereBasePlot().asSet();
|
||||
}
|
||||
|
||||
public List<Plot> sortPlotsByTemp(Collection<Plot> plots) {
|
||||
@ -903,27 +876,25 @@ public class PlotSquared {
|
||||
*
|
||||
* @param filters the filter
|
||||
* @return a filtered set of plots
|
||||
* @deprecated Use {@link PlotQuery}
|
||||
*/
|
||||
public Set<Plot> getPlots(final PlotFilter... filters) {
|
||||
final HashSet<Plot> set = new HashSet<>();
|
||||
forEachPlotArea(value -> {
|
||||
for (PlotFilter filter : filters) {
|
||||
if (!filter.allowsArea(value)) {
|
||||
return;
|
||||
@Deprecated public Set<Plot> getPlots(final PlotFilter... filters) {
|
||||
final List<PlotArea> areas = new LinkedList<>();
|
||||
for (final PlotArea plotArea : this.getPlotAreas()) {
|
||||
for (final PlotFilter filter : filters) {
|
||||
if (filter.allowsArea(plotArea)) {
|
||||
areas.add(plotArea);
|
||||
}
|
||||
}
|
||||
loop:
|
||||
for (Entry<PlotId, Plot> entry2 : value.getPlotEntries()) {
|
||||
Plot plot = entry2.getValue();
|
||||
for (PlotFilter filter : filters) {
|
||||
}
|
||||
return PlotQuery.newQuery().inAreas(areas).thatPasses(plot -> {
|
||||
for (final PlotFilter filter : filters) {
|
||||
if (!filter.allowsPlot(plot)) {
|
||||
continue loop;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
set.add(plot);
|
||||
}
|
||||
});
|
||||
return set;
|
||||
return true;
|
||||
}).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -966,7 +937,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot
|
||||
*/
|
||||
public Set<Plot> getPlots(String world, String player) {
|
||||
final UUID uuid = UUIDHandler.getUUID(player, null);
|
||||
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
return getPlots(world, uuid);
|
||||
}
|
||||
|
||||
@ -978,7 +949,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotArea area, String player) {
|
||||
UUID uuid = UUIDHandler.getUUID(player, null);
|
||||
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
|
||||
return getPlots(area, uuid);
|
||||
}
|
||||
|
||||
@ -990,7 +961,7 @@ public class PlotSquared {
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(String world, PlotPlayer player) {
|
||||
return getPlots(world, player.getUUID());
|
||||
return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1001,7 +972,7 @@ public class PlotSquared {
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotArea area, PlotPlayer player) {
|
||||
return getPlots(area, player.getUUID());
|
||||
return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1012,10 +983,7 @@ public class PlotSquared {
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(String world, UUID uuid) {
|
||||
final Set<Plot> plots =
|
||||
getPlots(world).stream().filter(plot -> plot.hasOwner() && plot.isOwnerAbs(uuid))
|
||||
.collect(Collectors.toSet());
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().inWorld(world).ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1026,13 +994,7 @@ public class PlotSquared {
|
||||
* @return Set of plots
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotArea area, UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
for (Plot plot : getPlots(area)) {
|
||||
if (plot.hasOwner() && plot.isOwnerAbs(uuid)) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1047,9 +1009,7 @@ public class PlotSquared {
|
||||
}
|
||||
|
||||
public Collection<Plot> getPlots(String world) {
|
||||
final Set<Plot> set = new HashSet<>();
|
||||
forEachPlotArea(world, value -> set.addAll(value.getPlots()));
|
||||
return set;
|
||||
return PlotQuery.newQuery().inWorld(world).asCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1059,7 +1019,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotPlayer player) {
|
||||
return getPlots(player.getUUID());
|
||||
return PlotQuery.newQuery().ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
public Collection<Plot> getPlots(PlotArea area) {
|
||||
@ -1081,13 +1041,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot's owned by the player
|
||||
*/
|
||||
public Set<Plot> getPlots(final UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
forEachPlot(value -> {
|
||||
if (value.isOwnerAbs(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
public boolean hasPlot(final UUID uuid) {
|
||||
@ -1096,13 +1050,7 @@ public class PlotSquared {
|
||||
}
|
||||
|
||||
public Set<Plot> getBasePlots(final UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
forEachBasePlot(value -> {
|
||||
if (value.isOwner(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().ownedBy(uuid).whereBasePlot().asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1112,13 +1060,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot
|
||||
*/
|
||||
public Set<Plot> getPlotsAbs(final UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
forEachPlot(value -> {
|
||||
if (value.isOwnerAbs(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1620,7 +1562,6 @@ public class PlotSquared {
|
||||
|
||||
// Close the connection
|
||||
DBFunc.close();
|
||||
UUIDHandler.handleShutdown();
|
||||
} catch (NullPointerException throwable) {
|
||||
throwable.printStackTrace();
|
||||
PlotSquared.log("&cCould not close database connection!");
|
||||
@ -2014,6 +1955,23 @@ public class PlotSquared {
|
||||
return Collections.unmodifiableSet(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the chunk uses vanilla/non-PlotSquared generation
|
||||
*
|
||||
* @param world World name
|
||||
* @param chunkCoordinates Chunk coordinates
|
||||
* @return True if the chunk uses non-standard generation, false if not
|
||||
*/
|
||||
public boolean isNonStandardGeneration(@NotNull final String world,
|
||||
@NotNull final BlockVector2 chunkCoordinates) {
|
||||
final Location location = new Location(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
|
||||
final PlotArea area = plotAreaManager.getApplicablePlotArea(location);
|
||||
if (area == null) {
|
||||
return true;
|
||||
}
|
||||
return area.getTerrain() != PlotAreaTerrainType.NONE;
|
||||
}
|
||||
|
||||
public boolean isAugmented(@NonNull final String world) {
|
||||
final PlotArea[] areas = plotAreaManager.getPlotAreas(world, null);
|
||||
return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL);
|
||||
@ -2103,16 +2061,7 @@ public class PlotSquared {
|
||||
*/
|
||||
public Set<Plot> getPlotsByAlias(@Nullable final String alias,
|
||||
@NonNull final String worldname) {
|
||||
final Set<Plot> result = new HashSet<>();
|
||||
if (alias != null) {
|
||||
for (final Plot plot : getPlots()) {
|
||||
if (alias.equals(plot.getAlias()) && (worldname == null || worldname
|
||||
.equals(plot.getWorldName()))) {
|
||||
result.add(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet();
|
||||
}
|
||||
|
||||
public Set<PlotArea> getPlotAreas(final String world, final CuboidRegion region) {
|
||||
|
@ -38,8 +38,6 @@ import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.uuid.UUIDWrapper;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -60,9 +58,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @version 5
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
@NoArgsConstructor
|
||||
public class PlotAPI {
|
||||
@SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Gets all plots.
|
||||
@ -140,17 +136,6 @@ public class PlotAPI {
|
||||
return GlobalBlockQueue.IMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDWrapper class has basic methods for getting UUIDS. It's recommended
|
||||
* to use the UUIDHandler class instead.
|
||||
*
|
||||
* @return UUIDWrapper
|
||||
* @see UUIDWrapper
|
||||
*/
|
||||
public UUIDWrapper getUUIDWrapper() {
|
||||
return UUIDHandler.getUUIDWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* SchematicHandler class contains methods related to pasting, reading
|
||||
* and writing schematics.
|
||||
|
@ -142,7 +142,7 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
}
|
||||
final List<Plot> plots = Collections.singletonList(plot);
|
||||
final boolean result = SchematicHandler.manager.exportAll(plots, getBackupDirectory().toFile(),
|
||||
"%world%-%id%-%owner%-" + System.currentTimeMillis(), () ->
|
||||
"%world%-%id%-" + System.currentTimeMillis(), () ->
|
||||
future.complete(new Backup(this, System.currentTimeMillis(), null)));
|
||||
if (!result) {
|
||||
future.completeExceptionally(new RuntimeException("Failed to complete the backup"));
|
||||
|
@ -32,13 +32,16 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "add",
|
||||
description = "Allow a user to build in a plot while the plot owner is online.",
|
||||
@ -53,7 +56,7 @@ public class Add extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
|
||||
@ -62,7 +65,19 @@ public class Add extends Command {
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
Captions.NO_PLOT_PERMS);
|
||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||
final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
||||
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||
} else {
|
||||
Captions.INVALID_PLAYER.send(player, args[0]);
|
||||
}
|
||||
future.completeExceptionally(throwable);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
|
||||
Iterator<UUID> iterator = uuids.iterator();
|
||||
int size = plot.getTrusted().size() + plot.getMembers().size();
|
||||
@ -88,8 +103,7 @@ public class Add extends Command {
|
||||
size += plot.getTrusted().contains(uuid) ? 0 : 1;
|
||||
}
|
||||
checkTrue(!uuids.isEmpty(), null);
|
||||
checkTrue(size <= plot.getArea().getMaxPlotMembers() || Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
checkTrue(size <= plot.getArea().getMaxPlotMembers() || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||
Captions.PLOT_MAX_MEMBERS);
|
||||
// Success
|
||||
confirm.run(this, () -> {
|
||||
@ -106,7 +120,18 @@ public class Add extends Command {
|
||||
MainUtil.sendMessage(player, Captions.MEMBER_ADDED);
|
||||
}
|
||||
}, null);
|
||||
|
||||
return CompletableFuture.completedFuture(true);
|
||||
} catch (final Throwable exception) {
|
||||
future.completeExceptionally(exception);
|
||||
return;
|
||||
}
|
||||
}
|
||||
future.complete(true);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,19 +33,26 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
|
||||
@CommandDeclaration(command = "setalias",
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "alias",
|
||||
permission = "plots.alias",
|
||||
description = "Set the plot name",
|
||||
usage = "/plot alias <set|remove> <alias>",
|
||||
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
||||
aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
||||
category = CommandCategory.SETTINGS,
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Alias extends SubCommand {
|
||||
private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {};
|
||||
private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {};
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
@ -63,13 +70,11 @@ public class Alias extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!plot.isOwner(player.getUUID())) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean result = false;
|
||||
|
||||
boolean owner = plot.isOwner(player.getUUID());
|
||||
boolean permission;
|
||||
boolean admin;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "set":
|
||||
if (args.length != 2) {
|
||||
@ -77,17 +82,34 @@ public class Alias extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET, false)
|
||||
|| canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
|
||||
result = setAlias(player, plot, args[1]);
|
||||
permission = isPermitted(player, Captions.PERMISSION_ALIAS_SET)
|
||||
|| isPermitted(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE);
|
||||
admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_SET);
|
||||
if (!admin && !owner) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (permission) { // is either admin or owner
|
||||
setAlias(player, plot, args[1]);
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION);
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_ALIAS_SET.getTranslated());
|
||||
}
|
||||
|
||||
break;
|
||||
case "remove":
|
||||
if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_REMOVE, true)) {
|
||||
permission = isPermitted(player, Captions.PERMISSION_ALIAS_REMOVE);
|
||||
admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_REMOVE);
|
||||
if (!admin && !owner) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (permission) {
|
||||
result = removeAlias(player, plot);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_ALIAS_REMOVE.getTranslated());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -98,54 +120,58 @@ public class Alias extends SubCommand {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
final List<Command> commands = new ArrayList<>(2);
|
||||
if (args.length == 1) {
|
||||
if ("set".startsWith(args[0])) {
|
||||
commands.add(SET_COMMAND);
|
||||
}
|
||||
if ("remove".startsWith(args[0])) {
|
||||
commands.add(REMOVE_COMMAND);
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
private boolean setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||
private void setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||
if (alias.isEmpty()) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
}
|
||||
if (alias.length() >= 50) {
|
||||
} else if (alias.length() >= 50) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
|
||||
return false;
|
||||
}
|
||||
if (alias.contains(" ")) {
|
||||
} else if (alias.contains(" ")) {
|
||||
Captions.NOT_VALID_VALUE.send(player);
|
||||
return false;
|
||||
}
|
||||
if (MathMan.isInteger(alias)) {
|
||||
} else if (MathMan.isInteger(alias)) {
|
||||
Captions.NOT_VALID_VALUE.send(player);
|
||||
return false;
|
||||
}
|
||||
for (Plot p : PlotSquared.get().getPlots(plot.getArea())) {
|
||||
if (p.getAlias().equalsIgnoreCase(alias)) {
|
||||
} else {
|
||||
if (PlotQuery.newQuery().inArea(plot.getArea())
|
||||
.withAlias(alias)
|
||||
.anyMatch()) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (UUIDHandler.nameExists(new StringWrapper(alias)) || PlotSquared.get()
|
||||
.hasPlotArea(alias)) {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (uuid != null) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
plot.setAlias(alias);
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.ALIAS_SET_TO.getTranslated().replaceAll("%alias%", alias));
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean removeAlias(PlotPlayer player, Plot plot) {
|
||||
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
|
||||
plot.setAlias(null);
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_REMOVED.getTranslated());
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean canExecuteCommand(PlotPlayer player, Captions caption, boolean sendMessage) {
|
||||
if (!Permissions.hasPermission(player, caption)) {
|
||||
if (sendMessage) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
private boolean isPermitted(PlotPlayer<?> player, Captions caption) {
|
||||
return Permissions.hasPermission(player, caption);
|
||||
}
|
||||
}
|
||||
|
@ -33,26 +33,41 @@ import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.generator.HybridPlotWorld;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.SetupObject;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
@ -68,12 +83,140 @@ import java.util.Set;
|
||||
confirmation = true)
|
||||
public class Area extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "single":
|
||||
if (player instanceof ConsolePlayer) {
|
||||
MainUtil.sendMessage(player, Captions.IS_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_CREATE)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_AREA_CREATE);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
|
||||
return false;
|
||||
}
|
||||
final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]);
|
||||
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
|
||||
return false;
|
||||
}
|
||||
final LocalSession localSession = WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor());
|
||||
if (localSession == null) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
|
||||
return false;
|
||||
}
|
||||
Region playerSelectedRegion = null;
|
||||
try {
|
||||
playerSelectedRegion = localSession.getSelection(((Player) player.toActor()).getWorld());
|
||||
} catch (final Exception ignored) {}
|
||||
if (playerSelectedRegion == null) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
|
||||
return false;
|
||||
}
|
||||
if (playerSelectedRegion.getWidth() != playerSelectedRegion.getLength()) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE);
|
||||
return false;
|
||||
}
|
||||
if (PlotSquared.get().getPlotAreaManager().getPlotAreas(
|
||||
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING);
|
||||
}
|
||||
// Alter the region
|
||||
final BlockVector3 playerSelectionMin = playerSelectedRegion.getMinimumPoint();
|
||||
final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
|
||||
// Create a new selection that spans the entire vertical range of the world
|
||||
final CuboidRegion selectedRegion = new CuboidRegion(playerSelectedRegion.getWorld(),
|
||||
BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
||||
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
|
||||
// There's only one plot in the area...
|
||||
final PlotId plotId = new PlotId(1, 1);
|
||||
final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorld(), args[1],
|
||||
Objects.requireNonNull(PlotSquared.imp()).getDefaultGenerator(), plotId, plotId);
|
||||
// Plot size is the same as the region width
|
||||
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
|
||||
// We use a schematic generator
|
||||
hybridPlotWorld.setTerrain(PlotAreaTerrainType.NONE);
|
||||
// It is always a partial plot world
|
||||
hybridPlotWorld.setType(PlotAreaType.PARTIAL);
|
||||
// We save the schematic :D
|
||||
hybridPlotWorld.PLOT_SCHEMATIC = true;
|
||||
// Set the road width to 0
|
||||
hybridPlotWorld.ROAD_WIDTH = hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0;
|
||||
// Set the plot height to the selection height
|
||||
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
||||
// No sign plz
|
||||
hybridPlotWorld.setAllowSigns(false);
|
||||
final File parentFile = MainUtil.getFile(PlotSquared.imp().getDirectory(), "schematics" + File.separator +
|
||||
"GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
|
||||
hybridPlotWorld.getId());
|
||||
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_COULD_NOT_MAKE_DIRECTORIES);
|
||||
return false;
|
||||
}
|
||||
final File file = new File(parentFile, "plot.schem");
|
||||
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
||||
final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
|
||||
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1);
|
||||
final ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
|
||||
forwardExtentCopy.setCopyingBiomes(true);
|
||||
forwardExtentCopy.setCopyingEntities(true);
|
||||
Operations.complete(forwardExtentCopy);
|
||||
clipboardWriter.write(clipboard);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_FAILED_TO_SAVE);
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup schematic
|
||||
try {
|
||||
hybridPlotWorld.setupSchematics();
|
||||
} catch (final SchematicHandler.UnsupportedFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Calculate the offset
|
||||
final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint();
|
||||
|
||||
// Now the schematic is saved, which is wonderful!
|
||||
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld)
|
||||
.plotManager(PlotSquared.imp().getPluginName())
|
||||
.generatorName(PlotSquared.imp().getPluginName())
|
||||
.maximumId(plotId)
|
||||
.minimumId(plotId);
|
||||
Runnable singleRun = () -> {
|
||||
final String path =
|
||||
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-'
|
||||
+ singleBuilder.minimumId() + '-' + singleBuilder.maximumId();
|
||||
final int offsetX = singlePos1.getX();
|
||||
final int offsetZ = singlePos1.getZ();
|
||||
if (offsetX != 0) {
|
||||
PlotSquared.get().worlds
|
||||
.set(path + ".road.offset.x", offsetX);
|
||||
}
|
||||
if (offsetZ != 0) {
|
||||
PlotSquared.get().worlds
|
||||
.set(path + ".road.offset.z", offsetZ);
|
||||
}
|
||||
final String world = SetupUtils.manager.setupWorld(singleBuilder);
|
||||
if (WorldUtil.IMP.isWorld(world)) {
|
||||
PlotSquared.get().loadWorld(world, null);
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_CREATED);
|
||||
} else {
|
||||
MainUtil.sendMessage(player,
|
||||
"An error occurred while creating the world: " + hybridPlotWorld
|
||||
.getWorldName());
|
||||
}
|
||||
};
|
||||
singleRun.run();
|
||||
return true;
|
||||
case "c":
|
||||
case "setup":
|
||||
case "create":
|
||||
@ -138,19 +281,14 @@ public class Area extends SubCommand {
|
||||
.send(player, areas.iterator().next().toString());
|
||||
return false;
|
||||
}
|
||||
final SetupObject object = new SetupObject();
|
||||
object.world = area.getWorldName();
|
||||
object.id = area.getId();
|
||||
object.terrain = area.getTerrain();
|
||||
object.type = area.getType();
|
||||
object.min = new PlotId(1, 1);
|
||||
object.max = new PlotId(numX, numZ);
|
||||
object.plotManager = PlotSquared.imp().getPluginName();
|
||||
object.setupGenerator = PlotSquared.imp().getPluginName();
|
||||
object.step = area.getSettingNodes();
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area)
|
||||
.plotManager(PlotSquared.imp().getPluginName())
|
||||
.generatorName(PlotSquared.imp().getPluginName())
|
||||
.minimumId(new PlotId(1, 1))
|
||||
.maximumId(new PlotId(numX, numZ));
|
||||
final String path =
|
||||
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-'
|
||||
+ object.min + '-' + object.max;
|
||||
+ builder.minimumId() + '-' + builder.maximumId();
|
||||
Runnable run = () -> {
|
||||
if (offsetX != 0) {
|
||||
PlotSquared.get().worlds
|
||||
@ -160,7 +298,7 @@ public class Area extends SubCommand {
|
||||
PlotSquared.get().worlds
|
||||
.set(path + ".road.offset.z", offsetZ);
|
||||
}
|
||||
final String world = SetupUtils.manager.setupWorld(object);
|
||||
final String world = SetupUtils.manager.setupWorld(builder);
|
||||
if (WorldUtil.IMP.isWorld(world)) {
|
||||
PlotSquared.get().loadWorld(world, null);
|
||||
Captions.SETUP_FINISHED.send(player);
|
||||
@ -198,9 +336,9 @@ public class Area extends SubCommand {
|
||||
} else {
|
||||
id = null;
|
||||
}
|
||||
final SetupObject object = new SetupObject();
|
||||
object.world = split[0];
|
||||
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id,
|
||||
PlotAreaBuilder builder = new PlotAreaBuilder();
|
||||
builder.worldName(split[0]);
|
||||
final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
|
||||
PlotSquared.get().IMP.getDefaultGenerator(), null, null);
|
||||
PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id);
|
||||
if (other != null && Objects.equals(pa.getId(), other.getId())) {
|
||||
@ -262,13 +400,13 @@ public class Area extends SubCommand {
|
||||
pa.setTerrain(PlotAreaTerrainType.fromString(pair[1])
|
||||
.orElseThrow(() -> new IllegalArgumentException(
|
||||
pair[1] + " is not a valid terrain.")));
|
||||
object.terrain = pa.getTerrain();
|
||||
builder.terrainType(pa.getTerrain());
|
||||
break;
|
||||
case "type":
|
||||
pa.setType(PlotAreaType.fromString(pair[1]).orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
pair[1] + " is not a valid type.")));
|
||||
object.type = pa.getType();
|
||||
builder.plotAreaType(pa.getType());
|
||||
break;
|
||||
default:
|
||||
Captions.COMMAND_SYNTAX.send(player, getCommandString()
|
||||
@ -290,9 +428,9 @@ public class Area extends SubCommand {
|
||||
PlotSquared.get().worlds.getConfigurationSection(path);
|
||||
pa.saveConfiguration(section);
|
||||
pa.loadConfiguration(section);
|
||||
object.plotManager = PlotSquared.imp().getPluginName();
|
||||
object.setupGenerator = PlotSquared.imp().getPluginName();
|
||||
String world = SetupUtils.manager.setupWorld(object);
|
||||
builder.plotManager(PlotSquared.imp().getPluginName());
|
||||
builder.generatorName(PlotSquared.imp().getPluginName());
|
||||
String world = SetupUtils.manager.setupWorld(builder);
|
||||
if (WorldUtil.IMP.isWorld(world)) {
|
||||
Captions.SETUP_FINISHED.send(player);
|
||||
player.teleport(WorldUtil.IMP.getSpawn(world),
|
||||
@ -327,9 +465,9 @@ public class Area extends SubCommand {
|
||||
TeleportCause.COMMAND);
|
||||
}
|
||||
} else {
|
||||
object.terrain = PlotAreaTerrainType.NONE;
|
||||
object.type = PlotAreaType.NORMAL;
|
||||
SetupUtils.manager.setupWorld(object);
|
||||
builder.terrainType(PlotAreaTerrainType.NONE);
|
||||
builder.plotAreaType(PlotAreaType.NORMAL);
|
||||
SetupUtils.manager.setupWorld(builder);
|
||||
player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()),
|
||||
TeleportCause.COMMAND);
|
||||
}
|
||||
|
@ -154,12 +154,12 @@ public class Auto extends SubCommand {
|
||||
() -> autoClaimFromDatabase(player, area, plot.getId(), whenDone));
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
PlotArea plotarea = player.getApplicablePlotArea();
|
||||
if (plotarea == null) {
|
||||
if (EconHandler.manager != null) {
|
||||
if (EconHandler.getEconHandler() != null) {
|
||||
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
|
||||
if (EconHandler.manager
|
||||
if (EconHandler.getEconHandler()
|
||||
.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
|
||||
if (plotarea != null) {
|
||||
plotarea = null;
|
||||
@ -253,18 +253,18 @@ public class Auto extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (EconHandler.manager != null && plotarea.useEconomy()) {
|
||||
if (EconHandler.getEconHandler() != null && plotarea.useEconomy()) {
|
||||
Expression<Double> costExp = plotarea.getPrices().get("claim");
|
||||
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
|
||||
player.getPlotCount() :
|
||||
player.getPlotCount(plotarea.getWorldName())));
|
||||
cost = (size_x * size_z) * cost;
|
||||
if (cost > 0d) {
|
||||
if (!force && EconHandler.manager.getMoney(player) < cost) {
|
||||
if (!force && EconHandler.getEconHandler().getMoney(player) < cost) {
|
||||
sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
return true;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(player, cost);
|
||||
EconHandler.getEconHandler().withdrawMoney(player, cost);
|
||||
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public final class Backup extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
if (args.length == 0 || !Arrays.asList("save", "list", "load")
|
||||
|
@ -37,7 +37,6 @@ import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -55,11 +54,11 @@ public class Buy extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||
|
||||
check(EconHandler.manager, Captions.ECON_DISABLED);
|
||||
check(EconHandler.getEconHandler(), Captions.ECON_DISABLED);
|
||||
final Plot plot;
|
||||
if (args.length != 0) {
|
||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||
@ -82,10 +81,10 @@ public class Buy extends Command {
|
||||
// Success
|
||||
confirm.run(this, () -> {
|
||||
Captions.REMOVED_BALANCE.send(player, price);
|
||||
EconHandler.manager
|
||||
.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.getOwnerAbs()),
|
||||
price);
|
||||
PlotPlayer owner = UUIDHandler.getPlayer(plot.getOwnerAbs());
|
||||
|
||||
EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
|
||||
|
||||
PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
|
||||
if (owner != null) {
|
||||
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
usage = "/plot caps")
|
||||
public class Caps extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, final String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
return Captions.NOT_IN_PLOT.send(player);
|
||||
|
@ -37,7 +37,7 @@ import com.plotsquared.core.util.MainUtil;
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Chat extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (player.getPlotAreaAbs().isForcingPlotChat()) {
|
||||
MainUtil.sendMessage(player, Captions.PLOT_CHAT_FORCED);
|
||||
return true;
|
||||
|
@ -54,7 +54,7 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
usage = "/plot claim")
|
||||
public class Claim extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
String schematic = null;
|
||||
if (args.length >= 1) {
|
||||
schematic = args[0];
|
||||
@ -105,14 +105,14 @@ public class Claim extends SubCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((EconHandler.manager != null) && area.useEconomy() && !force) {
|
||||
if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) {
|
||||
Expression<Double> costExr = area.getPrices().get("claim");
|
||||
double cost = costExr.evaluate((double) currentPlots);
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(player) < cost) {
|
||||
if (EconHandler.getEconHandler().getMoney(player) < cost) {
|
||||
return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(player, cost);
|
||||
EconHandler.getEconHandler().withdrawMoney(player, cost);
|
||||
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class Clear extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
checkTrue(args.length == 0, Captions.COMMAND_SYNTAX, getUsage());
|
||||
|
@ -39,12 +39,12 @@ import com.plotsquared.core.plot.PlotCluster;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "cluster",
|
||||
aliases = "clusters",
|
||||
@ -54,7 +54,7 @@ import java.util.UUID;
|
||||
description = "Manage a plot cluster")
|
||||
public class Cluster extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||
if (args.length == 0) {
|
||||
@ -371,22 +371,29 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// check uuid
|
||||
UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
|
||||
return false;
|
||||
}
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[1], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
|
||||
} else {
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
// add the user if not added
|
||||
cluster.invited.add(uuid);
|
||||
DBFunc.setInvited(cluster, uuid);
|
||||
PlotPlayer player2 = UUIDHandler.getPlayer(uuid);
|
||||
if (player2 != null) {
|
||||
MainUtil.sendMessage(player2, Captions.CLUSTER_INVITED, cluster.getName());
|
||||
|
||||
final PlotPlayer otherPlayer =
|
||||
PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (otherPlayer != null) {
|
||||
MainUtil.sendMessage(otherPlayer, Captions.CLUSTER_INVITED,
|
||||
cluster.getName());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_USER);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "k":
|
||||
@ -420,35 +427,43 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
}
|
||||
// check uuid
|
||||
UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||
if (uuid == null) {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[1], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner) || !cluster
|
||||
.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER, cluster.getName());
|
||||
return false;
|
||||
}
|
||||
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner)
|
||||
|| !cluster.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER,
|
||||
cluster.getName());
|
||||
} else {
|
||||
if (cluster.helpers.contains(uuid)) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
}
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
PlotPlayer player2 = UUIDHandler.getPlayer(uuid);
|
||||
|
||||
final PlotPlayer player2 =
|
||||
PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (player2 != null) {
|
||||
MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED, cluster.getName());
|
||||
MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED,
|
||||
cluster.getName());
|
||||
}
|
||||
for (Plot plot : new ArrayList<>(
|
||||
PlotSquared.get().getPlots(player2.getLocation().getWorld(), uuid))) {
|
||||
for (Plot plot : new ArrayList<>(PlotSquared.get()
|
||||
.getPlots(player2.getLocation().getWorld(), uuid))) {
|
||||
PlotCluster current = plot.getCluster();
|
||||
if (current != null && current.equals(cluster)) {
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player2, Captions.CLUSTER_KICKED_USER);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "quit":
|
||||
@ -529,24 +544,29 @@ public class Cluster extends SubCommand {
|
||||
MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(args[2], null);
|
||||
if (uuid == null) {
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[2], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
cluster.helpers.add(uuid);
|
||||
DBFunc.setHelper(cluster, uuid);
|
||||
return MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER);
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("remove")) {
|
||||
MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER);
|
||||
} else if (args[1].equalsIgnoreCase("remove")) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
return MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER);
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
|
||||
"/plot cluster helpers <add|remove> <player>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "spawn":
|
||||
case "home":
|
||||
@ -615,9 +635,17 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
}
|
||||
String id = cluster.toString();
|
||||
String owner = UUIDHandler.getName(cluster.owner);
|
||||
if (owner == null) {
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(cluster.owner, (username, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else {
|
||||
final String owner;
|
||||
if (username == null) {
|
||||
owner = "unknown";
|
||||
} else {
|
||||
owner = username;
|
||||
}
|
||||
String name = cluster.getName();
|
||||
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
|
||||
@ -630,6 +658,8 @@ public class Cluster extends SubCommand {
|
||||
message = message.replaceAll("%size%", size);
|
||||
message = message.replaceAll("%rights%", rights);
|
||||
MainUtil.sendMessage(player, message);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "sh":
|
||||
|
@ -32,15 +32,15 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
|
||||
public class CmdConfirm {
|
||||
|
||||
public static CmdInstance getPending(PlotPlayer player) {
|
||||
public static CmdInstance getPending(PlotPlayer<?> player) {
|
||||
return player.getMeta("cmdConfirm");
|
||||
}
|
||||
|
||||
public static void removePending(PlotPlayer player) {
|
||||
public static void removePending(PlotPlayer<?> player) {
|
||||
player.deleteMeta("cmdConfirm");
|
||||
}
|
||||
|
||||
public static void addPending(final PlotPlayer player, String commandStr,
|
||||
public static void addPending(final PlotPlayer<?> player, String commandStr,
|
||||
final Runnable runnable) {
|
||||
removePending(player);
|
||||
if (commandStr != null) {
|
||||
|
@ -37,6 +37,8 @@ import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import lombok.SneakyThrows;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -104,7 +106,7 @@ public abstract class Command {
|
||||
&& types[4] == RunnableVal2.class) {
|
||||
Command tmp = new Command(this, true) {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
try {
|
||||
@ -298,7 +300,7 @@ public abstract class Command {
|
||||
* @return CompletableFuture true if the command executed fully, false in
|
||||
* any other case
|
||||
*/
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
if (args.length == 0 || args[0] == null) {
|
||||
@ -603,6 +605,10 @@ public abstract class Command {
|
||||
return object;
|
||||
}
|
||||
|
||||
@SneakyThrows protected static void sneakyThrow(@NotNull final Throwable throwable) {
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
public enum CommandResult {
|
||||
FAILURE, SUCCESS
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
@ -33,11 +34,9 @@ import com.plotsquared.core.plot.comment.CommentManager;
|
||||
import com.plotsquared.core.plot.comment.PlotComment;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(command = "comment",
|
||||
aliases = {"msg"},
|
||||
@ -47,7 +46,7 @@ import java.util.Map.Entry;
|
||||
permission = "plots.comment")
|
||||
public class Comment extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 2) {
|
||||
sendMessage(player, Captions.COMMENT_SYNTAX,
|
||||
StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||
@ -96,12 +95,13 @@ public class Comment extends SubCommand {
|
||||
StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||
return false;
|
||||
}
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer pp = entry.getValue();
|
||||
|
||||
for (final PlotPlayer pp : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
if (pp.getAttribute("chatspy")) {
|
||||
MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " "));
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(player, Captions.COMMENT_ADDED);
|
||||
return true;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class Condense extends SubCommand {
|
||||
|
||||
public static boolean TASK = false;
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
MainUtil.sendMessage(player, getUsage());
|
||||
return false;
|
||||
|
@ -37,7 +37,7 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
category = CommandCategory.INFO)
|
||||
public class Confirm extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
CmdInstance command = CmdConfirm.getPending(player);
|
||||
if (command == null) {
|
||||
MainUtil.sendMessage(player, Captions.FAILED_CONFIRM);
|
||||
|
@ -44,7 +44,7 @@ import com.plotsquared.core.util.Permissions;
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Continue extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Plot plot = player.getCurrentPlot();
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
return !sendMessage(player, Captions.NOT_IN_PLOT);
|
||||
|
@ -41,7 +41,7 @@ import com.plotsquared.core.util.Permissions;
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Copy extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot1 = location.getPlotAbs();
|
||||
if (plot1 == null) {
|
||||
|
@ -42,7 +42,7 @@ import com.plotsquared.core.util.MainUtil;
|
||||
usage = "/plot createroadschematic")
|
||||
public class CreateRoadSchematic extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
|
@ -74,7 +74,7 @@ public class DatabaseCommand extends SubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(player, getUsage());
|
||||
return false;
|
||||
|
@ -34,8 +34,10 @@ import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.entity.EntityCategory;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
@ -46,7 +48,7 @@ import java.util.Map;
|
||||
permission = "plots.admin")
|
||||
public class Debug extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length > 0) {
|
||||
if ("player".equalsIgnoreCase(args[0])) {
|
||||
for (Map.Entry<String, Object> meta : player.getMeta().entrySet()) {
|
||||
@ -65,6 +67,18 @@ public class Debug extends SubCommand {
|
||||
.currentThread().getName()));
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && "uuids".equalsIgnoreCase(args[0])) {
|
||||
final Collection<UUIDMapping> mappings = PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
|
||||
MainUtil.sendMessage(player, String.format("There are %d cached UUIDs", mappings.size()));
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && "debug-players".equalsIgnoreCase(args[0])) {
|
||||
MainUtil.sendMessage(player, "Player in debug mode: " );
|
||||
for (final PlotPlayer<?> pp : PlotPlayer.getDebugModePlayers()) {
|
||||
MainUtil.sendMessage(player, "- " + pp.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) {
|
||||
EntityCategories.init();
|
||||
player.sendMessage(Captions.PREFIX.getTranslated() + "§cEntity Categories: ");
|
||||
|
@ -42,7 +42,7 @@ public class DebugAllowUnsafe extends SubCommand {
|
||||
|
||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
if (unsafeAllowed.contains(player.getUUID())) {
|
||||
unsafeAllowed.remove(player.getUUID());
|
||||
|
@ -1,134 +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.command;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "debugclaimtest",
|
||||
description =
|
||||
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
|
||||
+ "Execution time may vary",
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
permission = "plots.debugclaimtest")
|
||||
public class DebugClaimTest extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
if (args.length < 3) {
|
||||
return !MainUtil.sendMessage(null,
|
||||
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the "
|
||||
+ "plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
|
||||
}
|
||||
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
|
||||
if (area == null || !WorldUtil.IMP.isWorld(area.getWorldName())) {
|
||||
Captions.NOT_VALID_PLOT_WORLD.send(player, args[0]);
|
||||
return false;
|
||||
}
|
||||
PlotId min, max;
|
||||
try {
|
||||
args[1].split(";");
|
||||
args[2].split(";");
|
||||
min = PlotId.fromString(args[1]);
|
||||
max = PlotId.fromString(args[2]);
|
||||
} catch (Exception ignored) {
|
||||
return !MainUtil.sendMessage(player,
|
||||
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion "
|
||||
+ "will only check the plots in the selected area.");
|
||||
}
|
||||
MainUtil.sendMessage(player,
|
||||
"&3Sign Block&8->&3Plot&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||
MainUtil.sendMessage(player,
|
||||
"&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
||||
PlotManager manager = area.getPlotManager();
|
||||
CompletableFuture.runAsync(() -> {
|
||||
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(min, max);
|
||||
MainUtil.sendMessage(player,
|
||||
"&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!");
|
||||
for (PlotId id : ids) {
|
||||
Plot plot = area.getPlotAbs(id);
|
||||
if (plot.hasOwner()) {
|
||||
MainUtil.sendMessage(player, " - &cDB Already contains: " + plot.getId());
|
||||
continue;
|
||||
}
|
||||
Location location = manager.getSignLoc(plot);
|
||||
BlockVector2 chunk = BlockVector2.at(location.getX() >> 4, location.getZ() >> 4);
|
||||
ChunkManager.manager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
|
||||
String[] lines = WorldUtil.IMP.getSignSynchronous(location);
|
||||
if (lines != null) {
|
||||
String line = lines[2];
|
||||
if (line != null && line.length() > 2) {
|
||||
line = line.substring(2);
|
||||
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||
UUID uuid = map.get(new StringWrapper(line));
|
||||
if (uuid == null) {
|
||||
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map
|
||||
.entrySet()) {
|
||||
if (stringWrapperUUIDEntry.getKey().value.toLowerCase()
|
||||
.startsWith(line.toLowerCase())) {
|
||||
uuid = stringWrapperUUIDEntry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(line, null);
|
||||
}
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(player,
|
||||
" - &aFound plot: " + plot.getId() + " : " + line);
|
||||
plot.setOwner(uuid);
|
||||
MainUtil.sendMessage(player, " - &8Updated plot: " + plot.getId());
|
||||
} else {
|
||||
MainUtil.sendMessage(player,
|
||||
" - &cInvalid PlayerName: " + plot.getId() + " : " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).join();
|
||||
}
|
||||
}).thenRun(() -> MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: Finished scan."));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -35,7 +35,6 @@ import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.generator.HybridUtils;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
@ -59,7 +58,6 @@ import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import javax.script.Bindings;
|
||||
@ -71,13 +69,10 @@ import javax.script.SimpleScriptContext;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@CommandDeclaration(command = "debugexec",
|
||||
@ -171,8 +166,7 @@ public class DebugExec extends SubCommand {
|
||||
this.scope.put("BlockManager", WorldUtil.IMP);
|
||||
this.scope.put("SetupUtils", SetupUtils.manager);
|
||||
this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher());
|
||||
this.scope.put("EconHandler", EconHandler.manager);
|
||||
this.scope.put("UUIDHandler", UUIDHandler.implementation);
|
||||
this.scope.put("EconHandler", EconHandler.getEconHandler());
|
||||
this.scope.put("DBFunc", DBFunc.dbManager);
|
||||
this.scope.put("HybridUtils", HybridUtils.manager);
|
||||
this.scope.put("IMP", PlotSquared.get().IMP);
|
||||
@ -184,7 +178,7 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
List<String> allowed_params = Arrays
|
||||
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
|
||||
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
|
||||
@ -301,27 +295,6 @@ public class DebugExec extends SubCommand {
|
||||
} else {
|
||||
return MainUtil.sendMessage(player, "Plot expiry task already started");
|
||||
}
|
||||
case "seen":
|
||||
if (args.length != 2) {
|
||||
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||
if (uuid == null) {
|
||||
return MainUtil.sendMessage(player, "Player not found: " + args[1]);
|
||||
}
|
||||
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
|
||||
if (op == null || op.getLastPlayed() == 0) {
|
||||
return MainUtil
|
||||
.sendMessage(player, "Player hasn't connected before: " + args[1]);
|
||||
}
|
||||
Timestamp stamp = new Timestamp(op.getLastPlayed());
|
||||
Date date = new Date(stamp.getTime());
|
||||
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
||||
MainUtil.sendMessage(player, "UUID: " + uuid);
|
||||
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
|
||||
MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
|
||||
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
|
||||
return true;
|
||||
case "h":
|
||||
case "he":
|
||||
case "?":
|
||||
@ -339,7 +312,7 @@ public class DebugExec extends SubCommand {
|
||||
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
|
||||
RequiredType.NONE, CommandCategory.DEBUG) {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player,
|
||||
String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
try {
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
@ -35,7 +36,6 @@ import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
@ -52,7 +52,7 @@ public class DebugImportWorlds extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
|
||||
@ -76,7 +76,8 @@ public class DebugImportWorlds extends Command {
|
||||
if (name.length() > 16) {
|
||||
uuid = UUID.fromString(name);
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(name, null);
|
||||
Captions.FETCHING_PLAYER.send(player);
|
||||
uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(name, 60000L);
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid =
|
||||
|
@ -37,7 +37,7 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
requiredType = RequiredType.CONSOLE)
|
||||
public class DebugLoadTest extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
PlotSquared.get().plots_tmp = DBFunc.getPlots();
|
||||
return true;
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ 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 com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -72,7 +71,7 @@ public class DebugPaste extends SubCommand {
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
|
||||
@ -90,7 +89,7 @@ public class DebugPaste extends SubCommand {
|
||||
b.append("# Server Information\n");
|
||||
b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation())
|
||||
.append("\n");
|
||||
b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';')
|
||||
b.append("online_mode: ").append(!Settings.UUID.OFFLINE).append(';')
|
||||
.append(!Settings.UUID.OFFLINE).append('\n');
|
||||
b.append("Plugins:");
|
||||
for (Map.Entry<Map.Entry<String, String>, Boolean> pluginInfo : PlotSquared
|
||||
@ -122,7 +121,7 @@ public class DebugPaste extends SubCommand {
|
||||
b.append("OS Arch: ").append(System.getProperty("os.arch")).append('\n');
|
||||
b.append("# Okay :D Great. You are now ready to create your bug report!");
|
||||
b.append(
|
||||
"\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
|
||||
"\n# You can do so at https://issues.intellectualsites.com/projects/ps");
|
||||
b.append("\n# or via our Discord at https://discord.gg/KxkjDVg");
|
||||
|
||||
final IncendoPaster incendoPaster = new IncendoPaster("plotsquared");
|
||||
|
@ -46,7 +46,7 @@ import java.util.Arrays;
|
||||
public class DebugRoadRegen extends SubCommand {
|
||||
public static final String USAGE = "/plot debugroadregen <plot|region [height]>";
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE);
|
||||
return false;
|
||||
|
@ -41,7 +41,7 @@ import java.util.ArrayList;
|
||||
description = "This command will force the recreation of all plots in the DB")
|
||||
public class DebugSaveTest extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||
MainUtil.sendMessage(player, "&6Starting `DEBUGSAVETEST`");
|
||||
DBFunc.createPlotsAndData(plots,
|
||||
|
@ -53,7 +53,7 @@ public class Delete extends SubCommand {
|
||||
// Note: To delete a specific plot use /plot <plot> delete
|
||||
// The syntax also works with any command: /plot <plot> <command>
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -86,11 +86,11 @@ public class Delete extends SubCommand {
|
||||
final long start = System.currentTimeMillis();
|
||||
boolean result = plot.deletePlot(() -> {
|
||||
plot.removeRunning();
|
||||
if ((EconHandler.manager != null) && plotArea.useEconomy()) {
|
||||
if ((EconHandler.getEconHandler() != null) && plotArea.useEconomy()) {
|
||||
Expression<Double> valueExr = plotArea.getPrices().get("sell");
|
||||
double value = plots.size() * valueExr.evaluate((double) currentPlots);
|
||||
if (value > 0d) {
|
||||
EconHandler.manager.depositMoney(player, value);
|
||||
EconHandler.getEconHandler().depositMoney(player, value);
|
||||
sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,14 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "deny",
|
||||
aliases = {"d", "ban"},
|
||||
@ -52,7 +54,7 @@ public class Deny extends SubCommand {
|
||||
super(Argument.PlayerName);
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
@ -68,27 +70,25 @@ public class Deny extends SubCommand {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
||||
if (uuids.isEmpty()) {
|
||||
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null || uuids.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
for (UUID uuid : uuids) {
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
continue;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
} else if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.getDenied().contains(uuid)) {
|
||||
return;
|
||||
} else if (plot.getDenied().contains(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
return false;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (uuid != DBFunc.EVERYONE) {
|
||||
plot.removeMember(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
@ -96,7 +96,7 @@ public class Deny extends SubCommand {
|
||||
plot.addDenied(uuid);
|
||||
PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true);
|
||||
if (!uuid.equals(DBFunc.EVERYONE)) {
|
||||
handleKick(UUIDHandler.getPlayer(uuid), plot);
|
||||
handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid), plot);
|
||||
} else {
|
||||
for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
|
||||
// Ignore plot-owners
|
||||
@ -107,12 +107,18 @@ public class Deny extends SubCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!uuids.isEmpty()) {
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.DENIED_ADDED);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
private void handleKick(PlotPlayer player, Plot plot) {
|
||||
if (player == null) {
|
||||
return;
|
||||
|
@ -35,7 +35,7 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Dislike extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
return Like.handleLike(player, args, false);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ import com.plotsquared.core.util.task.RunnableVal;
|
||||
requiredType = RequiredType.NONE)
|
||||
public class Done extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
|
@ -50,7 +50,7 @@ import java.net.URL;
|
||||
permission = "plots.download")
|
||||
public class Download extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
String world = player.getLocation().getWorld();
|
||||
if (!PlotSquared.get().hasPlotArea(world)) {
|
||||
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
|
||||
|
@ -207,7 +207,7 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
if (args.length == 0 || !Arrays
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
@ -35,10 +36,10 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "grant",
|
||||
category = CommandCategory.CLAIMING,
|
||||
@ -52,7 +53,7 @@ public class Grant extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
checkTrue(args.length >= 1 && args.length <= 2, Captions.COMMAND_SYNTAX, getUsage());
|
||||
@ -69,17 +70,15 @@ public class Grant extends Command {
|
||||
if (args.length > 2) {
|
||||
break;
|
||||
}
|
||||
final UUID uuid;
|
||||
if (args.length == 2) {
|
||||
uuid = UUIDHandler.getUUIDFromString(args[1]);
|
||||
MainUtil.getUUIDsFromString(args[1], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null || uuids.size() != 1) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
|
||||
} else {
|
||||
uuid = player.getUUID();
|
||||
}
|
||||
if (uuid == null) {
|
||||
Captions.INVALID_PLAYER.send(player, args[1]);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal<byte[]>() {
|
||||
final UUID uuid = uuids.toArray(new UUID[0])[0];
|
||||
MainUtil.getPersistentMeta(uuid,
|
||||
"grantedPlots", new RunnableVal<byte[]>() {
|
||||
@Override public void run(byte[] array) {
|
||||
if (arg0.equals("check")) { // check
|
||||
int granted;
|
||||
@ -99,7 +98,8 @@ public class Grant extends Command {
|
||||
boolean replace = array != null;
|
||||
String key = "grantedPlots";
|
||||
byte[] rawData = Ints.toByteArray(amount);
|
||||
PlotPlayer online = UUIDHandler.getPlayer(uuid);
|
||||
|
||||
PlotPlayer online = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (online != null) {
|
||||
online.setPersistentMeta(key, rawData);
|
||||
} else {
|
||||
@ -108,6 +108,8 @@ public class Grant extends Command {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
|
@ -52,7 +52,7 @@ public class Help extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
switch (args.length) {
|
||||
|
@ -86,7 +86,7 @@ public class Inbox extends SubCommand {
|
||||
MainUtil.sendMessage(player, string.toString());
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
sendMessage(player, Captions.NOT_IN_PLOT);
|
||||
|
@ -41,7 +41,7 @@ import com.plotsquared.core.util.task.RunnableVal;
|
||||
category = CommandCategory.INFO)
|
||||
public class Info extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Plot plot;
|
||||
String arg;
|
||||
if (args.length > 0) {
|
||||
|
@ -33,12 +33,15 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@CommandDeclaration(command = "kick",
|
||||
aliases = "k",
|
||||
@ -53,7 +56,7 @@ public class Kick extends SubCommand {
|
||||
super(Argument.PlayerName);
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
@ -64,15 +67,17 @@ public class Kick extends SubCommand {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
||||
if (uuids.isEmpty()) {
|
||||
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null || uuids.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
Set<PlotPlayer> players = new HashSet<>();
|
||||
} else {
|
||||
Set<PlotPlayer<?>> players = new HashSet<>();
|
||||
for (UUID uuid : uuids) {
|
||||
if (uuid == DBFunc.EVERYONE) {
|
||||
for (PlotPlayer pp : plot.getPlayersInPlot()) {
|
||||
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
|
||||
if (pp == player || Permissions
|
||||
.hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
|
||||
continue;
|
||||
@ -81,7 +86,7 @@ public class Kick extends SubCommand {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
|
||||
PlotPlayer<?> pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (pp != null) {
|
||||
players.add(pp);
|
||||
}
|
||||
@ -89,16 +94,16 @@ public class Kick extends SubCommand {
|
||||
players.remove(player); // Don't ever kick the calling player
|
||||
if (players.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
for (PlotPlayer player2 : players) {
|
||||
for (PlotPlayer<?> player2 : players) {
|
||||
if (!plot.equals(player2.getCurrentPlot())) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (Permissions.hasPermission(player2, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
|
||||
Captions.CANNOT_KICK_PLAYER.send(player, player2.getName());
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
|
||||
Captions.YOU_GOT_KICKED.send(player2);
|
||||
@ -115,6 +120,19 @@ public class Kick extends SubCommand {
|
||||
player2.plotkick(spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return TabCompletions.completePlayersInPlot(plot, String.join(",", args).trim(),
|
||||
Collections.singletonList(player.getName()));
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class Leave extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
|
||||
|
@ -175,7 +175,7 @@ public class Like extends SubCommand {
|
||||
return numLikes / (numLikes + numDislikes);
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
return handleLike(player, args, true);
|
||||
}
|
||||
|
||||
|
@ -26,13 +26,12 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.PlotSquared.SortType;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.Rating;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
|
||||
@ -43,26 +42,36 @@ import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandDeclaration(command = "list",
|
||||
aliases = {"l", "find", "search"},
|
||||
description = "List plots",
|
||||
permission = "plots.list",
|
||||
category = CommandCategory.INFO,
|
||||
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|unknown|player|world|done|fuzzy <search...>> [#]")
|
||||
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|player|world|done|fuzzy <search...>> [#]")
|
||||
public class ListCmd extends SubCommand {
|
||||
|
||||
private String[] getArgumentList(PlotPlayer player) {
|
||||
List<String> args = new ArrayList<>();
|
||||
if (EconHandler.manager != null && Permissions
|
||||
if (EconHandler.getEconHandler() != null && Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
||||
args.add("forsale");
|
||||
}
|
||||
@ -84,9 +93,6 @@ public class ListCmd extends SubCommand {
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
|
||||
args.add("unowned");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNKNOWN)) {
|
||||
args.add("unknown");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
|
||||
args.add("<player>");
|
||||
}
|
||||
@ -110,30 +116,58 @@ public class ListCmd extends SubCommand {
|
||||
.toString(getArgumentList(player)));
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
if (args.length < 1) {
|
||||
noArgs(player);
|
||||
return false;
|
||||
}
|
||||
int page = 0;
|
||||
|
||||
final int page;
|
||||
if (args.length > 1) {
|
||||
int tempPage = -1;
|
||||
try {
|
||||
page = Integer.parseInt(args[args.length - 1]);
|
||||
--page;
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
tempPage = Integer.parseInt(args[args.length - 1]);
|
||||
--tempPage;
|
||||
if (tempPage < 0) {
|
||||
tempPage = 0;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
page = -1;
|
||||
}
|
||||
page = tempPage;
|
||||
} else {
|
||||
page = 0;
|
||||
}
|
||||
|
||||
List<Plot> plots = null;
|
||||
|
||||
String world = player.getLocation().getWorld();
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
String arg = args[0].toLowerCase();
|
||||
boolean sort = true;
|
||||
final boolean[] sort = new boolean[] {true};
|
||||
|
||||
final Consumer<PlotQuery> plotConsumer = query -> {
|
||||
if (query == null) {
|
||||
sendMessage(player, Captions.DID_YOU_MEAN,
|
||||
new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"})
|
||||
.getBestMatch());
|
||||
return;
|
||||
}
|
||||
|
||||
if (area != null) {
|
||||
query.relativeToArea(area);
|
||||
}
|
||||
|
||||
if (sort[0]) {
|
||||
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
|
||||
}
|
||||
|
||||
final List<Plot> plots = query.asList();
|
||||
|
||||
if (plots.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
|
||||
return;
|
||||
}
|
||||
displayPlots(player, plots, 12, page, args);
|
||||
};
|
||||
|
||||
switch (arg) {
|
||||
case "mine":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) {
|
||||
@ -141,8 +175,8 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_MINE);
|
||||
return false;
|
||||
}
|
||||
sort = false;
|
||||
plots = PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getBasePlots(player));
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().ownedBy(player).whereBasePlot().withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
break;
|
||||
case "shared":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_SHARED)) {
|
||||
@ -150,13 +184,7 @@ public class ListCmd extends SubCommand {
|
||||
Captions.PERMISSION_LIST_SHARED);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getTrusted().contains(player.getUUID()) || plot.getMembers()
|
||||
.contains(player.getUUID())) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().withMember(player.getUUID()).thatPasses(plot -> !plot.isOwnerAbs(player.getUUID())));
|
||||
break;
|
||||
case "world":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
|
||||
@ -171,7 +199,7 @@ public class ListCmd extends SubCommand {
|
||||
world));
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PlotSquared.get().getPlots(world));
|
||||
plotConsumer.accept(PlotQuery.newQuery().inWorld(world));
|
||||
break;
|
||||
case "expired":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_EXPIRED)) {
|
||||
@ -179,9 +207,11 @@ public class ListCmd extends SubCommand {
|
||||
Captions.PERMISSION_LIST_EXPIRED);
|
||||
return false;
|
||||
}
|
||||
plots = ExpireManager.IMP == null ?
|
||||
new ArrayList<Plot>() :
|
||||
new ArrayList<>(ExpireManager.IMP.getPendingExpired());
|
||||
if (ExpireManager.IMP == null) {
|
||||
plotConsumer.accept(PlotQuery.newQuery().noPlots());
|
||||
} else {
|
||||
plotConsumer.accept(PlotQuery.newQuery().expiredPlots());
|
||||
}
|
||||
break;
|
||||
case "area":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_AREA)) {
|
||||
@ -196,7 +226,11 @@ public class ListCmd extends SubCommand {
|
||||
world));
|
||||
return false;
|
||||
}
|
||||
plots = area == null ? new ArrayList<Plot>() : new ArrayList<>(area.getPlots());
|
||||
if (area == null) {
|
||||
plotConsumer.accept(PlotQuery.newQuery().noPlots());
|
||||
} else {
|
||||
plotConsumer.accept(PlotQuery.newQuery().inArea(area));
|
||||
}
|
||||
break;
|
||||
case "all":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_ALL)) {
|
||||
@ -204,7 +238,7 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_ALL);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots());
|
||||
break;
|
||||
case "done":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_DONE)) {
|
||||
@ -212,24 +246,8 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_DONE);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (DoneFlag.isDone(plot)) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plots.sort((a, b) -> {
|
||||
String va = a.getFlag(DoneFlag.class);
|
||||
String vb = b.getFlag(DoneFlag.class);
|
||||
if (MathMan.isInteger(va)) {
|
||||
if (MathMan.isInteger(vb)) {
|
||||
return Integer.parseInt(vb) - Integer.parseInt(va);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
sort = false;
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(DoneFlag::isDone).withSortingStrategy(SortingStrategy.SORT_BY_DONE));
|
||||
break;
|
||||
case "top":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_TOP)) {
|
||||
@ -237,32 +255,8 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_TOP);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||
plots.sort((p1, p2) -> {
|
||||
double v1 = 0;
|
||||
int p1s = p1.getSettings().getRatings().size();
|
||||
int p2s = p2.getRatings().size();
|
||||
if (!p1.getSettings().getRatings().isEmpty()) {
|
||||
v1 = p1.getRatings().values().stream().mapToDouble(Rating::getAverageRating)
|
||||
.map(av -> av * av).sum();
|
||||
v1 /= p1s;
|
||||
v1 += p1s;
|
||||
}
|
||||
double v2 = 0;
|
||||
if (!p2.getSettings().getRatings().isEmpty()) {
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v2 += av * av;
|
||||
}
|
||||
v2 /= p2s;
|
||||
v2 += p2s;
|
||||
}
|
||||
if (v2 == v1 && v2 != 0) {
|
||||
return p2s - p1s;
|
||||
}
|
||||
return (int) Math.signum(v2 - v1);
|
||||
});
|
||||
sort = false;
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().withSortingStrategy(SortingStrategy.SORT_BY_RATING));
|
||||
break;
|
||||
case "forsale":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
||||
@ -270,15 +264,10 @@ public class ListCmd extends SubCommand {
|
||||
Captions.PERMISSION_LIST_FOR_SALE);
|
||||
return false;
|
||||
}
|
||||
if (EconHandler.manager == null) {
|
||||
if (EconHandler.getEconHandler() == null) {
|
||||
break;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getFlag(PriceFlag.class) > 0) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0));
|
||||
break;
|
||||
case "unowned":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
|
||||
@ -286,28 +275,7 @@ public class ListCmd extends SubCommand {
|
||||
Captions.PERMISSION_LIST_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getOwner() == null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "unknown":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNKNOWN)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_LIST_UNKNOWN);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getOwner() == null) {
|
||||
continue;
|
||||
}
|
||||
if (UUIDHandler.getName(plot.getOwner()) == null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getOwner() == null));
|
||||
break;
|
||||
case "fuzzy":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FUZZY)) {
|
||||
@ -325,8 +293,8 @@ public class ListCmd extends SubCommand {
|
||||
} else {
|
||||
term = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||
}
|
||||
plots = MainUtil.getPlotsBySearch(term);
|
||||
sort = false;
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term));
|
||||
break;
|
||||
default:
|
||||
if (PlotSquared.get().hasPlotArea(args[0])) {
|
||||
@ -343,50 +311,43 @@ public class ListCmd extends SubCommand {
|
||||
args[0]));
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PlotSquared.get().getPlots(args[0]));
|
||||
plotConsumer.accept(PlotQuery.newQuery().inWorld(args[0]));
|
||||
break;
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(args[0], null);
|
||||
|
||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getSingle(args[0], (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null) {
|
||||
if (uuid == null) {
|
||||
try {
|
||||
uuid = UUID.fromString(args[0]);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (uuid != null) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||
} else {
|
||||
if (!Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_LIST_PLAYER);
|
||||
return false;
|
||||
} else {
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().ownedBy(uuid).withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
}
|
||||
sort = false;
|
||||
plots = PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getPlots(uuid));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (plots == null) {
|
||||
sendMessage(player, Captions.DID_YOU_MEAN,
|
||||
new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"})
|
||||
.getBestMatch());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plots.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
displayPlots(player, plots, 12, page, area, args, sort);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void displayPlots(final PlotPlayer player, List<Plot> plots, int pageSize, int page,
|
||||
PlotArea area, String[] args, boolean sort) {
|
||||
public void displayPlots(final PlotPlayer player, List<Plot> plots, int pageSize, int page, String[] args) {
|
||||
// Header
|
||||
plots.removeIf(plot -> !plot.isBasePlot());
|
||||
if (sort) {
|
||||
plots = PlotSquared.get().sortPlots(plots, SortType.CREATION_DATE, area);
|
||||
}
|
||||
this.paginate(player, plots, pageSize, page,
|
||||
new RunnableVal3<Integer, Plot, PlotMessage>() {
|
||||
@Override public void run(Integer i, Plot plot, PlotMessage message) {
|
||||
@ -417,25 +378,72 @@ public class ListCmd extends SubCommand {
|
||||
.command("/plot info " + plot.getArea() + ";" + plot.getId()).color(color)
|
||||
.text(" - ").color("$2");
|
||||
String prefix = "";
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
String name = UUIDHandler.getName(uuid);
|
||||
if (name == null) {
|
||||
message = message.text(prefix).color("$4").text("unknown").color("$2")
|
||||
.tooltip(uuid.toString()).suggest(uuid.toString());
|
||||
} else {
|
||||
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
|
||||
|
||||
try {
|
||||
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline()
|
||||
.getNames(plot.getOwners()).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
for (final UUIDMapping uuidMapping : names) {
|
||||
PlotPlayer pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
|
||||
if (pp != null) {
|
||||
message = message.text(prefix).color("$4").text(name).color("$1")
|
||||
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
|
||||
.tooltip(new PlotMessage("Online").color("$4"));
|
||||
} else {
|
||||
message = message.text(prefix).color("$4").text(name).color("$1")
|
||||
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
|
||||
.tooltip(new PlotMessage("Offline").color("$3"));
|
||||
}
|
||||
}
|
||||
prefix = ", ";
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
|
||||
} catch (TimeoutException e) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
}
|
||||
}
|
||||
}, "/plot list " + args[0], Captions.PLOT_LIST_HEADER_PAGED.getTranslated());
|
||||
}
|
||||
|
||||
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||
final List<String> completions = new LinkedList<>();
|
||||
if (EconHandler.getEconHandler() != null && Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
||||
completions.add("forsale");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) {
|
||||
completions.add("mine");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_SHARED)) {
|
||||
completions.add("shared");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
|
||||
completions.addAll(PlotSquared.imp().getWorldManager().getWorlds());
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_TOP)) {
|
||||
completions.add("top");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_ALL)) {
|
||||
completions.add("all");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
|
||||
completions.add("unowned");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_DONE)) {
|
||||
completions.add("done");
|
||||
}
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_EXPIRED)) {
|
||||
completions.add("expired");
|
||||
}
|
||||
|
||||
final List<Command> commands = new LinkedList<>();
|
||||
commands.addAll(completions.stream()
|
||||
.filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.TELEPORT) {})
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ import java.util.List;
|
||||
usage = "/plot load")
|
||||
public class Load extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
String world = player.getLocation().getWorld();
|
||||
if (!PlotSquared.get().hasPlotArea(world)) {
|
||||
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
|
||||
@ -152,7 +152,7 @@ public class Load extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void displaySaves(PlotPlayer player) {
|
||||
public void displaySaves(PlotPlayer<?> player) {
|
||||
List<String> schematics = player.getMeta("plot_schematics");
|
||||
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
|
||||
try {
|
||||
|
@ -99,7 +99,6 @@ public class MainCommand extends Command {
|
||||
new DebugPaste();
|
||||
new Unlink();
|
||||
new Kick();
|
||||
new DebugClaimTest();
|
||||
new Inbox();
|
||||
new Comment();
|
||||
new DatabaseCommand();
|
||||
@ -165,14 +164,14 @@ public class MainCommand extends Command {
|
||||
public void run(final Command cmd, final Runnable success, final Runnable failure) {
|
||||
if (cmd.hasConfirmation(player)) {
|
||||
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
|
||||
if (EconHandler.manager != null) {
|
||||
if (EconHandler.getEconHandler() != null) {
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
if (area != null) {
|
||||
Expression<Double> priceEval =
|
||||
area.getPrices().get(cmd.getFullId());
|
||||
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||
if (price != null
|
||||
&& EconHandler.manager.getMoney(player) < price) {
|
||||
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
||||
if (failure != null) {
|
||||
failure.run();
|
||||
}
|
||||
@ -186,12 +185,12 @@ public class MainCommand extends Command {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (EconHandler.manager != null) {
|
||||
if (EconHandler.getEconHandler() != null) {
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
if (area != null) {
|
||||
Expression<Double> priceEval = area.getPrices().get(cmd.getFullId());
|
||||
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||
if (price != 0d && EconHandler.manager.getMoney(player) < price) {
|
||||
if (price != 0d && EconHandler.getEconHandler().getMoney(player) < price) {
|
||||
if (failure != null) {
|
||||
failure.run();
|
||||
}
|
||||
@ -218,7 +217,7 @@ public class MainCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
// Clear perm caching //
|
||||
@ -253,14 +252,14 @@ public class MainCommand extends Command {
|
||||
if ("f".equals(args[0].substring(1))) {
|
||||
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
|
||||
@Override public void run(Command cmd, Runnable success, Runnable failure) {
|
||||
if (EconHandler.manager != null) {
|
||||
if (EconHandler.getEconHandler() != null) {
|
||||
PlotArea area = player.getApplicablePlotArea();
|
||||
if (area != null) {
|
||||
Expression<Double> priceEval =
|
||||
area.getPrices().get(cmd.getFullId());
|
||||
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||
if (price != 0d
|
||||
&& EconHandler.manager.getMoney(player) < price) {
|
||||
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
||||
if (failure != null) {
|
||||
failure.run();
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import com.plotsquared.core.util.Expression;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -79,7 +78,7 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocationFull();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
@ -157,8 +156,8 @@ public class Merge extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) {
|
||||
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
|
||||
EconHandler.manager.withdrawMoney(player, price);
|
||||
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
|
||||
EconHandler.getEconHandler().withdrawMoney(player, price);
|
||||
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
||||
@ -172,11 +171,11 @@ public class Merge extends SubCommand {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
return false;
|
||||
} else {
|
||||
uuid = plot.guessOwner();
|
||||
uuid = plot.getOwnerAbs();
|
||||
}
|
||||
}
|
||||
if (!force && EconHandler.manager != null && plotArea.useEconomy() && price > 0d
|
||||
&& EconHandler.manager.getMoney(player) < price) {
|
||||
if (!force && EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d
|
||||
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
||||
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
|
||||
return false;
|
||||
}
|
||||
@ -193,8 +192,8 @@ public class Merge extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) {
|
||||
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
|
||||
EconHandler.manager.withdrawMoney(player, price);
|
||||
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
|
||||
EconHandler.getEconHandler().withdrawMoney(player, price);
|
||||
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
||||
@ -213,7 +212,7 @@ public class Merge extends SubCommand {
|
||||
java.util.Set<UUID> uuids = adjacent.getOwners();
|
||||
boolean isOnline = false;
|
||||
for (final UUID owner : uuids) {
|
||||
final PlotPlayer accepter = UUIDHandler.getPlayer(owner);
|
||||
final PlotPlayer accepter = PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner);
|
||||
if (!force && accepter == null) {
|
||||
continue;
|
||||
}
|
||||
@ -222,17 +221,17 @@ public class Merge extends SubCommand {
|
||||
Runnable run = () -> {
|
||||
MainUtil.sendMessage(accepter, Captions.MERGE_ACCEPTED);
|
||||
plot.autoMerge(dir, maxSize - size, owner, terrain);
|
||||
PlotPlayer plotPlayer = UUIDHandler.getPlayer(player.getUUID());
|
||||
PlotPlayer plotPlayer = PlotSquared.imp().getPlayerManager().getPlayerIfExists(player.getUUID());
|
||||
if (plotPlayer == null) {
|
||||
sendMessage(accepter, Captions.MERGE_NOT_VALID);
|
||||
return;
|
||||
}
|
||||
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
|
||||
if (!force && EconHandler.manager.getMoney(player) < price) {
|
||||
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
|
||||
if (!force && EconHandler.getEconHandler().getMoney(player) < price) {
|
||||
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
|
||||
return;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(player, price);
|
||||
EconHandler.getEconHandler().withdrawMoney(player, price);
|
||||
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
||||
|
@ -42,7 +42,7 @@ import com.plotsquared.core.plot.Plot;
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Middle extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] arguments) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
|
@ -47,7 +47,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class Move extends SubCommand {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
Location location = player.getLocation();
|
||||
@ -107,7 +107,7 @@ public class Move extends SubCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class Music extends SubCommand {
|
||||
"music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal",
|
||||
"music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait");
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
Location location = player.getLocation();
|
||||
final Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
|
@ -46,7 +46,7 @@ public class Near extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
||||
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
|
||||
|
@ -36,10 +36,11 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@CommandDeclaration(command = "setowner",
|
||||
permission = "plots.set.owner",
|
||||
@ -57,26 +58,19 @@ public class Owner extends SetCommand {
|
||||
return false;
|
||||
}
|
||||
Set<Plot> plots = plot.getConnectedPlots();
|
||||
UUID uuid = null;
|
||||
if (value.length() == 36) {
|
||||
try {
|
||||
uuid = UUID.fromString(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(value, null);
|
||||
}
|
||||
|
||||
final Consumer<UUID> uuidConsumer = uuid -> {
|
||||
if (uuid == null && !value.equalsIgnoreCase("none") && !value.equalsIgnoreCase("null")
|
||||
&& !value.equalsIgnoreCase("-")) {
|
||||
Captions.INVALID_PLAYER.send(player, value);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher()
|
||||
.callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid,
|
||||
plot.hasOwner());
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
sendMessage(player, Captions.EVENT_DENIED, "Owner change");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
uuid = event.getNewOwner();
|
||||
boolean force = event.getEventResult() == Result.FORCE;
|
||||
@ -84,13 +78,13 @@ public class Owner extends SetCommand {
|
||||
if (!force && !Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SET_OWNER.getTranslated(),
|
||||
true)) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
PlotUnlinkEvent unlinkEvent = PlotSquared.get().getEventDispatcher()
|
||||
.callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER);
|
||||
if (unlinkEvent.getEventResult() == Result.DENY) {
|
||||
sendMessage(player, Captions.EVENT_DENIED, "Unlink on owner change");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
plot.unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad());
|
||||
Set<Plot> connected = plot.getConnectedPlots();
|
||||
@ -99,18 +93,18 @@ public class Owner extends SetCommand {
|
||||
current.removeSign();
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.SET_OWNER);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
final PlotPlayer other = UUIDHandler.getPlayer(uuid);
|
||||
final PlotPlayer other = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (plot.isOwner(uuid)) {
|
||||
Captions.ALREADY_OWNER.send(player, MainUtil.getName(uuid));
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (!force && !Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SET_OWNER)) {
|
||||
if (other == null) {
|
||||
Captions.INVALID_PLAYER_OFFLINE.send(player, value);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
int size = plots.size();
|
||||
int currentPlots = (Settings.Limit.GLOBAL ?
|
||||
@ -118,11 +112,11 @@ public class Owner extends SetCommand {
|
||||
other.getPlotCount(plot.getWorldName())) + size;
|
||||
if (currentPlots > other.getAllowedPlots()) {
|
||||
sendMessage(player, Captions.CANT_TRANSFER_MORE_PLOTS);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
final String finalName = UUIDHandler.getName(uuid);
|
||||
final UUID finalUUID = uuid;
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(uuid, (finalName, throwable) -> {
|
||||
final boolean removeDenied = plot.isDenied(finalUUID);
|
||||
Runnable run = () -> {
|
||||
if (plot.setOwner(finalUUID, player)) {
|
||||
@ -143,6 +137,25 @@ public class Owner extends SetCommand {
|
||||
} else {
|
||||
TaskManager.runTask(run);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (value.length() == 36) {
|
||||
try {
|
||||
uuidConsumer.accept(UUID.fromString(value));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} else {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(value, (uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
} else if (throwable != null) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, value);
|
||||
} else {
|
||||
uuidConsumer.accept(uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
category = CommandCategory.INFO)
|
||||
public class PluginCmd extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
TaskManager.IMP.taskAsync(() -> {
|
||||
MainUtil.sendMessage(player, String.format(
|
||||
"$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)",
|
||||
|
@ -36,7 +36,6 @@ 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.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -54,7 +53,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
confirmation = true)
|
||||
public class Purge extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
@ -65,7 +64,6 @@ public class Purge extends SubCommand {
|
||||
PlotId id = null;
|
||||
UUID owner = null;
|
||||
UUID added = null;
|
||||
boolean unknown = false;
|
||||
boolean clear = false;
|
||||
for (String arg : args) {
|
||||
String[] split = arg.split(":");
|
||||
@ -97,7 +95,7 @@ public class Purge extends SubCommand {
|
||||
break;
|
||||
case "owner":
|
||||
case "o":
|
||||
owner = UUIDHandler.getUUID(split[1], null);
|
||||
owner = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(split[1], Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (owner == null) {
|
||||
Captions.INVALID_PLAYER.send(player, split[1]);
|
||||
return false;
|
||||
@ -105,17 +103,12 @@ public class Purge extends SubCommand {
|
||||
break;
|
||||
case "shared":
|
||||
case "s":
|
||||
added = UUIDHandler.getUUID(split[1], null);
|
||||
added = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(split[1], Settings.UUID.BLOCKING_TIMEOUT);
|
||||
if (added == null) {
|
||||
Captions.INVALID_PLAYER.send(player, split[1]);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "unknown":
|
||||
case "?":
|
||||
case "u":
|
||||
unknown = Boolean.parseBoolean(split[1]);
|
||||
break;
|
||||
case "clear":
|
||||
case "c":
|
||||
case "delete":
|
||||
@ -145,9 +138,6 @@ public class Purge extends SubCommand {
|
||||
if (added != null && !plot.isAdded(added)) {
|
||||
continue;
|
||||
}
|
||||
if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) {
|
||||
continue;
|
||||
}
|
||||
toDelete.addAll(plot.getConnectedPlots());
|
||||
}
|
||||
if (PlotSquared.get().plots_tmp != null) {
|
||||
@ -168,9 +158,6 @@ public class Purge extends SubCommand {
|
||||
if (added != null && !plot.isAdded(added)) {
|
||||
continue;
|
||||
}
|
||||
if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) {
|
||||
continue;
|
||||
}
|
||||
toDelete.add(plot);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ import java.util.UUID;
|
||||
requiredType = RequiredType.PLAYER)
|
||||
public class Rate extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "next": {
|
||||
|
@ -43,7 +43,7 @@ import com.plotsquared.core.util.MainUtil;
|
||||
permission = "plots.regenallroads")
|
||||
public class RegenAllRoads extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
int height = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
|
@ -47,7 +47,7 @@ public class Relight extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
|
||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||
RunnableVal2<Command, CommandResult> whenDone) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
|
@ -45,7 +45,7 @@ import java.util.Objects;
|
||||
category = CommandCategory.ADMINISTRATION)
|
||||
public class Reload extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
try {
|
||||
// The following won't affect world generation, as that has to be
|
||||
// loaded during startup unfortunately.
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user