Skip to content

Commit

Permalink
Merge branch 'breaking' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Spazzinq committed Jan 6, 2024
2 parents 1157604 + cff351a commit cdf4ea7
Showing 15 changed files with 60 additions and 83 deletions.
2 changes: 1 addition & 1 deletion FlightControl/build.gradle
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ tasks.withType(JavaCompile).configureEach {
}

shadowJar {
relocate 'org.bstats.bukkit', 'org.spazzinq.flightcontrol.metric'
relocate 'org.bstats', 'org.spazzinq.flightcontrol'
relocate 'com.flowpowered' , 'com.griefdefender.lib.flowpowered'
archiveFileName = 'FlightControl.jar'
}
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ private void onMove(PlayerMoveEvent e) {
}

// Apply flyspeed on world changes
p.setFlySpeed(pl.getPlayerManager().getFlightPlayer(p).getActualFlightSpeed());
p.setFlySpeed(pl.getPlayerManager().getFlightPlayer(p).getRawFlightSpeed());
}


@@ -146,7 +146,7 @@ private void onMove(PlayerMoveEvent e) {
}

// Load FlightPlayer data
p.setFlySpeed(flightPlayer.getActualFlightSpeed());
p.setFlySpeed(flightPlayer.getRawFlightSpeed());
}
}.runTaskLater(pl, 10);
}
Original file line number Diff line number Diff line change
@@ -62,7 +62,11 @@ public void onEnable() {
new EventListener();
// Load and check
load();
updateManager.checkForUpdate(Bukkit.getConsoleSender(), true);
new BukkitRunnable() {
@Override public void run() {
updateManager.checkForUpdate(Bukkit.getConsoleSender());
}
}.runTaskLater(this, 70);

// Start bStats
new Metrics(this, 4704); // 4704 = plugin ID
@@ -76,11 +80,11 @@ public void onEnable() {
}

private void registerManagers() {
boolean isNewSpigotAPI = false;
boolean isNewSpigotAPI = true;

for (int i = 13; i < 21; i++) {
for (int i = 8; i < 13; i++) {
if (getServer().getBukkitVersion().contains("1." + i)) {
isNewSpigotAPI = true;
isNewSpigotAPI = false;
break;
}
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@

package org.spazzinq.flightcontrol.check.always;

import com.craftaro.skyblock.SkyBlock;
import com.craftaro.skyblock.api.SkyBlockAPI;
import com.craftaro.skyblock.api.island.Island;
import com.craftaro.skyblock.api.island.IslandManager;
Original file line number Diff line number Diff line change
@@ -6,10 +6,8 @@
package org.spazzinq.flightcontrol.check.territory.own;

import net.william278.husktowns.api.HuskTownsAPI;
import net.william278.husktowns.chunk.ClaimedChunk;
import net.william278.husktowns.claim.TownClaim;
import net.william278.husktowns.town.Member;
import net.william278.husktowns.town.Town;
import org.bukkit.entity.Player;
import org.spazzinq.flightcontrol.check.territory.TerritoryCheck;

Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.spazzinq.flightcontrol.FlightControl;
import org.spazzinq.flightcontrol.check.always.AdvancedEnchantmentsCheck;
import org.spazzinq.flightcontrol.manager.ConfManager;
@@ -84,11 +83,7 @@ private String loadHelp(String[] args) {
msg(s, pl.getLangManager().getPluginReloaded());
break;
case "update":
new BukkitRunnable() {
@Override public void run() {
pl.getUpdateManager().checkForUpdate(s, false);
}
}.runTaskAsynchronously(pl);
pl.getUpdateManager().checkForUpdate(s);
break;
case "combat":
config.setCombatChecked(!config.isCombatChecked());
@@ -143,11 +138,11 @@ private String loadHelp(String[] args) {
if (args.length == 2) {
if (args[1].matches("\\.\\d+|\\d+(\\.\\d+)?")) {
float speed = Float.parseFloat(args[1]);
float actualSpeed = MathUtil.calcConvertedSpeed(speed, config.getMaxFlightSpeed());
float actualSpeed = MathUtil.calcConvertedSpeed(speed, config.getMaxRawFlightSpeed());
if (speed > -1 && speed < 11) {
if (config.getDefaultFlightSpeed() != actualSpeed) {
if (config.getDefaultRawFlightSpeed() != actualSpeed) {
config.set("settings.flight_speed", speed);
config.setDefaultFlightSpeed(actualSpeed);
config.setDefaultRawFlightSpeed(actualSpeed);

pl.getPlayerManager().loadPlayerData();
msgVar(s, pl.getLangManager().getGlobalFlightSpeedSet(), false, "speed", String.valueOf(speed));
Original file line number Diff line number Diff line change
@@ -68,22 +68,22 @@ public FlySpeedCommand() {
return true;
}

private void setSpeed(CommandSender s, Player p, String wrongSpeedStr) {
if (wrongSpeedStr.matches("\\d+|(\\d+)?.\\d+")) {
float wrongSpeed = Math.min(Float.parseFloat(wrongSpeedStr), pl.getConfManager().getMaxFlightSpeed());
float speed = MathUtil.calcConvertedSpeed(wrongSpeed, pl.getConfManager().getMaxFlightSpeed());
private void setSpeed(CommandSender s, Player p, String rationalSpeedStr) {
if (rationalSpeedStr.matches("\\d+|(\\d+)?.\\d+")) {
float rationalSpeed = Float.parseFloat(rationalSpeedStr);
float rawSpeed = MathUtil.calcConvertedSpeed(rationalSpeed, pl.getConfManager().getMaxRawFlightSpeed());
FlightPlayer flightPlayer = playerManager.getFlightPlayer(p);

if (flightPlayer.getActualFlightSpeed() == speed) {
if (flightPlayer.getRawFlightSpeed() == rawSpeed) {
msgVar(s, pl.getLangManager().getFlySpeedSame(), false, new HashMap<>() {{
put("speed", String.valueOf(wrongSpeed));
put("speed", String.valueOf(rationalSpeed));
put("player", p.getName());
}});
} else {
playerManager.getFlightPlayer(p).setActualFlightSpeed(speed);
playerManager.getFlightPlayer(p).setRawFlightSpeed(rawSpeed);

msgVar(s, pl.getLangManager().getFlySpeedSet(), false, new HashMap<>() {{
put("speed", String.valueOf(wrongSpeed));
put("speed", String.valueOf(rationalSpeed));
put("player", p.getName());
}});
}
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ public class ConfManager extends StorageManager {
@Getter @Setter private boolean autoUpdate;
@Getter @Setter private boolean inGameSupport;

@Getter @Setter private float defaultFlightSpeed;
@Getter @Setter private float maxFlightSpeed;
@Getter @Setter private float defaultRawFlightSpeed;
@Getter @Setter private float maxRawFlightSpeed;
@Getter @Setter private int heightLimit;

@Getter @Setter private boolean combatChecked;
@@ -69,8 +69,8 @@ public ConfManager() {
}

// floats
maxFlightSpeed = (float) conf.getDouble("settings.max_flight_speed", 10);
defaultFlightSpeed = MathUtil.calcConvertedSpeed((float) conf.getDouble("settings.flight_speed", 1), maxFlightSpeed);
maxRawFlightSpeed = MathUtil.calcConvertedSpeed((float) conf.getDouble("settings.max_flight_speed", 10), 1f);
defaultRawFlightSpeed = MathUtil.calcConvertedSpeed((float) conf.getDouble("settings.flight_speed", 1), maxRawFlightSpeed);

// Strings
flyCommandName = conf.getString("settings.fly_command_name", "fly");
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public FlightPlayer getFlightPlayer(@Nullable Player p) {

float speed = dataConf.isDouble("flight_speed")
? (float) dataConf.getDouble("flight_speed")
: pl.getConfManager().getDefaultFlightSpeed();
: pl.getConfManager().getDefaultRawFlightSpeed();

long tempFlyLength;

@@ -72,7 +72,7 @@ public void loadPlayerData() {
for (Player p : Bukkit.getOnlinePlayers()) {
FlightPlayer flightPlayer = getFlightPlayer(p);

p.setFlySpeed(flightPlayer.getActualFlightSpeed());
p.setFlySpeed(flightPlayer.getRawFlightSpeed());
if (!flightPlayer.isTrailWanted()) {
pl.getTrailManager().disableTrail(p);
}
Original file line number Diff line number Diff line change
@@ -8,9 +8,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import org.spazzinq.flightcontrol.FlightControl;
import org.spazzinq.flightcontrol.object.UpdateStatus;
import org.spazzinq.flightcontrol.object.Version;
@@ -34,9 +32,8 @@

public class UpdateManager {
private static final String PLUGIN_PATH = "plugins/FlightControl.jar";
private static final int MSG_SEND_DELAY_IN_TICKS = 70;

private static UpdateStatus updateStatus;
private static UpdateStatus updateStatus = UpdateStatus.UNKNOWN;
private final FlightControl pl;

@Getter @Setter private Version newVersion;
@@ -67,20 +64,17 @@ public UpdateManager() {
}
}

public void checkForUpdate(CommandSender sender, boolean delayMessageSend) {
public void checkForUpdate(CommandSender sender) {
if (updateStatus == UpdateStatus.UNKNOWN || updateStatus == UpdateStatus.UP_TO_DATE) {
fetchSpigotVersion(sender);
} else {
sendStatus(sender);
}

new BukkitRunnable() {
@Override public void run() {
sendStatus(sender);
}
}.runTaskLaterAsynchronously(pl, delayMessageSend ? MSG_SEND_DELAY_IN_TICKS : 0);
}

public void fetchSpigotVersion(CommandSender sender) {
updateStatus = UpdateStatus.FETCHING_FROM_SPIGOT;
sendStatus(sender);

CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
try {
@@ -143,7 +137,7 @@ public void fetchSpigotVersion(CommandSender sender) {
});

future.thenAccept(knownHash -> {
updateStatus = UpdateStatus.DOWNLOADED_BUT_NOT_VERIFIED;
updateStatus = UpdateStatus.DOWNLOADED;

try {
// Read the bytes from the file path, then compute a hash
@@ -159,18 +153,7 @@ public void fetchSpigotVersion(CommandSender sender) {
e.printStackTrace();
}

if (updateStatus == UpdateStatus.VERIFIED) {
if (Bukkit.getPluginManager().isPluginEnabled("Plugman")) {
updateStatus = UpdateStatus.WILL_AUTO_UPDATE;
}
}

sendStatus(sender);

if (updateStatus == UpdateStatus.WILL_AUTO_UPDATE) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "plugman reload " +
"flightcontrol");
}
});
}

Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@ public class FlightPlayer {
private final UUID uuid;

@Getter private final Timer tempflyTimer;
@Getter private float actualFlightSpeed;
@Getter private float rawFlightSpeed;
@Getter @Setter private boolean trailWanted;

public FlightPlayer(File dataFile, YamlConfiguration data, UUID uuid, float actualFlightSpeed, boolean trailWanted, long tempflyDuration) {
public FlightPlayer(File dataFile, YamlConfiguration data, UUID uuid, float rawFlightSpeed, boolean trailWanted, long tempflyDuration) {
this.dataFile = dataFile;
this.data = data;
this.uuid = uuid;
// Don't store speed in data conf if not personal for player
this.actualFlightSpeed = actualFlightSpeed;
this.rawFlightSpeed = rawFlightSpeed;
this.trailWanted = trailWanted;
this.tempflyTimer = new Timer(tempflyDuration) {
@SneakyThrows @Override public void onFinish() {
@@ -101,11 +101,11 @@ public FlightPlayer(File dataFile, YamlConfiguration data, UUID uuid, float actu
}
}

@SneakyThrows public void setActualFlightSpeed(float actualFlightSpeed) {
this.actualFlightSpeed = actualFlightSpeed;
getPlayer().setFlySpeed(actualFlightSpeed);
@SneakyThrows public void setRawFlightSpeed(float rawFlightSpeed) {
this.rawFlightSpeed = rawFlightSpeed;
getPlayer().setFlySpeed(rawFlightSpeed);

data.set("flight_speed", actualFlightSpeed);
data.set("flight_speed", rawFlightSpeed);
}

@SneakyThrows public void saveData() {
Original file line number Diff line number Diff line change
@@ -28,17 +28,16 @@

@Getter
public enum UpdateStatus {
UNKNOWN("&e&lFlightControl &7» &eFailed to check for updates. Unknown update status."),
UNKNOWN("&e&lFlightControl &7» &eFailed to check for updates. Check your internet connection?"),
FETCHING_FROM_SPIGOT("&a&lFlightControl &7» &aChecking for updates..."),
NEEDS_UPDATE("&e&lFlightControl &7» &eThere is an update available, but you either disabled automatic " +
"updates or the update is major and requires manual installation. Remember to download and update the " +
"plugin to receive new features and security updates!"),
UP_TO_DATE("&a&lFlightControl &7» &aNo updates found. You're in the clear!"),
DOWNLOADING("&a&lFlightControl &7» &aCurrently downloading an update..."),
DOWNLOADED_BUT_NOT_VERIFIED("&c&lFlightControl &7» &cCould not verify the newly downloaded update is not corrupted!"),
VERIFIED("&a&lFlightControl &7» &aThe update has already been downloaded but cannot install right now. Restart " +
"(or reload) the server to install the update."),
WILL_AUTO_UPDATE("&a&lFlightControl &7» &aAutomatic installation finished! Welcome to a new version of FlightControl.");
DOWNLOADED("&c&lFlightControl &7» &cCould not verify the newly downloaded update is not corrupted!"),
VERIFIED("&a&lFlightControl &7» &aThe update has been downloaded but requires a server restart. Restart " +
"(or reload) the server to install the update.");

private final String message;

Original file line number Diff line number Diff line change
@@ -6,25 +6,24 @@
package org.spazzinq.flightcontrol.util;

public final class MathUtil {
public static float calcConvertedSpeed(float unconvertedSpeed, float maxSpeed) {
float actualSpeed;
float defaultMultiplier = 0.1f;
float wrongSpeed = unconvertedSpeed;
public static float calcConvertedSpeed(float rationalSpeed, float maxRawSpeed) {
float multiplier = 0.1f;

if (wrongSpeed > 10f) {
wrongSpeed = 10f;
} else if (wrongSpeed < 0.0001f) {
wrongSpeed = 0.0001f;
// Set min-max bounds
if (rationalSpeed > 10f) {
rationalSpeed = 10f;
} else if (rationalSpeed < 0.0001f) {
rationalSpeed = 0.0001f;
}

if (wrongSpeed < 1f) {
actualSpeed = defaultMultiplier * wrongSpeed;
if (rationalSpeed < 1f) {
// Scale down if less than 1
return multiplier * rationalSpeed;
} else {
float ratio = ((wrongSpeed - 1) / 9) * (maxSpeed - defaultMultiplier);
actualSpeed = ratio + defaultMultiplier;
// Use ratio formula otherwise
float ratio = ((rationalSpeed - 1) / 9) * (maxRawSpeed - multiplier);
return ratio + multiplier;
}

return actualSpeed;
}

/**
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = 'org.spazzinq'
version = '5.0.0'
version = '5.0.0-BETA'
}

subprojects {
Binary file removed lib/SavageFactions-2.5-RC-9.jar
Binary file not shown.

0 comments on commit cdf4ea7

Please sign in to comment.