Velocitab/src/main/java/net/william278/velocitab/hook/Hook.java
William 1f1e69ebca
Add support for Minecraft 1.20.2 (#99)
* Add protocol mappings for 1.20.2

* Cleanup some exception handling

* ci: Mark 1.20.2 as supported

* Minor code formatting tweaks
2023-10-11 17:10:29 +01:00

79 lines
3.0 KiB
Java

/*
* This file is part of Velocitab, licensed under the Apache License 2.0.
*
* Copyright (c) William278 <will27528@gmail.com>
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.william278.velocitab.hook;
import net.william278.velocitab.Velocitab;
import org.jetbrains.annotations.NotNull;
import org.slf4j.event.Level;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
public abstract class Hook {
public static final List<Function<Velocitab, Optional<Hook>>> AVAILABLE = List.of(
(plugin -> {
if (isPluginAvailable(plugin, "luckperms")) {
try {
plugin.log("Successfully hooked into LuckPerms");
return Optional.of(new LuckPermsHook(plugin));
} catch (Throwable e) {
plugin.log(Level.WARN, "LuckPerms hook was not loaded: " + e.getMessage(), e);
}
}
return Optional.empty();
}),
(plugin -> {
if (isPluginAvailable(plugin, "papiproxybridge") && plugin.getSettings().isEnablePapiHook()) {
try {
plugin.log("Successfully hooked into PAPIProxyBridge");
return Optional.of(new PAPIProxyBridgeHook(plugin));
} catch (Throwable e) {
plugin.log(Level.WARN, "PAPIProxyBridge hook was not loaded: " + e.getMessage(), e);
}
}
return Optional.empty();
}),
(plugin -> {
if (isPluginAvailable(plugin, "miniplaceholders") && plugin.getSettings().isEnableMiniPlaceholdersHook()) {
try {
plugin.log("Successfully hooked into MiniPlaceholders");
return Optional.of(new MiniPlaceholdersHook(plugin));
} catch (Throwable e) {
plugin.log(Level.WARN, "MiniPlaceholders hook was not loaded: " + e.getMessage(), e);
}
}
return Optional.empty();
})
);
protected final Velocitab plugin;
public Hook(@NotNull Velocitab plugin) {
this.plugin = plugin;
}
private static boolean isPluginAvailable(@NotNull Velocitab plugin, @NotNull String id) {
return plugin.getServer().getPluginManager().getPlugin(id).isPresent();
}
}