-
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.
Start working on database & stats system.
Signed-off-by: sqlongithub <[email protected]>
- Loading branch information
1 parent
220fa52
commit 6b06436
Showing
15 changed files
with
530 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,88 @@ | ||
package me.sql.exonrpg.mob; | ||
|
||
import me.sql.exonrpg.ExonRPG; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.ArmorStand; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.metadata.FixedMetadataValue; | ||
import org.bukkit.metadata.LazyMetadataValue; | ||
import org.bukkit.metadata.MetadataValue; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.util.List; | ||
|
||
public class Mob { | ||
|
||
private String mobName; | ||
private EntityType type; | ||
private EntityType entityType; | ||
private MobType mobType; | ||
private int mobHealth; | ||
private int mobLevel; | ||
private List<ItemStack> armor; | ||
private LivingEntity entity; | ||
private Location location; | ||
|
||
public Mob(String mobName, EntityType type, int mobHealth, int mobLevel, List<ItemStack> armor ) { | ||
this.mobName = mobName; | ||
this.type = type; | ||
this.mobHealth = mobHealth; | ||
this.mobLevel = mobLevel; | ||
this.armor = armor; | ||
public Mob(MobType mobType, Location loc) { | ||
this.mobName = mobType.getName(); | ||
this.entityType = mobType.getEntityType(); | ||
this.mobHealth = mobType.getMaxHealth(); | ||
this.mobLevel = mobType.getLevel(); | ||
this.armor = mobType.getArmor(); | ||
this.mobType = mobType; | ||
Entity e = loc.getWorld().spawnEntity(loc, entityType); | ||
if(!(e instanceof LivingEntity)) { | ||
ExonRPG.info("Mob of type "+entityType.toString()+" is not a LivingEntity!"); | ||
return; | ||
} | ||
entity = (LivingEntity) e; | ||
MobMetadata.setDefaults(entity, this); | ||
this.location = entity.getLocation(); | ||
this.entity.setCustomName("§7[Lvl. "+mobLevel+"] §c"+mobName+" §6"+mobHealth+"§b/"+mobType.getMaxHealth()); | ||
} | ||
|
||
public static Mob fromType(MobType type) { | ||
return new Mob(type.getName(), type.getType(), type.getHealth(), type.getLevel(), type.getArmor()); | ||
|
||
public String getName() { | ||
return this.mobName; | ||
} | ||
|
||
public void spawnAtLocation(Location loc) { | ||
Entity e = loc.getWorld().spawnEntity(loc, type); | ||
if(!(e instanceof LivingEntity)) { | ||
ExonRPG.info("Mob of type "+type.toString()+" is not a LivingEntity!"); | ||
return; | ||
public EntityType getEntityType() { | ||
return this.entityType; | ||
} | ||
|
||
public MobType getMobType() { | ||
return this.mobType; | ||
} | ||
|
||
public int getHealth() { | ||
return this.mobHealth; | ||
} | ||
|
||
public int getLevel() { | ||
return this.mobLevel; | ||
} | ||
|
||
public List<ItemStack> getArmor() { | ||
return this.armor; | ||
} | ||
|
||
public Location getLocation() { return this.location; } | ||
|
||
public void updateNametag() { | ||
entity.setCustomName("§7[Lvl. "+mobLevel+"] §c"+mobName+" §6"+mobHealth+"§b/"+mobType.getMaxHealth()); | ||
} | ||
|
||
public void setHealth(int health) { | ||
if(health<=0) { | ||
entity.damage(entity.getHealth()); | ||
} | ||
LivingEntity entity = (LivingEntity) e; | ||
entity.setMetadata(MobMetadata.IS_CUSTOM_MOB.toString(), new FixedMetadataValue(ExonRPG.plugin, true)); | ||
this.mobHealth = health; | ||
updateNametag(); | ||
MobMetadata.setMobHealth(entity, health); | ||
} | ||
|
||
public void setArmor(List<ItemStack> armor) { | ||
this.armor = armor; | ||
MobMetadata.setMobArmor(entity, armor); | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,11 +1,58 @@ | ||
package me.sql.exonrpg.mob; | ||
|
||
import me.sql.exonrpg.ExonRPG; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.metadata.FixedMetadataValue; | ||
|
||
import java.util.List; | ||
|
||
public enum MobMetadata { | ||
|
||
// TODO: Optimize this by removing all the stats metadata and just having the mob | ||
|
||
IS_CUSTOM_MOB, | ||
MOB_NAME, | ||
MOB_HEALTH, | ||
MOB_ARMOR, | ||
MOB_LEVEL, | ||
MOB_TYPE | ||
MOB_TYPE, | ||
MOB; | ||
|
||
public static void setMobHealth(LivingEntity entity, int health) { | ||
entity.setMetadata(MOB_HEALTH.toString(), new FixedMetadataValue(ExonRPG.plugin, health)); | ||
} | ||
|
||
public static void setMobName(LivingEntity entity, String name) { | ||
entity.setMetadata(MOB_NAME.toString(), new FixedMetadataValue(ExonRPG.plugin, name)); | ||
} | ||
|
||
public static void setMobArmor(LivingEntity entity, List<ItemStack> armor) { | ||
entity.setMetadata(MOB_ARMOR.toString(), new FixedMetadataValue(ExonRPG.plugin, armor)); | ||
} | ||
|
||
public static void setMobLevel(LivingEntity entity, int level) { | ||
entity.setMetadata(MOB_LEVEL.toString(), new FixedMetadataValue(ExonRPG.plugin, level)); | ||
} | ||
|
||
public static void setMobType(LivingEntity entity, MobType type) { | ||
entity.setMetadata(MOB_TYPE.toString(), new FixedMetadataValue(ExonRPG.plugin, type)); | ||
} | ||
|
||
public static void setDefaults(LivingEntity entity, Mob mob) { | ||
MobType type = mob.getMobType(); | ||
entity.setMetadata(MobMetadata.IS_CUSTOM_MOB.toString(), new FixedMetadataValue(ExonRPG.plugin, true)); | ||
entity.setMetadata(MobMetadata.MOB.toString(), new FixedMetadataValue(ExonRPG.plugin, mob)); | ||
setMobHealth(entity, type.getMaxHealth()); | ||
setMobLevel(entity, type.getLevel()); | ||
setMobName(entity, type.getName()); | ||
setMobType(entity, type); | ||
setMobArmor(entity, type.getArmor()); | ||
} | ||
|
||
public static Mob getMob(LivingEntity entity) { | ||
return (Mob) entity.getMetadata(MOB.toString()).get(0); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.