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

Allow regions to show coords

This commit is contained in:
SamB440
2020-01-17 20:45:11 +00:00
parent 2a351cca31
commit abc2556ea3
3 changed files with 38 additions and 8 deletions

View File

@@ -58,17 +58,19 @@ public class RPGRegionsCommand extends BaseCommand {
@Subcommand("add")
@CommandPermission("rpgregions.add")
public void onAdd(CommandSender sender, String[] args) {
public void onAdd(Player player, String[] args) {
if (args.length == 1) {
String region = args[0];
ConfiguredRegion configuredRegion = new ConfiguredRegion(region, region, new ArrayList<>());
int x = player.getLocation().getBlockX();
int z = player.getLocation().getBlockZ();
ConfiguredRegion configuredRegion = new ConfiguredRegion(region, region, new ArrayList<>(), x, z);
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
sender.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
sender.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
+ region
+ " to edit it!"));
} else {
sender.sendMessage(StringUtils.colour("&cUsage: /rpgregions add <region>"));
player.sendMessage(StringUtils.colour("&cUsage: /rpgregions add <region>"));
}
}
@@ -166,9 +168,13 @@ public class RPGRegionsCommand extends BaseCommand {
? Translations.DISCOVERED_ON.get(player,
account.getDiscoveredRegions().get(configuredRegion.getId()).getDate())
: "";
String lore2 = configuredRegion.isShowCoords()
? ChatColor.GRAY + "" + configuredRegion.getX() + ", " + configuredRegion.getZ()
: "";
items.add(new GuiItem(new ItemStackBuilder(configuredRegion.getIcon())
.withName(colour + configuredRegion.getCustomName())
.withLore(lore)
.withLore(lore2)
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
.build(),
event -> event.setCancelled(true)));

View File

@@ -49,7 +49,9 @@ public class RPGRegionsManagers {
rewards.add(new ConsoleCommandReward("say Server sees you discovered a region!"));
ConfiguredRegion configuredRegion = new ConfiguredRegion("exampleconfig", "ExampleConfig", rewards,
Sound.AMBIENT_UNDERWATER_EXIT,
Material.WOODEN_AXE);
Material.WOODEN_AXE,
0,
0);
try {
configuredRegion.save(plugin);
} catch (IOException e) {

View File

@@ -19,21 +19,31 @@ public class ConfiguredRegion {
private final List<DiscoveryReward> rewards;
private final Sound sound;
private final Material icon;
private final boolean showCoords;
private final int x;
private final int z;
public ConfiguredRegion(String id, String customName, List<DiscoveryReward> rewards) {
public ConfiguredRegion(String id, String customName, List<DiscoveryReward> rewards, int x, int z) {
this.id = id;
this.customName = customName;
this.rewards = rewards;
this.sound = Sound.UI_TOAST_CHALLENGE_COMPLETE;
this.icon = Material.TOTEM_OF_UNDYING;
this.showCoords = false;
this.x = x;
this.z = z;
}
public ConfiguredRegion(String id, String customName, List<DiscoveryReward> rewards, Sound sound, Material icon) {
public ConfiguredRegion(String id, String customName,
List<DiscoveryReward> rewards, Sound sound, Material icon, int x, int z) {
this.id = id;
this.customName = customName;
this.rewards = rewards;
this.sound = sound;
this.icon = icon;
this.showCoords = false;
this.x = x;
this.z = z;
}
public String getId() {
@@ -56,6 +66,18 @@ public class ConfiguredRegion {
return icon;
}
public int getX() {
return x;
}
public int getZ() {
return z;
}
public boolean isShowCoords() {
return showCoords;
}
public void save(RPGRegions plugin) throws IOException {
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
Writer writer = new FileWriter(file);