mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-19 14:59:19 +00:00
First run, fixed errors, removed mysql-connector dependency
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
# RPGRegions-2
|
||||
RPGRegions is a unique plugin allowing users to discover regions, whilst providing an easy to use rewards system and creating advanced pathways to prevent accessing locked regions.
|
||||
|
||||
|
||||
@@ -32,11 +32,10 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.15-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT'
|
||||
implementation 'co.aikar:acf-paper:0.5.0-SNAPSHOT'
|
||||
implementation 'co.aikar:idb-core:1.0.0-SNAPSHOT'
|
||||
implementation 'com.zaxxer:HikariCP:2.4.1'
|
||||
implementation 'mysql:mysql-connector-java:5.1.33'
|
||||
implementation 'org.apache.commons:commons-lang3:3.6'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.2-SNAPSHOT'
|
||||
compileOnly name: 'languagy-1.2.6'
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.islandearth.rpgregions.listener.ConnectionListener;
|
||||
import net.islandearth.rpgregions.listener.MoveListener;
|
||||
import net.islandearth.rpgregions.listener.RegionListener;
|
||||
import net.islandearth.rpgregions.managers.RPGRegionsManagers;
|
||||
import net.islandearth.rpgregions.rewards.DiscoveryReward;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -20,8 +19,9 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, LanguagyPluginHook {
|
||||
|
||||
@@ -50,6 +50,20 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
this.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
});
|
||||
|
||||
// Save all region configs
|
||||
managers.getRegionsCache().getConfiguredRegions().forEach((id, region) -> {
|
||||
File file = new File(this.getDataFolder() + "/regions/" + id + ".json");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
Gson gson = this.getGson();
|
||||
gson.toJson(region, new FileWriter(file));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Close database connection
|
||||
DB.close();
|
||||
}
|
||||
@@ -68,7 +82,14 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
String header;
|
||||
String eol = System.getProperty("line.separator");
|
||||
header = "This is the config for RPGRegions." + eol;
|
||||
header += "------ Useful information ------" + eol;
|
||||
header += "Documentation can be found at (TBA)" + eol;
|
||||
header += "Sounds can be found at https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html" + eol;
|
||||
header += "------ Support ------" + eol;
|
||||
header += "Found a bug? Create an issue at https://gitlab.com/SamB440/rpgregions-2/issues" + eol;
|
||||
header += "Need help? Join our discord at https://discord.gg/fh62mxU" + eol;
|
||||
config.options().header(header);
|
||||
config.addDefault("settings.integration.name", "WorldGuard");
|
||||
config.addDefault("settings.storage.mode", "file");
|
||||
config.addDefault("settings.sql.host", "localhost");
|
||||
config.addDefault("settings.sql.port", 3306);
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package net.islandearth.rpgregions.api.event;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
public class RegionsEnterEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player player;
|
||||
private final Set<ProtectedRegion> regions;
|
||||
private final List<String> regions;
|
||||
|
||||
public RegionsEnterEvent(Player player, Set<ProtectedRegion> regions) {
|
||||
public RegionsEnterEvent(Player player, List<String> regions) {
|
||||
this.player = player;
|
||||
this.regions = regions;
|
||||
}
|
||||
@@ -25,7 +24,7 @@ public class RegionsEnterEvent extends Event {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<ProtectedRegion> getRegions() {
|
||||
public List<String> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,4 +8,5 @@ public interface IntegrationManager {
|
||||
boolean isInRegion(Location location);
|
||||
|
||||
void handleMove(PlayerMoveEvent pme);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.islandearth.rpgregions.api.integrations;
|
||||
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.api.integrations.worldguard.WorldGuardIntegration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
@@ -17,7 +19,7 @@ public enum IntegrationType {
|
||||
public Optional<IntegrationManager> get() {
|
||||
IntegrationManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor().newInstance();
|
||||
generatedClazz = clazz.getConstructor(RPGRegions.class).newInstance(JavaPlugin.getPlugin(RPGRegions.class));
|
||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@ import net.islandearth.rpgregions.api.event.RegionsEnterEvent;
|
||||
import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldGuardIntegration implements IntegrationManager {
|
||||
@@ -43,11 +46,17 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
if (prevRegions.equals(regions)) return;
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, regions));
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
regions.forEach(region -> stringRegions.add(region.getId()));
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions));
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
Set<ProtectedRegion> regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(location.getWorld())).getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ())).getRegions();
|
||||
return regions;
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(World world) {
|
||||
return getProtectedRegions(world.getSpawnLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.islandearth.rpgregions.listener;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.api.event.RegionDiscoverEvent;
|
||||
import net.islandearth.rpgregions.api.event.RegionsEnterEvent;
|
||||
@@ -34,8 +33,8 @@ public class RegionListener implements Listener {
|
||||
for (Discovery discovery : account.getDiscoveredRegions()) {
|
||||
String region = discovery.getRegion();
|
||||
boolean has = false;
|
||||
for (ProtectedRegion protectedRegion : ree.getRegions()) {
|
||||
if (protectedRegion.getId().equals(region)) {
|
||||
for (String protectedRegion : ree.getRegions()) {
|
||||
if (protectedRegion.equals(region)) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
@@ -67,5 +66,7 @@ public class RegionListener implements Listener {
|
||||
1,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
|
||||
);
|
||||
|
||||
//TODO give rewards
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ import net.islandearth.rpgregions.api.integrations.IntegrationType;
|
||||
import net.islandearth.rpgregions.managers.data.RPGRegionsCache;
|
||||
import net.islandearth.rpgregions.managers.data.StorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.StorageType;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class RPGRegionsManagers {
|
||||
|
||||
@@ -19,12 +23,28 @@ public class RPGRegionsManagers {
|
||||
.ifPresent(storageManager1 -> storageManager = storageManager1);
|
||||
if (storageManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
|
||||
IntegrationType.valueOf(plugin.getConfig().getString("integration").toUpperCase())
|
||||
IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(integrationManager1 -> integrationManager = integrationManager1);
|
||||
if (integrationManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
if (integrationManager == null) throw new IllegalStateException("Could not find IntegrationManager!");
|
||||
|
||||
this.regionsCache = new RPGRegionsCache(plugin);
|
||||
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
if (!folder.exists()) folder.mkdirs();
|
||||
|
||||
for (File file : folder.listFiles()) {
|
||||
// Exclude non-json files
|
||||
if (file.getName().endsWith(".json")) {
|
||||
try {
|
||||
ConfiguredRegion region = plugin.getGson().fromJson(new FileReader(file), ConfiguredRegion.class);
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(region);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Error loading region config " + file.getName() + ":");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public StorageManager getStorageManager() {
|
||||
|
||||
@@ -1,14 +1,36 @@
|
||||
package net.islandearth.rpgregions.managers.data;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class RPGRegionsCache {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private Map<String, ConfiguredRegion> configuredRegions = new ConcurrentHashMap<>();
|
||||
|
||||
public RPGRegionsCache(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public ConfiguredRegion getConfiguredRegion(String id) {
|
||||
return configuredRegions.get(id);
|
||||
}
|
||||
|
||||
public void addConfiguredRegion(ConfiguredRegion region) {
|
||||
configuredRegions.put(region.getId(), region);
|
||||
}
|
||||
|
||||
public void removeConfiguredRegion(String id) {
|
||||
configuredRegions.remove(id);
|
||||
}
|
||||
|
||||
public Map<String, ConfiguredRegion> getConfiguredRegions() {
|
||||
return ImmutableMap.copyOf(configuredRegions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public enum StorageType {
|
||||
plugin.getLogger().info("Loaded StorageManager implementation " + clazz.getName() + ".");
|
||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
plugin.getLogger().severe("Unable to load StorageManager (" + clazz.getName() + ")! Plugin will disable.");
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.islandearth.rpgregions.managers.data.region;
|
||||
|
||||
import net.islandearth.rpgregions.rewards.DiscoveryReward;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfiguredRegion {
|
||||
|
||||
private String id;
|
||||
private List<DiscoveryReward> rewards;
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setRewards(List<DiscoveryReward> rewards) {
|
||||
this.rewards = rewards;
|
||||
}
|
||||
|
||||
public List<DiscoveryReward> getRewards() {
|
||||
return rewards;
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import net.islandearth.rpgregions.managers.data.StorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import net.islandearth.rpgregions.managers.data.region.WorldDiscovery;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
@@ -27,11 +25,10 @@ public class SqlStorage implements StorageManager {
|
||||
|
||||
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
|
||||
|
||||
public SqlStorage() {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
DatabaseOptions options = DatabaseOptions.builder().mysql(plugin.getConfig().getString("sql.user"),
|
||||
plugin.getConfig().getString("sql.pass"),
|
||||
plugin.getConfig().getString("sql.db"),
|
||||
public SqlStorage(RPGRegions plugin) {
|
||||
DatabaseOptions options = DatabaseOptions.builder().mysql(plugin.getConfig().getString("settings.sql.user"),
|
||||
plugin.getConfig().getString("settings.sql.pass"),
|
||||
plugin.getConfig().getString("settings.sql.db"),
|
||||
plugin.getConfig().getString("sql.host") + ":" + plugin.getConfig().getString("sql.port")).build();
|
||||
Database db = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
|
||||
DB.setGlobalDatabase(db);
|
||||
|
||||
@@ -24,8 +24,7 @@ public class YamlStorage implements StorageManager {
|
||||
|
||||
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
|
||||
|
||||
public YamlStorage() {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
public YamlStorage(RPGRegions plugin) {
|
||||
File dataFile = new File(plugin.getDataFolder() + "/accounts/");
|
||||
if (!dataFile.exists()) {
|
||||
if (!dataFile.mkdirs()) {
|
||||
|
||||
@@ -2,7 +2,6 @@ name: RPGRegions
|
||||
version: @version@
|
||||
main: net.islandearth.rpgregions.RPGRegions
|
||||
api-version: 1.13
|
||||
load: STARTUP
|
||||
depend: [Languagy]
|
||||
softdepend: [WorldGuard, RedProtect]
|
||||
authors: [SamB440]
|
||||
|
||||
Reference in New Issue
Block a user