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

Add PaperLib (async), allow region teleportation, add per-world config, remove empty lore lines

This commit is contained in:
SamB440
2020-01-26 18:45:37 +00:00
parent b6b7ab1573
commit ff8a1d7217
8 changed files with 71 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
<?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.0.3" 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.0.4" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">

View File

@@ -51,6 +51,7 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.6' // apache commons (included as it has changed in versions)
implementation 'com.github.stefvanschie.inventoryframework:IF:0.5.17' // inventory framework
implementation 'org.bstats:bstats-bukkit:1.5' // plugin stats
implementation "io.papermc:paperlib:1.0.2" // paperlib - async teleport on Paper
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.2-SNAPSHOT' // worldguard
compileOnly 'me.clip:placeholderapi:2.10.4' // PAPI
compileOnly name: 'languagy-1.2.6' // languagy
@@ -61,6 +62,7 @@ shadowJar {
relocate 'co.aikar.idb', 'net.islandearth.rpgregions.libs.idb'
relocate 'com.github.stefvanschie.inventoryframework', 'net.islandearth.rpgregions.inventoryframework'
relocate 'org.bstats', 'net.islandearth.rpgregions.bstats'
relocate 'io.papermc.lib', 'net.islandearth.rpgregions.paperlib'
}
javadoc {

View File

@@ -1,2 +1,2 @@
pluginGroup=net.islandearth
pluginVersion=1.0.3
pluginVersion=1.0.4

View File

@@ -9,6 +9,7 @@ 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 io.papermc.lib.PaperLib;
import net.islandearth.rpgregions.RPGRegions;
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.rewards.ItemReward;
@@ -17,6 +18,7 @@ import net.islandearth.rpgregions.utils.ItemStackBuilder;
import net.islandearth.rpgregions.utils.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -64,8 +66,9 @@ public class RPGRegionsCommand extends BaseCommand {
if (args.length == 1) {
String region = args[0];
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
ConfiguredRegion configuredRegion = new ConfiguredRegion(region, region, new ArrayList<>(), x, z);
ConfiguredRegion configuredRegion = new ConfiguredRegion(player.getWorld(), region, region, new ArrayList<>(), x, y, z);
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
@@ -172,21 +175,43 @@ public class RPGRegionsCommand extends BaseCommand {
String lore = account.getDiscoveredRegions().containsKey(configuredRegion.getId())
? Translations.DISCOVERED_ON.get(player,
account.getDiscoveredRegions().get(configuredRegion.getId()).getDate())
: "";
String lore2 = configuredRegion.isShowCoords() && player.hasPermission("rpgregions.showloc")
: null;
String lore2 = configuredRegion.isShowCoords()
&& player.hasPermission("rpgregions.showloc")
? ChatColor.GRAY + "" + configuredRegion.getX() + ", " + configuredRegion.getZ()
: "";
String hint = configuredRegion.isShowHint() && player.hasPermission("rpgregions.showhint")
: null;
String hint = configuredRegion.isShowHint()
&& player.hasPermission("rpgregions.showhint")
&& !hasDiscovered
? ChatColor.translateAlternateColorCodes('&', configuredRegion.getHint())
: "";
: null;
String teleport = configuredRegion.isTeleportable()
&& player.hasPermission("rpgregions.teleport")
&& hasDiscovered
? Translations.TELEPORT.get(player)
: null;
items.add(new GuiItem(new ItemStackBuilder(configuredRegion.getIcon())
.withName(colour + configuredRegion.getCustomName())
.withLore(lore)
.withLore(lore2)
.withLore(hint)
.withLore(" ")
.withLore(teleport)
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
.build(),
event -> event.setCancelled(true)));
event -> {
if (configuredRegion.isTeleportable()
&& player.hasPermission("rpgregions.teleport")
&& hasDiscovered) {
int x = configuredRegion.getX();
int y = configuredRegion.getY();
int z = configuredRegion.getZ();
if (configuredRegion.getWorld() == null) Translations.CANNOT_TELEPORT.send(player);
else PaperLib.teleportAsync(player, new Location(configuredRegion.getWorld(), x, y, z));
}
event.setCancelled(true);
}));
}
pane.populateWithGuiItems(items);

View File

@@ -49,10 +49,11 @@ public class RPGRegionsManagers {
rewards.add(new ItemReward(new ItemStack(Material.IRON_BARS)));
rewards.add(new PlayerCommandReward("say I discovered a region!"));
rewards.add(new ConsoleCommandReward("say Server sees you discovered a region!"));
ConfiguredRegion configuredRegion = new ConfiguredRegion("exampleconfig", "ExampleConfig", rewards,
ConfiguredRegion configuredRegion = new ConfiguredRegion(null, "exampleconfig", "ExampleConfig", rewards,
Sound.AMBIENT_UNDERWATER_EXIT,
Material.WOODEN_AXE,
0,
0,
0);
try {
configuredRegion.save(plugin);

View File

@@ -3,17 +3,22 @@ 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.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.UUID;
public class ConfiguredRegion {
private final UUID world;
private final String id;
private final String customName;
private final List<DiscoveryReward> rewards;
@@ -21,11 +26,15 @@ public class ConfiguredRegion {
private final Material icon;
private final boolean showCoords;
private final int x;
private final int y;
private final int z;
private final String hint;
private final boolean showHint;
private final boolean teleportable;
public ConfiguredRegion(String id, String customName, List<DiscoveryReward> rewards, int x, int z) {
public ConfiguredRegion(@Nullable World world, String id, String customName,
List<DiscoveryReward> rewards, int x, int y, int z) {
this.world = world != null ? world.getUID() : null;
this.id = id;
this.customName = customName;
this.rewards = rewards;
@@ -33,13 +42,16 @@ public class ConfiguredRegion {
this.icon = Material.TOTEM_OF_UNDYING;
this.showCoords = false;
this.x = x;
this.y = y;
this.z = z;
this.hint = "";
this.showHint = false;
this.teleportable = false;
}
public ConfiguredRegion(String id, String customName,
List<DiscoveryReward> rewards, Sound sound, Material icon, int x, int z) {
public ConfiguredRegion(@Nullable World world, String id, String customName,
List<DiscoveryReward> rewards, Sound sound, Material icon, int x, int y, int z) {
this.world = world != null ? world.getUID() : null;
this.id = id;
this.customName = customName;
this.rewards = rewards;
@@ -47,9 +59,11 @@ public class ConfiguredRegion {
this.icon = icon;
this.showCoords = false;
this.x = x;
this.y = y;
this.z = z;
this.hint = "";
this.showHint = false;
this.teleportable = false;
}
public String getId() {
@@ -76,6 +90,10 @@ public class ConfiguredRegion {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
@@ -92,6 +110,14 @@ public class ConfiguredRegion {
return showHint;
}
public boolean isTeleportable() {
return teleportable;
}
public World getWorld() {
return Bukkit.getWorld(world);
}
public void save(RPGRegions plugin) throws IOException {
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
Writer writer = new FileWriter(file);

View File

@@ -18,7 +18,9 @@ public enum Translations {
REGIONS("Regions"),
DISCOVERED_ON("&7Discovered on: %0"),
DISCOVERED_TITLE("&d%0 discovered!", true),
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!", true);
DISCOVERED_SUBTITLE("&fKeep exploring to discover more!", true),
TELEPORT("&aClick to teleport"),
CANNOT_TELEPORT("&cWe can't teleport you because that world doesn't exist!");
private final String defaultValue;
private final boolean isList;

View File

@@ -41,6 +41,7 @@ public class ItemStackBuilder {
}
public ItemStackBuilder withLore(String name) {
if (name == null) return this;
final ItemMeta meta = ITEM_STACK.getItemMeta();
List<String> lore = meta.getLore();
if (lore == null) {