mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-02 23:43:50 +01:00
Use Paper player profiles if available.
Also fall back to caching to memory if SQLite can't be linked. This is a common issue with (bad) server hosts who mount /tmp as noexec, which causes sqlite's native binaries to fail to link.
This commit is contained in:
parent
11a1ac6742
commit
14fe2d0e79
@ -16,9 +16,14 @@
|
|||||||
<allow pkg="org.khelekore"/>
|
<allow pkg="org.khelekore"/>
|
||||||
<allow pkg="org.flywaydb"/>
|
<allow pkg="org.flywaydb"/>
|
||||||
<allow pkg="org.yaml"/>
|
<allow pkg="org.yaml"/>
|
||||||
<allow pkg="org.json"/>
|
|
||||||
<allow pkg="org.enginehub.piston"/>
|
<allow pkg="org.enginehub.piston"/>
|
||||||
|
|
||||||
|
<subpackage name="util.profile.resolver">
|
||||||
|
<allow pkg="org.bukkit"/>
|
||||||
|
<allow pkg="io.papermc.lib"/>
|
||||||
|
<allow pkg="com.destroystokyo.paper"/>
|
||||||
|
</subpackage>
|
||||||
|
|
||||||
<subpackage name="bukkit">
|
<subpackage name="bukkit">
|
||||||
<allow pkg="org.bukkit"/>
|
<allow pkg="org.bukkit"/>
|
||||||
<allow pkg="org.bstats.bukkit"/>
|
<allow pkg="org.bstats.bukkit"/>
|
||||||
@ -26,16 +31,6 @@
|
|||||||
<allow pkg="com.destroystokyo.paper"/>
|
<allow pkg="com.destroystokyo.paper"/>
|
||||||
</subpackage>
|
</subpackage>
|
||||||
|
|
||||||
<subpackage name="sponge">
|
|
||||||
<allow pkg="org.spongepowered"/>
|
|
||||||
<allow pkg="org.bstats.sponge"/>
|
|
||||||
<allow pkg="com.flowpowered"/>
|
|
||||||
</subpackage>
|
|
||||||
|
|
||||||
<subpackage name="forge">
|
|
||||||
<allow pkg="net.minecraft"/>
|
|
||||||
<allow pkg="net.minecraftforge"/>
|
|
||||||
</subpackage>
|
|
||||||
</subpackage>
|
</subpackage>
|
||||||
|
|
||||||
</import-control>
|
</import-control>
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.PaperProfileService;
|
||||||
import com.sk89q.worldguard.bukkit.protection.events.flags.FlagContextCreateEvent;
|
import com.sk89q.worldguard.bukkit.protection.events.flags.FlagContextCreateEvent;
|
||||||
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
|
import com.sk89q.worldguard.bukkit.session.BukkitSessionManager;
|
||||||
import com.sk89q.worldguard.bukkit.util.report.PerformanceReport;
|
import com.sk89q.worldguard.bukkit.util.report.PerformanceReport;
|
||||||
@ -39,12 +40,20 @@
|
|||||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.session.SessionManager;
|
import com.sk89q.worldguard.session.SessionManager;
|
||||||
|
import com.sk89q.worldguard.util.profile.cache.ProfileCache;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.BukkitPlayerService;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.CacheForwardingService;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.CombinedProfileService;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.HttpRepositoryService;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.ProfileService;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -228,4 +237,18 @@ public void addPlatformReports(ReportList report) {
|
|||||||
report.add(new WorldReport());
|
report.add(new WorldReport());
|
||||||
report.add(new PerformanceReport());
|
report.add(new PerformanceReport());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfileService createProfileService(ProfileCache profileCache) {
|
||||||
|
List<ProfileService> services = new ArrayList<>();
|
||||||
|
if (PaperLib.isPaper()) {
|
||||||
|
// Paper has a shared cache, and will do lookups for us if needed
|
||||||
|
services.add(PaperProfileService.getInstance());
|
||||||
|
} else {
|
||||||
|
services.add(BukkitPlayerService.getInstance());
|
||||||
|
services.add(HttpRepositoryService.forMinecraft());
|
||||||
|
}
|
||||||
|
return new CacheForwardingService(new CombinedProfileService(services),
|
||||||
|
profileCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldGuard team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.util.profile.resolver;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||||
|
import com.sk89q.worldguard.util.profile.Profile;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public final class PaperProfileService extends SingleRequestService {
|
||||||
|
private static final PaperProfileService INSTANCE = new PaperProfileService();
|
||||||
|
|
||||||
|
private PaperProfileService() {
|
||||||
|
if (!PaperLib.isPaper()) {
|
||||||
|
throw new IllegalStateException("Attempt to access PaperProfileService on non-Paper server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIdealRequestLimit() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Profile findByName(String name) {
|
||||||
|
PlayerProfile profile = Bukkit.createProfile(name);
|
||||||
|
if (profile.complete(false)) {
|
||||||
|
//noinspection ConstantConditions - completeFromCache guarantees non-null on success
|
||||||
|
return new Profile(profile.getId(), profile.getName());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PaperProfileService getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
@ -27,10 +27,6 @@
|
|||||||
import com.sk89q.worldguard.util.profile.cache.HashMapCache;
|
import com.sk89q.worldguard.util.profile.cache.HashMapCache;
|
||||||
import com.sk89q.worldguard.util.profile.cache.ProfileCache;
|
import com.sk89q.worldguard.util.profile.cache.ProfileCache;
|
||||||
import com.sk89q.worldguard.util.profile.cache.SQLiteCache;
|
import com.sk89q.worldguard.util.profile.cache.SQLiteCache;
|
||||||
import com.sk89q.worldguard.util.profile.resolver.BukkitPlayerService;
|
|
||||||
import com.sk89q.worldguard.util.profile.resolver.CacheForwardingService;
|
|
||||||
import com.sk89q.worldguard.util.profile.resolver.CombinedProfileService;
|
|
||||||
import com.sk89q.worldguard.util.profile.resolver.HttpRepositoryService;
|
|
||||||
import com.sk89q.worldguard.util.profile.resolver.ProfileService;
|
import com.sk89q.worldguard.util.profile.resolver.ProfileService;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.util.task.SimpleSupervisor;
|
import com.sk89q.worldedit.util.task.SimpleSupervisor;
|
||||||
@ -85,16 +81,12 @@ public void setup() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
profileCache = new SQLiteCache(new File(cacheDir, "profiles.sqlite"));
|
profileCache = new SQLiteCache(new File(cacheDir, "profiles.sqlite"));
|
||||||
} catch (IOException e) {
|
} catch (IOException | UnsatisfiedLinkError ignored) {
|
||||||
logger.log(Level.WARNING, "Failed to initialize SQLite profile cache");
|
logger.log(Level.WARNING, "Failed to initialize SQLite profile cache. Cache is memory-only.");
|
||||||
profileCache = new HashMapCache();
|
profileCache = new HashMapCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
profileService = new CacheForwardingService(
|
profileService = getPlatform().createProfileService(profileCache);
|
||||||
new CombinedProfileService(
|
|
||||||
BukkitPlayerService.getInstance(),
|
|
||||||
HttpRepositoryService.forMinecraft()),
|
|
||||||
profileCache);
|
|
||||||
|
|
||||||
getPlatform().load();
|
getPlatform().load();
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.session.SessionManager;
|
import com.sk89q.worldguard.session.SessionManager;
|
||||||
|
import com.sk89q.worldguard.util.profile.cache.ProfileCache;
|
||||||
|
import com.sk89q.worldguard.util.profile.resolver.ProfileService;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
@ -148,4 +150,9 @@ public interface WorldGuardPlatform {
|
|||||||
* @param report The reportlist
|
* @param report The reportlist
|
||||||
*/
|
*/
|
||||||
void addPlatformReports(ReportList report);
|
void addPlatformReports(ReportList report);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal use.
|
||||||
|
*/
|
||||||
|
ProfileService createProfileService(ProfileCache profileCache);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user