Skip to content

Commit

Permalink
MOAR
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed Jan 10, 2018
1 parent fb7ec1c commit 4fe1a2d
Show file tree
Hide file tree
Showing 395 changed files with 3,550 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/org/phantomapi/sfx/Aud.java
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);
}
}
89 changes: 89 additions & 0 deletions src/main/java/org/phantomapi/sfx/Audible.java
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();
}
117 changes: 117 additions & 0 deletions src/main/java/org/phantomapi/sfx/AudibleEntity.java
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;
}
}
142 changes: 142 additions & 0 deletions src/main/java/org/phantomapi/sfx/Audio.java
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);
}
}
}
Loading

0 comments on commit 4fe1a2d

Please sign in to comment.