Skip to content

Commit

Permalink
Various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Feb 14, 2021
1 parent f70e318 commit b722928
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 15 deletions.
32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,36 @@
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<relocations>
<relocation>
<pattern>io.papermc.lib</pattern>
<shadedPattern>dev.efnilite.witp.paperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
Expand All @@ -40,6 +66,12 @@
</repositories>

<dependencies>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/dev/efnilite/witp/WITP.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nulla
public void join(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = WITP.getDivider().getWorld();
if (player.isOp() && WITP.OUTDATED) {
player.sendMessage(Util.color("&c&l(!) &7The WITP plugin you are using is outdated. " +
"Updates usually fix a variety of bugs. Check the Spigot page for more info."));
}
if (Option.BUNGEECORD) {
try {
ParkourPlayer.register(player);
Expand All @@ -178,14 +182,14 @@ public void join(PlayerJoinEvent event) {
} else if (player.getWorld() == WITP.getDivider().getWorld()) {
World fallback = Bukkit.getWorld(configuration.getString("config", "world.fall-back"));
if (fallback != null) {
player.teleport(fallback.getSpawnLocation());
player.teleport(fallback.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
player.sendMessage("You have been teleported to a backup location");
} else {
Verbose.error("There is no backup world! Selecting one at random...");
for (World last : Bukkit.getWorlds()) {
if (!(last.getName().equals(world.getName()))) {
player.sendMessage(Util.color("&cThere was an error while trying to get a world"));
player.teleport(last.getSpawnLocation());
player.teleport(last.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/efnilite/witp/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean execute(CommandSender sender, String[] args) {
return true;
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
if (sender.isOp()) {
if (sender.hasPermission("witp.reload")) {
WITP.getConfiguration().reload();
Option.init(false);
sender.sendMessage(Util.color("&a&l(!) &7The configuration file has been reloaded"));
Expand All @@ -56,7 +56,7 @@ public boolean execute(CommandSender sender, String[] args) {
}
return true;
} else if (args[0].equalsIgnoreCase("migrate")) { // borrowed from ParkourUser
if (sender.isOp()) {
if (sender.hasPermission("witp.reload")) {
if (Option.SQL) {
File folder = new File(WITP.getInstance().getDataFolder() + "/players/");
if (!folder.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -202,7 +203,7 @@ public void reset(boolean regenerate) {
}
deleteStructure();
buildLog.clear();
player.getPlayer().teleport(playerSpawn);
player.getPlayer().teleport(playerSpawn, PlayerTeleportEvent.TeleportCause.PLUGIN);
int score = this.score;
String time = this.time;
if (player.showDeathMsg && regenerate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -282,7 +283,7 @@ private void createIsland(ParkourPlayer pp, SubareaPoint point) {
to.setPitch(spawnPitch);
to.setYaw(spawnYaw);
to.setWorld(world);
player.teleport(to);
pp.teleportAsync(to);
block.setType(Material.AIR);
player.setGameMode(GameMode.ADVENTURE);
if (Option.INVENTORY_HANDLING) {
Expand Down Expand Up @@ -313,6 +314,9 @@ private void createIsland(ParkourPlayer pp, SubareaPoint point) {
}
}

if (!Option.INVENTORY_HANDLING) {
pp.sendTranslated("customize-menu");
}
pp.getGenerator().start();

// todo fix this check
Expand All @@ -321,7 +325,7 @@ private void createIsland(ParkourPlayer pp, SubareaPoint point) {
@Override
public void run() {
if (!player.getWorld().getUID().equals(world.getUID())) {
player.teleport(finalTo);
player.teleport(finalTo, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
}
};
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/dev/efnilite/witp/player/ParkourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public ParkourPlayer(@NotNull Player player, @Nullable ParkourGenerator generato
this.possibleStyle = new ArrayList<>();

WITP.getDivider().generate(this);
if (player.isOp() && WITP.OUTDATED) {
send("&4&l!!! &fThe WITP plugin version you are using is outdated. Please check the Spigot page for updates.");
}
}

public void setDefaults(int highScore, String time, String style, String highScoreTime,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/efnilite/witp/player/ParkourSpectator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.efnilite.witp.util.config.Option;
import dev.efnilite.witp.util.sql.InvalidStatementException;
import org.bukkit.GameMode;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand Down Expand Up @@ -45,7 +46,7 @@ public ParkourSpectator(@NotNull ParkourUser player, @NotNull ParkourPlayer watc
this.watchingGenerator = watching.getGenerator();
this.player.setGameMode(GameMode.SPECTATOR);
watching.addSpectator(this);
this.player.teleport(watching.getPlayer().getLocation());
this.player.teleport(watching.getPlayer().getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
WITP.getDivider().setBorder(this, WITP.getDivider().getPoint(watching));
sendTranslated("spectator");
}
Expand All @@ -56,7 +57,7 @@ public ParkourSpectator(@NotNull ParkourUser player, @NotNull ParkourPlayer watc
*/
public void checkDistance() {
if (watching.getPlayer().getLocation().distance(player.getLocation()) > 30) {
player.teleport(watching.getPlayer().getLocation());
player.teleport(watching.getPlayer().getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/dev/efnilite/witp/player/ParkourUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import dev.efnilite.witp.util.inventory.InventoryBuilder;
import dev.efnilite.witp.util.sql.InvalidStatementException;
import dev.efnilite.witp.util.sql.SelectStatement;
import io.papermc.lib.PaperLib;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -101,9 +103,9 @@ public static void unregister(@NotNull ParkourUser player, boolean sendBack, boo
Util.sendPlayer(pl, WITP.getConfiguration().getString("config", "bungeecord.return_server"));
} else {
if (Option.GO_BACK) {
pl.teleport(Option.GO_BACK_LOC);
player.teleportAsync(Option.GO_BACK_LOC);
} else {
pl.teleport(player.previousLocation);
player.teleportAsync(player.previousLocation);
}
WITP.getVersionManager().setWorldBorder(player.player, new Vector().zero(), 29999984);
pl.setGameMode(player.previousGamemode);
Expand All @@ -118,6 +120,18 @@ public static void unregister(@NotNull ParkourUser player, boolean sendBack, boo
}
}

/**
* Teleports the player asynchronously, which helps with unloaded chunks (?)
*
* @param to
* Where the player will be teleported to
*/
public void teleportAsync(Location to) {
PaperLib.getChunkAtAsync(to).thenAccept(chunk -> {
PaperLib.teleportAsync(player, to, PlayerTeleportEvent.TeleportCause.PLUGIN);
});
}

/**
* Saves the inventory to cache, so if the player leaves the player gets their items back
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ messages:
selected-special-blocks: '&a&l(!) &7You changed the usage of special blocks to %v'
selected-structures: '&a&l(!) &7You changed the usage of structures to %v'
cant-do: '&c&l(!) &cYou can''t do this right now.'
customize-menu: '&a&l(!) &7You can customize your parkour experience by using /parkour menu.'

not-there-search: '&7Type the player you want to spectate!'
click-search: '&c&l&nClick here&r&c&l to enter the player you want to search.'

true: "yes"
false: "no"
spectator: '&a&l(!) &7You are now a spectator. You can use "/witp gm" to leave/change your gamemode.'
spectator: '&a&l(!) &7You are now a spectator. You can use "/parkour gm" to leave/change your gamemode.'
divider: '&7----------------------------------------'
score: '&aYour score: &f%s'
time: '&aYour time: &f%s'
Expand Down

0 comments on commit b722928

Please sign in to comment.