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

Update javadocs, add WIP chests

This commit is contained in:
SamB440
2020-06-14 17:59:49 +01:00
parent 8bbe74b25d
commit 5d84675b31
8 changed files with 97 additions and 8 deletions

View File

@@ -0,0 +1,8 @@
package net.islandearth.rpgregions.chests;
import org.bukkit.Location;
public abstract class RegionChest {
public abstract Location getChestLocation();
}

View File

@@ -0,0 +1,28 @@
package net.islandearth.rpgregions.chests;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class RespawnableChest extends RegionChest {
private final Location location;
private final int respawnTime;
private final List<ItemStack> items;
public RespawnableChest(Location location, int respawnTime, List<ItemStack> items) {
this.location = location;
this.respawnTime = respawnTime;
this.items = items;
}
public int getRespawnTime() {
return respawnTime;
}
@Override
public Location getChestLocation() {
return location;
}
}

View File

@@ -15,6 +15,7 @@ import net.islandearth.rpgregions.commands.RPGRegionsCommand;
import net.islandearth.rpgregions.effects.RegionEffect;
import net.islandearth.rpgregions.gson.AbstractAdapter;
import net.islandearth.rpgregions.gson.ItemStackAdapter;
import net.islandearth.rpgregions.gson.LocationAdapter;
import net.islandearth.rpgregions.gson.PotionEffectAdapter;
import net.islandearth.rpgregions.listener.ConnectionListener;
import net.islandearth.rpgregions.listener.MoveListener;
@@ -29,6 +30,7 @@ import net.islandearth.rpgregions.utils.XMaterial;
import net.islandearth.rpgregions.utils.XSound;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
@@ -79,7 +81,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
e.printStackTrace();
}
});
// Close database connection
DB.close();
}
@@ -207,6 +209,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
.registerTypeAdapter(RegionRequirement.class, new AbstractAdapter<RegionRequirement>(null))
.registerTypeHierarchyAdapter(PotionEffect.class, new PotionEffectAdapter(this))
.registerTypeHierarchyAdapter(ItemStack.class, new ItemStackAdapter())
.registerTypeHierarchyAdapter(Location.class, new LocationAdapter())
.setPrettyPrinting()
.serializeNulls().create();
}
@@ -231,6 +234,8 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
return "Residence";
} else if (Bukkit.getPluginManager().getPlugin("GriefPrevention") != null) {
return "GriefPrevention";
} else if (Bukkit.getPluginManager().getPlugin("PlotSquared") != null) {
return "PlotSquared";
}
return "WorldGuard";
}

View File

@@ -2,6 +2,7 @@ package net.islandearth.rpgregions.api.integrations;
import net.islandearth.rpgregions.RPGRegions;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Optional;
@@ -20,12 +21,16 @@ public enum IntegrationType {
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...");
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.");

View File

@@ -0,0 +1,34 @@
package net.islandearth.rpgregions.gson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
import org.bukkit.Location;
import java.lang.reflect.Type;
import java.util.Map;
public class LocationAdapter implements JsonSerializer<Location>, JsonDeserializer<Location> {
private final Gson gson;
public LocationAdapter() {
this.gson = new GsonBuilder().create();
}
@Override
public Location deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
return Location.deserialize(gson.fromJson(jsonElement, new TypeToken<Map<String, Object>>(){}.getType()));
}
@Override
public JsonElement serialize(Location location, Type type, JsonSerializationContext context) {
return gson.toJsonTree(location.serialize());
}
}

View File

@@ -1,12 +1,17 @@
package net.islandearth.rpgregions.gui;
import com.github.stefvanschie.inventoryframework.Gui;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.translation.Translations;
import org.bukkit.entity.Player;
public class EditorGUI extends RPGRegionsGUI {
private final Gui gui;
public EditorGUI(RPGRegions plugin, Player player) {
super(plugin, player);
this.gui = new Gui(plugin, 6, Translations.REGIONS.get(player));
}
@Override

View File

@@ -120,13 +120,13 @@ public class ConfiguredRegion {
return sound;
}
@NotNull
@Nullable
public ItemStack getIcon() {
if (icon == null) return new ItemStack(XMaterial.TOTEM_OF_UNDYING.parseMaterial(true));
return icon.parseItem(true);
}
@NotNull
@Nullable
public ItemStack getUndiscoveredIcon() {
if (undiscoveredIcon == null) return new ItemStack(XMaterial.TOTEM_OF_UNDYING.parseMaterial(true));
return undiscoveredIcon.parseItem(true);
@@ -213,7 +213,7 @@ public class ConfiguredRegion {
/**
* Gets the region title for a player. If region title is null, the translation files will be used.
* @param player
* @param player the player
* @return A string list of title
*/
@NotNull
@@ -229,7 +229,7 @@ public class ConfiguredRegion {
/**
* Gets the region subtitle for a player. If region subtitle is null, the translation files will be used.
* @param player
* @param player the player
* @return A string list of subtitles
*/
@NotNull

View File

@@ -1,6 +1,7 @@
package net.islandearth.rpgregions.utils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@@ -11,6 +12,7 @@ import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -24,8 +26,10 @@ public class ItemStackBuilder {
this.ITEM_STACK = new ItemStack(mat);
}
public ItemStackBuilder(ItemStack item) {
this.ITEM_STACK = item;
public ItemStackBuilder(@Nullable ItemStack item) {
this.ITEM_STACK = item == null
? new ItemStackBuilder(new ItemStack(Material.BARRIER)).withName(ChatColor.RED + "Item is null").build()
: item;
}
public ItemStackBuilder withAmount(int amount) {