More sound stuff and a hearsound command available to everyone.

This commit is contained in:
Olof Larsson 2013-08-18 13:13:00 +02:00
parent b679c94892
commit 0fd2fc5bf5
7 changed files with 305 additions and 5 deletions

View File

@ -1,6 +1,6 @@
main: com.massivecraft.mcore.MCore main: com.massivecraft.mcore.MCore
name: mcore name: mcore
version: 6.6.0 version: 6.6.1_dev
website: http://massivecraft.com/mcore website: http://massivecraft.com/mcore
authors: [Cayorion] authors: [Cayorion]
description: §eMCore stands for MassiveCraft Core and is a plugin that contains libraries and features that other plugins make use of. §aCayorion §efrom the minecraft server §aMassiveCraft §eis the lead programmer. Feel free to visit us at §bhttp://massivecraft.com description: §eMCore stands for MassiveCraft Core and is a plugin that contains libraries and features that other plugins make use of. §aCayorion §efrom the minecraft server §aMassiveCraft §eis the lead programmer. Feel free to visit us at §bhttp://massivecraft.com
@ -13,6 +13,7 @@ permissions:
mcore.cmd.mcore: {description: use the mcore command, default: false} mcore.cmd.mcore: {description: use the mcore command, default: false}
mcore.cmd.mcore.id: {description: see the server id, default: false} mcore.cmd.mcore.id: {description: see the server id, default: false}
mcore.cmd.mcore.version: {description: diplay plugin version, default: false} mcore.cmd.mcore.version: {description: diplay plugin version, default: false}
mcore.cmd.mcore.hearsound: {description: hear a sound, default: false}
mcore.cmd.mcore.mstore: {description: use the mstore command, default: false} mcore.cmd.mcore.mstore: {description: use the mstore command, default: false}
mcore.cmd.mcore.mstore.stats: {description: show mstore statistics, default: false} mcore.cmd.mcore.mstore.stats: {description: show mstore statistics, default: false}
mcore.cmd.mcore.mstore.listcolls: {description: list collections in a database, default: false} mcore.cmd.mcore.mstore.listcolls: {description: list collections in a database, default: false}
@ -43,6 +44,7 @@ permissions:
mcore.cmd.mcore: true mcore.cmd.mcore: true
mcore.cmd.mcore.id: true mcore.cmd.mcore.id: true
mcore.cmd.mcore.version: true mcore.cmd.mcore.version: true
mcore.cmd.mcore.hearsound: true
mcore.cmd.mcore.mstore: true mcore.cmd.mcore.mstore: true
mcore.cmd.mcore.mstore.stats: true mcore.cmd.mcore.mstore.stats: true
mcore.cmd.mcore.mstore.listcolls: true mcore.cmd.mcore.mstore.listcolls: true
@ -82,9 +84,7 @@ permissions:
default: false default: false
children: children:
mcore.kit.rank0: true mcore.kit.rank0: true
mcore.cmd.mcore: true
mcore.cmd.mcore.id: true mcore.cmd.mcore.id: true
mcore.cmd.mcore.version: true
mcore.cmd.mcore.mstore: true mcore.cmd.mcore.mstore: true
mcore.cmd.mcore.mstore.stats: true mcore.cmd.mcore.mstore.stats: true
mcore.cmd.mcore.mstore.listcolls: true mcore.cmd.mcore.mstore.listcolls: true
@ -99,6 +99,9 @@ permissions:
mcore.kit.rank0: mcore.kit.rank0:
default: false default: false
children: children:
mcore.cmd.mcore: true
mcore.cmd.mcore.hearsound: true
mcore.cmd.mcore.version: true
mcore.kit.default: mcore.kit.default:
default: true default: true
children: children:

View File

@ -13,6 +13,7 @@ public enum MCorePerm
CMD_MCORE("cmd.mcore"), CMD_MCORE("cmd.mcore"),
CMD_MCORE_ID("cmd.mcore.id"), CMD_MCORE_ID("cmd.mcore.id"),
CMD_MCORE_VERSION("cmd.mcore.version"), CMD_MCORE_VERSION("cmd.mcore.version"),
CMD_MCORE_HEARSOUND("cmd.mcore.hearsound"),
CMD_MCORE_MSTORE("cmd.mcore.mstore"), CMD_MCORE_MSTORE("cmd.mcore.mstore"),
CMD_MCORE_MSTORE_STATS("cmd.mcore.mstore.stats"), CMD_MCORE_MSTORE_STATS("cmd.mcore.mstore.stats"),
CMD_MCORE_MSTORE_LISTCOLLS("cmd.mcore.mstore.listcolls"), CMD_MCORE_MSTORE_LISTCOLLS("cmd.mcore.mstore.listcolls"),

