Ability to modify api

This commit is contained in:
Sotr
2019-04-10 02:22:38 +08:00
parent 17e0e3edca
commit b2b93d9f87
1055 changed files with 107079 additions and 12 deletions

View File

@@ -1,17 +0,0 @@
package co.aikar.timings;
public class ThreadAssertion {
private static boolean mainThread;
public static boolean is() {
return mainThread;
}
static void start() {
mainThread = true;
}
public static void close() {
mainThread = false;
}
}

View File

@@ -1,87 +0,0 @@
/*
* This file is licensed under the MIT License (MIT).
*
* Copyright (c) 2014 Daniel Ennis <http://aikar.co>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package co.aikar.timings;
import javax.annotation.Nonnull; // Akarin - javax.annotation
import javax.annotation.Nullable; // Akarin - javax.annotation
/**
* Provides an ability to time sections of code within the Minecraft Server
*/
public interface Timing extends AutoCloseable {
/**
* Starts timing the execution until {@link #stopTiming()} is called.
*
* @return Timing
*/
@Nonnull // Akarin - javax.annotation
Timing startTiming();
default Timing startTiming(boolean assertThread) { return startTiming(); }; // Akarin
default Timing startTimingUnsafe() { return startTiming(); }; // Akarin
/**
* <p>Stops timing and records the data. Propagates the data up to group handlers.</p>
*
* Will automatically be called when this Timing is used with try-with-resources
*/
void stopTiming();
default void stopTimingUnsafe() { stopTiming(); }; // Akarin
/**
* Starts timing the execution until {@link #stopTiming()} is called.
*
* But only if we are on the primary thread.
*
* @return Timing
*/
@Nonnull // Akarin - javax.annotation
Timing startTimingIfSync();
default Timing startTimingIfSync(boolean assertThread) { return startTimingIfSync(); }; // Akarin
/**
* <p>Stops timing and records the data. Propagates the data up to group handlers.</p>
*
* <p>Will automatically be called when this Timing is used with try-with-resources</p>
*
* But only if we are on the primary thread.
*/
void stopTimingIfSync();
/**
* @deprecated Doesn't do anything - Removed
*/
@Deprecated
void abort();
/**
* Used internally to get the actual backing Handler in the case of delegated Handlers
*
* @return TimingHandler
*/
@Nullable
TimingHandler getTimingHandler();
@Override
void close();
}

View File

@@ -1,256 +0,0 @@
/*
* This file is licensed under the MIT License (MIT).
*
* Copyright (c) 2014 Daniel Ennis <http://aikar.co>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package co.aikar.timings;
import co.aikar.util.LoadingIntMap;
import io.akarin.server.core.AkarinGlobalConfig;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull; // Akarin - javax.annotation
import javax.annotation.Nullable; // Akarin - javax.annotation
import org.bukkit.Bukkit;
class TimingHandler implements Timing {
private static AtomicInteger idPool = new AtomicInteger(1);
private static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
final int id = idPool.getAndIncrement();
final TimingIdentifier identifier;
private final boolean verbose;
private final Int2ObjectOpenHashMap<TimingData> children = new LoadingIntMap<>(TimingData::new);
final TimingData record;
private final TimingHandler groupHandler;
private long start = 0;
private int timingDepth = 0;
private boolean added;
private boolean timed;
private boolean enabled;
TimingHandler(@Nonnull TimingIdentifier id) { // Akarin - javax.annotation
this.identifier = id;
this.verbose = id.name.startsWith("##");
this.record = new TimingData(this.id);
this.groupHandler = id.groupHandler;
TimingIdentifier.getGroup(id.group).handlers.add(this);
checkEnabled();
}
final void checkEnabled() {
enabled = Timings.timingsEnabled && (!verbose || Timings.verboseEnabled);
}
void processTick(boolean violated) {
if (timingDepth != 0 || record.getCurTickCount() == 0) {
timingDepth = 0;
start = 0;
return;
}
record.processTick(violated);
for (TimingData handler : children.values()) {
handler.processTick(violated);
}
}
@Nonnull // Akarin - javax.annotation
@Override
public Timing startTimingIfSync() {
// Akarin start
return startTiming(false);
}
@Nonnull // Akarin - javax.annotation
@Override
public Timing startTimingIfSync(boolean assertThread) {
startTiming(assertThread);
// Akarin end
return this;
}
@Override
public void stopTimingIfSync() {
stopTiming();
}
@Nonnull // Akarin - javax.annotation
public Timing startTiming() {
// Akarin start
return startTiming(false);
}
@Override
public Timing startTimingUnsafe() {
if (enabled && ++timingDepth == 1) {
ThreadAssertion.close();
// Akarin end
start = System.nanoTime();
TIMING_STACK.addLast(this);
}
return this;
}
// Akarin start
@Override
public Timing startTiming(boolean assertThread) {
if (enabled && (ThreadAssertion.is() || Bukkit.isPrimaryThread()) && ++timingDepth == 1) {
start = System.nanoTime();
TIMING_STACK.addLast(this);
if (assertThread && AkarinGlobalConfig.lazyThreadAssertion)
ThreadAssertion.start();
}
return this;
}
@Override
public void stopTimingUnsafe() {
if (enabled && timingDepth > 0 && --timingDepth == 0 && start != 0) {
TimingHandler last = TIMING_STACK.removeLast();
if (last != this) {
Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to Paper! ( " + this.identifier + ":" + last +")", new Throwable());
TIMING_STACK.addLast(last); // Add it back
}
addDiff(System.nanoTime() - start, TIMING_STACK.peekLast());
start = 0;
ThreadAssertion.close();
}
}
// Akarin end
public void stopTiming() {
if (enabled && timingDepth > 0 && (ThreadAssertion.is() || Bukkit.isPrimaryThread()) && --timingDepth == 0 && start != 0) { // Akarin
TimingHandler last;
while ((last = TIMING_STACK.removeLast()) != this) {
last.timingDepth = 0;
String reportTo;
if ("minecraft".equals(last.identifier.group)) {
reportTo = "Paper! This is a potential bug in Paper";
} else {
reportTo = "the plugin " + last.identifier.group + "(Look for errors above this in the logs)";
}
Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to " + reportTo + " (" + last.identifier +" did not stopTiming)", new Throwable());
}
addDiff(System.nanoTime() - start, TIMING_STACK.peekLast());
start = 0;
// Akarin start
if (AkarinGlobalConfig.lazyThreadAssertion)
ThreadAssertion.close();
// Akarin end
}
}
@Override
public final void abort() {
}
void addDiff(long diff, @Nullable TimingHandler parent) {
if (parent != null) {
parent.children.get(id).add(diff);
}
record.add(diff);
if (!added) {
added = true;
timed = true;
TimingsManager.HANDLERS.add(this);
}
if (groupHandler != null) {
groupHandler.addDiff(diff, parent);
groupHandler.children.get(id).add(diff);
}
}
/**
* Reset this timer, setting all values to zero.
*/
void reset(boolean full) {
record.reset();
if (full) {
timed = false;
}
start = 0;
timingDepth = 0;
added = false;
children.clear();
checkEnabled();
}
@Nonnull // Akarin - javax.annotation
@Override
public TimingHandler getTimingHandler() {
return this;
}
@Override
public boolean equals(Object o) {
return (this == o);
}
@Override
public int hashCode() {
return id;
}
/**
* This is simply for the Closeable interface so it can be used with try-with-resources ()
*/
@Override
public void close() {
if (ThreadAssertion.is()) stopTimingUnsafe(); else stopTimingIfSync(); // Akarin
}
public boolean isSpecial() {
return this == TimingsManager.FULL_SERVER_TICK || this == TimingsManager.TIMINGS_TICK;
}
boolean isTimed() {
return timed;
}
public boolean isEnabled() {
return enabled;
}
@Nonnull // Akarin - javax.annotation
TimingData[] cloneChildren() {
final TimingData[] clonedChildren = new TimingData[children.size()];
int i = 0;
for (TimingData child : children.values()) {
clonedChildren[i++] = child.clone();
}
return clonedChildren;
}
}

