-
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.
Mod damage and health can now be configured in config.yml EXP is now working but it still has a few "glitches" to sort out and perfect
- Loading branch information
1 parent
37ea5d8
commit 15979c8
Showing
10 changed files
with
343 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.myplugin.events; | ||
|
||
import com.myplugin.MyPlugin; | ||
import com.myplugin.lib.Logger; | ||
import com.myplugin.lib.PlayerData; | ||
import com.myplugin.lib.PlayerDataManager; | ||
import com.myplugin.lib.events.TriggerConfigUpdate; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDeathEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class ExperienceHandler implements Listener { | ||
|
||
private final MyPlugin plugin; | ||
private final PlayerDataManager manager; | ||
private HashMap<EntityType, MobExp> vanillaMobs; | ||
|
||
public ExperienceHandler(final MyPlugin plugin) { | ||
this.plugin = plugin; | ||
this.manager = this.plugin.getDataManager(); | ||
this.setConfigValues(); | ||
|
||
Bukkit.getPluginManager().registerEvents(this, this.plugin); | ||
} | ||
|
||
@EventHandler | ||
public void onConfigReload(final TriggerConfigUpdate e) { | ||
this.setConfigValues(); | ||
} | ||
|
||
@EventHandler | ||
public void playerKill(final EntityDeathEvent e) { | ||
if (e.getEntity().getKiller() != null) { | ||
final Player killer = e.getEntity().getKiller(); | ||
final PlayerData data = this.manager.getPlayerData(killer.getUniqueId()); | ||
final MobExp exp = this.vanillaMobs.get(e.getEntityType()); | ||
if (exp.getMax() <= 0 && exp.getMin() <= 0) return; | ||
final int randExp = this.plugin.getRandom().nextInt(exp.getMax() - exp.getMin()) + exp.getMin(); | ||
data.addExperience(randExp); | ||
Logger.debug("Player with UUID: " + killer.getUniqueId() + " receive " + randExp + " EXP for killing a " + e.getEntityType().toString()); | ||
} | ||
} | ||
|
||
public void setConfigValues() { | ||
this.vanillaMobs = new HashMap<>(); | ||
final FileConfiguration config = this.plugin.getConfig(); | ||
final ConfigurationSection expSettings = config.getConfigurationSection("ExpSettings"); | ||
if (expSettings == null) { | ||
Logger.error("Could not find field 'ExpSettings' inside of config.yml"); | ||
return; | ||
} | ||
|
||
for (String s : expSettings.getKeys(false)) { | ||
final EntityType type = EntityType.valueOf(s); | ||
final ConfigurationSection sec = expSettings.getConfigurationSection(s); | ||
if (sec != null) { | ||
final int min = sec.getInt("ExpMin"); | ||
final int max = sec.getInt("ExpMax"); | ||
final MobExp exp = new MobExp(min, max); | ||
this.vanillaMobs.put(type, exp); | ||
} else Logger.error("Could not find config path ExpSettings." + s); | ||
} | ||
} | ||
|
||
private static final class MobExp { | ||
|
||
private final int min; | ||
private final int max; | ||
|
||
public MobExp(final int min, final int max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public final int getMin() { | ||
return this.min; | ||
} | ||
|
||
public final int getMax() { | ||
return this.max; | ||
} | ||
} | ||
} |
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,101 @@ | ||
package com.myplugin.events; | ||
|
||
import com.myplugin.MyPlugin; | ||
import com.myplugin.lib.Logger; | ||
import com.myplugin.lib.events.TriggerConfigUpdate; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.attribute.Attribute; | ||
import org.bukkit.attribute.AttributeInstance; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Bee; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Zombie; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.CreatureSpawnEvent; | ||
|
||
import java.util.HashMap; | ||
import java.util.Set; | ||
|
||
public class MobSpawnManager implements Listener { | ||
|
||
private HashMap<EntityType, MobStat> mobStats; | ||
private Set<EntityType> entitySet; | ||
private final MyPlugin plugin; | ||
|
||
public MobSpawnManager(final MyPlugin plugin) { | ||
this.plugin = plugin; | ||
this.setConfigValues(); | ||
this.entitySet = this.mobStats.keySet(); | ||
|
||
Bukkit.getPluginManager().registerEvents(this, this.plugin); | ||
} | ||
|
||
@EventHandler | ||
public void onConfigUpdate(final TriggerConfigUpdate e) { | ||
this.setConfigValues(); | ||
this.entitySet = this.mobStats.keySet(); | ||
} | ||
|
||
@EventHandler | ||
public void onMobSpawn(final CreatureSpawnEvent e) { | ||
final EntityType type = e.getEntityType(); | ||
if (this.entitySet.contains(type)) { | ||
Logger.debug("Loading MobSpawn data for: " + type); | ||
final MobStat stat = this.mobStats.get(type); | ||
final AttributeInstance attackInstance = e.getEntity().getAttribute(Attribute.GENERIC_ATTACK_DAMAGE); | ||
final AttributeInstance healthInstance = e.getEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH); | ||
if (attackInstance != null) { | ||
e.getEntity().getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(stat.getMobAttack()); | ||
} | ||
|
||
if (healthInstance != null) { | ||
e.getEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(stat.getMobHealth()); | ||
e.getEntity().setHealth(stat.getMobHealth()); | ||
} | ||
} | ||
} | ||
|
||
private void setConfigValues() { | ||
this.mobStats = new HashMap<>(); | ||
final FileConfiguration config = this.plugin.getConfig(); | ||
final ConfigurationSection mobSec = config.getConfigurationSection("MobSettings"); | ||
if (mobSec != null) { | ||
for (String key : mobSec.getKeys(false)) { | ||
final EntityType type = EntityType.valueOf(key); | ||
final ConfigurationSection data = mobSec.getConfigurationSection(key); | ||
if (data != null) { | ||
final int health = data.getInt("Health"); | ||
final int attack = data.getInt("Attack"); | ||
final MobStat stat = new MobStat(health, attack); | ||
this.mobStats.put(type, stat); | ||
Logger.debug("Successfully loaded MobSettings for: " + type.toString()); | ||
} else Logger.error("Config path MobSettings." + key+ " was null when got"); | ||
} | ||
} else Logger.error("MobSetting value from config was null when got"); | ||
|
||
Logger.log("Successfully loaded " + this.mobStats + " ModStats to override for vanilla spawns!s"); | ||
} | ||
|
||
private static class MobStat { | ||
|
||
private final int mobHealth; | ||
private final int mobAttack; | ||
|
||
public MobStat(final int health, final int attack) { | ||
this.mobHealth = health; | ||
this.mobAttack = attack; | ||
} | ||
|
||
public final int getMobHealth() { | ||
return this.mobHealth; | ||
} | ||
|
||
public final int getMobAttack() { | ||
return this.mobAttack; | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.myplugin.events; | ||
|
||
import org.bukkit.event.EventHandler; | ||
|
||
public class PlayerFalls { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.