Personal modifications of BloodMoon

This commit is contained in:
Michel Roux 2012-04-29 21:55:29 +02:00
parent 372d6ae022
commit 8de9ba6e06
8 changed files with 16 additions and 126 deletions

View File

@ -1,6 +1,7 @@
name: BloodMoon name: BloodMoon
version: 0.13.2 version: 0.13.2
main: uk.co.jacekk.bukkit.bloodmoon.BloodMoon main: uk.co.jacekk.bukkit.bloodmoon.BloodMoon
author: wide_load & Xefir Destiny
load: startup load: startup
commands: commands:
bloodmoon: bloodmoon:

View File

@ -25,7 +25,6 @@ import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.MoreSpawningListener;
import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SpawnOnKillListener; import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SpawnOnKillListener;
import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SpawnOnSleepListener; import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SpawnOnSleepListener;
import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SuperCreepersListener; import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SuperCreepersListener;
import uk.co.jacekk.bukkit.bloodmoon.featurelisteners.SwordDamageListener;
import uk.co.jacekk.bukkit.bloodmoon.listeners.EntityListener; import uk.co.jacekk.bukkit.bloodmoon.listeners.EntityListener;
import uk.co.jacekk.bukkit.bloodmoon.listeners.PlayerListener; import uk.co.jacekk.bukkit.bloodmoon.listeners.PlayerListener;
import uk.co.jacekk.bukkit.bloodmoon.listeners.WorldListener; import uk.co.jacekk.bukkit.bloodmoon.listeners.WorldListener;
@ -131,10 +130,6 @@ public class BloodMoon extends JavaPlugin {
// arrow-rate is handled in BloodMoonEntitySkeleton // arrow-rate is handled in BloodMoonEntitySkeleton
if (BloodMoon.config.getBoolean("features.sword-damage.enabled")){
this.manager.registerEvents(new SwordDamageListener(this), this);
}
if (BloodMoon.config.getBoolean("features.lock-in-world.enabled") && BloodMoon.config.getBoolean("always-on") == false){ if (BloodMoon.config.getBoolean("features.lock-in-world.enabled") && BloodMoon.config.getBoolean("always-on") == false){
this.manager.registerEvents(new LockInWorldListener(), this); this.manager.registerEvents(new LockInWorldListener(), this);
} }
@ -142,15 +137,6 @@ public class BloodMoon extends JavaPlugin {
if (BloodMoon.config.getBoolean("features.spawn-on-sleep.enabled")){ if (BloodMoon.config.getBoolean("features.spawn-on-sleep.enabled")){
this.manager.registerEvents(new SpawnOnSleepListener(), this); this.manager.registerEvents(new SpawnOnSleepListener(), this);
} }
this.log.info("Enabled.");
}
public void onDisable(){
this.log.info("Disabled");
BloodMoon.config = null;
BloodMoon.bloodMoonWorlds = null;
} }
} }

View File

