Skip to content

Commit

Permalink
Reimplement correct api access.
Browse files Browse the repository at this point in the history
Songoda added latest EpicHopper addon in public maven repo.
  • Loading branch information
BONNe committed Mar 27, 2020
1 parent 3d6b525 commit 3569596
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 104 deletions.
26 changes: 12 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
<!-- More visible way how to change dependency versions -->
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.6.0</bentobox.version>
<epichopper.version>4.4.5</epichopper.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.0.0</build.version>
<build.version>1.1.0</build.version>
<build.number>-LOCAL</build.number>
</properties>

Expand Down Expand Up @@ -146,13 +147,10 @@
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<!-- It would be awesome to use proper classes into addon, but
unfortunately, it all is under private access and cannot be
used without access code -->
<!-- <repository>-->
<!-- <id>private</id>-->
<!-- <url>https://repo.songoda.com/artifactory/public/</url>-->
<!-- </repository>-->
<repository>
<id>private</id>
<url>https://repo.songoda.com/artifactory/public/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -171,12 +169,12 @@
<!-- It would be awesome to use proper classes into addon, but
unfortunately, it all is under private access and cannot be
used without access code -->
<!-- <dependency>-->
<!-- <groupId>com.songoda</groupId>-->
<!-- <artifactId>EpicHoppers</artifactId>-->
<!-- <version>4.3.7</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>com.songoda</groupId>
<artifactId>EpicHoppers</artifactId>
<version>${epichopper.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>


Expand Down
28 changes: 2 additions & 26 deletions src/main/java/world/bentobox/epichooks/EpicHooksAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,8 @@ public void onEnable()
return;
}

// This would be a correct way how to do access check.
//this.registerListener(new HopperAccessListener(this));
// But because no public maven repo for EpicHoppers with version 4.3.7 and newer exists,
// then I am forced to hack into all handlers.
new HopperAccessListener(this);

// Remove flag as it may confuse players with Hopper flag.
// this.getPlugin().getAddonsManager().getGameModeAddons().forEach(
// EpicHooksAddon.EPIC_HOPPER_ISLAND_PROTECTION::addGameModeAddon);
// Register Flags
//this.registerFlag(EpicHooksAddon.EPIC_HOPPER_ISLAND_PROTECTION);
// Register listener
this.registerListener(new HopperAccessListener(this));
}


Expand All @@ -54,19 +45,4 @@ public void onEnable()
public void onDisable()
{
}


// ---------------------------------------------------------------------
// Section: Constants
// ---------------------------------------------------------------------


/**
* This flag allows to define which users can access to epic hoppers. F.e. it can be
* set that only Island owner can access to them. By default it is set to Member
* rank.
*/
// public static final Flag EPIC_HOPPER_ISLAND_PROTECTION =
// new Flag.Builder("EPIC_HOPPER_ISLAND_PROTECTION", Material.HOPPER).defaultRank(
// RanksManager.MEMBER_RANK).build();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package world.bentobox.epichooks.events;


import com.songoda.epichoppers.api.events.HopperAccessEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.plugin.RegisteredListener;
import org.eclipse.jdt.annotation.NonNull;

import world.bentobox.bentobox.api.user.User;
Expand All @@ -28,78 +27,30 @@ public class HopperAccessListener implements Listener
public HopperAccessListener(@NonNull EpicHooksAddon addon)
{
this.addon = addon;

RegisteredListener registeredListener =
new RegisteredListener(this,
(listener, event) -> onHopperAccess(event),
EventPriority.NORMAL,
this.addon.getPlugin(),
true);

for (HandlerList handler : HandlerList.getHandlerLists())
{
handler.register(registeredListener);
}
}


/**
* This method cache all PlayerEvents and checks if it's name is HopperAccessEvent.
* If correct event is found, then it checks if player have access to hoppers in
* this world.
* @param event instance of PlayerEvent.
*/
public void onHopperAccess(Event event)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onHopperAccess(HopperAccessEvent event)
{
if (event instanceof PlayerEvent &&
event.getEventName().equals("HopperAccessEvent"))
{
Player player = ((PlayerEvent) event).getPlayer();
Player player = event.getPlayer();

if (!this.addon.getPlugin().getIWM().inWorld(Util.getWorld(player.getWorld())))
{
// Ignore non-bentobox worlds.
return;
}
if (!this.addon.getPlugin().getIWM().inWorld(Util.getWorld(player.getWorld())))
{
// Ignore non-bentobox worlds.
return;
}

if (!this.addon.getIslands().getIslandAt(player.getLocation()).
map(i -> i.isAllowed(User.getInstance(player),
Flags.HOPPER)).
orElse(false))
{
// Player does not have access to hoppers in this island
// I know it can be simplified in single line, but then it is hard
// to read!
((Cancellable) event).setCancelled(true);
}
if (!this.addon.getIslands().getIslandAt(player.getLocation()).
map(i -> i.isAllowed(User.getInstance(player), Flags.HOPPER)).
orElse(false))
{
// Player does not have access to hoppers in this island
event.setCancelled(true);
}
}


// This is proper event handling, however, without access to jar file, it cannot be
// compiled in public JENKINS server.
// @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
// public void onHopperAccess(HopperAccessEvent event)
// {
// Player player = event.getPlayer();
//
// if (!this.addon.getPlugin().getIWM().inWorld(Util.getWorld(player.getWorld())))
// {
// // Ignore non-bentobox worlds.
// return;
// }
//
// if (!this.addon.getIslands().getIslandAt(player.getLocation()).
// map(i -> i.isAllowed(User.getInstance(player),
// EpicHooksAddon.EPIC_HOPPER_ISLAND_PROTECTION)).
// orElse(false))
// {
// // Player does not have access to hoppers in this island
// event.setCancelled(true);
// }
// }


/**
* Current addon.
*/
Expand Down

0 comments on commit 3569596

Please sign in to comment.