Skip to content

Commit

Permalink
Merge branch 'regions'
Browse files Browse the repository at this point in the history
  • Loading branch information
oddlama committed Mar 16, 2021
2 parents 0a5640b + 87f2506 commit 292dc73
Show file tree
Hide file tree
Showing 46 changed files with 4,011 additions and 62 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ If you don't want a certain feature, simply disable it.
- [x] Build portals of arbitrary shape and orientation to get around easily (even horizontal!)
- [x] Correctly retains velocity of players, so you can fly through it
- [x] Apply different styles to portals so they fit your building style
- [ ] Integrates with regions to control portal connection access
- [x] Dynmap integration shows icons for global portals

#### Regions (vane-regions)

- [ ] Players can buy an arbitrarily shaped patch of land, and may control certain environmental conditions and player permissions for that area
- [ ] Server-owned regions can be used to protect gobal areas (e.g. spawn).
- [ ] Visual selection of any 2D polygon shape with arbitrary heights.
- [ ] Seamless integration into chest-like menus instead of commands.
- [x] Players can buy a patch of land, and may control certain environmental conditions and player permissions for that area
- [x] Regions created by admins can be used to protect gobal areas (e.g. spawn).
- [x] Seamless integration into chest-like menus instead of commands.
- [x] Integrates with portals to allow only players witha the portal permission to operate portals in the region
- [x] Integrates with dynmap to make regions visible on the online map
- [x] Visual region selection indicator

#### Proxy plugin (vane-waterfall)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.oddlama.vane.admin.commands;

import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;

import org.oddlama.vane.admin.Admin;
import org.oddlama.vane.annotation.command.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import org.oddlama.vane.annotation.VaneModule;
import org.oddlama.vane.annotation.config.ConfigDouble;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.UUID;
import java.util.logging.Level;

import org.bukkit.plugin.Plugin;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;

import org.dynmap.DynmapAPI;
import org.dynmap.markers.Marker;
Expand Down
9 changes: 9 additions & 0 deletions vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_16_R3.enchantments.CraftEnchantment;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -214,6 +215,14 @@ public int compare(final ItemStack a, final ItemStack b) {
}
}

public static ItemStack skull_for_player(final OfflinePlayer player) {
final var item = new ItemStack(Material.PLAYER_HEAD);
final var meta = (SkullMeta)item.getItemMeta();
meta.setOwningPlayer(player);
item.setItemMeta(meta);
return item;
}

