diff --git a/src/main/java/fr/peaceandcube/gpevents/GPEvents.java b/src/main/java/fr/peaceandcube/gpevents/GPEvents.java new file mode 100644 index 0000000..e325e1a --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/GPEvents.java @@ -0,0 +1,39 @@ +package fr.peaceandcube.gpevents; + +import fr.peaceandcube.gpevents.command.GPEventsCommand; +import fr.peaceandcube.gpevents.command.RemoveClaimAtCommand; +import fr.peaceandcube.gpevents.data.GPEvent; +import fr.peaceandcube.gpevents.event.GPEventListener; +import fr.peaceandcube.gpevents.file.EventsFile; +import me.ryanhamshire.GriefPrevention.GriefPrevention; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.List; + +public class GPEvents extends JavaPlugin { + private static GriefPrevention griefPrevention; + public static EventsFile eventsFile; + public static List events; + + @Override + public void onEnable() { + griefPrevention = GriefPrevention.getPlugin(GriefPrevention.class); + + this.getCommand("gpevents").setExecutor(new GPEventsCommand()); + this.getCommand("removeclaimat").setExecutor(new RemoveClaimAtCommand()); + + eventsFile = new EventsFile("events.yml", this); + events = eventsFile.getEvents(); + + this.getServer().getPluginManager().registerEvents(new GPEventListener(), this); + } + + public static void reload() { + eventsFile.reload(); + events = eventsFile.getEvents(); + } + + public static GriefPrevention getGriefPrevention() { + return griefPrevention; + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/command/GPEventsCommand.java b/src/main/java/fr/peaceandcube/gpevents/command/GPEventsCommand.java new file mode 100644 index 0000000..1682ba2 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/command/GPEventsCommand.java @@ -0,0 +1,44 @@ +package fr.peaceandcube.gpevents.command; + +import fr.peaceandcube.gpevents.GPEvents; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.TextColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Stream; + +public class GPEventsCommand implements CommandExecutor, TabExecutor { + private static final String PERM_GPEVENTS = "gpevents.gpevents"; + private static final TextComponent MESSAGE_RELOAD_SUCCESS = Component.text("GPEvents a été rechargé avec succès", TextColor.color(0x55FF55)); + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (sender.hasPermission(PERM_GPEVENTS)) { + if (args.length == 1) { + if (args[0].equals("reload")) { + GPEvents.reload(); + sender.sendMessage(MESSAGE_RELOAD_SUCCESS); + return true; + } + } + } + return false; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + if (sender.hasPermission(PERM_GPEVENTS)) { + if (args.length == 1) { + return Stream.of("reload").filter(s -> s.startsWith(args[0])).toList(); + } + } + return List.of(); + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/command/RemoveClaimAtCommand.java b/src/main/java/fr/peaceandcube/gpevents/command/RemoveClaimAtCommand.java new file mode 100644 index 0000000..ca1584c --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/command/RemoveClaimAtCommand.java @@ -0,0 +1,76 @@ +package fr.peaceandcube.gpevents.command; + +import fr.peaceandcube.gpevents.GPEvents; +import me.ryanhamshire.GriefPrevention.Claim; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.TextColor; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.generator.WorldInfo; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Stream; + +public class RemoveClaimAtCommand implements CommandExecutor, TabExecutor { + private static final String PERM_REMOVECLAIMAT = "gpevents.removeclaimat"; + private static final TextComponent MESSAGE_SUCCESS = Component.text("Le claim a bien été supprimé", TextColor.color(0x55FF55)); + private static final TextComponent MESSAGE_WORLD_NOT_FOUND = Component.text("Le monde n'a pas été trouvé !", TextColor.color(0xFF5555)); + private static final TextComponent MESSAGE_CLAIM_NOT_FOUND = Component.text("Aucun claim n'a été trouvé !", TextColor.color(0xFF5555)); + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (sender.hasPermission(PERM_REMOVECLAIMAT)) { + if (args.length >= 4 && args.length <= 5) { + World world = Bukkit.getWorld(args[0]); + int x = Integer.parseInt(args[1]); + int y = Integer.parseInt(args[2]); + int z = Integer.parseInt(args[3]); + boolean checkSubdivisions = args.length >= 5 && Boolean.parseBoolean(args[4]); + + if (world == null) { + sender.sendMessage(MESSAGE_WORLD_NOT_FOUND); + return true; + } + + Location location = new Location(world, x, y, z); + Claim claim = GPEvents.getGriefPrevention().dataStore.getClaimAt(location, true, !checkSubdivisions, null); + + if (claim == null) { + sender.sendMessage(MESSAGE_CLAIM_NOT_FOUND); + return true; + } + + GPEvents.getGriefPrevention().dataStore.deleteClaim(claim); + sender.sendMessage(MESSAGE_SUCCESS); + return true; + } + } + return false; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + if (sender.hasPermission(PERM_REMOVECLAIMAT)) { + if (args.length == 1) { + return Bukkit.getWorlds().stream().map(WorldInfo::getName).filter(s -> s.startsWith(args[0])).toList(); + } else if (args.length == 2) { + return Stream.of("0").filter(s -> s.startsWith(args[1])).toList(); + } else if (args.length == 3) { + return Stream.of("0").filter(s -> s.startsWith(args[2])).toList(); + } else if (args.length == 4) { + return Stream.of("0").filter(s -> s.startsWith(args[3])).toList(); + } else if (args.length == 5) { + return Stream.of("false", "true").filter(s -> s.startsWith(args[4])).toList(); + } + } + return List.of(); + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/data/GPCoord.java b/src/main/java/fr/peaceandcube/gpevents/data/GPCoord.java new file mode 100644 index 0000000..c92046c --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/data/GPCoord.java @@ -0,0 +1,8 @@ +package fr.peaceandcube.gpevents.data; + +public record GPCoord(int min, int max) { + + public GPCoord(int value) { + this(value, value); + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/data/GPEvent.java b/src/main/java/fr/peaceandcube/gpevents/data/GPEvent.java new file mode 100644 index 0000000..fd8649a --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/data/GPEvent.java @@ -0,0 +1,12 @@ +package fr.peaceandcube.gpevents.data; + +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import java.util.List; + +public record GPEvent(GPEventType type, List player, World world, int area, + GPPos greaterPos, GPPos lesserPos, List claimOwner, + boolean isSubdivision, TrustPermission trustPermission, String trustTarget, + String playerCommand, GPPos playerPosition, List commands) { +} diff --git a/src/main/java/fr/peaceandcube/gpevents/data/GPEventBuilder.java b/src/main/java/fr/peaceandcube/gpevents/data/GPEventBuilder.java new file mode 100644 index 0000000..f3dd6e6 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/data/GPEventBuilder.java @@ -0,0 +1,92 @@ +package fr.peaceandcube.gpevents.data; + +import com.google.common.base.Preconditions; +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import java.util.List; + +public class GPEventBuilder { + private GPEventType type; + private List player; + private World world; + private int area; + private GPPos greaterPos; + private GPPos lesserPos; + private List claimOwner; + private boolean isSubdivision; + private TrustPermission trustPermission; + private String trustTarget; + private String playerCommand; + private GPPos playerPosition; + private List commands; + + public GPEventBuilder(GPEventType type) { + this.type = type; + } + + public GPEventBuilder player(List player) { + this.player = player; + return this; + } + + public GPEventBuilder world(World world) { + this.world = world; + return this; + } + + public GPEventBuilder area(int area) { + this.area = area; + return this; + } + + public GPEventBuilder greaterPos(GPPos greaterPos) { + this.greaterPos = greaterPos; + return this; + } + + public GPEventBuilder lesserPos(GPPos lesserPos) { + this.lesserPos = lesserPos; + return this; + } + + public GPEventBuilder claimOwner(List claimOwner) { + this.claimOwner = claimOwner; + return this; + } + + public GPEventBuilder subdivision(boolean isSubdivision) { + this.isSubdivision = isSubdivision; + return this; + } + + public GPEventBuilder trustPermission(TrustPermission trustPermission) { + this.trustPermission = trustPermission; + return this; + } + + public GPEventBuilder trustTarget(String trustTarget) { + this.trustTarget = trustTarget; + return this; + } + + public GPEventBuilder playerCommand(String playerCommand) { + this.playerCommand = playerCommand; + return this; + } + + public GPEventBuilder playerPosition(GPPos playerPosition) { + this.playerPosition = playerPosition; + return this; + } + + public GPEventBuilder commands(List commands) { + this.commands = commands; + return this; + } + + public GPEvent build() { + Preconditions.checkState(type != null, "GPEvent.type must be specified!"); + return new GPEvent(type, player, world, area, greaterPos, lesserPos, claimOwner, isSubdivision, trustPermission, trustTarget, playerCommand, playerPosition, commands); + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/data/GPEventType.java b/src/main/java/fr/peaceandcube/gpevents/data/GPEventType.java new file mode 100644 index 0000000..a481b60 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/data/GPEventType.java @@ -0,0 +1,21 @@ +package fr.peaceandcube.gpevents.data; + +public enum GPEventType { + CREATE, + DELETE, + RESIZE, + TRUST, + UNTRUST, + COMMAND; + + public static GPEventType fromName(String name) { + if (name != null) { + for (GPEventType type : GPEventType.values()) { + if (type.name().toLowerCase().equals(name)) { + return type; + } + } + } + return null; + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/data/GPPos.java b/src/main/java/fr/peaceandcube/gpevents/data/GPPos.java new file mode 100644 index 0000000..7f24190 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/data/GPPos.java @@ -0,0 +1,4 @@ +package fr.peaceandcube.gpevents.data; + +public record GPPos(GPCoord x, GPCoord y, GPCoord z) { +} diff --git a/src/main/java/fr/peaceandcube/gpevents/data/TrustPermission.java b/src/main/java/fr/peaceandcube/gpevents/data/TrustPermission.java new file mode 100644 index 0000000..f91baf6 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/data/TrustPermission.java @@ -0,0 +1,28 @@ +package fr.peaceandcube.gpevents.data; + +import me.ryanhamshire.GriefPrevention.ClaimPermission; + +import java.util.Map; + +public enum TrustPermission { + BUILD, + CONTAINER, + ACCESS; + + public static final Map TRUST_PERMISSIONS = Map.of( + ClaimPermission.Build, BUILD, + ClaimPermission.Inventory, CONTAINER, + ClaimPermission.Access, ACCESS + ); + + public static TrustPermission fromName(String name) { + if (name != null) { + for (TrustPermission type : TrustPermission.values()) { + if (type.name().toLowerCase().equals(name)) { + return type; + } + } + } + return null; + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/event/GPEventListener.java b/src/main/java/fr/peaceandcube/gpevents/event/GPEventListener.java new file mode 100644 index 0000000..61b1b70 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/event/GPEventListener.java @@ -0,0 +1,143 @@ +package fr.peaceandcube.gpevents.event; + +import fr.peaceandcube.gpevents.GPEvents; +import fr.peaceandcube.gpevents.data.GPCoord; +import fr.peaceandcube.gpevents.data.GPEvent; +import fr.peaceandcube.gpevents.data.GPEventType; +import fr.peaceandcube.gpevents.data.TrustPermission; +import fr.peaceandcube.gpevents.file.EventsFile; +import me.ryanhamshire.GriefPrevention.events.*; +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.List; +import java.util.UUID; + +public class GPEventListener implements Listener { + + public GPEventListener() { + } + + @EventHandler + public void onClaimCreated(ClaimCreatedEvent event) { + List createEvents = GPEvents.events.stream().filter(e -> e.type().equals(GPEventType.CREATE)).toList(); + // System.out.println(createEvents); + for (GPEvent createEvent : createEvents) { + if (isEqual(createEvent.world(), event.getClaim().getGreaterBoundaryCorner().getWorld()) + && (createEvent.area() < 0 || createEvent.area() == event.getClaim().getArea()) + && event.getCreator() instanceof Player player && isInList(createEvent.player(), player.getUniqueId()) + && (createEvent.greaterPos() == null || isInRange(createEvent.greaterPos().x(), event.getClaim().getGreaterBoundaryCorner().getBlockX())) + && (createEvent.greaterPos() == null || isInRange(createEvent.greaterPos().z(), event.getClaim().getGreaterBoundaryCorner().getBlockZ())) + && (createEvent.lesserPos() == null || isInRange(createEvent.lesserPos().x(), event.getClaim().getLesserBoundaryCorner().getBlockX())) + && (createEvent.lesserPos() == null || isInRange(createEvent.lesserPos().z(), event.getClaim().getLesserBoundaryCorner().getBlockZ())) + && isInList(createEvent.claimOwner(), event.getClaim().getOwnerID()) + && isEqual(createEvent.isSubdivision(), event.getClaim().parent != null)) + { + for (String command : createEvent.commands()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + } + } + } + + @EventHandler + public void onClaimDeleted(ClaimDeletedEvent event) { + List deleteEvents = GPEvents.events.stream().filter(e -> e.type().equals(GPEventType.DELETE)).toList(); + // System.out.println(deleteEvents); + for (GPEvent deleteEvent : deleteEvents) { + if (isEqual(deleteEvent.world(), event.getClaim().getGreaterBoundaryCorner().getWorld()) + && (deleteEvent.area() < 0 || deleteEvent.area() == event.getClaim().getArea()) + && (deleteEvent.greaterPos() == null || isInRange(deleteEvent.greaterPos().x(), event.getClaim().getGreaterBoundaryCorner().getBlockX())) + && (deleteEvent.greaterPos() == null || isInRange(deleteEvent.greaterPos().z(), event.getClaim().getGreaterBoundaryCorner().getBlockZ())) + && (deleteEvent.lesserPos() == null || isInRange(deleteEvent.lesserPos().x(), event.getClaim().getLesserBoundaryCorner().getBlockX())) + && (deleteEvent.lesserPos() == null || isInRange(deleteEvent.lesserPos().z(), event.getClaim().getLesserBoundaryCorner().getBlockZ())) + && isInList(deleteEvent.claimOwner(), event.getClaim().getOwnerID()) + && isEqual(deleteEvent.isSubdivision(), event.getClaim().parent != null)) + { + for (String command : deleteEvent.commands()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + } + } + } + + @EventHandler + public void onClaimResized(ClaimModifiedEvent event) { + List resizeEvents = GPEvents.events.stream().filter(e -> e.type().equals(GPEventType.RESIZE)).toList(); + // System.out.println(resizeEvents); + for (GPEvent resizeEvent : resizeEvents) { + if (isEqual(resizeEvent.world(), event.getTo().getGreaterBoundaryCorner().getWorld()) + && (resizeEvent.area() < 0 || resizeEvent.area() == event.getTo().getArea()) + && (resizeEvent.greaterPos() == null || isInRange(resizeEvent.greaterPos().x(), event.getTo().getGreaterBoundaryCorner().getBlockX())) + && (resizeEvent.greaterPos() == null || isInRange(resizeEvent.greaterPos().z(), event.getTo().getGreaterBoundaryCorner().getBlockZ())) + && (resizeEvent.lesserPos() == null || isInRange(resizeEvent.lesserPos().x(), event.getTo().getLesserBoundaryCorner().getBlockX())) + && (resizeEvent.lesserPos() == null || isInRange(resizeEvent.lesserPos().z(), event.getTo().getLesserBoundaryCorner().getBlockZ())) + && isInList(resizeEvent.claimOwner(), event.getTo().getOwnerID()) + && isEqual(resizeEvent.isSubdivision(), event.getTo().parent != null)) + { + for (String command : resizeEvent.commands()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + } + } + } + + @EventHandler + public void onTrustChanged(TrustChangedEvent event) { + List trustEvents = GPEvents.events.stream().filter(e -> e.type().equals(GPEventType.TRUST) || e.type().equals(GPEventType.UNTRUST)).toList(); + // System.out.println(trustEvents); + for (GPEvent trustEvent : trustEvents) { + if (isEqual(trustEvent.world(), event.getClaims().get(0).getGreaterBoundaryCorner().getWorld()) + && (trustEvent.area() < 0 || trustEvent.area() == event.getClaims().get(0).getArea()) + && (trustEvent.greaterPos() == null || isInRange(trustEvent.greaterPos().x(), event.getClaims().get(0).getGreaterBoundaryCorner().getBlockX())) + && (trustEvent.greaterPos() == null || isInRange(trustEvent.greaterPos().z(), event.getClaims().get(0).getGreaterBoundaryCorner().getBlockZ())) + && (trustEvent.lesserPos() == null || isInRange(trustEvent.lesserPos().x(), event.getClaims().get(0).getLesserBoundaryCorner().getBlockX())) + && (trustEvent.lesserPos() == null || isInRange(trustEvent.lesserPos().z(), event.getClaims().get(0).getLesserBoundaryCorner().getBlockZ())) + && isInList(trustEvent.claimOwner(), event.getClaims().get(0).getOwnerID()) + && isEqual(trustEvent.isSubdivision(), event.getClaims().get(0).parent != null) + && (!event.isGiven() || isEqual(trustEvent.trustPermission(), TrustPermission.TRUST_PERMISSIONS.get(event.getClaimPermission()))) + && isEqual(trustEvent.trustTarget(), event.getIdentifier())) + { + if ((event.isGiven() && trustEvent.type().equals(GPEventType.TRUST)) || (!event.isGiven() && trustEvent.type().equals(GPEventType.UNTRUST))) { + for (String command : trustEvent.commands()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + } + } + } + } + + @EventHandler + public void onCommand(PlayerCommandPreprocessEvent event) { + List commandEvents = GPEvents.events.stream().filter(e -> e.type().equals(GPEventType.COMMAND)).toList(); + // System.out.println(commandEvents); + for (GPEvent commandEvent : commandEvents) { + if (isInList(commandEvent.player(), event.getPlayer().getUniqueId()) + && (commandEvent.playerPosition() == null || isInRange(commandEvent.playerPosition().x(), event.getPlayer().getLocation().getX())) + && (commandEvent.playerPosition() == null || isInRange(commandEvent.playerPosition().y(), event.getPlayer().getLocation().getY())) + && (commandEvent.playerPosition() == null || isInRange(commandEvent.playerPosition().z(), event.getPlayer().getLocation().getZ())) + && isEqual(commandEvent.playerCommand(), event.getMessage())) + { + for (String command : commandEvent.commands()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + } + } + } + + private boolean isEqual(Object obj1, Object obj2) { + return obj1 == null || obj1.equals(obj2); + } + + private boolean isInList(List entities, UUID playerUuid) { + return entities.isEmpty() || entities.stream().map(Entity::getUniqueId).toList().contains(playerUuid); + } + + private boolean isInRange(GPCoord coord, double value) { + return coord == null || (value >= coord.min() && value <= coord.max()); + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/file/EventsFile.java b/src/main/java/fr/peaceandcube/gpevents/file/EventsFile.java new file mode 100644 index 0000000..e58f5c8 --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/file/EventsFile.java @@ -0,0 +1,87 @@ +package fr.peaceandcube.gpevents.file; + +import fr.peaceandcube.gpevents.data.*; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; + +import java.util.ArrayList; +import java.util.List; + +public class EventsFile extends YamlFile { + + public EventsFile(String name, Plugin plugin) { + super(name, plugin); + } + + public List getEvents() { + List events = new ArrayList<>(); + + for (String eventName : config.getKeys(false)) { + ConfigurationSection event = config.getConfigurationSection(eventName); + + if (event != null) { + GPEventType type = GPEventType.fromName(event.getString("type", null)); + List player = parseSelector(event.getString("player", null)); + World world = Bukkit.getWorld(event.getString("world", "")); + int area = event.getInt("area", -1); + GPPos greaterPos = getPos(event, "greater_pos", false); + GPPos lesserPos = getPos(event, "lesser_pos", false); + List claimOwner = parseSelector(event.getString("claim_owner", null)); + boolean isSubdivision = event.getBoolean("is_subdivision", false); + TrustPermission trustPermission = TrustPermission.fromName(event.getString("trust_permission", null)); + String trustTarget = event.getString("trust_target", null); + String playerCommand = event.getString("player_command", null); + GPPos playerPosition = getPos(event, "player_position", true); + List commands = event.getStringList("commands"); + + GPEvent gpEvent = new GPEventBuilder(type).player(player).world(world).area(area) + .greaterPos(greaterPos).lesserPos(lesserPos).claimOwner(claimOwner) + .subdivision(isSubdivision).trustPermission(trustPermission).trustTarget(trustTarget) + .playerCommand(playerCommand).playerPosition(playerPosition).commands(commands).build(); + events.add(gpEvent); + } + } + + return events; + } + + private List parseSelector(String selector) { + if (selector != null) { + return Bukkit.selectEntities(Bukkit.getConsoleSender(), selector); + } + return List.of(); + } + + private GPPos getPos(ConfigurationSection event, String sectionName, boolean includeY) { + GPPos pos = null; + ConfigurationSection posSection = event.getConfigurationSection(sectionName); + + if (posSection != null) { + GPCoord x = getCoord(posSection, "x"); + GPCoord y = null; + if (includeY) { + y = getCoord(posSection, "y"); + } + GPCoord z = getCoord(posSection, "z"); + pos = new GPPos(x, y, z); + } + + return pos; + } + + private GPCoord getCoord(ConfigurationSection posSection, String coordName) { + GPCoord coord; + ConfigurationSection coordSection = posSection.getConfigurationSection(coordName); + if (coordSection != null) { + int min = coordSection.getInt("min"); + int max = coordSection.getInt("max"); + coord = new GPCoord(min, max); + } else { + coord = new GPCoord(posSection.getInt(coordName)); + } + return coord; + } +} diff --git a/src/main/java/fr/peaceandcube/gpevents/file/YamlFile.java b/src/main/java/fr/peaceandcube/gpevents/file/YamlFile.java new file mode 100644 index 0000000..455f98e --- /dev/null +++ b/src/main/java/fr/peaceandcube/gpevents/file/YamlFile.java @@ -0,0 +1,52 @@ +package fr.peaceandcube.gpevents.file; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.logging.Level; + +public class YamlFile { + protected final String name; + protected final File file; + protected FileConfiguration config; + + public YamlFile(String name, Plugin plugin) { + this.name = name; + this.file = new File(plugin.getDataFolder(), name); + + if (!this.file.exists()) { + plugin.getDataFolder().mkdirs(); + try { + Files.createFile(this.file.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + this.config = YamlConfiguration.loadConfiguration(this.file); + } + + public void save() { + try { + saveToDisk(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Unable to save " + this.name + " to disk!"); + } + } + + private void saveToDisk() throws IOException { + if (this.config != null && this.file != null) { + this.config.save(this.file); + } + } + + public void reload() { + this.config = YamlConfiguration.loadConfiguration(this.file); + save(); + } +} diff --git a/src/main/java/fr/peaceandcube/gplistener/GPEvents.java b/src/main/java/fr/peaceandcube/gplistener/GPEvents.java deleted file mode 100644 index 3bfd242..0000000 --- a/src/main/java/fr/peaceandcube/gplistener/GPEvents.java +++ /dev/null @@ -1,7 +0,0 @@ -package fr.peaceandcube.gplistener; - -public class GPEvents extends JavaPlugin { - @Override - public void onEnable() { - } -} diff --git a/src/main/resources/events.examples.yml b/src/main/resources/events.examples.yml new file mode 100644 index 0000000..cde99f3 --- /dev/null +++ b/src/main/resources/events.examples.yml @@ -0,0 +1,31 @@ +NAME: + type: create + + player: "@p" + world: world + area: 100 + greater_pos: + x: + min: 1 + max: 10 + z: + min: 1 + max: 10 + lesser_pos: + x: 0 + z: 0 + claim_owner: "@p" + is_subdivision: false + trust_permission: build + trust_target: username + player_command: /command + player_position: + x: 0 + y: + min: 1 + max: 10 + z: 0 + + commands: + - command1 + - command2 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f49e07f..c95f5ae 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,3 +7,23 @@ api-version: 1.18 depend: - GriefPrevention + +commands: + removeclaimat: + description: Remove a claim at a specified location + permission: gpevents.removeclaimat + permission-message: §cYou do not have the permission to use this command. + usage: "§eUsage: §r/removeclaimat []" + gpevents: + description: Reload the plugin + permission: gpevents.gpevents + permission-message: §cYou do not have the permission to use this command. + usage: "§eUsage: §r/gpevents reload" + +permissions: + gpevents.gpevents: + description: Allows you to use the /gpevents command + default: op + gpevents.removeclaimat: + description: Allows you to use the /removeclaimat command + default: op