View File

@ -0,0 +1,172 @@
package com.massivecraft.mcore;
import java.io.Serializable;
import java.util.Collection;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import com.massivecraft.mcore.cmd.arg.ARSound;
public final class SoundEffect implements Cloneable, Serializable
{
private static final transient long serialVersionUID = 1L;
// -------------------------------------------- //
// FIELDS: RAW
// -------------------------------------------- //
private final Sound sound;
public Sound getSound() { return this.sound; }
private final float volume;
public float getVolume() { return this.volume; }
private final float pitch;
public float getPitch() { return this.pitch; }
// -------------------------------------------- //
// FIELDS: WITH
// -------------------------------------------- //
public SoundEffect withSound(Sound sound) { return new SoundEffect(sound, volume, pitch); }
public SoundEffect withVolume(float volume) { return new SoundEffect(sound, volume, pitch); }
public SoundEffect withPitch(float pitch) { return new SoundEffect(sound, volume, pitch); }
// -------------------------------------------- //
// CONSTUCT
// -------------------------------------------- //
private SoundEffect(Sound sound, float volume, float pitch)
{
this.sound = sound;
this.volume = volume;
this.pitch = pitch;
}
private SoundEffect()
{
// No Arg Constructor for GSON
this(null, 1.0f, 1.0f);
}
// -------------------------------------------- //
// VALUE OF
// -------------------------------------------- //
public static SoundEffect valueOf(Sound sound, float volume, float pitch)
{
return new SoundEffect(sound, volume, pitch);
}
public static SoundEffect valueOf(String soundString) throws Exception
{
if (soundString == null) throw new NullPointerException("soundString was null");
soundString = soundString.trim();
String[] parts = soundString.split("[^a-zA-Z0-9_.]+");
Sound sound = ARSound.getSoundFromString(parts[0]);
if (sound == null) throw new IllegalArgumentException("Unknown sound \"" + parts[0] + "\"");
float volume = 1.0f;
if (parts.length >= 2)
{
volume = Float.parseFloat(parts[1]);
}
float pitch = 1.0f;
if (parts.length >= 3)
{
pitch = Float.parseFloat(parts[2]);
}
return SoundEffect.valueOf(sound, volume, pitch);
}
// -------------------------------------------- //
// RUN
// -------------------------------------------- //
public void run(Location location)
{
location.getWorld().playSound(location, this.getSound(), this.getVolume(), this.getPitch());
}
public void run(Player player, Location location)
{
player.playSound(location, this.getSound(), this.getVolume(), this.getPitch());
}
public void run(Player player)
{
this.run(player, player.getEyeLocation());
}
// -------------------------------------------- //
// RUN ALL
// -------------------------------------------- //
public static void runAll(Collection<SoundEffect> soundEffects, Location location)
{
for (SoundEffect soundEffect : soundEffects)
{
soundEffect.run(location);
}
}
public static void runAll(Collection<SoundEffect> soundEffects, Player player, Location location)
{
for (SoundEffect soundEffect : soundEffects)
{
soundEffect.run(player, location);
}
}
public static void runAll(Collection<SoundEffect> soundEffects, Player player)
{
for (SoundEffect soundEffect : soundEffects)
{
soundEffect.run(player);
}
}
// -------------------------------------------- //
// CLONE
// -------------------------------------------- //
@Override
public SoundEffect clone()
{
return this;
}
// -------------------------------------------- //
// EQUALS & HASHCODE
// -------------------------------------------- //
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + Float.floatToIntBits(pitch);
result = prime * result + ((sound == null) ? 0 : sound.hashCode());
result = prime * result + Float.floatToIntBits(volume);
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof SoundEffect)) return false;
SoundEffect other = (SoundEffect) obj;
if (Float.floatToIntBits(pitch) != Float.floatToIntBits(other.pitch)) return false;
if (sound != other.sound) return false;
if (Float.floatToIntBits(volume) != Float.floatToIntBits(other.volume)) return false;
return true;
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.mcore.cmd.arg;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.SoundEffect;
import com.massivecraft.mcore.util.Txt;
public class ARSoundEffect extends ArgReaderAbstract<SoundEffect>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ARSoundEffect i = new ARSoundEffect();
public static ARSoundEffect get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public ArgResult<SoundEffect> read(String arg, CommandSender sender)
{
ArgResult<SoundEffect> ret = new ArgResult<SoundEffect>();
try
{
ret.setResult(SoundEffect.valueOf(arg));
}
catch (Exception e)
{
ret.setErrors(Txt.parse("<b>") + e.getMessage());
}
return ret;
}
}

