From 1aab6ecf2317aa5d99729ca1d27db416262b2a4e Mon Sep 17 00:00:00 2001 From: aegistudio <1910567646@qq.com> Date: Sun, 6 Mar 2016 18:51:46 +0800 Subject: [PATCH] Fix some bugs. Adding compatible extension. --- .classpath | 2 +- .../aegistudio/magick/buff/BuffManager.java | 2 + .../aegistudio/magick/buff/BuffRecord.java | 4 ++ .../magick/buff/MutedBuffManager.java | 21 ++++++-- .../magick/buff/ScoreboardBuffManager.java | 10 ++++ .../cauldron/MagickCauldronListener.java | 34 +++++++------ .../magick/chant/ChantRecordEntry.java | 22 ++++---- .../magick/chant/ChantSpellHandler.java | 9 ++-- .../magick/compat/CompatibleSound.java | 50 +++++++++++++++++++ .../aegistudio/magick/effect/FeatherFall.java | 13 ++--- .../aegistudio/magick/effect/RangedSpawn.java | 7 ++- .../magick/effect/RangedSpawnRunnable.java | 8 ++- .../aegistudio/magick/entity/Flamepillar.java | 7 +-- .../aegistudio/magick/mp/MpSpellHandler.java | 4 +- 14 files changed, 141 insertions(+), 52 deletions(-) create mode 100644 src/net/aegistudio/magick/compat/CompatibleSound.java diff --git a/.classpath b/.classpath index ab10745..ec2d58a 100644 --- a/.classpath +++ b/.classpath @@ -2,6 +2,6 @@ - + diff --git a/src/net/aegistudio/magick/buff/BuffManager.java b/src/net/aegistudio/magick/buff/BuffManager.java index 7a124cd..e9ba001 100644 --- a/src/net/aegistudio/magick/buff/BuffManager.java +++ b/src/net/aegistudio/magick/buff/BuffManager.java @@ -9,6 +9,8 @@ public interface BuffManager extends Module { public void buff(Entity entity, Buff buff, long duration); + public void unbuff(Entity entity, Buff buff); + public void load(MagickElement element, ConfigurationSection section); public void save(MagickElement element, ConfigurationSection section); diff --git a/src/net/aegistudio/magick/buff/BuffRecord.java b/src/net/aegistudio/magick/buff/BuffRecord.java index 4e18c0d..94bc51b 100644 --- a/src/net/aegistudio/magick/buff/BuffRecord.java +++ b/src/net/aegistudio/magick/buff/BuffRecord.java @@ -20,6 +20,10 @@ public void increment(Buff buff, int count) { this.set(buff, this.get(buff) + count); } + public void remove(Buff buff) { + this.buffRecord.remove(buff); + } + public boolean hasBuff(Buff buff) { return buffRecord.containsKey(buff); } diff --git a/src/net/aegistudio/magick/buff/MutedBuffManager.java b/src/net/aegistudio/magick/buff/MutedBuffManager.java index 4d066db..da8dd6c 100644 --- a/src/net/aegistudio/magick/buff/MutedBuffManager.java +++ b/src/net/aegistudio/magick/buff/MutedBuffManager.java @@ -21,11 +21,13 @@ public BuffRemoval(Entity entity, BuffRecord record, Buff buff) { } @Override public void run() { - this.record.increment(buff, -1); - if(!this.record.hasBuff(buff)) - buff.remove(element, entity); + if(this.record.hasBuff(buff)) { + this.record.increment(buff, -1); + if(!this.record.hasBuff(buff)) + buff.remove(element, entity); + } - if(this.record.hasBuff()) + if(!this.record.hasBuff()) entityBuffs.remove(entity.getEntityId()); } } @@ -58,5 +60,14 @@ public void save(MagickElement element, ConfigurationSection section) { public void after(MagickElement element) { this.element = element; } - + + @Override + public void unbuff(Entity entity, Buff buff) { + BuffRecord buffRecord = entityBuffs.get(entity.getEntityId()); + if(buffRecord == null) return; + if(buffRecord.hasBuff(buff)) { + buffRecord.remove(buff); + buff.remove(element, entity); + } + } } diff --git a/src/net/aegistudio/magick/buff/ScoreboardBuffManager.java b/src/net/aegistudio/magick/buff/ScoreboardBuffManager.java index fcfa9e5..4c4ad38 100644 --- a/src/net/aegistudio/magick/buff/ScoreboardBuffManager.java +++ b/src/net/aegistudio/magick/buff/ScoreboardBuffManager.java @@ -50,4 +50,14 @@ public void save(MagickElement element, ConfigurationSection section) { public void after(MagickElement element) { this.element = element; } + + @Override + public void unbuff(Entity entity, Buff buff) { + BuffRecord buffRecord = entityBuffs.get(entity); + if(buffRecord == null) return; + if(buffRecord.hasBuff(buff)) { + buffRecord.remove(buff); + buff.remove(element, entity); + } + } } diff --git a/src/net/aegistudio/magick/cauldron/MagickCauldronListener.java b/src/net/aegistudio/magick/cauldron/MagickCauldronListener.java index dd60a25..efcd902 100644 --- a/src/net/aegistudio/magick/cauldron/MagickCauldronListener.java +++ b/src/net/aegistudio/magick/cauldron/MagickCauldronListener.java @@ -5,7 +5,6 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -15,6 +14,7 @@ import org.bukkit.event.block.BlockIgniteEvent; import net.aegistudio.magick.MagickElement; +import net.aegistudio.magick.compat.CompatibleSound; import net.aegistudio.magick.inventory.BlockCoordinate; import net.aegistudio.magick.particle.BlockParticle; import net.aegistudio.magick.particle.MagickParticle; @@ -36,6 +36,21 @@ public MagickCauldronListener(MagickElement element, CauldronInventoryHandler in this.stillForging = stillForging; this.tickBrewing = tickBrewing; this.tickInterval = tickInterval; + + this.glyph = new MagickParticle(CompatibleSound.ORB_PICKUP.get(element)) { + public int tier() { + return 10; + } + + public float volume() { + return 0.07f; + } + + public float pitch() { + return 0.5f * TONAL_PITCH_LOOKUP[(int)Math.min(Math + .round(8.0f * Math.random()), 7)]; + } + }; } @EventHandler @@ -62,20 +77,7 @@ public void onBreakCauldron(BlockBreakEvent event) { private final BlockParticle blockParticle = new BlockParticle(Effect.HAPPY_VILLAGER, 6); - private final MagickParticle glyph = new MagickParticle(Sound.ORB_PICKUP) { - public int tier() { - return 10; - } - - public float volume() { - return 0.07f; - } - - public float pitch() { - return 0.5f * TONAL_PITCH_LOOKUP[(int)Math.min(Math - .round(8.0f * Math.random()), 7)]; - } - }; + private final MagickParticle glyph; @EventHandler public void onActivateCauldron(BlockIgniteEvent event) { @@ -105,7 +107,7 @@ protected void endTick() { activatedCauldrons.remove(new BlockCoordinate(block.getLocation())); blockParticle.show(block); inventory.brewBlock(block); - block.getWorld().playSound(block.getLocation(), Sound.LEVEL_UP, 1.0f, 1.0f); + block.getWorld().playSound(block.getLocation(), CompatibleSound.LEVEL_UP.get(element), 1.0f, 1.0f); } }; if(event.getPlayer() != null) diff --git a/src/net/aegistudio/magick/chant/ChantRecordEntry.java b/src/net/aegistudio/magick/chant/ChantRecordEntry.java index 1aab305..0129797 100644 --- a/src/net/aegistudio/magick/chant/ChantRecordEntry.java +++ b/src/net/aegistudio/magick/chant/ChantRecordEntry.java @@ -1,23 +1,33 @@ package net.aegistudio.magick.chant; -import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; import net.aegistudio.magick.MagickElement; +import net.aegistudio.magick.compat.CompatibleSound; import net.aegistudio.magick.particle.MagickParticle; public class ChantRecordEntry { public int chantTotal; public int chantStatus; public ItemStack magickBook; + public MagickParticle chantParticle; public ChantRecordEntry(MagickElement element, ItemStack magickBook) { this.magickBook = magickBook; chantTotal = chantStatus = 0; for(String spell : element.book.extractSpell(magickBook)) chantTotal += (int)(element.registry.getSpell(spell).handlerInfo); + this.chantParticle = new MagickParticle(CompatibleSound.LEVEL_UP.get(element)) { + protected int tier() { + return chantStatus; + } + + protected int max() { + return chantTotal; + } + }; } public void execute(Player player, MagickElement element) { @@ -30,14 +40,4 @@ public void execute(Player player, MagickElement element) { public String tips(String format) { return format.replace("$magick", ((BookMeta)magickBook.getItemMeta()).getTitle()); } - - public MagickParticle chantParticle = new MagickParticle(Sound.LEVEL_UP) { - protected int tier() { - return chantStatus; - } - - protected int max() { - return chantTotal; - } - }; } diff --git a/src/net/aegistudio/magick/chant/ChantSpellHandler.java b/src/net/aegistudio/magick/chant/ChantSpellHandler.java index 118369f..55a54a9 100644 --- a/src/net/aegistudio/magick/chant/ChantSpellHandler.java +++ b/src/net/aegistudio/magick/chant/ChantSpellHandler.java @@ -4,7 +4,6 @@ import org.bukkit.ChatColor; import org.bukkit.Effect; -import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -15,6 +14,7 @@ import net.aegistudio.magick.MagickElement; import net.aegistudio.magick.buff.Buff; +import net.aegistudio.magick.compat.CompatibleSound; import net.aegistudio.magick.particle.PlayerParticle; import net.aegistudio.magick.spell.SpellEntry; import net.aegistudio.magick.spell.SpellHandler; @@ -148,6 +148,7 @@ public void buff(MagickElement element, Entity entity) { record.tips(this.endChant); } chantRecord.remove(entityId); + element.buff.unbuff(entity, this); } else record.chantParticle.play(entity.getLocation()); @@ -161,7 +162,7 @@ public void buff(MagickElement element, Entity entity) { public void onPlayerMove(PlayerMoveEvent event) { if(chantRecord.containsKey(event.getPlayer().getEntityId())) { if(event.getTo().distance(event.getFrom()) >= threshold) - this.remove(element, event.getPlayer()); + element.buff.unbuff(event.getPlayer(), this); } } @@ -171,8 +172,8 @@ public void remove(MagickElement element, Entity entity) { if(record != null) { if(spellBreak != null) entity.sendMessage(record.tips(spellBreak)); - entity.getWorld().playSound(entity.getLocation(), Sound.NOTE_BASS, 1.2f, 0.5f); - entity.getWorld().playSound(entity.getLocation(), Sound.NOTE_BASS, 1.2f, 0.25f); + entity.getWorld().playSound(entity.getLocation(), CompatibleSound.NOTE_BASS.get(element), 1.2f, 0.5f); + entity.getWorld().playSound(entity.getLocation(), CompatibleSound.NOTE_BASS.get(element), 1.2f, 0.25f); } } } diff --git a/src/net/aegistudio/magick/compat/CompatibleSound.java b/src/net/aegistudio/magick/compat/CompatibleSound.java new file mode 100644 index 0000000..bdda58b --- /dev/null +++ b/src/net/aegistudio/magick/compat/CompatibleSound.java @@ -0,0 +1,50 @@ +package net.aegistudio.magick.compat; + +import org.bukkit.Sound; + +import net.aegistudio.magick.MagickElement; + +public enum CompatibleSound { + LEVEL_UP(new String[][]{ + {"1.8", "LEVEL_UP"}, + {"1.9", "ENTITY_PLAYER_LEVELUP"} + }), + ORB_PICKUP(new String[][] { + {"1.8", "ORB_PICKUP"}, + {"1.9", "ENTITY_EXPERIENCE_ORB_PICKUP"} + }), + FIZZ(new String[][] { + {"1.8", "FIZZ"}, + {"1.9", "ENTITY_CREEPER_PRIMED"} + }), + NOTE_BASS(new String[][] { + {"1.8", "NOTE_BASS"}, + {"1.9", "BLOCK_NOTE_BASS"} + }), + ENDERDRAGON_WING(new String[][] { + {"1.8", "ENDERDRAGON_WINGS"}, + {"1.9", "ENTITY_ENDERDRAGON_FLAP"} + }); + + private final String[][] mapping; + + private CompatibleSound(String mapping[][]) { + this.mapping = mapping; + } + + public Sound get(MagickElement element) { + String version = element.getServer().getVersion(); + for(int i = 0; i < this.mapping.length - 1; i ++) { + String[] entry = this.mapping[i]; + String[] next = this.mapping[i + 1]; + if(entry[0].compareTo(version) < 0 && + next[0].compareTo(version) > 0) { + return Sound.valueOf(entry[1]); + } + } + + if(this.mapping.length - 1 > 0) + return Sound.valueOf(this.mapping[this.mapping.length - 1][1]); + return null; + } +} diff --git a/src/net/aegistudio/magick/effect/FeatherFall.java b/src/net/aegistudio/magick/effect/FeatherFall.java index e4e28a2..0c12e27 100644 --- a/src/net/aegistudio/magick/effect/FeatherFall.java +++ b/src/net/aegistudio/magick/effect/FeatherFall.java @@ -3,7 +3,6 @@ import java.util.TreeSet; import org.bukkit.Location; -import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -13,6 +12,7 @@ import net.aegistudio.magick.MagickElement; import net.aegistudio.magick.buff.Buff; +import net.aegistudio.magick.compat.CompatibleSound; import net.aegistudio.magick.particle.MagickParticle; import net.aegistudio.magick.spell.SpellEffect; @@ -49,11 +49,7 @@ public void save(MagickElement element, ConfigurationSection spellConfig) { spellConfig.set(EFFECT_BUFFNAME, buffName); } - private final MagickParticle feather = new MagickParticle(Sound.ENDERDRAGON_WINGS) { - public float volume() { - return Math.random() < (1.0 / 12)? 1.0f : 0.0f; - } - }; + private MagickParticle feather; @EventHandler public void handleFallSpeed(PlayerMoveEvent event) { @@ -85,5 +81,10 @@ public void remove(MagickElement element, Entity entity) { @Override public void after(MagickElement element) { element.getServer().getPluginManager().registerEvents(this, element); + this.feather = new MagickParticle(CompatibleSound.ENDERDRAGON_WING.get(element)) { + public float volume() { + return Math.random() < (1.0 / 12)? 1.0f : 0.0f; + } + }; } } diff --git a/src/net/aegistudio/magick/effect/RangedSpawn.java b/src/net/aegistudio/magick/effect/RangedSpawn.java index 17f60d7..f643af4 100644 --- a/src/net/aegistudio/magick/effect/RangedSpawn.java +++ b/src/net/aegistudio/magick/effect/RangedSpawn.java @@ -13,7 +13,8 @@ public class RangedSpawn implements SpellEffect { public static final String CLUSTER = "cluster"; public int cluster = 1; public static final String RANGE = "maxRange"; public double range = 5.0; public static final String MIN_RANGE = "minRange"; public double minRange = 1.0; - public static final String DELAY = "delay"; public int delay = 40; + public static final String LAG = "lag"; public long lag = 0; + public static final String DELAY = "delay"; public long delay = 40; public static final String ENTITY_CLASS = "entityClass"; public static final String ENTITY_CONFIG = "entityConfig"; public Spawnable entity; @@ -28,7 +29,8 @@ public void load(MagickElement element, ConfigurationSection spellConfig) throws if(spellConfig.contains(TIER)) tier = spellConfig.getInt(TIER); if(spellConfig.contains(RANGE)) range = spellConfig.getDouble(RANGE); if(spellConfig.contains(MIN_RANGE)) minRange = spellConfig.getDouble(MIN_RANGE); - if(spellConfig.contains(DELAY)) delay = spellConfig.getInt(DELAY); + if(spellConfig.contains(DELAY)) delay = spellConfig.getLong(DELAY); + if(spellConfig.contains(LAG)) lag = spellConfig.getLong(LAG); if(spellConfig.contains(CLUSTER)) cluster = spellConfig.getInt(CLUSTER); this.entity = element.loadInstance(Spawnable.class, spellConfig, ENTITY_CLASS, null, ENTITY_CONFIG, null); } @@ -38,6 +40,7 @@ public void save(MagickElement element, ConfigurationSection spellConfig) throws spellConfig.set(TIER, tier); spellConfig.set(RANGE, range); spellConfig.set(MIN_RANGE, minRange); + spellConfig.set(LAG, lag); spellConfig.set(DELAY, delay); spellConfig.set(CLUSTER, cluster); diff --git a/src/net/aegistudio/magick/effect/RangedSpawnRunnable.java b/src/net/aegistudio/magick/effect/RangedSpawnRunnable.java index 2c696bc..e517798 100644 --- a/src/net/aegistudio/magick/effect/RangedSpawnRunnable.java +++ b/src/net/aegistudio/magick/effect/RangedSpawnRunnable.java @@ -33,11 +33,15 @@ public void run() { protected void next() { if(tiersRemained > 0) element.getServer().getScheduler().runTaskLater(element, - this, (long) (Math.random() * spawn.delay)); + this, (long)(Math.random() * spawn.delay)); tiersRemained --; } public void start() { - this.next(); + if(tiersRemained > 0) { + element.getServer().getScheduler() + .runTaskLater(element, this, spawn.lag + (long)(Math.random() * spawn.delay)); + tiersRemained --; + } } } diff --git a/src/net/aegistudio/magick/entity/Flamepillar.java b/src/net/aegistudio/magick/entity/Flamepillar.java index b90e482..f4bdb01 100644 --- a/src/net/aegistudio/magick/entity/Flamepillar.java +++ b/src/net/aegistudio/magick/entity/Flamepillar.java @@ -2,12 +2,12 @@ import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.FallingBlock; import net.aegistudio.magick.MagickElement; import net.aegistudio.magick.Spawnable; +import net.aegistudio.magick.compat.CompatibleSound; public class Flamepillar implements Spawnable { @Override @@ -20,16 +20,17 @@ public void save(MagickElement element, ConfigurationSection config) throws Exce } + private MagickElement element; @Override public void after(MagickElement element) { - + this.element = element; } public static final double PILLAR_FACTOR = 0.12; @SuppressWarnings("deprecation") @Override public void spawn(Location location) { - location.getWorld().playSound(location, Sound.FIZZ, 1.0f, 1.0f); + location.getWorld().playSound(location, CompatibleSound.FIZZ.get(element), 1.0f, 1.0f); FallingBlock previous = null; for(int i = 0; i < 3; i ++) { FallingBlock block = location.getWorld() diff --git a/src/net/aegistudio/magick/mp/MpSpellHandler.java b/src/net/aegistudio/magick/mp/MpSpellHandler.java index b5a8c37..f66d453 100644 --- a/src/net/aegistudio/magick/mp/MpSpellHandler.java +++ b/src/net/aegistudio/magick/mp/MpSpellHandler.java @@ -5,13 +5,13 @@ import java.util.TreeSet; import org.bukkit.Effect; -import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; import net.aegistudio.magick.MagickElement; +import net.aegistudio.magick.compat.CompatibleSound; import net.aegistudio.magick.particle.PlayerParticle; import net.aegistudio.magick.spell.SpellEntry; import net.aegistudio.magick.spell.SpellHandler; @@ -48,7 +48,7 @@ public void handleSpell(Player player, ItemStack magickBook) { new MpCooldown(this, player); new PlayerParticle(Effect.HAPPY_VILLAGER, spellPoint).show(player); - player.getWorld().playSound(player.getLocation(), Sound.LEVEL_UP, 1.0f, 1.0f); + player.getWorld().playSound(player.getLocation(), CompatibleSound.LEVEL_UP.get(element), 1.0f, 1.0f); } String title = ((BookMeta)(magickBook.getItemMeta())).getTitle();