mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 05:16:55 +00:00
add placeholderapi hook
This commit is contained in:
@@ -80,6 +80,10 @@
|
|||||||
<id>sk89q-repo</id>
|
<id>sk89q-repo</id>
|
||||||
<url>https://maven.enginehub.org/repo/</url>
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -117,5 +121,11 @@
|
|||||||
<version>7.0.4-SNAPSHOT</version>
|
<version>7.0.4-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package me.youhavetrouble.preventstabby;
|
|||||||
|
|
||||||
import me.youhavetrouble.preventstabby.commands.MainCommand;
|
import me.youhavetrouble.preventstabby.commands.MainCommand;
|
||||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||||
|
import me.youhavetrouble.preventstabby.hooks.PlacoholderApiHook;
|
||||||
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
||||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||||
@@ -77,6 +78,10 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
worldGuardHook = false;
|
worldGuardHook = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
new PlacoholderApiHook(this).register();
|
||||||
|
}
|
||||||
|
|
||||||
Metrics metrics = new Metrics(this, 14074);
|
Metrics metrics = new Metrics(this, 14074);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ public class ConfigCache {
|
|||||||
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
||||||
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
||||||
pvp_disabled_other, punish_for_combat_logout_message, entering_combat, leaving_combat,
|
pvp_disabled_other, punish_for_combat_logout_message, entering_combat, leaving_combat,
|
||||||
cant_do_that_during_combat, cannot_attack_mounts_attacker, cannot_attack_mounts_victim;
|
cant_do_that_during_combat, cannot_attack_mounts_attacker, cannot_attack_mounts_victim,
|
||||||
|
placeholder_combat_time, placeholder_not_in_combat;
|
||||||
@Getter private final double lava_and_fire_stopper_radius;
|
@Getter private final double lava_and_fire_stopper_radius;
|
||||||
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
||||||
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
||||||
@@ -82,6 +83,8 @@ public class ConfigCache {
|
|||||||
addDefault("messages.entering_combat", "&cEntering combat");
|
addDefault("messages.entering_combat", "&cEntering combat");
|
||||||
addDefault("messages.leaving_combat", "&cLeaving combat");
|
addDefault("messages.leaving_combat", "&cLeaving combat");
|
||||||
addDefault("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
addDefault("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
||||||
|
addDefault("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||||
|
addDefault("placeholder.not_in_combat", "Not in combat");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,6 +138,9 @@ public class ConfigCache {
|
|||||||
this.entering_combat = config.getString("messages.entering_combat", "&cEntering combat");
|
this.entering_combat = config.getString("messages.entering_combat", "&cEntering combat");
|
||||||
this.leaving_combat = config.getString("messages.leaving_combat", "&cLeaving combat");
|
this.leaving_combat = config.getString("messages.leaving_combat", "&cLeaving combat");
|
||||||
this.cant_do_that_during_combat = config.getString("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
this.cant_do_that_during_combat = config.getString("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
||||||
|
|
||||||
|
this.placeholder_combat_time = config.getString("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||||
|
this.placeholder_not_in_combat = config.getString("placeholder.not_in_combat", "Not in combat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package me.youhavetrouble.preventstabby.hooks;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
|
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlacoholderApiHook extends PlaceholderExpansion {
|
||||||
|
|
||||||
|
private final PreventStabby plugin;
|
||||||
|
|
||||||
|
public PlacoholderApiHook(PreventStabby preventStabby) {
|
||||||
|
plugin = preventStabby;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getIdentifier() {
|
||||||
|
return "preventstabby";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getAuthor() {
|
||||||
|
return plugin.getDescription().getAuthors().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getVersion() {
|
||||||
|
return plugin.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String onRequest(OfflinePlayer player, String params) {
|
||||||
|
if (params.equalsIgnoreCase("combat_time")) {
|
||||||
|
return getCombatTimePlaceholder(player.getUniqueId());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCombatTimePlaceholder(UUID uuid) {
|
||||||
|
long seconds = plugin.getPlayerManager().getPlayer(uuid).getCombattime() - Instant.now().getEpochSecond();
|
||||||
|
if (seconds > 0) {
|
||||||
|
String msg = plugin.getConfigCache().getPlaceholder_combat_time();
|
||||||
|
msg = msg.replaceAll("%time%", String.valueOf(seconds));
|
||||||
|
return PluginMessages.parseMessage(msg);
|
||||||
|
}
|
||||||
|
return PluginMessages.parseMessage(plugin.getConfigCache().getPlaceholder_not_in_combat());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package me.youhavetrouble.preventstabby.util;
|
package me.youhavetrouble.preventstabby.util;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
@@ -9,16 +11,18 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class PluginMessages {
|
public class PluginMessages {
|
||||||
|
|
||||||
public static String parseMessage(String message) {
|
public static String parseMessage(String message) {
|
||||||
//TODO PAPI support
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', message);
|
return ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(Player player, String message) {
|
public static void sendMessage(Player player, String message) {
|
||||||
String parsedMessage = ChatColor.translateAlternateColorCodes('&', message);
|
String parsedMessage = message;
|
||||||
|
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
parsedMessage = PlaceholderAPI.setPlaceholders(player, parsedMessage);
|
||||||
|
}
|
||||||
|
parsedMessage = ChatColor.translateAlternateColorCodes('&', parsedMessage);
|
||||||
player.sendMessage(parsedMessage);
|
player.sendMessage(parsedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,10 +33,9 @@ public class PluginMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBar(UUID uuid, String message) {
|
public static void sendActionBar(UUID uuid, String message) {
|
||||||
try {
|
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null) return;
|
||||||
sendActionBar(player, message);
|
sendActionBar(player, message);
|
||||||
} catch (NullPointerException ignored) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parsePlayerName(Player player, String message) {
|
public static String parsePlayerName(Player player, String message) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ api-version: 1.13
|
|||||||
description: Stop people from getting stabbed!
|
description: Stop people from getting stabbed!
|
||||||
soft-depend:
|
soft-depend:
|
||||||
- WorldGuard
|
- WorldGuard
|
||||||
|
- PlaceholderAPI
|
||||||
commands:
|
commands:
|
||||||
preventstabby:
|
preventstabby:
|
||||||
permission: preventstabby.command
|
permission: preventstabby.command
|
||||||
|
|||||||
Reference in New Issue
Block a user