Skip to content

Commit

Permalink
Added a configuration to customize effects, sounds and tweak gameplay
Browse files Browse the repository at this point in the history
Implements #1
  • Loading branch information
Poslovitch committed Dec 15, 2019
1 parent 29f7eed commit 62a48a6
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 10 deletions.
176 changes: 176 additions & 0 deletions src/main/java/world/bentobox/twerk/Settings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package world.bentobox.twerk;

import org.bukkit.Effect;
import org.bukkit.Sound;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
import world.bentobox.bentobox.api.configuration.ConfigObject;
import world.bentobox.bentobox.api.configuration.StoreAt;

/**
* @since 1.1.0
*/
@ConfigComment("TwerkingForTrees v[version] configuration file.")
@ConfigComment("")
@StoreAt(filename="config.yml", path = "addons/TwerkingForTrees")
public class Settings implements ConfigObject {

@ConfigComment("How many times the player must twerk before the tree start growing faster.")
@ConfigComment("If the player has not twerked enough, then the tree will not grow faster.")
@ConfigEntry(path = "minimum-twerks")
private int minimumTwerks = 4;

@ConfigComment("Toggle on/off the sounds.")
@ConfigEntry(path = "sounds.enabled")
private boolean soundsEnabled = true;

@ConfigComment("Sound that plays when the player twerked enough for the sapling to start growing faster.")
@ConfigComment("Available sounds are the following:")
@ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html")
@ConfigEntry(path = "sounds.twerk.sound")
private Sound soundsTwerkSound = Sound.BLOCK_NOTE_BLOCK_BASS;

@ConfigEntry(path = "sounds.twerk.volume")
private float soundsTwerkVolume = 1.0F;

@ConfigEntry(path = "sounds.twerk.pitch")
private float soundsTwerkPitch = 2.0F;

@ConfigComment("Sound that plays when a small tree (1x1) grows.")
@ConfigComment("Available sounds are the following:")
@ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html")
@ConfigEntry(path = "sounds.growing-small-tree.sound")
private Sound soundsGrowingSmallTreeSound = Sound.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT;

@ConfigEntry(path = "sounds.growing-small-tree.volume")
private float soundsGrowingSmallTreeVolume = 1.0F;

@ConfigEntry(path = "sounds.growing-small-tree.pitch")
private float soundsGrowingSmallTreePitch = 1.0F;

@ConfigComment("Sound that plays when a big tree (2x2) grows.")
@ConfigComment("Available sounds are the following:")
@ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html")
@ConfigEntry(path = "sounds.growing-big-tree.sound")
private Sound soundsGrowingBigTreeSound = Sound.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT;

@ConfigEntry(path = "sounds.growing-big-tree.volume")
private float soundsGrowingBigTreeVolume = 1.0F;

@ConfigEntry(path = "sounds.growing-big-tree.pitch")
private float soundsGrowingBigTreePitch = 1.0F;

@ConfigComment("Toggle on/off the particle effects.")
@ConfigEntry(path = "effects.enabled")
private boolean effectsEnabled = true;

@ConfigComment("Effect that plays each time the player twerks.")
@ConfigComment("Available effects are the following:")
@ConfigComment(" https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Effect.html")
@ConfigEntry(path = "effects.twerk")
private Effect effectsTwerk = Effect.MOBSPAWNER_FLAMES;

public int getMinimumTwerks() {
return minimumTwerks;
}

public void setMinimumTwerks(int minimumTwerks) {
this.minimumTwerks = minimumTwerks;
}

public boolean isSoundsEnabled() {
return soundsEnabled;
}

public void setSoundsEnabled(boolean soundsEnabled) {
this.soundsEnabled = soundsEnabled;
}

public Sound getSoundsTwerkSound() {
return soundsTwerkSound;
}

public void setSoundsTwerkSound(Sound soundsTwerkSound) {
this.soundsTwerkSound = soundsTwerkSound;
}

public float getSoundsTwerkVolume() {
return soundsTwerkVolume;
}

public void setSoundsTwerkVolume(float soundsTwerkVolume) {
this.soundsTwerkVolume = soundsTwerkVolume;
}

public float getSoundsTwerkPitch() {
return soundsTwerkPitch;
}

public void setSoundsTwerkPitch(float soundsTwerkPitch) {
this.soundsTwerkPitch = soundsTwerkPitch;
}

public Sound getSoundsGrowingSmallTreeSound() {
return soundsGrowingSmallTreeSound;
}

public void setSoundsGrowingSmallTreeSound(Sound soundsGrowingSmallTreeSound) {
this.soundsGrowingSmallTreeSound = soundsGrowingSmallTreeSound;
}

public float getSoundsGrowingSmallTreeVolume() {
return soundsGrowingSmallTreeVolume;
}

public void setSoundsGrowingSmallTreeVolume(float soundsGrowingSmallTreeVolume) {
this.soundsGrowingSmallTreeVolume = soundsGrowingSmallTreeVolume;
}

public float getSoundsGrowingSmallTreePitch() {
return soundsGrowingSmallTreePitch;
}

public void setSoundsGrowingSmallTreePitch(float soundsGrowingSmallTreePitch) {
this.soundsGrowingSmallTreePitch = soundsGrowingSmallTreePitch;
}

public Sound getSoundsGrowingBigTreeSound() {
return soundsGrowingBigTreeSound;
}

public void setSoundsGrowingBigTreeSound(Sound soundsGrowingBigTreeSound) {
this.soundsGrowingBigTreeSound = soundsGrowingBigTreeSound;
}

public float getSoundsGrowingBigTreeVolume() {
return soundsGrowingBigTreeVolume;
}

public void setSoundsGrowingBigTreeVolume(float soundsGrowingBigTreeVolume) {
this.soundsGrowingBigTreeVolume = soundsGrowingBigTreeVolume;
}

public float getSoundsGrowingBigTreePitch() {
return soundsGrowingBigTreePitch;
}

public void setSoundsGrowingBigTreePitch(float soundsGrowingBigTreePitch) {
this.soundsGrowingBigTreePitch = soundsGrowingBigTreePitch;
}

public boolean isEffectsEnabled() {
return effectsEnabled;
}

public void setEffectsEnabled(boolean effectsEnabled) {
this.effectsEnabled = effectsEnabled;
}

public Effect getEffectsTwerk() {
return effectsTwerk;
}

public void setEffectsTwerk(Effect effectsTwerk) {
this.effectsTwerk = effectsTwerk;
}
}
34 changes: 33 additions & 1 deletion src/main/java/world/bentobox/twerk/TwerkingForTrees.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package world.bentobox.twerk;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.twerk.events.TreeGrowListener;

