Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class TimingSystemConfiguration {
private Integer pushToPassFullChargeTime;
private Double pushToPassForwardAccel;
private Integer pushToPassStartingCharge;
private Boolean pushToPassParticlesToggle;
private final boolean frostHexAddOnEnabled;
private final boolean medalsAddOnEnabled;
private final boolean medalsShowNextMedal;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class TimingSystemConfiguration {
pushToPassFullChargeTime = plugin.getConfig().getInt("pushtopass.fullChargeTime", 60000);
pushToPassForwardAccel = plugin.getConfig().getDouble("pushtopass.forwardAccel", 0.05);
pushToPassStartingCharge = plugin.getConfig().getInt("pushtopass.startingCharge", 0);
pushToPassParticlesToggle = plugin.getConfig().getBoolean("pushtopass.particlestoggle", true);
frostHexAddOnEnabled = plugin.getConfig().getBoolean("frosthexaddon.enabled");
medalsAddOnEnabled = plugin.getConfig().getBoolean("medalsaddon.enabled");
medalsShowNextMedal = plugin.getConfig().getBoolean("medalsaddon.showNextMedal");
Expand Down Expand Up @@ -172,6 +174,10 @@ public void setPushToPassStartingCharge(int value) {
pushToPassStartingCharge = value;
}

public void setPushToPassParticlesToggle(boolean value) {
pushToPassParticlesToggle = value;
}

public <T extends TSDatabase & EventDatabase> T getDatabaseType() {
// This could maybe be improved but I have no idea :P
return (T) databaseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import me.makkuusen.timing.system.track.tags.TrackTag;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.block.data.type.Switch;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -171,6 +172,14 @@ public static void onPushToPassStartingChargeChange(CommandSender sender, int va
Text.send(sender, Success.SAVED);
}

@Subcommand("pushtopass|p2p particlestoggle")
@CommandCompletion("<value>")
@CommandPermission("%permissiontimingsystem_pushtopass_set_particlestoggle")
public static void onPushToPassParticlesToggle(CommandSender sender, boolean value) {
TimingSystem.configuration.setPushToPassParticlesToggle(value);
Text.send(sender, Success.SAVED);
}

@Subcommand("shortname")
@CommandCompletion("<shortname> @players")
@CommandPermission("%permissiontimingsystem_shortname_others")
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/me/makkuusen/timing/system/drs/PushToPass.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import me.makkuusen.timing.system.participant.Driver;
import me.makkuusen.timing.system.track.Track;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
Expand All @@ -32,6 +34,8 @@ public class PushToPass {
private static final Map<UUID, Float> preP2PForwardAccel = new HashMap<>();
private static final short PACKET_ID_SET_FORWARD_ACCELERATION = 11;
private static final long TOGGLE_COOLDOWN_MS = 500;
private static final Map<UUID, Integer> trailTaskIds = new HashMap<>();
private static final Long TRAIL_PARTICLE_TICK_SPACING = 1L;

/**
* Activates push to pass for a player if they have charge available
Expand All @@ -58,6 +62,7 @@ public static void activatePushToPass(Player player) {
preP2PForwardAccel.put(playerId, originalAccel);

data.setActive(true);
startTrail(player);
double forwardAccel = TimingSystem.configuration.getPushToPassForwardAccel();
sendForwardAccelerationPacket(player, (float) forwardAccel);

Expand All @@ -78,6 +83,7 @@ public static void deactivatePushToPass(Player player) {

data.updateCharge();
data.setActive(false);
stopTrail(playerId);

Float originalAccel = preP2PForwardAccel.remove(playerId);
if (originalAccel != null) {
Expand Down Expand Up @@ -121,6 +127,7 @@ public static void togglePushToPass(Player player) {
*/
public static void initializePushToPass(UUID playerId) {
int startingCharge = TimingSystem.configuration.getPushToPassStartingCharge();

PushToPassData data = new PushToPassData(startingCharge);
pushToPassPlayers.put(playerId, data);

Expand All @@ -134,6 +141,7 @@ public static void initializePushToPass(UUID playerId) {
* Cleans up push to pass data for a player
*/
public static void cleanupPlayer(UUID playerId) {
stopTrail(playerId);
PushToPassData data = pushToPassPlayers.remove(playerId);
toggleCooldowns.remove(playerId);
preP2PForwardAccel.remove(playerId);
Expand Down Expand Up @@ -237,6 +245,62 @@ public static void updateAllCharges() {
}
}

/**
* Activates particle trail for a player
*/
private static void startTrail(Player player) {
UUID playerId = player.getUniqueId();
if (trailTaskIds.containsKey(playerId) || !TimingSystem.configuration.getPushToPassParticlesToggle()) {
return;
}

Color teamColor = EventDatabase.getDriverFromRunningHeat(playerId)
.map(driver -> hexToColor(driver.getTPlayer().getSettings().getHexColor()))
.orElse(Color.fromRGB(255, 100, 255));

int taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(
TimingSystem.getPlugin(),
() -> {
boolean particleToggle = TimingSystem.configuration.getPushToPassParticlesToggle();
if (!player.isOnline() || !particleToggle) {
stopTrail(playerId);
return;
}
spawnTrailParticles(player, teamColor);
},
0L,
TRAIL_PARTICLE_TICK_SPACING
);

trailTaskIds.put(playerId, taskId);
}

/**
* Deactivates particle trail for a player
*/
private static void stopTrail(UUID playerId) {
Integer taskId = trailTaskIds.remove(playerId);
if (taskId != null) {
Bukkit.getScheduler().cancelTask(taskId);
}
}

/**
* Spawns Particle Trail for Player
*/
private static void spawnTrailParticles(Player player, Color color) {
var location = player.getLocation();
var direction = location.getDirection().normalize().multiply(-0.5);
var spawnLoc = location.clone().add(direction).add(0, 0.3, 0);

player.getWorld().spawnParticle(
Particle.DUST,
spawnLoc,
3, 0.1, 0.1, 0.1, 0.0,
new Particle.DustOptions(color, 1.5f)
);
}

private static void updateDriverScoreboard(UUID playerId) {
var maybeDriver = TimingSystemAPI.getDriverFromRunningHeat(playerId);
if (maybeDriver.isPresent()) {
Expand Down Expand Up @@ -284,6 +348,19 @@ public static void reDisplayBossBar(Player player) {
}
}

private static Color hexToColor(String hex) {
try {
if (hex == null || hex.isEmpty()) return Color.WHITE;
hex = hex.replace("#", "");
int r = Integer.parseInt(hex.substring(0, 2), 16);
int g = Integer.parseInt(hex.substring(2, 4), 16);
int b = Integer.parseInt(hex.substring(4, 6), 16);
return Color.fromRGB(r, g, b);
} catch (Exception e) {
return Color.WHITE;
}
}

@Getter
private static class PushToPassData {
private double chargePercent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum PermissionTimingSystem implements Permissions {
PUSHTOPASS_SET_FULLCHARGETIME,
PUSHTOPASS_SET_FORWARDACCEL,
PUSHTOPASS_SET_STARTINGCHARGE,
PUSHTOPASS_SET_PARTICLETOGGLE,
COLOR_SET_NAMED,
COLOR_SET_HEX,
GHOST;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pushtopass:
fullChargeTime: 60000
forwardAccel: 0.05
startingCharge: 0
particlesToggle: true
sql:
databaseType: SQLite # Options: MySQL, MariaDB, SQLite
host: '127.0.0.1'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ permissions:
timingsystem.pushtopass.set.fullchargetime: true
timingsystem.pushtopass.set.forwardaccel: true
timingsystem.pushtopass.set.startingcharge: true
timingsystem.pushtopass.set.particlestoggle: true
timingsystem.team.create: true
timingsystem.team.delete: true
timingsystem.team.manage: true
Expand Down