mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-07-12 17:53:55 +00:00
Various fixes & improvements (#246)
* HuskClaims Support * Bump Lombok for compilation and fix other obscure issues * Resolve database locking * Have the executor service perform in multiple places * Utilize a ConcurrentHashMap instead of a HashMap for player data management to mitigate fast connections and thread switching * Reapply modifications with UUID checking for this particular instance * Apply additional null checks to mitigate player reading exceptions once again * Fix RTP on death on custom worlds and add it to debug print * Migrate to newer FoliaLib module and fix compilation again * Fix Min-Max Radius Co-authored-by: ZepsiZola <zepsizola@gmail.com> * Implement labeled HuskClaims support since it's internally implemented * Rebase * Likely make thread-safe * Resolve obscure and rare ArrayIndexOutOfBoundsException --------- Co-authored-by: JMaleta <13309090+JMeta0@users.noreply.github.com> Co-authored-by: ZepsiZola <zepsizola@gmail.com>
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<!-- Local Server Building -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<version>3.4.2</version>
|
||||
<configuration>
|
||||
<outputDirectory>../../Java/plugins</outputDirectory>
|
||||
</configuration>
|
||||
@@ -47,13 +47,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- Shade PaperLib into project -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml
|
||||
</dependencyReducedPomLocation>
|
||||
@@ -66,10 +66,6 @@
|
||||
<pattern>com.tcoded.folialib</pattern>
|
||||
<shadedPattern>me.SuperRonanCraft.BetterRTP.lib.folialib</shadedPattern>
|
||||
</relocation>
|
||||
<!--relocation>
|
||||
<pattern>xyz.xenondevs.particle</pattern>
|
||||
<shadedPattern>me.SuperRonanCraft.BetterRTP.particleLib</shadedPattern>
|
||||
</relocation-->
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -84,7 +80,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.14.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@@ -105,6 +101,11 @@
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<!-- FoliaLib Repo -->
|
||||
<repository>
|
||||
<id>tcoded-releases</id>
|
||||
<url>https://repo.tcoded.com/releases</url>
|
||||
</repository>
|
||||
<!-- Spigot Repo -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
@@ -120,7 +121,7 @@
|
||||
<id>vault-repo</id>
|
||||
<url>https://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<!-- Worldguard Repo -->
|
||||
<!-- WorldGuard Repo -->
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
@@ -191,7 +192,7 @@
|
||||
<version>1.0.8</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Worldguard (https://dev.bukkit.org/projects/worldguard) -->
|
||||
<!-- WorldGuard (https://dev.bukkit.org/projects/worldguard) -->
|
||||
<dependency> <!-- Saber Factions screws up if updated -->
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
@@ -229,7 +230,7 @@
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.8.0</version>
|
||||
<version>5.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Towny (https://www.spigotmc.org/resources/towny.72694/) -->
|
||||
@@ -243,10 +244,10 @@
|
||||
<dependency>
|
||||
<groupId>com.github.TechFortress</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.18</version>
|
||||
<version>17.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- KingdomsX v1.10.5.2 (https://www.spigotmc.org/resources/kingdomsx.77670/) -->
|
||||
<!-- KingdomsX (https://www.spigotmc.org/resources/kingdomsx.77670/) -->
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>kingdoms</artifactId>
|
||||
@@ -286,14 +287,14 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
<version>1.18.38</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- EssentialsX -->
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.20.1</version>
|
||||
<version>2.21.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@@ -319,14 +320,14 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.2</version>
|
||||
<version>2.11.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- HuskClaims (https://www.spigotmc.org/resources/huskclaims.114467/) (Added in 3.6.13)-->
|
||||
<dependency>
|
||||
<groupId>net.william278.huskclaims</groupId>
|
||||
<artifactId>huskclaims-bukkit</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Husktown (https://www.spigotmc.org/resources/husktowns.92672/) (Added in 3.4.5)-->
|
||||
@@ -345,9 +346,9 @@
|
||||
</dependency>
|
||||
<!-- FoliaLib -->
|
||||
<dependency>
|
||||
<groupId>com.github.TechnicallyCoded</groupId>
|
||||
<groupId>com.tcoded</groupId>
|
||||
<artifactId>FoliaLib</artifactId>
|
||||
<version>0.4.3</version>
|
||||
<version>0.5.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- FactionsBridge -->
|
||||
@@ -364,19 +365,6 @@
|
||||
<version>c697d3e9ef</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- CAN BE UNCOMMENTED IF YOU HAVE ACCESS TO THE PLUGIN -->
|
||||
<!-- Private Repoed -->
|
||||
<!-- This is uploaded to our private repo on https://repo.ronanplugins.com -->
|
||||
<!-- hClaims (https://www.spigotmc.org/resources/90540/) -->
|
||||
<!--<dependency>
|
||||
<groupId>com.ronanplugins</groupId>
|
||||
<artifactId>hClaims</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>-->
|
||||
<!-- Provided by repo: devmart-public -->
|
||||
<dependency>
|
||||
<groupId>com.bekvon.bukkit.residence</groupId>
|
||||
<artifactId>Residence</artifactId>
|
||||
|
||||
@@ -20,9 +20,7 @@ public class Join {
|
||||
static void event(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
updater(p);
|
||||
AsyncHandler.async(() -> {
|
||||
getPl().getCooldowns().loadPlayer(p);
|
||||
});
|
||||
AsyncHandler.async(() -> getPl().getCooldowns().loadPlayer(p));
|
||||
rtpOnFirstJoin(p);
|
||||
}
|
||||
|
||||
@@ -42,10 +40,7 @@ public class Join {
|
||||
//RTP on first join
|
||||
private static void rtpOnFirstJoin(Player p) {
|
||||
if (getPl().getSettings().isRtpOnFirstJoin_Enabled() && !p.hasPlayedBefore())
|
||||
HelperRTP.tp(p, Bukkit.getConsoleSender(),
|
||||
Bukkit.getWorld(getPl().getSettings().getRtpOnFirstJoin_World()),
|
||||
null, RTP_TYPE.JOIN, true, true);
|
||||
//Fixed via @kazigk on Github
|
||||
HelperRTP.tp(p, Bukkit.getConsoleSender(), Bukkit.getWorld(getPl().getSettings().getRtpOnFirstJoin_World()), null, RTP_TYPE.JOIN, true, true);
|
||||
}
|
||||
|
||||
private static BetterRTP getPl() {
|
||||
|
||||
@@ -6,8 +6,6 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.google.common.base.Objects;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public abstract class AbstractPacket {
|
||||
// The packet we will be modifying
|
||||
protected PacketContainer handle;
|
||||
@@ -42,15 +40,9 @@ public abstract class AbstractPacket {
|
||||
* Send the current packet to the given receiver.
|
||||
*
|
||||
* @param receiver - the receiver.
|
||||
* @throws RuntimeException If the packet cannot be sent.
|
||||
*/
|
||||
public void sendPacket(Player receiver) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
|
||||
getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Cannot send packet.", e);
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +63,7 @@ public abstract class AbstractPacket {
|
||||
@Deprecated
|
||||
public void recievePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
|
||||
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot recieve packet.", e);
|
||||
@@ -86,7 +78,7 @@ public abstract class AbstractPacket {
|
||||
*/
|
||||
public void receivePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
|
||||
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot receive packet.", e);
|
||||
|
||||
+45
-33
@@ -6,6 +6,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
@@ -29,7 +30,6 @@ public class DatabasePlayers extends SQLite {
|
||||
//COOLDOWN DATA
|
||||
COUNT("count", "long"),
|
||||
LAST_COOLDOWN_DATE("last_rtp_date", "long"),
|
||||
//USES("uses", "integer"),
|
||||
;
|
||||
|
||||
public final String name;
|
||||
@@ -42,43 +42,55 @@ public class DatabasePlayers extends SQLite {
|
||||
}
|
||||
|
||||
public void setupData(PlayerData data) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
if (data == null || data.player == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE " + COLUMNS.UUID.name + " = ?");
|
||||
ps.setString(1, data.player.getUniqueId().toString());
|
||||
Future<?> task = SQLiteExecutor.EXECUTOR.submit(() -> {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE " + COLUMNS.UUID.name + " = ?");
|
||||
ps.setString(1, data.player.getUniqueId().toString());
|
||||
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
long count = rs.getLong(COLUMNS.COUNT.name);
|
||||
long time = rs.getLong(COLUMNS.LAST_COOLDOWN_DATE.name);
|
||||
data.setRtpCount(Math.toIntExact(count));
|
||||
data.setGlobalCooldown(time);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
long count = rs.getLong(COLUMNS.COUNT.name);
|
||||
long time = rs.getLong(COLUMNS.LAST_COOLDOWN_DATE.name);
|
||||
data.setRtpCount(Math.toIntExact(count));
|
||||
data.setGlobalCooldown(time);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
}
|
||||
});
|
||||
task.get();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//Set a player Cooldown
|
||||
public void setData(PlayerData data) {
|
||||
String pre = "INSERT OR REPLACE INTO ";
|
||||
String sql = pre + tables.get(0) + " ("
|
||||
+ COLUMNS.UUID.name + ", "
|
||||
+ COLUMNS.COUNT.name + ", "
|
||||
+ COLUMNS.LAST_COOLDOWN_DATE.name + " "
|
||||
//+ COLUMNS.USES.name + " "
|
||||
+ ") VALUES(?, ?, ?)";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(data.player.getUniqueId().toString());
|
||||
add(data.getRtpCount());
|
||||
add(data.getGlobalCooldown());
|
||||
//add(data.getUses());
|
||||
}};
|
||||
sqlUpdate(sql, params);
|
||||
try {
|
||||
SQLiteExecutor.EXECUTOR.submit(() -> {
|
||||
String sql = "INSERT OR REPLACE INTO " + tables.get(0) + " ("
|
||||
+ COLUMNS.UUID.name + ", "
|
||||
+ COLUMNS.COUNT.name + ", "
|
||||
+ COLUMNS.LAST_COOLDOWN_DATE.name + ") VALUES(?, ?, ?)";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(data.player.getUniqueId().toString());
|
||||
add(data.getRtpCount());
|
||||
add(data.getGlobalCooldown());
|
||||
}};
|
||||
sqlUpdate(sql, params);
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+77
-119
@@ -11,7 +11,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -48,124 +52,72 @@ public class DatabaseQueue extends SQLite {
|
||||
}
|
||||
}
|
||||
|
||||
/*public List<QueueData> getAll() {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
List<QueueData> queueDataList = new ArrayList<>();
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0));
|
||||
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
long x = rs.getLong(COLUMNS.X.name);
|
||||
long z = rs.getLong(COLUMNS.Z.name);
|
||||
String worldName = rs.getString(COLUMNS.WORLD.name);
|
||||
int id = rs.getInt(COLUMNS.ID.name);
|
||||
long generated = rs.getLong(COLUMNS.GENERATED.name);
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
queueDataList.add(new QueueData(new Location(world, x, 69, z), generated, id));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
}
|
||||
return queueDataList;
|
||||
}*/
|
||||
|
||||
@Override public void load() {
|
||||
if (QueueHandler.isEnabled())
|
||||
super.load();
|
||||
}
|
||||
|
||||
public List<QueueData> getInRange(QueueRangeData range) {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
List<QueueData> queueDataList = new ArrayList<>();
|
||||
final List<QueueData> queueDataList = new ArrayList<>();
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
//ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE ? BETWEEN ? AND ? AND ? BETWEEN ? AND ?");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE "
|
||||
+ COLUMNS.WORLD.name + " = '" + range.getWorld().getName() + "' AND "
|
||||
+ COLUMNS.X.name + " BETWEEN " + range.getXLow() + " AND " + range.getXHigh()
|
||||
+ " AND " + COLUMNS.Z.name + " BETWEEN " + range.getZLow() + " AND " + range.getZHigh()
|
||||
+ " ORDER BY RANDOM() LIMIT " + (QueueGenerator.queueMax + 1)
|
||||
);
|
||||
/*ps.setString(1, COLUMNS.X.name);
|
||||
ps.setInt(2, range.getXLow());
|
||||
ps.setInt(3, range.getXHigh());
|
||||
ps.setString(4, COLUMNS.Z.name);
|
||||
ps.setInt(5, range.getZLow());
|
||||
ps.setInt(6, range.getZHigh());*/
|
||||
|
||||
//BetterRTP.getInstance().getLogger().info(ps.toString());
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
long x = rs.getLong(COLUMNS.X.name);
|
||||
long z = rs.getLong(COLUMNS.Z.name);
|
||||
String worldName = rs.getString(COLUMNS.WORLD.name);
|
||||
int id = rs.getInt(COLUMNS.ID.name);
|
||||
long generated = rs.getLong(COLUMNS.GENERATED.name);
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
queueDataList.add(new QueueData(new Location(world, x, 69 /*giggity*/, z), generated, id));
|
||||
//queueDataList.add(data);
|
||||
SQLiteExecutor.EXECUTOR.submit(() -> {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE "
|
||||
+ COLUMNS.WORLD.name + " = '" + range.getWorld().getName() + "' AND "
|
||||
+ COLUMNS.X.name + " BETWEEN " + range.getXLow() + " AND " + range.getXHigh()
|
||||
+ " AND " + COLUMNS.Z.name + " BETWEEN " + range.getZLow() + " AND " + range.getZHigh()
|
||||
+ " ORDER BY RANDOM() LIMIT " + (QueueGenerator.queueMax + 1)
|
||||
);
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
long x = rs.getLong(COLUMNS.X.name);
|
||||
long z = rs.getLong(COLUMNS.Z.name);
|
||||
String worldName = rs.getString(COLUMNS.WORLD.name);
|
||||
int id = rs.getInt(COLUMNS.ID.name);
|
||||
long generated = rs.getLong(COLUMNS.GENERATED.name);
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
queueDataList.add(new QueueData(new Location(world, x, 69, z), generated, id));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
}).get();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return queueDataList;
|
||||
}
|
||||
|
||||
//Set a queue to save
|
||||
public QueueData addQueue(Location loc) {
|
||||
String pre = "INSERT INTO ";
|
||||
String sql = pre + tables.get(0) + " ("
|
||||
+ COLUMNS.X.name + ", "
|
||||
+ COLUMNS.Z.name + ", "
|
||||
+ COLUMNS.WORLD.name + ", "
|
||||
+ COLUMNS.GENERATED.name + " "
|
||||
//+ COLUMNS.USES.name + " "
|
||||
+ ") VALUES(?, ?, ?, ?)";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(loc.getBlockX());
|
||||
add(loc.getBlockZ());
|
||||
add(loc.getWorld().getName());
|
||||
add(System.currentTimeMillis());
|
||||
//add(data.getUses());
|
||||
}};
|
||||
//return sqlUpdate(sql, params);
|
||||
int database_id = createQueue(sql, params);
|
||||
if (database_id >= 0)
|
||||
return new QueueData(loc, System.currentTimeMillis(), database_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
Connection conn = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
int count = 0;
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + tables.get(0));
|
||||
|
||||
rs = ps.executeQuery();
|
||||
count = rs.getFetchSize();
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
} finally {
|
||||
close(ps, rs, conn);
|
||||
return SQLiteExecutor.EXECUTOR.submit(() -> {
|
||||
String sql = "INSERT INTO " + tables.get(0) + " ("
|
||||
+ COLUMNS.X.name + ", "
|
||||
+ COLUMNS.Z.name + ", "
|
||||
+ COLUMNS.WORLD.name + ", "
|
||||
+ COLUMNS.GENERATED.name + ") VALUES(?, ?, ?, ?)";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(loc.getBlockX());
|
||||
add(loc.getBlockZ());
|
||||
add(loc.getWorld().getName());
|
||||
add(System.currentTimeMillis());
|
||||
}};
|
||||
int database_id = createQueue(sql, params);
|
||||
return database_id >= 0 ? new QueueData(loc, System.currentTimeMillis(), database_id) : null;
|
||||
}).get();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private int createQueue(String statement, @NonNull List<Object> params) {
|
||||
@@ -195,24 +147,31 @@ public class DatabaseQueue extends SQLite {
|
||||
}
|
||||
|
||||
public boolean removeLocation(Location loc) {
|
||||
String sql = "DELETE FROM " + tables.get(0) + " WHERE "
|
||||
+ COLUMNS.X.name + " = ? AND "
|
||||
+ COLUMNS.Z.name + " = ? AND "
|
||||
+ COLUMNS.WORLD.name + " = ?"
|
||||
;
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(loc.getBlockX());
|
||||
add(loc.getBlockZ());
|
||||
add(loc.getWorld().getName());
|
||||
}};
|
||||
return sqlUpdate(sql, params);
|
||||
try {
|
||||
return SQLiteExecutor.EXECUTOR.submit(() -> {
|
||||
String sql = "DELETE FROM " + tables.get(0) + " WHERE "
|
||||
+ COLUMNS.X.name + " = ? AND "
|
||||
+ COLUMNS.Z.name + " = ? AND "
|
||||
+ COLUMNS.WORLD.name + " = ?";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(loc.getBlockX());
|
||||
add(loc.getBlockZ());
|
||||
add(loc.getWorld().getName());
|
||||
}};
|
||||
return sqlUpdate(sql, params);
|
||||
}).get();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class QueueRangeData {
|
||||
|
||||
@Getter int xLow, xHigh;
|
||||
@Getter int zLow, zHigh;
|
||||
@Getter World world;
|
||||
int xLow, xHigh;
|
||||
int zLow, zHigh;
|
||||
World world;
|
||||
|
||||
public QueueRangeData(RTPWorld rtpWorld) {
|
||||
this.xLow = rtpWorld.getCenterX() - rtpWorld.getMaxRadius();
|
||||
@@ -221,6 +180,5 @@ public class DatabaseQueue extends SQLite {
|
||||
this.zHigh = rtpWorld.getCenterZ() + rtpWorld.getMaxRadius();
|
||||
this.world = rtpWorld.getWorld();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.database;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SQLiteExecutor {
|
||||
public static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
-3
@@ -19,9 +19,6 @@ public class RTP_WorldGuard implements RegionPluginCheck {
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(loc));
|
||||
//for (ProtectedRegion region : set.getRegions()) {
|
||||
// region.getId()
|
||||
//}
|
||||
result = set.size() == 0;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.player.playerdata;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,7 +17,7 @@ public class PlayerData {
|
||||
//Menus
|
||||
@Getter final PlayerData_Menus menu = new PlayerData_Menus();
|
||||
//Player Data
|
||||
@Getter final HashMap<World, CooldownData> cooldowns = new HashMap<>();
|
||||
@Getter final Map<World, CooldownData> cooldowns = new ConcurrentHashMap<>();
|
||||
//@Getter @Setter CooldownData globalCooldown;
|
||||
@Getter @Setter boolean rtping;
|
||||
@Getter @Setter int rtpCount;
|
||||
|
||||
+6
-10
@@ -4,25 +4,21 @@ import lombok.NonNull;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerDataManager {
|
||||
|
||||
private final HashMap<Player, PlayerData> playerData = new HashMap<>();
|
||||
private final Map<UUID, PlayerData> playerData = new ConcurrentHashMap<>();
|
||||
|
||||
public PlayerData getData(@NonNull Player p) {
|
||||
if (!playerData.containsKey(p))
|
||||
playerData.put(p, new PlayerData(p));
|
||||
return playerData.get(p);
|
||||
return playerData.computeIfAbsent(p.getUniqueId(), uuid -> new PlayerData(p));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PlayerData getData(UUID id) {
|
||||
for (Player p : playerData.keySet())
|
||||
if (p.getUniqueId().equals(id))
|
||||
return playerData.get(p);
|
||||
return null;
|
||||
return playerData.get(id);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@@ -30,6 +26,6 @@ public class PlayerDataManager {
|
||||
}
|
||||
|
||||
public void clear(Player p) {
|
||||
playerData.remove(p);
|
||||
playerData.remove(p.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
+28
-70
@@ -1,8 +1,8 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -26,11 +26,9 @@ public class CooldownHandler {
|
||||
@Getter boolean enabled, loaded, cooldownByWorld;
|
||||
@Getter private int defaultCooldownTime; //Global Cooldown timer
|
||||
private int lockedAfter; //Rtp's before being locked
|
||||
private final List<Player> downloading = new ArrayList<>();
|
||||
//private final DatabaseCooldownsGlobal globalCooldown = new DatabaseCooldownsGlobal();
|
||||
private final List<Player> downloading = new CopyOnWriteArrayList<>();
|
||||
|
||||
public void load() {
|
||||
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||
FileOther.FILETYPE config = FileOther.FILETYPE.CONFIG;
|
||||
enabled = config.getBoolean("Settings.Cooldown.Enabled");
|
||||
downloading.clear();
|
||||
@@ -54,7 +52,6 @@ public class CooldownHandler {
|
||||
queueDownload();
|
||||
return;
|
||||
}
|
||||
//OldCooldownConverter.loadOldCooldowns();
|
||||
//Load any online players cooldowns (mostly after a reload)
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
loadPlayer(p);
|
||||
@@ -66,7 +63,7 @@ public class CooldownHandler {
|
||||
if (!enabled) return;
|
||||
PlayerData playerData = getData(player);
|
||||
if (cooldownByWorld) {
|
||||
HashMap<World, CooldownData> cooldowns = playerData.getCooldowns();
|
||||
Map<World, CooldownData> cooldowns = playerData.getCooldowns();
|
||||
CooldownData data = cooldowns.getOrDefault(world, new CooldownData(player.getUniqueId(), 0L));
|
||||
playerData.setRtpCount(playerData.getRtpCount() + 1);
|
||||
data.setTime(System.currentTimeMillis());
|
||||
@@ -89,7 +86,7 @@ public class CooldownHandler {
|
||||
public CooldownData get(Player p, World world) {
|
||||
PlayerData data = getData(p);
|
||||
if (cooldownByWorld) {
|
||||
HashMap<World, CooldownData> cooldownData = getData(p).getCooldowns();
|
||||
Map<World, CooldownData> cooldownData = getData(p).getCooldowns();
|
||||
if (data != null)
|
||||
return cooldownData.getOrDefault(world, null);
|
||||
} else if (data.getGlobalCooldown() > 0) {
|
||||
@@ -101,8 +98,6 @@ public class CooldownHandler {
|
||||
public long timeLeft(CommandSender sendi, CooldownData data, WorldPlayer pWorld) {
|
||||
long cooldown = data.getTime();
|
||||
long timeLeft = ((cooldown / 1000) + pWorld.getCooldown()) - (System.currentTimeMillis() / 1000);
|
||||
//if (BetterRTP.getInstance().getSettings().isDelayEnabled() && !PermissionNode.BYPASS_DELAY.check(sendi))
|
||||
// timeLeft = timeLeft + BetterRTP.getInstance().getSettings().getDelayTime();
|
||||
return timeLeft * 1000L;
|
||||
}
|
||||
|
||||
@@ -116,7 +111,6 @@ public class CooldownHandler {
|
||||
CooldownData cooldownData = playerData.getCooldowns().getOrDefault(world, null);
|
||||
if (cooldownData != null) {
|
||||
if (lockedAfter > 0) {
|
||||
//uses.put(id, uses.getOrDefault(id, 1) - 1);
|
||||
if (playerData.getRtpCount() <= 0) { //Remove from file as well
|
||||
savePlayer(player, world, cooldownData, true);
|
||||
getData(player).getCooldowns().put(world, null);
|
||||
@@ -146,19 +140,31 @@ public class CooldownHandler {
|
||||
}
|
||||
|
||||
public void loadPlayer(Player player) {
|
||||
if (!isEnabled()) return;
|
||||
downloading.add(player);
|
||||
if (!isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = getData(player);
|
||||
if (getDatabaseWorlds() != null) //Per World enabled?
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
//Cooldowns
|
||||
CooldownData cooldown = getDatabaseWorlds().getCooldown(player.getUniqueId(), world);
|
||||
if (cooldown != null)
|
||||
playerData.getCooldowns().put(world, cooldown);
|
||||
if (playerData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
downloading.add(player);
|
||||
|
||||
try {
|
||||
if (getDatabaseWorlds() != null) { //Per World enabled?
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
//Cooldowns
|
||||
CooldownData cooldown = getDatabaseWorlds().getCooldown(player.getUniqueId(), world);
|
||||
if (cooldown != null)
|
||||
playerData.getCooldowns().put(world, cooldown);
|
||||
}
|
||||
}
|
||||
//Player Data
|
||||
DatabaseHandler.getPlayers().setupData(playerData);
|
||||
downloading.remove(player);
|
||||
//Player Data
|
||||
DatabaseHandler.getPlayers().setupData(playerData);
|
||||
} finally {
|
||||
downloading.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadedPlayer(Player player) {
|
||||
@@ -176,51 +182,3 @@ public class CooldownHandler {
|
||||
return HelperPlayer.getData(p);
|
||||
}
|
||||
}
|
||||
|
||||
//Old yaml file based system, no longer useful as of 3.3.1
|
||||
/*@Deprecated
|
||||
static class OldCooldownConverter {
|
||||
|
||||
static void loadOldCooldowns() {
|
||||
File file = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||
YamlConfiguration config = getFile(file);
|
||||
if (config == null) return;
|
||||
if (config.getBoolean("Converted")) return;
|
||||
List<CooldownData> cooldownData = new ArrayList<>();
|
||||
for (String id : config.getConfigurationSection("").getKeys(false)) {
|
||||
try {
|
||||
Long time = config.getLong(id + ".Time");
|
||||
UUID uuid = UUID.fromString(id);
|
||||
int uses = config.getInt(id + ".Attempts");
|
||||
cooldownData.add(new CooldownData(uuid, time, uses));
|
||||
} catch (IllegalArgumentException e) {
|
||||
//Invalid UUID
|
||||
}
|
||||
}
|
||||
config.set("Converted", true);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BetterRTP.getInstance().getLogger().info("Cooldowns converting to new database...");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||
BetterRTP.getInstance().getDatabaseCooldowns().setCooldown(cooldownData);
|
||||
BetterRTP.getInstance().getLogger().info("Cooldowns have been converted to the new database!");
|
||||
});
|
||||
}
|
||||
|
||||
private static YamlConfiguration getFile(File configfile) {
|
||||
if (!configfile.exists()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.load(configfile);
|
||||
return config;
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -25,44 +25,32 @@ public class RandomLocation {
|
||||
}
|
||||
|
||||
private static Location generateSquare(RTPWorld rtpWorld) {
|
||||
//Generate a random X and Z based off the quadrant selected
|
||||
int min = rtpWorld.getMinRadius();
|
||||
int max = rtpWorld.getMaxRadius() - min;
|
||||
int x, z;
|
||||
int quadrant = new Random().nextInt(4);
|
||||
// Return a Location where a random X and Z are within the bounds defined by MinRadius and MaxRadius
|
||||
int radius_min = rtpWorld.getMinRadius();
|
||||
int radius_max = rtpWorld.getMaxRadius();
|
||||
try {
|
||||
switch (quadrant) {
|
||||
case 0: // Positive X and Z
|
||||
x = new Random().nextInt(max) + min;
|
||||
z = new Random().nextInt(max) + min;
|
||||
break;
|
||||
case 1: // Negative X and Z
|
||||
x = -new Random().nextInt(max) - min;
|
||||
z = -(new Random().nextInt(max) + min);
|
||||
break;
|
||||
case 2: // Negative X and Positive Z
|
||||
x = -new Random().nextInt(max) - min;
|
||||
z = new Random().nextInt(max) + min;
|
||||
break;
|
||||
default: // Positive X and Negative Z
|
||||
x = new Random().nextInt(max) + min;
|
||||
z = -(new Random().nextInt(max) + min);
|
||||
break;
|
||||
if (radius_min < 0 || radius_max < 0 || radius_min >= radius_max) {
|
||||
throw new IllegalArgumentException(); // If MinRadius or MaxRadius is negative, throw an exception
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
BetterRTP.getInstance().getLogger().warning("A bounding location was negative! Please check your config only has positive x/z for max/min radius!");
|
||||
BetterRTP.getInstance().getLogger().warning("Incorrect configuration! Check your config and confirm that MinRadius is smaller than MaxRadius and that they are both positive numbers!");
|
||||
BetterRTP.getInstance().getLogger().warning("Max: " + rtpWorld.getMaxRadius() + " Min: " + rtpWorld.getMinRadius());
|
||||
return null;
|
||||
}
|
||||
// Generate a random X and Z based off the radius. No quadrants voodoo.
|
||||
Random random = new Random();
|
||||
int x = random.nextInt(radius_max * 2) - radius_max;
|
||||
int z = (Math.abs(x) >= radius_min)
|
||||
? random.nextInt(radius_max * 2) - radius_max
|
||||
: (random.nextBoolean() ? 1 : -1) * (radius_min + random.nextInt(radius_max - radius_min));
|
||||
x += rtpWorld.getCenterX();
|
||||
z += rtpWorld.getCenterZ();
|
||||
//System.out.println(quadrant);
|
||||
return new Location(rtpWorld.getWorld(), x, 69, z);
|
||||
}
|
||||
|
||||
private static Location generateRound(RTPWorld rtpWorld) {
|
||||
//Generate a random X and Z based off location on a spiral curve
|
||||
// Return a random X and Z based off location on a spiral curve
|
||||
int min = rtpWorld.getMinRadius();
|
||||
int max = rtpWorld.getMaxRadius() - min;
|
||||
int x, z;
|
||||
|
||||
@@ -9,26 +9,21 @@ public class AsyncHandler {
|
||||
|
||||
public static void async(Runnable runnable) {
|
||||
getFolia().runAsync(task -> runnable.run());
|
||||
//Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), runnable);
|
||||
}
|
||||
|
||||
public static void sync(Runnable runnable) {
|
||||
getFolia().runNextTick(task -> runnable.run());
|
||||
//Bukkit.getScheduler().runTask(BetterRTP.getInstance(), runnable);
|
||||
}
|
||||
|
||||
public static void syncAtEntity(Entity entity, Runnable runnable) {
|
||||
getFolia().runAtEntity(entity, task -> runnable.run());
|
||||
//Bukkit.getScheduler().runTask(BetterRTP.getInstance(), runnable);
|
||||
}
|
||||
|
||||
public static WrappedTask asyncLater(Runnable runnable, long ticks) {
|
||||
return getFolia().runLaterAsync(runnable, ticks);
|
||||
//return Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), runnable, ticks);
|
||||
}
|
||||
public static WrappedTask syncLater(Runnable runnable, long ticks) {
|
||||
return getFolia().runLater(runnable, ticks);
|
||||
//return Bukkit.getScheduler().runTaskLater(BetterRTP.getInstance(), runnable, ticks);
|
||||
}
|
||||
|
||||
private static ServerImplementation getFolia() {
|
||||
|
||||
@@ -25,7 +25,7 @@ softdepend:
|
||||
- Multiverse-Core #Forcing Multiverse to load BEFORE BetterRTP
|
||||
- Essentials #adds `/back` support
|
||||
- PlaceholderAPI
|
||||
- HuskClaims #fixed condition race which breaks hooking
|
||||
- HuskClaims #Respect HuskClaims areas (https://www.spigotmc.org/resources/huskclaims-1-17-1-21-modern-golden-shovel-land-claiming-fully-cross-server-compatible.114467/) (fixes race condition that breaks hooking)
|
||||
api-version: '1.13'
|
||||
|
||||
commands:
|
||||
|
||||
Reference in New Issue
Block a user