-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
395 changed files
with
3,550 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.phantomapi.sfx; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.Sound; | ||
import org.bukkit.entity.Player; | ||
|
||
import phantom.lang.GSound; | ||
|
||
/** | ||
* Audio sounds commonly used | ||
* | ||
* @author cyberpwn | ||
*/ | ||
public enum Aud | ||
{ | ||
CLICK(new GSound(Sound.UI_BUTTON_CLICK, 1f, 1.5f)); | ||
|
||
private Audible aud; | ||
|
||
private Aud(Audible aud) | ||
{ | ||
this.aud = aud; | ||
} | ||
|
||
public Audible get() | ||
{ | ||
return aud; | ||
} | ||
|
||
public void play(Player p) | ||
{ | ||
get().play(p); | ||
} | ||
|
||
public void play(Location l) | ||
{ | ||
get().play(l); | ||
} | ||
} |
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,89 @@ | ||
package org.phantomapi.sfx; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.util.Vector; | ||
|
||
/** | ||
* Allows you to wrap either objects or more folders of wrappers into one | ||
* audible object allowing multiple sounds at different pitches and volumes be | ||
* played with one object | ||
* | ||
* @author cyberpwn | ||
* | ||
*/ | ||
public interface Audible | ||
{ | ||
/** | ||
* Play the sound to just the player | ||
* | ||
* @param p | ||
* the player | ||
* @param l | ||
* the location | ||
*/ | ||
public void play(Player p, Location l); | ||
|
||
/** | ||
* Play the sound to just the player | ||
* | ||
* @param p | ||
* the player | ||
*/ | ||
public void play(Player p); | ||
|
||
/** | ||
* Play the sound globally | ||
* | ||
* @param l | ||
* the location | ||
*/ | ||
public void play(Location l); | ||
|
||
/** | ||
* Play the sound to the player | ||
* | ||
* @param p | ||
* the player | ||
* @param v | ||
* relative to the players location | ||
*/ | ||
public void play(Player p, Vector v); | ||
|
||
/** | ||
* Get volume | ||
* | ||
* @return the volume | ||
*/ | ||
public Float getVolume(); | ||
|
||
/** | ||
* Sets the volume | ||
* | ||
* @param volume | ||
* the volume | ||
*/ | ||
public void setVolume(Float volume); | ||
|
||
/** | ||
* get the pitch | ||
* | ||
* @return the pitch | ||
*/ | ||
public Float getPitch(); | ||
|
||
/** | ||
* Set the pitch | ||
* | ||
* @param pitch | ||
* the pitch | ||
*/ | ||
public void setPitch(Float pitch); | ||
|
||
/** | ||
* Clone the audio | ||
* | ||
* @return the audio | ||
*/ | ||
public Audible clone(); | ||
} |
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,117 @@ | ||
package org.phantomapi.sfx; | ||
|
||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
|
||
import phantom.sched.Task; | ||
import phantom.world.Area; | ||
|
||
/** | ||
* Audio bound to entities | ||
* | ||
* @author cyberpwn | ||
* | ||
*/ | ||
public class AudibleEntity | ||
{ | ||
private Entity entity; | ||
private Audible audible; | ||
private Task task; | ||
|
||
/** | ||
* Create the audio bind to an entity | ||
* | ||
* @param entity | ||
* the entity | ||
* @param audible | ||
* the audio | ||
* @param interval | ||
* the interval in ticks to play | ||
*/ | ||
public AudibleEntity(Entity entity, Audible audible, Integer interval) | ||
{ | ||
this.entity = entity; | ||
this.audible = audible; | ||
this.task = null; | ||
|
||
if(interval > -1) | ||
{ | ||
task = new Task(interval) | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
if(entity == null || entity.isDead()) | ||
{ | ||
cancel(); | ||
return; | ||
} | ||
|
||
Area a = new Area(entity.getLocation(), 64); | ||
|
||
for(Player i : a.getNearbyPlayers()) | ||
{ | ||
onPlay(i, audible.clone(), entity); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Stop playing the sound | ||
*/ | ||
public void cancel() | ||
{ | ||
if(task != null) | ||
{ | ||
task.cancel(); | ||
} | ||
} | ||
|
||
/** | ||
* Override when played | ||
* | ||
* @param i | ||
* the player | ||
* @param audible | ||
* the sound | ||
* @param entity | ||
* the entity | ||
*/ | ||
protected void onPlay(Player i, Audible audible, Entity entity) | ||
{ | ||
audible.play(i, entity.getLocation()); | ||
} | ||
|
||
/** | ||
* Get the audible sound | ||
* | ||
* @return the sound | ||
*/ | ||
public Audible getAudible() | ||
{ | ||
return audible; | ||
} | ||
|
||
/** | ||
* Set the sound | ||
* | ||
* @param audible | ||
* the sound | ||
*/ | ||
public void setAudible(Audible audible) | ||
{ | ||
this.audible = audible; | ||
} | ||
|
||
/** | ||
* Get the entity | ||
* | ||
* @return the entity | ||
*/ | ||
public Entity getEntity() | ||
{ | ||
return entity; | ||
} | ||
} |
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,142 @@ | ||
package org.phantomapi.sfx; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.util.Vector; | ||
|
||
import phantom.lang.GList; | ||
import phantom.math.Average; | ||
|
||
/** | ||
* A collection of audibles which may contain more sub-audibles or actual sound | ||
* objects. This allows you to create sounds with mixtures of multiple sounds | ||
* and volumes | ||
* | ||
* @author cyberpwn | ||
*/ | ||
public class Audio implements Audible | ||
{ | ||
private GList<Audible> audibles; | ||
|
||
/** | ||
* Create an audible object | ||
*/ | ||
public Audio() | ||
{ | ||
audibles = new GList<Audible>(); | ||
} | ||
|
||
/** | ||
* Create an audible entity with multiple sub-audibles | ||
* | ||
* @param audibles | ||
* the audibles | ||
*/ | ||
public Audio(GList<Audible> audibles) | ||
{ | ||
this.audibles = audibles; | ||
} | ||
|
||
@Override | ||
public Audible clone() | ||
{ | ||
return new Audio(audibles); | ||
} | ||
|
||
/** | ||
* Add an audible object to the sound entity | ||
* | ||
* @param audible | ||
* to be played with the others | ||
*/ | ||
public void add(Audible audible) | ||
{ | ||
audibles.add(audible); | ||
} | ||
|
||
public Audio qadd(Audible audible) | ||
{ | ||
audibles.add(audible); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void play(Player p, Location l) | ||
{ | ||
for(Audible i : audibles) | ||
{ | ||
i.play(p, l); | ||
} | ||
} | ||
|
||
@Override | ||
public void play(Player p) | ||
{ | ||
for(Audible i : audibles) | ||
{ | ||
i.play(p); | ||
} | ||
} | ||
|
||
@Override | ||
public void play(Location l) | ||
{ | ||
for(Audible i : audibles) | ||
{ | ||
i.play(l); | ||
} | ||
} | ||
|
||
@Override | ||
public void play(Player p, Vector v) | ||
{ | ||
for(Audible i : audibles) | ||
{ | ||
i.play(p, v); | ||
} | ||
} | ||
|
||
@Override | ||
public Float getVolume() | ||
{ | ||
Average a = new Average(-1); | ||
|
||
for(Audible i : audibles) | ||
{ | ||
a.put(i.getVolume()); | ||
} | ||
|
||
return (float) a.getAverage(); | ||
} | ||
|
||
@Override | ||
public void setVolume(Float volume) | ||
{ | ||
for(Audible i : audibles) | ||
{ | ||
i.setVolume(volume); | ||
} | ||
} | ||
|
||
@Override | ||
public Float getPitch() | ||
{ | ||
Average a = new Average(-1); | ||
|
||
for(Audible i : audibles) | ||
{ | ||
a.put(i.getPitch()); | ||
} | ||
|
||
return (float) a.getAverage(); | ||
} | ||
|
||
@Override | ||
public void setPitch(Float pitch) | ||
{ | ||
for(Audible i : audibles) | ||
{ | ||
i.setPitch(pitch); | ||
} | ||
} | ||
} |
Oops, something went wrong.