1
0
mirror of https://github.com/nkomarn/harbor.git synced 2025-01-20 06:21:26 +01:00

add support for papi placeholders in BedListener messages, (#73)

added papi dependency to pom.xml,
added placeholderapi as softdepend in plugin.yml
This commit is contained in:
Lucy 2020-12-07 22:57:17 +00:00 committed by GitHub
parent 42f51938e3
commit 2c871f2b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

10
pom.xml
View File

@ -21,6 +21,10 @@
<id>ess-repo</id>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
@ -42,5 +46,11 @@
<version>20.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,5 +1,6 @@
package xyz.nkomarn.harbor.listener;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -16,12 +17,20 @@ public class BedListener implements Listener {
private final Harbor harbor;
private final PlayerManager playerManager;
private final boolean papiPresent = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
public BedListener(@NotNull Harbor harbor) {
this.harbor = harbor;
this.playerManager = harbor.getPlayerManager();
}
public String formatForChat(Player sender, String message) {
String output = message.replace("[player]", sender.getName())
.replace("[displayname]", sender.getDisplayName());
if(papiPresent) output = PlaceholderAPI.setPlaceholders(sender, output);
return output;
}
@EventHandler(ignoreCancelled = true)
public void onBedEnter(PlayerBedEnterEvent event) {
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) {
@ -35,9 +44,8 @@ public class BedListener implements Listener {
Bukkit.getScheduler().runTaskLater(harbor, () -> {
playerManager.setCooldown(player, System.currentTimeMillis());
harbor.getMessages().sendWorldChatMessage(event.getBed().getWorld(), harbor.getConfiguration().getString("messages.chat.player-sleeping")
.replace("[player]", event.getPlayer().getName())
.replace("[displayname]", event.getPlayer().getDisplayName()));
harbor.getMessages().sendWorldChatMessage(event.getBed().getWorld(),
formatForChat(player, harbor.getConfiguration().getString("messages.chat.player-sleeping")));
}, 1);
}
@ -49,9 +57,8 @@ public class BedListener implements Listener {
Bukkit.getScheduler().runTaskLater(harbor, () -> {
playerManager.setCooldown(event.getPlayer(), System.currentTimeMillis());
harbor.getMessages().sendWorldChatMessage(event.getBed().getWorld(), harbor.getConfiguration().getString("messages.chat.player-left-bed")
.replace("[player]", event.getPlayer().getName())
.replace("[displayname]", event.getPlayer().getDisplayName()));
harbor.getMessages().sendWorldChatMessage(event.getBed().getWorld(), formatForChat(event.getPlayer(),
harbor.getConfiguration().getString("messages.chat.player-left-bed")));
}, 1);
}

View File

@ -8,6 +8,7 @@ api-version: "1.14"
softdepend:
- "Essentials"
- "PlaceholderAPI"
commands:
harbor: