Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added reload event for better plugin integration #441

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.sacredlabyrinth.phaed.simpleclans.commands.ClanPlayerInput;
import net.sacredlabyrinth.phaed.simpleclans.events.PlayerHomeSetEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.PlayerResetKdrEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.ReloadEvent;
import net.sacredlabyrinth.phaed.simpleclans.events.TagChangeEvent;
import net.sacredlabyrinth.phaed.simpleclans.language.LanguageResource;
import net.sacredlabyrinth.phaed.simpleclans.managers.ClanManager;
Expand All @@ -15,7 +16,6 @@
import net.sacredlabyrinth.phaed.simpleclans.managers.StorageManager;
import net.sacredlabyrinth.phaed.simpleclans.ui.InventoryController;
import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils;
import net.sacredlabyrinth.phaed.simpleclans.utils.TagValidator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -123,6 +123,8 @@ public void reload(CommandSender sender) {
for (Clan clan : cm.getClans()) {
permissions.updateClanPermissions(clan);
}
Bukkit.getPluginManager().callEvent(new ReloadEvent(sender));

ChatBlock.sendMessage(sender, AQUA + lang("configuration.reloaded", sender));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.sacredlabyrinth.phaed.simpleclans.events;

import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class ReloadEvent extends Event {

private static final HandlerList HANDLER_LIST = new HandlerList();

private final CommandSender sender;

public ReloadEvent(CommandSender sender) {
this.sender = sender;
}

public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}

@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}

public CommandSender getSender() {
return sender;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void run() {
connection.addRequestProperty("User-Agent", userAgent);
InputStreamReader reader = new InputStreamReader(connection.getInputStream());

JsonElement parse = new JsonParser().parse(reader);
JsonElement parse = JsonParser.parseReader(reader);
if (parse.isJsonObject()) {
String latestVersion = parse.getAsJsonObject().get("name").getAsString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,43 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

public class UUIDFetcherTest {

private UUID ghostUUID;

@BeforeEach
public void setup() {
ghostUUID = UUID.fromString("bfe9a44f-e44d-453b-8219-74eb186c3932");
}

@Test
public void getUUIDOf() throws Exception {
assertEquals(ghostUUID, UUIDFetcher.getUUIDOf("GhostTheWolf"));
try {
assertEquals(ghostUUID, UUIDFetcher.getUUIDOf("GhostTheWolf"));
}
catch (IOException e) {
if (e.getMessage().startsWith("Server returned HTTP response code: 403 for URL")) {
System.out.println(
"You have been throttled by Mojang's API. Please wait a few minutes before trying again.");
}
else {
throw e;
}
Peng1104 marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Test
public void getUUIDOfThrottled() throws IOException, InterruptedException {
assertEquals(ghostUUID, UUIDFetcher.getUUIDOfThrottled("GhostTheWolf"));
try {
assertEquals(ghostUUID, UUIDFetcher.getUUIDOfThrottled("GhostTheWolf"));
}
catch (IOException e) {
if (e.getMessage().startsWith("Server returned HTTP response code: 403 for URL")) {
System.out.println(
"You have been throttled by Mojang's API. Please wait a few minutes before trying again.");
}
else {
throw e;
}
}
}
}
Loading