public final class TwerkingForTrees extends Addon {

// Settings
private Settings settings;
private Config<Settings> configObject = new Config<>(this, Settings.class);

@Override
public void onLoad() {
// Nothing to do
// Save the default config from config.yml
saveDefaultConfig();
// Load the config
loadSettings();
}

/**
* @since 1.1.0
*/
private void loadSettings() {
// Load settings
settings = configObject.loadConfigObject();
// Save config
configObject.saveConfigObject(settings);
}

@Override
Expand All @@ -21,4 +39,18 @@ public void onDisable() {
// Nothing to do here
}

@Override
public void onReload() {
// Reload the config
loadSettings();
}

/**
* Returns the Settings instance
* @return the settings
* @since 1.1.0
*/
public Settings getSettings() {
return settings;
}
}
28 changes: 19 additions & 9 deletions src/main/java/world/bentobox/twerk/events/TreeGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class TreeGrowListener implements Listener {
private static final List<BlockFace> AROUND = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.NORTH_EAST,
BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST);

private static final int TWERK_MIN = 4;
/**
* Converts between sapling and tree type. Why doesn't this API exist already I wonder?
*/
Expand Down Expand Up @@ -83,7 +82,7 @@ public TreeGrowListener(@NonNull TwerkingForTrees addon) {
private void runChecker() {
// Every two seconds
Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> {
isTwerking = twerkCount.entrySet().stream().filter(e -> e.getValue() > TWERK_MIN).map(Map.Entry::getKey).collect(Collectors.toSet());
isTwerking = twerkCount.entrySet().stream().filter(e -> e.getValue() > addon.getSettings().getMinimumTwerks()).map(Map.Entry::getKey).collect(Collectors.toSet());
twerkCount.clear();
plantedTrees.keySet().removeIf(k -> !Tag.SAPLINGS.isTagged(k.getType()));
}
Expand All @@ -110,9 +109,14 @@ private void growTree(Block b) {
TreeType type = SAPLING_TO_TREE_TYPE.getOrDefault(b.getType(), TreeType.TREE);
b.setType(Material.AIR);
b.getWorld().generateTree(b.getLocation(), type);
showSparkles(b);
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
addon.getPlugin().logDebug("Growing 1x1 tree " + type);
b.getWorld().playSound(b.getLocation(), Sound.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, 1F, 1F);
if (addon.getSettings().isSoundsEnabled()) {
b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingSmallTreeSound(),
addon.getSettings().getSoundsGrowingSmallTreeVolume(), addon.getSettings().getSoundsGrowingSmallTreePitch());
}
}
}

