Archived
0

Introduced event-based resource getter interfaces

This commit is contained in:
Daniil
2018-08-04 23:47:38 +07:00
parent 60cbec2119
commit 5928cb8913
4 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package mc.core.events.api.interfaces;
import mc.core.Location;
import java.util.Collection;
public interface LocationProvidingEvent {
Collection<Location> getAssociatedLocations();
}

View File

@@ -0,0 +1,22 @@
package mc.core.events.api.interfaces;
import mc.core.Location;
import mc.core.player.Player;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public interface PlayerProvidingEvent extends LocationProvidingEvent {
List<Player> getAssociatedPlayers();
@Override
default Collection<Location> getAssociatedLocations() {
List<Player> players = getAssociatedPlayers();
if (players.size() == 1)
return Collections.singletonList(players.get(0).getLocation());
else
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,10 @@
package mc.core.events.api.interfaces;
import mc.core.world.World;
import java.util.Collection;
public interface WorldProvidingEvent {
Collection<World> getAssociatedWorlds();
}

View File

@@ -0,0 +1,28 @@
package mc.core.events.api.samples;
import mc.core.Location;
import mc.core.events.EventBase;
import mc.core.events.api.interfaces.LocationProvidingEvent;
import mc.core.events.api.interfaces.PlayerProvidingEvent;
import mc.core.player.Player;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class BlockBreakEvent extends EventBase implements PlayerProvidingEvent, LocationProvidingEvent {
private Player player;
// TODO: There should be a proper block reference
private Location blockLocation;
@Override
public List<Player> getAssociatedPlayers() {
return Collections.singletonList(player);
}
@Override
public Collection<Location> getAssociatedLocations() {
return Collections.singletonList(blockLocation);
}
}