mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-30 12:19:16 +00:00
feature: add prevention commands for region requirements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.islandearth.rpgregions.api.integrations;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
@@ -8,6 +9,7 @@ import net.islandearth.rpgregions.requirements.DependencyRequirement;
|
||||
import net.islandearth.rpgregions.requirements.RegionRequirement;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.islandearth.rpgregions.utils.MessageUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -82,6 +84,11 @@ public interface IntegrationManager {
|
||||
if (flag) {
|
||||
requirement.getPreventType().prevent(event);
|
||||
if (requirement.getPreventMessage() != null) {
|
||||
for (String preventCommand : requirement.getPreventCommands()) {
|
||||
final String converted = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, preventCommand) : preventCommand;
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), converted.replace("[player]", player.getName()));
|
||||
}
|
||||
|
||||
String requirementMessage = MessageUtils.setPapi(player, requirement.getPreventMessage());
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', requirementMessage));
|
||||
} else Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
|
||||
@@ -10,15 +10,22 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RegionRequirement implements IGuiEditable, ICustomGuiFeedback {
|
||||
|
||||
private final transient IRPGRegionsAPI api;
|
||||
|
||||
@GuiEditable(value = "Prevent Type", type = GuiEditable.GuiEditableType.CHAT)
|
||||
private PreventType preventType;
|
||||
|
||||
@GuiEditable(value = "Prevention Entry Message", type = GuiEditable.GuiEditableType.CHAT)
|
||||
private String preventMessage;
|
||||
|
||||
@GuiEditable(value = "Prevention Commands", type = GuiEditable.GuiEditableType.CHAT)
|
||||
private List<String> preventCommands;
|
||||
|
||||
public RegionRequirement(IRPGRegionsAPI api) {
|
||||
this(api, PreventType.TELEPORT);
|
||||
}
|
||||
@@ -26,6 +33,7 @@ public abstract class RegionRequirement implements IGuiEditable, ICustomGuiFeedb
|
||||
public RegionRequirement(IRPGRegionsAPI api, PreventType preventType) {
|
||||
this.api = api;
|
||||
this.preventType = preventType;
|
||||
this.preventCommands = new ArrayList<>();
|
||||
}
|
||||
|
||||
public IRPGRegionsAPI getApi() {
|
||||
@@ -58,6 +66,14 @@ public abstract class RegionRequirement implements IGuiEditable, ICustomGuiFeedb
|
||||
this.preventMessage = preventMessage;
|
||||
}
|
||||
|
||||
public List<String> getPreventCommands() {
|
||||
return preventCommands;
|
||||
}
|
||||
|
||||
public void setPreventCommands(List<String> preventCommand) {
|
||||
this.preventCommands = preventCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean feedback(Player player, String input) {
|
||||
Optional<?> value = Enums.getIfPresent(PreventType.class, input.toUpperCase());
|
||||
|
||||
Reference in New Issue
Block a user