This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
18 changed files
with
667 additions
and
49 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.gradle/ | ||
.idea/ | ||
build/ | ||
build/ | ||
|
||
*.DS_Store |
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
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,53 @@ | ||
package hu.nugget.bungeegui; | ||
|
||
import hu.nugget.bungeegui.gui.GuiHandler; | ||
import hu.nugget.bungeegui.util.Message; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.plugin.Command; | ||
import net.md_5.bungee.api.plugin.TabExecutor; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.stream.Collectors; | ||
|
||
public class BungeeGuiCommand extends Command implements TabExecutor { | ||
|
||
private final String name; | ||
private final GuiHandler guiHandler; | ||
|
||
public BungeeGuiCommand(String name, GuiHandler guiHandler) { | ||
super(guiHandler.getGui(name).getCommandAliases().stream().findFirst().orElseThrow(), guiHandler.getGui(name).getPermission(), guiHandler.getGui(name).getCommandAliases().stream().skip(1L).toArray(String[]::new)); | ||
this.name = name; | ||
this.guiHandler = guiHandler; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
if (!(sender instanceof ProxiedPlayer)) { | ||
sender.sendMessage(Message.PLAYER_ONLY.toComponent()); | ||
return; | ||
} | ||
|
||
if (args.length == 0 && guiHandler.getGui(name).isTargeted()) { | ||
sender.sendMessage(Message.TARGET_REQUIRED.toComponent()); | ||
return; | ||
} | ||
|
||
guiHandler.open(name, (ProxiedPlayer)sender, args.length == 0 ? "" : args[0]); | ||
} | ||
|
||
@Override | ||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) { | ||
if (!guiHandler.getGui(name).isTargeted()) { | ||
return List.of(); | ||
} | ||
if (args.length > 1) { | ||
return List.of(); | ||
} | ||
|
||
String filter = args.length == 0 ? "" : args[args.length - 1]; | ||
return ProxyServer.getInstance().getPlayers().stream().map(CommandSender::getName).filter(n -> n.toLowerCase(Locale.ROOT).startsWith(filter.toLowerCase(Locale.ROOT))).collect(Collectors.toList()); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,13 +1,63 @@ | ||
package hu.nugget.bungeegui; | ||
|
||
import com.electronwill.nightconfig.core.Config; | ||
import hu.nugget.bungeegui.gui.GuiHandler; | ||
import hu.nugget.bungeegui.util.FileUtil; | ||
import hu.nugget.bungeegui.util.Message; | ||
import hu.nugget.bungeegui.util.StringUtil; | ||
import net.md_5.bungee.api.plugin.PluginManager; | ||
|
||
import javax.inject.Inject; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
|
||
public class BungeeGuiLoader { | ||
|
||
private final GuiHandler guiHandler; | ||
private final BungeeGuiPlugin plugin; | ||
private final Logger logger; | ||
private final PluginManager pluginManager; | ||
private final Path datafolder; | ||
|
||
@Inject | ||
public BungeeGuiLoader() {} | ||
public BungeeGuiLoader(GuiHandler guiHandler, BungeeGuiPlugin plugin, Logger logger, PluginManager pluginManager, Path datafolder) { | ||
this.guiHandler = guiHandler; | ||
this.plugin = plugin; | ||
this.logger = logger; | ||
this.pluginManager = pluginManager; | ||
this.datafolder = datafolder; | ||
} | ||
|
||
void load() { | ||
StringUtil.blockPrint("Loading " + plugin.getDescription().getName() + " version " + plugin.getDescription().getVersion()).forEach(logger::info); | ||
|
||
try { | ||
FileUtil.ensureFile(datafolder, "config.yml"); | ||
} catch (IOException e) { | ||
logger.severe("Could not preload config file"); | ||
logger.severe(e.getMessage()); | ||
e.printStackTrace(); | ||
} | ||
|
||
Config config = guiHandler.load(datafolder.resolve("config.yml")); | ||
|
||
Map<String, String> messages = new HashMap<>(); | ||
for (Config.Entry message: ((Config)config.get("messages")).entrySet()) { | ||
messages.put(message.getKey(), message.getValue()); | ||
} | ||
Message.setMessageProvider(messages); | ||
|
||
void load() {} | ||
pluginManager.registerCommand(plugin, new ReloadCommand(this)); | ||
guiHandler.registerCommands(); | ||
pluginManager.registerListener(plugin, new BungeeGuiListener(guiHandler)); | ||
} | ||
|
||
void unload() {} | ||
void unload() { | ||
StringUtil.blockPrint("Unloading " + plugin.getDescription().getName() + " version " + plugin.getDescription().getVersion()).forEach(logger::info); | ||
pluginManager.unregisterCommands(plugin); | ||
pluginManager.unregisterListeners(plugin); | ||
} | ||
} |
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
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,32 @@ | ||
package hu.nugget.bungeegui; | ||
|
||
import hu.nugget.bungeegui.util.Message; | ||
import hu.nugget.bungeegui.util.Pair; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.plugin.Command; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
public class ReloadCommand extends Command { | ||
|
||
private final BungeeGuiLoader loader; | ||
|
||
public ReloadCommand(BungeeGuiLoader loader) { | ||
super("bguireload", "bungeegui.reload"); | ||
this.loader = loader; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
Instant loadStart = Instant.now(); | ||
|
||
loader.unload(); | ||
loader.load(); | ||
|
||
Instant loadEnd = Instant.now(); | ||
long length = Duration.between(loadStart, loadEnd).toMillis(); | ||
|
||
sender.sendMessage(Message.RELOAD_SUCCESS.toComponent(Pair.of("time", String.valueOf(length)))); | ||
} | ||
} |
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,43 @@ | ||
package hu.nugget.bungeegui.api; | ||
|
||
import hu.nugget.bungeegui.gui.GuiHandler; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@SuppressWarnings("unused") | ||
public class BungeeGuiAPI { | ||
|
||
private static BungeeGuiAPI apiInstance; | ||
public static BungeeGuiAPI getInstance() { | ||
return apiInstance; | ||
} | ||
protected static void setInstance(BungeeGuiAPI apiInstance) { | ||
BungeeGuiAPI.apiInstance = apiInstance; | ||
} | ||
|
||
private final GuiHandler guiHandler; | ||
|
||
@Inject | ||
public BungeeGuiAPI(GuiHandler guiHandler) { | ||
this.guiHandler = guiHandler; | ||
} | ||
|
||
public void openGui(ProxiedPlayer player, String guiName, String target) { | ||
guiHandler.open(guiName, player, target); | ||
} | ||
|
||
public void closeGui(ProxiedPlayer player) { | ||
guiHandler.close(player); | ||
} | ||
|
||
public boolean hasOpenGui(ProxiedPlayer player) { | ||
return guiHandler.getOpenGui(player.getUniqueId()) != null; | ||
} | ||
|
||
public String getOpenGui(ProxiedPlayer player) { | ||
return guiHandler.getGuiName(guiHandler.getOpenGui(player.getUniqueId())); | ||
} | ||
} |
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
Oops, something went wrong.