Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #24 from ProjectG-Plugins/1.3.1
Browse files Browse the repository at this point in the history
1.3.1
  • Loading branch information
Konicai authored Dec 2, 2021
2 parents 8e3b144 + f1c846f commit 1318bd6
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 248 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Build Status](https://ci.projectg.dev/job/GeyserHub/job/master/badge/icon)](https://ci.projectg.dev/job/GeyserHub/job/master/)
[![Spigot page downloads](https://img.shields.io/spiget/downloads/95455?color=yellow&label=Spigot%20page%20downloads)](https://www.spigotmc.org/resources/geyserhub.95455/)
[![bStats Spigot](https://img.shields.io/bstats/servers/13469?color=yellow&label=Spigot%20servers)](https://bstats.org/plugin/bukkit/GeyserHub/13469)
[![Discord](https://img.shields.io/discord/806179549498966058?color=7289da&label=discord&logo=discord&logoColor=white)](https://discord.gg/M2SvqCu4e9)
[![Build Status](https://ci.projectg.dev/job/GeyserHub/job/master/badge/icon)](https://ci.projectg.dev/job/GeyserHub/job/master/)
[![License](https://img.shields.io/badge/License-GPL-orange)](https://github.com/ProjectG-Plugins/GeyserUpdater/blob/master/LICENSE)


Expand Down
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

<groupId>dev.projectg</groupId>
<artifactId>GeyserHub</artifactId>
<version>1.3.0</version>
<name>GeyserHub</name>
<version>1.3.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -49,7 +50,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -61,17 +62,23 @@
<dependency>
<groupId>org.geysermc.floodgate</groupId>
<artifactId>api</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<version>2.10.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/dev/projectg/geyserhub/GeyserHubMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.projectg.geyserhub.command.GeyserHubCommand;
import dev.projectg.geyserhub.config.ConfigManager;
import dev.projectg.geyserhub.module.menu.AccessItemRegistry;
import dev.projectg.geyserhub.module.menu.CommonMenuListeners;
import dev.projectg.geyserhub.module.menu.InventoryManager;
import dev.projectg.geyserhub.module.menu.java.JavaMenuListeners;
import dev.projectg.geyserhub.module.menu.bedrock.BedrockFormRegistry;
import dev.projectg.geyserhub.module.menu.java.JavaMenuRegistry;
Expand All @@ -30,7 +30,6 @@ public class GeyserHubMain extends JavaPlugin {
public void onEnable() {
long start = System.currentTimeMillis();
plugin = this;
new Metrics(this, 13469);
// getting the logger forces the config to load before our loadConfiguration() is called...
SelectorLogger logger = SelectorLogger.getLogger();

Expand Down Expand Up @@ -67,7 +66,7 @@ public void onEnable() {
// todo: sort all of this, and make checking for enable value in config consistent

// Listeners for the Bedrock and Java menus
Bukkit.getServer().getPluginManager().registerEvents(new CommonMenuListeners(accessItemRegistry, bedrockFormRegistry, javaMenuRegistry), this);
Bukkit.getServer().getPluginManager().registerEvents(new InventoryManager(accessItemRegistry, bedrockFormRegistry, javaMenuRegistry), this);
Bukkit.getServer().getPluginManager().registerEvents(new JavaMenuListeners(javaMenuRegistry), this);

// Listener the Join Teleporter module
Expand All @@ -89,6 +88,10 @@ public void onEnable() {
// The random interval broadcast module
Broadcast.startBroadcastTimer(getServer().getScheduler());

if (getConfig().getBoolean("Bstats", true)) {
new Metrics(this, 13469);
}

logger.info("Took " + (System.currentTimeMillis() - start) + "ms to boot GeyserHub.");
}

Expand Down
22 changes: 8 additions & 14 deletions src/main/java/dev/projectg/geyserhub/command/GeyserHubCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.projectg.geyserhub.command;

import com.google.common.collect.ImmutableMap;
import dev.projectg.geyserhub.SelectorLogger;
import dev.projectg.geyserhub.module.menu.MenuUtils;
import dev.projectg.geyserhub.module.menu.java.JavaMenuRegistry;
Expand All @@ -15,10 +16,16 @@
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Objects;

public class GeyserHubCommand implements CommandExecutor {

private static final Map<SelectorLogger.Level, ChatColor> LOGGER_COLORS = ImmutableMap.of(
SelectorLogger.Level.INFO, ChatColor.RESET,
SelectorLogger.Level.WARN, ChatColor.GOLD,
SelectorLogger.Level.SEVERE, ChatColor.RED);

private static final String[] HELP = {
"/ghub - Opens the default form if one exists. If not, shows the help page",
"/ghub - Opens the help page",
Expand Down Expand Up @@ -122,20 +129,7 @@ public static void sendMessage(@Nonnull CommandSender sender, @Nonnull SelectorL
if (sender instanceof ConsoleCommandSender) {
SelectorLogger.getLogger().log(level, message);
} else {
ChatColor colour;
switch (level) {
default: // intentional fallthrough
case INFO:
colour = ChatColor.RESET;
break;
case WARN:
colour = ChatColor.GOLD;
break;
case SEVERE:
colour = ChatColor.RED;
break;
}
sender.sendMessage("[GeyserHub] " + colour + message);
sender.sendMessage("[GeyserHub] " + LOGGER_COLORS.getOrDefault(level, ChatColor.RESET) + message);
}
}
}
4 changes: 1 addition & 3 deletions src/main/java/dev/projectg/geyserhub/config/ConfigId.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* An enum containing the identities of all valid configuration files.
*/
public enum ConfigId {
MAIN("config.yml", 5),
MAIN("config.yml", 6),
SELECTOR("selector.yml", 2);

public static final ConfigId[] VALUES = values();

public final String fileName;
public final int version;

// todo: maybe load configs on enum init

/**
* @param fileName the filename, including the extension, of the configuration
* @param version the version of the configuration
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/dev/projectg/geyserhub/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.projectg.geyserhub.GeyserHubMain;
import dev.projectg.geyserhub.SelectorLogger;
import dev.projectg.geyserhub.config.updaters.MAIN_4;
import dev.projectg.geyserhub.config.updaters.MAIN_5;
import dev.projectg.geyserhub.config.updaters.SELECTOR_1;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
Expand All @@ -22,8 +23,12 @@ public class ConfigManager {

static {
// todo: this is awful but oh well
Map<Integer, Class<? extends ConfigUpdater>> mainUpdaters = new HashMap<>();
mainUpdaters.put(4, MAIN_4.class);
mainUpdaters.put(5, MAIN_5.class);

updaters.put(ConfigId.SELECTOR, Collections.singletonMap(1, SELECTOR_1.class));
updaters.put(ConfigId.MAIN, Collections.singletonMap(4, MAIN_4.class));
updaters.put(ConfigId.MAIN, mainUpdaters);
}

private final Map<ConfigId, FileConfiguration> configurations = new HashMap<>();
Expand Down Expand Up @@ -151,7 +156,7 @@ public boolean loadConfig(@Nonnull ConfigId config) {
if (configuration.getInt("Config-Version") == config.version) {
logger.info(config.fileName + " was successfully updated to the latest version");
} else {
logger.warn("Failed to fully update " + config.fileName + " from version " + oldVersion + " to " + config.version);
logger.severe("Failed to fully update " + config.fileName + " from version " + oldVersion + " to " + config.version);
return false;
}
}
Expand Down Expand Up @@ -184,7 +189,7 @@ public Map<ConfigId, FileConfiguration> getAllFileConfigurations() {
* Converts a ConfigurationSection into a Map, whose keys and values are those of the ConfigurationSection.
* Child ConfigurationSections will also be converted into Maps.
*/
public static Map<String, Object> getMap(@Nonnull ConfigurationSection config) {
public static Map<String, Object> asMap(@Nonnull ConfigurationSection config) {
Map<String, Object> map = new LinkedHashMap<>();

for (String key : config.getKeys(false)) {
Expand All @@ -193,7 +198,7 @@ public static Map<String, Object> getMap(@Nonnull ConfigurationSection config) {
ConfigurationSection subSection = config.getConfigurationSection(key);
Objects.requireNonNull(subSection);

value = getMap(subSection);
value = asMap(subSection);
} else {
value = config.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.bukkit.configuration.ConfigurationSection;

/**
* All implementing classes must have a zero-argument constructor.
*/
public interface ConfigUpdater {

/**
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/dev/projectg/geyserhub/config/updaters/MAIN_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.projectg.geyserhub.config.updaters;

import dev.projectg.geyserhub.config.ConfigUpdater;
import org.bukkit.configuration.ConfigurationSection;

import java.util.Objects;

public class MAIN_5 implements ConfigUpdater {

@Override
public boolean update(ConfigurationSection config) throws IllegalArgumentException {
if (!config.contains("Join-Teleporter.Coordinates", true)) {
throw new IllegalArgumentException("Main config must contain Join-Teleporter config section and Coordinates string value");
}

ConfigurationSection teleporter = config.getConfigurationSection("Join-Teleporter");
Objects.requireNonNull(teleporter);

String composedCoords = Objects.requireNonNull(teleporter.getString("Coordinates"));
String[] coordinates = composedCoords.split(";", 3);

try {
teleporter.set("X", Integer.parseInt(coordinates[0]));
teleporter.set("Y", Integer.parseInt(coordinates[1]));
teleporter.set("Z", Integer.parseInt(coordinates[2]));
teleporter.set("Yaw", 0); // Default
teleporter.set("Pitch", 0); // Default

config.set("Join-Teleporter.Coordinates", null); // Remove
config.set("Config-Version", 6);

return true;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Config contains invalid coordinates value: string must be 3 integers separated by 2 semicolons.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean update(ConfigurationSection config) throws IllegalArgumentExcepti
config.set("Selector-Item", null);

// A map containing the same information as the configuration section
Map<String, Object> defaultItem = ConfigManager.getMap(items);
Map<String, Object> defaultItem = ConfigManager.asMap(items);
defaultItem.put("Form", "default"); // new data

// Clear the section
Expand All @@ -40,7 +40,7 @@ public boolean update(ConfigurationSection config) throws IllegalArgumentExcepti
items.createSection("Items.default", defaultItem); // re-insert the old data into the default access item

// Add the Selector-Item section back in, under the new name
config.createSection("Access-Items", ConfigManager.getMap(items));
config.createSection("Access-Items", ConfigManager.asMap(items));

// bump version
config.set("Config-Version", 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class AccessItem {
*/
public final boolean onJoin;

/**
* True for players to receive it when they respawn
*/
public final boolean onRespawn;

/**
* True for players to be able to drop the item
*/
Expand Down Expand Up @@ -70,13 +75,14 @@ public class AccessItem {
* @param material The material for the ItemStack to be
* @param lore The lore for the ItemStack
* @param onJoin True for players to receive it when they join
* @param onRespawn True for players to receive it when they respawn (excluding server join)
* @param allowDrop True for players to be able to drop the item
* @param destroyDropped True for the item to be destroyed when dropped
* @param allowMove True for players to be able to move the item
* @param formName The form/menu name to open.
*/
public AccessItem(@Nonnull String itemId, int slot, @Nonnull String displayName, @Nonnull Material material, @Nonnull List<String> lore,
boolean onJoin, boolean allowDrop, boolean destroyDropped, boolean allowMove,
boolean onJoin, boolean onRespawn, boolean allowDrop, boolean destroyDropped, boolean allowMove,
@Nonnull String formName) {
Objects.requireNonNull(material);
if (new ItemStack(material).getItemMeta() == null) {
Expand All @@ -89,6 +95,7 @@ public AccessItem(@Nonnull String itemId, int slot, @Nonnull String displayName,
this.lore = Objects.requireNonNull(lore);

this.onJoin = onJoin;
this.onRespawn = onRespawn;
this.allowDrop = allowDrop;
this.destroyDropped = destroyDropped;
this.allowMove = allowMove;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ private void load() {
String formName = Objects.requireNonNull(itemEntry.getString("Form"));

if (itemEntry.contains("Slot", true) && itemEntry.isInt("Slot")) {
if ( !itemEntry.contains("Join") || !itemEntry.contains("Allow-Drop") || !itemEntry.contains("Destroy-Dropped") || !itemEntry.contains("Allow-Move")
|| !itemEntry.isBoolean("Join") || !itemEntry.isBoolean("Allow-Drop") || !itemEntry.isBoolean("Destroy-Dropped") || !itemEntry.isBoolean("Allow-Move")) {
logger.warn("Failed to create access item " + itemId + " because it is missing config values!");
continue;
}
int slot = Math.abs(itemEntry.getInt("Slot"));
items.put(itemId, new AccessItem(itemId, slot, name, material, lore,
itemEntry.getBoolean("Join"), itemEntry.getBoolean("Allow-Drop"),
itemEntry.getBoolean("Destroy-Dropped"), itemEntry.getBoolean("Allow-Move"),
items.put(itemId, new AccessItem(itemId,
slot,
name,
material,
lore,
itemEntry.getBoolean("Join", true),
itemEntry.getBoolean("Respawn", true),
itemEntry.getBoolean("Allow-Drop", false),
itemEntry.getBoolean("Destroy-Dropped", true),
itemEntry.getBoolean("Allow-Move", false),
formName));

isEnabled = true;
Expand Down
Loading

0 comments on commit 1318bd6

Please sign in to comment.