Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix energy drink time #236

Merged
merged 4 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TestServer/plugins/TF_PrisonEscape/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ ChestsLocations:
Z: -36
"9":
X: 13
Y: 99
Z: -36
Y: 100
Z: -41
"10":
X: 24
Y: 102
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.bukkit.boss.BossBar;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -937,7 +936,7 @@ public void playerDrankEnergyDrink(String playerName, int eneryDrinkIndex) {

ConfigManager config = ConfigManager.getInstance();

player.setEffect(PotionEffectType.SPEED, config.getSpeedDuration(), config.getSpeedLevel());
player.giveEnergyDrinkEffect(config.getSpeedDuration(), config.getSpeedLevel());

int contentIndex = player.convertToInventoryIndex(eneryDrinkIndex);
player.removeItem(contentIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public abstract class PrisonEscapePlayer {
private boolean _isOnline;
private List<Item> _inventory;
private Kit _currentKit;
private long _lastDrankPotionTime;
private int _secondsLeft;

private ScoreboardData _scoreboardData;
private Clickable _openedMenu;
Expand All @@ -43,6 +45,8 @@ public PrisonEscapePlayer(String name) {
_name = name;
_isOnline = true;
_inventory = createInventory();
_lastDrankPotionTime = -1;
_secondsLeft = 0;

_scoreboardData = createScoreboardData();
setScoreboard(_scoreboardData.getScoreboard());
Expand Down Expand Up @@ -246,6 +250,27 @@ public void closeMenu(boolean closeView) {
}
}

// ########################################
// # Energy Drink #
// ########################################

public void giveEnergyDrinkEffect(int seconds, int amplifier) {
long currentTime = System.currentTimeMillis();
_secondsLeft = Math.max(0, _secondsLeft + seconds - convertToSeconds(currentTime - _lastDrankPotionTime));

if (_lastDrankPotionTime == -1) {
setEffect(PotionEffectType.SPEED, seconds, amplifier);
} else {
setEffect(PotionEffectType.SPEED, _secondsLeft + seconds, amplifier);
}

_lastDrankPotionTime = currentTime;
}

private int convertToSeconds(long miliseconds) {
return (int) (miliseconds / 1000);
}

// ########################################
// # Scoreboard #
// ########################################
Expand Down
Loading