This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Title Command * PlaySound Command Also some title command documentation * server.pitch tag Converts a pitch (like A0) to a double that can be used with the playsound command. Also some fixes/improvements to playsound and playeffect. * Fixes * Make Title Required in Title Command Genius
- Loading branch information
1 parent
5c78124
commit 3520822
Showing
5 changed files
with
242 additions
and
21 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
115 changes: 115 additions & 0 deletions
115
src/main/java/com/denizenscript/denizen2sponge/commands/player/TitleCommand.java
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,115 @@ | ||
package com.denizenscript.denizen2sponge.commands.player; | ||
|
||
import com.denizenscript.denizen2core.commands.AbstractCommand; | ||
import com.denizenscript.denizen2core.commands.CommandEntry; | ||
import com.denizenscript.denizen2core.commands.CommandQueue; | ||
import com.denizenscript.denizen2core.tags.AbstractTagObject; | ||
import com.denizenscript.denizen2core.tags.objects.DurationTag; | ||
import com.denizenscript.denizen2core.utilities.debugging.ColorSet; | ||
import com.denizenscript.denizen2sponge.Denizen2Sponge; | ||
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag; | ||
import org.spongepowered.api.text.title.Title; | ||
|
||
public class TitleCommand extends AbstractCommand { | ||
|
||
// <--[command] | ||
// @Name title | ||
// @Arguments <player> <title> [subtitle] | ||
// @Short sends a title to a player. | ||
// @Updated 2017/04/24 | ||
// @Group Player | ||
// @Minimum 2 | ||
// @Maximum 3 | ||
// @Named action_bar (FormattedTextTag) Sets the message that will be shown to the player in the action bar. | ||
// @Named fade_in (DurationTag) Sets the fade in time. | ||
// @Named stay (DurationTag) Sets the stay time. | ||
// @Named fade_out (DurationTag) Sets the fade out time. | ||
// @Description | ||
// Sends a title to a player. Optionally specify fade in, stay and fade out times. | ||
// These times all default to 1 second. | ||
// @Example | ||
// # This example sends the title "hello there!" to the player. | ||
// - title <player> "hello there!" | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "title"; | ||
} | ||
|
||
@Override | ||
public String getArguments() { | ||
return "<player> <title> [subtitle]"; | ||
} | ||
|
||
@Override | ||
public int getMinimumArguments() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public int getMaximumArguments() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
public void execute(CommandQueue queue, CommandEntry entry) { | ||
PlayerTag player = PlayerTag.getFor(queue.error, entry.getArgumentObject(queue, 0)); | ||
Title.Builder build = Title.builder(); | ||
AbstractTagObject title = entry.getArgumentObject(queue, 1); | ||
if (title instanceof FormattedTextTag) { | ||
build.title(((FormattedTextTag) title).getInternal()); | ||
} | ||
else { | ||
build.title(Denizen2Sponge.parseColor(title.toString())); | ||
} | ||
if (entry.arguments.size() > 2) { | ||
AbstractTagObject subtitle = entry.getArgumentObject(queue, 2); | ||
if (subtitle instanceof FormattedTextTag) { | ||
build.subtitle(((FormattedTextTag) subtitle).getInternal()); | ||
} | ||
else { | ||
build.subtitle(Denizen2Sponge.parseColor(subtitle.toString())); | ||
} | ||
} | ||
if (entry.namedArgs.containsKey("action_bar")) { | ||
AbstractTagObject ato = entry.getNamedArgumentObject(queue, "action_bar"); | ||
if (ato instanceof FormattedTextTag) { | ||
build.actionBar(((FormattedTextTag) ato).getInternal()); | ||
} | ||
else { | ||
build.actionBar(Denizen2Sponge.parseColor(ato.toString())); | ||
} | ||
} | ||
if (entry.namedArgs.containsKey("fade_in")) { | ||
DurationTag dur = DurationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "fade_in")); | ||
build.fadeIn((int) (dur.getInternal() * 20)); | ||
} | ||
else { | ||
build.fadeIn(20); | ||
} | ||
if (entry.namedArgs.containsKey("stay")) { | ||
DurationTag dur = DurationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "stay")); | ||
build.stay((int) (dur.getInternal() * 20)); | ||
} | ||
else { | ||
build.stay(20); | ||
} | ||
if (entry.namedArgs.containsKey("fade_out")) { | ||
DurationTag dur = DurationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "fade_out")); | ||
build.fadeOut((int) (dur.getInternal() * 20)); | ||
} | ||
else { | ||
build.fadeOut(20); | ||
} | ||
if (queue.shouldShowGood()) { | ||
queue.outGood("Showing title '" + (build.getTitle().isPresent() ? | ||
ColorSet.emphasis + build.getTitle().get().toPlain() + ColorSet.good : "") + | ||
"' and subtitle '" + (build.getSubtitle().isPresent() ? | ||
ColorSet.emphasis + build.getSubtitle().get().toPlain() + ColorSet.good : "") + | ||
"' to player:" + ColorSet.emphasis + player.debug() + ColorSet.good + "!"); | ||
} | ||
player.getInternal().sendTitle(build.build()); | ||
} | ||
} |
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
113 changes: 113 additions & 0 deletions
113
src/main/java/com/denizenscript/denizen2sponge/commands/world/PlaySoundCommand.java
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,113 @@ | ||
package com.denizenscript.denizen2sponge.commands.world; | ||
|
||
import com.denizenscript.denizen2core.commands.AbstractCommand; | ||
import com.denizenscript.denizen2core.commands.CommandEntry; | ||
import com.denizenscript.denizen2core.commands.CommandQueue; | ||
import com.denizenscript.denizen2core.tags.objects.NumberTag; | ||
import com.denizenscript.denizen2core.utilities.CoreUtilities; | ||
import com.denizenscript.denizen2core.utilities.debugging.ColorSet; | ||
import com.denizenscript.denizen2sponge.tags.objects.LocationTag; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.effect.sound.SoundType; | ||
|
||
import java.util.Optional; | ||
|
||
public class PlaySoundCommand extends AbstractCommand { | ||
|
||
// <--[explanation] | ||
// @Name Sound Types | ||
// @Group Useful Lists | ||
// @Description | ||
// A list of all default sound types can be found here: | ||
// <@link url https://jd.spongepowered.org/6.0.0-SNAPSHOT/org/spongepowered/api/effect/sound/SoundTypes.html>sound types list<@/link> | ||
// These can be used with the playsound command, if you replace '_' with '.'. | ||
// For example, 'entity.arrow.hit' is a valid sound type. | ||
// --> | ||
|
||
// <--[command] | ||
// @Name playsound | ||
// @Arguments <location> <sound> <volume> | ||
// @Short plays a sound. | ||
// @Updated 2017/04/24 | ||
// @Group World | ||
// @Minimum 2 | ||
// @Maximum 2 | ||
// @Named pitch (IntegerTag) Sets the pitch of the sound. | ||
// @Named min_volume (IntegerTag) Sets the minimum volume of the sound. | ||
// @Description | ||
// Plays a sound at certain location. Optionally specify a pitch and minimum volume. | ||
// Related information: <@link explanation Sound Types>sound types<@/link>. | ||
// TODO: Explain more! | ||
// @Example | ||
// # This example plays a loud 'entity_arrow_hit' sound at the player's location. | ||
// - playsound <player.location> entity.arrow.hit 2 | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "playsound"; | ||
} | ||
|
||
@Override | ||
public String getArguments() { | ||
return "<location> <sound> <volume>"; | ||
} | ||
|
||
@Override | ||
public int getMinimumArguments() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
public int getMaximumArguments() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
public void execute(CommandQueue queue, CommandEntry entry) { | ||
LocationTag loc = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 0)); | ||
String soundName = CoreUtilities.toLowerCase(entry.getArgumentObject(queue, 1).toString()); | ||
Optional<SoundType> type = Sponge.getRegistry().getType(SoundType.class, soundName); | ||
if (!type.isPresent()) { | ||
queue.handleError(entry, "Invalid sound type: '" + soundName + "'!"); | ||
return; | ||
} | ||
NumberTag volume = NumberTag.getFor(queue.error, entry.getArgumentObject(queue, 2)); | ||
NumberTag pitch; | ||
NumberTag min_volume; | ||
// TODO: Only play the sound to a list of target players. | ||
// TODO: Allow for playing custom sounds. | ||
if (entry.namedArgs.containsKey("pitch")) { | ||
pitch = NumberTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "pitch")); | ||
if (entry.namedArgs.containsKey("min_volume")) { | ||
min_volume = NumberTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "min_volume")); | ||
loc.getInternal().world.playSound(type.get(), loc.getInternal().toVector3d(), volume.getInternal(), pitch.getInternal(), min_volume.getInternal()); | ||
if (queue.shouldShowGood()) { | ||
queue.outGood("Successfully played the sound of type '" + ColorSet.emphasis + type.get().getName() + | ||
ColorSet.good + "' with volume of " + ColorSet.emphasis + volume.debug() + ColorSet.good + | ||
", pitch of " + ColorSet.emphasis + pitch.debug() + ColorSet.good + " and minimum volume of " + | ||
ColorSet.emphasis + min_volume.debug() + ColorSet.good + " at location " + ColorSet.emphasis + | ||
loc.debug() + ColorSet.good + "!"); | ||
} | ||
} | ||
else { | ||
loc.getInternal().world.playSound(type.get(), loc.getInternal().toVector3d(), volume.getInternal(), pitch.getInternal()); | ||
if (queue.shouldShowGood()) { | ||
queue.outGood("Successfully played the sound of type '" + ColorSet.emphasis + type.get().getName() + | ||
ColorSet.good + "' with volume of " + ColorSet.emphasis + volume.debug() + ColorSet.good + | ||
" and pitch of " + ColorSet.emphasis + pitch.debug() + ColorSet.good + " at location " + | ||
ColorSet.emphasis + loc.debug() + ColorSet.good + "!"); | ||
} | ||
} | ||
} | ||
else { | ||
loc.getInternal().world.playSound(type.get(), loc.getInternal().toVector3d(), volume.getInternal()); | ||
if (queue.shouldShowGood()) { | ||
queue.outGood("Successfully played the sound of type '" + ColorSet.emphasis + type.get().getName() + | ||
ColorSet.good + "' with volume of " + ColorSet.emphasis + volume.debug() + ColorSet.good + | ||
" at location " + ColorSet.emphasis + loc.debug() + ColorSet.good + "!"); | ||
} | ||
} | ||
|
||
} | ||
} |
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