9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-27 18:59:10 +00:00

Finish GUI, add bStats, fix map error

This commit is contained in:
SamB440
2020-01-07 16:55:24 +00:00
parent 6a0f7c18d3
commit 264f2eac47
10 changed files with 107 additions and 74 deletions

View File

@@ -21,6 +21,11 @@ repositories {
url = 'https://oss.sonatype.org/content/groups/public/'
}
maven {
name = 'CodeMC'
url = 'https://repo.codemc.org/repository/maven-public'
}
maven { url = "https://repo.aikar.co/content/groups/aikar/" }
maven { url "https://maven.enginehub.org/repo/" }
@@ -38,14 +43,16 @@ dependencies {
implementation 'com.zaxxer:HikariCP:2.4.1' // database
implementation 'org.apache.commons:commons-lang3:3.6' // apache commons
implementation 'com.github.stefvanschie.inventoryframework:IF:0.5.17' // inventory framework
implementation 'org.bstats:bstats-bukkit:1.5' // plugin stats
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.2-SNAPSHOT' // worldguard
compileOnly name: 'languagy-1.2.6' // languagy
}
shadowJar {
relocate 'co.aikar.commands', 'net.islandearth.rpgmap.libs.acf'
relocate 'co.aikar.idb', 'net.islandearth.rpgmap.libs.idb'
relocate 'com.github.stefvanschie.inventoryframework', 'net.islandearth.inventoryframework'
relocate 'co.aikar.commands', 'net.islandearth.rpgregions.libs.acf'
relocate 'co.aikar.idb', 'net.islandearth.rpgregions.libs.idb'
relocate 'com.github.stefvanschie.inventoryframework', 'net.islandearth.rpgregions.inventoryframework'
relocate 'org.bstats', 'net.islandearth.rpgregions.bstats'
}
javadoc {

View File

@@ -16,6 +16,7 @@ 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.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
@@ -39,6 +40,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
@Override
public void onEnable() {
new Metrics(this);
plugin = this;
this.createConfig();
this.generateLang();

View File

@@ -2,6 +2,7 @@ package net.islandearth.rpgregions.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Subcommand;
import com.github.stefvanschie.inventoryframework.Gui;
@@ -16,6 +17,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +43,7 @@ public class RPGRegionsCommand extends BaseCommand {
}
@Subcommand("add")
@CommandPermission("rpgregions.add")
public void onAdd(CommandSender sender, String[] args) {
if (args.length == 1) {
String region = args[0];
@@ -56,6 +59,7 @@ public class RPGRegionsCommand extends BaseCommand {
}
@Subcommand("remove")
@CommandPermission("rpgregions.remove")
public void onRemove(CommandSender sender, String[] args) {
if (args.length == 1) {
String region = args[0];
@@ -73,6 +77,7 @@ public class RPGRegionsCommand extends BaseCommand {
}
@Subcommand("edit")
@CommandPermission("rpgregions.edit")
public void onEdit(Player player, String[] args) {
if (args.length == 1) {//TODO gui
String region = args[0];
@@ -92,7 +97,8 @@ public class RPGRegionsCommand extends BaseCommand {
}
}
@Subcommand("list")
@Subcommand("list|discoveries")
@CommandPermission("rpgregions.list")
public void onList(Player player) {
Gui gui = new Gui(plugin, 6, "Regions");
PaginatedPane pane = new PaginatedPane(0, 0, 9, 5);
@@ -136,16 +142,27 @@ public class RPGRegionsCommand extends BaseCommand {
gui.addPane(back);
gui.addPane(forward);
List<GuiItem> items = new ArrayList<>();
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
items.add(new GuiItem(new ItemStackBuilder(configuredRegion.getIcon())
.withName(ChatColor.WHITE + configuredRegion.getCustomName())
.build(),
event -> event.setCancelled(true)));
}
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
List<GuiItem> items = new ArrayList<>();
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
ChatColor colour = account.getDiscoveredRegions().containsKey(configuredRegion.getId())
? ChatColor.GREEN
: ChatColor.RED;
String lore = account.getDiscoveredRegions().containsKey(configuredRegion.getId())
? ChatColor.GRAY + "Discovered on: "
+ account.getDiscoveredRegions().get(configuredRegion.getId()).getDate()
: "";
items.add(new GuiItem(new ItemStackBuilder(configuredRegion.getIcon())
.withName(colour + configuredRegion.getCustomName())
.withLore(lore)
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
.build(),
event -> event.setCancelled(true)));
}
pane.populateWithGuiItems(items);
gui.addPane(pane);
gui.show(player);
pane.populateWithGuiItems(items);
gui.addPane(pane);
gui.show(player);
});
}
}

View File

@@ -33,7 +33,7 @@ public class RegionListener implements Listener {
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
for (String region : ree.getRegions()) {
boolean has = false;
for (Discovery discoveredRegion : account.getDiscoveredRegions()) {
for (Discovery discoveredRegion : account.getDiscoveredRegions().values()) {
if (discoveredRegion.getRegion().equals(region)) {
has = true;
break;
@@ -41,7 +41,7 @@ public class RegionListener implements Listener {
}
if (!has) {
account.addDiscovery(new WorldDiscovery(Date.from(Instant.now()), region));
account.addDiscovery(new WorldDiscovery(Date.from(Instant.now()).toString(), region));
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region));
}
}
@@ -53,6 +53,7 @@ public class RegionListener implements Listener {
Player player = rde.getPlayer();
String region = rde.getRegion();
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
player.sendTitle(
Translations.DISCOVERED_TITLE.get(player, region),
Translations.DISCOVERED_SUBTITLE.get(player, region),
@@ -61,14 +62,22 @@ public class RegionListener implements Listener {
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadeout")
);
player.playSound(
player.getLocation(),
Sound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
if (configuredRegion.getSound() == null) {
player.playSound(
player.getLocation(),
Sound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
} else {
player.playSound(
player.getLocation(),
configuredRegion.getSound(),
1,
plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch")
);
}
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
configuredRegion.getRewards().forEach(reward -> reward.award(player));
}
}

View File

@@ -9,6 +9,10 @@ import net.islandearth.rpgregions.managers.data.StorageType;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.rewards.DiscoveryReward;
import net.islandearth.rpgregions.rewards.ExperienceReward;
import net.islandearth.rpgregions.rewards.ItemReward;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.FileReader;
@@ -41,7 +45,10 @@ public class RPGRegionsManagers {
List<DiscoveryReward> rewards = new ArrayList<>();
rewards.add(new ExperienceReward(10));
ConfiguredRegion configuredRegion = new ConfiguredRegion("docks-1", "Docks", rewards);
rewards.add(new ItemReward(new ItemStack(Material.IRON_BARS)));
ConfiguredRegion configuredRegion = new ConfiguredRegion("docks-1", "Docks", rewards,
Sound.AMBIENT_UNDERWATER_EXIT,
Material.WOODEN_AXE);
regionsCache.addConfiguredRegion(configuredRegion);
try {
configuredRegion.save(plugin);

View File

@@ -2,24 +2,24 @@ package net.islandearth.rpgregions.managers.data.account;
import net.islandearth.rpgregions.managers.data.region.Discovery;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class RPGRegionsAccount {
private UUID uuid;
private List<Discovery> discoveredRegions = new ArrayList<>();
private Map<String, Discovery> discoveredRegions;
public RPGRegionsAccount(UUID uuid, List<Discovery> discoveredRegions) {
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
this.uuid = uuid;
this.discoveredRegions = discoveredRegions;
}
public List<Discovery> getDiscoveredRegions() {
public Map<String, Discovery> getDiscoveredRegions() {
return discoveredRegions;
}
public void addDiscovery(Discovery discovery) {
discoveredRegions.add(discovery);
discoveredRegions.put(discovery.getRegion(), discovery);
}
}

View File

@@ -1,14 +1,12 @@
package net.islandearth.rpgregions.managers.data.region;
import java.util.Date;
public interface Discovery {
/**
* Gets the date this discovery was made.
* @return date of discovery
*/
Date getDate();
String getDate();
/**
* Gets the name of the region that was discovered.

View File

@@ -1,19 +1,17 @@
package net.islandearth.rpgregions.managers.data.region;
import java.util.Date;
public class WorldDiscovery implements Discovery {
private Date date;
private String date;
private String region;
public WorldDiscovery(Date date, String region) {
public WorldDiscovery(String date, String region) {
this.date = date;
this.region = region;
}
@Override
public Date getDate() {
public String getDate() {
return date;
}

View File

@@ -1,26 +1,22 @@
package net.islandearth.rpgregions.managers.data.sql;
import co.aikar.idb.*;
import com.google.common.collect.ImmutableMap;
import net.islandearth.rpgregions.RPGRegions;
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 java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class SqlStorage implements StorageManager {
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Discoveries (uuid varchar(32) NOT NULL, region varchar(32) NOT NULL, time datetime NOT NULL, PRIMARY KEY(uuid))";
private static final String SELECT_REGION = "SELECT region FROM Discoveries WHERE uuid = ?";
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Discoveries (uuid varchar(32) NOT NULL, region varchar(32) NOT NULL, time varchar(64) NOT NULL, PRIMARY KEY(uuid))";
private static final String SELECT_REGION = "SELECT * FROM Discoveries WHERE uuid = ?";
private static final String INSERT_DISCOVERY = "INSERT INTO Discoveries (uuid, region, time) VALUES (?, ?, ?)";
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
@@ -46,9 +42,10 @@ public class SqlStorage implements StorageManager {
future.complete(cachedAccounts.get(uuid));
} else {
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
List<Discovery> regions = new ArrayList<>();
Map<String, Discovery> regions = new HashMap<>();
for (DbRow row : results) {
regions.add(new WorldDiscovery(Date.valueOf(row.getString("time")), row.getString("region")));
String region = row.getString("region");
regions.put(region, new WorldDiscovery(row.getString("time"), region));
}
RPGRegionsAccount account = new RPGRegionsAccount(uuid, regions);
@@ -61,28 +58,28 @@ public class SqlStorage implements StorageManager {
@Override
public ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts() {
return (ConcurrentMap<UUID, RPGRegionsAccount>) ImmutableMap.copyOf(cachedAccounts);
return cachedAccounts;
}
@Override
public void removeCachedAccount(UUID uuid) {
RPGRegionsAccount account = cachedAccounts.get(uuid);
List<Discovery> current = new ArrayList<>();
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
List<String> current = new ArrayList<>();
for (DbRow row : results) {
current.add(new WorldDiscovery(Date.valueOf(row.getString("time")), row.getString("region")));
current.add(row.getString("region"));
}
});
for (Discovery region : account.getDiscoveredRegions()) {
if (!current.contains(region)) {
try {
DB.executeInsert(INSERT_DISCOVERY, getDatabaseUuid(uuid), region.getRegion(), region.getDate().toString());
} catch (SQLException e) {
e.printStackTrace();
for (Discovery region : account.getDiscoveredRegions().values()) {
if (!current.contains(region.getRegion())) {
try {
DB.executeInsert(INSERT_DISCOVERY, getDatabaseUuid(uuid), region.getRegion(), region.getDate());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
cachedAccounts.remove(uuid);
cachedAccounts.remove(uuid);
});
}
}

View File

@@ -1,6 +1,5 @@
package net.islandearth.rpgregions.managers.data.yml;
import com.google.common.collect.ImmutableMap;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.managers.data.StorageManager;
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
@@ -8,14 +7,10 @@ import net.islandearth.rpgregions.managers.data.region.Discovery;
import net.islandearth.rpgregions.managers.data.region.WorldDiscovery;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -24,7 +19,10 @@ public class YamlStorage implements StorageManager {
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
private final RPGRegions plugin;
public YamlStorage(RPGRegions plugin) {
this.plugin = plugin;
File dataFile = new File(plugin.getDataFolder() + "/accounts/");
dataFile.mkdirs();
}
@@ -35,14 +33,14 @@ public class YamlStorage implements StorageManager {
if (cachedAccounts.containsKey(uuid)) {
future.complete(cachedAccounts.get(uuid));
} else {
File file = new File(JavaPlugin.getPlugin(RPGRegions.class).getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
List<Discovery> regions = new ArrayList<>();
Map<String, Discovery> regions = new HashMap<>();
for (String results : config.getStringList("Discoveries")) {
String[] data = results.split(";");
Date time = Date.valueOf(data[0]);
String time = data[0];
String region = data[1];
regions.add(new WorldDiscovery(time, region));
regions.put(region, new WorldDiscovery(time, region));
}
RPGRegionsAccount account = new RPGRegionsAccount(uuid, regions);
@@ -54,26 +52,26 @@ public class YamlStorage implements StorageManager {
@Override
public ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts() {
return (ConcurrentMap<UUID, RPGRegionsAccount>) ImmutableMap.copyOf(cachedAccounts);
return cachedAccounts;
}
@Override
public void removeCachedAccount(UUID uuid) {
RPGRegionsAccount account = cachedAccounts.get(uuid);
File file = new File(JavaPlugin.getPlugin(RPGRegions.class).getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
List<Discovery> current = new ArrayList<>();
for (String results : config.getStringList("Discoveries")) {
String[] data = results.split(";");
Date time = Date.valueOf(data[0]);
String time = data[0];
String region = data[1];
current.add(new WorldDiscovery(time, region));
}
List<String> newData = config.getStringList("Discoveries");
for (Discovery region : account.getDiscoveredRegions()) {
for (Discovery region : account.getDiscoveredRegions().values()) {
if (!current.contains(region)) {
newData.add(region.getDate().toString() + ";" + region.getRegion());
newData.add(region.getDate() + ";" + region.getRegion());
}
}