mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-27 02:39:07 +00:00
Add basic region effects
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package net.islandearth.rpgregions.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RegionsEffectEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player player;
|
||||
private final List<String> regions;
|
||||
|
||||
public RegionsEffectEvent(Player player, List<String> regions) {
|
||||
this.player = player;
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public List<String> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.islandearth.rpgregions.effects;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PotionRegionEffect extends RegionEffect {
|
||||
|
||||
private final PotionEffect potionEffect;
|
||||
|
||||
public PotionRegionEffect(PotionEffect potionEffect, List<ItemStack> ignoreItems) {
|
||||
super(ignoreItems);
|
||||
this.potionEffect = potionEffect;
|
||||
}
|
||||
|
||||
public PotionEffect getPotionEffect() {
|
||||
return potionEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void effect(Player player) {
|
||||
player.addPotionEffect(potionEffect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.islandearth.rpgregions.effects;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RegionEffect {
|
||||
|
||||
private final List<ItemStack> ignoreItems;
|
||||
|
||||
public RegionEffect(List<ItemStack> ignoreItems) {
|
||||
this.ignoreItems = ignoreItems;
|
||||
}
|
||||
|
||||
public abstract void effect(Player player);
|
||||
|
||||
public List<ItemStack> getIgnoreItems() {
|
||||
return ignoreItems;
|
||||
}
|
||||
|
||||
public boolean shouldIgnore(ItemStack item) {
|
||||
return ignoreItems.contains(item);
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import net.islandearth.languagy.language.LanguagyPluginHook;
|
||||
import net.islandearth.languagy.language.Translator;
|
||||
import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
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.listener.ConnectionListener;
|
||||
@@ -138,6 +139,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
public Gson getGson() {
|
||||
return new GsonBuilder()
|
||||
.registerTypeAdapter(DiscoveryReward.class, new AbstractAdapter<DiscoveryReward>(null))
|
||||
.registerTypeAdapter(RegionEffect.class, new AbstractAdapter<RegionEffect>(null))
|
||||
.registerTypeHierarchyAdapter(ItemStack.class, new ItemStackAdapter())
|
||||
.setPrettyPrinting()
|
||||
.serializeNulls().create();
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -27,7 +28,7 @@ public class RegionListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles region discoveries on enter (WG 7).
|
||||
* Handles region discoveries on enter.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEnter(RegionsEnterEvent ree) {
|
||||
@@ -43,7 +44,20 @@ public class RegionListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (!has) {
|
||||
ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegions().get(region);
|
||||
configuredRegion.getEffects().forEach(regionEffect -> {
|
||||
boolean canEffect = true;
|
||||
for (ItemStack itemStack : player.getInventory()) {
|
||||
if (!regionEffect.shouldIgnore(itemStack)) {
|
||||
canEffect = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canEffect) regionEffect.effect(player);
|
||||
});
|
||||
|
||||
if (!has && configuredRegion.isDiscoverable()) {
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(plugin.getConfig().getString("settings.server.discoveries.date.format"));
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.islandearth.rpgregions.managers.data.region;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.effects.RegionEffect;
|
||||
import net.islandearth.rpgregions.rewards.DiscoveryReward;
|
||||
import net.islandearth.rpgregions.utils.XMaterial;
|
||||
import net.islandearth.rpgregions.utils.XSound;
|
||||
@@ -34,9 +35,11 @@ public class ConfiguredRegion {
|
||||
private final boolean showHint;
|
||||
private final boolean teleportable;
|
||||
private final boolean hidden;
|
||||
private final boolean discoverable;
|
||||
private final List<RegionEffect> effects;
|
||||
|
||||
public ConfiguredRegion(@Nullable World world, String id, String customName,
|
||||
List<DiscoveryReward> rewards, int x, int y, int z) {
|
||||
List<DiscoveryReward> rewards, List<RegionEffect> effects, int x, int y, int z) {
|
||||
this.world = world != null ? world.getUID() : null;
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
@@ -51,10 +54,13 @@ public class ConfiguredRegion {
|
||||
this.showHint = false;
|
||||
this.teleportable = false;
|
||||
this.hidden = false;
|
||||
this.discoverable = true;
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public ConfiguredRegion(@Nullable World world, String id, String customName,
|
||||
List<DiscoveryReward> rewards, Sound sound, Material icon, int x, int y, int z) {
|
||||
List<DiscoveryReward> rewards, List<RegionEffect> effects, Sound sound, Material icon,
|
||||
int x, int y, int z) {
|
||||
this.world = world != null ? world.getUID() : null;
|
||||
this.id = id;
|
||||
this.customName = customName;
|
||||
@@ -69,6 +75,8 @@ public class ConfiguredRegion {
|
||||
this.showHint = false;
|
||||
this.teleportable = false;
|
||||
this.hidden = false;
|
||||
this.discoverable = true;
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@@ -123,10 +131,18 @@ public class ConfiguredRegion {
|
||||
return Bukkit.getWorld(world);
|
||||
}
|
||||
|
||||
public boolean isDiscoverable() {
|
||||
return discoverable;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public List<RegionEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void save(RPGRegions plugin) throws IOException {
|
||||
File file = new File(plugin.getDataFolder() + "/regions/" + this.id + ".json");
|
||||
Writer writer = new FileWriter(file);
|
||||
|
||||
Reference in New Issue
Block a user