Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
There's always some last minute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniFoldi committed Jan 20, 2022
1 parent cdc3473 commit 32c0644
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/danifoldi/protogui/main/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void open(final @NotNull GuiGrid gui, final @NotNull UUID uuid, final @NotNull S
return;
}

runCommand(uuid,openGui, slot, target, event.clickType());
runCommand(uuid, openGui, slot, target, event.clickType());
close(uuid, true);
});
inventory.onClose(event -> close(event.player().uniqueId(), false));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/danifoldi/protogui/main/ProtoGuiAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public void removeGui(final @NotNull String name) {
public long reloadGuis() {
final @NotNull Instant loadStart = Instant.now();

loader.unload();
loader.load();
loader.unload(true);
loader.load(true);

final @NotNull Instant loadEnd = Instant.now();
return Duration.between(loadStart, loadEnd).toMillis();
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/com/danifoldi/protogui/main/ProtoGuiLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ public ProtoGuiLoader(final @NotNull GuiHandler guiHandler,
this.threadPool = threadPool;
}

public void load() {
StringUtil.blockPrint(logger::info, "Loading %s version %s".formatted(platform.pluginName(), platform.pluginVersion()));
public void load(boolean reload) {
if (reload) {
StringUtil.blockPrint(logger::info, "Reloading %s version %s".formatted(platform.pluginName(), platform.pluginVersion()));
} else {
StringUtil.blockPrint(logger::info, "Loading %s version %s".formatted(platform.pluginName(), platform.pluginVersion()));
}

ProtoGuiAPI.setInstance(new ProtoGuiAPI(guiHandler, this, placeholderHandler));
commandManager.setup();
Expand Down Expand Up @@ -91,10 +95,12 @@ public void load() {
logger.setFilter(record -> newConfig.getEnumOrElse("logLevel", LogLevel.ALL, EnumGetMethod.NAME_IGNORECASE).level.intValue() <= record.getLevel().intValue());

if (newInstall) {
FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("authors.yml"), "authors.yml");
FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("servermenu.yml"), "servermenu.yml");
FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("sounds.yml"), "sounds.yml");
FileUtil.ensureConfigFile(datafolder.resolve("guis").resolve("stats.yml"), "stats.yml");
logger.info("Fresh install, copying example files");
FileUtil.ensureConfigFile(datafolder.resolve("guis"), "authors.yml");
FileUtil.ensureConfigFile(datafolder.resolve("guis"), "servermenu.yml");
FileUtil.ensureConfigFile(datafolder.resolve("guis"), "sounds.yml");
FileUtil.ensureConfigFile(datafolder.resolve("guis"), "stats.yml");
FileUtil.ensureConfigFile(datafolder.resolve("templates"), "test.yml");
}

guiHandler.load(datafolder);
Expand All @@ -116,8 +122,10 @@ public void load() {
});
}

