mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-28 11:19:24 +00:00
Reindent everything with 4 spaces
This commit is contained in:
@@ -20,78 +20,78 @@ import java.util.Set;
|
||||
|
||||
public class WorldGuardLegacyIntegration implements IntegrationManager {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public WorldGuardLegacyIntegration(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public WorldGuardLegacyIntegration(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
return this.getProtectedRegions(location).size() > 0;
|
||||
}
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
return this.getProtectedRegions(location).size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
int x = pme.getTo().getBlockX();
|
||||
int y = pme.getTo().getBlockY();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
int x = pme.getTo().getBlockX();
|
||||
int y = pme.getTo().getBlockY();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
regions.forEach(region -> {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region.getId());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !requirement.meetsRequirements(player)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
regions.forEach(region -> {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region.getId());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !requirement.meetsRequirements(player)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredRegion getPrioritisedRegion(Location location) {
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(location);
|
||||
ProtectedRegion highest = null;
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (highest == null) {
|
||||
highest = region;
|
||||
continue;
|
||||
}
|
||||
@Override
|
||||
public ConfiguredRegion getPrioritisedRegion(Location location) {
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(location);
|
||||
ProtectedRegion highest = null;
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (highest == null) {
|
||||
highest = region;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (region.getPriority() >= highest.getPriority()) {
|
||||
highest = region;
|
||||
}
|
||||
}
|
||||
if (region.getPriority() >= highest.getPriority()) {
|
||||
highest = region;
|
||||
}
|
||||
}
|
||||
|
||||
if (highest == null) return null;
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
||||
}
|
||||
if (highest == null) return null;
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(World world, String region) {
|
||||
return WorldGuardPlugin.inst()
|
||||
.getRegionContainer()
|
||||
.get(world)
|
||||
.getRegions().containsKey(region);
|
||||
}
|
||||
@Override
|
||||
public boolean exists(World world, String region) {
|
||||
return WorldGuardPlugin.inst()
|
||||
.getRegionContainer()
|
||||
.get(world)
|
||||
.getRegions().containsKey(region);
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
return WorldGuardPlugin.inst()
|
||||
.getRegionContainer()
|
||||
.get(location.getWorld())
|
||||
.getApplicableRegions(location)
|
||||
.getRegions();
|
||||
}
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
return WorldGuardPlugin.inst()
|
||||
.getRegionContainer()
|
||||
.get(location.getWorld())
|
||||
.getApplicableRegions(location)
|
||||
.getRegions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,68 +19,68 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GriefPreventionIntegration implements IntegrationManager {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public GriefPreventionIntegration(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
||||
return claim != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
Claim oldClaim = GriefPrevention.instance.dataStore.getClaimAt(pme.getFrom(), false, null);
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(pme.getTo(), false, null);
|
||||
if (oldClaim == null || claim == null) return;
|
||||
|
||||
List<String> stringClaim = new ArrayList<>();
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion("" + claim.getID());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
if (requirement instanceof DependencyRequirement) {
|
||||
DependencyRequirement dependencyRequirement = (DependencyRequirement) requirement;
|
||||
List<String> discoveries = new ArrayList<>();
|
||||
RPGRegions.getAPI().getManagers().getStorageManager().getAccount(player.getUniqueId()).whenComplete((account, error) -> {
|
||||
discoveries.addAll(account.getDiscoveredRegions().keySet());
|
||||
}).exceptionally(error -> {
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !dependencyRequirement.meetsRequirements(player, discoveries)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !requirement.meetsRequirements(player)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stringClaim.add("" + claim.getID());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringClaim, !oldClaim.equals(claim)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredRegion getPrioritisedRegion(Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegions().get("" + claim.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(World location, String region) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaim(Long.parseLong(region));
|
||||
return claim != null;
|
||||
}
|
||||
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public GriefPreventionIntegration(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
||||
return claim != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
Claim oldClaim = GriefPrevention.instance.dataStore.getClaimAt(pme.getFrom(), false, null);
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(pme.getTo(), false, null);
|
||||
if (oldClaim == null || claim == null) return;
|
||||
|
||||
List<String> stringClaim = new ArrayList<>();
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion("" + claim.getID());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
if (requirement instanceof DependencyRequirement) {
|
||||
DependencyRequirement dependencyRequirement = (DependencyRequirement) requirement;
|
||||
List<String> discoveries = new ArrayList<>();
|
||||
RPGRegions.getAPI().getManagers().getStorageManager().getAccount(player.getUniqueId()).whenComplete((account, error) -> {
|
||||
discoveries.addAll(account.getDiscoveredRegions().keySet());
|
||||
}).exceptionally(error -> {
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !dependencyRequirement.meetsRequirements(player, discoveries)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !requirement.meetsRequirements(player)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stringClaim.add("" + claim.getID());
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringClaim, !oldClaim.equals(claim)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredRegion getPrioritisedRegion(Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegions().get("" + claim.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(World location, String region) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaim(Long.parseLong(region));
|
||||
return claim != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,98 +23,98 @@ 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 this.getProtectedRegions(location).size() > 0;
|
||||
}
|
||||
private final RPGRegions plugin;
|
||||
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
int x = pme.getTo().getBlockX();
|
||||
int y = pme.getTo().getBlockY();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
public WorldGuardIntegration(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
regions.forEach(region -> {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region.getId());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
if (requirement instanceof DependencyRequirement) {
|
||||
DependencyRequirement dependencyRequirement = (DependencyRequirement) requirement;
|
||||
List<String> discoveries = new ArrayList<>();
|
||||
RPGRegions.getAPI().getManagers().getStorageManager().getAccount(player.getUniqueId()).whenComplete((account, error) -> {
|
||||
discoveries.addAll(account.getDiscoveredRegions().keySet());
|
||||
}).exceptionally(error -> {
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !dependencyRequirement.meetsRequirements(player, discoveries)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !requirement.meetsRequirements(player)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
@Override
|
||||
public boolean isInRegion(Location location) {
|
||||
return this.getProtectedRegions(location).size() > 0;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredRegion getPrioritisedRegion(Location location) {
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(location);
|
||||
ProtectedRegion highest = null;
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (highest == null) {
|
||||
highest = region;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (region.getPriority() >= highest.getPriority()) {
|
||||
highest = region;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handleMove(PlayerMoveEvent pme) {
|
||||
Player player = pme.getPlayer();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldY = pme.getFrom().getBlockY();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
int x = pme.getTo().getBlockX();
|
||||
int y = pme.getTo().getBlockY();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
Set<ProtectedRegion> oldRegions = this.getProtectedRegions(new Location(player.getWorld(), oldX, oldY, oldZ));
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(new Location(player.getWorld(), x, y, z));
|
||||
|
||||
if (highest == null) return null;
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
||||
}
|
||||
List<String> stringRegions = new ArrayList<>();
|
||||
regions.forEach(region -> {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region.getId());
|
||||
if (configuredRegion != null && configuredRegion.getRequirements() != null) {
|
||||
for (RegionRequirement requirement : configuredRegion.getRequirements()) {
|
||||
if (requirement instanceof DependencyRequirement) {
|
||||
DependencyRequirement dependencyRequirement = (DependencyRequirement) requirement;
|
||||
List<String> discoveries = new ArrayList<>();
|
||||
RPGRegions.getAPI().getManagers().getStorageManager().getAccount(player.getUniqueId()).whenComplete((account, error) -> {
|
||||
discoveries.addAll(account.getDiscoveredRegions().keySet());
|
||||
}).exceptionally(error -> {
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
@Override
|
||||
public boolean exists(World world, String region) {
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(world))
|
||||
.getRegions().containsKey(region);
|
||||
}
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !dependencyRequirement.meetsRequirements(player, discoveries)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!player.hasPermission("rpgregions.bypassentry") && !requirement.meetsRequirements(player)) {
|
||||
requirement.getPreventType().prevent(pme);
|
||||
Translations.CANNOT_ENTER.send(player, requirement.getText(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stringRegions.add(region.getId());
|
||||
});
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(location.getWorld()))
|
||||
.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ()))
|
||||
.getRegions();
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, stringRegions, !oldRegions.equals(regions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredRegion getPrioritisedRegion(Location location) {
|
||||
Set<ProtectedRegion> regions = this.getProtectedRegions(location);
|
||||
ProtectedRegion highest = null;
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (highest == null) {
|
||||
highest = region;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (region.getPriority() >= highest.getPriority()) {
|
||||
highest = region;
|
||||
}
|
||||
}
|
||||
|
||||
if (highest == null) return null;
|
||||
return plugin.getManagers().getRegionsCache().getConfiguredRegion(highest.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(World world, String region) {
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(world))
|
||||
.getRegions().containsKey(region);
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(location.getWorld()))
|
||||
.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ()))
|
||||
.getRegions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@ import net.islandearth.rpgregions.managers.RPGRegionsManagers;
|
||||
|
||||
public interface RPGRegionsAPI {
|
||||
|
||||
/**
|
||||
* Gets the class handling managers.
|
||||
* @return class handling managers
|
||||
*/
|
||||
RPGRegionsManagers getManagers();
|
||||
/**
|
||||
* Gets the class handling managers.
|
||||
* @return class handling managers
|
||||
*/
|
||||
RPGRegionsManagers getManagers();
|
||||
|
||||
/**
|
||||
* Gets the translator provided by Languagy
|
||||
* @return Translator
|
||||
*/
|
||||
Translator getTranslator();
|
||||
/**
|
||||
* Gets the translator provided by Languagy
|
||||
* @return Translator
|
||||
*/
|
||||
Translator getTranslator();
|
||||
}
|
||||
|
||||
@@ -7,26 +7,26 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public interface IntegrationManager {
|
||||
|
||||
/**
|
||||
* Checks if the specified location is within a region.
|
||||
* @param location location to check
|
||||
* @return true if location is within a region, false otherwise
|
||||
*/
|
||||
boolean isInRegion(Location location);
|
||||
/**
|
||||
* Checks if the specified location is within a region.
|
||||
* @param location location to check
|
||||
* @return true if location is within a region, false otherwise
|
||||
*/
|
||||
boolean isInRegion(Location location);
|
||||
|
||||
/**
|
||||
* Handles a move event to perform related region checks.
|
||||
* @param pme PlayerMoveEvent
|
||||
*/
|
||||
void handleMove(PlayerMoveEvent pme);
|
||||
|
||||
/**
|
||||
* Gets the highest priority region at given location
|
||||
* @param location location to check
|
||||
* @return highest prioritised region
|
||||
*/
|
||||
ConfiguredRegion getPrioritisedRegion(Location location);
|
||||
/**
|
||||
* Handles a move event to perform related region checks.
|
||||
* @param pme PlayerMoveEvent
|
||||
*/
|
||||
void handleMove(PlayerMoveEvent pme);
|
||||
|
||||
boolean exists(World location, String region);
|
||||
/**
|
||||
* Gets the highest priority region at given location
|
||||
* @param location location to check
|
||||
* @return highest prioritised region
|
||||
*/
|
||||
ConfiguredRegion getPrioritisedRegion(Location location);
|
||||
|
||||
boolean exists(World location, String region);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,45 +8,45 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum IntegrationType {
|
||||
WORLDGUARD_LEGACY("WorldGuard", "worldguard.WorldGuardLegacyIntegration"),
|
||||
WORLDGUARD("WorldGuard", "worldguard.WorldGuardIntegration"),
|
||||
RESIDENCE("Residence", "residence.ResidenceIntegration"),
|
||||
GRIEFPREVENTION("GriefPrevention", "griefprevention.GriefPreventionIntegration"),
|
||||
ULTRAREGIONS("UltraRegions", "ultraregions.UltraRegionsIntegration");
|
||||
WORLDGUARD_LEGACY("WorldGuard", "worldguard.WorldGuardLegacyIntegration"),
|
||||
WORLDGUARD("WorldGuard", "worldguard.WorldGuardIntegration"),
|
||||
RESIDENCE("Residence", "residence.ResidenceIntegration"),
|
||||
GRIEFPREVENTION("GriefPrevention", "griefprevention.GriefPreventionIntegration"),
|
||||
ULTRAREGIONS("UltraRegions", "ultraregions.UltraRegionsIntegration");
|
||||
|
||||
private final String plugin;
|
||||
private final String path;
|
||||
private final String plugin;
|
||||
private final String path;
|
||||
|
||||
IntegrationType(String plugin, String path) {
|
||||
this.plugin = plugin;
|
||||
this.path = path;
|
||||
}
|
||||
IntegrationType(String plugin, String path) {
|
||||
this.plugin = plugin;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public Optional<IntegrationManager> get() throws ClassNotFoundException {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
if (plugin.getManagers() != null && plugin.getManagers().getIntegrationManager() != null) throw new UnsupportedOperationException("IntegrationManager already loaded");
|
||||
plugin.getLogger().info("Loading IntegrationManager implementation...");
|
||||
if (Bukkit.getPluginManager().getPlugin(this.plugin) == null) {
|
||||
plugin.getLogger().severe("Unable to load IntegrationManager. The requested plugin is not enabled.");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Class<? extends IntegrationManager> clazz = (Class<? extends IntegrationManager>) Class
|
||||
.forName("net.islandearth.rpgregions.api.integrations." + path);
|
||||
IntegrationManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor(RPGRegions.class).newInstance(JavaPlugin.getPlugin(RPGRegions.class));
|
||||
if (generatedClazz instanceof Listener) { // Register events if applicable
|
||||
Bukkit.getPluginManager().registerEvents((Listener) generatedClazz, plugin);
|
||||
}
|
||||
plugin.getLogger().info("Loaded IntegrationManager implementation " + clazz.getName() + ".");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.getLogger().severe("Unable to load IntegrationManager (" + clazz.getName() + ")! Plugin will disable.");
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
public Optional<IntegrationManager> get() throws ClassNotFoundException {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
if (plugin.getManagers() != null && plugin.getManagers().getIntegrationManager() != null) throw new UnsupportedOperationException("IntegrationManager already loaded");
|
||||
plugin.getLogger().info("Loading IntegrationManager implementation...");
|
||||
if (Bukkit.getPluginManager().getPlugin(this.plugin) == null) {
|
||||
plugin.getLogger().severe("Unable to load IntegrationManager. The requested plugin is not enabled.");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(generatedClazz);
|
||||
}
|
||||
Class<? extends IntegrationManager> clazz = (Class<? extends IntegrationManager>) Class
|
||||
.forName("net.islandearth.rpgregions.api.integrations." + path);
|
||||
IntegrationManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor(RPGRegions.class).newInstance(JavaPlugin.getPlugin(RPGRegions.class));
|
||||
if (generatedClazz instanceof Listener) { // Register events if applicable
|
||||
Bukkit.getPluginManager().registerEvents((Listener) generatedClazz, plugin);
|
||||
}
|
||||
plugin.getLogger().info("Loaded IntegrationManager implementation " + clazz.getName() + ".");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.getLogger().severe("Unable to load IntegrationManager (" + clazz.getName() + ")! Plugin will disable.");
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
|
||||
return Optional.ofNullable(generatedClazz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,60 +9,60 @@ import org.bukkit.entity.Player;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PlaceholderRegionHook extends PlaceholderExpansion {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public PlaceholderRegionHook(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return plugin.getDescription().getAuthors().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "rpgregions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String identifier) {
|
||||
if (player == null) return "";
|
||||
|
||||
switch (identifier.toLowerCase()) {
|
||||
case "region":
|
||||
if (plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()) != null)
|
||||
return plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()).getCustomName();
|
||||
else
|
||||
return Translations.UNKNOWN_REGION.get(player);
|
||||
case "discovered_count":
|
||||
// We have to do a blocking operation :(
|
||||
try {
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
return String.valueOf(account.getDiscoveredRegions().size());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
case "region_total":
|
||||
return String.valueOf(plugin.getManagers().getRegionsCache().getConfiguredRegions().size());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public PlaceholderRegionHook(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return plugin.getDescription().getAuthors().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "rpgregions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String identifier) {
|
||||
if (player == null) return "";
|
||||
|
||||
switch (identifier.toLowerCase()) {
|
||||
case "region":
|
||||
if (plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()) != null)
|
||||
return plugin.getManagers().getIntegrationManager().getPrioritisedRegion(player.getLocation()).getCustomName();
|
||||
else
|
||||
return Translations.UNKNOWN_REGION.get(player);
|
||||
case "discovered_count":
|
||||
// We have to do a blocking operation :(
|
||||
try {
|
||||
RPGRegionsAccount account = plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).get();
|
||||
return String.valueOf(account.getDiscoveredRegions().size());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
case "region_total":
|
||||
return String.valueOf(plugin.getManagers().getRegionsCache().getConfiguredRegions().size());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,230 +29,230 @@ import java.util.ArrayList;
|
||||
@CommandAlias("rpgregions")
|
||||
public class RPGRegionsCommand extends BaseCommand {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public RPGRegionsCommand(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public RPGRegionsCommand(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Default
|
||||
public void onDefault(CommandSender sender) {
|
||||
if (sender.hasPermission("rpgregions.noview") && !sender.isOp()) return;
|
||||
@Default
|
||||
public void onDefault(CommandSender sender) {
|
||||
if (sender.hasPermission("rpgregions.noview") && !sender.isOp()) return;
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Wiki > " + plugin.getDescription().getWebsite());
|
||||
sender.sendMessage(ChatColor.YELLOW + "Bugs > https://gitlab.com/SamB440/rpgregions-2");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Discord > https://discord.gg/fh62mxU");
|
||||
int rewards = 0;
|
||||
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
|
||||
rewards += configuredRegion.getRewards().size();
|
||||
}
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" +
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().size()
|
||||
+ " regions are loaded with " + rewards + " rewards.");
|
||||
}
|
||||
sender.sendMessage(ChatColor.YELLOW + "Wiki > " + plugin.getDescription().getWebsite());
|
||||
sender.sendMessage(ChatColor.YELLOW + "Bugs > https://gitlab.com/SamB440/rpgregions-2");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Discord > https://discord.gg/fh62mxU");
|
||||
int rewards = 0;
|
||||
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
|
||||
rewards += configuredRegion.getRewards().size();
|
||||
}
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" +
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().size()
|
||||
+ " regions are loaded with " + rewards + " rewards.");
|
||||
}
|
||||
|
||||
@Subcommand("about")
|
||||
public void onAbout(CommandSender sender) {
|
||||
sender.sendMessage(StringUtils.colour("&eRPGRegions v" + plugin.getDescription().getVersion() + "."));
|
||||
sender.sendMessage(StringUtils.colour("&eOwner: https://www.spigotmc.org/members/%%__USER__%%/"));
|
||||
sender.sendMessage(StringUtils.colour("&eStorage: " + plugin.getManagers().getStorageManager().getClass().getName()));
|
||||
sender.sendMessage(StringUtils.colour("&eIntegration: " + plugin.getManagers().getIntegrationManager().getClass().getName()));
|
||||
}
|
||||
@Subcommand("about")
|
||||
public void onAbout(CommandSender sender) {
|
||||
sender.sendMessage(StringUtils.colour("&eRPGRegions v" + plugin.getDescription().getVersion() + "."));
|
||||
sender.sendMessage(StringUtils.colour("&eOwner: https://www.spigotmc.org/members/%%__USER__%%/"));
|
||||
sender.sendMessage(StringUtils.colour("&eStorage: " + plugin.getManagers().getStorageManager().getClass().getName()));
|
||||
sender.sendMessage(StringUtils.colour("&eIntegration: " + plugin.getManagers().getIntegrationManager().getClass().getName()));
|
||||
}
|
||||
|
||||
@Subcommand("add")
|
||||
@CommandPermission("rpgregions.add")
|
||||
@CommandCompletion("@regions")
|
||||
public void onAdd(Player player, String region) {
|
||||
if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) {
|
||||
player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin."));
|
||||
return;
|
||||
}
|
||||
@Subcommand("add")
|
||||
@CommandPermission("rpgregions.add")
|
||||
@CommandCompletion("@regions")
|
||||
public void onAdd(Player player, String region) {
|
||||
if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) {
|
||||
player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin."));
|
||||
return;
|
||||
}
|
||||
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(player.getWorld(), region, region, new ArrayList<>(),
|
||||
new ArrayList<>());
|
||||
configuredRegion.setLocation(player.getLocation());
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
||||
player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
|
||||
player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
|
||||
+ region
|
||||
+ " to edit it!"));
|
||||
player.sendMessage(StringUtils.colour("&e&oUse /rpgregions save to save this to file for editing."));
|
||||
}
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(player.getWorld(), region, region, new ArrayList<>(),
|
||||
new ArrayList<>());
|
||||
configuredRegion.setLocation(player.getLocation());
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
||||
player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
|
||||
player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
|
||||
+ region
|
||||
+ " to edit it!"));
|
||||
player.sendMessage(StringUtils.colour("&e&oUse /rpgregions save to save this to file for editing."));
|
||||
}
|
||||
|
||||
@Subcommand("remove")
|
||||
@CommandPermission("rpgregions.remove")
|
||||
@CommandCompletion("@regions")
|
||||
public void onRemove(CommandSender sender, ConfiguredRegion configuredRegion) {
|
||||
if (configuredRegion != null) {
|
||||
try {
|
||||
configuredRegion.delete(plugin);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
plugin.getManagers().getRegionsCache().removeConfiguredRegion(configuredRegion.getId());
|
||||
sender.sendMessage(StringUtils.colour("&cRemoved configured region " + configuredRegion.getId() + "!"));
|
||||
} else {
|
||||
sender.sendMessage(StringUtils.colour("&cA region by that name is not yet configured."));
|
||||
}
|
||||
}
|
||||
@Subcommand("remove")
|
||||
@CommandPermission("rpgregions.remove")
|
||||
@CommandCompletion("@regions")
|
||||
public void onRemove(CommandSender sender, ConfiguredRegion configuredRegion) {
|
||||
if (configuredRegion != null) {
|
||||
try {
|
||||
configuredRegion.delete(plugin);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
plugin.getManagers().getRegionsCache().removeConfiguredRegion(configuredRegion.getId());
|
||||
sender.sendMessage(StringUtils.colour("&cRemoved configured region " + configuredRegion.getId() + "!"));
|
||||
} else {
|
||||
sender.sendMessage(StringUtils.colour("&cA region by that name is not yet configured."));
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("edit")
|
||||
@CommandPermission("rpgregions.edit")
|
||||
@CommandCompletion("@regions")
|
||||
public void onEdit(Player player, ConfiguredRegion configuredRegion) {
|
||||
new EditorGUI(plugin, player, configuredRegion).open();
|
||||
player.sendMessage(ChatColor.YELLOW + "This feature is currently being worked on!");
|
||||
}
|
||||
@Subcommand("edit")
|
||||
@CommandPermission("rpgregions.edit")
|
||||
@CommandCompletion("@regions")
|
||||
public void onEdit(Player player, ConfiguredRegion configuredRegion) {
|
||||
new EditorGUI(plugin, player, configuredRegion).open();
|
||||
player.sendMessage(ChatColor.YELLOW + "This feature is currently being worked on!");
|
||||
}
|
||||
|
||||
@Subcommand("list|discoveries")
|
||||
@CommandPermission("rpgregions.list")
|
||||
public void onList(Player player) {
|
||||
new DiscoveryGUI(plugin, player).open();
|
||||
}
|
||||
@Subcommand("list|discoveries")
|
||||
@CommandPermission("rpgregions.list")
|
||||
public void onList(Player player) {
|
||||
new DiscoveryGUI(plugin, player).open();
|
||||
}
|
||||
|
||||
@Subcommand("additem")
|
||||
@CommandPermission("rpgregions.additem")
|
||||
@CommandCompletion("@regions")
|
||||
public void onAddItem(Player player, ConfiguredRegion configuredRegion) {
|
||||
if (configuredRegion != null) {
|
||||
configuredRegion.getRewards().add(new ItemReward(player.getInventory().getItemInMainHand()));
|
||||
player.sendMessage(ChatColor.GREEN + "Item added to configuration!");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "No region exists by that name.");
|
||||
}
|
||||
}
|
||||
@Subcommand("additem")
|
||||
@CommandPermission("rpgregions.additem")
|
||||
@CommandCompletion("@regions")
|
||||
public void onAddItem(Player player, ConfiguredRegion configuredRegion) {
|
||||
if (configuredRegion != null) {
|
||||
configuredRegion.getRewards().add(new ItemReward(player.getInventory().getItemInMainHand()));
|
||||
player.sendMessage(ChatColor.GREEN + "Item added to configuration!");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "No region exists by that name.");
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("reload")
|
||||
@CommandPermission("rpgregions.reload")
|
||||
public void onReload(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Reloading region files...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().clear();
|
||||
@Subcommand("reload")
|
||||
@CommandPermission("rpgregions.reload")
|
||||
public void onReload(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Reloading region files...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().clear();
|
||||
|
||||
for (File file : folder.listFiles()) {
|
||||
// Exclude non-json files
|
||||
if (file.getName().endsWith(".json")) {
|
||||
try {
|
||||
Reader reader = new FileReader(file);
|
||||
ConfiguredRegion region = plugin.getGson().fromJson(reader, ConfiguredRegion.class);
|
||||
if (!region.getId().equals("exampleconfig")) plugin.getManagers().getRegionsCache().addConfiguredRegion(region);
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Error loading region config " + file.getName() + ":");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (File file : folder.listFiles()) {
|
||||
// Exclude non-json files
|
||||
if (file.getName().endsWith(".json")) {
|
||||
try {
|
||||
Reader reader = new FileReader(file);
|
||||
ConfiguredRegion region = plugin.getGson().fromJson(reader, ConfiguredRegion.class);
|
||||
if (!region.getId().equals("exampleconfig")) plugin.getManagers().getRegionsCache().addConfiguredRegion(region);
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Error loading region config " + file.getName() + ":");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.reloadConfig();
|
||||
plugin.getManagers().getRegenerationManager().reload(plugin);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
}
|
||||
plugin.reloadConfig();
|
||||
plugin.getManagers().getRegenerationManager().reload(plugin);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
}
|
||||
|
||||
@Subcommand("save")
|
||||
@CommandPermission("rpgregions.save")
|
||||
public void onSave(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Saving data...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
@Subcommand("save")
|
||||
@CommandPermission("rpgregions.save")
|
||||
public void onSave(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Saving data...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// Save all player data (quit event not called for shutdown)
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (plugin.getManagers().getStorageManager().getCachedAccounts().containsKey(player.getUniqueId()))
|
||||
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
});
|
||||
// Save all player data (quit event not called for shutdown)
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (plugin.getManagers().getStorageManager().getCachedAccounts().containsKey(player.getUniqueId()))
|
||||
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
});
|
||||
|
||||
// Save all region configs
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().forEach((id, region) -> {
|
||||
try {
|
||||
region.save(plugin);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
// Save all region configs
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().forEach((id, region) -> {
|
||||
try {
|
||||
region.save(plugin);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
}
|
||||
|
||||
@Subcommand("reset")
|
||||
@CommandPermission("rpgregions.reset")
|
||||
@CommandCompletion("@players @regions")
|
||||
public void onReset(CommandSender sender, String[] args) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
if (player.hasPlayedBefore()) {
|
||||
plugin.getManagers().getStorageManager().clearDiscoveries(player.getUniqueId());
|
||||
if (!player.isOnline()) plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Players discoveries has been cleared.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
if (player.hasPlayedBefore()) {
|
||||
String regionId = args[1];
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(regionId)) {
|
||||
plugin.getManagers().getStorageManager().clearDiscovery(player.getUniqueId(), regionId);
|
||||
if (!player.isOnline()) plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Discovery cleared.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Region does not exist or is not configured.");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /rpgregions reset <player> [region_id]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("delete")
|
||||
@CommandPermission("rpgregions.delete")
|
||||
@CommandCompletion("@players")
|
||||
public void onDelete(CommandSender sender, Player player) {
|
||||
if (player != null) {
|
||||
plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("setlocation")
|
||||
@CommandPermission("rpgregions.setlocation")
|
||||
@CommandCompletion("@regions")
|
||||
public void onSetLocation(Player player, ConfiguredRegion configuredRegion) {
|
||||
if (configuredRegion != null) {
|
||||
Location location = player.getLocation();
|
||||
configuredRegion.setLocation(location);
|
||||
player.sendMessage(ChatColor.GREEN + "Location has been updated.");
|
||||
} else {
|
||||
player.sendMessage(StringUtils.colour("&cA region by that name is not yet configured."));
|
||||
}
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
}
|
||||
|
||||
@Subcommand("regenerate|regen")
|
||||
@CommandPermission("rpgregions.regenerate")
|
||||
@CommandCompletion("@regions")
|
||||
public void onRegenerate(CommandSender sender, ConfiguredRegion configuredRegion) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Regenerating region...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
boolean done = RegenUtils.regenerate(configuredRegion);
|
||||
if (!done) {
|
||||
sender.sendMessage(ChatColor.RED + "Unable to regenerate region. Check console for details.");
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
}
|
||||
@Subcommand("reset")
|
||||
@CommandPermission("rpgregions.reset")
|
||||
@CommandCompletion("@players @regions")
|
||||
public void onReset(CommandSender sender, String[] args) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
if (player.hasPlayedBefore()) {
|
||||
plugin.getManagers().getStorageManager().clearDiscoveries(player.getUniqueId());
|
||||
if (!player.isOnline()) plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Players discoveries has been cleared.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
if (player.hasPlayedBefore()) {
|
||||
String regionId = args[1];
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(regionId)) {
|
||||
plugin.getManagers().getStorageManager().clearDiscovery(player.getUniqueId(), regionId);
|
||||
if (!player.isOnline()) plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
sender.sendMessage(ChatColor.GREEN + "Discovery cleared.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Region does not exist or is not configured.");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /rpgregions reset <player> [region_id]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("delete")
|
||||
@CommandPermission("rpgregions.delete")
|
||||
@CommandCompletion("@players")
|
||||
public void onDelete(CommandSender sender, Player player) {
|
||||
if (player != null) {
|
||||
plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "That player cannot be found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("setlocation")
|
||||
@CommandPermission("rpgregions.setlocation")
|
||||
@CommandCompletion("@regions")
|
||||
public void onSetLocation(Player player, ConfiguredRegion configuredRegion) {
|
||||
if (configuredRegion != null) {
|
||||
Location location = player.getLocation();
|
||||
configuredRegion.setLocation(location);
|
||||
player.sendMessage(ChatColor.GREEN + "Location has been updated.");
|
||||
} else {
|
||||
player.sendMessage(StringUtils.colour("&cA region by that name is not yet configured."));
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("regenerate|regen")
|
||||
@CommandPermission("rpgregions.regenerate")
|
||||
@CommandCompletion("@regions")
|
||||
public void onRegenerate(CommandSender sender, ConfiguredRegion configuredRegion) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Regenerating region...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
boolean done = RegenUtils.regenerate(configuredRegion);
|
||||
if (!done) {
|
||||
sender.sendMessage(ChatColor.RED + "Unable to regenerate region. Check console for details.");
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
sender.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,276 +26,276 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
|
||||
private final Gui gui;
|
||||
|
||||
public DiscoveryGUI(RPGRegions plugin, Player player) {
|
||||
super(plugin, player);
|
||||
this.gui = new Gui(plugin, plugin.getConfig().getInt("settings.server.gui.general.rows"), Translations.REGIONS.get(player));
|
||||
gui.setOnGlobalClick(click -> click.setCancelled(true));
|
||||
// I wish there was a cleaner way to do this :(
|
||||
int backX = plugin.getConfig().getInt("settings.server.gui.back.posX");
|
||||
int backY = plugin.getConfig().getInt("settings.server.gui.back.posY");
|
||||
int backL = plugin.getConfig().getInt("settings.server.gui.back.length");
|
||||
int backH = plugin.getConfig().getInt("settings.server.gui.back.height");
|
||||
int forwardX = plugin.getConfig().getInt("settings.server.gui.forward.posX");
|
||||
int forwardY = plugin.getConfig().getInt("settings.server.gui.forward.posY");
|
||||
int forwardL = plugin.getConfig().getInt("settings.server.gui.forward.length");
|
||||
int forwardH = plugin.getConfig().getInt("settings.server.gui.forward.height");
|
||||
int exitX = plugin.getConfig().getInt("settings.server.gui.exit.posX");
|
||||
int exitY = plugin.getConfig().getInt("settings.server.gui.exit.posY");
|
||||
int exitL = plugin.getConfig().getInt("settings.server.gui.exit.length");
|
||||
int exitH = plugin.getConfig().getInt("settings.server.gui.exit.height");
|
||||
int paneX = plugin.getConfig().getInt("settings.server.gui.pane.posX");
|
||||
int paneY = plugin.getConfig().getInt("settings.server.gui.pane.posY");
|
||||
int paneL = plugin.getConfig().getInt("settings.server.gui.pane.length");
|
||||
int paneH = plugin.getConfig().getInt("settings.server.gui.pane.height");
|
||||
int oPaneX = plugin.getConfig().getInt("settings.server.gui.outlinePane.posX");
|
||||
int oPaneY = plugin.getConfig().getInt("settings.server.gui.outlinePane.posY");
|
||||
int oPaneL = plugin.getConfig().getInt("settings.server.gui.outlinePane.length");
|
||||
int oPaneH = plugin.getConfig().getInt("settings.server.gui.outlinePane.height");
|
||||
int iPaneX = plugin.getConfig().getInt("settings.server.gui.innerPane.posX");
|
||||
int iPaneY = plugin.getConfig().getInt("settings.server.gui.innerPane.posY");
|
||||
int iPaneL = plugin.getConfig().getInt("settings.server.gui.innerPane.length");
|
||||
int iPaneH = plugin.getConfig().getInt("settings.server.gui.innerPane.height");
|
||||
PaginatedPane pane = new PaginatedPane(paneX, paneY, paneL, paneH);
|
||||
OutlinePane oPane = new OutlinePane(oPaneX, oPaneY, oPaneL, oPaneH);
|
||||
OutlinePane innerPane = new OutlinePane(iPaneX, iPaneY, iPaneL, iPaneH);
|
||||
StaticPane back = new StaticPane(backX, backY, backL, backH);
|
||||
StaticPane forward = new StaticPane(forwardX, forwardY, forwardL, forwardH);
|
||||
StaticPane exit = new StaticPane(exitX, exitY, exitL, exitH);
|
||||
|
||||
// Inner pane
|
||||
if (plugin.getConfig().getBoolean("settings.server.gui.innerPane.show")) {
|
||||
innerPane.setRepeat(true);
|
||||
List<String> mask = plugin.getConfig().getStringList("settings.server.gui.innerPane.mask");
|
||||
innerPane.applyMask(new Mask(mask.toArray(new String[]{})));
|
||||
innerPane.setOnClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));
|
||||
private final Gui gui;
|
||||
|
||||
innerPane.addItem(new GuiItem(new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.innerPane.innerPane")).get().parseItem(true))
|
||||
.withName(" ")
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()));
|
||||
public DiscoveryGUI(RPGRegions plugin, Player player) {
|
||||
super(plugin, player);
|
||||
this.gui = new Gui(plugin, plugin.getConfig().getInt("settings.server.gui.general.rows"), Translations.REGIONS.get(player));
|
||||
gui.setOnGlobalClick(click -> click.setCancelled(true));
|
||||
// I wish there was a cleaner way to do this :(
|
||||
int backX = plugin.getConfig().getInt("settings.server.gui.back.posX");
|
||||
int backY = plugin.getConfig().getInt("settings.server.gui.back.posY");
|
||||
int backL = plugin.getConfig().getInt("settings.server.gui.back.length");
|
||||
int backH = plugin.getConfig().getInt("settings.server.gui.back.height");
|
||||
int forwardX = plugin.getConfig().getInt("settings.server.gui.forward.posX");
|
||||
int forwardY = plugin.getConfig().getInt("settings.server.gui.forward.posY");
|
||||
int forwardL = plugin.getConfig().getInt("settings.server.gui.forward.length");
|
||||
int forwardH = plugin.getConfig().getInt("settings.server.gui.forward.height");
|
||||
int exitX = plugin.getConfig().getInt("settings.server.gui.exit.posX");
|
||||
int exitY = plugin.getConfig().getInt("settings.server.gui.exit.posY");
|
||||
int exitL = plugin.getConfig().getInt("settings.server.gui.exit.length");
|
||||
int exitH = plugin.getConfig().getInt("settings.server.gui.exit.height");
|
||||
int paneX = plugin.getConfig().getInt("settings.server.gui.pane.posX");
|
||||
int paneY = plugin.getConfig().getInt("settings.server.gui.pane.posY");
|
||||
int paneL = plugin.getConfig().getInt("settings.server.gui.pane.length");
|
||||
int paneH = plugin.getConfig().getInt("settings.server.gui.pane.height");
|
||||
int oPaneX = plugin.getConfig().getInt("settings.server.gui.outlinePane.posX");
|
||||
int oPaneY = plugin.getConfig().getInt("settings.server.gui.outlinePane.posY");
|
||||
int oPaneL = plugin.getConfig().getInt("settings.server.gui.outlinePane.length");
|
||||
int oPaneH = plugin.getConfig().getInt("settings.server.gui.outlinePane.height");
|
||||
int iPaneX = plugin.getConfig().getInt("settings.server.gui.innerPane.posX");
|
||||
int iPaneY = plugin.getConfig().getInt("settings.server.gui.innerPane.posY");
|
||||
int iPaneL = plugin.getConfig().getInt("settings.server.gui.innerPane.length");
|
||||
int iPaneH = plugin.getConfig().getInt("settings.server.gui.innerPane.height");
|
||||
PaginatedPane pane = new PaginatedPane(paneX, paneY, paneL, paneH);
|
||||
OutlinePane oPane = new OutlinePane(oPaneX, oPaneY, oPaneL, oPaneH);
|
||||
OutlinePane innerPane = new OutlinePane(iPaneX, iPaneY, iPaneL, iPaneH);
|
||||
StaticPane back = new StaticPane(backX, backY, backL, backH);
|
||||
StaticPane forward = new StaticPane(forwardX, forwardY, forwardL, forwardH);
|
||||
StaticPane exit = new StaticPane(exitX, exitY, exitL, exitH);
|
||||
|
||||
gui.addPane(innerPane);
|
||||
}
|
||||
// Inner pane
|
||||
if (plugin.getConfig().getBoolean("settings.server.gui.innerPane.show")) {
|
||||
innerPane.setRepeat(true);
|
||||
List<String> mask = plugin.getConfig().getStringList("settings.server.gui.innerPane.mask");
|
||||
innerPane.applyMask(new Mask(mask.toArray(new String[]{})));
|
||||
innerPane.setOnClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));
|
||||
|
||||
// Outline pane
|
||||
if (plugin.getConfig().getBoolean("settings.server.gui.outlinePane.show")) {
|
||||
oPane.setRepeat(true);
|
||||
List<String> mask = plugin.getConfig().getStringList("settings.server.gui.outlinePane.mask");
|
||||
oPane.applyMask(new Mask(mask.toArray(new String[]{})));
|
||||
oPane.setOnClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));
|
||||
innerPane.addItem(new GuiItem(new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.innerPane.innerPane")).get().parseItem(true))
|
||||
.withName(" ")
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()));
|
||||
|
||||
oPane.addItem(new GuiItem(new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.outlinePane.outlinePane")).get().parseItem(true))
|
||||
.withName(" ")
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()));
|
||||
gui.addPane(innerPane);
|
||||
}
|
||||
|
||||
gui.addPane(oPane);
|
||||
}
|
||||
// Outline pane
|
||||
if (plugin.getConfig().getBoolean("settings.server.gui.outlinePane.show")) {
|
||||
oPane.setRepeat(true);
|
||||
List<String> mask = plugin.getConfig().getStringList("settings.server.gui.outlinePane.mask");
|
||||
oPane.applyMask(new Mask(mask.toArray(new String[]{})));
|
||||
oPane.setOnClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));
|
||||
|
||||
// Back item
|
||||
String bm = plugin.getConfig().getString("settings.server.gui.back.back");
|
||||
ItemStack backItem = bm.startsWith("hdb-") && plugin.hasHeadDatabase()
|
||||
?
|
||||
new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(bm.replace("hdb-", "")))
|
||||
.withName(Translations.PREVIOUS_PAGE.get(player))
|
||||
.withLore(Translations.PREVIOUS_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.back.back")).get().parseItem(true))
|
||||
.withName(Translations.PREVIOUS_PAGE.get(player))
|
||||
.withLore(Translations.PREVIOUS_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build();
|
||||
oPane.addItem(new GuiItem(new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.outlinePane.outlinePane")).get().parseItem(true))
|
||||
.withName(" ")
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()));
|
||||
|
||||
back.addItem(new GuiItem(backItem, event -> {
|
||||
event.setCancelled(true);
|
||||
if (pane.getPages() == 0 || pane.getPages() == 1) return;
|
||||
|
||||
pane.setPage(pane.getPage() - 1);
|
||||
|
||||
forward.setVisible(true);
|
||||
gui.update();
|
||||
}), 0, 0);
|
||||
gui.addPane(oPane);
|
||||
}
|
||||
|
||||
// Forward item
|
||||
String fm = plugin.getConfig().getString("settings.server.gui.forward.forward");
|
||||
ItemStack forwardItem = fm.startsWith("hdb-") && plugin.hasHeadDatabase()
|
||||
?
|
||||
new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(fm.replace("hdb-", "")))
|
||||
.withName(Translations.NEXT_PAGE.get(player))
|
||||
.withLore(Translations.NEXT_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.forward.forward")).get().parseItem(true))
|
||||
.withName(Translations.NEXT_PAGE.get(player))
|
||||
.withLore(Translations.NEXT_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build();
|
||||
// Back item
|
||||
String bm = plugin.getConfig().getString("settings.server.gui.back.back");
|
||||
ItemStack backItem = bm.startsWith("hdb-") && plugin.hasHeadDatabase()
|
||||
?
|
||||
new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(bm.replace("hdb-", "")))
|
||||
.withName(Translations.PREVIOUS_PAGE.get(player))
|
||||
.withLore(Translations.PREVIOUS_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.back.back")).get().parseItem(true))
|
||||
.withName(Translations.PREVIOUS_PAGE.get(player))
|
||||
.withLore(Translations.PREVIOUS_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build();
|
||||
|
||||
forward.addItem(new GuiItem(forwardItem, event -> {
|
||||
event.setCancelled(true);
|
||||
if (pane.getPages() == 0 || pane.getPages() == 1) return;
|
||||
|
||||
pane.setPage(pane.getPage() + 1);
|
||||
|
||||
back.setVisible(true);
|
||||
gui.update();
|
||||
}), 0, 0);
|
||||
back.addItem(new GuiItem(backItem, event -> {
|
||||
event.setCancelled(true);
|
||||
if (pane.getPages() == 0 || pane.getPages() == 1) return;
|
||||
|
||||
// Exit item
|
||||
if (plugin.getConfig().getBoolean("settings.server.gui.exit.show")) {
|
||||
String em = plugin.getConfig().getString("settings.server.gui.exit.exit");
|
||||
ItemStack item = em.startsWith("hdb-") && plugin.hasHeadDatabase()
|
||||
?
|
||||
new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(em.replace("hdb-", "")))
|
||||
.withName(Translations.EXIT.get(player))
|
||||
.withLore(Translations.EXIT_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.exit.exit")).get().parseItem(true))
|
||||
.withName(Translations.EXIT.get(player))
|
||||
.withLore(Translations.EXIT_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build();
|
||||
exit.addItem(new GuiItem(item, event -> {
|
||||
event.setCancelled(true);
|
||||
gui.update();
|
||||
player.closeInventory();
|
||||
String command = plugin.getConfig().getString("settings.server.gui.exit.command");
|
||||
if (!command.isEmpty()) player.performCommand(command
|
||||
.replace("%player%", player.getName()));
|
||||
}), 0, 0);
|
||||
pane.setPage(pane.getPage() - 1);
|
||||
|
||||
gui.addPane(exit);
|
||||
}
|
||||
forward.setVisible(true);
|
||||
gui.update();
|
||||
}), 0, 0);
|
||||
|
||||
gui.addPane(back);
|
||||
gui.addPane(forward);
|
||||
|
||||
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
|
||||
List<GuiItem> items = new ArrayList<>();
|
||||
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
|
||||
boolean hasDiscovered = account.getDiscoveredRegions().containsKey(configuredRegion.getId());
|
||||
if (!hasDiscovered && !player.hasPermission("rpgregions.show")) continue;
|
||||
if (configuredRegion.isHidden()) continue;
|
||||
// Forward item
|
||||
String fm = plugin.getConfig().getString("settings.server.gui.forward.forward");
|
||||
ItemStack forwardItem = fm.startsWith("hdb-") && plugin.hasHeadDatabase()
|
||||
?
|
||||
new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(fm.replace("hdb-", "")))
|
||||
.withName(Translations.NEXT_PAGE.get(player))
|
||||
.withLore(Translations.NEXT_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.forward.forward")).get().parseItem(true))
|
||||
.withName(Translations.NEXT_PAGE.get(player))
|
||||
.withLore(Translations.NEXT_PAGE_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build();
|
||||
|
||||
ChatColor colour = hasDiscovered
|
||||
? ChatColor.GREEN
|
||||
: ChatColor.RED;
|
||||
String lore = account.getDiscoveredRegions().containsKey(configuredRegion.getId())
|
||||
? Translations.DISCOVERED_ON.get(player,
|
||||
account.getDiscoveredRegions().get(configuredRegion.getId()).getDate())
|
||||
: null;
|
||||
String lore2 = configuredRegion.isShowCoords()
|
||||
&& player.hasPermission("rpgregions.showloc")
|
||||
? ChatColor.GRAY + "" + configuredRegion.getLocation().getBlockX() + ", " + configuredRegion.getLocation().getBlockZ()
|
||||
: null;
|
||||
List<String> translatedHint = new ArrayList<>();
|
||||
if (configuredRegion.getHints() != null) {
|
||||
configuredRegion.getHints().forEach(hint -> translatedHint.add(StringUtils.colour(hint)));
|
||||
}
|
||||
forward.addItem(new GuiItem(forwardItem, event -> {
|
||||
event.setCancelled(true);
|
||||
if (pane.getPages() == 0 || pane.getPages() == 1) return;
|
||||
|
||||
List<String> hint = configuredRegion.isShowHint()
|
||||
&& player.hasPermission("rpgregions.showhint." + configuredRegion.getId()) || player.hasPermission("rpgregions.showhint.*")
|
||||
&& !hasDiscovered
|
||||
? translatedHint
|
||||
: null;
|
||||
String teleport = configuredRegion.isTeleportable()
|
||||
&& player.hasPermission("rpgregions.teleport")
|
||||
&& hasDiscovered
|
||||
? Translations.TELEPORT.get(player)
|
||||
: null;
|
||||
pane.setPage(pane.getPage() + 1);
|
||||
|
||||
List<String> translatedDiscoveredLore = new ArrayList<>();
|
||||
if (configuredRegion.getDiscoveredLore() != null) {
|
||||
configuredRegion.getDiscoveredLore().forEach(discoveredLore -> translatedDiscoveredLore.add(StringUtils.colour(discoveredLore)));
|
||||
}
|
||||
ItemStack item = hasDiscovered
|
||||
?
|
||||
new ItemStackBuilder(configuredRegion.getIcon())
|
||||
.withLore(translatedDiscoveredLore)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(configuredRegion.getUndiscoveredIcon())
|
||||
.build();
|
||||
back.setVisible(true);
|
||||
gui.update();
|
||||
}), 0, 0);
|
||||
|
||||
items.add(new GuiItem(new ItemStackBuilder(item)
|
||||
.withName(colour + configuredRegion.getCustomName())
|
||||
.withLore(lore)
|
||||
.withLore(lore2)
|
||||
.withLore(hint)
|
||||
.withLore(" ")
|
||||
.withLore(teleport)
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build(),
|
||||
event -> {
|
||||
event.setCancelled(true);
|
||||
if (configuredRegion.isTeleportable()
|
||||
&& player.hasPermission("rpgregions.teleport")
|
||||
&& hasDiscovered) {
|
||||
if (!account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.TELEPORT)) {
|
||||
if (configuredRegion.getWorld() == null) {
|
||||
Translations.CANNOT_TELEPORT.send(player);
|
||||
} else {
|
||||
if (configuredRegion.getLocation() != null) PaperLib.teleportAsync(player, configuredRegion.getLocation());
|
||||
else player.sendMessage(ChatColor.RED + "Unable to find teleport location.");
|
||||
if (configuredRegion.getTeleportCooldown() != 0) {
|
||||
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.TELEPORT);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT), configuredRegion.getTeleportCooldown());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Translations.COOLDOWN.send(player);
|
||||
}
|
||||
}
|
||||
// Exit item
|
||||
if (plugin.getConfig().getBoolean("settings.server.gui.exit.show")) {
|
||||
String em = plugin.getConfig().getString("settings.server.gui.exit.exit");
|
||||
ItemStack item = em.startsWith("hdb-") && plugin.hasHeadDatabase()
|
||||
?
|
||||
new ItemStackBuilder(new HeadDatabaseAPI().getItemHead(em.replace("hdb-", "")))
|
||||
.withName(Translations.EXIT.get(player))
|
||||
.withLore(Translations.EXIT_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(XMaterial.matchXMaterial(
|
||||
plugin.getConfig().getString("settings.server.gui.exit.exit")).get().parseItem(true))
|
||||
.withName(Translations.EXIT.get(player))
|
||||
.withLore(Translations.EXIT_LORE.getList(player))
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build();
|
||||
exit.addItem(new GuiItem(item, event -> {
|
||||
event.setCancelled(true);
|
||||
gui.update();
|
||||
player.closeInventory();
|
||||
String command = plugin.getConfig().getString("settings.server.gui.exit.command");
|
||||
if (!command.isEmpty()) player.performCommand(command
|
||||
.replace("%player%", player.getName()));
|
||||
}), 0, 0);
|
||||
|
||||
if (!configuredRegion.getIconCommand().isEmpty()) {
|
||||
configuredRegion.getIconCommand().forEach(iconCommand -> {
|
||||
if (iconCommand.getClickType() != IconCommand.CommandClickType.DISCOVERED && hasDiscovered
|
||||
|| iconCommand.getClickType() != IconCommand.CommandClickType.UNDISCOVERED && !hasDiscovered) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.ICON_COMMAND)) {
|
||||
Translations.COOLDOWN.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.performCommand(iconCommand.getCommand()
|
||||
.replace("%region%", configuredRegion.getId())
|
||||
.replace("%player%", player.getName()));
|
||||
|
||||
if (iconCommand.getCooldown() != 0) {
|
||||
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.ICON_COMMAND), iconCommand.getCooldown());
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
gui.addPane(exit);
|
||||
}
|
||||
|
||||
pane.populateWithGuiItems(items);
|
||||
gui.addPane(pane);
|
||||
}).exceptionally(error -> {
|
||||
plugin.getLogger().warning("There was an error whilst listing regions");
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
gui.show(getPlayer());
|
||||
}
|
||||
gui.addPane(back);
|
||||
gui.addPane(forward);
|
||||
|
||||
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
|
||||
List<GuiItem> items = new ArrayList<>();
|
||||
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
|
||||
boolean hasDiscovered = account.getDiscoveredRegions().containsKey(configuredRegion.getId());
|
||||
if (!hasDiscovered && !player.hasPermission("rpgregions.show")) continue;
|
||||
if (configuredRegion.isHidden()) continue;
|
||||
|
||||
ChatColor colour = hasDiscovered
|
||||
? ChatColor.GREEN
|
||||
: ChatColor.RED;
|
||||
String lore = account.getDiscoveredRegions().containsKey(configuredRegion.getId())
|
||||
? Translations.DISCOVERED_ON.get(player,
|
||||
account.getDiscoveredRegions().get(configuredRegion.getId()).getDate())
|
||||
: null;
|
||||
String lore2 = configuredRegion.isShowCoords()
|
||||
&& player.hasPermission("rpgregions.showloc")
|
||||
? ChatColor.GRAY + "" + configuredRegion.getLocation().getBlockX() + ", " + configuredRegion.getLocation().getBlockZ()
|
||||
: null;
|
||||
List<String> translatedHint = new ArrayList<>();
|
||||
if (configuredRegion.getHints() != null) {
|
||||
configuredRegion.getHints().forEach(hint -> translatedHint.add(StringUtils.colour(hint)));
|
||||
}
|
||||
|
||||
List<String> hint = configuredRegion.isShowHint()
|
||||
&& player.hasPermission("rpgregions.showhint." + configuredRegion.getId()) || player.hasPermission("rpgregions.showhint.*")
|
||||
&& !hasDiscovered
|
||||
? translatedHint
|
||||
: null;
|
||||
String teleport = configuredRegion.isTeleportable()
|
||||
&& player.hasPermission("rpgregions.teleport")
|
||||
&& hasDiscovered
|
||||
? Translations.TELEPORT.get(player)
|
||||
: null;
|
||||
|
||||
List<String> translatedDiscoveredLore = new ArrayList<>();
|
||||
if (configuredRegion.getDiscoveredLore() != null) {
|
||||
configuredRegion.getDiscoveredLore().forEach(discoveredLore -> translatedDiscoveredLore.add(StringUtils.colour(discoveredLore)));
|
||||
}
|
||||
ItemStack item = hasDiscovered
|
||||
?
|
||||
new ItemStackBuilder(configuredRegion.getIcon())
|
||||
.withLore(translatedDiscoveredLore)
|
||||
.build()
|
||||
:
|
||||
new ItemStackBuilder(configuredRegion.getUndiscoveredIcon())
|
||||
.build();
|
||||
|
||||
items.add(new GuiItem(new ItemStackBuilder(item)
|
||||
.withName(colour + configuredRegion.getCustomName())
|
||||
.withLore(lore)
|
||||
.withLore(lore2)
|
||||
.withLore(hint)
|
||||
.withLore(" ")
|
||||
.withLore(teleport)
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build(),
|
||||
event -> {
|
||||
event.setCancelled(true);
|
||||
if (configuredRegion.isTeleportable()
|
||||
&& player.hasPermission("rpgregions.teleport")
|
||||
&& hasDiscovered) {
|
||||
if (!account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.TELEPORT)) {
|
||||
if (configuredRegion.getWorld() == null) {
|
||||
Translations.CANNOT_TELEPORT.send(player);
|
||||
} else {
|
||||
if (configuredRegion.getLocation() != null) PaperLib.teleportAsync(player, configuredRegion.getLocation());
|
||||
else player.sendMessage(ChatColor.RED + "Unable to find teleport location.");
|
||||
if (configuredRegion.getTeleportCooldown() != 0) {
|
||||
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.TELEPORT);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT), configuredRegion.getTeleportCooldown());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Translations.COOLDOWN.send(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!configuredRegion.getIconCommand().isEmpty()) {
|
||||
configuredRegion.getIconCommand().forEach(iconCommand -> {
|
||||
if (iconCommand.getClickType() != IconCommand.CommandClickType.DISCOVERED && hasDiscovered
|
||||
|| iconCommand.getClickType() != IconCommand.CommandClickType.UNDISCOVERED && !hasDiscovered) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.ICON_COMMAND)) {
|
||||
Translations.COOLDOWN.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.performCommand(iconCommand.getCommand()
|
||||
.replace("%region%", configuredRegion.getId())
|
||||
.replace("%player%", player.getName()));
|
||||
|
||||
if (iconCommand.getCooldown() != 0) {
|
||||
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.ICON_COMMAND);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.ICON_COMMAND), iconCommand.getCooldown());
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
pane.populateWithGuiItems(items);
|
||||
gui.addPane(pane);
|
||||
}).exceptionally(error -> {
|
||||
plugin.getLogger().warning("There was an error whilst listing regions");
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
gui.show(getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,116 +19,116 @@ import java.util.Arrays;
|
||||
|
||||
public class EditorGUI extends RPGRegionsGUI {
|
||||
|
||||
private final Gui gui;
|
||||
private static final ItemStack SET_COOLDOWN_ITEM = new ItemStackBuilder(XMaterial.NETHER_STAR.parseMaterial(true))
|
||||
.withName(ChatColor.GREEN + "Set teleport cooldown")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Set the cooldown for teleportation", ChatColor.GRAY + "int, ticks"))
|
||||
.build();
|
||||
private static final ItemStack SET_NAME_ITEM = new ItemStackBuilder(XMaterial.NAME_TAG.parseMaterial(true))
|
||||
.withName(ChatColor.GREEN + "Set name")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Set the display name of the region", ChatColor.GRAY + "string"))
|
||||
.build();
|
||||
private static final ItemStack SET_LOCATION_ITEM = new ItemStackBuilder(XMaterial.ENDER_PEARL.parseMaterial(true))
|
||||
.withName(ChatColor.GREEN + "Set teleport location")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Set the teleport location to your current location", ChatColor.GRAY + "location"))
|
||||
.build();
|
||||
private static final ItemStack EXIT_ITEM = new ItemStackBuilder(XMaterial.BARRIER.parseMaterial(true))
|
||||
.withName(ChatColor.RED + "Exit and save")
|
||||
.build();
|
||||
|
||||
public EditorGUI(RPGRegions plugin, Player player, ConfiguredRegion region) {
|
||||
super(plugin, player);
|
||||
this.gui = new Gui(plugin, 1, region.getCustomName());
|
||||
gui.setOnGlobalClick(click -> click.setCancelled(true));
|
||||
private final Gui gui;
|
||||
private static final ItemStack SET_COOLDOWN_ITEM = new ItemStackBuilder(XMaterial.NETHER_STAR.parseMaterial(true))
|
||||
.withName(ChatColor.GREEN + "Set teleport cooldown")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Set the cooldown for teleportation", ChatColor.GRAY + "int, ticks"))
|
||||
.build();
|
||||
private static final ItemStack SET_NAME_ITEM = new ItemStackBuilder(XMaterial.NAME_TAG.parseMaterial(true))
|
||||
.withName(ChatColor.GREEN + "Set name")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Set the display name of the region", ChatColor.GRAY + "string"))
|
||||
.build();
|
||||
private static final ItemStack SET_LOCATION_ITEM = new ItemStackBuilder(XMaterial.ENDER_PEARL.parseMaterial(true))
|
||||
.withName(ChatColor.GREEN + "Set teleport location")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Set the teleport location to your current location", ChatColor.GRAY + "location"))
|
||||
.build();
|
||||
private static final ItemStack EXIT_ITEM = new ItemStackBuilder(XMaterial.BARRIER.parseMaterial(true))
|
||||
.withName(ChatColor.RED + "Exit and save")
|
||||
.build();
|
||||
|
||||
StaticPane pane = new StaticPane(0, 0, 9, 1);
|
||||
pane.addItem(new GuiItem(SET_NAME_ITEM, event -> new AnvilGUI.Builder()
|
||||
.onComplete((responder, text) -> {
|
||||
region.setCustomName(text);
|
||||
player.sendMessage(ChatColor.GREEN + "Region display name has been set.");
|
||||
Bukkit.getScheduler().runTaskLater(plugin, this::open, 20L);
|
||||
return AnvilGUI.Response.close();
|
||||
})
|
||||
.preventClose()
|
||||
.text(region.getCustomName())
|
||||
.item(new ItemStack(Material.NAME_TAG))
|
||||
.title("Set display name") // only works in 1.14+
|
||||
.plugin(plugin)
|
||||
.open(player)), 0, 0);
|
||||
pane.addItem(new GuiItem(SET_LOCATION_ITEM, event -> {
|
||||
region.setLocation(player.getLocation());
|
||||
player.sendMessage(ChatColor.GREEN + "Region teleport location has been set.");
|
||||
this.open();
|
||||
}), 1, 0);
|
||||
pane.addItem(new GuiItem(SET_COOLDOWN_ITEM, event -> new AnvilGUI.Builder()
|
||||
.onComplete((responder, text) -> {
|
||||
try {
|
||||
int cooldown = Integer.parseInt(text);
|
||||
region.setTeleportCooldown(cooldown);
|
||||
player.sendMessage(ChatColor.GREEN + "Region teleport cooldown has been set.");
|
||||
Bukkit.getScheduler().runTaskLater(plugin, this::open, 20L);
|
||||
return AnvilGUI.Response.close();
|
||||
} catch (NumberFormatException e) {
|
||||
return AnvilGUI.Response.text("Please provide a number");
|
||||
}
|
||||
})
|
||||
.preventClose()
|
||||
.text("" + region.getTeleportCooldown())
|
||||
.item(new ItemStack(Material.NAME_TAG))
|
||||
.title("Set teleport cooldown") // only works in 1.14+
|
||||
.plugin(plugin)
|
||||
.open(player)), 2, 0);
|
||||
Material toggleTeleportMaterial = region.isTeleportable() ? XMaterial.GREEN_WOOL.parseMaterial(true) : XMaterial.RED_WOOL.parseMaterial(true);
|
||||
ItemStack toggleTeleport = new ItemStackBuilder(toggleTeleportMaterial)
|
||||
.withName(ChatColor.GREEN + "Toggle teleport")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Toggle whether this region can be teleported to", ChatColor.GRAY + "boolean"))
|
||||
.build();
|
||||
pane.addItem(new GuiItem(toggleTeleport, event -> {
|
||||
region.setTeleportable(!region.isTeleportable());
|
||||
player.closeInventory();
|
||||
new EditorGUI(plugin, player, region).open();
|
||||
player.sendMessage(ChatColor.GREEN + "Region teleporting has been toggled");
|
||||
}), 3, 0);
|
||||
Material toggleDiscoverableMaterial = region.isDiscoverable() ? XMaterial.GREEN_WOOL.parseMaterial(true) : XMaterial.RED_WOOL.parseMaterial(true);
|
||||
ItemStack toggleDiscoverable = new ItemStackBuilder(toggleDiscoverableMaterial)
|
||||
.withName(ChatColor.GREEN + "Toggle discoverable")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Toggle whether this region can be discovered", ChatColor.GRAY + "boolean"))
|
||||
.build();
|
||||
pane.addItem(new GuiItem(toggleDiscoverable, event -> {
|
||||
region.setDiscoverable(!region.isDiscoverable());
|
||||
player.closeInventory();
|
||||
new EditorGUI(plugin, player, region).open();
|
||||
player.sendMessage(ChatColor.GREEN + "Region discovering has been toggled");
|
||||
}), 4, 0);
|
||||
Material toggleHiddenMaterial = region.isHidden() ? XMaterial.GREEN_WOOL.parseMaterial(true) : XMaterial.RED_WOOL.parseMaterial(true);
|
||||
ItemStack toggleHidden = new ItemStackBuilder(toggleHiddenMaterial)
|
||||
.withName(ChatColor.GREEN + "Toggle hidden")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Toggle whether this region is hidden", ChatColor.GRAY + "boolean"))
|
||||
.build();
|
||||
pane.addItem(new GuiItem(toggleHidden, event -> {
|
||||
region.setHidden(!region.isHidden());
|
||||
player.closeInventory();
|
||||
new EditorGUI(plugin, player, region).open();
|
||||
player.sendMessage(ChatColor.GREEN + "Region visibility has been toggled");
|
||||
}), 5, 0);
|
||||
pane.addItem(new GuiItem(EXIT_ITEM, event -> {
|
||||
player.closeInventory();
|
||||
try {
|
||||
player.sendMessage(ChatColor.GREEN + "Saving data...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
region.save(plugin);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
player.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}), 8, 0);
|
||||
gui.addPane(pane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
gui.show(getPlayer());
|
||||
}
|
||||
public EditorGUI(RPGRegions plugin, Player player, ConfiguredRegion region) {
|
||||
super(plugin, player);
|
||||
this.gui = new Gui(plugin, 1, region.getCustomName());
|
||||
gui.setOnGlobalClick(click -> click.setCancelled(true));
|
||||
|
||||
StaticPane pane = new StaticPane(0, 0, 9, 1);
|
||||
pane.addItem(new GuiItem(SET_NAME_ITEM, event -> new AnvilGUI.Builder()
|
||||
.onComplete((responder, text) -> {
|
||||
region.setCustomName(text);
|
||||
player.sendMessage(ChatColor.GREEN + "Region display name has been set.");
|
||||
Bukkit.getScheduler().runTaskLater(plugin, this::open, 20L);
|
||||
return AnvilGUI.Response.close();
|
||||
})
|
||||
.preventClose()
|
||||
.text(region.getCustomName())
|
||||
.item(new ItemStack(Material.NAME_TAG))
|
||||
.title("Set display name") // only works in 1.14+
|
||||
.plugin(plugin)
|
||||
.open(player)), 0, 0);
|
||||
pane.addItem(new GuiItem(SET_LOCATION_ITEM, event -> {
|
||||
region.setLocation(player.getLocation());
|
||||
player.sendMessage(ChatColor.GREEN + "Region teleport location has been set.");
|
||||
this.open();
|
||||
}), 1, 0);
|
||||
pane.addItem(new GuiItem(SET_COOLDOWN_ITEM, event -> new AnvilGUI.Builder()
|
||||
.onComplete((responder, text) -> {
|
||||
try {
|
||||
int cooldown = Integer.parseInt(text);
|
||||
region.setTeleportCooldown(cooldown);
|
||||
player.sendMessage(ChatColor.GREEN + "Region teleport cooldown has been set.");
|
||||
Bukkit.getScheduler().runTaskLater(plugin, this::open, 20L);
|
||||
return AnvilGUI.Response.close();
|
||||
} catch (NumberFormatException e) {
|
||||
return AnvilGUI.Response.text("Please provide a number");
|
||||
}
|
||||
})
|
||||
.preventClose()
|
||||
.text("" + region.getTeleportCooldown())
|
||||
.item(new ItemStack(Material.NAME_TAG))
|
||||
.title("Set teleport cooldown") // only works in 1.14+
|
||||
.plugin(plugin)
|
||||
.open(player)), 2, 0);
|
||||
Material toggleTeleportMaterial = region.isTeleportable() ? XMaterial.GREEN_WOOL.parseMaterial(true) : XMaterial.RED_WOOL.parseMaterial(true);
|
||||
ItemStack toggleTeleport = new ItemStackBuilder(toggleTeleportMaterial)
|
||||
.withName(ChatColor.GREEN + "Toggle teleport")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Toggle whether this region can be teleported to", ChatColor.GRAY + "boolean"))
|
||||
.build();
|
||||
pane.addItem(new GuiItem(toggleTeleport, event -> {
|
||||
region.setTeleportable(!region.isTeleportable());
|
||||
player.closeInventory();
|
||||
new EditorGUI(plugin, player, region).open();
|
||||
player.sendMessage(ChatColor.GREEN + "Region teleporting has been toggled");
|
||||
}), 3, 0);
|
||||
Material toggleDiscoverableMaterial = region.isDiscoverable() ? XMaterial.GREEN_WOOL.parseMaterial(true) : XMaterial.RED_WOOL.parseMaterial(true);
|
||||
ItemStack toggleDiscoverable = new ItemStackBuilder(toggleDiscoverableMaterial)
|
||||
.withName(ChatColor.GREEN + "Toggle discoverable")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Toggle whether this region can be discovered", ChatColor.GRAY + "boolean"))
|
||||
.build();
|
||||
pane.addItem(new GuiItem(toggleDiscoverable, event -> {
|
||||
region.setDiscoverable(!region.isDiscoverable());
|
||||
player.closeInventory();
|
||||
new EditorGUI(plugin, player, region).open();
|
||||
player.sendMessage(ChatColor.GREEN + "Region discovering has been toggled");
|
||||
}), 4, 0);
|
||||
Material toggleHiddenMaterial = region.isHidden() ? XMaterial.GREEN_WOOL.parseMaterial(true) : XMaterial.RED_WOOL.parseMaterial(true);
|
||||
ItemStack toggleHidden = new ItemStackBuilder(toggleHiddenMaterial)
|
||||
.withName(ChatColor.GREEN + "Toggle hidden")
|
||||
.withLore(Arrays.asList(ChatColor.WHITE + "Toggle whether this region is hidden", ChatColor.GRAY + "boolean"))
|
||||
.build();
|
||||
pane.addItem(new GuiItem(toggleHidden, event -> {
|
||||
region.setHidden(!region.isHidden());
|
||||
player.closeInventory();
|
||||
new EditorGUI(plugin, player, region).open();
|
||||
player.sendMessage(ChatColor.GREEN + "Region visibility has been toggled");
|
||||
}), 5, 0);
|
||||
pane.addItem(new GuiItem(EXIT_ITEM, event -> {
|
||||
player.closeInventory();
|
||||
try {
|
||||
player.sendMessage(ChatColor.GREEN + "Saving data...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
region.save(plugin);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
player.sendMessage(ChatColor.GREEN + "Done! (" + totalTime + "ms)");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}), 8, 0);
|
||||
gui.addPane(pane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
gui.show(getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ import net.islandearth.rpgregions.RPGRegions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class RPGRegionsGUI {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final Player player;
|
||||
|
||||
public RPGRegionsGUI(RPGRegions plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public abstract void open();
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final Player player;
|
||||
|
||||
public RPGRegionsGUI(RPGRegions plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public abstract void open();
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class ConnectionListener implements Listener {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public ConnectionListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public ConnectionListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent pqe) {
|
||||
Player player = pqe.getPlayer();
|
||||
if (plugin.getManagers().getStorageManager().getCachedAccounts().containsKey(player.getUniqueId()))
|
||||
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
}
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent pqe) {
|
||||
Player player = pqe.getPlayer();
|
||||
if (plugin.getManagers().getStorageManager().getCachedAccounts().containsKey(player.getUniqueId()))
|
||||
plugin.getManagers().getStorageManager().removeCachedAccount(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,20 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class MoveListener implements Listener {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public MoveListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public MoveListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent pme) {
|
||||
int x = pme.getTo().getBlockX();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
if (x == oldX && z == oldZ) return;
|
||||
|
||||
plugin.getManagers().getIntegrationManager().handleMove(pme);
|
||||
}
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent pme) {
|
||||
int x = pme.getTo().getBlockX();
|
||||
int z = pme.getTo().getBlockZ();
|
||||
int oldX = pme.getFrom().getBlockX();
|
||||
int oldZ = pme.getFrom().getBlockZ();
|
||||
if (x == oldX && z == oldZ) return;
|
||||
|
||||
plugin.getManagers().getIntegrationManager().handleMove(pme);
|
||||
}
|
||||
}
|
||||
@@ -22,128 +22,128 @@ import java.util.UUID;
|
||||
|
||||
public class RegionListener implements Listener {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final List<UUID> titleCooldown;
|
||||
private final RPGRegions plugin;
|
||||
private final List<UUID> titleCooldown;
|
||||
|
||||
public RegionListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
this.titleCooldown = new ArrayList<>();
|
||||
}
|
||||
public RegionListener(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
this.titleCooldown = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles region discoveries on enter.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEnter(RegionsEnterEvent ree) {
|
||||
Player player = ree.getPlayer();
|
||||
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
|
||||
for (String region : ree.getRegions()) {
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
|
||||
boolean has = false;
|
||||
for (Discovery discoveredRegion : account.getDiscoveredRegions().values()) {
|
||||
if (discoveredRegion.getRegion().equals(region)) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handles region discoveries on enter.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEnter(RegionsEnterEvent ree) {
|
||||
Player player = ree.getPlayer();
|
||||
plugin.getManagers().getStorageManager().getAccount(player.getUniqueId()).thenAccept(account -> {
|
||||
for (String region : ree.getRegions()) {
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
|
||||
boolean has = false;
|
||||
for (Discovery discoveredRegion : account.getDiscoveredRegions().values()) {
|
||||
if (discoveredRegion.getRegion().equals(region)) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegions().get(region);
|
||||
if (configuredRegion.getEffects() != null) {
|
||||
configuredRegion.getEffects().forEach(regionEffect -> {
|
||||
boolean canEffect = true;
|
||||
if (regionEffect.isWearingRequired()) {
|
||||
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
if (regionEffect.shouldIgnore(itemStack)) {
|
||||
canEffect = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegions().get(region);
|
||||
if (configuredRegion.getEffects() != null) {
|
||||
configuredRegion.getEffects().forEach(regionEffect -> {
|
||||
boolean canEffect = true;
|
||||
if (regionEffect.isWearingRequired()) {
|
||||
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
if (regionEffect.shouldIgnore(itemStack)) {
|
||||
canEffect = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canEffect) regionEffect.effect(player);
|
||||
return;
|
||||
}
|
||||
if (canEffect) regionEffect.effect(player);
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : player.getInventory()) {
|
||||
if (regionEffect.shouldIgnore(itemStack)) {
|
||||
canEffect = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (ItemStack itemStack : player.getInventory()) {
|
||||
if (regionEffect.shouldIgnore(itemStack)) {
|
||||
canEffect = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canEffect) regionEffect.effect(player);
|
||||
});
|
||||
}
|
||||
if (canEffect) regionEffect.effect(player);
|
||||
});
|
||||
}
|
||||
|
||||
if (configuredRegion.alwaysShowTitles() && ree.hasChanged() && has) {
|
||||
this.sendTitles(player, configuredRegion, false);
|
||||
}
|
||||
if (configuredRegion.alwaysShowTitles() && ree.hasChanged() && has) {
|
||||
this.sendTitles(player, configuredRegion, false);
|
||||
}
|
||||
|
||||
if (!has && configuredRegion.isDiscoverable()) {
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(plugin.getConfig().getString("settings.server.discoveries.date.format"));
|
||||
if (!has && configuredRegion.isDiscoverable()) {
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(plugin.getConfig().getString("settings.server.discoveries.date.format"));
|
||||
|
||||
String formattedDate = date.format(format);
|
||||
account.addDiscovery(new WorldDiscovery(formattedDate, region));
|
||||
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
String formattedDate = date.format(format);
|
||||
account.addDiscovery(new WorldDiscovery(formattedDate, region));
|
||||
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDiscover(RegionDiscoverEvent rde) {
|
||||
Player player = rde.getPlayer();
|
||||
String region = rde.getRegion();
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
|
||||
this.sendTitles(player, configuredRegion, true);
|
||||
@EventHandler
|
||||
public void onDiscover(RegionDiscoverEvent rde) {
|
||||
Player player = rde.getPlayer();
|
||||
String region = rde.getRegion();
|
||||
if (plugin.getManagers().getRegionsCache().getConfiguredRegions().containsKey(region)) {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
|
||||
this.sendTitles(player, configuredRegion, true);
|
||||
|
||||
if (configuredRegion.getSound() == null) {
|
||||
player.playSound(
|
||||
player.getLocation(),
|
||||
XSound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")).parseSound(),
|
||||
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")
|
||||
);
|
||||
}
|
||||
if (configuredRegion.getSound() == null) {
|
||||
player.playSound(
|
||||
player.getLocation(),
|
||||
XSound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")).parseSound(),
|
||||
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")
|
||||
);
|
||||
}
|
||||
|
||||
if (configuredRegion.getRewards() != null) configuredRegion.getRewards().forEach(reward -> reward.award(player));
|
||||
}
|
||||
}
|
||||
if (configuredRegion.getRewards() != null) configuredRegion.getRewards().forEach(reward -> reward.award(player));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendTitles(Player player, ConfiguredRegion configuredRegion, boolean discovered) {
|
||||
if (titleCooldown.contains(player.getUniqueId())) return;
|
||||
else {
|
||||
titleCooldown.add(player.getUniqueId());
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
titleCooldown.remove(player.getUniqueId());
|
||||
}, plugin.getConfig().getInt("settings.server.discoveries.discovered.title.cooldown"));
|
||||
}
|
||||
if (!discovered) {
|
||||
List<String> discoveredTitle = configuredRegion.getDiscoveredTitle(player);
|
||||
List<String> discoveredSubtitle = configuredRegion.getDiscoveredSubtitle(player);
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
discoveredTitle,
|
||||
discoveredSubtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.animation_speed"));
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> title = configuredRegion.getTitle(player);
|
||||
List<String> subtitle = configuredRegion.getSubtitle(player);
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
title,
|
||||
subtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.animation_speed"));
|
||||
}
|
||||
private void sendTitles(Player player, ConfiguredRegion configuredRegion, boolean discovered) {
|
||||
if (titleCooldown.contains(player.getUniqueId())) return;
|
||||
else {
|
||||
titleCooldown.add(player.getUniqueId());
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
titleCooldown.remove(player.getUniqueId());
|
||||
}, plugin.getConfig().getInt("settings.server.discoveries.discovered.title.cooldown"));
|
||||
}
|
||||
if (!discovered) {
|
||||
List<String> discoveredTitle = configuredRegion.getDiscoveredTitle(player);
|
||||
List<String> discoveredSubtitle = configuredRegion.getDiscoveredSubtitle(player);
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
discoveredTitle,
|
||||
discoveredSubtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.animation_speed"));
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> title = configuredRegion.getTitle(player);
|
||||
List<String> subtitle = configuredRegion.getSubtitle(player);
|
||||
new TitleAnimator(player,
|
||||
plugin,
|
||||
title,
|
||||
subtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.animation_speed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,116 +45,116 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class RPGRegionsManagers {
|
||||
|
||||
private StorageManager storageManager;
|
||||
private IntegrationManager integrationManager;
|
||||
private RPGRegionsCache regionsCache;
|
||||
private RegenerationManager regenerationManager;
|
||||
private StorageManager storageManager;
|
||||
private IntegrationManager integrationManager;
|
||||
private RPGRegionsCache regionsCache;
|
||||
private RegenerationManager regenerationManager;
|
||||
|
||||
public RPGRegionsManagers(RPGRegions plugin) {
|
||||
StorageType.valueOf(plugin.getConfig().getString("settings.storage.mode").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(storageManager1 -> storageManager = storageManager1);
|
||||
if (storageManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
public RPGRegionsManagers(RPGRegions plugin) {
|
||||
StorageType.valueOf(plugin.getConfig().getString("settings.storage.mode").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(storageManager1 -> storageManager = storageManager1);
|
||||
if (storageManager == null) throw new IllegalStateException("Could not find StorageManager!");
|
||||
|
||||
try {
|
||||
IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(integrationManager1 -> integrationManager = integrationManager1);
|
||||
} catch (ClassNotFoundException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not find IntegrationManager!", e);
|
||||
}
|
||||
|
||||
this.regionsCache = new RPGRegionsCache(plugin);
|
||||
try {
|
||||
IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase())
|
||||
.get()
|
||||
.ifPresent(integrationManager1 -> integrationManager = integrationManager1);
|
||||
} catch (ClassNotFoundException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not find IntegrationManager!", e);
|
||||
}
|
||||
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
if (!folder.exists()) folder.mkdirs();
|
||||
this.regionsCache = new RPGRegionsCache(plugin);
|
||||
|
||||
// Generate an example config
|
||||
List<DiscoveryReward> rewards = new ArrayList<>();
|
||||
rewards.add(new ExperienceReward(10));
|
||||
rewards.add(new ItemReward(new ItemStack(XMaterial.IRON_BARS.parseMaterial())));
|
||||
rewards.add(new PlayerCommandReward("say I discovered a region!"));
|
||||
rewards.add(new ConsoleCommandReward("say Server sees you discovered a region!"));
|
||||
rewards.add(new MessageReward(Collections.singletonList("&aExample message as a reward")));
|
||||
List<RegionEffect> effects = new ArrayList<>();
|
||||
if (!plugin.isLegacyServer()) effects.add(new PotionRegionEffect(
|
||||
new PotionEffect(PotionEffectType.GLOWING, 100, 1, true, true, true),
|
||||
true,
|
||||
Collections.singletonList(new ItemStackBuilder(Material.IRON_CHESTPLATE).build())));
|
||||
else effects.add(new PotionRegionEffect(
|
||||
new PotionEffect(PotionEffectType.GLOWING, 100, 1, true, true),
|
||||
true,
|
||||
Collections.singletonList(new ItemStackBuilder(Material.IRON_CHESTPLATE).build())));
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
if (!folder.exists()) folder.mkdirs();
|
||||
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(null, "exampleconfig", "ExampleConfig", rewards, effects,
|
||||
XSound.AMBIENT_UNDERWATER_EXIT.parseSound(),
|
||||
XMaterial.WOODEN_AXE);
|
||||
configuredRegion.setRegenerate(new Regenerate(5000,
|
||||
false,
|
||||
Collections.singletonList(
|
||||
new RegeneratingEntity(EntityType.SHULKER, Arrays.asList(
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.PURPUR_PILLAR), 5, 30))));
|
||||
configuredRegion.getIconCommand().add(new IconCommand("say", IconCommand.CommandClickType.DISCOVERED, 0));
|
||||
try {
|
||||
configuredRegion.save(plugin);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Generate an example config
|
||||
List<DiscoveryReward> rewards = new ArrayList<>();
|
||||
rewards.add(new ExperienceReward(10));
|
||||
rewards.add(new ItemReward(new ItemStack(XMaterial.IRON_BARS.parseMaterial())));
|
||||
rewards.add(new PlayerCommandReward("say I discovered a region!"));
|
||||
rewards.add(new ConsoleCommandReward("say Server sees you discovered a region!"));
|
||||
rewards.add(new MessageReward(Collections.singletonList("&aExample message as a reward")));
|
||||
List<RegionEffect> effects = new ArrayList<>();
|
||||
if (!plugin.isLegacyServer()) effects.add(new PotionRegionEffect(
|
||||
new PotionEffect(PotionEffectType.GLOWING, 100, 1, true, true, true),
|
||||
true,
|
||||
Collections.singletonList(new ItemStackBuilder(Material.IRON_CHESTPLATE).build())));
|
||||
else effects.add(new PotionRegionEffect(
|
||||
new PotionEffect(PotionEffectType.GLOWING, 100, 1, true, true),
|
||||
true,
|
||||
Collections.singletonList(new ItemStackBuilder(Material.IRON_CHESTPLATE).build())));
|
||||
|
||||
try {
|
||||
Files.walk(Paths.get(folder.getPath()))
|
||||
.filter(Files::isRegularFile)
|
||||
.collect(Collectors.toList())
|
||||
.forEach(path -> {
|
||||
File file = path.toFile();
|
||||
if (regionsCache.getConfiguredRegions().containsKey(file.getName().replace(".json", ""))) {
|
||||
plugin.getLogger().severe("Duplicate region files have been found for " + file.getName() + ". " +
|
||||
"In order to protect your data, the plugin will NOT load the duplicate region config.");
|
||||
return;
|
||||
}
|
||||
// Exclude non-json files
|
||||
if (file.getName().endsWith(".json")) {
|
||||
try {
|
||||
Reader reader = new FileReader(file);
|
||||
ConfiguredRegion region = plugin.getGson().fromJson(reader, ConfiguredRegion.class);
|
||||
if (!region.getId().equals("exampleconfig")) regionsCache.addConfiguredRegion(region);
|
||||
if (region.getRequirements() != null) region.getRequirements().forEach(regionRequirement -> plugin.getLogger().warning("Warning: Region " + region.getId() + " uses requirements. These are highly experimental and there may be bypasses."));
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Error loading region config " + file.getName() + ":");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(null, "exampleconfig", "ExampleConfig", rewards, effects,
|
||||
XSound.AMBIENT_UNDERWATER_EXIT.parseSound(),
|
||||
XMaterial.WOODEN_AXE);
|
||||
configuredRegion.setRegenerate(new Regenerate(5000,
|
||||
false,
|
||||
Collections.singletonList(
|
||||
new RegeneratingEntity(EntityType.SHULKER, Arrays.asList(
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.PURPUR_PILLAR), 5, 30))));
|
||||
configuredRegion.getIconCommand().add(new IconCommand("say", IconCommand.CommandClickType.DISCOVERED, 0));
|
||||
try {
|
||||
configuredRegion.save(plugin);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.regenerationManager = new RegenerationManager(plugin);
|
||||
try {
|
||||
Files.walk(Paths.get(folder.getPath()))
|
||||
.filter(Files::isRegularFile)
|
||||
.collect(Collectors.toList())
|
||||
.forEach(path -> {
|
||||
File file = path.toFile();
|
||||
if (regionsCache.getConfiguredRegions().containsKey(file.getName().replace(".json", ""))) {
|
||||
plugin.getLogger().severe("Duplicate region files have been found for " + file.getName() + ". " +
|
||||
"In order to protect your data, the plugin will NOT load the duplicate region config.");
|
||||
return;
|
||||
}
|
||||
// Exclude non-json files
|
||||
if (file.getName().endsWith(".json")) {
|
||||
try {
|
||||
Reader reader = new FileReader(file);
|
||||
ConfiguredRegion region = plugin.getGson().fromJson(reader, ConfiguredRegion.class);
|
||||
if (!region.getId().equals("exampleconfig")) regionsCache.addConfiguredRegion(region);
|
||||
if (region.getRequirements() != null) region.getRequirements().forEach(regionRequirement -> plugin.getLogger().warning("Warning: Region " + region.getId() + " uses requirements. These are highly experimental and there may be bypasses."));
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Error loading region config " + file.getName() + ":");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlaceholderRegionHook(plugin).register();
|
||||
}
|
||||
this.regenerationManager = new RegenerationManager(plugin);
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("Plan") != null) {
|
||||
new PlanRegistryManager(plugin);
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlaceholderRegionHook(plugin).register();
|
||||
}
|
||||
|
||||
public StorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("Plan") != null) {
|
||||
new PlanRegistryManager(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
public IntegrationManager getIntegrationManager() {
|
||||
return integrationManager;
|
||||
}
|
||||
|
||||
public RPGRegionsCache getRegionsCache() {
|
||||
return regionsCache;
|
||||
}
|
||||
public StorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
public RegenerationManager getRegenerationManager() {
|
||||
return regenerationManager;
|
||||
}
|
||||
public IntegrationManager getIntegrationManager() {
|
||||
return integrationManager;
|
||||
}
|
||||
|
||||
public RPGRegionsCache getRegionsCache() {
|
||||
return regionsCache;
|
||||
}
|
||||
|
||||
public RegenerationManager getRegenerationManager() {
|
||||
return regenerationManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,27 +9,27 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class RPGRegionsCache {
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private Map<String, ConfiguredRegion> configuredRegions = new ConcurrentHashMap<>();
|
||||
private final RPGRegions plugin;
|
||||
private Map<String, ConfiguredRegion> configuredRegions = new ConcurrentHashMap<>();
|
||||
|
||||
public RPGRegionsCache(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public RPGRegionsCache(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ConfiguredRegion getConfiguredRegion(String id) {
|
||||
return configuredRegions.get(id);
|
||||
}
|
||||
@Nullable
|
||||
public ConfiguredRegion getConfiguredRegion(String id) {
|
||||
return configuredRegions.get(id);
|
||||
}
|
||||
|
||||
public void addConfiguredRegion(ConfiguredRegion region) {
|
||||
configuredRegions.put(region.getId(), region);
|
||||
}
|
||||
public void addConfiguredRegion(ConfiguredRegion region) {
|
||||
configuredRegions.put(region.getId(), region);
|
||||
}
|
||||
|
||||
public void removeConfiguredRegion(String id) {
|
||||
configuredRegions.remove(id);
|
||||
}
|
||||
public void removeConfiguredRegion(String id) {
|
||||
configuredRegions.remove(id);
|
||||
}
|
||||
|
||||
public Map<String, ConfiguredRegion> getConfiguredRegions() {
|
||||
return configuredRegions;
|
||||
}
|
||||
public Map<String, ConfiguredRegion> getConfiguredRegions() {
|
||||
return configuredRegions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,47 +8,47 @@ import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public interface StorageManager {
|
||||
|
||||
/**
|
||||
* Gets a player's account from the storage.
|
||||
* This will return an account stored in the cache.
|
||||
* If no account is found in the cache a new account will be fetched and added to the cache.
|
||||
* @param uuid player's UUID
|
||||
* @return player's account
|
||||
*/
|
||||
CompletableFuture<RPGRegionsAccount> getAccount(UUID uuid);
|
||||
/**
|
||||
* Gets a player's account from the storage.
|
||||
* This will return an account stored in the cache.
|
||||
* If no account is found in the cache a new account will be fetched and added to the cache.
|
||||
* @param uuid player's UUID
|
||||
* @return player's account
|
||||
*/
|
||||
CompletableFuture<RPGRegionsAccount> getAccount(UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets a map of currently cached accounts.
|
||||
* @return map of cached accounts
|
||||
*/
|
||||
ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts();
|
||||
|
||||
/**
|
||||
* Removes all discoveries matching a player.
|
||||
* @param uuid player uuid
|
||||
*/
|
||||
void clearDiscoveries(UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes a specific discovery matching a player.
|
||||
* @param uuid player uuid
|
||||
* @param regionId region id
|
||||
*/
|
||||
void clearDiscovery(UUID uuid, String regionId);
|
||||
|
||||
void deleteAccount(UUID uuid);
|
||||
/**
|
||||
* Removes an account from the storage cache and saves its data.
|
||||
* @param uuid player's UUID
|
||||
*/
|
||||
void removeCachedAccount(UUID uuid);
|
||||
/**
|
||||
* Gets a map of currently cached accounts.
|
||||
* @return map of cached accounts
|
||||
*/
|
||||
ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts();
|
||||
|
||||
/**
|
||||
* Gets a UUID safe to use in databases.
|
||||
* @param uuid player's UUID
|
||||
* @return new string uuid to use in databases
|
||||
*/
|
||||
default String getDatabaseUuid(UUID uuid) {
|
||||
return uuid.toString().replace("-", "");
|
||||
}
|
||||
/**
|
||||
* Removes all discoveries matching a player.
|
||||
* @param uuid player uuid
|
||||
*/
|
||||
void clearDiscoveries(UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes a specific discovery matching a player.
|
||||
* @param uuid player uuid
|
||||
* @param regionId region id
|
||||
*/
|
||||
void clearDiscovery(UUID uuid, String regionId);
|
||||
|
||||
void deleteAccount(UUID uuid);
|
||||
/**
|
||||
* Removes an account from the storage cache and saves its data.
|
||||
* @param uuid player's UUID
|
||||
*/
|
||||
void removeCachedAccount(UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets a UUID safe to use in databases.
|
||||
* @param uuid player's UUID
|
||||
* @return new string uuid to use in databases
|
||||
*/
|
||||
default String getDatabaseUuid(UUID uuid) {
|
||||
return uuid.toString().replace("-", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,28 +10,28 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum StorageType {
|
||||
FILE(YamlStorage.class),
|
||||
SQL(SqlStorage.class);
|
||||
FILE(YamlStorage.class),
|
||||
SQL(SqlStorage.class);
|
||||
|
||||
private final Class<? extends StorageManager> clazz;
|
||||
private final Class<? extends StorageManager> clazz;
|
||||
|
||||
StorageType(Class<? extends StorageManager> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
StorageType(Class<? extends StorageManager> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Optional<StorageManager> get() {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
plugin.getLogger().info("Loading StorageManager implementation...");
|
||||
StorageManager generatedClazz = null;
|
||||
try {
|
||||
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.");
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
public Optional<StorageManager> get() {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
plugin.getLogger().info("Loading StorageManager implementation...");
|
||||
StorageManager generatedClazz = null;
|
||||
try {
|
||||
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.");
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
|
||||
return Optional.ofNullable(generatedClazz);
|
||||
}
|
||||
return Optional.ofNullable(generatedClazz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,30 +9,30 @@ import java.util.UUID;
|
||||
|
||||
public class RPGRegionsAccount {
|
||||
|
||||
private UUID uuid;
|
||||
private Map<String, Discovery> discoveredRegions;
|
||||
private List<AccountCooldown> cooldowns;
|
||||
private UUID uuid;
|
||||
private Map<String, Discovery> discoveredRegions;
|
||||
private List<AccountCooldown> cooldowns;
|
||||
|
||||
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
|
||||
this.uuid = uuid;
|
||||
this.discoveredRegions = discoveredRegions;
|
||||
this.cooldowns = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Map<String, Discovery> getDiscoveredRegions() {
|
||||
return discoveredRegions;
|
||||
}
|
||||
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
|
||||
this.uuid = uuid;
|
||||
this.discoveredRegions = discoveredRegions;
|
||||
this.cooldowns = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addDiscovery(Discovery discovery) {
|
||||
discoveredRegions.put(discovery.getRegion(), discovery);
|
||||
}
|
||||
|
||||
public List<AccountCooldown> getCooldowns() {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
public enum AccountCooldown {
|
||||
ICON_COMMAND,
|
||||
TELEPORT
|
||||
}
|
||||
public Map<String, Discovery> getDiscoveredRegions() {
|
||||
return discoveredRegions;
|
||||
}
|
||||
|
||||
public void addDiscovery(Discovery discovery) {
|
||||
discoveredRegions.put(discovery.getRegion(), discovery);
|
||||
}
|
||||
|
||||
public List<AccountCooldown> getCooldowns() {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
public enum AccountCooldown {
|
||||
ICON_COMMAND,
|
||||
TELEPORT
|
||||
}
|
||||
}
|
||||
@@ -38,302 +38,302 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ConfiguredRegion {
|
||||
|
||||
private final UUID world;
|
||||
private final String id;
|
||||
private String customName;
|
||||
private final List<DiscoveryReward> rewards;
|
||||
private final Sound sound;
|
||||
private final String icon;
|
||||
private final String undiscoveredIcon;
|
||||
private final List<IconCommand> iconCommand;
|
||||
private final boolean showCoords;
|
||||
private Location location;
|
||||
private final List<String> hints;
|
||||
private final boolean showHint;
|
||||
private boolean teleportable;
|
||||
private boolean hidden;
|
||||
private boolean discoverable;
|
||||
private final List<RegionEffect> effects;
|
||||
private final List<RegionRequirement> requirements;
|
||||
private final List<String> discoveredLore;
|
||||
private final boolean alwaysShowTitles;
|
||||
private List<String> title;
|
||||
private List<String> subtitle;
|
||||
private List<String> discoveredTitle;
|
||||
private List<String> discoveredSubtitle;
|
||||
private Regenerate regenerate;
|
||||
private int teleportCooldown;
|
||||
private final UUID world;
|
||||
private final String id;
|
||||
private String customName;
|
||||
private final List<DiscoveryReward> rewards;
|
||||
private final Sound sound;
|
||||
private final String icon;
|
||||
private final String undiscoveredIcon;
|
||||
private final List<IconCommand> iconCommand;
|
||||
private final boolean showCoords;
|
||||
private Location location;
|
||||
private final List<String> hints;
|
||||
private final boolean showHint;
|
||||
private boolean teleportable;
|
||||
private boolean hidden;
|
||||
private boolean discoverable;
|
||||
private final List<RegionEffect> effects;
|
||||
private final List<RegionRequirement> requirements;
|
||||
private final List<String> discoveredLore;
|
||||
private final boolean alwaysShowTitles;
|
||||
private List<String> title;
|
||||
private List<String> subtitle;
|
||||
private List<String> discoveredTitle;
|
||||
private List<String> discoveredSubtitle;
|
||||
private Regenerate regenerate;
|
||||
private int teleportCooldown;
|
||||
|
||||
public ConfiguredRegion(@Nullable World world, String id, String customName,
|
||||
List<DiscoveryReward> rewards, List<RegionEffect> effects) {
|
||||
this.world = world != null ? world.getUID() : null;
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
this.rewards = rewards;
|
||||
this.sound = XSound.UI_TOAST_CHALLENGE_COMPLETE.parseSound();
|
||||
this.icon = XMaterial.TOTEM_OF_UNDYING.name();
|
||||
this.undiscoveredIcon = XMaterial.TOTEM_OF_UNDYING.name();
|
||||
this.iconCommand = new ArrayList<>();
|
||||
this.showCoords = false;
|
||||
this.hints = new ArrayList<>();
|
||||
this.showHint = false;
|
||||
this.teleportable = false;
|
||||
this.hidden = false;
|
||||
this.discoverable = true;
|
||||
this.effects = effects;
|
||||
this.requirements = Collections.singletonList(new LevelRequirement(5));
|
||||
this.discoveredLore = new ArrayList<>();
|
||||
this.alwaysShowTitles = false;
|
||||
this.teleportCooldown = 0;
|
||||
}
|
||||
public ConfiguredRegion(@Nullable World world, String id, String customName,
|
||||
List<DiscoveryReward> rewards, List<RegionEffect> effects) {
|
||||
this.world = world != null ? world.getUID() : null;
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
this.rewards = rewards;
|
||||
this.sound = XSound.UI_TOAST_CHALLENGE_COMPLETE.parseSound();
|
||||
this.icon = XMaterial.TOTEM_OF_UNDYING.name();
|
||||
this.undiscoveredIcon = XMaterial.TOTEM_OF_UNDYING.name();
|
||||
this.iconCommand = new ArrayList<>();
|
||||
this.showCoords = false;
|
||||
this.hints = new ArrayList<>();
|
||||
this.showHint = false;
|
||||
this.teleportable = false;
|
||||
this.hidden = false;
|
||||
this.discoverable = true;
|
||||
this.effects = effects;
|
||||
this.requirements = Collections.singletonList(new LevelRequirement(5));
|
||||
this.discoveredLore = new ArrayList<>();
|
||||
this.alwaysShowTitles = false;
|
||||
this.teleportCooldown = 0;
|
||||
}
|
||||
|
||||
public ConfiguredRegion(@Nullable World world, String id, String customName,
|
||||
List<DiscoveryReward> rewards, List<RegionEffect> effects, Sound sound, XMaterial icon) {
|
||||
this.world = world != null ? world.getUID() : null;
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
this.rewards = rewards;
|
||||
this.sound = sound;
|
||||
this.icon = icon.name();
|
||||
this.undiscoveredIcon = icon.name();
|
||||
this.iconCommand = new ArrayList<>();
|
||||
this.showCoords = false;
|
||||
this.hints = new ArrayList<>();
|
||||
this.showHint = false;
|
||||
this.teleportable = false;
|
||||
this.hidden = false;
|
||||
this.discoverable = true;
|
||||
this.effects = effects;
|
||||
this.requirements = Collections.singletonList(new LevelRequirement(5));
|
||||
this.discoveredLore = new ArrayList<>();
|
||||
this.alwaysShowTitles = false;
|
||||
this.teleportCooldown = 0;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getCustomName() {
|
||||
return customName;
|
||||
}
|
||||
public ConfiguredRegion(@Nullable World world, String id, String customName,
|
||||
List<DiscoveryReward> rewards, List<RegionEffect> effects, Sound sound, XMaterial icon) {
|
||||
this.world = world != null ? world.getUID() : null;
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
this.rewards = rewards;
|
||||
this.sound = sound;
|
||||
this.icon = icon.name();
|
||||
this.undiscoveredIcon = icon.name();
|
||||
this.iconCommand = new ArrayList<>();
|
||||
this.showCoords = false;
|
||||
this.hints = new ArrayList<>();
|
||||
this.showHint = false;
|
||||
this.teleportable = false;
|
||||
this.hidden = false;
|
||||
this.discoverable = true;
|
||||
this.effects = effects;
|
||||
this.requirements = Collections.singletonList(new LevelRequirement(5));
|
||||
this.discoveredLore = new ArrayList<>();
|
||||
this.alwaysShowTitles = false;
|
||||
this.teleportCooldown = 0;
|
||||
}
|
||||
|
||||
public void setCustomName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<DiscoveryReward> getRewards() {
|
||||
return rewards;
|
||||
}
|
||||
public String getCustomName() {
|
||||
return customName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Sound getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getIcon() {
|
||||
if (icon == null) return new ItemStack(XMaterial.TOTEM_OF_UNDYING.parseMaterial(true));
|
||||
if (icon.startsWith("hdb-") && JavaPlugin.getPlugin(RPGRegions.class).hasHeadDatabase()) return new ItemStack(new HeadDatabaseAPI().getItemHead(icon.replace("hdb-", "")));
|
||||
return XMaterial.valueOf(icon).parseItem(true);
|
||||
}
|
||||
public void setCustomName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getUndiscoveredIcon() {
|
||||
if (undiscoveredIcon == null) return new ItemStack(XMaterial.TOTEM_OF_UNDYING.parseMaterial(true));
|
||||
if (undiscoveredIcon.startsWith("hdb-") && JavaPlugin.getPlugin(RPGRegions.class).hasHeadDatabase()) return new ItemStack(new HeadDatabaseAPI().getItemHead(undiscoveredIcon.replace("hdb-", "")));
|
||||
return XMaterial.valueOf(undiscoveredIcon).parseItem(true);
|
||||
}
|
||||
@Nullable
|
||||
public List<DiscoveryReward> getRewards() {
|
||||
return rewards;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<IconCommand> getIconCommand() {
|
||||
return iconCommand == null ? new ArrayList<>() : iconCommand;
|
||||
}
|
||||
@Nullable
|
||||
public Sound getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
@Nullable
|
||||
public ItemStack getIcon() {
|
||||
if (icon == null) return new ItemStack(XMaterial.TOTEM_OF_UNDYING.parseMaterial(true));
|
||||
if (icon.startsWith("hdb-") && JavaPlugin.getPlugin(RPGRegions.class).hasHeadDatabase()) return new ItemStack(new HeadDatabaseAPI().getItemHead(icon.replace("hdb-", "")));
|
||||
return XMaterial.valueOf(icon).parseItem(true);
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
@Nullable
|
||||
public ItemStack getUndiscoveredIcon() {
|
||||
if (undiscoveredIcon == null) return new ItemStack(XMaterial.TOTEM_OF_UNDYING.parseMaterial(true));
|
||||
if (undiscoveredIcon.startsWith("hdb-") && JavaPlugin.getPlugin(RPGRegions.class).hasHeadDatabase()) return new ItemStack(new HeadDatabaseAPI().getItemHead(undiscoveredIcon.replace("hdb-", "")));
|
||||
return XMaterial.valueOf(undiscoveredIcon).parseItem(true);
|
||||
}
|
||||
|
||||
public boolean isShowCoords() {
|
||||
return showCoords;
|
||||
}
|
||||
@NotNull
|
||||
public List<IconCommand> getIconCommand() {
|
||||
return iconCommand == null ? new ArrayList<>() : iconCommand;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> getHints() {
|
||||
return hints;
|
||||
}
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public boolean isShowHint() {
|
||||
return showHint;
|
||||
}
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public boolean isTeleportable() {
|
||||
return teleportable;
|
||||
}
|
||||
public boolean isShowCoords() {
|
||||
return showCoords;
|
||||
}
|
||||
|
||||
public void setTeleportable(boolean teleportable) {
|
||||
this.teleportable = teleportable;
|
||||
}
|
||||
@Nullable
|
||||
public List<String> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public World getWorld() {
|
||||
return Bukkit.getWorld(world);
|
||||
}
|
||||
public boolean isShowHint() {
|
||||
return showHint;
|
||||
}
|
||||
|
||||
public boolean isDiscoverable() {
|
||||
return discoverable;
|
||||
}
|
||||
public boolean isTeleportable() {
|
||||
return teleportable;
|
||||
}
|
||||
|
||||
public void setDiscoverable(boolean discoverable) {
|
||||
this.discoverable = discoverable;
|
||||
}
|
||||
public void setTeleportable(boolean teleportable) {
|
||||
this.teleportable = teleportable;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
@Nullable
|
||||
public World getWorld() {
|
||||
return Bukkit.getWorld(world);
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
public boolean isDiscoverable() {
|
||||
return discoverable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<RegionEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
public void setDiscoverable(boolean discoverable) {
|
||||
this.discoverable = discoverable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<RegionRequirement> getRequirements() {
|
||||
return requirements;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> getDiscoveredLore() {
|
||||
return discoveredLore;
|
||||
}
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public boolean alwaysShowTitles() {
|
||||
return alwaysShowTitles;
|
||||
}
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region title for a player. If region title is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of title
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getTitle(Player player) {
|
||||
if (title == null) {
|
||||
return Translations.DISCOVERED_TITLE.getList(player, customName);
|
||||
}
|
||||
@Nullable
|
||||
public List<RegionEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<RegionRequirement> getRequirements() {
|
||||
return requirements;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> getDiscoveredLore() {
|
||||
return discoveredLore;
|
||||
}
|
||||
|
||||
public boolean alwaysShowTitles() {
|
||||
return alwaysShowTitles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region title for a player. If region title is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of title
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getTitle(Player player) {
|
||||
if (title == null) {
|
||||
return Translations.DISCOVERED_TITLE.getList(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedTitle = new ArrayList<>();
|
||||
title.forEach(titles -> translatedTitle.add(ChatColor.translateAlternateColorCodes('&', titles)));
|
||||
return translatedTitle;
|
||||
}
|
||||
return translatedTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region subtitle for a player. If region subtitle is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of subtitles
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getSubtitle(Player player) {
|
||||
if (subtitle == null) {
|
||||
return Translations.DISCOVERED_SUBTITLE.getList(player, customName);
|
||||
}
|
||||
/**
|
||||
* Gets the region subtitle for a player. If region subtitle is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of subtitles
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getSubtitle(Player player) {
|
||||
if (subtitle == null) {
|
||||
return Translations.DISCOVERED_SUBTITLE.getList(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedSubtitle = new ArrayList<>();
|
||||
subtitle.forEach(sub -> translatedSubtitle.add(ChatColor.translateAlternateColorCodes('&', sub)));
|
||||
return translatedSubtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region discovered title for a player. If region title is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of title
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getDiscoveredTitle(Player player) {
|
||||
if (title == null) {
|
||||
return Translations.ALREADY_DISCOVERED_TITLE.getList(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedTitle = new ArrayList<>();
|
||||
discoveredTitle.forEach(titles -> translatedTitle.add(ChatColor.translateAlternateColorCodes('&', titles)));
|
||||
return translatedTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region discovered subtitle for a player. If region subtitle is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of subtitles
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getDiscoveredSubtitle(Player player) {
|
||||
if (discoveredSubtitle == null) {
|
||||
return Translations.ALREADY_DISCOVERED_SUBTITLE.getList(player, customName);
|
||||
}
|
||||
|
||||
List<String> translatedSubtitle = new ArrayList<>();
|
||||
discoveredSubtitle.forEach(sub -> translatedSubtitle.add(ChatColor.translateAlternateColorCodes('&', sub)));
|
||||
return translatedSubtitle;
|
||||
}
|
||||
List<String> translatedSubtitle = new ArrayList<>();
|
||||
subtitle.forEach(sub -> translatedSubtitle.add(ChatColor.translateAlternateColorCodes('&', sub)));
|
||||
return translatedSubtitle;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Regenerate getRegenerate() {
|
||||
return regenerate;
|
||||
}
|
||||
/**
|
||||
* Gets the region discovered title for a player. If region title is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of title
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getDiscoveredTitle(Player player) {
|
||||
if (title == null) {
|
||||
return Translations.ALREADY_DISCOVERED_TITLE.getList(player, customName);
|
||||
}
|
||||
|
||||
public void setRegenerate(@NotNull Regenerate regenerate) {
|
||||
this.regenerate = regenerate;
|
||||
}
|
||||
|
||||
public int getTeleportCooldown() {
|
||||
return teleportCooldown;
|
||||
}
|
||||
List<String> translatedTitle = new ArrayList<>();
|
||||
discoveredTitle.forEach(titles -> translatedTitle.add(ChatColor.translateAlternateColorCodes('&', titles)));
|
||||
return translatedTitle;
|
||||
}
|
||||
|
||||
public void setTeleportCooldown(int teleportCooldown) {
|
||||
this.teleportCooldown = teleportCooldown;
|
||||
}
|
||||
/**
|
||||
* Gets the region discovered subtitle for a player. If region subtitle is null, the translation files will be used.
|
||||
* @param player the player
|
||||
* @return A string list of subtitles
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getDiscoveredSubtitle(Player player) {
|
||||
if (discoveredSubtitle == null) {
|
||||
return Translations.ALREADY_DISCOVERED_SUBTITLE.getList(player, customName);
|
||||
}
|
||||
|
||||
public void save(RPGRegions plugin) throws IOException {
|
||||
File file = this.findFile(plugin);
|
||||
if (file == null) file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
Writer writer = new FileWriter(file);
|
||||
Gson gson = plugin.getGson();
|
||||
gson.toJson(this, writer);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
List<String> translatedSubtitle = new ArrayList<>();
|
||||
discoveredSubtitle.forEach(sub -> translatedSubtitle.add(ChatColor.translateAlternateColorCodes('&', sub)));
|
||||
return translatedSubtitle;
|
||||
}
|
||||
|
||||
public boolean delete(RPGRegions plugin) throws IOException {
|
||||
File file = this.findFile(plugin);
|
||||
if (file == null) file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
return file.delete();
|
||||
}
|
||||
@Nullable
|
||||
public Regenerate getRegenerate() {
|
||||
return regenerate;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private File findFile(RPGRegions plugin) throws IOException {
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
List<Path> valid = Files.walk(Paths.get(folder.getPath()))
|
||||
.filter(path -> Files.isRegularFile(path) && path.toFile().getName().equals(this.id + ".json"))
|
||||
.collect(Collectors.toList());
|
||||
if (valid.isEmpty()) return null;
|
||||
if (valid.size() > 1) {
|
||||
plugin.getLogger().severe("Duplicate region files have been found for " + this.id + ". " +
|
||||
"In order to protect your data, the plugin will NOT save the region config.");
|
||||
throw new IOException("Duplicate region file");
|
||||
}
|
||||
public void setRegenerate(@NotNull Regenerate regenerate) {
|
||||
this.regenerate = regenerate;
|
||||
}
|
||||
|
||||
File file = null;
|
||||
for (Path path : valid) {
|
||||
file = path.toFile();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
public int getTeleportCooldown() {
|
||||
return teleportCooldown;
|
||||
}
|
||||
|
||||
public void setTeleportCooldown(int teleportCooldown) {
|
||||
this.teleportCooldown = teleportCooldown;
|
||||
}
|
||||
|
||||
public void save(RPGRegions plugin) throws IOException {
|
||||
File file = this.findFile(plugin);
|
||||
if (file == null) file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
Writer writer = new FileWriter(file);
|
||||
Gson gson = plugin.getGson();
|
||||
gson.toJson(this, writer);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public boolean delete(RPGRegions plugin) throws IOException {
|
||||
File file = this.findFile(plugin);
|
||||
if (file == null) file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private File findFile(RPGRegions plugin) throws IOException {
|
||||
File folder = new File(plugin.getDataFolder() + "/regions/");
|
||||
List<Path> valid = Files.walk(Paths.get(folder.getPath()))
|
||||
.filter(path -> Files.isRegularFile(path) && path.toFile().getName().equals(this.id + ".json"))
|
||||
.collect(Collectors.toList());
|
||||
if (valid.isEmpty()) return null;
|
||||
if (valid.size() > 1) {
|
||||
plugin.getLogger().severe("Duplicate region files have been found for " + this.id + ". " +
|
||||
"In order to protect your data, the plugin will NOT save the region config.");
|
||||
throw new IOException("Duplicate region file");
|
||||
}
|
||||
|
||||
File file = null;
|
||||
for (Path path : valid) {
|
||||
file = path.toFile();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package net.islandearth.rpgregions.managers.data.region;
|
||||
|
||||
public interface Discovery {
|
||||
|
||||
/**
|
||||
* Gets the date this discovery was made.
|
||||
* @return date of discovery
|
||||
*/
|
||||
String getDate();
|
||||
/**
|
||||
* Gets the date this discovery was made.
|
||||
* @return date of discovery
|
||||
*/
|
||||
String getDate();
|
||||
|
||||
/**
|
||||
* Gets the name of the region that was discovered.
|
||||
* @return name of region discovered
|
||||
*/
|
||||
String getRegion();
|
||||
/**
|
||||
* Gets the name of the region that was discovered.
|
||||
* @return name of region discovered
|
||||
*/
|
||||
String getRegion();
|
||||
}
|
||||
|
||||
@@ -2,21 +2,21 @@ package net.islandearth.rpgregions.managers.data.region;
|
||||
|
||||
public class WorldDiscovery implements Discovery {
|
||||
|
||||
private String date;
|
||||
private String region;
|
||||
private String date;
|
||||
private String region;
|
||||
|
||||
public WorldDiscovery(String date, String region) {
|
||||
this.date = date;
|
||||
this.region = region;
|
||||
}
|
||||
public WorldDiscovery(String date, String region) {
|
||||
this.date = date;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
@Override
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
@Override
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,117 +22,117 @@ 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 rpgregions_discoveries (uuid varchar(32) NOT NULL, region varchar(32) NOT NULL, time varchar(64) NOT NULL, PRIMARY KEY(uuid, region))";
|
||||
private static final String SELECT_REGION = "SELECT * FROM rpgregions_discoveries WHERE uuid = ?";
|
||||
private static final String INSERT_DISCOVERY = "INSERT INTO rpgregions_discoveries (uuid, region, time) VALUES (?, ?, ?)";
|
||||
private static final String DELETE_DISCOVERIES = "DELETE * FROM rpgregions_discoveries WHERE uuid = ?";
|
||||
private static final String DELETE_DISCOVERY = "DELETE * FROM rpgregions_discoveries WHERE uuid = ? AND region = ?";
|
||||
|
||||
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS rpgregions_discoveries (uuid varchar(32) NOT NULL, region varchar(32) NOT NULL, time varchar(64) NOT NULL, PRIMARY KEY(uuid, region))";
|
||||
private static final String SELECT_REGION = "SELECT * FROM rpgregions_discoveries WHERE uuid = ?";
|
||||
private static final String INSERT_DISCOVERY = "INSERT INTO rpgregions_discoveries (uuid, region, time) VALUES (?, ?, ?)";
|
||||
private static final String DELETE_DISCOVERIES = "DELETE * FROM rpgregions_discoveries WHERE uuid = ?";
|
||||
private static final String DELETE_DISCOVERY = "DELETE * FROM rpgregions_discoveries WHERE uuid = ? AND region = ?";
|
||||
|
||||
public SqlStorage(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
|
||||
|
||||
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("settings.sql.host") + ":" + plugin.getConfig().getString("settings.sql.port")).build();
|
||||
Database db = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
|
||||
DB.setGlobalDatabase(db);
|
||||
try {
|
||||
db.executeUpdate(CREATE_TABLE);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private final RPGRegions plugin;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<RPGRegionsAccount> getAccount(UUID uuid) {
|
||||
// Add a check to ensure accounts aren't taking a long time
|
||||
long startTime = System.currentTimeMillis();
|
||||
CompletableFuture<RPGRegionsAccount> future = new CompletableFuture<>();
|
||||
if (cachedAccounts.containsKey(uuid)) {
|
||||
future.complete(cachedAccounts.get(uuid));
|
||||
} else {
|
||||
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (DbRow row : results) {
|
||||
String region = row.getString("region");
|
||||
regions.put(region, new WorldDiscovery(row.getString("time"), region));
|
||||
}
|
||||
public SqlStorage(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
RPGRegionsAccount account = new RPGRegionsAccount(uuid, regions);
|
||||
cachedAccounts.put(uuid, account);
|
||||
future.complete(account);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
if (totalTime >= 20) {
|
||||
plugin.getLogger().warning("Grabbing accounts is taking a long time! (" + totalTime + "ms)");
|
||||
}
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return future;
|
||||
}
|
||||
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("settings.sql.host") + ":" + plugin.getConfig().getString("settings.sql.port")).build();
|
||||
Database db = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
|
||||
DB.setGlobalDatabase(db);
|
||||
try {
|
||||
db.executeUpdate(CREATE_TABLE);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts() {
|
||||
return cachedAccounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscoveries(UUID uuid) {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveredRegions().clear()).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
DB.executeUpdateAsync(DELETE_DISCOVERIES, getDatabaseUuid(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscovery(UUID uuid, String regionId) {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveredRegions().remove(regionId)).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
@Override
|
||||
public CompletableFuture<RPGRegionsAccount> getAccount(UUID uuid) {
|
||||
// Add a check to ensure accounts aren't taking a long time
|
||||
long startTime = System.currentTimeMillis();
|
||||
CompletableFuture<RPGRegionsAccount> future = new CompletableFuture<>();
|
||||
if (cachedAccounts.containsKey(uuid)) {
|
||||
future.complete(cachedAccounts.get(uuid));
|
||||
} else {
|
||||
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (DbRow row : results) {
|
||||
String region = row.getString("region");
|
||||
regions.put(region, new WorldDiscovery(row.getString("time"), region));
|
||||
}
|
||||
|
||||
DB.executeUpdateAsync(DELETE_DISCOVERY, getDatabaseUuid(uuid), regionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAccount(UUID uuid) {
|
||||
this.clearDiscoveries(uuid);
|
||||
cachedAccounts.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCachedAccount(UUID uuid) {
|
||||
RPGRegionsAccount account = cachedAccounts.get(uuid);
|
||||
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
|
||||
List<String> current = new ArrayList<>();
|
||||
for (DbRow row : results) {
|
||||
current.add(row.getString("region"));
|
||||
}
|
||||
RPGRegionsAccount account = new RPGRegionsAccount(uuid, regions);
|
||||
cachedAccounts.put(uuid, account);
|
||||
future.complete(account);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
if (totalTime >= 20) {
|
||||
plugin.getLogger().warning("Grabbing accounts is taking a long time! (" + totalTime + "ms)");
|
||||
}
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
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);
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts() {
|
||||
return cachedAccounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscoveries(UUID uuid) {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveredRegions().clear()).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
DB.executeUpdateAsync(DELETE_DISCOVERIES, getDatabaseUuid(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscovery(UUID uuid, String regionId) {
|
||||
getAccount(uuid).thenAccept(account -> account.getDiscoveredRegions().remove(regionId)).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
DB.executeUpdateAsync(DELETE_DISCOVERY, getDatabaseUuid(uuid), regionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAccount(UUID uuid) {
|
||||
this.clearDiscoveries(uuid);
|
||||
cachedAccounts.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCachedAccount(UUID uuid) {
|
||||
RPGRegionsAccount account = cachedAccounts.get(uuid);
|
||||
DB.getResultsAsync(SELECT_REGION, getDatabaseUuid(uuid)).thenAccept(results -> {
|
||||
List<String> current = new ArrayList<>();
|
||||
for (DbRow row : results) {
|
||||
current.add(row.getString("region"));
|
||||
}
|
||||
|
||||
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);
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,130 +21,130 @@ import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class YamlStorage implements StorageManager {
|
||||
|
||||
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
|
||||
private ConcurrentMap<UUID, RPGRegionsAccount> cachedAccounts = new ConcurrentHashMap<>();
|
||||
|
||||
private final RPGRegions plugin;
|
||||
private final RPGRegions plugin;
|
||||
|
||||
public YamlStorage(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
File dataFile = new File(plugin.getDataFolder() + "/accounts/");
|
||||
dataFile.mkdirs();
|
||||
}
|
||||
public YamlStorage(RPGRegions plugin) {
|
||||
this.plugin = plugin;
|
||||
File dataFile = new File(plugin.getDataFolder() + "/accounts/");
|
||||
dataFile.mkdirs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<RPGRegionsAccount> getAccount(UUID uuid) {
|
||||
// Add a check to ensure accounts aren't taking a long time
|
||||
long startTime = System.currentTimeMillis();
|
||||
CompletableFuture<RPGRegionsAccount> future = new CompletableFuture<>();
|
||||
if (cachedAccounts.containsKey(uuid)) {
|
||||
future.complete(cachedAccounts.get(uuid));
|
||||
} else {
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (String results : config.getStringList("Discoveries")) {
|
||||
String[] data = results.split(";");
|
||||
String time = data[0];
|
||||
String region = data[1];
|
||||
regions.put(region, new WorldDiscovery(time, region));
|
||||
}
|
||||
@Override
|
||||
public CompletableFuture<RPGRegionsAccount> getAccount(UUID uuid) {
|
||||
// Add a check to ensure accounts aren't taking a long time
|
||||
long startTime = System.currentTimeMillis();
|
||||
CompletableFuture<RPGRegionsAccount> future = new CompletableFuture<>();
|
||||
if (cachedAccounts.containsKey(uuid)) {
|
||||
future.complete(cachedAccounts.get(uuid));
|
||||
} else {
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (String results : config.getStringList("Discoveries")) {
|
||||
String[] data = results.split(";");
|
||||
String time = data[0];
|
||||
String region = data[1];
|
||||
regions.put(region, new WorldDiscovery(time, region));
|
||||
}
|
||||
|
||||
RPGRegionsAccount account = new RPGRegionsAccount(uuid, regions);
|
||||
cachedAccounts.put(uuid, account);
|
||||
future.complete(account);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
if (totalTime >= 20) {
|
||||
plugin.getLogger().warning("Grabbing accounts is taking a long time! (" + totalTime + "ms)");
|
||||
}
|
||||
}
|
||||
return future;
|
||||
}
|
||||
RPGRegionsAccount account = new RPGRegionsAccount(uuid, regions);
|
||||
cachedAccounts.put(uuid, account);
|
||||
future.complete(account);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = endTime - startTime;
|
||||
if (totalTime >= 20) {
|
||||
plugin.getLogger().warning("Grabbing accounts is taking a long time! (" + totalTime + "ms)");
|
||||
}
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts() {
|
||||
return cachedAccounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscoveries(UUID uuid) {
|
||||
getAccount(uuid).thenAccept(account -> {
|
||||
account.getDiscoveredRegions().clear();
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
config.set("Discoveries", null);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscovery(UUID uuid, String regionId) {
|
||||
getAccount(uuid).thenAccept(account -> {
|
||||
account.getDiscoveredRegions().remove(regionId);
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (String results : config.getStringList("Discoveries")) {
|
||||
String[] data = results.split(";");
|
||||
String time = data[0];
|
||||
String region = data[1];
|
||||
regions.put(region, new WorldDiscovery(time, region));
|
||||
}
|
||||
|
||||
regions.remove(regionId);
|
||||
|
||||
List<String> newData = config.getStringList("Discoveries");
|
||||
newData.clear();
|
||||
for (Discovery region : regions.values()) {
|
||||
newData.add(region.getDate() + ";" + region.getRegion());
|
||||
}
|
||||
|
||||
config.set("Discoveries", newData);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAccount(UUID uuid) {
|
||||
this.clearDiscoveries(uuid);
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
file.delete();
|
||||
cachedAccounts.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCachedAccount(UUID uuid) {
|
||||
RPGRegionsAccount account = cachedAccounts.get(uuid);
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
@Override
|
||||
public ConcurrentMap<UUID, RPGRegionsAccount> getCachedAccounts() {
|
||||
return cachedAccounts;
|
||||
}
|
||||
|
||||
List<String> newData = new ArrayList<>();
|
||||
for (Discovery region : account.getDiscoveredRegions().values()) {
|
||||
newData.add(region.getDate() + ";" + region.getRegion());
|
||||
}
|
||||
@Override
|
||||
public void clearDiscoveries(UUID uuid) {
|
||||
getAccount(uuid).thenAccept(account -> {
|
||||
account.getDiscoveredRegions().clear();
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
config.set("Discoveries", newData);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cachedAccounts.remove(uuid);
|
||||
}
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
config.set("Discoveries", null);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDiscovery(UUID uuid, String regionId) {
|
||||
getAccount(uuid).thenAccept(account -> {
|
||||
account.getDiscoveredRegions().remove(regionId);
|
||||
}).exceptionally(t -> {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
});
|
||||
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
Map<String, Discovery> regions = new HashMap<>();
|
||||
for (String results : config.getStringList("Discoveries")) {
|
||||
String[] data = results.split(";");
|
||||
String time = data[0];
|
||||
String region = data[1];
|
||||
regions.put(region, new WorldDiscovery(time, region));
|
||||
}
|
||||
|
||||
regions.remove(regionId);
|
||||
|
||||
List<String> newData = config.getStringList("Discoveries");
|
||||
newData.clear();
|
||||
for (Discovery region : regions.values()) {
|
||||
newData.add(region.getDate() + ";" + region.getRegion());
|
||||
}
|
||||
|
||||
config.set("Discoveries", newData);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAccount(UUID uuid) {
|
||||
this.clearDiscoveries(uuid);
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
file.delete();
|
||||
cachedAccounts.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCachedAccount(UUID uuid) {
|
||||
RPGRegionsAccount account = cachedAccounts.get(uuid);
|
||||
File file = new File(plugin.getDataFolder() + "/accounts/" + uuid.toString() + ".yml");
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
List<String> newData = new ArrayList<>();
|
||||
for (Discovery region : account.getDiscoveredRegions().values()) {
|
||||
newData.add(region.getDate() + ";" + region.getRegion());
|
||||
}
|
||||
|
||||
config.set("Discoveries", newData);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cachedAccounts.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,137 +14,137 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum Translations {
|
||||
NEXT_PAGE("&aNext Page"),
|
||||
NEXT_PAGE_LORE("&fGo to the next page", true),
|
||||
PREVIOUS_PAGE("&cPrevious Page"),
|
||||
PREVIOUS_PAGE_LORE("&fGo to the previous page", true),
|
||||
REGIONS("Regions"),
|
||||
DISCOVERED_ON("&7Discovered on: %0"),
|
||||
DISCOVERED_TITLE("&d%0 discovered!", true),
|
||||
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!", true),
|
||||
ALREADY_DISCOVERED_TITLE("&d%0 entered!", true),
|
||||
ALREADY_DISCOVERED_SUBTITLE("&fAlready discovered!", true),
|
||||
TELEPORT("&aClick to teleport"),
|
||||
CANNOT_TELEPORT("&cWe can't teleport you because that world doesn't exist!"),
|
||||
UNKNOWN_REGION("Unknown Realm"),
|
||||
EXIT("&cExit"),
|
||||
EXIT_LORE("&fExit the GUI", true),
|
||||
CANNOT_ENTER("&cYou require %0 to enter this area."),
|
||||
COOLDOWN("&cThat is currently on cooldown.");
|
||||
NEXT_PAGE("&aNext Page"),
|
||||
NEXT_PAGE_LORE("&fGo to the next page", true),
|
||||
PREVIOUS_PAGE("&cPrevious Page"),
|
||||
PREVIOUS_PAGE_LORE("&fGo to the previous page", true),
|
||||
REGIONS("Regions"),
|
||||
DISCOVERED_ON("&7Discovered on: %0"),
|
||||
DISCOVERED_TITLE("&d%0 discovered!", true),
|
||||
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!", true),
|
||||
ALREADY_DISCOVERED_TITLE("&d%0 entered!", true),
|
||||
ALREADY_DISCOVERED_SUBTITLE("&fAlready discovered!", true),
|
||||
TELEPORT("&aClick to teleport"),
|
||||
CANNOT_TELEPORT("&cWe can't teleport you because that world doesn't exist!"),
|
||||
UNKNOWN_REGION("Unknown Realm"),
|
||||
EXIT("&cExit"),
|
||||
EXIT_LORE("&fExit the GUI", true),
|
||||
CANNOT_ENTER("&cYou require %0 to enter this area."),
|
||||
COOLDOWN("&cThat is currently on cooldown.");
|
||||
|
||||
private final String defaultValue;
|
||||
private final boolean isList;
|
||||
|
||||
Translations(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = false;
|
||||
}
|
||||
private final String defaultValue;
|
||||
private final boolean isList;
|
||||
|
||||
Translations(String defaultValue, boolean isList) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = isList;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
Translations(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = false;
|
||||
}
|
||||
|
||||
public boolean isList() {
|
||||
return isList;
|
||||
}
|
||||
Translations(String defaultValue, boolean isList) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.isList = isList;
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
return this.toString().toLowerCase();
|
||||
}
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void send(Player player) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
player.sendMessage(this.setPapi(player, message));
|
||||
}
|
||||
public boolean isList() {
|
||||
return isList;
|
||||
}
|
||||
|
||||
public void send(Player player, String... values) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
message = this.setPapi(player, replaceVariables(message, values));
|
||||
player.sendMessage(message);
|
||||
}
|
||||
private String getPath() {
|
||||
return this.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public void sendList(Player player) {
|
||||
List<String> messages = RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> player.sendMessage(this.setPapi(player, message)));
|
||||
}
|
||||
public void send(Player player) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
player.sendMessage(this.setPapi(player, message));
|
||||
}
|
||||
|
||||
public void sendList(Player player, String... values) {
|
||||
List<String> messages = RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> {
|
||||
message = this.setPapi(player, replaceVariables(message, values));
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
public void send(Player player, String... values) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
message = this.setPapi(player, replaceVariables(message, values));
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
public String get(Player player) {
|
||||
return this.setPapi(player, RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath()));
|
||||
}
|
||||
|
||||
public String get(Player player, String... values) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
message = replaceVariables(message, values);
|
||||
return this.setPapi(player, message);
|
||||
}
|
||||
public void sendList(Player player) {
|
||||
List<String> messages = RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> player.sendMessage(this.setPapi(player, message)));
|
||||
}
|
||||
|
||||
public List<String> getList(Player player) {
|
||||
List<String> list = new ArrayList<>();
|
||||
RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath()).forEach(text -> list.add(this.setPapi(player, text)));
|
||||
return list;
|
||||
}
|
||||
public void sendList(Player player, String... values) {
|
||||
List<String> messages = RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath());
|
||||
messages.forEach(message -> {
|
||||
message = this.setPapi(player, replaceVariables(message, values));
|
||||
player.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public List<String> getList(Player player, String... values) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
RPGRegions.getAPI().getTranslator()
|
||||
.getTranslationListFor(player, this.getPath())
|
||||
.forEach(message -> messages.add(this.setPapi(player, replaceVariables(message, values))));
|
||||
return messages;
|
||||
}
|
||||
|
||||
public static void generateLang(RPGRegions plugin) {
|
||||
File lang = new File(plugin.getDataFolder() + "/lang/");
|
||||
lang.mkdirs();
|
||||
|
||||
for (Language language : Language.values()) {
|
||||
try {
|
||||
plugin.saveResource("lang/" + language.getCode() + ".yml", false);
|
||||
plugin.getLogger().info("Generated " + language.getCode() + ".yml");
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
public String get(Player player) {
|
||||
return this.setPapi(player, RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath()));
|
||||
}
|
||||
|
||||
File file = new File(plugin.getDataFolder() + "/lang/" + language.getCode() + ".yml");
|
||||
if (file.exists()) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
for (Translations key : values()) {
|
||||
if (config.get(key.toString().toLowerCase()) == null) {
|
||||
plugin.getLogger().warning("No value in translation file for key "
|
||||
+ key.toString() + " was found. Regenerate language files?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public String get(Player player, String... values) {
|
||||
String message = RPGRegions.getAPI().getTranslator().getTranslationFor(player, this.getPath());
|
||||
message = replaceVariables(message, values);
|
||||
return this.setPapi(player, message);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String replaceVariables(String message, String... values) {
|
||||
String modifiedMessage = message;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) modifiedMessage = modifiedMessage.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
public List<String> getList(Player player) {
|
||||
List<String> list = new ArrayList<>();
|
||||
RPGRegions.getAPI().getTranslator().getTranslationListFor(player, this.getPath()).forEach(text -> list.add(this.setPapi(player, text)));
|
||||
return list;
|
||||
}
|
||||
|
||||
return modifiedMessage;
|
||||
}
|
||||
public List<String> getList(Player player, String... values) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
RPGRegions.getAPI().getTranslator()
|
||||
.getTranslationListFor(player, this.getPath())
|
||||
.forEach(message -> messages.add(this.setPapi(player, replaceVariables(message, values))));
|
||||
return messages;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String setPapi(Player player, String message) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
return PlaceholderAPI.setPlaceholders(player, message);
|
||||
}
|
||||
public static void generateLang(RPGRegions plugin) {
|
||||
File lang = new File(plugin.getDataFolder() + "/lang/");
|
||||
lang.mkdirs();
|
||||
|
||||
return message;
|
||||
}
|
||||
for (Language language : Language.values()) {
|
||||
try {
|
||||
plugin.saveResource("lang/" + language.getCode() + ".yml", false);
|
||||
plugin.getLogger().info("Generated " + language.getCode() + ".yml");
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
|
||||
File file = new File(plugin.getDataFolder() + "/lang/" + language.getCode() + ".yml");
|
||||
if (file.exists()) {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
for (Translations key : values()) {
|
||||
if (config.get(key.toString().toLowerCase()) == null) {
|
||||
plugin.getLogger().warning("No value in translation file for key "
|
||||
+ key.toString() + " was found. Regenerate language files?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String replaceVariables(String message, String... values) {
|
||||
String modifiedMessage = message;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (values.length > i) modifiedMessage = modifiedMessage.replaceAll("%" + i, values[i]);
|
||||
else break;
|
||||
}
|
||||
|
||||
return modifiedMessage;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String setPapi(Player player, String message) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
return PlaceholderAPI.setPlaceholders(player, message);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,26 +8,26 @@ import java.util.List;
|
||||
|
||||
public class TitleAnimator {
|
||||
|
||||
public TitleAnimator(Player player, RPGRegions plugin, List<String> titles, List<String> subtitles, int speed) {
|
||||
new BukkitRunnable() {
|
||||
int current = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
String title = current < titles.size() ? titles.get(current) : "";
|
||||
String subtitle = current < subtitles.size() ? subtitles.get(current) : "";
|
||||
if (current >= titles.size()
|
||||
&& current >= subtitles.size()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
public TitleAnimator(Player player, RPGRegions plugin, List<String> titles, List<String> subtitles, int speed) {
|
||||
new BukkitRunnable() {
|
||||
int current = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
String title = current < titles.size() ? titles.get(current) : "";
|
||||
String subtitle = current < subtitles.size() ? subtitles.get(current) : "";
|
||||
if (current >= titles.size()
|
||||
&& current >= subtitles.size()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendTitle(title,
|
||||
subtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadein"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.stay"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadeout"));
|
||||
current++;
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, speed);
|
||||
}
|
||||
player.sendTitle(title,
|
||||
subtitle,
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadein"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.stay"),
|
||||
plugin.getConfig().getInt("settings.server.discoveries.discovered.title.fadeout"));
|
||||
current++;
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, speed);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user