View File

@ -0,0 +1,49 @@
package com.massivecraft.mcore.cmd.arg;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.SoundEffect;
import com.massivecraft.mcore.util.Txt;
public class ARSoundEffects extends ArgReaderAbstract<List<SoundEffect>>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ARSoundEffects i = new ARSoundEffects();
public static ARSoundEffects get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public ArgResult<List<SoundEffect>> read(String arg, CommandSender sender)
{
ArgResult<List<SoundEffect>> ret = new ArgResult<List<SoundEffect>>();
List<SoundEffect> result = new ArrayList<SoundEffect>();
arg = arg.trim();
List<String> soundStrings = Arrays.asList(arg.split("\\s+"));
try
{
for (String soundString : soundStrings)
{
result.add(SoundEffect.valueOf(soundString));
}
ret.setResult(result);
}
catch (Exception e)
{
ret.setErrors(Txt.parse("<b>") + e.getMessage());
}
return ret;
}
}

View File

@ -14,6 +14,8 @@ public class CmdMCore extends MCoreCommand
public CmdMCoreUsys cmdMCoreUsys = new CmdMCoreUsys(MUtil.list("usys")); public CmdMCoreUsys cmdMCoreUsys = new CmdMCoreUsys(MUtil.list("usys"));
public CmdMCoreMStore cmdMCoreMStore = new CmdMCoreMStore(MUtil.list("mstore")); public CmdMCoreMStore cmdMCoreMStore = new CmdMCoreMStore(MUtil.list("mstore"));
public CmdMCoreId cmdMCoreId = new CmdMCoreId(MUtil.list("id")); public CmdMCoreId cmdMCoreId = new CmdMCoreId(MUtil.list("id"));
public CmdMCoreHearsound cmdMCoreHearsound = new CmdMCoreHearsound(MUtil.list("hearsound", "hearsounds"));
public VersionCommand cmdMCoreVersion = new VersionCommand(MCore.get(), MCorePerm.CMD_MCORE_VERSION.node, "v", "version");
public CmdMCore(List<String> aliases) public CmdMCore(List<String> aliases)
@ -23,8 +25,8 @@ public class CmdMCore extends MCoreCommand
this.addSubCommand(this.cmdMCoreUsys); this.addSubCommand(this.cmdMCoreUsys);
this.addSubCommand(this.cmdMCoreMStore); this.addSubCommand(this.cmdMCoreMStore);
this.addSubCommand(this.cmdMCoreId); this.addSubCommand(this.cmdMCoreId);
this.addSubCommand(this.cmdMCoreHearsound);
this.addSubCommand(new VersionCommand(MCore.get(), MCorePerm.CMD_MCORE_VERSION.node, "v", "version")); this.addSubCommand(this.cmdMCoreVersion);
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE.node)); this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE.node));
} }

View File

@ -0,0 +1,36 @@
package com.massivecraft.mcore.mcorecmd;
import java.util.List;
import com.massivecraft.mcore.MCorePerm;
import com.massivecraft.mcore.SoundEffect;
import com.massivecraft.mcore.cmd.arg.ARSoundEffects;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
public class CmdMCoreHearsound extends MCoreCommand
{
public CmdMCoreHearsound(List<String> aliases)
{
super(aliases);
this.addRequiredArg("sound(s)");
this.setErrorOnToManyArgs(false);
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_HEARSOUND.node));
this.addRequirements(ReqIsPlayer.get());
}
@Override
public void perform()
{
// Args
List<SoundEffect> soundEffects = this.argConcatFrom(0, ARSoundEffects.get());
if (soundEffects == null) return;
// Apply
SoundEffect.runAll(soundEffects, me);
}
}