@ -44,15 +44,6 @@ public class BloodMoonConfig {
this.configDefaults.put("features.more-exp.enabled", true); this.configDefaults.put("features.more-exp.enabled", true);
this.configDefaults.put("features.more-exp.multiplier", 2); this.configDefaults.put("features.more-exp.multiplier", 2);
this.configDefaults.put("features.sword-damage.enabled", true);
this.configDefaults.put("features.sword-damage.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN"));
this.configDefaults.put("features.sword-damage.chance", 10);
this.configDefaults.put("features.sword-damage.damage.diamond", 100);
this.configDefaults.put("features.sword-damage.damage.iron", 20);
this.configDefaults.put("features.sword-damage.damage.gold", 10);
this.configDefaults.put("features.sword-damage.damage.stone", 20);
this.configDefaults.put("features.sword-damage.damage.wood", 10);
this.configDefaults.put("features.super-creepers.enabled", true); this.configDefaults.put("features.super-creepers.enabled", true);
this.configDefaults.put("features.super-creepers.power", 4.0D); this.configDefaults.put("features.super-creepers.power", 4.0D);
@ -65,6 +56,7 @@ public class BloodMoonConfig {
this.configDefaults.put("features.spawn-on-sleep.spawn", Arrays.asList("ZOMBIE")); this.configDefaults.put("features.spawn-on-sleep.spawn", Arrays.asList("ZOMBIE"));
this.configDefaults.put("features.lock-in-world.enabled", true); this.configDefaults.put("features.lock-in-world.enabled", true);
this.configDefaults.put("message", "The blood moon is rising !");
if (configFile.exists()){ if (configFile.exists()){
try { try {
@ -142,4 +134,8 @@ public class BloodMoonConfig {
return this.getStringList(key).contains(mobName); return this.getStringList(key).contains(mobName);
} }
public String getMessage() {
return this.config.getString("message", this.configDefaults.get("message").toString());
}
} }

View File

@ -21,7 +21,7 @@ public class BloodMoonTimeMonitor implements Runnable {
if (worldTime == 123 && Math.random() < (((double) BloodMoon.config.getInt("bloodmoon-chance")) / 100) && BloodMoon.bloodMoonWorlds.contains(worldName) == false){ if (worldTime == 123 && Math.random() < (((double) BloodMoon.config.getInt("bloodmoon-chance")) / 100) && BloodMoon.bloodMoonWorlds.contains(worldName) == false){
for (Player player : world.getPlayers()){ for (Player player : world.getPlayers()){
player.sendMessage(ChatColor.RED + "The blood moon is rising !"); player.sendMessage(ChatColor.RED + BloodMoon.config.getMessage());
} }
BloodMoon.bloodMoonWorlds.add(worldName); BloodMoon.bloodMoonWorlds.add(worldName);

View File

@ -41,7 +41,7 @@ public class BloodMoonExecuter implements CommandExecutor {
BloodMoon.bloodMoonWorlds.add(worldName); BloodMoon.bloodMoonWorlds.add(worldName);
for (Player worldPlayer : world.getPlayers()){ for (Player worldPlayer : world.getPlayers()){
worldPlayer.sendMessage(ChatColor.RED + "[" + player.getName() + "] The blood moon is rising !"); worldPlayer.sendMessage(ChatColor.RED + "[" + player.getName() + "]" + BloodMoon.config.getMessage());
} }
} }

View File

@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
@ -28,11 +27,6 @@ public class LockInWorldListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPortal(PlayerPortalEvent event){
this.onPlayerTeleport(event);
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event){ public void onPlayerRespawn(PlayerRespawnEvent event){
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -1,73 +0,0 @@
package uk.co.jacekk.bukkit.bloodmoon.featurelisteners;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack;
import uk.co.jacekk.bukkit.bloodmoon.BloodMoon;
public class SwordDamageListener implements Listener {
private BloodMoon plugin;
public SwordDamageListener(BloodMoon instance){
this.plugin = instance;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event){
if (event.isCancelled()) return;
Entity entity = event.getEntity();
if (event.getCause() == DamageCause.ENTITY_ATTACK && BloodMoon.bloodMoonWorlds.contains(entity.getWorld().getName())){
if (entity instanceof Creature){
Creature creature = (Creature) entity;
LivingEntity target = creature.getTarget();
if (target instanceof Player){
Player player = (Player) target;
ItemStack item = player.getItemInHand();
// 190 character line :D
if (BloodMoon.config.isCreatureOnMobList("features.sword-damage.mobs", creature) && plugin.rand.nextInt(100) <= BloodMoon.config.getInt("features.sword-damage.chance")){
short damage = item.getDurability();
switch (item.getType()){
case DIAMOND_SWORD:
if (damage > BloodMoon.config.getInt("features.sword-damage.damage.diamond")){
item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.diamond")));
}
case IRON_SWORD:
if (damage > BloodMoon.config.getInt("features.sword-damage.damage.iron")){
item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.iron")));
}
case GOLD_SWORD:
if (damage > BloodMoon.config.getInt("features.sword-damage.damage.gold")){
item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.gold")));
}
case STONE_SWORD:
if (damage > BloodMoon.config.getInt("features.sword-damage.damage.stone")){
item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.stone")));
}
case WOOD_SWORD:
if (damage > BloodMoon.config.getInt("features.sword-damage.damage.wood")){
item.setDurability((short) (item.getDurability() - BloodMoon.config.getInt("features.sword-damage.damage.wood")));
}
}
}
}
}
}
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; import uk.co.jacekk.bukkit.bloodmoon.BloodMoon;
@ -20,7 +19,7 @@ public class PlayerListener implements Listener {
World toWorld = player.getWorld(); World toWorld = player.getWorld();
if (BloodMoon.bloodMoonWorlds.contains(toWorld.getName())){ if (BloodMoon.bloodMoonWorlds.contains(toWorld.getName())){
player.sendMessage(ChatColor.RED + "The blood moon is rising !"); player.sendMessage(ChatColor.RED + BloodMoon.config.getMessage());
} }
} }
@ -29,20 +28,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (BloodMoon.bloodMoonWorlds.contains(player.getWorld().getName())){ if (BloodMoon.bloodMoonWorlds.contains(player.getWorld().getName())){
player.sendMessage(ChatColor.RED + "The blood moon is rising !"); player.sendMessage(ChatColor.RED + BloodMoon.config.getMessage());
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
if (event.isCancelled()) return;
if (event.getMessage().equalsIgnoreCase("/reload")){
event.getPlayer().sendMessage(ChatColor.RED + "Due to the way BloodMoon works, /reload can cause a crash.");
event.getPlayer().sendMessage(ChatColor.RED + "A fix is being worked on, but for now you will have to restart.");
event.getPlayer().sendMessage(ChatColor.RED + "To ignore this and crash the server use /reload force.");
event.setCancelled(true);
} }
} }