mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Don't use always exceptions
This commit is contained in:
parent
e00a0de496
commit
4af2927658
@ -33,6 +33,7 @@ import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
@ -44,6 +45,7 @@ import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -58,6 +60,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
*/
|
||||
public class ProtocolLib extends JavaPlugin {
|
||||
|
||||
public static boolean isFolia = false;
|
||||
|
||||
// Every possible error or warning report type
|
||||
public static final ReportType REPORT_CANNOT_DELETE_CONFIG = new ReportType(
|
||||
"Cannot delete old ProtocolLib configuration.");
|
||||
@ -303,6 +307,13 @@ public class ProtocolLib extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
isFolia = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
isFolia = false;
|
||||
}
|
||||
|
||||
try {
|
||||
Server server = this.getServer();
|
||||
PluginManager manager = server.getPluginManager();
|
||||
@ -491,11 +502,10 @@ public class ProtocolLib extends JavaPlugin {
|
||||
|
||||
// Attempt to create task
|
||||
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
if (isFolia) {
|
||||
this.packetTask = 1;
|
||||
server.getGlobalRegionScheduler().runAtFixedRate(this, task -> packetTaskRegistrator(), ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
|
||||
} catch (ClassNotFoundException e) {
|
||||
} else {
|
||||
this.packetTask = server.getScheduler().scheduleSyncRepeatingTask(this, this::packetTaskRegistrator, ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
@ -575,10 +585,9 @@ public class ProtocolLib extends JavaPlugin {
|
||||
|
||||
// Clean up
|
||||
if (this.packetTask >= 0) {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
if (isFolia) {
|
||||
this.getServer().getGlobalRegionScheduler().cancelTasks(this);
|
||||
} catch (ClassNotFoundException e) {
|
||||
} else {
|
||||
this.getServer().getScheduler().cancelTask(this.packetTask);
|
||||
}
|
||||
this.packetTask = -1;
|
||||
|
@ -1,21 +1,22 @@
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2015 dmulloy2
|
||||
*
|
||||
* <p>
|
||||
* 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 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol.updater;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.utility.Closer;
|
||||
@ -80,10 +81,9 @@ public final class SpigotUpdater extends Updater {
|
||||
} finally {
|
||||
// Invoke the listeners on the main thread
|
||||
for (Runnable listener : listeners) {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
if (ProtocolLib.isFolia) {
|
||||
plugin.getServer().getGlobalRegionScheduler().execute(plugin, listener);
|
||||
} catch (ClassNotFoundException e) {
|
||||
} else {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user