Skip to content

Commit

Permalink
Fixed #41: Attack mode issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacxk committed Apr 6, 2020
1 parent f4921e5 commit 0ddeb60
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/main/java/me/jackint0sh/timedfly/commands/TFly.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ private void handleTimeArg(String[] args, CommandSender sender, boolean b) {
other = "fly.time.set.other";
}

if (playerManager.isAttacking()) {
MessageUtil.sendTranslation(player, "fly.time.attack_mode.time_changed");
return;
}
if (!playerManager.handleWorldChange(null)) return;

playerManager.startTimer();
Expand Down Expand Up @@ -187,6 +191,10 @@ static void toggleTimer(String[] args, CommandSender sender, ToggleType type) {
return;
}

if (playerManager.isAttacking()) {
MessageUtil.sendTranslation(player, "fly.time.attack_mode.currently_active");
return;
}
if (!playerManager.handleWorldChange(null)) return;

if (player.equals(sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static boolean handlePlayerQuery(PlayerManager playerManager, boolean upd
player.teleport(player.getLocation().add(0, height, 0));
playerManager.setOnFloor(false);
}
playerManager.startTimer();
if (!playerManager.isAttacking()) playerManager.startTimer();
} else if (!playerManager.hasTime() && playerManager.isTimeRunning()) playerManager.stopTimer();
});
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/me/jackint0sh/timedfly/managers/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import me.jackint0sh.timedfly.events.TimedFlyStartEvent;
import me.jackint0sh.timedfly.flygui.FlyInventory;
import me.jackint0sh.timedfly.flygui.inventories.FlightStore;
import me.jackint0sh.timedfly.utilities.Config;
import me.jackint0sh.timedfly.utilities.MessageUtil;
import me.jackint0sh.timedfly.utilities.Permissions;
import me.jackint0sh.timedfly.utilities.TimeParser;
import me.jackint0sh.timedfly.utilities.*;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -171,6 +168,7 @@ public static boolean hasAnyPermission(CommandSender sender, Permissions... perm
public void enterAttackMode() {
if (!Config.getConfig("config").get().getBoolean("StopTimerOn.Attack.Enable")) return;
if (this.hasPermission(Permissions.BYPASS_ATTACK)) return;

if (!this.isAttacking() && this.isTimeRunning()) {

this.player.setAllowFlight(false);
Expand All @@ -183,14 +181,16 @@ public void enterAttackMode() {
if (attackTimer != null) attackTimer.cancel();

try {
attackTimer = Bukkit.getScheduler().runTaskLater(Bukkit.getPluginManager().getPlugins()[0], () -> {
if (!this.hasTime()) return;
this.player.setAllowFlight(true);
this.setAttacking(false).setTimeRunning(true);
MessageUtil.sendTranslation(this.player, "fly.time.attack_mode.flight_enabled");
}, TimeParser.parse(Config.getConfig("config").get().getString("StopTimerOn.Attack.Cooldown")));
long cooldown = TimeParser.parse(Config.getConfig("config").get().getString("StopTimerOn.Attack.Cooldown"));

attackTimer = PluginTask.runLater(() -> {
if (!hasTime()) return;
setAttacking(false).setTimeRunning(true);
player.setAllowFlight(true);
MessageUtil.sendTranslation(player, "fly.time.attack_mode.flight_enabled");
}, cooldown / 100);
} catch (TimeParser.TimeFormatException e) {
MessageUtil.sendError(player, e);
e.printStackTrace();
}
}

Expand All @@ -204,7 +204,7 @@ public boolean handleWorldChange(@Nullable World from) {
switch (type) {
case "enable":
if (this.worlds.stream().anyMatch(world -> to.getName().equals(world.getName()))) {
startTimer();
if (!isAttacking()) startTimer();
this.inBlacklistedWorld = false;
return true;
} else {
Expand All @@ -221,7 +221,7 @@ public boolean handleWorldChange(@Nullable World from) {
return false;
} else {
this.inBlacklistedWorld = false;
startTimer();
if (!isAttacking()) startTimer();
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

public class PluginTask {

Expand All @@ -18,4 +20,10 @@ public static void run(Runnable task) {
if (plugin.isEnabled()) Bukkit.getScheduler().runTask(plugin, task);
else task.run();
}

public static BukkitTask runLater(Runnable task, long delay) {
Plugin plugin = Bukkit.getPluginManager().getPlugin("TimedFly");
if (plugin == null || !plugin.isEnabled()) return null;
return Bukkit.getScheduler().runTaskLater(plugin, task, delay);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/languages/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"pause": "The timer has been paused!"
},
"attack_mode": {
"time_changed": "&cYour fly time change but your &eattack mode&c is currently active.",
"currently_active": "&cYou can't do this while &eattack mode&c is currently active.",
"flight_disabled": "&7Entering &eattack mode&7. Flight &cdisabled&7!",
"flight_enabled": "&7Exiting &eattack mode&7. Flight &are-enabled&7!"
}
Expand Down

0 comments on commit 0ddeb60

Please sign in to comment.