Skip to content

Commit

Permalink
Version 1.14.1: Additions + bugfix
Browse files Browse the repository at this point in the history
* Add optional bossbar displayed to ridden player
* Add the ability to disable the plugin by world
* Add the ability to disable the feature which hide the rider
  to the ridden player (I've documented this in config.yml
  but forgot to add the code for it in last version...)
* Fix a bug that could let the rider invisible to previously
  mounted player (requiring disconnect/reconnect to see him again)
  • Loading branch information
arboriginal committed Sep 27, 2019
1 parent 0a9cf84 commit 2cfb6af
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ duck:
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!"

# Bossbar displayed to ridden player
bossbar_on_ridden_player:
enabled: true
title: "{player} is ridding you!" # {player} will be replaced by the rider's name
color: YELLOW # Available values: BLUE, GREEN, PINK, PURPLE, RED, WHITE, YELLOW
style: SOLID # Available values: SOLID, SEGMENTED_6, SEGMENTED_10, SEGMENTED_12, SEGMENTED_20
progress: 1.0 # Between 0 and 1

# Cooldowns (in seconds)
cooldowns:
ride:
Expand Down Expand Up @@ -117,6 +125,11 @@ consume_items:
ride: false
whip: true

# Disabled worlds (you can use « [] > to represents an empty list)
disabled_worlds:
- world1_to_disable
- World2_to_disable

# 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>"
Expand Down
45 changes: 38 additions & 7 deletions src/me/arboriginal/PlayerRider/PlayerRider.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.KeyedBossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -150,6 +154,7 @@ public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
}
}

@EventHandler
public void onEntityDismount(EntityDismountEvent event) {
if (event.isCancelled()) return;

Expand All @@ -160,6 +165,9 @@ public void onEntityDismount(EntityDismountEvent event) {
if (!(duck instanceof Player)) return;

((Player) player).showPlayer(this, ((Player) duck));

KeyedBossBar bossbar = Bukkit.getBossBar(bossbarKey(((Player) player)));
if (bossbar != null) bossbar.removeAll();
}

@EventHandler
Expand Down Expand Up @@ -205,7 +213,12 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
// https://www.spigotmc.org/threads/how-would-i-stop-an-event-from-being-called-twice.135234/#post-1434104
if (event.getHand() == EquipmentSlot.OFF_HAND || !isPlayer(event.getRightClicked())) return;

Player player = event.getPlayer(), duck = (Player) event.getRightClicked();
Player player = event.getPlayer();
List<?> list = config.getList("disabled_worlds");

if (!list.isEmpty() && list.contains(player.getWorld().getName())) return;

Player duck = (Player) event.getRightClicked();

if (player.getPassengers().contains(duck)) {
if (player.getLocation().getPitch() < config.getDouble("eject_maxPitch")
Expand Down Expand Up @@ -252,9 +265,20 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
cooldown.set("ride.perform", player, duck);
cooldown.set("eject.perform", duck);

if (duck.getLocation().getPitch() > config.getDouble("hide_rider_maxPitch")
&& duck.getPassengers().get(0).equals(player))
if (canSeeRider(duck) && duck.getPassengers().get(0).equals(player))
duck.hidePlayer(this, player);

if (config.getBoolean("bossbar_on_ridden_player.enabled")) {
KeyedBossBar bossbar = Bukkit.createBossBar(
bossbarKey(duck),
config.getString("bossbar_on_ridden_player.title").replace("{player}", player.getName()),
BarColor.valueOf(config.getString("bossbar_on_ridden_player.color")),
BarStyle.valueOf(config.getString("bossbar_on_ridden_player.style")));

bossbar.addPlayer(duck);
bossbar.setProgress(config.getDouble("bossbar_on_ridden_player.progress"));
bossbar.setVisible(true);
}
}
else {
userMessage(player, "failed", player, duck);
Expand All @@ -273,10 +297,8 @@ public void onPlayerMove(PlayerMoveEvent event) {

Entity duck = player.getPassengers().get(0);
if (!(duck instanceof Player)) return;

Location loc = player.getLocation();

if (loc.getPitch() > config.getDouble("hide_rider_maxPitch"))
if (canSeeRider(player))
player.hidePlayer(this, ((Player) duck));
else
player.showPlayer(this, ((Player) duck));
Expand All @@ -303,6 +325,10 @@ private void alert(String key, Player player, Player duck) {
}
}

private NamespacedKey bossbarKey(Player player) {
return new NamespacedKey(this, getName() + "." + player.getUniqueId());
}

private void broadcast(String key, CommandSender player, CommandSender duck) {
String message = config.getString("broadcast." + key);

Expand All @@ -311,6 +337,11 @@ private void broadcast(String key, CommandSender player, CommandSender duck) {
}
}

private boolean canSeeRider(Player player) {
double max = config.getDouble("hide_rider_maxPitch");
return max != 0 && player.getLocation().getPitch() > max;
}

private void consume(Player player, ItemStack item, String key) {
if (config.getBoolean("consume_items." + key)
&& !player.hasPermission("playerrider." + key + ".keepitem")
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PlayerRider
description: Allow you to ride players.
version: 1.14
version: 1.14.1

author: arboriginal
website: https://www.spigotmc.org/resources/playerrider.62799/
Expand Down

0 comments on commit 2cfb6af

Please sign in to comment.