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

Update to 1.17, improvements to error handling

This commit is contained in:
SamB440
2021-06-11 21:34:31 +01:00
parent 512e961757
commit c0850abff3
13 changed files with 49 additions and 275 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="RPGRegions" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="net.islandearth" external.system.module.version="1.3.8" type="JAVA_MODULE" version="4">
<module external.linked.project.id="RPGRegions" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="net.islandearth" external.system.module.version="1.3.9" type="JAVA_MODULE" version="4">
<component name="ExternalSystem" externalSystem="GRADLE" externalSystemModuleGroup="net.islandearth" externalSystemModuleVersion="1.3.3" linkedProjectId="RPGRegions" linkedProjectPath="$MODULE_DIR$" rootProjectPath="$MODULE_DIR$" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_16" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />

View File

@@ -53,7 +53,7 @@ dependencies {
implementation 'com.gitlab.samb440:languagy:2.0.3-RELEASE' // languagy
implementation 'io.papermc:paperlib:1.0.4' // paperlib - async teleport on Paper
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' // spigot
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' // spigot
compileOnly 'com.github.MilkBowl:VaultAPI:1.7' // vault
compileOnly 'me.clip:placeholderapi:2.10.4' // PAPI
compileOnly name: 'AlonsoLevels_v2.0-BETA' // alonsolevels

View File

@@ -26,8 +26,6 @@ public enum IntegrationType {
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((JavaPlugin) plugin);
return Optional.empty();
}

View File

@@ -6,8 +6,8 @@ plugins {
group = pluginGroup
version = pluginVersion
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
java.sourceCompatibility = JavaVersion.VERSION_16
java.targetCompatibility = JavaVersion.VERSION_16
repositories {
mavenCentral()
@@ -73,4 +73,4 @@ import org.apache.tools.ant.filters.ReplaceTokens
processResources {
filter ReplaceTokens, tokens: [version: version]
}
}

View File

@@ -1,4 +1,4 @@
pluginGroup=net.islandearth
pluginVersion=1.3.8
pluginVersion=1.3.9
# Set to false if you don't have access to the UltraRegions API jar to make the plugin compilable. The purchased plugin has support for it.
ultraRegionsSupport=true

View File

@@ -56,7 +56,7 @@ dependencies {
exclude group: 'com.destroystokyo.paper'
exclude group: 'org.spigotmc'
}
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' // spigot
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' // spigot
compileOnly name: 'Residence4.9.2.2' // residence
compileOnly name: 'GriefPrevention' // griefprevention
if (ultraRegionsSupport) compileOnly name: 'UltraRegions' // ultraregions

View File

@@ -2,6 +2,9 @@ plugins {
id 'java'
}
group = pluginGroup
version = pluginVersion
repositories {
mavenCentral()
mavenLocal()
@@ -47,7 +50,7 @@ repositories {
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.5'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.15:0.3.0-SNAPSHOT'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.0.0'
testImplementation 'org.reflections:reflections:0.9.12'
implementation 'com.github.WesJD.AnvilGUI:anvilgui:bb60945f7a' // anvilgui
@@ -69,7 +72,7 @@ dependencies {
exclude group: 'org.bukkit'
exclude group: 'org.spigotmc'
}
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' // spigot
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' // spigot
compileOnly 'me.clip:placeholderapi:2.10.4' // PAPI
compileOnly 'com.github.MilkBowl:VaultAPI:1.7' // vault
compileOnly name: 'AlonsoLevels_v2.0-BETA' // alonsolevels
@@ -90,3 +93,10 @@ javadoc {
exclude 'net/islandearth/rpgregions/commands/**'
exclude 'net/islandearth/rpgregions/utils/**'
}
import org.apache.tools.ant.filters.ReplaceTokens
processResources {
filter ReplaceTokens, tokens: [version: version]
}

View File

@@ -18,6 +18,7 @@ import net.islandearth.rpgregions.commands.RPGRegionsDebugCommand;
import net.islandearth.rpgregions.effects.PotionRegionEffect;
import net.islandearth.rpgregions.effects.RegionEffect;
import net.islandearth.rpgregions.effects.RegionEffectRegistry;
import net.islandearth.rpgregions.exception.CouldNotStartException;
import net.islandearth.rpgregions.gson.AbstractAdapter;
import net.islandearth.rpgregions.gson.ItemStackAdapter;
import net.islandearth.rpgregions.gson.LocationAdapter;
@@ -98,9 +99,8 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI, Lang
this.generateLang();
try {
this.managers = new RPGRegionsManagers(this);
} catch (ReflectiveOperationException | IOException e) {
getLogger().severe("Error starting managers: ");
e.printStackTrace();
} catch (ReflectiveOperationException | IOException | CouldNotStartException e) {
getLogger().log(Level.SEVERE, "Error starting managers, please report this!", e);
Bukkit.getPluginManager().disablePlugin(this);
return;
}

View File

@@ -0,0 +1,8 @@
package net.islandearth.rpgregions.exception;
public class CouldNotStartException extends Exception {
public CouldNotStartException(final String message) {
super(message);
}
}

View File

@@ -1,248 +0,0 @@
package net.islandearth.rpgregions.gui;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
import com.github.stefvanschie.inventoryframework.pane.util.Mask;
import me.arcaniax.hdb.api.HeadDatabaseAPI;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.editor.ClassEditor;
import net.islandearth.rpgregions.editor.field.EditField;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.translation.Translations;
import net.islandearth.rpgregions.utils.ItemStackBuilder;
import net.islandearth.rpgregions.utils.XMaterial;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @deprecated It is preferable to use the new RegionCreateGUI class.
* This will be removed in version 1.3.6.
* @see net.islandearth.rpgregions.gui.RegionCreateGUI
*/
@Deprecated
public class EditorGUI extends RPGRegionsGUI {
private final RPGRegions plugin;
private final Player player;
private final ConfiguredRegion region;
private final ChestGui gui;
public EditorGUI(RPGRegions plugin, Player player, ConfiguredRegion region) {
super(plugin, player);
this.plugin = plugin;
this.player = player;
this.region = region;
this.gui = new ChestGui(6, region.getCustomName());
gui.setOnGlobalClick(click -> click.setCancelled(true));
ClassEditor classEditor = new ClassEditor(region);
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));
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()));
gui.addPane(innerPane);
}
// 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));
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(oPane);
}
// 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();
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);
// 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();
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);
// 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()));
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)");
}), 0, 0);
gui.addPane(exit);
}
gui.addPane(back);
gui.addPane(forward);
List<GuiItem> guiItems = new ArrayList<>();
for (EditField editField : classEditor.getEditable()) {
ItemStack itemStack = new ItemStackBuilder(editField.getMaterial().parseMaterial(true))
.withName(ChatColor.GREEN + editField.getName())
.withLore(Arrays.asList(ChatColor.WHITE + editField.getDescription(),
ChatColor.GRAY + editField.getValue().getClass().getSimpleName().toLowerCase()))
.build();
if (editField.getValue() instanceof Boolean) {
Boolean bool = (Boolean) editField.getValue();
if (bool) {
itemStack.setType(XMaterial.LIME_DYE.parseMaterial(true));
} else {
itemStack.setType(XMaterial.GRAY_DYE.parseMaterial(true));
}
}
try {
if (editField.getField().get(region) instanceof Location) {
guiItems.add(new GuiItem(itemStack, event -> {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(editField.setValue(player.getLocation())));
this.open();
}));
} else if (editField.getField().get(region) instanceof Boolean) {
Boolean bool = (Boolean) editField.getField().get(region);
guiItems.add(new GuiItem(itemStack, event -> {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(editField.setValue(!bool)));
player.closeInventory();
new EditorGUI(plugin, player, region).open();
}));
} else {
guiItems.add(new GuiItem(itemStack, event -> {
new AnvilGUI.Builder()
.onComplete((responder, text) -> {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(editField.setValue(text)));
Bukkit.getScheduler().runTaskLater(plugin, this::open, 20L);
return AnvilGUI.Response.close();
})
.preventClose()
.text(region.getCustomName())
.itemLeft(new ItemStack(Material.NAME_TAG))
.title("Set display name") // only works in 1.14+
.plugin(plugin)
.open(player);
}));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
pane.populateWithGuiItems(guiItems);
gui.addPane(pane);
}
@Override
public void render() {
}
@Override
public ChestGui getGui() {
return gui;
}
}

