Skip to content

Commit

Permalink
added an interface for Mode and removed getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofpu committed Sep 5, 2021
1 parent e6e13e2 commit cfb6bb8
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 40 deletions.
23 changes: 23 additions & 0 deletions api/src/main/java/me/tofpu/speedbridge/api/island/Island.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.tofpu.speedbridge.api.island;

import me.tofpu.speedbridge.api.user.User;
import me.tofpu.speedbridge.api.util.Identifier;
import org.bukkit.Location;

import java.util.List;

public interface Island extends Identifier {
boolean isAvailable();

User takenBy();
void takenBy(final User takenBy);

Location location();
void location(final Location location);
boolean hasLocation();

int slot();
Mode mode();
List<Location> placedBlocks();
IslandProperties properties();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.tofpu.speedbridge.api.island;

import me.tofpu.speedbridge.api.island.point.Point;

import java.util.List;

public interface IslandProperties {
/**
* @param identifier point identifier
*
* @return the island's point, otherwise null
*/
Point get(final String identifier);

/**
* @return the island points
*/
List<Point> points();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.tofpu.speedbridge.api.island;

import me.tofpu.speedbridge.api.user.User;

import java.io.File;
import java.util.List;

public interface IslandService {
void addIsland(final Island island);

void removeIsland(final Island island);

Island getIslandBySlot(final int slot);

Island getIslandByUser(final User takenBy);

List<Island> getAvailableIslands();

List<Island> getAvailableIslands(final Mode mode);

void saveAll(final File directory, final boolean emptyList);

void loadAll(final File directory);
}
25 changes: 25 additions & 0 deletions api/src/main/java/me/tofpu/speedbridge/api/island/point/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.tofpu.speedbridge.api.island.point;

import org.bukkit.Location;

public interface Point {
/**
* @return the point identifier
*/
String identifier();

/**
* @return the point location
*/
Location pointA();

/**
* @param location new location
*/
void pointA(final Location location);

/**
* @return true if the location is not null, otherwise false
*/
boolean hasPointA();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.tofpu.speedbridge.api.island.point;

import org.bukkit.Location;

public interface TwoSection extends Point {
String identifier();

@Override
Location pointA();

@Override
void pointA(final Location pointA);

@Override
boolean hasPointA();

Location pointB();

void pointB(final Location pointB);

boolean hasPointB();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.tofpu.speedbridge.api.util;

public interface Identifier {
String getIdentifier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.tofpu.speedbridge.game.Game;
import me.tofpu.speedbridge.game.controller.SetupStage;
import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.island.mode.ModeManager;
import me.tofpu.speedbridge.util.Util;

Expand All @@ -25,7 +26,7 @@ public CommandHandler(Game game, final SpeedBridge plugin) {
});

// completions
this.commandManager.getCommandCompletions().registerCompletion("modes", context -> Util.toString(ModeManager.getModeManager().getModes()));
this.commandManager.getCommandCompletions().registerCompletion("modes", context -> Util.toString(ModeManager.getModeManager().modes()));
this.commandManager.getCommandCompletions().registerCompletion("availableIslands", context -> Util.toString(game.getIslandService().getAvailableIslands()));
this.commandManager.getCommandCompletions().registerCompletion("setupStage", context -> Util.toString(SetupStage.values()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.tofpu.speedbridge.game.Result;
import me.tofpu.speedbridge.game.service.GameService;
import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.island.mode.ModeManager;
import me.tofpu.speedbridge.lobby.service.LobbyService;
import me.tofpu.speedbridge.user.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.tofpu.speedbridge.game.Result;
import me.tofpu.speedbridge.island.Island;
import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.user.User;
import me.tofpu.speedbridge.user.properties.timer.Timer;
import org.bukkit.entity.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.tofpu.speedbridge.game.runnable.GameRunnable;
import me.tofpu.speedbridge.island.Island;
import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.island.mode.ModeManager;
import me.tofpu.speedbridge.island.service.IslandService;
import me.tofpu.speedbridge.lobby.service.LobbyService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.tofpu.speedbridge.island;

import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.island.properties.IslandProperties;
import me.tofpu.speedbridge.user.User;
import me.tofpu.speedbridge.util.Identifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.tofpu.speedbridge.island;

import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.island.mode.ModeManager;
import me.tofpu.speedbridge.island.properties.IslandProperties;
import me.tofpu.speedbridge.island.properties.IslandPropertiesImpl;
Expand Down
41 changes: 9 additions & 32 deletions spigot/src/main/java/me/tofpu/speedbridge/island/mode/Mode.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
package me.tofpu.speedbridge.island.mode;

import com.google.common.collect.Lists;
import me.tofpu.speedbridge.util.Identifier;

import java.util.ArrayList;
import java.util.List;

public class Mode implements Identifier {
private final String identifier;
private final List<Integer> slots;
private final boolean aDefault;
public interface Mode extends Identifier {
/**
* @return the mode initial selected slots
*/
List<Integer> slots();

public Mode(final String identifier, final boolean aDefault) {
this(identifier, Lists.newArrayList(), aDefault);
}

public Mode(final String identifier, final List<Integer> slots, final boolean aDefault) {
this.identifier = identifier;
this.slots = new ArrayList<>(slots);
this.aDefault = aDefault;
}

public Mode(final String identifier, final List<Integer> slots) {
this(identifier, slots, false);
}

@Override
public String getIdentifier() {
return identifier;
}

public List<Integer> getSlots() {
return slots;
}

public boolean isDefault() {
return aDefault;
}
/**
* @return true if the settings was set to this, otherwise false
*/
boolean isDefault();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.tofpu.speedbridge.island.mode;

public class ModeFactory {
public static Mode of(final String identifier, final boolean isDefault){
return new ModeImpl(identifier, isDefault);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package me.tofpu.speedbridge.island.mode;

import com.google.common.collect.Lists;
import me.tofpu.speedbridge.util.Identifier;

import java.util.ArrayList;
import java.util.List;

public class ModeImpl implements Mode {
private final String identifier;
private final List<Integer> slots;
private final boolean aDefault;

public ModeImpl(final String identifier, final boolean aDefault) {
this(identifier, Lists.newArrayList(), aDefault);
}

public ModeImpl(final String identifier, final List<Integer> slots, final boolean aDefault) {
this.identifier = identifier;
this.slots = new ArrayList<>(slots);
this.aDefault = aDefault;
}

@Override
public String getIdentifier() {
return identifier;
}

@Override
public List<Integer> slots() {
return slots;
}

@Override
public boolean isDefault() {
return aDefault;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void initialize() {
final ConfigurationSection section = configuration.getConfigurationSection(path + "list");
for (final String value : section.getKeys(false)) {
boolean isDefault = defaultMode.equalsIgnoreCase(value);
final Mode mode = new Mode(value, isDefault);
final Mode mode = ModeFactory.of(value, isDefault);
final String[] args = section.getString(value).split("-");

final int integer = Integer.parseInt(args[0]);
Expand All @@ -44,16 +44,16 @@ public void initialize() {
list.add(i);
}
}
if (hasArray) mode.getSlots().addAll(list);
else mode.getSlots().add(integer);
if (hasArray) mode.slots().addAll(list);
else mode.slots().add(integer);

getModes().add(mode);
modes().add(mode);
}
}

public Mode get(final int slot) {
for (final Mode mode : modes) {
if (mode.getSlots().contains(slot)) return mode;
if (mode.slots().contains(slot)) return mode;
}
return null;
}
Expand All @@ -72,7 +72,7 @@ public Mode getDefault() {
return null;
}

public List<Mode> getModes() {
public List<Mode> modes() {
return modes;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.tofpu.speedbridge.island.service;

import me.tofpu.speedbridge.data.DataManager;
import me.tofpu.speedbridge.island.Island;
import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.user.User;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.tofpu.speedbridge.game.Game;
import me.tofpu.speedbridge.island.Island;
import me.tofpu.speedbridge.island.mode.Mode;
import me.tofpu.speedbridge.island.mode.ModeImpl;
import me.tofpu.speedbridge.user.User;

import java.io.File;
Expand Down

0 comments on commit cfb6bb8

Please sign in to comment.