public static ItemStack skull_with_texture(final String name, final String base64_texture) {
final var profile = Bukkit.createProfile(SKULL_OWNER);
profile.setProperty(new ProfileProperty("textures", base64_texture));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantRecipe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ public void on_player_interact_console(final PlayerInteractEvent event) {
return;
}

event.setUseInteractedBlock(Event.Result.DENY);
event.setUseItemInHand(Event.Result.DENY);

final var player = event.getPlayer();
final var portal = get_module().portal_for(portal_block);
if (portal.open_console(get_module(), player, block)) {
swing_arm(player, event.getHand());
event.setUseInteractedBlock(Event.Result.DENY);
event.setUseItemInHand(Event.Result.DENY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private boolean can_link_console(final Player player, final List<Block> blocks,
}

// Call event
final var event = new PortalLinkConsoleEvent(player, blocks, check_only, existing_portal);
final var event = new PortalLinkConsoleEvent(player, console, blocks, check_only, existing_portal);
get_module().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
lang_link_restricted.send(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void update_marker(final Portal portal) {
return;
}

// Only public portals
if (portal.visibility() != Portal.Visibility.PUBLIC) {
// Don't show private portals
if (portal.visibility() == Portal.Visibility.PRIVATE) {
remove_marker(portal.id());
return;
}
Expand Down
73 changes: 63 additions & 10 deletions vane-portals/src/main/java/org/oddlama/vane/portals/Portals.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.world.ChunkLoadEvent;
Expand All @@ -50,6 +51,7 @@
import org.oddlama.vane.annotation.lang.LangMessage;
import org.oddlama.vane.annotation.persistent.Persistent;
import org.oddlama.vane.core.functional.Consumer2;
import org.oddlama.vane.core.functional.Function2;
import org.oddlama.vane.core.lang.TranslatedMessage;
import org.oddlama.vane.core.material.ExtendedMaterial;
import org.oddlama.vane.core.module.Module;
Expand All @@ -63,7 +65,7 @@
import org.oddlama.vane.portals.portal.PortalBlockLookup;
import org.oddlama.vane.portals.portal.Style;

@VaneModule(name = "portals", bstats = 8642, config_version = 1, lang_version = 1, storage_version = 1)
@VaneModule(name = "portals", bstats = 8642, config_version = 2, lang_version = 2, storage_version = 2)
public class Portals extends Module<Portals> {
// Add (de-)serializers
static {
Expand Down Expand Up @@ -181,6 +183,8 @@ public Portals() {
constructor = new PortalConstructor(this);
new PortalTeleporter(this);
dynmap_layer = new PortalDynmapLayer(this);

persistent_storage_manager.add_migration_to(2, "Portal visibility GROUP_INTERNAL was added. This is a no-op.", (json) -> {});
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -234,6 +238,37 @@ public void on_config_change() {
}
}

// Lightweight callbacks to the regions module, if it is installed.
// Lifting the callback storage into the portals module saves us
// from having to ship regions api with this module.
private Function2<Portal, Portal, Boolean> is_in_same_region_group_callback = null;
public void set_is_in_same_region_group_callback(final Function2<Portal, Portal, Boolean> callback) {
is_in_same_region_group_callback = callback;
}

private Function2<Player, Portal, Boolean> player_can_use_portals_in_region_group_of_callback = null;
public void set_player_can_use_portals_in_region_group_of_callback(final Function2<Player, Portal, Boolean> callback) {
player_can_use_portals_in_region_group_of_callback = callback;
}

public boolean is_in_same_region_group(final Portal a, final Portal b) {
if (is_in_same_region_group_callback == null) {
return true;
}
return is_in_same_region_group_callback.apply(a, b);
}

public boolean player_can_use_portals_in_region_group_of(final Player player, final Portal portal) {
if (player_can_use_portals_in_region_group_of_callback == null) {
return true;
}
return player_can_use_portals_in_region_group_of_callback.apply(player, portal);
}

public boolean is_regions_installed() {
return is_in_same_region_group_callback != null;
}

public Style style(final NamespacedKey key) {
final var s = styles.get(key);
if (s == null) {
Expand Down Expand Up @@ -534,13 +569,15 @@ public void disconnect_portals(final Portal src, final Portal dst) {
src.on_disconnect(this, dst);
dst.on_disconnect(this, src);

// Reset target id's if the target portal was private
if (dst.visibility() == Portal.Visibility.PRIVATE) {
// Reset target id's if the target portal was transient
if (dst.visibility().is_transient_target()) {
src.target_id(null);
src.update_blocks(this);
mark_persistent_storage_dirty();
}
if (src.visibility() == Portal.Visibility.PRIVATE) {
if (src.visibility().is_transient_target()) {
dst.target_id(null);
dst.update_blocks(this);
mark_persistent_storage_dirty();
}

Expand Down Expand Up @@ -654,13 +691,29 @@ public void update_portal_icon(final Portal portal) {
public void update_portal_visibility(final Portal portal) {
// Replace references to the portal everywhere, if visibility
// has changed.
if (portal.visibility() != Portal.Visibility.PUBLIC) {
for (final var other : storage_portals.values()) {
if (Objects.equals(other.target_id(), portal.id())) {
other.target_id(null);
switch (portal.visibility()) {
case PRIVATE:
case GROUP:
// Not visible from outside, these are transient.
for (final var other : storage_portals.values()) {
if (Objects.equals(other.target_id(), portal.id())) {
other.target_id(null);
}
}
}
// TODO don't hide for group access
break;

case GROUP_INTERNAL:
// Remove from portals outside of the group
for (final var other : storage_portals.values()) {
if (Objects.equals(other.target_id(), portal.id()) &&
!is_in_same_region_group(other, portal)) {
other.target_id(null);
}
}
break;

default: // Nothing to do
break;
}

// Update dynmap marker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public class PortalLinkConsoleEvent extends PortalEvent {
private static final HandlerList handlers = new HandlerList();
private Player player;
private Portal portal;
private Block console;
private List<Block> portal_blocks;
private boolean check_only;
private boolean cancel_if_not_owner = true;

public PortalLinkConsoleEvent(final Player player, final List<Block> portal_blocks, boolean check_only, @Nullable final Portal portal) {
public PortalLinkConsoleEvent(final Player player, final Block console, final List<Block> portal_blocks, boolean check_only, @Nullable final Portal portal) {
this.player = player;
this.console = console;
this.portal_blocks = portal_blocks;
this.check_only = check_only;
this.portal = portal;
Expand All @@ -33,6 +35,10 @@ public Player getPlayer() {
return player;
}

public Block getConsole() {
return console;
}

public List<Block> getPortalBlocks() {
return portal_blocks;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.oddlama.vane.portals.event;

import java.util.UUID;

import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;

import org.oddlama.vane.portals.portal.Portal;

public class PortalOpenConsoleEvent extends PortalEvent {
private static final HandlerList handlers = new HandlerList();
private Player player;
private Block console;
private UUID portal_id;
private Portal portal;

public PortalOpenConsoleEvent(final Player player, final Block console, final UUID portal_id) {
public PortalOpenConsoleEvent(final Player player, final Block console, final Portal portal) {
this.player = player;
this.console = console;
this.portal_id = portal_id;
this.portal = portal;
}

public Player getPlayer() {
Expand All @@ -26,8 +26,8 @@ public Block getConsole() {
return console;
}

public UUID getPortalId() {
return portal_id;
public Portal getPortal() {
return portal;
}

public HandlerList getHandlers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oddlama.vane.portals.event;

import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;

Expand All @@ -8,12 +9,14 @@
public class PortalUnlinkConsoleEvent extends PortalEvent {
private static final HandlerList handlers = new HandlerList();
private Player player;
private Block console;
private Portal portal;
private boolean check_only;
private boolean cancel_if_not_owner = true;

public PortalUnlinkConsoleEvent(final Player player, final Portal portal, boolean check_only) {
public PortalUnlinkConsoleEvent(final Player player, final Block console, final Portal portal, boolean check_only) {
this.player = player;
this.console = console;
this.portal = portal;
this.check_only = check_only;
}
Expand All @@ -26,6 +29,10 @@ public Player getPlayer() {
return player;
}

public Block getConsole() {
return console;
}

public Portal getPortal() {
return portal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Menu create(final Portal portal, final Player player, final Block console
}

// Check if unlink would be allowed
final var unlink_event = new PortalUnlinkConsoleEvent(player, portal, true);
final var unlink_event = new PortalUnlinkConsoleEvent(player, console, portal, true);
get_module().getServer().getPluginManager().callEvent(unlink_event);
if (!unlink_event.isCancelled()) {
console_menu.add(menu_item_unlink_console(portal, console));
Expand Down Expand Up @@ -125,9 +125,10 @@ private MenuWidget menu_item_select_target(final Portal portal) {
.stream()
.filter(p -> {
switch (p.visibility()) {
case PUBLIC: return true;
case GROUP: return false; // TODO group visibility
case PRIVATE: return player.getUniqueId().equals(p.owner());
case PUBLIC: return true;
case GROUP: return get_module().player_can_use_portals_in_region_group_of(player, p);
case GROUP_INTERNAL: return get_module().is_in_same_region_group(portal, p);
case PRIVATE: return player.getUniqueId().equals(p.owner());
}
return false;
})
Expand Down Expand Up @@ -183,7 +184,7 @@ private MenuWidget menu_item_unlink_console(final Portal portal, final Block con
MenuFactory.confirm(get_context(), lang_unlink_console_confirm_title.str(),
item_unlink_console_confirm_accept.item(), (player2) -> {
// Call event
final var event = new PortalUnlinkConsoleEvent(player2, portal, false);
final var event = new PortalUnlinkConsoleEvent(player2, console, portal, false);
get_module().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
get_module().lang_unlink_restricted.send(player2);
Expand Down
Loading

0 comments on commit 292dc73

Please sign in to comment.