Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Title and Playsound Commands (#18)
Browse files Browse the repository at this point in the history
* 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
Xenmai authored and mcmonkey4eva committed Apr 25, 2017
1 parent 5c78124 commit 3520822
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 21 deletions.
Expand Up @@ -9,10 +9,7 @@
import com.denizenscript.denizen2sponge.commands.player.*;
import com.denizenscript.denizen2sponge.commands.server.ExecuteCommand;
import com.denizenscript.denizen2sponge.commands.server.ShutdownCommand;
import com.denizenscript.denizen2sponge.commands.world.EditBlockCommand;
import com.denizenscript.denizen2sponge.commands.world.PlayEffectCommand;
import com.denizenscript.denizen2sponge.commands.world.SetBlockCommand;
import com.denizenscript.denizen2sponge.commands.world.WeatherCommand;
import com.denizenscript.denizen2sponge.commands.world.*;
import com.denizenscript.denizen2sponge.events.entity.*;
import com.denizenscript.denizen2sponge.events.player.*;
import com.denizenscript.denizen2sponge.events.server.ClientPingsServerScriptEvent;
Expand Down Expand Up @@ -141,12 +138,14 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.register(new NarrateCommand());
Denizen2Core.register(new PardonCommand());
Denizen2Core.register(new TellCommand());
Denizen2Core.register(new TitleCommand());
// Commands: Server
Denizen2Core.register(new ExecuteCommand());
Denizen2Core.register(new ShutdownCommand());
// Commands: World
Denizen2Core.register(new EditBlockCommand());
Denizen2Core.register(new PlayEffectCommand());
Denizen2Core.register(new PlaySoundCommand());
Denizen2Core.register(new SetBlockCommand());
Denizen2Core.register(new WeatherCommand());
// Events: Entity
Expand Down
@@ -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());
}
}
Expand Up @@ -42,7 +42,7 @@ public class PlayEffectCommand extends AbstractCommand {
// TODO: Explain more!
// @Example
// # This example plays the 'heart' effect around the player.
// - playeffect <player.location> heart --count 50 --offset 1,1,1
// - playeffect <player.location> minecraft:heart --count 50 --offset 1,1,1
// -->

@Override
Expand Down Expand Up @@ -77,17 +77,18 @@ public void execute(CommandQueue queue, CommandEntry entry) {
}
build.type(type.get());
if (entry.namedArgs.containsKey("count")) {
IntegerTag integer = IntegerTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "count"));
build.quantity((int) integer.getInternal());
IntegerTag count = IntegerTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "count"));
build.quantity((int) count.getInternal());
}
if (entry.namedArgs.containsKey("offset")) {
LocationTag offset = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "offset"));
build.offset(offset.getInternal().toVector3d());
}
if (entry.namedArgs.containsKey("motion")) {
LocationTag offset = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "motion"));
build.velocity(offset.getInternal().toVector3d());
LocationTag motion = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "motion"));
build.velocity(motion.getInternal().toVector3d());
}
// TODO: Only show the particles to a list of target players.
if (entry.namedArgs.containsKey("visibility")) {
IntegerTag visibility = IntegerTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "visibility"));
loc.getInternal().world.spawnParticles(build.build(), loc.getInternal().toVector3d(), (int) visibility.getInternal());
Expand All @@ -96,8 +97,9 @@ public void execute(CommandQueue queue, CommandEntry entry) {
loc.getInternal().world.spawnParticles(build.build(), loc.getInternal().toVector3d());
}
if (queue.shouldShowGood()) {
queue.outGood("Successfully played the specified effect of type: "
+ ColorSet.emphasis + type.get().getName() + ColorSet.good + "!");
queue.outGood("Successfully played the particle effect of type '" +
ColorSet.emphasis + type.get().getName() + ColorSet.good + "' at location " +
ColorSet.emphasis + loc.debug() + ColorSet.good + "!");
}
}
}
@@ -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 + "!");
}
}

}
}
Expand Up @@ -4,24 +4,16 @@
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2core.tags.TagData;
import com.denizenscript.denizen2core.tags.objects.*;
import com.denizenscript.denizen2core.utilities.CoreUtilities;
import com.denizenscript.denizen2core.utilities.Function2;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.CuboidTag;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.tags.objects.WorldTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColor;
import org.spongepowered.api.text.format.TextStyles;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.effect.sound.PitchModulation;
import org.spongepowered.api.world.World;

import java.net.MalformedURLException;
import java.net.URL;
import java.lang.reflect.Field;
import java.util.HashMap;

public class ServerTagBase extends AbstractTagBase {
Expand Down

0 comments on commit 3520822

Please sign in to comment.