-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
657 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GPEvent> 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; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/fr/peaceandcube/gpevents/command/GPEventsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/fr/peaceandcube/gpevents/command/RemoveClaimAtCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fr.peaceandcube.gpevents.data; | ||
|
||
public record GPCoord(int min, int max) { | ||
|
||
public GPCoord(int value) { | ||
this(value, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Entity> player, World world, int area, | ||
GPPos greaterPos, GPPos lesserPos, List<Entity> claimOwner, | ||
boolean isSubdivision, TrustPermission trustPermission, String trustTarget, | ||
String playerCommand, GPPos playerPosition, List<String> commands) { | ||
} |
92 changes: 92 additions & 0 deletions
92
src/main/java/fr/peaceandcube/gpevents/data/GPEventBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Entity> player; | ||
private World world; | ||
private int area; | ||
private GPPos greaterPos; | ||
private GPPos lesserPos; | ||
private List<Entity> claimOwner; | ||
private boolean isSubdivision; | ||
private TrustPermission trustPermission; | ||
private String trustTarget; | ||
private String playerCommand; | ||
private GPPos playerPosition; | ||
private List<String> commands; | ||
|
||
public GPEventBuilder(GPEventType type) { | ||
this.type = type; | ||
} | ||
|
||
public GPEventBuilder player(List<Entity> 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<Entity> 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<String> 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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/fr/peaceandcube/gpevents/data/GPEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package fr.peaceandcube.gpevents.data; | ||
|
||
public record GPPos(GPCoord x, GPCoord y, GPCoord z) { | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/fr/peaceandcube/gpevents/data/TrustPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ClaimPermission, TrustPermission> 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; | ||
} | ||
} |
Oops, something went wrong.