View File

@@ -8,6 +8,7 @@ import net.islandearth.rpgregions.command.IconCommand;
import net.islandearth.rpgregions.effects.PotionRegionEffect;
import net.islandearth.rpgregions.effects.RegionEffect;
import net.islandearth.rpgregions.effects.RegionEffectRegistry;
import net.islandearth.rpgregions.exception.CouldNotStartException;
import net.islandearth.rpgregions.gui.element.BooleanGuiFieldElement;
import net.islandearth.rpgregions.gui.element.GuiFieldElementRegistry;
import net.islandearth.rpgregions.gui.element.IGuiFieldElementRegistry;
@@ -55,28 +56,34 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class RPGRegionsManagers implements IRPGRegionsManagers {
private IStorageManager storageManager;
private IntegrationManager integrationManager;
private final IntegrationManager integrationManager;
private final IRPGRegionsCache regionsCache;
private final IRegenerationManager regenerationManager;
private final Map<Class<? extends RPGRegionsRegistry<?>>, RPGRegionsRegistry<?>> registry;
private final IGuiFieldElementRegistry guiFieldElementRegistry;
public RPGRegionsManagers(RPGRegions plugin) throws ReflectiveOperationException, IllegalStateException, IOException {
public RPGRegionsManagers(RPGRegions plugin) throws ReflectiveOperationException, CouldNotStartException, IOException {
StorageType.valueOf(plugin.getConfig().getString("settings.storage.mode").toUpperCase())
.get()
.ifPresent(storageManager1 -> storageManager = storageManager1);
if (storageManager == null) throw new IllegalStateException("Could not find StorageManager!");
if (storageManager == null) throw new CouldNotStartException("Could not find StorageManager!");
IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase())
.get(plugin)
.ifPresent(integrationManager1 -> integrationManager = integrationManager1);
Optional<IntegrationManager> integrationManager = IntegrationType.valueOf(plugin.getConfig().getString("settings.integration.name").toUpperCase())
.get(plugin);
if (integrationManager.isPresent()) {
this.integrationManager = integrationManager.get();
} else {
throw new CouldNotStartException("Unable to load IntegrationManager. The requested plugin is not enabled.");
}
this.regionsCache = new RPGRegionsCache(plugin);
this.registry = new ConcurrentHashMap<>();
@@ -121,9 +128,11 @@ public class RPGRegionsManagers implements IRPGRegionsManagers {
.collect(Collectors.toList())
.forEach(path -> {
File file = path.toFile();
plugin.debug("Walking file tree: " + file);
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.");
"In order to protect your data, the plugin will NOT load the duplicate region config " +
"(which is " + file + ").");
return;
}
// Exclude non-json files
@@ -132,8 +141,7 @@ public class RPGRegionsManagers implements IRPGRegionsManagers {
ConfiguredRegion region = plugin.getGson().fromJson(reader, ConfiguredRegion.class);
if (!region.getId().equals("exampleconfig")) regionsCache.addConfiguredRegion(region);
} catch (Exception e) {
plugin.getLogger().severe("Error loading region config " + file.getName() + ":");
e.printStackTrace();
plugin.getLogger().log(Level.SEVERE, "Error loading region config " + file.getName() + ".", e);
}
}
});

View File

@@ -31,7 +31,6 @@ public abstract class SQLCommonStorage implements IStorageManager {
public SQLCommonStorage(RPGRegions plugin) {
this.plugin = plugin;
}
@Override

View File

@@ -1,4 +1,3 @@
include 'rpgregions'
include 'modern'
include 'api'
include 'api'