Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
------
Refactored nearly everything. Removed hard dependency on PK. There is still plenty to do from here!
  • Loading branch information
CozmycDev committed Jul 23, 2024
0 parents commit e9391d3
Show file tree
Hide file tree
Showing 25 changed files with 1,858 additions and 0 deletions.
94 changes: 94 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

<groupId>net.doodcraft</groupId>
<artifactId>bendingmobs</artifactId>
<version>1.2.0</version>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository>
<id>md5-repo</id>
<url>https://repo.md-5.net/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>https://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>stealthyone-repo</id>
<url>https://repo.stealthyone.com/content/groups/public</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>http://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>LibsDisguises</groupId>
<artifactId>LibsDisguises</artifactId>
<version>10.0.44</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.8.0</version>
</dependency>
<dependency>
<groupId>com.projectkorra</groupId>
<artifactId>projectkorra</artifactId>
<version>1.11.3</version>
</dependency>
</dependencies>
</project>
78 changes: 78 additions & 0 deletions src/main/java/net/doodcraft/cozmyc/bendingmobs/BendingMobs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.doodcraft.cozmyc.bendingmobs;

import net.doodcraft.cozmyc.bendingmobs.ability.air.AirAbility;
import net.doodcraft.cozmyc.bendingmobs.ability.earth.EarthAbility;
import net.doodcraft.cozmyc.bendingmobs.ability.fire.FireAbility;
import net.doodcraft.cozmyc.bendingmobs.ability.water.WaterAbility;
import net.doodcraft.cozmyc.bendingmobs.config.ConfigManager;
import net.doodcraft.cozmyc.bendingmobs.listener.MobListener;
import net.doodcraft.cozmyc.bendingmobs.manager.AbilityManager;
import net.doodcraft.cozmyc.bendingmobs.manager.EntityManager;

import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;

public class BendingMobs extends JavaPlugin {

public static BendingMobs plugin;
public static Logger log;
public static DisguiseStrategy disguiseStrategy;

@Override
public void onDisable() {
AirAbility.remove();
EarthAbility.remove();
FireAbility.remove();
WaterAbility.remove();
EntityManager.remove();
}

@Override
public void onEnable() {
plugin = this;
BendingMobs.log = this.getLogger();
new ConfigManager(this);
checkHooks();
registerEntityTypes();
selectDisguiseStrategy();
registerListeners();
scheduleTasks();

log.info("BendingMobs is now enabled! Using DisguiseStrategy: " + disguiseStrategy.name());
}

private void checkHooks() {
Compatibility.hookPlugin("ProjectKorra", "1.11", "1.13");
}

private void registerEntityTypes() {
MobMethods.entityTypes.clear();
for (String type : BendingMobs.plugin.getConfig().getStringList("Properties.EntityTypes")) {
MobMethods.entityTypes.add(type.toUpperCase());
}
}

private void selectDisguiseStrategy() {
boolean libsEnabled = BendingMobs.plugin.getConfig().getBoolean("LibsDisguises.Enabled");
// boolean mythicEnabled = BendingMobs.plugin.getConfig().getBoolean("MythicMobs.Enabled");

switch (libsEnabled ? 1 : 0) {
case 0:
disguiseStrategy = DisguiseStrategy.NONE;
break;
case 1:
disguiseStrategy = DisguiseStrategy.LIBSDISGUISES;
break;
}
}

private void registerListeners() {
getServer().getPluginManager().registerEvents(new MobListener(this), this);
}

private void scheduleTasks() {
getServer().getScheduler().scheduleSyncRepeatingTask(this, new AbilityManager(), 0L, 1L);
MobMethods.startMobUpdateTask(this);
}
}
65 changes: 65 additions & 0 deletions src/main/java/net/doodcraft/cozmyc/bendingmobs/Compatibility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.doodcraft.cozmyc.bendingmobs;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

import java.util.HashMap;
import java.util.Map;

public class Compatibility {

private static final Map<String, Plugin> hookedPlugins = new HashMap<>();

public static boolean isHooked(String name) {
return hookedPlugins.containsKey(name);
}

public static boolean hookPlugin(String name, String minVersion, String maxVersion) {
Plugin plugin = Bukkit.getPluginManager().getPlugin(name);

if (plugin == null) {
return false;
}

String version = plugin.getDescription().getVersion().split("-")[0];

if (isVersionSupported(version, minVersion, maxVersion)) {
return hookPlugin(name, plugin);
} else {
Bukkit.getLogger().info(String.format("%s v%s is unknown or unsupported. Attempting to hook anyway. There may be errors.", name, version));
return hookPlugin(name, plugin);
}
}

private static boolean isVersionSupported(String version, String minVersion, String maxVersion) {
try {
return compareVersions(version, minVersion) >= 0 && compareVersions(version, maxVersion) <= 0;
} catch (Exception e) {
return false;
}
}

private static boolean hookPlugin(String name, Plugin plugin) {
if (hookedPlugins.containsKey(name)) {
return false;
}
hookedPlugins.put(name, plugin);
Bukkit.getLogger().info(String.format("Hooked into %s successfully!", name));
return true;
}

private static int compareVersions(String version, String otherVersion) {
String[] versionParts = version.split("\\.");
String[] otherVersionParts = otherVersion.split("\\.");

int length = Math.max(versionParts.length, otherVersionParts.length);
for (int i = 0; i < length; i++) {
int vPart = i < versionParts.length ? Integer.parseInt(versionParts[i]) : 0;
int oPart = i < otherVersionParts.length ? Integer.parseInt(otherVersionParts[i]) : 0;
if (vPart != oPart) {
return Integer.compare(vPart, oPart);
}
}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.doodcraft.cozmyc.bendingmobs;

public enum DisguiseStrategy {
NONE,
MYTHICMOBS,
LIBSDISGUISES
}
Loading

0 comments on commit e9391d3

Please sign in to comment.