-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
306 additions
and
206 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
19 changes: 19 additions & 0 deletions
19
spigot/src/main/java/me/tofpu/speedbridge/game/process/Process.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,19 @@ | ||
package me.tofpu.speedbridge.game.process; | ||
|
||
import me.tofpu.speedbridge.game.process.item.JoinItemProcessor; | ||
import me.tofpu.speedbridge.game.process.processors.JoinProcessor; | ||
import me.tofpu.speedbridge.game.process.processors.SpectatorProcessor; | ||
import me.tofpu.speedbridge.game.process.item.SpectatorItemProcessor; | ||
import me.tofpu.speedbridge.game.process.processors.TimerUpdateProcessor; | ||
import me.tofpu.speedbridge.game.process.type.GameItemProcessor; | ||
import me.tofpu.speedbridge.game.process.type.GameProcessor; | ||
|
||
public class Process { | ||
public static final GameProcessor GAME_JOIN = new JoinProcessor(); | ||
public static final GameProcessor GAME_SPECTATOR = new SpectatorProcessor(); | ||
public static final GameProcessor GAME_UPDATE = new TimerUpdateProcessor(); | ||
|
||
public static final GameItemProcessor ITEM_JOIN = new JoinItemProcessor(); | ||
public static final GameItemProcessor ITEM_SPECTATOR = | ||
new SpectatorItemProcessor(); | ||
} |
2 changes: 1 addition & 1 deletion
2
...eedbridge/game/processor/ProcessType.java → ...speedbridge/game/process/ProcessType.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
37 changes: 37 additions & 0 deletions
37
spigot/src/main/java/me/tofpu/speedbridge/game/process/item/JoinItemProcessor.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,37 @@ | ||
package me.tofpu.speedbridge.game.process.item; | ||
|
||
import me.tofpu.speedbridge.api.user.User; | ||
import me.tofpu.speedbridge.data.file.path.Path; | ||
import me.tofpu.speedbridge.game.process.ProcessType; | ||
import me.tofpu.speedbridge.game.process.type.GameItemProcessor; | ||
import me.tofpu.speedbridge.util.XMaterial; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Optional; | ||
|
||
public class JoinItemProcessor extends GameItemProcessor { | ||
@Override | ||
public void process(final User user, final Player player, | ||
final ProcessType type) { | ||
final Inventory inventory = player.getInventory(); | ||
// clearing this user inventory | ||
inventory.clear(); | ||
|
||
// if the process type is not process, we're done here | ||
if (type != ProcessType.PROCESS) return; | ||
|
||
// trying to get the material that matches the server version | ||
final Optional<XMaterial> material = XMaterial.matchXMaterial(Path.SETTINGS_BLOCK.getValue()); | ||
|
||
// if the material is present | ||
if (material.isPresent()){ | ||
// parsing the material chosen | ||
inventory.addItem(new ItemStack(material.get().parseMaterial(), 64)); | ||
} else { | ||
// default material | ||
inventory.addItem(new ItemStack(XMaterial.WHITE_WOOL.parseMaterial(), 64)); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
spigot/src/main/java/me/tofpu/speedbridge/game/process/item/SpectatorItemProcessor.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,31 @@ | ||
package me.tofpu.speedbridge.game.process.item; | ||
|
||
import me.tofpu.speedbridge.api.user.User; | ||
import me.tofpu.speedbridge.game.process.ProcessType; | ||
import me.tofpu.speedbridge.game.process.type.GameItemProcessor; | ||
import me.tofpu.speedbridge.util.Util; | ||
import me.tofpu.speedbridge.util.XMaterial; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
public class SpectatorItemProcessor extends GameItemProcessor { | ||
@Override | ||
public void process(final User user, final Player player, | ||
final ProcessType type) { | ||
final Inventory inventory = player.getInventory(); | ||
// clearing this user inventory | ||
inventory.clear(); | ||
|
||
// if the process type is not process, we're done here | ||
if (type != ProcessType.PROCESS) return; | ||
|
||
final ItemStack itemStack = XMaterial.RED_DYE.parseItem(); | ||
final ItemMeta meta = itemStack.getItemMeta(); | ||
meta.setDisplayName(Util.colorize("&cLeave")); | ||
itemStack.setItemMeta(meta); | ||
|
||
inventory.setItem(0, itemStack); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
spigot/src/main/java/me/tofpu/speedbridge/game/process/processors/JoinProcessor.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,79 @@ | ||
package me.tofpu.speedbridge.game.process.processors; | ||
|
||
import me.tofpu.speedbridge.api.island.Island; | ||
import me.tofpu.speedbridge.api.user.User; | ||
import me.tofpu.speedbridge.game.process.ProcessType; | ||
import me.tofpu.speedbridge.game.process.Process; | ||
import me.tofpu.speedbridge.game.process.type.GameProcessor; | ||
import me.tofpu.speedbridge.game.service.GameServiceImpl; | ||
import org.bukkit.GameMode; | ||
import org.bukkit.entity.Player; | ||
|
||
public class JoinProcessor extends GameProcessor { | ||
@Override | ||
public void process(final GameServiceImpl gameService, | ||
final Island island, final User user, | ||
final Player player, | ||
final ProcessType type) { | ||
|
||
switch (type) { | ||
case PROCESS: | ||
// setting the user properties island slot | ||
// to this island's slot for tracking purposes | ||
user.properties().islandSlot(island.slot()); | ||
|
||
// setting the island takenBy to this user | ||
// for availability reasons | ||
island.takenBy(user); | ||
|
||
// teleporting player to the island's location | ||
// MULTI-WORLD PATCH | ||
player.teleport(island.location()); | ||
|
||
// removing their effects | ||
player.getActivePotionEffects().clear(); | ||
|
||
// setting their gamemode to survival | ||
player.setGameMode(GameMode.SURVIVAL); | ||
// resetting their health back to the max health attribute | ||
player.setHealth(player.getMaxHealth()); | ||
// resetting their food levels back to full | ||
player.setFoodLevel(20); | ||
|
||
// storing an instance of user & the island that | ||
// they're in for the runnable to keep track of them | ||
gameService.gameChecker().put(user, island); | ||
|
||
// if the runnable is paused | ||
if (gameService.runnable().isPaused()) { | ||
// since the runnable is paused | ||
// we'll start it | ||
gameService.runnable().resume(); | ||
} | ||
break; | ||
case REVERSE: | ||
// resetting the island for the next player | ||
gameService.resetIsland(user.properties().islandSlot()); | ||
// resetting the user's properties slot to null | ||
// since they're not playing anymore | ||
user.properties().islandSlot(null); | ||
|
||
// removing them from our tracker | ||
gameService.gameTimer().remove(player.getUniqueId()); | ||
gameService.gameChecker().remove(user); | ||
|
||
// if the gameChecker is empty | ||
if (gameService.gameChecker().isEmpty()) { | ||
// since no one is playing right now | ||
// we'll stop the runnable to save up resources | ||
gameService.runnable().pause(); | ||
} | ||
|
||
// teleporting the player to the lobby location | ||
player.teleport(gameService.lobbyService().getLobbyLocation()); | ||
break; | ||
} | ||
// processing the items to this user | ||
Process.ITEM_JOIN.process(user, player, type); | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
spigot/src/main/java/me/tofpu/speedbridge/game/process/processors/TimerUpdateProcessor.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,72 @@ | ||
package me.tofpu.speedbridge.game.process.processors; | ||
|
||
import me.tofpu.speedbridge.api.island.Island; | ||
import me.tofpu.speedbridge.api.user.User; | ||
import me.tofpu.speedbridge.api.user.UserProperties; | ||
import me.tofpu.speedbridge.api.user.timer.Timer; | ||
import me.tofpu.speedbridge.data.file.path.Path; | ||
import me.tofpu.speedbridge.game.process.ProcessType; | ||
import me.tofpu.speedbridge.game.process.type.GameProcessor; | ||
import me.tofpu.speedbridge.game.service.GameServiceImpl; | ||
import me.tofpu.speedbridge.util.Util; | ||
import org.bukkit.entity.Player; | ||
|
||
public class TimerUpdateProcessor extends GameProcessor { | ||
@Override | ||
public void process(final GameServiceImpl gameService, final User user, final Player player, final ProcessType type) { | ||
// if the process type is not process, no need to continue | ||
if (type != ProcessType.PROCESS) return; | ||
|
||
// getting an instance of timer that were | ||
// associated with this users unique id | ||
final Timer gameTimer = gameService.gameTimer().get(user.uniqueId()); | ||
// temporally instance of user's properties for ease of use | ||
final UserProperties properties = user.properties(); | ||
// temporally instance of user's timer for ease of use | ||
final Timer lowestTimer = properties.timer(); | ||
|
||
// resetting the island state | ||
gameService.reset(user); | ||
|
||
// ending the timer with the current system millis second | ||
gameTimer.end(System.currentTimeMillis()); | ||
|
||
// messaging this player that they scored | ||
Util.message(player, Path.MESSAGES_SCORED, new String[]{"%scored%"}, gameTimer.result() + ""); | ||
|
||
// notifying the spectators | ||
gameService.messageSpectator(user, | ||
Util.WordReplacer.replace(Path.MESSAGES_SPECTATOR_SCORED.getValue(), new String[]{"%player%", "%scored%"}, player.getName(), gameTimer.result() + ""), false); | ||
|
||
// checking if the player has a personal best record | ||
// and if the timer was higher than the player's best record | ||
if (lowestTimer != null && lowestTimer.result() <= gameTimer.result()) { | ||
// since the timer was higher than the player's best record | ||
// sending a message saying they've not beaten their best score | ||
|
||
// messaging the player | ||
Util.message(player, Path.MESSAGES_NOT_BEATEN, new String[]{"%score%"}, lowestTimer.result() + ""); | ||
} else { | ||
// if the player has personal best score | ||
if (lowestTimer != null) { | ||
// since they do, we are calculating the player's best record | ||
// subtracting with the current timer and sending it to them | ||
final String result = String.format("%.03f", lowestTimer.result() - gameTimer.result()); | ||
|
||
// messaging this player that they have beaten their score | ||
Util.message(player, Path.MESSAGES_BEATEN_SCORE, new String[]{"%calu_score%"}, | ||
result); | ||
|
||
// notifying the target & spectators | ||
gameService.messageSpectator(user, | ||
Util.WordReplacer.replace(Path.MESSAGES_SPECTATOR_BEATEN_SCORE.getValue(), new String[]{"%player%", "%calu_score%"}, player.getName(), result), true); | ||
} | ||
|
||
// replacing the old record with the player's current record | ||
properties.timer(gameTimer); | ||
|
||
// manually triggering the leaderboard | ||
gameService.leaderboardService().check(user, null); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
spigot/src/main/java/me/tofpu/speedbridge/game/process/type/GameItemProcessor.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,11 @@ | ||
package me.tofpu.speedbridge.game.process.type; | ||
|
||
import me.tofpu.speedbridge.api.user.User; | ||
import me.tofpu.speedbridge.game.process.ProcessType; | ||
import org.bukkit.entity.Player; | ||
|
||
public abstract class GameItemProcessor { | ||
public void process(final User user, | ||
final Player player, | ||
final ProcessType type) {} | ||
} |
19 changes: 9 additions & 10 deletions
19
...ge/game/processor/type/GameProcessor.java → ...idge/game/process/type/GameProcessor.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
13 changes: 0 additions & 13 deletions
13
spigot/src/main/java/me/tofpu/speedbridge/game/processor/Processor.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
spigot/src/main/java/me/tofpu/speedbridge/game/processor/item/SpectatorItemProcessor.java
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
spigot/src/main/java/me/tofpu/speedbridge/game/processor/type/GameItemProcessor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.