Skip to content

Commit

Permalink
Possibly fixed teleporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Feb 15, 2021
1 parent b722928 commit 32ee83c
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 60 deletions.
32 changes: 0 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,10 @@
<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 @@ -66,12 +40,6 @@
</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
3 changes: 0 additions & 3 deletions src/main/java/dev/efnilite/witp/WITP.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.Callable;

public class WITP extends JavaPlugin implements Listener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.efnilite.witp.player.ParkourSpectator;
import dev.efnilite.witp.player.ParkourUser;
import dev.efnilite.witp.util.inventory.InventoryBuilder;
import dev.efnilite.witp.util.inventory.ItemBuilder;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/dev/efnilite/witp/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import dev.efnilite.witp.WITP;
import dev.efnilite.witp.player.Highscore;
import dev.efnilite.witp.player.ParkourPlayer;
import dev.efnilite.witp.player.ParkourSpectator;
import dev.efnilite.witp.player.ParkourUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void run() {
player.updateScoreboard();
return;
}
tick();
if (current.getType() != Material.AIR) {
previousSpawn = lastPlayer.clone();
lastPlayer = current.getLocation();
Expand All @@ -148,6 +149,7 @@ public void run() {
score++;
totalScore++;
latestLocation = current.getLocation();
score();

// Rewards
if ((Option.REWARDS_INTERVAL > 0 && totalScore % Option.REWARDS_INTERVAL == 0)
Expand Down Expand Up @@ -187,6 +189,10 @@ public void run() {
}, Option.GENERATOR_CHECK);
}

public void score() { }

public void tick() { }

/**
* Resets the parkour
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private void createIsland(ParkourPlayer pp, SubareaPoint point) {
to.setPitch(spawnPitch);
to.setYaw(spawnYaw);
to.setWorld(world);
pp.teleportAsync(to);
pp.teleport(to);
block.setType(Material.AIR);
player.setGameMode(GameMode.ADVENTURE);
if (Option.INVENTORY_HANDLING) {
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/dev/efnilite/witp/player/ParkourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
import dev.efnilite.witp.util.sql.InvalidStatementException;
import dev.efnilite.witp.util.sql.SelectStatement;
import dev.efnilite.witp.util.sql.UpdertStatement;
import dev.efnilite.witp.util.task.Tasks;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -508,9 +506,23 @@ public void save() {
* @throws IOException
* Thrown if the reader fails or the getting fails
*/
public static @NotNull ParkourPlayer register(Player player) throws IOException, SQLException {
if (players.get(player) == null) {
UUID uuid = player.getUniqueId();
public static @NotNull ParkourPlayer register(@NotNull Player player) throws IOException, SQLException {
return register(new ParkourPlayer(player, null));
}

/**
* Registers a player
* Doesn't use async reading because the system immediately needs the data.
*
* @param pp
* The player
*
* @throws IOException
* Thrown if the reader fails or the getting fails
*/
public static @NotNull ParkourPlayer register(@NotNull ParkourPlayer pp) throws IOException, SQLException {
if (players.get(pp.player) == null) {
UUID uuid = pp.getPlayer().getUniqueId();
if (!Option.SQL) {
File data = new File(WITP.getInstance().getDataFolder() + "/players/" + uuid.toString() + ".json");
if (data.exists()) {
Expand All @@ -534,19 +546,17 @@ public void save() {
if (from.highScoreTime == null) {
from.highScoreTime = "0.0s";
}
ParkourPlayer pp = new ParkourPlayer(player, null);
pp.setDefaults(from.highScore, from.time, from.style, from.highScoreTime, from.blockLead,
from.useParticles, from.useDifficulty, from.useStructure, from.useSpecial, from.showDeathMsg, from.showScoreboard);
pp.saveStats();
players.put(player, pp);
players.put(pp.player, pp);
reader.close();
return pp;
} else {
ParkourPlayer pp = new ParkourPlayer(player, null);
pp.setDefaults(0, "Day", WITP.getConfiguration().getString("config", "styles.default"),
"0.0s", 4, true, true, true,
true, true, true);
players.put(player, pp);
players.put(pp.player, pp);
pp.saveStats();
return pp;
}
Expand All @@ -555,7 +565,6 @@ public void save() {
.addColumns("`uuid`", "`name`", "`highscore`", "`hstime`").addCondition("`uuid` = '" + uuid.toString() + "'");
HashMap<String, List<Object>> map = select.fetch();
List<Object> objects = map != null ? map.get(uuid.toString()) : null;
ParkourPlayer pp = new ParkourPlayer(player, null);
String highScoreTime;
int highscore;
if (objects != null) {
Expand All @@ -565,7 +574,7 @@ public void save() {
pp.setDefaults(0, "Day", WITP.getConfiguration().getString("config", "styles.default"),
"0.0s", 4, true, true, true,
true, true, true);
players.put(player, pp);
players.put(pp.player, pp);
pp.saveStats();
return pp;
}
Expand All @@ -587,11 +596,11 @@ public void save() {
true, true, true);
pp.saveStats();
}
players.put(player, pp);
players.put(pp.player, pp);
return pp;
}
}
return players.get(player);
return pp;
}

private static boolean translateSqlBoolean(String string) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/dev/efnilite/witp/player/ParkourUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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;
Expand Down Expand Up @@ -103,9 +102,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) {
player.teleportAsync(Option.GO_BACK_LOC);
player.teleport(Option.GO_BACK_LOC);
} else {
player.teleportAsync(player.previousLocation);
player.teleport(player.previousLocation);
}
WITP.getVersionManager().setWorldBorder(player.player, new Vector().zero(), 29999984);
pl.setGameMode(player.previousGamemode);
Expand All @@ -126,10 +125,11 @@ public static void unregister(@NotNull ParkourUser player, boolean sendBack, boo
* @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);
});
public void teleport(@NotNull Location to) {
if (to.getWorld() != null) {
to.getWorld().getChunkAt(to);
}
player.teleport(to, PlayerTeleportEvent.TeleportCause.PLUGIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.efnilite.witp.util.config;

import dev.efnilite.witp.util.Verbose;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

public class SelectStatement extends Statement {

Expand Down

0 comments on commit 32ee83c

Please sign in to comment.