/src/main/java/com/crimsonrpg/magicrpg/MagicRPG.java

https://bitbucket.org/DylanHolmes/magicrpg · Java · 110 lines · 82 code · 19 blank · 9 comment · 6 complexity · ec92a2d83233b704497ce91c65fe5f27 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package com.crimsonrpg.magicrpg;
  6. import java.util.Map;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12. import com.crimsonrpg.magicrpg.spell.Spell;
  13. import com.crimsonrpg.magicrpg.spell.SpellBlink;
  14. import com.crimsonrpg.magicrpg.spell.SpellDoubleJump;
  15. import com.crimsonrpg.magicrpg.spell.SpellEnderDragon;
  16. import com.crimsonrpg.magicrpg.spell.SpellEnderman;
  17. import com.crimsonrpg.magicrpg.spell.SpellExplosion;
  18. import com.crimsonrpg.magicrpg.spell.SpellFireBall;
  19. import com.crimsonrpg.magicrpg.spell.SpellHeal;
  20. import com.crimsonrpg.magicrpg.spell.SpellLightning;
  21. import com.crimsonrpg.magicrpg.spell.SpellThunderStorm;
  22. import com.crimsonrpg.magicrpg.spell.SpellTimeTravel;
  23. import com.crimsonrpg.magicrpg.spell.SpellTornado;
  24. import com.crimsonrpg.magicrpg.spell.SpellTsunami;
  25. import com.crimsonrpg.magicrpg.spell.SpellWildfire;
  26. import java.util.HashMap;
  27. import org.bukkit.entity.Player;
  28. /**
  29. *
  30. * @author simplyianm
  31. */
  32. public class MagicRPG extends JavaPlugin {
  33. public static final Logger LOGGER = Logger.getLogger("Minecraft");
  34. private Map<String, Spell> spells = new HashMap<String, Spell>();
  35. public void onDisable() {
  36. LOGGER.log(Level.INFO, "[MagicRPG] Plugin disabled!");
  37. }
  38. public void onEnable() {
  39. registerSpells(
  40. new SpellBlink(),
  41. new SpellDoubleJump(),
  42. new SpellEnderman(this),
  43. new SpellEnderDragon(this),
  44. new SpellExplosion(),
  45. new SpellHeal(),
  46. new SpellLightning(),
  47. new SpellTimeTravel(),
  48. new SpellTornado(this),
  49. new SpellTsunami(),
  50. new SpellWildfire(),
  51. new SpellThunderStorm(this),
  52. new SpellFireBall(this));
  53. LOGGER.log(Level.INFO, "[MagicRPG] Plugin enabled!");
  54. }
  55. @Override
  56. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  57. if (!(sender instanceof Player)) {
  58. sender.sendMessage("You can only use this command in-game.");
  59. return false;
  60. }
  61. if (args.length < 1) {
  62. sender.sendMessage("You need to input a skill name.");
  63. return false;
  64. }
  65. Spell spell = spells.get(args[0]);
  66. if (spell == null) {
  67. sender.sendMessage("There is no spell registered with that name.");
  68. return false;
  69. }
  70. Player player = (Player) sender;
  71. spell.cast(player);
  72. return true;
  73. }
  74. public void registerSpell(Spell spell) {
  75. Class<?> type = spell.getClass();
  76. //Check annotation
  77. if (!type.isAnnotationPresent(SpellInfo.class)) {
  78. LOGGER.log(Level.WARNING, "Spell '" + spell.getClass() + "' does not have a @SpellInfo annotation present; skipping...");
  79. return;
  80. }
  81. SpellInfo info = type.getAnnotation(SpellInfo.class);
  82. String id = info.id();
  83. String name = info.name();
  84. spells.put(id, spell);
  85. }
  86. public void registerSpells(Spell... spells) {
  87. for (Spell spell : spells) {
  88. registerSpell(spell);
  89. }
  90. }
  91. }