public void unload() {
StringUtil.blockPrint(logger::info, "Unloading %s version %s".formatted(platform.pluginName(), platform.pluginVersion()));
public void unload(boolean reload) {
if (!reload) {
StringUtil.blockPrint(logger::info, "Unloading %s version %s".formatted(platform.pluginName(), platform.pluginVersion()));
}

guiHandler.unload();
placeholderHandler.unregisterAll();
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/danifoldi/protogui/platform/bungee/ProtoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.ProxyReloadEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void onEnable() {
.build();

this.loader = component.loader();
this.loader.load();
this.loader.load(false);
}

@Override
Expand All @@ -110,7 +111,7 @@ public void onDisable() {
if (this.loader == null) {
return;
}
this.loader.unload();
this.loader.unload(false);
}

final @NotNull Function<CommandSender, PlatformInteraction.ProtoSender> senderGenerator = commandSender -> new PlatformInteraction.ProtoSender() {
Expand Down Expand Up @@ -425,6 +426,16 @@ public Map<String, ProtoServer> getServers() {
}
};

@EventHandler
@SuppressWarnings("unused")
public void onReload(final @NotNull ProxyReloadEvent event) {
if (this.loader == null) {
return;
}
this.loader.unload(true);
this.loader.load(true);
}

@EventHandler
@SuppressWarnings("unused")
public void onServerSwitch(final @NotNull ServerSwitchEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
Expand Down Expand Up @@ -90,15 +91,24 @@ public void onInitialize(ProxyInitializeEvent event) {
.build();

this.loader = component.loader();
this.loader.load();
this.loader.load(false);
}

@Subscribe
public void onShutdown(ProxyReloadEvent event) {
if (this.loader == null) {
return;
}
this.loader.unload(true);
this.loader.load(true);
}

@Subscribe
public void onShutdown(ProxyShutdownEvent event) {
if (this.loader == null) {
return;
}
this.loader.unload();
this.loader.unload(false);
}

final @NotNull Function<CommandSource, PlatformInteraction.ProtoSender> senderGenerator = commandSource -> new PlatformInteraction.ProtoSender() {
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/danifoldi/protogui/util/ConditionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

public class ConditionUtil {

private static final Pattern permissionPattern = Pattern.compile("^(?<mode>(no)?perm)<(?<node>[\\w.]+)>");
private static final Pattern relationPattern = Pattern.compile("^(?<relation>le|lq|eq|ne|ge|gq):(?<left>[\\w\\d.]+):(?<right>[\\w\\d.]+)");
private static final Pattern permissionPattern = Pattern.compile("^(?<mode>(no)?perm):(?<node>[\\w.]+)");
private static final Pattern relationPattern = Pattern.compile("^(?<left>[\\w\\d.]+):(?<relation>le|lq|eq|ne|ge|gq):(?<right>[\\w\\d.]+)");

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean holds(String condition, PlatformInteraction.ProtoSender sender) {
Expand All @@ -30,15 +30,23 @@ public static boolean holds(String condition, PlatformInteraction.ProtoSender se

Matcher relationMatcher = relationPattern.matcher(condition);
if (relationMatcher.matches()) {
String mode = permissionMatcher.group("mode");
String mode = permissionMatcher.group("relation");
String left = permissionMatcher.group("left");
String right = permissionMatcher.group("right");
try {
switch (mode) {
case "le": return Integer.parseInt(left) <= Integer.parseInt(right);
case "lq": return Integer.parseInt(left) < Integer.parseInt(right);
case "eq": return left.equalsIgnoreCase(right);
case "ne": return !left.equalsIgnoreCase(right);
case "eq": try {
return Integer.parseInt(left) == Integer.parseInt(right);
} catch (NumberFormatException ignored) {
return left.equalsIgnoreCase(right);
}
case "ne": try {
return Integer.parseInt(left) != Integer.parseInt(right);
} catch (NumberFormatException ignored) {
return !left.equalsIgnoreCase(right);
}
case "ge": return Integer.parseInt(left) >= Integer.parseInt(right);
case "gq": return Integer.parseInt(left) > Integer.parseInt(right);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ aliases:
size: 45
title: '&6BungeeGui Authors'
items:
'0,8,36,44':
'0+8+36+44':
type: nether_star
'21':
type: player_head
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/servermenu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ aliases:
size: 54
title: '&d&lExampleCraft &dserver menu'
items:
'row0,row5,column0,column8':
'row0+row5+column0+column8':
type: white_stained_glass_pane
'20':
type: player_head
Expand Down
21 changes: 2 additions & 19 deletions src/main/resources/stats.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
template: test
aliases:
- stats
size: 45
title: '&4&lStatistics'
openSound:
sound: block_beacon_activate
volume: 0.4
closeable: false
items:
row0,row4,column0,column8:
type: red_stained_glass_pane
enchanted: true
clickSound:
sound: entity_villager_no
'13':
type: player_head
data: texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzI3NDA3NjFkYmQ0MmY3NmU0ZjEyYzQ4ZWMwOTlhY2RjMWM2OTI3MmFiNTc2MzU3OWJiZTkxYzVmNTg2NTZkNyJ9fX0=
Expand Down Expand Up @@ -53,12 +44,4 @@ items:
lore:
- 'MOTD: %motd@%servername%%'
- 'Players: %online_visible@%servername%% / %max@%servername%%'
- 'Version: %version@%servername%%'
'16':
type: barrier
clickSound:
sound: block_beacon_deactivate
volume: 0.4
name: '&cClose'
commands:
- ''
- 'Version: %version@%servername%%'
19 changes: 19 additions & 0 deletions src/main/resources/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
size: 45
openSound:
sound: block_beacon_activate
volume: 0.4
closeable: false
items:
row0+row4+column0+column8:
type: red_stained_glass_pane
enchanted: true
clickSound:
sound: entity_villager_no
'16':
type: barrier
clickSound:
sound: block_beacon_deactivate
volume: 0.4
name: '&cClose'
commands:
- ''

0 comments on commit 32c0644

Please sign in to comment.