mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-28 03:09:14 +00:00
Start inventory work, add more config, relocate inventoryframework
This commit is contained in:
@@ -45,6 +45,7 @@ dependencies {
|
||||
shadowJar {
|
||||
relocate 'co.aikar.commands', 'net.islandearth.rpgmap.libs.acf'
|
||||
relocate 'co.aikar.idb', 'net.islandearth.rpgmap.libs.idb'
|
||||
relocate 'com.github.stefvanschie.inventoryframework', 'net.islandearth.inventoryframework'
|
||||
}
|
||||
|
||||
javadoc {
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.islandearth.rpgregions.api.event.RegionsEnterEvent;
|
||||
import net.islandearth.rpgregions.api.integrations.IntegrationManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
@@ -47,11 +46,11 @@ public class WorldGuardIntegration implements IntegrationManager {
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(Location location) {
|
||||
Set<ProtectedRegion> regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(location.getWorld())).getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ())).getRegions();
|
||||
return regions;
|
||||
}
|
||||
|
||||
private Set<ProtectedRegion> getProtectedRegions(World world) {
|
||||
return getProtectedRegions(world.getSpawnLocation());
|
||||
return WorldGuard.getInstance()
|
||||
.getPlatform()
|
||||
.getRegionContainer()
|
||||
.get(BukkitAdapter.adapt(location.getWorld()))
|
||||
.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ()))
|
||||
.getRegions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@ import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.github.stefvanschie.inventoryframework.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
|
||||
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -27,33 +33,81 @@ public class RPGRegionsCommand extends BaseCommand {
|
||||
|
||||
@Subcommand("add")
|
||||
public void onAdd(Player player, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
String region = args[0];
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(region, new ArrayList<>());
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
||||
player.sendMessage(ChatColor.GREEN + "Added configured region " + region + "!");
|
||||
player.sendMessage(ChatColor.YELLOW + "" + ChatColor.ITALIC+ "Now use /rpgregions edit " + region + " to edit it!");
|
||||
break;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
String region = args[0];
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion(region, region, new ArrayList<>());
|
||||
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
||||
player.sendMessage(ChatColor.GREEN + "Added configured region " + region + "!");
|
||||
player.sendMessage(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Now use /rpgregions edit " + region + " to edit it!");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /rpgregions add <region>");
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
player.sendMessage(ChatColor.RED + "Usage: /rpgregions add <region>");
|
||||
break;
|
||||
@Subcommand("remove")
|
||||
public void onRemove(Player player, String[] args) {
|
||||
if (args.length == 1) {
|
||||
String region = args[0];
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region);
|
||||
if (configuredRegion != null) {
|
||||
configuredRegion.delete(plugin);
|
||||
plugin.getManagers().getRegionsCache().removeConfiguredRegion(region);
|
||||
player.sendMessage(ChatColor.RED + "Removed configured region " + region + "!");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "A region by that name is not yet configured.");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /rpgregions add <region>");
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("edit")
|
||||
public void onEdit(Player player, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
//TODO gui
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
player.sendMessage(ChatColor.RED + "Usage: /rpgregions edit <region>");
|
||||
break;
|
||||
if (args.length == 1) {//TODO gui
|
||||
String region = args[0];
|
||||
Gui gui = new Gui(plugin, 9, "Editing: " + region);
|
||||
player.openInventory(gui.getInventory());
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /rpgregions edit <region>");
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("list")
|
||||
public void onList(Player player, String[] args) {
|
||||
Gui gui = new Gui(plugin, 45, "Regions");
|
||||
PaginatedPane pane = new PaginatedPane(0, 0, 9, 5);
|
||||
StaticPane back = new StaticPane(2, 5, 1, 1);
|
||||
StaticPane forward = new StaticPane(6, 5, 1, 1);
|
||||
|
||||
back.addItem(new GuiItem(new ItemStack(Material.ARROW), event -> {
|
||||
pane.setPage(pane.getPage() - 1);
|
||||
|
||||
if (pane.getPage() == 0) {
|
||||
back.setVisible(false);
|
||||
}
|
||||
|
||||
forward.setVisible(true);
|
||||
gui.update();
|
||||
}), 0, 0);
|
||||
|
||||
back.setVisible(false);
|
||||
|
||||
forward.addItem(new GuiItem(new ItemStack(Material.ARROW), event -> {
|
||||
pane.setPage(pane.getPage() + 1);
|
||||
|
||||
if (pane.getPage() == pane.getPages() - 1) {
|
||||
forward.setVisible(false);
|
||||
}
|
||||
|
||||
back.setVisible(true);
|
||||
gui.update();
|
||||
}), 0, 0);
|
||||
|
||||
gui.addPane(back);
|
||||
gui.addPane(forward);
|
||||
|
||||
plugin.getManagers().getRegionsCache().getConfiguredRegions().forEach((id, config) -> {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class RPGRegionsManagers {
|
||||
|
||||
List<DiscoveryReward> rewards = new ArrayList<>();
|
||||
rewards.add(new ExperienceReward(10));
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion("docks-1", rewards);
|
||||
ConfiguredRegion configuredRegion = new ConfiguredRegion("docks-1", "Docks", rewards);
|
||||
regionsCache.addConfiguredRegion(configuredRegion);
|
||||
try {
|
||||
configuredRegion.save(plugin);
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.islandearth.rpgregions.managers.data.region;
|
||||
import com.google.gson.Gson;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.rewards.DiscoveryReward;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -12,30 +14,48 @@ import java.util.List;
|
||||
|
||||
public class ConfiguredRegion {
|
||||
|
||||
private String id;
|
||||
private List<DiscoveryReward> rewards;
|
||||
private final String id;
|
||||
private final String customName;
|
||||
private final List<DiscoveryReward> rewards;
|
||||
private final Sound sound;
|
||||
private final Material icon;
|
||||
|
||||
public ConfiguredRegion(String id, List<DiscoveryReward> rewards) {
|
||||
public ConfiguredRegion(String id, String customName, List<DiscoveryReward> rewards) {
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
this.rewards = rewards;
|
||||
this.sound = Sound.UI_TOAST_CHALLENGE_COMPLETE;
|
||||
this.icon = Material.TOTEM_OF_UNDYING;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
public ConfiguredRegion(String id, String customName, List<DiscoveryReward> rewards, Sound sound, Material icon) {
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
this.rewards = rewards;
|
||||
this.sound = sound;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setRewards(List<DiscoveryReward> rewards) {
|
||||
this.rewards = rewards;
|
||||
public String getCustomName() {
|
||||
return customName;
|
||||
}
|
||||
|
||||
public List<DiscoveryReward> getRewards() {
|
||||
return rewards;
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
public Material getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void save(RPGRegions plugin) throws IOException {
|
||||
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
Writer writer = new FileWriter(file);
|
||||
@@ -44,4 +64,9 @@ public class ConfiguredRegion {
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public void delete(RPGRegions plugin) {
|
||||
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user