Skip to content

Commit

Permalink
lightning transforms mobs upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed May 28, 2022
1 parent 810d01a commit 3e57e12
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

<groupId>me.youhavetrouble</groupId>
<artifactId>PurpurExtras</artifactId>
<version>1.15.0</version>
<version>1.16.0</version>
<packaging>jar</packaging>

<name>PurpurExtras</name>
@@ -93,7 +93,7 @@
<dependency>
<groupId>com.github.YouHaveTrouble</groupId>
<artifactId>Entiddy</artifactId>
<version>1.2.0</version>
<version>v2.0.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -149,7 +149,8 @@ private void handleLightningTransformedEntities(boolean enable) {
lightningTransformEntities.put(key, value);
}
if (lightningTransformEntities.isEmpty()) return;
plugin.registerListener(LightningTransformsMobsListener.class);

plugin.getServer().getPluginManager().registerEvents(new LightningTransformsMobsListener(lightningTransformEntities), plugin);
}

private void getAnvilCrushIndex() {
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.youhavetrouble.purpurextras.listeners;

import com.destroystokyo.paper.event.entity.EntityZapEvent;
import me.youhavetrouble.entiddy.Entiddy;
import me.youhavetrouble.purpurextras.PurpurExtras;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -18,10 +18,10 @@

public class LightningTransformsMobsListener implements Listener {

private final HashMap<String, Object> entities = new HashMap<>();
private static final HashMap<String, Object> entities = new HashMap<>();

public LightningTransformsMobsListener() {
for (Map.Entry<String, String> entry : PurpurExtras.getPurpurConfig().lightningTransformEntities.entrySet()) {
public LightningTransformsMobsListener(Map<String, String> lightningTransformEntities) {
for (Map.Entry<String, String> entry : lightningTransformEntities.entrySet()) {
getEntityTypeOrSpecial(entry.getKey(), entry.getValue());
}
}
@@ -31,7 +31,10 @@ public void onLightningStrike(EntityDamageByEntityEvent event) {
if (!event.getDamager().getType().equals(EntityType.LIGHTNING)) return;
Entity entity = event.getEntity();
if (!(entity instanceof LivingEntity livingEntity)) return;
if (entity.getEntitySpawnReason().equals(CreatureSpawnEvent.SpawnReason.LIGHTNING)) return;
if (entity.getEntitySpawnReason().equals(CreatureSpawnEvent.SpawnReason.LIGHTNING)) {
event.setCancelled(true);
return;
};
Location location = entity.getLocation();
Entiddy specialEntity = Entiddy.fromEntity(livingEntity);
if (specialEntity != null) {
@@ -72,15 +75,22 @@ private void getEntityTypeOrSpecial(String key, String value) {
}
if (sourceKey == null) {
try {
Entiddy entiddy = Entiddy.valueOf(key);
Entiddy entiddy = Entiddy.valueOf(key.toUpperCase(Locale.ROOT));
sourceKey = key;
} catch (IllegalArgumentException ignored) {}
}
if (goal == null) {
try {
goal = Entiddy.valueOf(value);
goal = Entiddy.valueOf(value.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException ignored) {}
}
this.entities.put(sourceKey, goal);
System.out.println(sourceKey);
System.out.println(goal);
entities.put(sourceKey, goal);
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onLightningStrike(EntityZapEvent event) {
event.setCancelled(true);
}
}

0 comments on commit 3e57e12

Please sign in to comment.