View File

@@ -1,217 +0,0 @@
package io.akarin.server.core;
import com.google.common.base.Throwables;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@SuppressWarnings({"UnusedIsStillUsed", "unused"})
public class AkarinGlobalConfig {
private static File CONFIG_FILE;
private static final String HEADER = "This is the global configuration file for Akarin.\n"
+ "Some options may impact gameplay, so use with caution,\n"
+ "and make sure you know what each option does before configuring.\n"
+ "\n"
+ "Akarin website: https://akarin.io/ \n";
/*========================================================================*/
public static YamlConfiguration config;
static int version;
/*========================================================================*/
public static void init(File configFile) {
CONFIG_FILE = configFile;
config = new YamlConfiguration();
try {
config.load(CONFIG_FILE);
} catch (IOException ex) {
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().severe("Could not load akarin.yml, please correct your syntax errors");
ex.printStackTrace();
throw Throwables.propagate(ex);
}
config.options().header(HEADER);
config.options().copyDefaults(true);
version = getInt("config-version", 3);
set("config-version", 3);
readConfig(AkarinGlobalConfig.class, null);
}
static void readConfig(Class<?> clazz, Object instance) {
for (Method method : clazz.getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers())) {
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
try {
method.setAccessible(true);
method.invoke(instance);
} catch (InvocationTargetException ex) {
throw Throwables.propagate(ex.getCause());
} catch (Exception ex) {
Bukkit.getLogger().severe("Error invoking " + method);
ex.printStackTrace();
}
}
}
}
try {
config.save(CONFIG_FILE);
} catch (IOException ex) {
Bukkit.getLogger().severe("Could not save " + CONFIG_FILE);
ex.printStackTrace();
}
}
private static final Pattern SPACE = Pattern.compile(" ");
private static final Pattern NOT_NUMERIC = Pattern.compile("[^-\\d.]");
public static int getSeconds(String str) {
str = SPACE.matcher(str).replaceAll("");
final char unit = str.charAt(str.length() - 1);
str = NOT_NUMERIC.matcher(str).replaceAll("");
double num;
try {
num = Double.parseDouble(str);
} catch (Exception e) {
num = 0D;
}
switch (unit) {
case 'd': num *= (double) 60*60*24; break;
case 'h': num *= (double) 60*60; break;
case 'm': num *= 60; break;
default: case 's': break;
}
return (int) num;
}
protected static String timeSummary(int seconds) {
String time = "";
if (seconds > 60 * 60 * 24) {
time += TimeUnit.SECONDS.toDays(seconds) + "d";
seconds %= 60 * 60 * 24;
}
if (seconds > 60 * 60) {
time += TimeUnit.SECONDS.toHours(seconds) + "h";
seconds %= 60 * 60;
}
if (seconds > 0) {
time += TimeUnit.SECONDS.toMinutes(seconds) + "m";
}
return time;
}
public static void set(String path, Object val) {
config.set(path, val);
}
private static boolean getBoolean(String path, boolean def) {
config.addDefault(path, def);
return config.getBoolean(path, config.getBoolean(path));
}
private static double getDouble(String path, double def) {
config.addDefault(path, def);
return config.getDouble(path, config.getDouble(path));
}
private static float getFloat(String path, float def) {
// TODO: Figure out why getFloat() always returns the default value.
return (float) getDouble(path, def);
}
private static int getInt(String path, int def) {
config.addDefault(path, def);
return config.getInt(path, config.getInt(path));
}
private static <T> List getList(String path, T def) {
config.addDefault(path, def);
return config.getList(path, config.getList(path));
}
private static String getString(String path, String def) {
config.addDefault(path, def);
return config.getString(path, config.getString(path));
}
/*========================================================================*/
public static boolean noResponseDoGC = true;
private static void noResponseDoGC() {
noResponseDoGC = getBoolean("alternative.gc-before-stuck-restart", noResponseDoGC);
}
public static String serverBrandName = "";
private static void serverBrandName() {
serverBrandName = getString("alternative.modified-server-brand-name", serverBrandName);
}
public static int fileIOThreads = 2;
private static void fileIOThreads() {
fileIOThreads = getInt("core.chunk-save-threads", fileIOThreads);
fileIOThreads = fileIOThreads < 1 ? 1 : fileIOThreads;
fileIOThreads = fileIOThreads > 8 ? 8 : fileIOThreads;
}
public static boolean fixPhysicsEventBehaviour = false;
private static void fixPhysicsEventBehavior() {
fixPhysicsEventBehaviour = getBoolean("alternative.fix-physics-event-behaviour", fixPhysicsEventBehaviour);
}
public static boolean lazyThreadAssertion = true;
private static void lazyThreadAssertion() {
lazyThreadAssertion = getBoolean("core.lazy-thread-assertion", lazyThreadAssertion);
}
public static int userCacheExpireDays = 30;
private static void userCacheExpireDays() {
userCacheExpireDays = getSeconds(getString("core.user-cache-expire-time", "30d"));
}
public static double blockbreakAnimationVisibleDistance = 1024;
private static void blockbreakAnimationVisibleDistance() {
double def = 32.00;
if (version == 2)
def = getDouble("alternative.block-break-animation-visible-distance", def);
blockbreakAnimationVisibleDistance = Math.sqrt(getDouble("core.block-break-animation-visible-distance", def));
}
public static boolean enableAsyncLighting = true;
private static void enableAsyncLighting() {
enableAsyncLighting = getBoolean("core.async-lighting.enable", enableAsyncLighting);
}
public static String yggdrasilServerURL = "https://api.mojang.com/";
private static void yggdrasilServerURL() {
yggdrasilServerURL = getString("alternative.yggdrasil.url", yggdrasilServerURL);
}
public static boolean disallowBeforeLogin = false;
private static void disallowBeforeLogin() {
disallowBeforeLogin = getBoolean("alternative.disallow-before-login-event", disallowBeforeLogin);
}
public static boolean allowExcessiveSigns = false;
private static void allowExcessiveSigns() {
allowExcessiveSigns = getBoolean("alternative.allow-excessive-signs", allowExcessiveSigns);
}
public static boolean ignoreRayTraceForSeatableBlocks = false;
private static void ignoreRayTraceForSeatableBlocks() {
ignoreRayTraceForSeatableBlocks = getBoolean("alternative.ignore-ray-trace-for-seatable-blocks", ignoreRayTraceForSeatableBlocks);
}
public static boolean improvedMobSpawnMechanics = false;
private static void improvedMobSpawnMechanics() {
improvedMobSpawnMechanics = getBoolean("core.improved-mob-spawn-mechanics.enable", improvedMobSpawnMechanics);
}
}

