Skip to content

Commit

Permalink
Fix some bugs. Adding compatible extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
aegistudio committed Mar 6, 2016
1 parent 48c4555 commit 1aab6ec
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="/home/luohaoran/spigot-1.8.7/spigot-1.8.7-R0.1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="/home/luohaoran/spigot-1.9.0/spigot-1.9.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions src/net/aegistudio/magick/buff/BuffManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/net/aegistudio/magick/buff/BuffRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
21 changes: 16 additions & 5 deletions src/net/aegistudio/magick/buff/MutedBuffManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions src/net/aegistudio/magick/buff/ScoreboardBuffManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
34 changes: 18 additions & 16 deletions src/net/aegistudio/magick/cauldron/MagickCauldronListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions src/net/aegistudio/magick/chant/ChantRecordEntry.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
}
};
}
9 changes: 5 additions & 4 deletions src/net/aegistudio/magick/chant/ChantSpellHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
50 changes: 50 additions & 0 deletions src/net/aegistudio/magick/compat/CompatibleSound.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
13 changes: 7 additions & 6 deletions src/net/aegistudio/magick/effect/FeatherFall.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
};
}
}
7 changes: 5 additions & 2 deletions src/net/aegistudio/magick/effect/RangedSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/net/aegistudio/magick/effect/RangedSpawnRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 --;
}
}
}
Loading

0 comments on commit 1aab6ec

Please sign in to comment.