Expand All @@ -126,16 +130,21 @@ private boolean bigTreeSaplings(Block b) {
// Get the tree planting location
Location l = b.getRelative(q.get(0)).getLocation();
b.getWorld().generateTree(l, type);
showSparkles(b);
b.getWorld().playSound(b.getLocation(), Sound.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, 1F, 1F);
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
if (addon.getSettings().isSoundsEnabled()) {
b.getWorld().playSound(b.getLocation(), addon.getSettings().getSoundsGrowingBigTreeSound(),
addon.getSettings().getSoundsGrowingBigTreeVolume(), addon.getSettings().getSoundsGrowingBigTreePitch());
}
return true;
}
}
return false;
}

private void showSparkles(Block b) {
AROUND.stream().map(b::getRelative).map(Block::getLocation).forEach(x -> x.getWorld().playEffect(x, Effect.MOBSPAWNER_FLAMES, 0));
AROUND.stream().map(b::getRelative).map(Block::getLocation).forEach(x -> x.getWorld().playEffect(x, addon.getSettings().getEffectsTwerk(), 0));
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
Expand Down Expand Up @@ -169,8 +178,9 @@ public void onTwerk(PlayerToggleSneakEvent e) {
twerkCount.putIfAbsent(i, 0);
int count = twerkCount.get(i) + 1;
twerkCount.put(i, count);
if (count == TWERK_MIN) {
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1F, 2F);
if (count == addon.getSettings().getMinimumTwerks()) {
e.getPlayer().playSound(e.getPlayer().getLocation(), addon.getSettings().getSoundsTwerkSound(),
addon.getSettings().getSoundsTwerkVolume(), addon.getSettings().getSoundsTwerkPitch());
}
});
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# TwerkingForTrees v1.1.0-SNAPSHOT-LOCAL configuration file.
#
# How many times the player must twerk before the tree start growing faster.
# If the player has not twerked enough, then the tree will not grow faster.
minimum-twerks: 4
sounds:
# Toggle on/off the sounds.
enabled: true
twerk:
# Sound that plays when the player twerked enough for the sapling to start growing faster.
# Available sounds are the following:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
sound: BLOCK_NOTE_BLOCK_BASS
volume: 1.0
pitch: 2.0
growing-small-tree:
# Sound that plays when a small tree (1x1) grows.
# Available sounds are the following:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
sound: BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT
volume: 1.0
pitch: 1.0
growing-big-tree:
# Sound that plays when a big tree (2x2) grows.
# Available sounds are the following:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
sound: BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT
volume: 1.0
pitch: 1.0
effects:
# Toggle on/off the particle effects.
enabled: true
# Effect that plays each time the player twerks.
# Available effects are the following:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Effect.html
twerk: MOBSPAWNER_FLAMES

0 comments on commit 62a48a6

Please sign in to comment.