-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from m7rlin/dev/marcin
(chore) release 1.2.0
- Loading branch information
Showing
11 changed files
with
440 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
plugin/src/main/java/pl/mgtm/magicznakraina/config/BetterMobsModuleConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pl.mgtm.magicznakraina.config; | ||
|
||
import java.io.Serializable; | ||
|
||
public class BetterMobsModuleConfig implements Serializable { | ||
|
||
// Module status on/off | ||
private boolean enabled; | ||
|
||
|
||
|
||
public BetterMobsModuleConfig() { | ||
} | ||
|
||
public BetterMobsModuleConfig(boolean moduleEnabled) { | ||
this.enabled = moduleEnabled; | ||
} | ||
|
||
public boolean getEnabled() { | ||
return enabled; | ||
} | ||
public void setEnabled(boolean status) { | ||
enabled = status; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
plugin/src/main/java/pl/mgtm/magicznakraina/modules/better_mobs/BetterMobsModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pl.mgtm.magicznakraina.modules.better_mobs; | ||
|
||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import pl.mgtm.magicznakraina.MagicznaKraina; | ||
import pl.mgtm.magicznakraina.module.ModuleInfo; | ||
import pl.mgtm.magicznakraina.module.PluginModule; | ||
import pl.mgtm.magicznakraina.modules.better_mobs.events.*; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
@ModuleInfo(name = "better_mobs") | ||
public class BetterMobsModule extends PluginModule { | ||
|
||
private final MagicznaKraina pl = MagicznaKraina.getInstance(); | ||
|
||
|
||
public BetterMobsModule() { | ||
super(); | ||
|
||
// Register commands | ||
//super.registerCommand(new SpawnCommand()); | ||
//super.registerCommand(new SetSpawnCommand()); | ||
|
||
// Register events | ||
super.registerEvents(new MobDamageEvent()); | ||
super.registerEvents(new MobDeathEvent()); | ||
super.registerEvents(new MobSpawnEvent()); | ||
super.registerEvents(new BossDeathEvent()); | ||
super.registerEvents(new SilverFishSpawnEvent()); | ||
|
||
} | ||
|
||
public static boolean isTakenFromPlayer(ItemStack item) { | ||
ItemMeta itemMeta = item.getItemMeta(); | ||
|
||
// Check if the item has lore indicating it was taken from a player | ||
if (itemMeta != null && itemMeta.getLore() != null) { | ||
for (String loreLine : itemMeta.getLore()) { | ||
if (loreLine.contains("Taken from player")) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static boolean isHostileMob(LivingEntity entity) { | ||
EntityType entityType = entity.getType(); | ||
return entityType.isAlive() && entityType != EntityType.PLAYER && entityType.isSpawnable(); | ||
} | ||
|
||
public static boolean shouldSpawnAsHydra() { | ||
int chance = ThreadLocalRandom.current().nextInt(1, 11); // 10% chance | ||
return chance == 1; | ||
} | ||
|
||
public static boolean shouldSpawnZombieWithExtraSpeed() { | ||
int chance = ThreadLocalRandom.current().nextInt(1, 5); // 25% chance | ||
return chance == 1; | ||
} | ||
|
||
public static boolean shouldSpawnSilverfish(int spawnChance) { | ||
int chance = ThreadLocalRandom.current().nextInt(1, 101); // 1-100 | ||
return chance <= spawnChance; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
plugin/src/main/java/pl/mgtm/magicznakraina/modules/better_mobs/events/BossDeathEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package pl.mgtm.magicznakraina.modules.better_mobs.events; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDeathEvent; | ||
|
||
public class BossDeathEvent implements Listener { | ||
|
||
@EventHandler | ||
public void onEntityDeath(EntityDeathEvent event) { | ||
Entity entity = event.getEntity(); | ||
|
||
// Check if the entity killed is a mob | ||
if (entity instanceof LivingEntity) { | ||
LivingEntity livingEntity = (LivingEntity) entity; | ||
|
||
// Check if the entity is a Hydra | ||
if (livingEntity.getScoreboardTags().contains("Hydra")) { | ||
// Drop double XP | ||
event.setDroppedExp(event.getDroppedExp() * 2); | ||
|
||
// Play extra sound effect | ||
entity.getWorld().playSound(entity.getLocation(), Sound.ENTITY_WITHER_DEATH, 1.0f, 1.0f); | ||
|
||
if (event.getEntity().getKiller() instanceof Player) { | ||
Player player = event.getEntity().getKiller(); | ||
player.sendMessage(ChatColor.RED + "Hydra: "+ ChatColor.GRAY + "Nie dasz rady mnie zabić...."); | ||
} | ||
|
||
// Spawn 2 additional mobs of the same type | ||
int numExtraMobs = 2; | ||
EntityType entityType = livingEntity.getType(); | ||
for (int i = 0; i < numExtraMobs; i++) { | ||
Entity extraMob = livingEntity.getWorld().spawnEntity(livingEntity.getLocation(), entityType); | ||
if (extraMob instanceof LivingEntity) { | ||
LivingEntity livingExtraMob = (LivingEntity) extraMob; | ||
livingExtraMob.setRemoveWhenFarAway(true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
plugin/src/main/java/pl/mgtm/magicznakraina/modules/better_mobs/events/MobDamageEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package pl.mgtm.magicznakraina.modules.better_mobs.events; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Monster; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.inventory.EntityEquipment; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.util.Vector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class MobDamageEvent implements Listener { | ||
|
||
private final Random random = new Random(); | ||
|
||
@EventHandler | ||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | ||
Entity entity = event.getEntity(); | ||
|
||
|
||
// Check if the damaged entity is a player | ||
if (entity instanceof Player) { | ||
|
||
Player player = (Player) entity; | ||
|
||
//player.sendMessage("damage"); | ||
// Check if the attacking entity is a hostile monster | ||
if (event.getDamager().getType().equals(EntityType.ZOMBIE) | ||
|| event.getDamager().getType().equals(EntityType.SPIDER)) { | ||
|
||
// Blast the player into the air | ||
if (random.nextInt(1) == 0) { // 10% chance | ||
//player.sendMessage("To the air!"); | ||
|
||
// Only works when player is jumping | ||
//player.setVelocity(player.getLocation().getDirection().multiply(0).setY(2)); | ||
|
||
// Blast player to the air | ||
player.setVelocity(player.getVelocity().add(new Vector(0, 1, 0))); | ||
} | ||
// Take away player's weapon | ||
if (random.nextInt(2) == 0) { // 1% chance | ||
// Remove player hand item | ||
//player.getInventory().setItemInMainHand(null); | ||
|
||
// Give it the attacker monster | ||
ItemStack weapon = player.getInventory().getItemInMainHand(); | ||
if (weapon != null && !weapon.getType().equals(Material.AIR)) { | ||
player.getInventory().setItemInMainHand(null); | ||
|
||
if (event.getDamager() instanceof Monster) { | ||
Monster attacker = (Monster) event.getDamager(); | ||
EntityEquipment equipment = attacker.getEquipment(); | ||
if (equipment != null) { | ||
if (equipment.getItemInMainHand().getType().equals(Material.AIR)) { | ||
|
||
List<Component> lore = new ArrayList<>(); | ||
lore.add(Component.text("Taken from player")); | ||
weapon.lore(lore); | ||
|
||
equipment.setItemInMainHand(weapon); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
plugin/src/main/java/pl/mgtm/magicznakraina/modules/better_mobs/events/MobDeathEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package pl.mgtm.magicznakraina.modules.better_mobs.events; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Monster; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDeathEvent; | ||
import org.bukkit.inventory.EntityEquipment; | ||
import org.bukkit.inventory.ItemStack; | ||
import pl.mgtm.magicznakraina.modules.better_mobs.BetterMobsModule; | ||
|
||
|
||
public class MobDeathEvent implements Listener { | ||
|
||
@EventHandler | ||
public void onEntityDeath(EntityDeathEvent event) { | ||
LivingEntity entity = event.getEntity(); | ||
|
||
// Check if the entity killed is a boss (Ender Dragon or Wither) | ||
if (entity.getType().equals(EntityType.ENDER_DRAGON) | ||
|| entity.getType().equals(EntityType.WITHER)) { | ||
|
||
|
||
// Increase boss health and damage | ||
entity.setMaxHealth(entity.getMaxHealth() * 2); | ||
entity.setHealth(entity.getMaxHealth()); | ||
} | ||
|
||
|
||
// Check if the entity killed is a Zombie or Spider | ||
if (entity.getType().equals(EntityType.ZOMBIE) || entity.getType().equals(EntityType.SPIDER) || entity.getType().equals(EntityType.SKELETON)) { | ||
// Remove all item drop from entity | ||
//event.getDrops().clear(); | ||
|
||
event.getDrops().removeIf(item -> | ||
item.getType().equals(Material.SHIELD) | ||
|| item.getType().toString().endsWith("_SWORD") | ||
|| item.getType().toString().endsWith("_AXE") | ||
|| item.getType().toString().endsWith("_PICKAXE") | ||
|| item.getType().toString().endsWith("_SHOVEL") | ||
|| item.getType().toString().endsWith("_HOE") | ||
|| item.getType().toString().endsWith("_HELMET") | ||
|| item.getType().toString().endsWith("_CHESTPLATE") | ||
|| item.getType().toString().endsWith("_LEGGINGS") | ||
|| item.getType().toString().endsWith("_BOOTS")); | ||
|
||
//Bukkit.getPlayer("Merlin_PlayGames").sendMessage(event.getDrops() + ""); | ||
|
||
if (entity instanceof Monster) { | ||
Monster monster = (Monster) entity; | ||
EntityEquipment equipment = monster.getEquipment(); | ||
if (equipment != null) { | ||
// Check if the main hand item is not empty | ||
ItemStack mainHandItem = equipment.getItemInMainHand(); | ||
if (mainHandItem != null && !mainHandItem.getType().equals(Material.AIR)) { | ||
// If the item is not generated by plugin | ||
if (BetterMobsModule.isTakenFromPlayer(mainHandItem)) { | ||
// Clear item lore | ||
mainHandItem.lore(null); | ||
// Drop the main hand item on death | ||
event.getDrops().add(mainHandItem); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.