View File

@@ -1,338 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.base.Charsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Resources;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
// Paper start
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import com.destroystokyo.paper.VersionHistoryManager;
// Paper end
public class VersionCommand extends BukkitCommand {
public VersionCommand(String name) {
super(name);
this.description = "Gets the version of this server including any plugins in use";
this.usageMessage = "/version [plugin name]";
this.setPermission("bukkit.command.version");
this.setAliases(Arrays.asList("ver", "about"));
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")");
tellHistory(sender); // Paper
sendVersion(sender);
} else {
StringBuilder name = new StringBuilder();
for (String arg : args) {
if (name.length() > 0) {
name.append(' ');
}
name.append(arg);
}
String pluginName = name.toString();
Plugin exactPlugin = Bukkit.getPluginManager().getPlugin(pluginName);
if (exactPlugin != null) {
describeToSender(exactPlugin, sender);
return true;
}
boolean found = false;
pluginName = pluginName.toLowerCase(java.util.Locale.ENGLISH);
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin.getName().toLowerCase(java.util.Locale.ENGLISH).contains(pluginName)) {
describeToSender(plugin, sender);
found = true;
}
}
if (!found) {
sender.sendMessage("This server is not running any plugin by that name.");
sender.sendMessage("Use /plugins to get a list of plugins.");
}
}
return true;
}
// Paper start - show version history
private void tellHistory(final CommandSender sender) {
final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
if (data == null) {
return;
}
final String oldVersion = data.getOldVersion();
if (oldVersion == null) {
return;
}
sender.sendMessage("Previous version: " + oldVersion);
}
// Paper end
private void describeToSender(Plugin plugin, CommandSender sender) {
PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
if (desc.getDescription() != null) {
sender.sendMessage(desc.getDescription());
}
if (desc.getWebsite() != null) {
sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
}
if (!desc.getAuthors().isEmpty()) {
if (desc.getAuthors().size() == 1) {
sender.sendMessage("Author: " + getAuthors(desc));
} else {
sender.sendMessage("Authors: " + getAuthors(desc));
}
}
}
private String getAuthors(final PluginDescriptionFile desc) {
StringBuilder result = new StringBuilder();
List<String> authors = desc.getAuthors();
for (int i = 0; i < authors.size(); i++) {
if (result.length() > 0) {
result.append(ChatColor.WHITE);
if (i < authors.size() - 1) {
result.append(", ");
} else {
result.append(" and ");
}
}
result.append(ChatColor.GREEN);
result.append(authors.get(i));
}
return result.toString();
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
List<String> completions = new ArrayList<String>();
String toComplete = args[0].toLowerCase(java.util.Locale.ENGLISH);
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) {
completions.add(plugin.getName());
}
}
return completions;
}
return ImmutableList.of();
}
private final ReentrantLock versionLock = new ReentrantLock();
private boolean hasVersion = false;
private String versionMessage = null;
private final Set<CommandSender> versionWaiters = new HashSet<CommandSender>();
private boolean versionTaskStarted = false;
private long lastCheck = 0;
private void sendVersion(CommandSender sender) {
if (hasVersion) {
if (System.currentTimeMillis() - lastCheck > 7200000) { // Paper - Lower to 2 hours
lastCheck = System.currentTimeMillis();
hasVersion = false;
} else {
sender.sendMessage(versionMessage);
return;
}
}
versionLock.lock();
try {
if (hasVersion) {
sender.sendMessage(versionMessage);
return;
}
versionWaiters.add(sender);
sender.sendMessage("Checking version, please wait...");
if (!versionTaskStarted) {
versionTaskStarted = true;
new Thread(new Runnable() {
@Override
public void run() {
obtainVersion();
}
}).start();
}
} finally {
versionLock.unlock();
}
}
// Paper start
private void obtainVersion() {
String version = Bukkit.getVersion();
if (version == null) version = "Custom";
if (version.startsWith("git-Akarin-")) { // Akarin
String[] parts = version.substring("git-Akarin-".length()).split("[-\\s]"); // Akarin
int distance = getDistance(null, parts[0]);
switch (distance) {
case -1:
setVersionMessage("Error obtaining version information");
break;
case 0:
setVersionMessage("You are running the latest version");
break;
case -2:
setVersionMessage("Unknown version");
break;
default:
setVersionMessage("You are " + distance + " version(s) behind");
}
} else if (version.startsWith("git-Bukkit-")) {
// Paper end
version = version.substring("git-Bukkit-".length());
int cbVersions = getDistance("craftbukkit", version.substring(0, version.indexOf(' ')));
if (cbVersions == -1) {
setVersionMessage("Error obtaining version information");
} else {
if (cbVersions == 0) {
setVersionMessage("You are running the latest version");
} else {
setVersionMessage("You are " + cbVersions + " version(s) behind");
}
}
} else {
setVersionMessage("Unknown version, custom build?");
}
}
private void setVersionMessage(String msg) {
lastCheck = System.currentTimeMillis();
versionMessage = msg;
versionLock.lock();
try {
hasVersion = true;
versionTaskStarted = false;
for (CommandSender sender : versionWaiters) {
sender.sendMessage(versionMessage);
}
versionWaiters.clear();
} finally {
versionLock.unlock();
}
}
// Paper start
private static int getDistance(String repo, String verInfo) {
// Akarin start
//try {
// int currentVer = Integer.decode(verInfo);
// return getFromJenkins(currentVer);
//} catch (NumberFormatException ex) {
// Akarin end
verInfo = verInfo.replace("\"", "");
return getFromRepo("Akarin-project/Akarin", "master", verInfo); // Akarin
//} // Akarin
/*
BufferedReader reader = Resources.asCharSource(
new URL("https://hub.spigotmc.org/stash/rest/api/1.0/projects/SPIGOT/repos/" + repo + "/commits?since=" + URLEncoder.encode(hash, "UTF-8") + "&withCounts=true"),
Charsets.UTF_8
).openBufferedStream();
try {
JSONObject obj = (JSONObject) new JSONParser().parse(reader);
return ((Number) obj.get("totalCount")).intValue();
} catch (ParseException ex) {
ex.printStackTrace();
return -1;
} finally {
reader.close();
}
*/
}
private static int getFromJenkins(int currentVer) {
try {
BufferedReader reader = Resources.asCharSource(
new URL("https://ci.destroystokyo.com/job/Paper-1.13/lastSuccessfulBuild/buildNumber"), // Paper
Charsets.UTF_8
).openBufferedStream();
try {
int newVer = Integer.decode(reader.readLine());
return newVer - currentVer;
} catch (NumberFormatException ex) {
ex.printStackTrace();
return -2;
} finally {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
return -1;
}
}
// Contributed by Techcable <Techcable@outlook.com> in GH PR #65
private static int getFromRepo(String repo, String branch, String hash) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/" + repo + "/compare/" + branch + "..." + hash).openConnection();
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return -2; // Unknown commit
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))
) {
JSONObject obj = (JSONObject) new JSONParser().parse(reader);
String status = (String) obj.get("status");
switch (status) {
case "identical":
return 0;
case "behind":
return ((Number) obj.get("behind_by")).intValue();
default:
return -1;
}
} catch (ParseException | NumberFormatException e) {
e.printStackTrace();
return -1;
}
} catch (IOException e) {
e.printStackTrace();
return -1;
}
}
// Paper end
}

