Skip to content

Commit 3f7f463

Browse files
committed
Preliminary 1.19.4+ support
1 parent d1a1792 commit 3f7f463

File tree

17 files changed

+109
-73
lines changed

17 files changed

+109
-73
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Future updates will support custom mobs and models through MythicMobs and ModelE
3232
Here is the default `config.yml` for BendingMobs:
3333

3434
```yaml
35-
Version: 1.2.0
3635
Properties:
3736
EntityTypes:
3837
- ZOMBIE

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.doodcraft</groupId>
88
<artifactId>bendingmobs</artifactId>
9-
<version>1.2.0</version>
9+
<version>1.3.0</version>
1010

1111
<properties>
1212
<java.version>1.8</java.version>
@@ -20,8 +20,8 @@
2020
<artifactId>maven-compiler-plugin</artifactId>
2121
<version>3.8.1</version>
2222
<configuration>
23-
<source>17</source>
24-
<target>17</target>
23+
<source>8</source>
24+
<target>8</target>
2525
</configuration>
2626
</plugin>
2727
</plugins>
@@ -71,7 +71,7 @@
7171
<dependency>
7272
<groupId>org.spigotmc</groupId>
7373
<artifactId>spigot-api</artifactId>
74-
<version>1.20.4-R0.1-SNAPSHOT</version>
74+
<version>1.19.4-R0.1-SNAPSHOT</version>
7575
<scope>provided</scope>
7676
</dependency>
7777
<dependency>

src/main/java/net/doodcraft/cozmyc/bendingmobs/BendingMobs.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.doodcraft.cozmyc.bendingmobs.manager.AbilityManager;
1010
import net.doodcraft.cozmyc.bendingmobs.manager.EntityManager;
1111

12+
import org.bukkit.Bukkit;
1213
import org.bukkit.plugin.java.JavaPlugin;
1314

1415
import java.util.logging.Logger;
@@ -30,6 +31,11 @@ public void onDisable() {
3031

3132
@Override
3233
public void onEnable() {
34+
if (!isVersionAtLeast1_19_4()) {
35+
log.warning("Looks like you're trying to load BendingMobs on an unsupported MC version. This is for 1.19.4+ only.");
36+
return;
37+
}
38+
3339
plugin = this;
3440
BendingMobs.log = this.getLogger();
3541
new ConfigManager(this);
@@ -75,4 +81,20 @@ private void scheduleTasks() {
7581
getServer().getScheduler().scheduleSyncRepeatingTask(this, new AbilityManager(), 0L, 1L);
7682
MobMethods.startMobUpdateTask(this);
7783
}
84+
85+
public static boolean isVersionAtLeast1_19_4() {
86+
String version = Bukkit.getBukkitVersion();
87+
88+
String[] versionParts = version.split("-")[0].split("\\.");
89+
90+
int major = Integer.parseInt(versionParts[0]);
91+
int minor = Integer.parseInt(versionParts[1]);
92+
int patch = Integer.parseInt(versionParts.length > 2 ? versionParts[2] : "0");
93+
94+
if (major > 1) {
95+
return true;
96+
} else if (major == 1 && minor > 19) {
97+
return true;
98+
} else return major == 1 && minor == 19 && patch >= 4;
99+
}
78100
}

src/main/java/net/doodcraft/cozmyc/bendingmobs/Compatibility.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ public static boolean isHooked(String name) {
1414
return hookedPlugins.containsKey(name);
1515
}
1616

17-
public static boolean hookPlugin(String name, String minVersion, String maxVersion) {
17+
public static void hookPlugin(String name, String minVersion, String maxVersion) {
1818
Plugin plugin = Bukkit.getPluginManager().getPlugin(name);
1919

2020
if (plugin == null) {
21-
return false;
21+
return;
2222
}
2323

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

2626
if (isVersionSupported(version, minVersion, maxVersion)) {
27-
return hookPlugin(name, plugin);
27+
hookPlugin(name, plugin);
2828
} else {
2929
Bukkit.getLogger().info(String.format("%s v%s is unknown or unsupported. Attempting to hook anyway. There may be errors.", name, version));
30-
return hookPlugin(name, plugin);
30+
hookPlugin(name, plugin);
3131
}
3232
}
3333

@@ -39,13 +39,12 @@ private static boolean isVersionSupported(String version, String minVersion, Str
3939
}
4040
}
4141

42-
private static boolean hookPlugin(String name, Plugin plugin) {
42+
private static void hookPlugin(String name, Plugin plugin) {
4343
if (hookedPlugins.containsKey(name)) {
44-
return false;
44+
return;
4545
}
4646
hookedPlugins.put(name, plugin);
4747
Bukkit.getLogger().info(String.format("Hooked into %s successfully!", name));
48-
return true;
4948
}
5049

5150
private static int compareVersions(String version, String otherVersion) {

src/main/java/net/doodcraft/cozmyc/bendingmobs/MobMethods.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public class MobMethods {
2626
private static final double movementSpeed = BendingMobs.plugin.getConfig().getDouble("Properties.MovementSpeed");
2727
private static final boolean mobsSwim = BendingMobs.plugin.getConfig().getBoolean("Properties.DoMobsSwim");
2828

29-
public static List<String> disabledWorlds = new ArrayList<String>();
30-
public static List<String> entityTypes = new ArrayList<String>();
29+
public static final List<String> disabledWorlds = new ArrayList<>();
30+
public static final List<String> entityTypes = new ArrayList<>();
3131

32-
public static Random rand = new Random();
32+
public static final Random rand = new Random();
3333

3434
public static void assignElement(Entity entity) {
3535
if (!entity.hasMetadata("element")) {
@@ -61,10 +61,7 @@ public static void assignElement(Entity entity, Element element) {
6161
}
6262

6363
public static boolean isAvatar(LivingEntity entity) {
64-
if (entity.hasMetadata("element") && !entity.getMetadata("element").isEmpty() && (entity.getMetadata("element").get(0).asInt() == 4)) {
65-
return true;
66-
}
67-
return false;
64+
return entity.hasMetadata("element") && !entity.getMetadata("element").isEmpty() && (entity.getMetadata("element").get(0).asInt() == 4);
6865
}
6966

7067
public static boolean isDisabledWorld(World world) {
@@ -78,11 +75,16 @@ public static void startMobUpdateTask(JavaPlugin plugin) {
7875
public void run() {
7976
List<Entity> entitiesToRemove = new ArrayList<>();
8077

81-
for (Entity entity : Bukkit.getWorlds().stream().flatMap(world -> world.getEntities().stream()).toList()) {
78+
List<Entity> entities = new ArrayList<>();
79+
for (World world : Bukkit.getWorlds()) {
80+
entities.addAll(world.getEntities());
81+
}
82+
83+
for (Entity entity : entities) {
8284
if (!(entity instanceof LivingEntity)) continue;
8385
if (!canEntityBend(entity.getType().name())) continue;
8486

85-
if (!(hasElement((LivingEntity) entity))) {
87+
if (!hasElement((LivingEntity) entity)) {
8688
entitiesToRemove.add(entity);
8789
continue;
8890
}
@@ -145,13 +147,27 @@ public static void disguiseEntity(Entity entity, Element element) {
145147
}
146148

147149
private static String getNameFor(Element element, String configPath) {
148-
return switch (element) {
149-
case Air -> BendingMobs.plugin.getConfig().getString(configPath + ".Air");
150-
case Earth -> BendingMobs.plugin.getConfig().getString(configPath + ".Earth");
151-
case Fire -> BendingMobs.plugin.getConfig().getString(configPath + ".Fire");
152-
case Water -> BendingMobs.plugin.getConfig().getString(configPath + ".Water");
153-
case Avatar -> BendingMobs.plugin.getConfig().getString(configPath + ".Avatar");
154-
default -> "Herobrine";
155-
};
150+
String name;
151+
switch (element) {
152+
case Air:
153+
name = BendingMobs.plugin.getConfig().getString(configPath + ".Air");
154+
break;
155+
case Earth:
156+
name = BendingMobs.plugin.getConfig().getString(configPath + ".Earth");
157+
break;
158+
case Fire:
159+
name = BendingMobs.plugin.getConfig().getString(configPath + ".Fire");
160+
break;
161+
case Water:
162+
name = BendingMobs.plugin.getConfig().getString(configPath + ".Water");
163+
break;
164+
case Avatar:
165+
name = BendingMobs.plugin.getConfig().getString(configPath + ".Avatar");
166+
break;
167+
default:
168+
name = "Herobrine";
169+
break;
170+
}
171+
return name;
156172
}
157173
}

src/main/java/net/doodcraft/cozmyc/bendingmobs/PKMethods.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
public class PKMethods {
1212

13+
// using deprecated methods
1314
public static boolean isWithinPKShield(Location loc) {
1415
if (!Compatibility.isHooked("ProjectKorra")) return false;
1516
if (AirShield.isWithinShield(loc)) {

src/main/java/net/doodcraft/cozmyc/bendingmobs/StaticMethods.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
public class StaticMethods {
2121

2222
public static final Set<Material> TRANSPARENT = new HashSet<>();
23-
public static Set<String> EARTH_BLOCKS = new HashSet<>();
24-
public static Set<String> ICE_BLOCKS = new HashSet<>();
25-
public static Set<String> LAVA_BLOCKS = new HashSet<>();
23+
public static final Set<String> EARTH_BLOCKS = new HashSet<>();
24+
public static final Set<String> ICE_BLOCKS = new HashSet<>();
25+
public static final Set<String> LAVA_BLOCKS = new HashSet<>();
2626

2727
static {
2828
for (final Material mat : Material.values()) {
@@ -48,7 +48,7 @@ public class StaticMethods {
4848
}
4949

5050
public static boolean isFinite(Location loc) {
51-
return Double.isFinite(loc.getX()) && Double.isFinite(loc.getY()) && Double.isFinite(loc.getZ());
51+
return !Double.isFinite(loc.getX()) || !Double.isFinite(loc.getY()) || !Double.isFinite(loc.getZ());
5252
}
5353

5454
public static boolean isFinite(Vector vec) {
@@ -190,7 +190,7 @@ public static BlockFace getCardinalDirection(Vector vector) {
190190
}
191191

192192
public static Block getRandomSourceBlock(Location location, int radius, Element element) {
193-
List<Integer> checked = new ArrayList<Integer>();
193+
List<Integer> checked = new ArrayList<>();
194194
List<Block> blocks = getBlocksAroundPoint(location, radius);
195195

196196
for (int i = 0; i < blocks.size(); i++) {

src/main/java/net/doodcraft/cozmyc/bendingmobs/ability/air/AirBlast.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
public class AirBlast {
1717

1818
private static final double knockBack = BendingMobs.plugin.getConfig().getDouble("Abilities.Air.AirBlast.Knockback");
19-
public static ConcurrentHashMap<Integer, AirBlast> instances = new ConcurrentHashMap<Integer, AirBlast>();
19+
public static final ConcurrentHashMap<Integer, AirBlast> instances = new ConcurrentHashMap<>();
2020
private static int ID = Integer.MIN_VALUE;
2121
private final LivingEntity entity;
2222
private final Location origin;
2323
private final int id;
24-
private Location head;
25-
private Vector dir;
24+
private final Location head;
25+
private final Vector dir;
2626

2727
public AirBlast(LivingEntity entity, Location target) {
2828
this.entity = entity;
@@ -46,7 +46,7 @@ public static void progressAll() {
4646
}
4747

4848
private boolean progress() {
49-
if (entity == null || !StaticMethods.isFinite(head) || !StaticMethods.isFinite(dir)) {
49+
if (entity == null || StaticMethods.isFinite(head) || !StaticMethods.isFinite(dir)) {
5050
return false;
5151
}
5252
if (entity.getWorld() != head.getWorld()) {

src/main/java/net/doodcraft/cozmyc/bendingmobs/ability/air/AirScooter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class AirScooter {
1212

1313
private static final long duration = BendingMobs.plugin.getConfig().getLong("Abilities.Air.AirScooter.Duration");
1414
private static final double speed = BendingMobs.plugin.getConfig().getDouble("Abilities.Air.AirScooter.Speed");
15-
public static ConcurrentHashMap<Integer, AirScooter> instances = new ConcurrentHashMap<Integer, AirScooter>();
15+
public static final ConcurrentHashMap<Integer, AirScooter> instances = new ConcurrentHashMap<>();
1616
private static int ID = Integer.MIN_VALUE;
1717
private final LivingEntity entity;
1818
private final Location target;

src/main/java/net/doodcraft/cozmyc/bendingmobs/ability/earth/EarthBlast.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class EarthBlast {
2525

2626
private static final double damage = BendingMobs.plugin.getConfig().getDouble("Abilities.Earth.EarthBlast.Damage");
27-
public static ConcurrentHashMap<Integer, EarthBlast> instances = new ConcurrentHashMap<Integer, EarthBlast>();
27+
public static final ConcurrentHashMap<Integer, EarthBlast> instances = new ConcurrentHashMap<>();
2828
private static int ID = Integer.MIN_VALUE;
2929
private final LivingEntity entity;
3030
private Location origin;
@@ -68,7 +68,7 @@ public static void progressAll() {
6868
}
6969

7070
private boolean progress() {
71-
if (entity == null || !StaticMethods.isFinite(head) || !StaticMethods.isFinite(dir)) {
71+
if (entity == null || StaticMethods.isFinite(head) || !StaticMethods.isFinite(dir)) {
7272
return false;
7373
}
7474
if (entity.isDead()) {

0 commit comments

Comments
 (0)