org.bukkit.SoundCategory Java Examples

The following examples show how to use org.bukkit.SoundCategory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoundMessageSign.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initialize() {
    sound = getLine(1);
    if (getLine(2).isEmpty()) {
        return;
    }

    String[] args = getLine(2).split(",");
    if (args.length >= 1 && args.length != 2 && Internals.isAtLeast(Internals.v1_11_R1)) {
        category = EnumUtil.getEnumIgnoreCase(SoundCategory.class, args[0]);
        if (category == null) {
            category = SoundCategory.MASTER;
        }
    }
    if (args.length == 2) {
        volume = (float) NumberUtil.parseDouble(args[0], 5.0);
        pitch = (float) NumberUtil.parseDouble(args[1], 1.0);
    } else if (args.length == 3) {
        volume = (float) NumberUtil.parseDouble(args[1], 5.0);
        pitch = (float) NumberUtil.parseDouble(args[2], 1.0);
    }
}
 
Example #2
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
	Player player = event.getPlayer();
	Connection connection = ProtocolSupportAPI.getConnection(player);
	if (
		(connection != null) &&
		(connection.getVersion().getProtocolType() == ProtocolType.PC) &&
		connection.getVersion().isBefore(ProtocolVersion.MINECRAFT_1_9)
	) {
		BlockDataEntry blockdataentry = MinecraftBlockData.get(MaterialAPI.getBlockDataNetworkId(event.getBlock().getBlockData()));
		player.playSound(
			event.getBlock().getLocation(),
			blockdataentry.getBreakSound(),
			SoundCategory.BLOCKS,
			(blockdataentry.getVolume() + 1.0F) / 2.0F,
			blockdataentry.getPitch() * 0.8F
		);
	}
}
 
Example #3
Source File: EffStopSound.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "null"})
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	sounds = (Expression<String>) exprs[0];
	if (SOUND_CATEGORIES_EXIST) {
		category = (Expression<SoundCategory>) exprs[1];
		players = (Expression<Player>) exprs[2];
	} else {
		players = (Expression<Player>) exprs[1];
	}
	return true;
}
 
Example #4
Source File: EffPlaySound.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "null"})
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	sounds = (Expression<String>) exprs[0];
	if (SOUND_CATEGORIES_EXIST) {
		category = (Expression<SoundCategory>) exprs[1];
		volume = (Expression<Number>) exprs[2];
		pitch = (Expression<Number>) exprs[3];
		if (matchedPattern == 0) {
			locations = (Expression<Location>) exprs[4];
			players = (Expression<Player>) exprs[5];
		} else {
			players = (Expression<Player>) exprs[4];
			locations = (Expression<Location>) exprs[5];
		}
	} else {
		volume = (Expression<Number>) exprs[1];
		pitch = (Expression<Number>) exprs[2];
		if (matchedPattern == 0) {
			locations = (Expression<Location>) exprs[3];
			players = (Expression<Player>) exprs[4];
		} else {
			players = (Expression<Player>) exprs[3];
			locations = (Expression<Location>) exprs[4];
		}
	}
	return true;
}
 
Example #5
Source File: EffPlaySound.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
private static void playSound(Player p, Location location, String[] sounds, SoundCategory category, float volume, float pitch) {
	for (String sound : sounds) {
		Sound soundEnum = null;
		try {
			soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
		} catch (IllegalArgumentException ignored) {}
		if (SOUND_CATEGORIES_EXIST) {
			if (soundEnum == null) {
				sound = sound.toLowerCase(Locale.ENGLISH);
				if (!SOUND_VALID_PATTERN.matcher(sound).matches())
					continue;
				p.playSound(location, sound, category, volume, pitch);
			} else {
				p.playSound(location, soundEnum, category, volume, pitch);
			}
		} else {
			if (soundEnum == null) {
				sound = sound.toLowerCase(Locale.ENGLISH);
				if (!SOUND_VALID_PATTERN.matcher(sound).matches())
					continue;
				p.playSound(location, sound, volume, pitch);
			} else {
				p.playSound(location, soundEnum, volume, pitch);
			}
		}
	}
}
 
Example #6
Source File: EffPlaySound.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
private static void playSound(Location location, String[] sounds, SoundCategory category, float volume, float pitch) {
	World w = location.getWorld();
	for (String sound : sounds) {
		Sound soundEnum = null;
		try {
			soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
		} catch (IllegalArgumentException ignored) {}
		if (SOUND_CATEGORIES_EXIST) {
			if (soundEnum == null) {
				sound = sound.toLowerCase(Locale.ENGLISH);
				if (!SOUND_VALID_PATTERN.matcher(sound).matches())
					continue;
				w.playSound(location, sound, category, volume, pitch);
			} else {
				w.playSound(location, soundEnum, category, volume, pitch);
			}
		} else {
			if (soundEnum == null) {
				sound = sound.toLowerCase(Locale.ENGLISH);
				if (!SOUND_VALID_PATTERN.matcher(sound).matches())
					continue;
				w.playSound(location, sound, volume, pitch);
			} else {
				w.playSound(location, soundEnum, volume, pitch);
			}
		}
	}
}
 
Example #7
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch) {
    TaskManager.IMP.sync(new RunnableVal<Object>() {
        @Override
        public void run(Object value) {
            parent.playSound(location, sound, category, volume, pitch);
        }
    });
}
 
Example #8
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void playSound(Location location, String sound, SoundCategory category, float volume, float pitch) {
    TaskManager.IMP.sync(new RunnableVal<Object>() {
        @Override
        public void run(Object value) {
            parent.playSound(location, sound, category, volume, pitch);
        }
    });
}
 
Example #9
Source File: PlaysoundEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
public PlaysoundEvent(Instruction instruction) throws InstructionParseException {
    super(instruction, true);
    sound = instruction.next();
    location = instruction.getLocation(instruction.getOptional("location"));
    String category = instruction.getOptional("category");
    if (category != null) {
        soundCategoty = instruction.getEnum(category, SoundCategory.class);
    } else {
        soundCategoty = SoundCategory.MASTER;
    }
    volume = (float) instruction.getDouble(instruction.getOptional("volume"), 1D);
    pitch = (float) instruction.getDouble(instruction.getOptional("pitch"), 1D);
}