View File

@@ -1,233 +0,0 @@
package org.bukkit.event;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
import java.util.*;
import java.util.Map.Entry;
/**
* A list of event handlers, stored per-event. Based on lahwran's fevents.
*/
public class HandlerList {
/**
* Handler array. This field being an array is the key to this system's
* speed.
*/
private RegisteredListener[] handlers = null; // Akarin - remove volatile
private boolean dirty = true; // Akarin
/**
* Dynamic handler lists. These are changed using register() and
* unregister() and are automatically baked to the handlers array any time
* they have changed.
*/
private final EnumMap<EventPriority, ArrayList<RegisteredListener>> handlerslots;
/**
* List of all HandlerLists which have been created, for use in bakeAll()
*/
private static ArrayList<HandlerList> allLists = new ArrayList<HandlerList>();
/**
* Bake all handler lists. Best used just after all normal event
* registration is complete, ie just after all plugins are loaded if
* you're using fevents in a plugin system.
*/
public static void bakeAll() {
synchronized (allLists) {
for (HandlerList h : allLists) {
h.bake();
}
}
}
/**
* Unregister all listeners from all handler lists.
*/
public static void unregisterAll() {
synchronized (allLists) {
for (HandlerList h : allLists) {
synchronized (h) {
for (List<RegisteredListener> list : h.handlerslots.values()) {
list.clear();
}
h.dirty = true; // Akarin
}
}
}
}
/**
* Unregister a specific plugin's listeners from all handler lists.
*
* @param plugin plugin to unregister
*/
public static void unregisterAll(Plugin plugin) {
synchronized (allLists) {
for (HandlerList h : allLists) {
h.unregister(plugin);
}
}
}
/**
* Unregister a specific listener from all handler lists.
*
* @param listener listener to unregister
*/
public static void unregisterAll(Listener listener) {
synchronized (allLists) {
for (HandlerList h : allLists) {
h.unregister(listener);
}
}
}
/**
* Create a new handler list and initialize using EventPriority.
* <p>
* The HandlerList is then added to meta-list for use in bakeAll()
*/
public HandlerList() {
handlerslots = new EnumMap<EventPriority, ArrayList<RegisteredListener>>(EventPriority.class);
for (EventPriority o : EventPriority.values()) {
handlerslots.put(o, new ArrayList<RegisteredListener>());
}
synchronized (allLists) {
allLists.add(this);
}
}
/**
* Register a new listener in this handler list
*
* @param listener listener to register
*/
public synchronized void register(RegisteredListener listener) {
if (handlerslots.get(listener.getPriority()).contains(listener))
throw new IllegalStateException("This listener is already registered to priority " + listener.getPriority().toString());
dirty = true; // Akarin
handlerslots.get(listener.getPriority()).add(listener);
}
/**
* Register a collection of new listeners in this handler list
*
* @param listeners listeners to register
*/
public void registerAll(Collection<RegisteredListener> listeners) {
for (RegisteredListener listener : listeners) {
register(listener);
}
}
/**
* Remove a listener from a specific order slot
*
* @param listener listener to remove
*/
public synchronized void unregister(RegisteredListener listener) {
if (handlerslots.get(listener.getPriority()).remove(listener)) {
dirty = true; // Akarin
}
}
/**
* Remove a specific plugin's listeners from this handler
*
* @param plugin plugin to remove
*/
public synchronized void unregister(Plugin plugin) {
boolean changed = false;
for (List<RegisteredListener> list : handlerslots.values()) {
for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext();) {
if (i.next().getPlugin().equals(plugin)) {
i.remove();
changed = true;
}
}
}
if (changed) dirty = true; // Akarin
}
/**
* Remove a specific listener from this handler
*
* @param listener listener to remove
*/
public synchronized void unregister(Listener listener) {
boolean changed = false;
for (List<RegisteredListener> list : handlerslots.values()) {
for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext();) {
if (i.next().getListener().equals(listener)) {
i.remove();
changed = true;
}
}
}
if (changed) dirty = true; // Akarin
}
/**
* Bake HashMap and ArrayLists to 2d array - does nothing if not necessary
*/
public synchronized RegisteredListener[] bake() { // Akarin - add return value
if (!dirty) return handlers; // don't re-bake when still valid // Akarin
dirty = false; // Akarin - mark dirty to prevent any rebaking
List<RegisteredListener> entries = new ArrayList<RegisteredListener>();
for (Entry<EventPriority, ArrayList<RegisteredListener>> entry : handlerslots.entrySet()) {
entries.addAll(entry.getValue());
}
return handlers = entries.toArray(new RegisteredListener[entries.size()]);
}
/**
* Get the baked registered listeners associated with this handler list
*
* @return the array of registered listeners
*/
public RegisteredListener[] getRegisteredListeners() {
//RegisteredListener[] handlers; // Akarin
//while ((handlers = this.handlers) == null) bake(); // This prevents fringe cases of returning null // Akarin
return dirty ? bake() : handlers;
}
/**
* Get a specific plugin's registered listeners associated with this
* handler list
*
* @param plugin the plugin to get the listeners of
* @return the list of registered listeners
*/
public static ArrayList<RegisteredListener> getRegisteredListeners(Plugin plugin) {
ArrayList<RegisteredListener> listeners = new ArrayList<RegisteredListener>();
synchronized (allLists) {
for (HandlerList h : allLists) {
synchronized (h) {
for (List<RegisteredListener> list : h.handlerslots.values()) {
for (RegisteredListener listener : list) {
if (listener.getPlugin().equals(plugin)) {
listeners.add(listener);
}
}
}
}
}
}
return listeners;
}
/**
* Get a list of all handler lists for every event type
*
* @return the list of all handler lists
*/
@SuppressWarnings("unchecked")
public static ArrayList<HandlerList> getHandlerLists() {
synchronized (allLists) {
return (ArrayList<HandlerList>) allLists.clone();
}
}
}

View File

