mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2026-01-02 21:52:19 +00:00
Start reward work
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package net.islandearth.rpgregions;
|
||||
|
||||
import co.aikar.idb.DB;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.islandearth.languagy.language.LanguagyImplementation;
|
||||
import net.islandearth.languagy.language.LanguagyPluginHook;
|
||||
import net.islandearth.languagy.language.Translator;
|
||||
@@ -8,6 +11,7 @@ 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;
|
||||
@@ -16,8 +20,11 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, LanguagyPluginHook {
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, LanguagyPluginHook {
|
||||
|
||||
private RPGRegionsManagers managers;
|
||||
private static RPGRegions plugin;
|
||||
|
||||
@@ -38,7 +45,13 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
// Save all player data (quit event not called for shutdown)
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
this.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
});
|
||||
|
||||
// Close database connection
|
||||
DB.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,4 +99,8 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
public void onLanguagyHook() {
|
||||
translator.setDisplay(Material.MAP);
|
||||
}
|
||||
|
||||
public Gson getGson() {
|
||||
return new GsonBuilder().setPrettyPrinting().serializeNulls().create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,21 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldGuardIntegration implements IntegrationManager {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public WorldGuardIntegration(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
return WorldGuard.getInstance().getPlatform()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.islandearth.rpgregions.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("rpgregions")
|
||||
public class RPGRegionsCommand extends BaseCommand {
|
||||
|
||||
@Default
|
||||
public void onDefault(Player player, String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.islandearth.rpgregions.managers;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
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;
|
||||
|
||||
@@ -10,6 +11,7 @@ public class RPGRegionsManagers {
|
||||
|
||||
private StorageManager storageManager;
|
||||
private IntegrationManager integrationManager;
|
||||
private RPGRegionsCache regionsCache;
|
||||
|
||||
public RPGRegionsManagers(RPGRegions plugin) {
|
||||
StorageType.valueOf(plugin.getConfig().getString("settings.storage.mode").toUpperCase())
|
||||
@@ -21,6 +23,8 @@ public class RPGRegionsManagers {
|
||||
.get()
|
||||
.ifPresent(integrationManager1 -> integrationManager = integrationManager1);
|
||||
if (integrationManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
|
||||
this.regionsCache = new RPGRegionsCache(plugin);
|
||||
}
|
||||
|
||||
public StorageManager getStorageManager() {
|
||||
@@ -30,4 +34,8 @@ public class RPGRegionsManagers {
|
||||
public IntegrationManager getIntegrationManager() {
|
||||
return integrationManager;
|
||||
}
|
||||
|
||||
public RPGRegionsCache getRegionsCache() {
|
||||
return regionsCache;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.islandearth.rpgregions.managers.data;
|
||||
|
||||
public class RPGRegionsCache {
|
||||
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public enum StorageType {
|
||||
plugin.getLogger().info("Loading StorageManager implementation...");
|
||||
StorageManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor().newInstance();
|
||||
generatedClazz = clazz.getConstructor(RPGRegions.class).newInstance(JavaPlugin.getPlugin(RPGRegions.class));
|
||||
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.");
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.islandearth.rpgregions.rewards;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class DiscoveryReward {
|
||||
|
||||
private final String region;
|
||||
|
||||
DiscoveryReward(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
abstract void award(Player player);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.islandearth.rpgregions.rewards;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ExperienceReward extends DiscoveryReward {
|
||||
|
||||
private final int xp;
|
||||
|
||||
ExperienceReward(String region, int xp) {
|
||||
super(region);
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
void award(Player player) {
|
||||
player.giveExp(xp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.islandearth.rpgregions.rewards;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemReward extends DiscoveryReward {
|
||||
|
||||
private final ItemStack item;
|
||||
|
||||
ItemReward(String region, ItemStack item) {
|
||||
super(region);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
void award(Player player) {
|
||||
player.getInventory().addItem(item).forEach((pos, item) -> {
|
||||
player.getLocation().getWorld().dropItemNaturally(player.getLocation(), item);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user