mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-27 10:49:08 +00:00
Initial commit
This commit is contained in:
BIN
libraries/languagy-1.2.5.jar
Normal file
BIN
libraries/languagy-1.2.5.jar
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
package net.islandearth.rpgregions.api;
|
||||
|
||||
import net.islandearth.rpgregions.managers.RPGRegionsManagers;
|
||||
|
||||
public interface RPGRegionsAPI {
|
||||
|
||||
RPGRegionsManagers getManagers();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.islandearth.rpgregions.managers;
|
||||
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.managers.data.StorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.StorageType;
|
||||
import net.islandearth.rpgregions.managers.integrations.IntegrationManager;
|
||||
import net.islandearth.rpgregions.managers.integrations.IntegrationType;
|
||||
|
||||
public class RPGRegionsManagers {
|
||||
|
||||
private StorageManager storageManager;
|
||||
private IntegrationManager integrationManager;
|
||||
|
||||
public RPGRegionsManagers(RPGRegions plugin) {
|
||||
StorageType.valueOf(plugin.getConfig().getString("storage").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(storageManager1 -> storageManager = storageManager1);
|
||||
if (storageManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
|
||||
IntegrationType.valueOf(plugin.getConfig().getString("integration").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(integrationManager1 -> integrationManager = integrationManager1);
|
||||
if (integrationManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
}
|
||||
|
||||
public StorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
public IntegrationManager getIntegrationManager() {
|
||||
return integrationManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.islandearth.rpgregions.managers.data;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface StorageManager {
|
||||
|
||||
RPGRegionsAccount getAccount(Player player);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.islandearth.rpgregions.managers.data;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.sql.SqlStorage;
|
||||
import net.islandearth.rpgregions.managers.data.yml.YamlStorage;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum StorageType {
|
||||
FILE(YamlStorage.class),
|
||||
SQL(SqlStorage.class);
|
||||
|
||||
private final Class<? extends StorageManager> clazz;
|
||||
|
||||
StorageType(Class<? extends StorageManager> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Optional<StorageManager> get() {
|
||||
StorageManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor().newInstance();
|
||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(generatedClazz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.islandearth.rpgregions.managers.data.account;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RPGRegionsAccount {
|
||||
|
||||
public List<String> getDiscoveredRegions() {
|
||||
return discoveredRegions;
|
||||
}
|
||||
|
||||
private List<String> discoveredRegions = new ArrayList<>();
|
||||
|
||||
public RPGRegionsAccount(UUID uuid) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.islandearth.rpgregions.managers.data.sql;
|
||||
|
||||
import co.aikar.idb.DB;
|
||||
import co.aikar.idb.Database;
|
||||
import co.aikar.idb.DatabaseOptions;
|
||||
import co.aikar.idb.PooledDatabaseOptions;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.managers.data.StorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class SqlStorage implements StorageManager {
|
||||
|
||||
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"),
|
||||
plugin.getConfig().getString("sql.host") + ":" + plugin.getConfig().getString("sql.port")).build();
|
||||
Database db = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
|
||||
DB.setGlobalDatabase(db);
|
||||
//TODO make table
|
||||
}
|
||||
|
||||
@Override
|
||||
public RPGRegionsAccount getAccount(Player player) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.islandearth.rpgregions.managers.data.yml;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.StorageManager;
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class YamlStorage implements StorageManager {
|
||||
@Override
|
||||
public RPGRegionsAccount getAccount(Player player) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.islandearth.rpgregions.managers.integrations;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface IntegrationManager {
|
||||
|
||||
boolean isInRegion(Location location);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.islandearth.rpgregions.managers.integrations;
|
||||
|
||||
import net.islandearth.rpgregions.managers.integrations.redprotect.RedProtectIntegration;
|
||||
import net.islandearth.rpgregions.managers.integrations.worldguard.WorldGuardIntegration;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum IntegrationType {
|
||||
WORLDGUARD(WorldGuardIntegration.class),
|
||||
REDPROTECT(RedProtectIntegration.class);
|
||||
|
||||
private final Class<? extends IntegrationManager> clazz;
|
||||
|
||||
IntegrationType(Class<? extends IntegrationManager> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Optional<IntegrationManager> get() {
|
||||
IntegrationManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor().newInstance();
|
||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(generatedClazz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.islandearth.rpgregions.managers.integrations.redprotect;
|
||||
|
||||
import net.islandearth.rpgregions.managers.integrations.IntegrationManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class RedProtectIntegration implements IntegrationManager {
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.islandearth.rpgregions.managers.integrations.worldguard;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import net.islandearth.rpgregions.managers.integrations.IntegrationManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class WorldGuardIntegration implements IntegrationManager {
|
||||
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
return WorldGuard.getInstance().getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(location.getWorld()))
|
||||
.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ())).size() > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package net.islandearth.rpgregions.translation;
|
||||
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum Translations {
|
||||
DISCOVERED;
|
||||
|
||||
private String getPath() {
|
||||
return this.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public void send(Player player) {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
String message = plugin.getTranslator().getTranslationFor(player, this.getPath());
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
public void send(Player player, String... values) {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
String message = plugin.getTranslator().getTranslationFor(player, this.getPath());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) message = message.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
public void sendList(Player player) {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
List<String> message = plugin.getTranslator().getTranslationListFor(player, this.getPath());
|
||||
message.forEach(player::sendMessage);
|
||||
}
|
||||
|
||||
public void sendList(Player player, String... values) {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
List<String> messages = plugin.getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) message = message.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public String get(Player player) {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
return plugin.getTranslator().getTranslationFor(player, this.getPath());
|
||||
}
|
||||
|
||||
public List<String> getList(Player player) {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
return plugin.getTranslator().getTranslationListFor(player, this.getPath());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user