@@ -1,853 +0,0 @@
package org.bukkit.plugin;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.destroystokyo.paper.event.server.ServerExceptionEvent;
import com.destroystokyo.paper.exception.ServerEventException;
import com.destroystokyo.paper.exception.ServerPluginEnableDisableException;
import org.apache.commons.lang.Validate;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommandYamlParser;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.util.FileUtil;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.koloboke.collect.map.hash.HashIntObjMap;
import com.koloboke.collect.map.hash.HashIntObjMaps;
import com.koloboke.collect.map.hash.HashObjObjMap;
import com.koloboke.collect.map.hash.HashObjObjMaps;
import com.koloboke.collect.set.hash.HashObjSets;
/**
* Handles all plugin management from the Server
*/
public final class SimplePluginManager implements PluginManager {
private final Server server;
private final Map<Pattern, PluginLoader> fileAssociations = HashObjObjMaps.newMutableMap(); // Akarin
private final List<Plugin> plugins = new ArrayList<Plugin>();
private final Map<String, Plugin> lookupNames = HashObjObjMaps.newMutableMap(); // Akarin
private File updateDirectory;
private final SimpleCommandMap commandMap;
private Map<String, Permission> permissions = Collections.emptyMap(); // Akarin
private final Object permissionsLock = new Object();
private Map<Boolean, Set<Permission>> defaultPerms; // Akarin
private final Map<String, Map<Permissible, Boolean>> permSubs = HashObjObjMaps.newMutableMap(); // Akarin
private final Object permSubsLock = new Object();
private final Map<Boolean, Map<Permissible, Boolean>> defSubs = HashObjObjMaps.newMutableMap(); // Akarin
private boolean useTimings = false;
public SimplePluginManager(@Nonnull Server instance, @Nonnull SimpleCommandMap commandMap) { // Akarin - javax.annotation
server = instance;
this.commandMap = commandMap;
// Akarin start
HashObjObjMap<Boolean, Set<Permission>> defaultPerms = HashObjObjMaps.newUpdatableMap();
defaultPerms.put(Boolean.TRUE, HashObjSets.newUpdatableSet());
defaultPerms.put(Boolean.FALSE, HashObjSets.newUpdatableSet());
this.defaultPerms = defaultPerms;
// Akarin end
}
/**
* Registers the specified plugin loader
*
* @param loader Class name of the PluginLoader to register
* @throws IllegalArgumentException Thrown when the given Class is not a
* valid PluginLoader
*/
public void registerInterface(@Nonnull Class<? extends PluginLoader> loader) throws IllegalArgumentException { // Akarin - javax.annotation
PluginLoader instance;
if (PluginLoader.class.isAssignableFrom(loader)) {
Constructor<? extends PluginLoader> constructor;
try {
constructor = loader.getConstructor(Server.class);
instance = constructor.newInstance(server);
} catch (NoSuchMethodException ex) {
String className = loader.getName();
throw new IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", className, className), ex);
} catch (Exception ex) {
throw new IllegalArgumentException(String.format("Unexpected exception %s while attempting to construct a new instance of %s", ex.getClass().getName(), loader.getName()), ex);
}
} else {
throw new IllegalArgumentException(String.format("Class %s does not implement interface PluginLoader", loader.getName()));
}
Pattern[] patterns = instance.getPluginFileFilters();
synchronized (this) {
for (Pattern pattern : patterns) {
fileAssociations.put(pattern, instance);
}
}
}
/**
* Loads the plugins contained within the specified directory
*
* @param directory Directory to check for plugins
* @return A list of all plugins loaded
*/
@Nonnull // Akarin - javax.annotation
public Plugin[] loadPlugins(@Nonnull File directory) { // Akarin - javax.annotation
Validate.notNull(directory, "Directory cannot be null");
Validate.isTrue(directory.isDirectory(), "Directory must be a directory");
List<Plugin> result = new ArrayList<Plugin>();
Set<Pattern> filters = fileAssociations.keySet();
if (!(server.getUpdateFolder().equals(""))) {
updateDirectory = new File(directory, server.getUpdateFolder());
}
Map<String, File> plugins = HashObjObjMaps.newMutableMap(); // Akarin
Set<String> loadedPlugins = HashObjSets.newMutableSet(); // Akarin
Map<String, Collection<String>> dependencies = HashObjObjMaps.newMutableMap(); // Akarin
Map<String, Collection<String>> softDependencies = HashObjObjMaps.newMutableMap(); // Akarin
// This is where it figures out all possible plugins
for (File file : directory.listFiles()) {
PluginLoader loader = null;
for (Pattern filter : filters) {
Matcher match = filter.matcher(file.getName());
if (match.find()) {
loader = fileAssociations.get(filter);
}
}
if (loader == null) continue;
PluginDescriptionFile description = null;
try {
description = loader.getPluginDescription(file);
String name = description.getName();
if (name.equalsIgnoreCase("bukkit") || name.equalsIgnoreCase("minecraft") || name.equalsIgnoreCase("mojang")) {
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': Restricted Name");
continue;
} else if (description.rawName.indexOf(' ') != -1) {
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': uses the space-character (0x20) in its name");
continue;
}
} catch (InvalidDescriptionException ex) {
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
continue;
}
File replacedFile = plugins.put(description.getName(), file);
if (replacedFile != null) {
server.getLogger().severe(String.format(
"Ambiguous plugin name `%s' for files `%s' and `%s' in `%s'",
description.getName(),
file.getPath(),
replacedFile.getPath(),
directory.getPath()
));
}
Collection<String> softDependencySet = description.getSoftDepend();
if (softDependencySet != null && !softDependencySet.isEmpty()) {
if (softDependencies.containsKey(description.getName())) {
// Duplicates do not matter, they will be removed together if applicable
softDependencies.get(description.getName()).addAll(softDependencySet);
} else {
softDependencies.put(description.getName(), new LinkedList<String>(softDependencySet));
}
}
Collection<String> dependencySet = description.getDepend();
if (dependencySet != null && !dependencySet.isEmpty()) {
dependencies.put(description.getName(), new LinkedList<String>(dependencySet));
}
Collection<String> loadBeforeSet = description.getLoadBefore();
if (loadBeforeSet != null && !loadBeforeSet.isEmpty()) {
for (String loadBeforeTarget : loadBeforeSet) {
if (softDependencies.containsKey(loadBeforeTarget)) {
softDependencies.get(loadBeforeTarget).add(description.getName());
} else {
// softDependencies is never iterated, so 'ghost' plugins aren't an issue
Collection<String> shortSoftDependency = new LinkedList<String>();
shortSoftDependency.add(description.getName());
softDependencies.put(loadBeforeTarget, shortSoftDependency);
}
}
}
}
while (!plugins.isEmpty()) {
boolean missingDependency = true;
Iterator<Map.Entry<String, File>> pluginIterator = plugins.entrySet().iterator();
while (pluginIterator.hasNext()) {
Map.Entry<String, File> entry = pluginIterator.next();
String plugin = entry.getKey();
if (dependencies.containsKey(plugin)) {
Iterator<String> dependencyIterator = dependencies.get(plugin).iterator();
while (dependencyIterator.hasNext()) {
String dependency = dependencyIterator.next();
// Dependency loaded
if (loadedPlugins.contains(dependency)) {
dependencyIterator.remove();
// We have a dependency not found
} else if (!plugins.containsKey(dependency)) {
missingDependency = false;
pluginIterator.remove();
softDependencies.remove(plugin);
dependencies.remove(plugin);
server.getLogger().log(
Level.SEVERE,
"Could not load '" + entry.getValue().getPath() + "' in folder '" + directory.getPath() + "'",
new UnknownDependencyException(dependency));
break;
}
}
if (dependencies.containsKey(plugin) && dependencies.get(plugin).isEmpty()) {
dependencies.remove(plugin);
}
}
if (softDependencies.containsKey(plugin)) {
Iterator<String> softDependencyIterator = softDependencies.get(plugin).iterator();
while (softDependencyIterator.hasNext()) {
String softDependency = softDependencyIterator.next();
// Soft depend is no longer around
if (!plugins.containsKey(softDependency)) {
softDependencyIterator.remove();
}
}
if (softDependencies.get(plugin).isEmpty()) {
softDependencies.remove(plugin);
}
}
if (!(dependencies.containsKey(plugin) || softDependencies.containsKey(plugin)) && plugins.containsKey(plugin)) {
// We're clear to load, no more soft or hard dependencies left
File file = plugins.get(plugin);
pluginIterator.remove();
missingDependency = false;
try {
result.add(loadPlugin(file));
loadedPlugins.add(plugin);
continue;
} catch (InvalidPluginException ex) {
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
}
}
}
if (missingDependency) {
// We now iterate over plugins until something loads
// This loop will ignore soft dependencies
pluginIterator = plugins.entrySet().iterator();
while (pluginIterator.hasNext()) {
Map.Entry<String, File> entry = pluginIterator.next();
String plugin = entry.getKey();
if (!dependencies.containsKey(plugin)) {
softDependencies.remove(plugin);
missingDependency = false;
File file = entry.getValue();
pluginIterator.remove();
try {
result.add(loadPlugin(file));
loadedPlugins.add(plugin);
break;
} catch (InvalidPluginException ex) {
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
}
}
}
// We have no plugins left without a depend
if (missingDependency) {
softDependencies.clear();
dependencies.clear();
Iterator<File> failedPluginIterator = plugins.values().iterator();
while (failedPluginIterator.hasNext()) {
File file = failedPluginIterator.next();
failedPluginIterator.remove();
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': circular dependency detected");
}
}
}
}
return result.toArray(new Plugin[result.size()]);
}
/**
* Loads the plugin in the specified file
* <p>
* File must be valid according to the current enabled Plugin interfaces
*
* @param file File containing the plugin to load
* @return The Plugin loaded, or null if it was invalid
* @throws InvalidPluginException Thrown when the specified file is not a
* valid plugin
* @throws UnknownDependencyException If a required dependency could not
* be found
*/
@Nullable
public synchronized Plugin loadPlugin(@Nonnull File file) throws InvalidPluginException, UnknownDependencyException { // Akarin - javax.annotation
Validate.notNull(file, "File cannot be null");
checkUpdate(file);
Set<Pattern> filters = fileAssociations.keySet();
Plugin result = null;
for (Pattern filter : filters) {
String name = file.getName();
Matcher match = filter.matcher(name);
if (match.find()) {
PluginLoader loader = fileAssociations.get(filter);
result = loader.loadPlugin(file);
}
}
if (result != null) {
plugins.add(result);
lookupNames.put(result.getDescription().getName().toLowerCase(java.util.Locale.ENGLISH), result); // Paper
}
return result;
}
private void checkUpdate(@Nonnull File file) { // Akarin - javax.annotation
if (updateDirectory == null || !updateDirectory.isDirectory()) {
return;
}
File updateFile = new File(updateDirectory, file.getName());
if (updateFile.isFile() && FileUtil.copy(updateFile, file)) {
updateFile.delete();
}
}
/**
* Checks if the given plugin is loaded and returns it when applicable
* <p>
* Please note that the name of the plugin is case-sensitive
*
* @param name Name of the plugin to check
* @return Plugin if it exists, otherwise null
*/
@Nullable
public synchronized Plugin getPlugin(@Nonnull String name) { // Akarin - javax.annotation
return lookupNames.get(name.replace(' ', '_').toLowerCase(java.util.Locale.ENGLISH)); // Paper
}
@Nonnull // Akarin - javax.annotation
public synchronized Plugin[] getPlugins() {
return plugins.toArray(new Plugin[plugins.size()]);
}
/**
* Checks if the given plugin is enabled or not
* <p>
* Please note that the name of the plugin is case-sensitive.
*
* @param name Name of the plugin to check
* @return true if the plugin is enabled, otherwise false
*/
public boolean isPluginEnabled(@Nonnull String name) { // Akarin - javax.annotation
Plugin plugin = getPlugin(name);
return isPluginEnabled(plugin);
}
/**
* Checks if the given plugin is enabled or not
*
* @param plugin Plugin to check
* @return true if the plugin is enabled, otherwise false
*/
public synchronized boolean isPluginEnabled(@Nullable Plugin plugin) { // Paper - synchronize
if ((plugin != null) && (plugins.contains(plugin))) {
return plugin.isEnabled();
} else {
return false;
}
}
public synchronized void enablePlugin(@Nonnull final Plugin plugin) { // Paper - synchronize // Akarin - javax.annotation
if (!plugin.isEnabled()) {
List<Command> pluginCommands = PluginCommandYamlParser.parse(plugin);
if (!pluginCommands.isEmpty()) {
commandMap.registerAll(plugin.getDescription().getName(), pluginCommands);
}
try {
plugin.getPluginLoader().enablePlugin(plugin);
} catch (Throwable ex) {
handlePluginException("Error occurred (in the plugin loader) while enabling "
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin);
}
HandlerList.bakeAll();
}
}
// Paper start - close Classloader on disable
public void disablePlugins() {
disablePlugins(false);
}
public void disablePlugins(boolean closeClassloaders) {
// Paper end - close Classloader on disable
Plugin[] plugins = getPlugins();
for (int i = plugins.length - 1; i >= 0; i--) {
disablePlugin(plugins[i], closeClassloaders); // Paper - close Classloader on disable
}
}
// Paper start - close Classloader on disable
public void disablePlugin(@Nonnull final Plugin plugin) { // Akarin - javax.annotation
disablePlugin(plugin, false);
}
public synchronized void disablePlugin(@Nonnull final Plugin plugin, boolean closeClassloader) { // Paper - synchronize // Akarin - javax.annotation
// Paper end - close Classloader on disable
if (plugin.isEnabled()) {
try {
plugin.getPluginLoader().disablePlugin(plugin, closeClassloader); // Paper - close Classloader on disable
} catch (Throwable ex) {
handlePluginException("Error occurred (in the plugin loader) while disabling "
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
}
try {
server.getScheduler().cancelTasks(plugin);
} catch (Throwable ex) {
handlePluginException("Error occurred (in the plugin loader) while cancelling tasks for "
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
}
try {
server.getServicesManager().unregisterAll(plugin);
} catch (Throwable ex) {
handlePluginException("Error occurred (in the plugin loader) while unregistering services for "
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
}
try {
HandlerList.unregisterAll(plugin);
} catch (Throwable ex) {
handlePluginException("Error occurred (in the plugin loader) while unregistering events for "
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
}
try {
server.getMessenger().unregisterIncomingPluginChannel(plugin);
server.getMessenger().unregisterOutgoingPluginChannel(plugin);
} catch (Throwable ex) {
handlePluginException("Error occurred (in the plugin loader) while unregistering plugin channels for "
+ plugin.getDescription().getFullName() + " (Is it up to date?)", ex, plugin); // Paper
}
}
}
// Paper start
private void handlePluginException(String msg, Throwable ex, Plugin plugin) {
server.getLogger().log(Level.SEVERE, msg, ex);
callEvent(new ServerExceptionEvent(new ServerPluginEnableDisableException(msg, ex, plugin)));
}
// Paper end
public void clearPlugins() {
synchronized (this) {
disablePlugins(true); // Paper - close Classloader on disable
plugins.clear();
lookupNames.clear();
HandlerList.unregisterAll();
fileAssociations.clear();
synchronized (permissionsLock) { permissions = Collections.emptyMap(); } // Akarin
// Akarin start
//defaultPerms.get(true).clear();
//defaultPerms.get(false).clear();
HashObjObjMap<Boolean, Set<Permission>> defaultPerms = HashObjObjMaps.newUpdatableMap();
defaultPerms.put(Boolean.TRUE, HashObjSets.newUpdatableSet());
defaultPerms.put(Boolean.FALSE, HashObjSets.newUpdatableSet());
this.defaultPerms = defaultPerms;
// Akarin end
}
}
private void fireEvent(Event event) { callEvent(event); } // Paper - support old method incase plugin uses reflection
/**
* Calls an event with the given details.
* <p>
* This method only synchronizes when the event is not asynchronous.
*
* @param event Event details
*/
public void callEvent(@Nonnull Event event) { // Akarin - javax.annotation
// Paper - replace callEvent by merging to below method
HandlerList handlers = event.getHandlers();
RegisteredListener[] listeners = handlers.getRegisteredListeners();
for (RegisteredListener registration : listeners) {
if (!registration.getPlugin().isEnabled()) {
continue;
}
try {
registration.callEvent(event);
} catch (AuthorNagException ex) {
Plugin plugin = registration.getPlugin();
if (plugin.isNaggable()) {
plugin.setNaggable(false);
server.getLogger().log(Level.SEVERE, String.format(
"Nag author(s): '%s' of '%s' about the following: %s",
plugin.getDescription().getAuthors(),
plugin.getDescription().getFullName(),
ex.getMessage()
));
}
} catch (Throwable ex) {
// Paper start - error reporting
String msg = "Could not pass event " + event.getEventName() + " to " + registration.getPlugin().getDescription().getFullName();
server.getLogger().log(Level.SEVERE, msg, ex);
if (!(event instanceof ServerExceptionEvent)) { // We don't want to cause an endless event loop
callEvent(new ServerExceptionEvent(new ServerEventException(msg, ex, registration.getPlugin(), registration.getListener(), event)));
}
// Paper end
}
}
}
public void registerEvents(@Nonnull Listener listener, @Nonnull Plugin plugin) { // Akarin - javax.annotation
if (!plugin.isEnabled()) {
throw new IllegalPluginAccessException("Plugin attempted to register " + listener + " while not enabled");
}
for (Map.Entry<Class<? extends Event>, Set<RegisteredListener>> entry : plugin.getPluginLoader().createRegisteredListeners(listener, plugin).entrySet()) {
getEventListeners(getRegistrationClass(entry.getKey())).registerAll(entry.getValue());
}
}
public void registerEvent(@Nonnull Class<? extends Event> event, @Nonnull Listener listener, @Nonnull EventPriority priority, @Nonnull EventExecutor executor, @Nonnull Plugin plugin) { // Akarin - javax.annotation
registerEvent(event, listener, priority, executor, plugin, false);
}
/**
* Registers the given event to the specified listener using a directly
* passed EventExecutor
*
* @param event Event class to register
* @param listener PlayerListener to register
* @param priority Priority of this event
* @param executor EventExecutor to register
* @param plugin Plugin to register
* @param ignoreCancelled Do not call executor if event was already
* cancelled
*/
public void registerEvent(@Nonnull Class<? extends Event> event, @Nonnull Listener listener, @Nonnull EventPriority priority, @Nonnull EventExecutor executor, @Nonnull Plugin plugin, boolean ignoreCancelled) { // Akarin - javax.annotation
Validate.notNull(listener, "Listener cannot be null");
Validate.notNull(priority, "Priority cannot be null");
Validate.notNull(executor, "Executor cannot be null");
Validate.notNull(plugin, "Plugin cannot be null");
if (!plugin.isEnabled()) {
throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
}
executor = new co.aikar.timings.TimedEventExecutor(executor, plugin, null, event); // Paper
if (false) { // Spigot - RL handles useTimings check now // Paper
getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
} else {
getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
}
}
@Nonnull // Akarin - javax.annotation
private HandlerList getEventListeners(@Nonnull Class<? extends Event> type) { // Akarin - javax.annotation
try {
Method method = getRegistrationClass(type).getDeclaredMethod("getHandlerList");
method.setAccessible(true);
return (HandlerList) method.invoke(null);
} catch (Exception e) {
throw new IllegalPluginAccessException(e.toString());
}
}
@Nonnull // Akarin - javax.annotation
private Class<? extends Event> getRegistrationClass(@Nonnull Class<? extends Event> clazz) { // Akarin - javax.annotation
try {
clazz.getDeclaredMethod("getHandlerList");
return clazz;
} catch (NoSuchMethodException e) {
if (clazz.getSuperclass() != null
&& !clazz.getSuperclass().equals(Event.class)
&& Event.class.isAssignableFrom(clazz.getSuperclass())) {
return getRegistrationClass(clazz.getSuperclass().asSubclass(Event.class));
} else {
throw new IllegalPluginAccessException("Unable to find handler list for event " + clazz.getName() + ". Static getHandlerList method required!");
}
}
}
@Nullable
public Permission getPermission(@Nonnull String name) { // Akarin - javax.annotation
return permissions.get(name.toLowerCase(java.util.Locale.ENGLISH));
}
public void addPermission(@Nonnull Permission perm) { // Akarin - javax.annotation
addPermission(perm, true);
}
@Deprecated
public void addPermission(@Nonnull Permission perm, boolean dirty) { // Akarin - javax.annotation
String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH);
if (permissions.containsKey(name)) {
throw new IllegalArgumentException("The permission " + name + " is already defined!");
}
// Akarin start
synchronized (permissionsLock) {
HashObjObjMap<String, Permission> toImmutable = HashObjObjMaps.newUpdatableMap(permissions);
toImmutable.put(name, perm);
permissions = HashObjObjMaps.newImmutableMap(toImmutable);
}
// Akarin end
calculatePermissionDefault(perm, dirty);
}
@Nonnull // Akarin - javax.annotation
public Set<Permission> getDefaultPermissions(boolean op) {
return defaultPerms.get(op);
}
public void removePermission(@Nonnull Permission perm) { // Akarin - javax.annotation
removePermission(perm.getName());
}
public void removePermission(@Nonnull String name) { // Akarin - javax.annotation
// Akarin start
synchronized (permissionsLock) {
HashObjObjMap<String, Permission> toImmutable = HashObjObjMaps.newMutableMap(permissions);
toImmutable.remove(name.toLowerCase(java.util.Locale.ENGLISH));
permissions = HashObjObjMaps.newImmutableMap(toImmutable);
}
// Akarin end
}
public void recalculatePermissionDefaults(@Nonnull Permission perm) { // Akarin - javax.annotation
if (perm != null && permissions.containsKey(perm.getName().toLowerCase(java.util.Locale.ENGLISH))) {
// Akarin start
HashObjObjMap<Boolean, Set<Permission>> toImmutable = HashObjObjMaps.newUpdatableMap(defaultPerms);
Set<Permission> toImmutableValueOp = HashObjSets.newMutableSet(defaultPerms.get(Boolean.TRUE));
toImmutableValueOp.remove(perm);
toImmutable.put(Boolean.TRUE, HashObjSets.newImmutableSet(toImmutableValueOp));
Set<Permission> toImmutableValue = HashObjSets.newMutableSet(defaultPerms.get(Boolean.FALSE));
toImmutableValue.remove(perm);
toImmutable.put(Boolean.FALSE, HashObjSets.newImmutableSet(toImmutableValue));
defaultPerms = toImmutable;
// Akarin end
calculatePermissionDefault(perm, true);
}
}
private void calculatePermissionDefault(@Nonnull Permission perm, boolean dirty) { // Akarin - javax.annotation
if ((perm.getDefault() == PermissionDefault.OP) || (perm.getDefault() == PermissionDefault.TRUE)) {
// Akarin start
HashObjObjMap<Boolean, Set<Permission>> toImmutable = HashObjObjMaps.newUpdatableMap(defaultPerms);
Set<Permission> toImmutableValue = HashObjSets.newUpdatableSet(defaultPerms.get(Boolean.TRUE));
toImmutableValue.add(perm);
toImmutable.put(Boolean.TRUE, HashObjSets.newImmutableSet(toImmutableValue));
defaultPerms = toImmutable;
// Akarin end
if (dirty) {
dirtyPermissibles(true);
}
}
if ((perm.getDefault() == PermissionDefault.NOT_OP) || (perm.getDefault() == PermissionDefault.TRUE)) {
// Akarin start
HashObjObjMap<Boolean, Set<Permission>> toImmutable = HashObjObjMaps.newUpdatableMap(defaultPerms);
Set<Permission> toImmutableValue = HashObjSets.newUpdatableSet(defaultPerms.get(Boolean.FALSE));
toImmutableValue.add(perm);
toImmutable.put(Boolean.FALSE, HashObjSets.newImmutableSet(toImmutableValue));
defaultPerms = toImmutable;
// Akarin end
if (dirty) {
dirtyPermissibles(false);
}
}
}
@Deprecated
public void dirtyPermissibles() {
dirtyPermissibles(true);
dirtyPermissibles(false);
}
private void dirtyPermissibles(boolean op) {
Set<Permissible> permissibles = getDefaultPermSubscriptions(op);
for (Permissible p : permissibles) {
p.recalculatePermissions();
}
}
public void subscribeToPermission(@Nonnull String permission, @Nonnull Permissible permissible) { // Akarin - javax.annotation
String name = permission.toLowerCase(java.util.Locale.ENGLISH);
synchronized (permSubsLock) { // Akarin
Map<Permissible, Boolean> map = permSubs.get(name);
if (map == null) {
map = new WeakHashMap<Permissible, Boolean>();
permSubs.put(name, map);
}
map.put(permissible, true);
} // Akarin
}
public void unsubscribeFromPermission(@Nonnull String permission, @Nonnull Permissible permissible) { // Akarin - javax.annotation
String name = permission.toLowerCase(java.util.Locale.ENGLISH);
synchronized (permSubsLock) { // Akarin
Map<Permissible, Boolean> map = permSubs.get(name);
if (map != null) {
map.remove(permissible);
if (map.isEmpty()) {
permSubs.remove(name);
}
}
} // Akarin
}
@Nonnull // Akarin - javax.annotation
public Set<Permissible> getPermissionSubscriptions(@Nonnull String permission) { // Akarin - javax.annotation
String name = permission.toLowerCase(java.util.Locale.ENGLISH);
synchronized (permSubsLock) { // Akarin
Map<Permissible, Boolean> map = permSubs.get(name);
if (map == null) {
return ImmutableSet.of();
} else {
return ImmutableSet.copyOf(map.keySet());
}
} // Akarin
}
public void subscribeToDefaultPerms(boolean op, @Nonnull Permissible permissible) { // Akarin - javax.annotation
Map<Permissible, Boolean> map = defSubs.get(op);
if (map == null) {
map = new WeakHashMap<Permissible, Boolean>();
defSubs.put(op, map);
}
map.put(permissible, true);
}
public void unsubscribeFromDefaultPerms(boolean op, @Nonnull Permissible permissible) { // Akarin - javax.annotation
Map<Permissible, Boolean> map = defSubs.get(op);
if (map != null) {
map.remove(permissible);
if (map.isEmpty()) {
defSubs.remove(op);
}
}
}
@Nonnull // Akarin - javax.annotation
public Set<Permissible> getDefaultPermSubscriptions(boolean op) {
Map<Permissible, Boolean> map = defSubs.get(op);
if (map == null) {
return ImmutableSet.of();
} else {
return ImmutableSet.copyOf(map.keySet());
}
}
@Nonnull // Akarin - javax.annotation
public Set<Permission> getPermissions() {
return new HashSet<Permission>(permissions.values());
}
public boolean useTimings() {
return co.aikar.timings.Timings.isTimingsEnabled(); // Spigot
}
/**
* Sets whether or not per event timing code should be used
*
* @param use True if per event timing code should be used
*/
public void useTimings(boolean use) {
co.aikar.timings.Timings.setTimingsEnabled(use); // Paper
}
// Paper start
public void clearPermissions() {
synchronized (permissionsLock) { permissions = Collections.emptyMap(); } // Akarin
// Akarin start
//defaultPerms.get(true).clear();
//defaultPerms.get(false).clear();
HashObjObjMap<Boolean, Set<Permission>> defaultPerms = HashObjObjMaps.newUpdatableMap();
defaultPerms.put(Boolean.TRUE, HashObjSets.newUpdatableSet());
defaultPerms.put(Boolean.FALSE, HashObjSets.newUpdatableSet());
this.defaultPerms = defaultPerms;
// Akarin end
}
// Paper end
}

View File

@@ -1,245 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-parent</artifactId>
<version>dev-SNAPSHOT</version>
</parent>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Paper-API</name>
<url>https://github.com/PaperMC/Paper</url>
<description>An enhanced plugin API for Minecraft servers.</description>
<properties>
<!-- <skipTests>true</skipTests> Paper - This [was] not going to end well -->
<!-- Paper - #Logic -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<!--
If you are a plugin developer, please use https://hub.spigotmc.org/nexus/content/repositories/snapshots/
as your repository URL. This will ensure only Bukkit / Spigot-API are pulled from our Maven repository.
Please see https://www.spigotmc.org/go/maven for more information.
-->
<repository>
<id>spigotmc-public</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spigotmc-public</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<!-- bundled with Minecraft, shouldn't ever change -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
<scope>compile</scope>
</dependency>
<!-- bundled with Minecraft, should be kept in sync -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
<scope>compile</scope>
</dependency>
<!-- bundled with Minecraft, should be kept in sync -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.13-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version>
<scope>compile</scope>
</dependency>
<!-- annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
<version>17.0.0</version>
<scope>provided</scope>
</dependency>
<!-- Paper - Add SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>compile</scope>
</dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>7.1</version>
<scope>test</scope>
</dependency>
<!-- ASM -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.1</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>7.1</version>
</dependency>
<!-- Akarin -->
<dependency>
<groupId>com.koloboke</groupId>
<artifactId>koloboke-api-jdk8</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.koloboke</groupId>
<artifactId>koloboke-impl-jdk8</artifactId>
<version>1.0.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<dependencies>
<!-- we need our custom version as it fixes some bugs on case sensitive file systems -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8.5-spigotmc</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.bukkit</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<!-- when downloading via Maven we can pull depends individually -->
<shadedArtifactAttached>true</shadedArtifactAttached>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>development</id>
<properties>
<skipTests>false</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.17</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java17</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>