Skip to content

Commit

Permalink
Improvements:
Browse files Browse the repository at this point in the history
* Allows to fix the max number of riders (you can have several groups)
* Add configurable cooldowns (actions and messages)
* Now, items used can be consumed (your choice)
* Add the permission playerrider.ride.keepitem
* Add the permission playerrider.whip.keepitem
* Add an option to prevent the rider to be hit by his victim
  • Loading branch information
arboriginal committed Dec 4, 2018
1 parent 0b47190 commit 275ef47
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 53 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Simply copy [PlayerRider.jar](https://github.com/arboriginal/PlayerRider/release

* **playerrider.reload**: Allows to use `/prider-reload` command.
* **playerrider.ride**: Allows to ride a player.
* **playerrider.ride.keepitem**: Allows to ride a player without consuming the item (if activated).
* **playerrider.whip**t: Allows to whip he player you are riding.
* **playerrider.whip.keepitem**t: Allows to whip he player you are riding without consuming the item (if activated).
* **playerrider.duck**: Allows to be ridden.
* **playerrider.eject**: Allows to eject your passenger.

Expand All @@ -50,10 +52,7 @@ Edit `plugins/PlayerRider/config.yml` then reload the plugin, or the server if y

## Previous version

I did this plugin in 2012, as an easter egg, players on the server I was got tons of fun with it *(we mainly used it on new guys who are not correct)*. So I've decided to extract this part, and shared it as an independent plugin on [Bukkit.org page](http://dev.bukkit.org/projects/playerrider). Then, I've stopped to play at Minecraft, and seen people grabbed the code and make their own "updated" versions *(with minor modifications like change the value of the API...)* without mention the origin, this had discouraged me to make new releases.

## For now
I've recently started a server with friends, so it gives me motivation to re-use Java and develop new plugins. I've ported this one because it was funny to play with and quick to upgrade. The new version contains (much) more options and a few funny features.
I did this plugin in 2012, as an easter egg, players on the server I was got tons of fun with it *(we mainly used it on new guys who are not correct)*. So I've decided to extract this part, and shared it as an independent plugin on [Bukkit.org page](http://dev.bukkit.org/projects/playerrider).

## TODO
Because hitboxes have changed, the player ridden can see his rider's legs. I will work soon to improve this not to reduce the FOV. But the plugin is fully working except this visual effect.
80 changes: 68 additions & 12 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,70 @@
#
# Prefix used to all plugin messages (at least by default...)
# If you want a different prefix for messages (or no prefix), leave it blank « "" ».
# This value replace « {prefix} » in the next parameters.
# This value replace « {prefix} » in the next parameters.
prefix: "&8[&7&lPlayerRider&8] "
# Message displayed when using the command /prider-reload
reload: "{prefix} &aConfiguration successfully reloaded."
reload: "{prefix}&aConfiguration successfully reloaded."
# Error message when the chosen sound « boost_whip_sound » is incorrect.
sndErr: "{prefix} &cChosen sound is invalid and has been disabled."
sndErr: "{prefix}&cChosen sound is invalid and has been disabled."
# Message sent to player trying to ride a player who already have reached his limit.
tooMany: "{prefix}&6{duck}&c cannot wear more players... He needs to eat more spinach!"
# Message when the player should be able to ride but it's fail (maybe another plugin cancel the event)
failed: "{prefix}&cUnable to ride &6{duck}&c, maybe another plugin is preventing it..."

# In the both 3 sections: (broadcast, player and duck)
# - sub-section "ride" is used when a player riders another
# - sub-section "eject" when he's being ejected
# - sub-section "whip" is used when a player whips another
# - sub-section "eject" when he's being ejected
#
# If you don't want one those messages, simply leave it blank « "" ».

# If you don't want one of those messages, simply leave it blank « "" ».
# You can also adjust the cooldown for messages, see below.
broadcast:
ride: "&f&l•&r {prefix}&6{player}&3 now rides &6{duck}&3!"
whip: "&f&l•&r {prefix}&6{player}&3 whips &6{duck}&3!"
eject: "&f&l•&r {prefix}&6{duck}&3 has ejected &6{player}&3!"

player:
ride: "{prefix}&bYou are riding &e&l{duck}&b, yeah!!!"
whip: "{prefix}&bYou whiped &e&l{duck}&b!!!"
eject: "{prefix}&e&l{duck}&b's got a temper, try to give him a carrot maybe?"

duck:
ride: "{prefix}&e&l{player}&b likes you so much, he now stands on your shoulder :)"
whip: "{prefix}&e&l{player}&b whipped you, do you like that?"
eject: "{prefix}&bYou've just ejected &e&l{player}&b, beware... I'm sure he will try again!"

cooldowns:
ride:
perform: 0
broadcast: 30
alertPlayer: 0
alertDuck: 0

whip:
perform: 2
broadcast: 30
alertPlayer: 2
alertDuck: 2

eject:
perform: 3 # Not a real cooldown here, but time to wait before being able to eject the rider
broadcast: 30
alertPlayer: 3
alertDuck: 3

# When an action cannot be done because of the cooldown, the player will receive this message
# Because the chat can be spammed or not read, this will be done as an action bar message.
# Here, you can use {delay} as the delay value in seconds before the player will be able again.
#
# If you don't want one of those messages, simply leave it blank « "" ».
warn_player_when_cooldown:
ride: "&4&lWait &6&l{delay}&4&ls before to ride another player"
whip: "&4&lWait &6&l{delay}&4&ls before to whip again &e&l{duck}"
eject: "&4&lWait &6&l{delay}&4&ls before to eject &e&l{duck}"

########################################################################################################
# Settings which change the plugin mechanisms
# Settings which change the plugin mechanisms
########################################################################################################

# Here, you will define which items the player can have in hand to perform the action.
Expand All @@ -55,6 +92,23 @@ allowed_items:
- CARROT
- GOLDEN_CARROT

# You decide if items used to perform the action are consumed or not
consume_items:
ride: false
whip: true

# Define how many riders can sit on the same player's shoulders
# You can set groups you need, and give the appropriate permission to your users.
# Each groups you define will be checked with the permission "playerrider.duck.<group>"
max_riders:
# This group is the default one (if you delete it, it will be re-added into your configuration).
# It will be applied to all players who don't have another "playerrider.duck.<group>" permission.
# No need to give the permission "playerrider.duck.newbies", it's assumed if the player have "playerrider.duck".
default: 16
# Here are some examples to illustrate:
# newbies: 1 <--- corresponds to the permission "playerrider.duck.newbies"
# staff: 32 <--- corresponds to the permission "playerrider.duck.staff"

# Max pitch value the riden player must be to be able to eject his rider
# (look with F3 in the game and see what pich value is OK for you).
eject_maxPitch: -40.0
Expand All @@ -64,20 +118,22 @@ eject_when_hurt: true
getoff_when_hurt: true
# Decide if riders will be protected of suffocation damages when riding a player (true or false).
prevent_suffocation: true
# Decide if riders can boost players of not (true or false)
# Decide if a player riden cannot damage his rider (true or false).
prevent_hit_rider: true
# Decide if riders can boost players or not (true or false)
boost_allowed: true

##### [ the next parameters are ignored if boost_allowed: false ] #####

# Value of the speed boost (integer)
# Value of the speed boost (integer), 0 to disable the boost
boost_amplifier: 4
# Duration in server ticks (20 ticks = 1 second) of the speed effect
# Duration in server ticks (20 ticks = 1 second) of the speed effect, 0 to disable the boost
boost_duration: 60
# Max pitch value the rider must be to be able to whip and boost the player (float)
# Max pitch value the rider must be to whip and boost the player (float), check in game with F3.
boost_maxPitch: 60.0
# Sound the whip action will play, see https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Effect.html
boost_whip_sound: ENTITY_FIREWORK_ROCKET_SHOOT
# Volume of the sound. Set it to zero if you don't want a sound effect
# Volume of the sound. Set it to zero if you don't want a sound effect (float)
boost_whip_volume: 1.0
# Pitch of the sound (normal play = 1, value can be from 0.4 to 2 if I remember well)
boost_whip_pitch: 1.3
Expand Down
74 changes: 74 additions & 0 deletions src/me/arboriginal/PlayerRider/PRcooldown.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package me.arboriginal.PlayerRider;

import java.util.HashMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PRcooldown {
public static HashMap<String, Long> cooldowns;
public static HashMap<String, String> warnings;

public PRcooldown() {
cooldowns = new HashMap<String, Long>() {
private static final long serialVersionUID = 1L;
};
}

public String id(String key, CommandSender player, CommandSender duck) {
return key + "..." + player.getName() + "." + ((duck == null) ? ".." : duck.getName());
}

public boolean isActive(String key, Player player) {
return isActive(key, player, null, false);
}

public boolean isActive(String key, Player player, boolean warn) {
return isActive(key, player, null, warn);
}

public boolean isActive(String key, Player player, Player duck) {
return isActive(key, player, duck, false);
}

public boolean isActive(String key, Player player, Player duck, boolean warn) {
Long now = getCurrentTime(), next = get(key, player, duck);

if (next > now) {
if (warn) PlayerRider.warn(key, player, duck, (int) Math.max(1, Math.floor((next - now) / 1000)));

return true;
}

return false;
}

public Long getCurrentTime() {
return System.currentTimeMillis();
}

public Long get(String key, Player player, Player duck) {
key = id(key, player, duck);

return cooldowns.containsKey(key) ? cooldowns.get(key) : 0;
}

public void clear(String key, Player player) {
clear(key, player, null);
}

public void clear(String key, Player player, Player duck) {
cooldowns.remove(id(key, player, duck));
}

public void set(String key, Player player) {
set(key, player, null);
}

public void set(String key, Player player, Player duck) {
int delay = PlayerRider.config.getInt("cooldowns." + key) * 1000;

if (delay > 0) {
cooldowns.put(id(key, player, duck), getCurrentTime() + delay);
}
}
}
Loading

0 comments on commit 275ef47

Please sign in to comment.