This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Zayon-Network/v1.2
V1.2
- Loading branch information
Showing
15 changed files
with
401 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/de/nehlen/gameapi/PhaseApi/AbstractGamePhase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.nehlen.gameapi.PhaseApi; | ||
|
||
import de.nehlen.gameapi.Gameapi; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.bukkit.Bukkit; | ||
|
||
public abstract class AbstractGamePhase implements GamePhase { | ||
|
||
@Getter @Setter | ||
protected int counter = 0; | ||
protected int scheduler = 0; | ||
|
||
public AbstractGamePhase(int counter) { | ||
this.counter = counter; | ||
} | ||
|
||
public void startPhase() { | ||
scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(Gameapi.getGameapi(), () -> {}, 20L, 20L); | ||
}; | ||
public void endPhase(){ | ||
Bukkit.getScheduler().cancelTask(scheduler); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,17 @@ | ||
package de.nehlen.gameapi.PhaseApi; | ||
|
||
import de.nehlen.gameapi.Gameapi; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.bukkit.Bukkit; | ||
|
||
public class GamePhase { | ||
@Getter @Setter | ||
public int counter = 0; | ||
public int scheduler = 0; | ||
public interface GamePhase { | ||
int counter = 0; | ||
int scheduler = 0; | ||
|
||
public GamePhase(int counter) { | ||
this.counter=counter; | ||
} | ||
void setCounter(int counter); | ||
|
||
public void startPhase() { | ||
scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(Gameapi.getGameapi(), new Runnable() { | ||
@Override | ||
public void run() { | ||
//PUT CONTENT HERE | ||
} | ||
}, 20L, 20L); | ||
}; | ||
public void endPhase(){ | ||
Bukkit.getScheduler().cancelTask(scheduler); | ||
}; | ||
int getCounter(); | ||
|
||
void startPhase(); | ||
|
||
void endPhase(); | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/de/nehlen/gameapi/PhaseApi/GamePhaseManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package de.nehlen.gameapi.PhaseApi; | ||
|
||
import de.nehlen.gameapi.PhaseApi.exceptions.GamePhaseLastException; | ||
import de.nehlen.gameapi.PhaseApi.exceptions.GamePhaseNotRegisteredException; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class GamePhaseManager { | ||
|
||
private Map<String, GamePhase> gamePhases = new HashMap<>(); | ||
|
||
public void registerPhase(String name, GamePhase gamePhase) { | ||
gamePhases.put(name, gamePhase); | ||
} | ||
|
||
public void startPhase(String name, int count) { | ||
GamePhase gamePhase = gamePhases.get(name); | ||
if (gamePhase != null) { | ||
gamePhase.setCounter(count); | ||
gamePhase.startPhase(); | ||
} else { | ||
throw new GamePhaseNotRegisteredException("Game Phase with name " + name + " is not registered."); | ||
} | ||
} | ||
|
||
public void endPhase(String name) { | ||
GamePhase gamePhase = gamePhases.get(name); | ||
if (gamePhase != null) { | ||
gamePhase.endPhase(); | ||
} else { | ||
throw new GamePhaseNotRegisteredException("Game Phase with name " + name + " is not registered."); | ||
} | ||
} | ||
|
||
public void continueToNextPhase() { | ||
if(gamePhases.size() <= 1) { | ||
throw new GamePhaseLastException("No Game Phase to continue to."); | ||
} | ||
Map.Entry<String, GamePhase> currentGamePhase = gamePhases.entrySet().iterator().next(); | ||
currentGamePhase.getValue().endPhase(); | ||
gamePhases.remove(currentGamePhase.getKey()); | ||
|
||
Map.Entry<String, GamePhase> newCurrentPhase = gamePhases.entrySet().iterator().next(); | ||
newCurrentPhase.getValue().startPhase(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseLastException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package de.nehlen.gameapi.PhaseApi.exceptions; | ||
|
||
public class GamePhaseLastException extends RuntimeException { | ||
|
||
public GamePhaseLastException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/de/nehlen/gameapi/PhaseApi/exceptions/GamePhaseNotRegisteredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.nehlen.gameapi.PhaseApi.exceptions; | ||
|
||
public class GamePhaseNotRegisteredException extends RuntimeException { | ||
public GamePhaseNotRegisteredException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.