Skip to content

Commit

Permalink
Merge pull request #40 from m7rlin/dev/marcin
Browse files Browse the repository at this point in the history
(chore) release 1.2.0
  • Loading branch information
m7rlin committed Jun 9, 2023
2 parents 382b06f + 90d103b commit 1681032
Show file tree
Hide file tree
Showing 11 changed files with 440 additions and 141 deletions.
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>pl.mgtm</groupId>
<artifactId>MagicznaKraina</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>MagicznaKraina</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pl.mgtm.magicznakraina.config.MainConfig;
import pl.mgtm.magicznakraina.config.UsersConfig;
import pl.mgtm.magicznakraina.module.PluginModuleManager;
import pl.mgtm.magicznakraina.modules.better_mobs.BetterMobsModule;
import pl.mgtm.magicznakraina.modules.clever_sleep.CleverSleepModule;
import pl.mgtm.magicznakraina.modules.home.HomeModule;
import pl.mgtm.magicznakraina.modules.home.commands.HomeCommand;
Expand Down Expand Up @@ -89,6 +90,7 @@ public void onEnable() {
new ResetWorldsModule();
new SpawnModule();
new HomeModule();
new BetterMobsModule();

getLogger().info("MagicznaKraina has been successfully loaded!");
}
Expand Down
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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pl.mgtm.magicznakraina.api.config.annotation.Comment;
import pl.mgtm.magicznakraina.api.config.annotation.ConfigName;

@ConfigName("merlin.yml")
@ConfigName("config.yml")
public interface MainConfig extends Config {

default boolean getDebug() {
Expand Down Expand Up @@ -58,6 +58,12 @@ default KitsModuleConfig getKitsModule() {

void setKitsModule(KitsModuleConfig kitsModuleConfig);

default BetterMobsModuleConfig getBetterMobsModule() {
return new BetterMobsModuleConfig(true);
}

void setBetterMobsModule(BetterMobsModuleConfig kitsModuleConfig);

}


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;
}

}
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);
}
}
}
}
}
}
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);
}
}
}
}
}
}
}
}
}
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);
}

}
}
}
}
}

}
Loading

0 comments on commit 1681032

Please sign in to comment.