This repository has been archived by the owner on Jun 16, 2022. 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.
Merge pull request #11 from ProjectG-Plugins/1.2.0
1.2.0
- Loading branch information
Showing
43 changed files
with
2,398 additions
and
994 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
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
159 changes: 57 additions & 102 deletions
159
src/main/java/dev/projectg/geyserhub/GeyserHubMain.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 |
---|---|---|
@@ -1,151 +1,106 @@ | ||
package dev.projectg.geyserhub; | ||
|
||
import dev.projectg.geyserhub.command.ReloadCommand; | ||
import dev.projectg.geyserhub.command.SelectorCommand; | ||
import dev.projectg.geyserhub.module.menu.BedrockMenu; | ||
import dev.projectg.geyserhub.module.listeners.ItemInteract; | ||
import dev.projectg.geyserhub.module.listeners.SelectorInventory; | ||
import dev.projectg.geyserhub.module.listeners.ItemOnJoin; | ||
import dev.projectg.geyserhub.module.message.BroadCast; | ||
import dev.projectg.geyserhub.command.GeyserHubCommand; | ||
import dev.projectg.geyserhub.config.ConfigManager; | ||
import dev.projectg.geyserhub.module.menu.CommonMenuListeners; | ||
import dev.projectg.geyserhub.module.menu.java.JavaMenuListeners; | ||
import dev.projectg.geyserhub.module.menu.bedrock.BedrockFormRegistry; | ||
import dev.projectg.geyserhub.module.menu.java.JavaMenuRegistry; | ||
import dev.projectg.geyserhub.module.message.Broadcast; | ||
import dev.projectg.geyserhub.module.message.MessageJoin; | ||
import dev.projectg.geyserhub.module.scoreboard.Placeholders; | ||
import dev.projectg.geyserhub.module.scoreboard.ScoreboardManager; | ||
import dev.projectg.geyserhub.module.teleporter.JoinTeleporter; | ||
import dev.projectg.geyserhub.module.world.WorldSettings; | ||
import dev.projectg.geyserhub.utils.FileUtils; | ||
import dev.projectg.geyserhub.utils.bstats.Metrics; | ||
import dev.projectg.geyserhub.utils.bstats.SelectorLogger; | ||
import net.milkbowl.vault.economy.Economy; | ||
import net.milkbowl.vault.permission.Permission; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.InvalidConfigurationException; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.Properties; | ||
|
||
public class GeyserHubMain extends JavaPlugin { | ||
private static GeyserHubMain plugin; | ||
private SelectorLogger logger; | ||
|
||
public static final int configVersion = 3; | ||
private ConfigManager configManager; | ||
|
||
@Override | ||
public void onEnable() { | ||
plugin = this; | ||
new Metrics(this, 11427); | ||
logger = SelectorLogger.getLogger(); | ||
if (!loadConfiguration()) { | ||
logger.severe("Disabling due to configuration error. Fix the formatting or regenerate a new one"); | ||
// getting the logger forces the config to load before our loadConfiguration() is called... | ||
SelectorLogger logger = SelectorLogger.getLogger(); | ||
if (!Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { | ||
logger.warn("This plugin works best with PlaceholderAPI! Since you don't have it installed, only %player_name% and %player_uuid% will work in the GeyserHub config!"); | ||
} | ||
|
||
try { | ||
Properties gitProperties = new Properties(); | ||
gitProperties.load(FileUtils.getResource("git.properties")); | ||
logger.info("Branch: " + gitProperties.getProperty("git.branch", "Unknown") + ", Commit: " + gitProperties.getProperty("git.commit.id.abbrev", "Unknown")); | ||
} catch (IOException e) { | ||
logger.warn("Unable to load resource: git.properties"); | ||
e.printStackTrace(); | ||
} | ||
|
||
configManager = new ConfigManager(); | ||
if (!configManager.loadAllConfigs()) { | ||
logger.severe("Disabling due to configuration error."); | ||
return; | ||
} | ||
|
||
// Bungee channel for selector | ||
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); | ||
|
||
new BedrockMenu(); | ||
// Load forms | ||
BedrockFormRegistry bedrockFormRegistry = new BedrockFormRegistry(); | ||
JavaMenuRegistry javaMenuRegistry = new JavaMenuRegistry(); | ||
|
||
// todo: and add command suggestions/completions, help pages that only shows available commands | ||
Objects.requireNonNull(getCommand("ghub")).setExecutor(new GeyserHubCommand(bedrockFormRegistry, javaMenuRegistry)); | ||
|
||
// todo: sort all of this, and make checking for enable value in config consistent | ||
|
||
Objects.requireNonNull(getCommand("ghteleporter")).setExecutor(new SelectorCommand()); | ||
Objects.requireNonNull(getCommand("ghreload")).setExecutor(new ReloadCommand()); | ||
// Listeners for the Bedrock and Java menus | ||
Bukkit.getServer().getPluginManager().registerEvents(new CommonMenuListeners(bedrockFormRegistry, javaMenuRegistry), this); | ||
Bukkit.getServer().getPluginManager().registerEvents(new JavaMenuListeners(javaMenuRegistry), this); | ||
|
||
Bukkit.getServer().getPluginManager().registerEvents(new ItemInteract(), this); | ||
Bukkit.getServer().getPluginManager().registerEvents(new SelectorInventory(), this); | ||
Bukkit.getServer().getPluginManager().registerEvents(new ItemOnJoin(), this); | ||
// Listener the Join Teleporter module | ||
Bukkit.getServer().getPluginManager().registerEvents(new JoinTeleporter(), this); | ||
|
||
// Listener for world settings | ||
Bukkit.getServer().getPluginManager().registerEvents(new WorldSettings(), this); | ||
|
||
// load the scoreboard if enabled | ||
if (getConfig().getBoolean("Scoreboard.Enable", false)) { | ||
enableScoreboards(); | ||
initializeScoreboard(); | ||
} | ||
|
||
// Enable the join message if enabled | ||
if (getConfig().getBoolean("Enable-Join-Message", false)) { | ||
Bukkit.getServer().getPluginManager().registerEvents(new MessageJoin(), this); | ||
} | ||
BroadCast.startBroadcastTimer(getServer().getScheduler()); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
} | ||
|
||
private void enableScoreboards() { | ||
if (this.getServer().getPluginManager().getPlugin("Vault") == null) { | ||
Placeholders.vault = 0; | ||
} else { | ||
this.setupPermissions(); | ||
} | ||
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") == null) { | ||
Placeholders.PAPI = 0; | ||
} | ||
if (this.getServer().getPluginManager().getPlugin("Essentials") == null) { | ||
Placeholders.essentials = 0; | ||
} else { | ||
this.setupEconomy(); | ||
} | ||
this.Scheduler(); | ||
Bukkit.getServer().getPluginManager().registerEvents(new ScoreboardManager(), this); | ||
// The random interval broadcast module | ||
Broadcast.startBroadcastTimer(getServer().getScheduler()); | ||
} | ||
|
||
public boolean loadConfiguration() { | ||
File configFile = new File(getDataFolder(), "config.yml"); | ||
if (!configFile.exists()) { | ||
try { | ||
configFile.getParentFile().mkdirs(); | ||
} catch (SecurityException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
saveResource("config.yml", false); | ||
} | ||
// Get the config but don't actually load it into the main memory config | ||
FileConfiguration config = new YamlConfiguration(); | ||
try { | ||
config.load(configFile); | ||
if (!config.contains("Config-Version", true)) { | ||
logger.severe("Config-Version does not exist!"); | ||
return false; | ||
} else if (!config.isInt("Config-Version")) { | ||
logger.severe("Config-Version is not an integer!"); | ||
return false; | ||
} else if (!(config.getInt("Config-Version") == configVersion)) { | ||
logger.severe("Mismatched config version!"); | ||
return false; | ||
} else { | ||
reloadConfig(); | ||
return true; | ||
} | ||
} catch (IOException | InvalidConfigurationException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
public void Scheduler() { | ||
public void initializeScoreboard() { | ||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { | ||
try { | ||
ScoreboardManager.addScoreboard(); | ||
} catch (Exception var2) { | ||
var2.printStackTrace(); | ||
} | ||
}, 20L, Placeholders.isb * 20L); | ||
} | ||
|
||
// todo: I think we can just set vault as a softdepend instead of doing this? | ||
|
||
private void setupEconomy() { | ||
RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(Economy.class); | ||
if (economyProvider != null) { | ||
Placeholders.economy = (Economy) economyProvider.getProvider(); | ||
} | ||
} | ||
|
||
private void setupPermissions() { | ||
RegisteredServiceProvider permissionProvider = this.getServer().getServicesManager().getRegistration(Permission.class); | ||
if (permissionProvider != null) { | ||
Placeholders.permission = (Permission) permissionProvider.getProvider(); | ||
} | ||
}, 20L, ScoreboardManager.REFRESH_RATE * 20L); | ||
} | ||
|
||
public static GeyserHubMain getInstance() { | ||
return plugin; | ||
} | ||
|
||
} | ||
public ConfigManager getConfigManager() { | ||
return configManager; | ||
} | ||
} |
Oops, something went wrong.