9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-31 04:46:36 +00:00
This commit is contained in:
Xiao-MoMi
2023-03-18 14:46:02 +08:00
parent 3b06cd07b9
commit 93f43c2498
10 changed files with 63 additions and 57 deletions

View File

@@ -32,6 +32,8 @@ import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.TimeZone;
public final class CustomFishing extends JavaPlugin {
private static CustomFishing plugin;
@@ -83,20 +85,18 @@ public final class CustomFishing extends JavaPlugin {
@Override
public void onDisable() {
this.fishingManager.unload();
this.integrationManager.unload();
this.competitionManager.unload();
this.effectManager.unload();
this.lootManager.unload();
this.barMechanicManager.unload();
this.bagDataManager.disable();
this.totemManager.unload();
this.sellManager.disable();
this.dataManager.disable();
this.statisticsManager.disable();
if (adventure != null) {
adventure.close();
}
if (this.fishingManager != null) this.fishingManager.unload();
if (this.integrationManager != null) this.integrationManager.unload();
if (this.competitionManager != null) this.competitionManager.unload();
if (this.effectManager != null) this.effectManager.unload();
if (this.lootManager != null) this.lootManager.unload();
if (this.barMechanicManager != null) this.barMechanicManager.unload();
if (this.totemManager != null) this.totemManager.unload();
if (this.bagDataManager != null) this.bagDataManager.disable();
if (this.sellManager != null) this.sellManager.disable();
if (this.statisticsManager != null) this.statisticsManager.disable();
if (this.dataManager != null) this.dataManager.disable();
if (adventure != null) adventure.close();
}
private void registerCommands() {
@@ -121,12 +121,14 @@ public final class CustomFishing extends JavaPlugin {
}
private void loadLibs() {
LibraryLoader.load("redis.clients","jedis","4.3.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.apache.commons","commons-pool2","2.11.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("net.objecthunter","exp4j","0.4.8","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.0.6","https://repo.maven.apache.org/maven2/");
TimeZone timeZone = TimeZone.getDefault();
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
LibraryLoader.load("org.apache.commons","commons-pool2","2.11.1", libRepo);
LibraryLoader.load("redis.clients","jedis","4.3.1", libRepo);
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3", libRepo);
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1", libRepo);
LibraryLoader.load("net.objecthunter","exp4j","0.4.8", libRepo);
LibraryLoader.load("org.mariadb.jdbc","mariadb-java-client","3.1.2", libRepo);
}
private void registerQuests() {

View File

@@ -65,17 +65,19 @@ public class BossBarManager extends Function {
@Override
public void onJoin(Player player) {
if (Competition.currentCompetition != null){
if (Competition.currentCompetition.isJoined(player) && cache.get(player) == null){
BossBarSender sender = new BossBarSender(player, Competition.currentCompetition.getCompetitionConfig().getBossBarConfig());
if (!sender.getStatus()) {
sender.show();
Bukkit.getScheduler().runTaskLater(CustomFishing.getInstance(), () -> {
if (Competition.currentCompetition != null){
if (Competition.currentCompetition.isJoined(player) && cache.get(player) == null){
BossBarSender sender = new BossBarSender(player, Competition.currentCompetition.getCompetitionConfig().getBossBarConfig());
if (!sender.getStatus()) {
sender.show();
}
cache.put(player, sender);
} else {
AdventureUtil.playerMessage(player, MessageManager.competitionOn);
}
cache.put(player, sender);
} else {
AdventureUtil.playerMessage(player, MessageManager.competitionOn);
}
}
}, 5);
}
public void tryJoin(Player player) {

View File

@@ -37,6 +37,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.util.Objects;
import java.util.StringJoiner;
/**
* Resolves {@link MavenLibrary} annotations for a class, and loads the dependency
@@ -66,7 +67,6 @@ public final class LibraryLoader {
if (libs == null) {
return;
}
for (MavenLibrary lib : libs) {
load(lib.groupId(), lib.artifactId(), lib.version(), lib.repo().url());
}
@@ -77,7 +77,7 @@ public final class LibraryLoader {
}
public static void load(Dependency d) {
//Log.info(String.format("Loading dependency %s:%s:%s from %s", d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getRepoUrl()));
Log.info(String.format("Loading dependency %s:%s:%s from %s", d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getRepoUrl()));
String name = d.getArtifactId() + "-" + d.getVersion();
File saveLocation = new File(getLibFolder(d), name + ".jar");
@@ -98,13 +98,13 @@ public final class LibraryLoader {
}
if (!saveLocation.exists()) {
throw new RuntimeException("Unable to download dependency: " + d.toString());
throw new RuntimeException("Unable to download dependency: " + d);
}
try {
URL_INJECTOR.get().addURL(saveLocation.toURI().toURL());
} catch (Exception e) {
throw new RuntimeException("Unable to load dependency: " + saveLocation.toString(), e);
throw new RuntimeException("Unable to load dependency: " + saveLocation, e);
}
}
@@ -115,11 +115,11 @@ public final class LibraryLoader {
File helperDir = new File(serverDir, "libraries");
String[] split = StringUtils.split(dependency.getGroupId(), ".");
File jarDir;
if (split.length > 1){
jarDir = new File(helperDir, split[0] + File.separator + split[1] + File.separator + dependency.artifactId + File.separator + dependency.version );
}else {
jarDir = new File(helperDir, dependency.getGroupId() + File.separator + dependency.artifactId + File.separator + dependency.version );
StringJoiner stringJoiner = new StringJoiner(File.separator);
for (String str : split) {
stringJoiner.add(str);
}
jarDir = new File(helperDir, stringJoiner + File.separator + dependency.artifactId + File.separator + dependency.version);
jarDir.mkdirs();
return jarDir;
}

View File

@@ -34,15 +34,18 @@ import java.util.Optional;
public class MythicMobsMobImpl implements MobInterface {
private final MobManager mobManager;
private MythicBukkit mythicBukkit;
public MythicMobsMobImpl() {
this.mobManager = MythicBukkit.inst().getMobManager();
this.mythicBukkit = MythicBukkit.inst();
}
@Override
public void summon(Location playerLoc, Location summonLoc, Mob mob){
Optional<MythicMob> mythicMob = mobManager.getMythicMob(mob.getMobID());
if (this.mythicBukkit == null || mythicBukkit.isClosed()) {
this.mythicBukkit = MythicBukkit.inst();
}
Optional<MythicMob> mythicMob = mythicBukkit.getMobManager().getMythicMob(mob.getMobID());
if (mythicMob.isPresent()) {
MythicMob theMob = mythicMob.get();
Position position = Position.of(summonLoc);

View File

@@ -173,10 +173,8 @@ public class ConfigManager {
}
useRedis = true;
}
else {
if (JedisUtil.isPoolEnabled()) {
JedisUtil.closePool();
}
else if (useRedis && JedisUtil.isPoolEnabled()) {
JedisUtil.closePool();
useRedis = false;
}
}

View File

@@ -116,7 +116,7 @@ public class IntegrationManager extends Function {
}
private void hookMobs() {
if (pluginManager.isPluginEnabled("MythicMobs")) {
if (pluginManager.isPluginEnabled("MythicMobs") && pluginManager.getPlugin("MythicMobs").getDescription().getVersion().startsWith("5")) {
this.mobInterface = new MythicMobsMobImpl();
}
}
@@ -190,7 +190,7 @@ public class IntegrationManager extends Function {
itemInterfaceList.add(new MMOItemsItemImpl());
hookMessage("MMOItems");
}
if (pluginManager.isPluginEnabled("MythicMobs")) {
if (pluginManager.isPluginEnabled("MythicMobs") && pluginManager.getPlugin("MythicMobs").getDescription().getVersion().startsWith("5")) {
itemInterfaceList.add(new MythicMobsItemImpl());
hookMessage("MythicMobs");
}
@@ -210,7 +210,7 @@ public class IntegrationManager extends Function {
hookMessage("ClueScrolls");
}
if (pluginManager.isPluginEnabled("BetonQuest")) {
if (Bukkit.getPluginManager().getPlugin("BetonQuest").getDescription().getVersion().startsWith("2.")) NewBetonQuestCFQuest.register();
if (Bukkit.getPluginManager().getPlugin("BetonQuest").getDescription().getVersion().startsWith("2")) NewBetonQuestCFQuest.register();
else OldBetonQuestCFQuest.register();
hookMessage("BetonQuest");
}

View File

@@ -84,6 +84,6 @@ public class JedisUtil {
}
public static boolean isPoolEnabled() {
return !(jedisPool == null || jedisPool.isClosed());
return jedisPool != null && !jedisPool.isClosed();
}
}