Skip to content

Commit

Permalink
Timed temp bypass flight, bug fixes (3.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spazzinq authored Aug 8, 2019
1 parent c6196f4 commit 761ed2a
Show file tree
Hide file tree
Showing 16 changed files with 523 additions and 146 deletions.
24 changes: 12 additions & 12 deletions FlightControl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<id>spazz-repo</id>
<url>https://mvn.spazzinq.org/repository/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
Expand All @@ -108,21 +112,23 @@
<id>sk89q-repo</id>
<url>https://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>ess-facs-repo</id>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand All @@ -146,7 +152,7 @@
<dependency>
<groupId>net.ess3</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.17.0</version>
<version>2.17.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -391,11 +397,5 @@
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
Expand All @@ -45,11 +43,9 @@
public final class ConfigManager {
private FlightControl pl;
private PluginManager pm;
CommentedConfig configData;

CommentedConfig configData;
private File f;
private File trailFile;
private FileConfiguration trailConfig;

@Getter @Setter
boolean autoEnable, autoUpdate, support,
Expand All @@ -60,29 +56,25 @@ public final class ConfigManager {
@Getter @Setter
double facEnemyRange;
@Getter @Setter float flightSpeed;
String dFlight, eFlight, cFlight, nFlight,
dTrail, eTrail;
@Getter
String dFlight, eFlight, cFlight, nFlight, disableTrail, enableTrail;
@Getter
String noPermission;
Sound eSound, dSound, cSound, nSound;
HashSet<String> worlds;
HashSet<UUID> trailPrefs;
HashMap<String, List<String>> regions;
HashMap<String, Category> categories;

ConfigManager(FlightControl pl) {
this.pl = pl;
pm = pl.getServer().getPluginManager();
trailFile = new File(pl.getDataFolder(), "disabled_trail.yml");
f = new File(pl.getDataFolder(), "config.yml");

reloadConfig();
updateConfig();
}

public void reloadConfig() {
if (trailPrefs != null) saveTrailPrefs();

void reloadConfig() {
pl.saveDefaultConfig();
try {
configData = new CommentedConfig(f, pl.getResource("config.yml"));
Expand Down Expand Up @@ -115,18 +107,18 @@ public void reloadConfig() {
eFlight = configData.getString("messages.flight.enable");
cFlight = configData.getString("messages.flight.can_enable");
nFlight = configData.getString("messages.flight.cannot_enable");
dTrail = configData.getString("messages.trail.disable");
eTrail = configData.getString("messages.trail.enable");
disableTrail = configData.getString("messages.trail.disable");
enableTrail = configData.getString("messages.trail.enable");
noPermission = configData.getString("messages.permission_denied");

// Load other stuff that have separate methods
loadWorlds();
loadSounds();
loadTrail();
loadTrailPrefs();

// Reassign it anyways because it'll cause an NPE
regions = new HashMap<>();
if (pm.isPluginEnabled("WorldGuard")) {
regions = new HashMap<>();
loadRegions();
}
if (pm.isPluginEnabled("Factions")) loadCategories();
Expand Down Expand Up @@ -227,28 +219,6 @@ private void loadTrail() {
}
}

// Per-player trail preferences
private void loadTrailPrefs() {
trailPrefs = new HashSet<>();
if (!trailFile.exists()) {
try { //noinspection ResultOfMethodCallIgnored
trailFile.createNewFile();
} catch (IOException e) { e.printStackTrace(); }
}
trailConfig = YamlConfiguration.loadConfiguration(trailFile);

if (trailConfig.isList("disabled_trail")) {
if (!trailConfig.getStringList("disabled_trail").isEmpty()) {
for (String uuid : trailConfig.getStringList("disabled_trail")) {
try {
if (uuid.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"))
trailPrefs.add(UUID.fromString(uuid));
} catch (IllegalArgumentException ignored) {}
}
}
} else trailConfig.createSection("disabled_trail");
}

private void loadSounds() {
everyEnable = configData.getBoolean("sounds.every_enable");
eSound = getSound("sounds.enable");
Expand Down Expand Up @@ -301,17 +271,6 @@ private Category createCategory(List<String> types, boolean blacklist) {
}

// FILE CONFIG METHODS
void saveTrailPrefs() { // Saves personal trail preferences
if (trailConfig != null && trailFile != null) {
List<String> prefs = new ArrayList<>();
for (UUID uuid : trailPrefs) {
prefs.add(uuid.toString());
}
trailConfig.set("disabled_trail", prefs);
try { trailConfig.save(trailFile); } catch (IOException e) { e.printStackTrace(); }
}
}

public void set(String path, Object value) {
configData.set(path, value);
save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.spazzinq.flightcontrol.commands.FlightControlCommand;
import org.spazzinq.flightcontrol.commands.FlyCommand;
import org.spazzinq.flightcontrol.commands.TempFlyCommand;
import org.spazzinq.flightcontrol.commands.ToggleTrailCommand;
import org.spazzinq.flightcontrol.hooks.combat.*;
import org.spazzinq.flightcontrol.hooks.factions.Factions;
import org.spazzinq.flightcontrol.hooks.factions.Massive;
Expand All @@ -64,15 +65,22 @@
import org.spazzinq.flightcontrol.multiversion.v1_8.WorldGuard6;
import org.spazzinq.flightcontrol.objects.Category;
import org.spazzinq.flightcontrol.objects.Evaluation;
import org.spazzinq.flightcontrol.utils.Actionbar;

import java.util.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

public final class FlightControl extends org.bukkit.plugin.java.JavaPlugin {
@Getter private APIManager apiManager = APIManager.getInstance();
private PluginManager pm = Bukkit.getPluginManager();
@Getter File storageFolder = new File(getDataFolder() + File.separator + "data");

@Getter ConfigManager configManager;
@Getter FlightManager flightManager;
@Getter TempFlyManager tempflyManager;
@Getter TrailManager trailManager;
@Getter Updater updater;
@Getter private TempFlyCommand tempFlyCommand;
Expand All @@ -88,26 +96,9 @@ public final class FlightControl extends org.bukkit.plugin.java.JavaPlugin {
private HashSet<String> registeredPerms = new HashSet<>();

public void onEnable() {
getCommand("flightcontrol").setExecutor(new FlightControlCommand(this));
// Anonymous command class
getCommand("toggletrail").setExecutor((s, cmd, label, args) -> {
if (s instanceof Player) {
Player p = (Player) s;
UUID uuid = p.getUniqueId();
if (configManager.trailPrefs.contains(uuid)) {
configManager.trailPrefs.remove(uuid);
// No need to check for trail enable because of command listener
msg(s, configManager.eTrail, configManager.byActionBar);
}
else {
configManager.trailPrefs.add(uuid);
trailManager.trailRemove(p);
msg(s, configManager.dTrail, configManager.byActionBar);
}
}
else getLogger().info("Only players can use this command (the console isn't a player!)");
return true;
});
// Prepare storage folder
//noinspection ResultOfMethodCallIgnored
storageFolder.mkdirs();

boolean is1_13 = getServer().getBukkitVersion().contains("1.13") || getServer().getBukkitVersion().contains("1.14");

Expand All @@ -128,18 +119,25 @@ public void onEnable() {
if (pm.isPluginEnabled("Towny")) towny = new Towny();

// Load classes

// Load FlightManager before all because Config uses it & only needs to initialize pl
flightManager = new FlightManager(this);
configManager = new ConfigManager(this);
// Loads from Config
trailManager = new TrailManager(this);
// Loads from FlightManager
tempflyManager = new TempFlyManager(this);

new Actionbar();
new Listener(this);
updater = new Updater(getDescription().getVersion());

// Load commands
tempFlyCommand = new TempFlyCommand(this);
getCommand("tempfly").setExecutor(tempFlyCommand);
getCommand("fly").setExecutor(new FlyCommand(this));
getCommand("flightcontrol").setExecutor(new FlightControlCommand(this));
getCommand("toggletrail").setExecutor(new ToggleTrailCommand(this));

if (configManager.autoUpdate) updater.install(Bukkit.getConsoleSender(), true);
else if (updater.exists()) new BukkitRunnable() {
Expand All @@ -154,27 +152,37 @@ public void run() {
}

public void onDisable() {
if (configManager != null) {
configManager.saveTrailPrefs();
if (trailManager != null) {
trailManager.saveTrailPrefs();
}
}

public void reload() {
configManager.reloadConfig();
trailManager.saveTrailPrefs();
trailManager.reloadTrailPrefs();
tempflyManager.reloadTempflyData();
checkCurrentPlayers();
}

// Set for players already online
public void checkCurrentPlayers() {
float actualSpeed = calcActualSpeed(configManager.flightSpeed);
private void checkCurrentPlayers() {
for (Player p : Bukkit.getOnlinePlayers()) {
flightManager.check(p);
trailManager.trailCheck(p);
p.setFlySpeed(actualSpeed);
p.setFlySpeed(configManager.flightSpeed);
}
}

Evaluation eval(Player p, Location l) {
String world = l.getWorld().getName(),
region = worldGuard.getRegion(l);
Evaluation categories = evalCategories(p),
worlds = new Evaluation(configManager.worldBL, configManager.worlds.contains(world)),
regions = new Evaluation(configManager.regionBL, configManager.regions.containsKey(world) && configManager.regions.get(world).contains(region));
worlds = new Evaluation(configManager.worldBL,
configManager.worlds.contains(world)),
regions = new Evaluation(configManager.regionBL,
configManager.regions.containsKey(world)
&& configManager.regions.get(world).contains(region));

if (region != null) defaultPerms(world + "." + region); // Register new regions dynamically

Expand Down Expand Up @@ -202,14 +210,14 @@ Evaluation eval(Player p, Location l) {
// Distance is calculated a second time to match the shape of the other distance calculation
// (this would be a cube while the other would be a sphere otherwise)
if (fac.isEnemy(p, otherP) && l.distance(otherP.getLocation()) <= configManager.facEnemyRange) {
if (otherP.isFlying()) flightManager.disableFlight(otherP, false);
if (otherP.isFlying()) flightManager.check(otherP);
disable = true;
}
}
} else {
for (Player otherP : worldPlayers)
if (fac.isEnemy(p, otherP) && l.distance(otherP.getLocation()) <= configManager.facEnemyRange) {
if (otherP.isFlying()) flightManager.disableFlight(otherP, false);
if (otherP.isFlying()) flightManager.check(otherP);
disable = true;
}
}
Expand Down Expand Up @@ -271,7 +279,7 @@ private ArrayList<Category> categories(Player p) {
}

public static void msg(CommandSender s, String msg) { msg(s, msg, false); }
static void msg(CommandSender s, String msg, boolean actionBar) {
public static void msg(CommandSender s, String msg, boolean actionBar) {
if (msg != null && !msg.isEmpty()) {
String finalMsg = msg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void enableFlight(Player p, boolean isCommand) {

pl.getApiManager().callEvent(e);
if (!e.isCancelled()) {
if (isCommand) disabledByPlayerList.remove(p);
p.setAllowFlight(true);
if (!pl.configManager.everyEnable) Sound.play(p, pl.configManager.eSound);
FlightControl.msg(p, e.getMessage(), e.isByActionbar());
Expand All @@ -116,7 +117,11 @@ public void disableFlight(Player p, boolean isCommand) {

pl.getApiManager().callEvent(e);
if (!e.isCancelled()) {
alreadyCanMsgList.remove(p);
if (isCommand) {
disabledByPlayerList.add(p);
alreadyCanMsgList.add(p);
} else alreadyCanMsgList.remove(p);

if (pl.configManager.fallCancelled && p.isFlying()) {
cancelFallList.add(p);
new BukkitRunnable() { public void run() { cancelFallList.remove(p); } }.runTaskLater(pl, 300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,19 @@ private void onMove(PlayerMoveEvent e) {
@EventHandler private void onTP(PlayerTeleportEvent e) { pl.flightManager.check(e.getPlayer(), e.getTo()); }
@EventHandler private void onQuit(PlayerQuitEvent e) { pl.trailManager.trailRemove(e.getPlayer()); }
@EventHandler private void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer(); pl.flightManager.check(p);
if (p.isFlying()) new BukkitRunnable() { public void run() { pl.trailManager.trailCheck(p); } }.runTaskLater(pl, 5);
Player p = e.getPlayer();

pl.getTempflyManager().getAndSetTempfly(p);

new BukkitRunnable() {
public void run() {
pl.flightManager.check(p);
if (p.isFlying()) {
pl.trailManager.trailCheck(p);
}
}
}.runTaskLater(pl, 5);

p.setFlySpeed(pl.configManager.flightSpeed);
}
// Because commands might affect permissions/fly
Expand Down
Loading

0 comments on commit 761ed2a

Please sign in to comment.