Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed May 2, 2024
2 parents a2d5874 + 73e2c27 commit 2d305f3
Show file tree
Hide file tree
Showing 38 changed files with 69 additions and 79 deletions.
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
<paper.version>1.20.4-R0.1-SNAPSHOT</paper.version>
<spigot.version>1.20.5-R0.1-SNAPSHOT</spigot.version>
<paper.version>1.20.6-R0.1-SNAPSHOT</paper.version>
<spigot.version>1.20.6-R0.1-SNAPSHOT</spigot.version>
<worldguard.version>7.0.9</worldguard.version>
<placeholderapi.version>2.11.5</placeholderapi.version>
<griefprevention.version>16.18.2</griefprevention.version>
<plotsquared.version>7.3.8</plotsquared.version>
<viaversion.version>4.9.3</viaversion.version>
<viaversion.version>4.10.0</viaversion.version>
</properties>

<repositories>
Expand Down
29 changes: 7 additions & 22 deletions core/src/main/java/dev/geco/gsit/GSitMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.event.*;
import org.bukkit.plugin.*;
import org.bukkit.plugin.java.*;

Expand Down Expand Up @@ -80,12 +81,6 @@ public class GSitMain extends JavaPlugin {
private WorldGuardLink worldGuardLink;
public WorldGuardLink getWorldGuardLink() { return worldGuardLink; }

private boolean supportsSpigotMountFeature = false;
public boolean supportsSpigotMountFeature() { return supportsSpigotMountFeature; }

private boolean supportsBukkitMountFeature = false;
public boolean supportsBukkitMountFeature() { return supportsBukkitMountFeature; }

private boolean supportsPaperFeature = false;
public boolean supportsPaperFeature() { return supportsPaperFeature; }

Expand Down Expand Up @@ -216,23 +211,16 @@ private void setupEvents() {
getServer().getPluginManager().registerEvents(new PlayerSitEvents(getInstance()), getInstance());
getServer().getPluginManager().registerEvents(new BlockEvents(getInstance()), getInstance());
getServer().getPluginManager().registerEvents(new InteractEvents(getInstance()), getInstance());
getServer().getPluginManager().registerEvents(supportsBukkitMountFeature() ? new EntityEvents(getInstance()) : new dev.geco.gsit.events.deprecated.EntityEvents(getInstance()), getInstance());

Listener entityEvents = getSVManager().isNewerOrVersion(17, 0) ? (Listener) getSVManager().getPackageObject("events.EntityEvents", getInstance()) : null;
if(entityEvents == null) entityEvents = (Listener) getSVManager().getLegacyPackageObject("events.EntityEvents", getInstance());
if(entityEvents != null) getServer().getPluginManager().registerEvents(entityEvents, getInstance());

getServer().getPluginManager().registerEvents(new SpinConfusionEvent(getInstance()), getInstance());
}

private void preloadPluginDependencies() {

try {
Class.forName("org.spigotmc.event.entity.EntityMountEvent");
supportsSpigotMountFeature = true;
} catch (ClassNotFoundException ignored) { supportsSpigotMountFeature = false; }

try {
Class.forName("org.bukkit.event.entity.EntityMountEvent");
supportsBukkitMountFeature = true;
} catch (ClassNotFoundException ignored) { supportsBukkitMountFeature = false; }

try {
Class.forName("io.papermc.paper.event.entity.EntityMoveEvent");
supportsPaperFeature = true;
Expand Down Expand Up @@ -321,12 +309,9 @@ private boolean connectDatabase(CommandSender Sender) {

private boolean versionCheck() {

boolean baseMissing = !supportsSpigotMountFeature() && !supportsBukkitMountFeature();
boolean internalMissing = !getSVManager().isAvailable();

if(baseMissing || !getSVManager().isNewerOrVersion(16, 0) || (getSVManager().isNewerOrVersion(17, 0) && internalMissing)) {
if(!getSVManager().isNewerOrVersion(16, 0) || (getSVManager().isNewerOrVersion(17, 0) && !getSVManager().isAvailable())) {

getMManager().sendMessage(Bukkit.getConsoleSender(), "Plugin.plugin-version", "%Version%", baseMissing ? "outdated-server" : getSVManager().getServerVersion());
getMManager().sendMessage(Bukkit.getConsoleSender(), "Plugin.plugin-version", "%Version%", getSVManager().getServerVersion());

getUManager().checkForUpdates();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void PGetUPE(PlayerGetUpPoseEvent Event) {

if(!GPM.getCManager().FEATUREFLAGS.contains("SPIN_CONFUSION")) return;

Event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 120, 2));
Event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(GPM.getSVManager().isNewerOrVersion(20, 5) ? "NAUSEA" : "CONFUSION"), 120, 2));
}

}
23 changes: 14 additions & 9 deletions core/src/main/java/dev/geco/gsit/manager/DManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DManager {

private final GSitMain GPM;

private final int MAX_RETRIES = 3;
protected final int MAX_RETRIES = 3;

private Connection connection;
private String type = null;
Expand Down Expand Up @@ -40,38 +40,43 @@ public boolean connect() {
private boolean reconnect() {
try {
if(type.equals("sqlite")) Class.forName("org.sqlite.JDBC");
connection = getConnection();
connection = getConnection(false);
if(connection != null) {
if(!type.equals("sqlite")) execute("CREATE DATABASE IF NOT EXISTS " + database);
retries = 0;
return true;
if(!type.equals("sqlite")) {
execute("CREATE DATABASE IF NOT EXISTS " + database);
connection = getConnection(true);
}
if(connection != null) {
retries = 0;
return true;
}
}
} catch (Exception e) { e.printStackTrace(); }
if(retries == MAX_RETRIES) return false;
retries++;
return reconnect();
}

private Connection getConnection() throws SQLException {
private Connection getConnection(boolean WithDatabase) throws SQLException {
switch(type) {
case "mysql":
return DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
return DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + (WithDatabase ? "/" + database : ""), user, password);
case "sqlite":
return DriverManager.getConnection("jdbc:sqlite:" + new File(GPM.getDataFolder(), "data/data.db").getPath());
}
return null;
}

public boolean execute(String Query, Object... Data) throws SQLException {
if(connection == null) throw new SQLException("missing database connection");
if(connection == null) throw new SQLException("missing " + type + " database connection");
if(connection.isClosed() && !reconnect()) return false;
PreparedStatement preparedStatement = connection.prepareStatement(Query);
for(int i = 1; i <= Data.length; i++) preparedStatement.setObject(i, Data[i - 1]);
return preparedStatement.execute();
}

public ResultSet executeAndGet(String Query, Object... Data) throws SQLException {
if(connection == null) throw new SQLException("missing database connection");
if(connection == null) throw new SQLException("missing " + type + " database connection");
if(connection.isClosed() && !reconnect()) return null;
PreparedStatement preparedStatement = connection.prepareStatement(Query);
for(int i = 1; i <= Data.length; i++) preparedStatement.setObject(i, Data[i - 1]);
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/dev/geco/gsit/manager/SVManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SVManager {
VERSION_MAPPING.put("v1_19_2", "v1_19_1");
VERSION_MAPPING.put("v1_20_1", "v1_20");
VERSION_MAPPING.put("v1_20_4", "v1_20_3");
VERSION_MAPPING.put("v1_20_6", "v1_20_5");
}

public SVManager(GSitMain GPluginMain) {
Expand Down Expand Up @@ -47,6 +48,16 @@ public boolean isVersion(int Version, int SubVersion) {
return version.length > 2 ? Integer.parseInt(version[1]) == Version && Integer.parseInt(version[2]) == SubVersion : Integer.parseInt(version[1]) == Version && SubVersion == 0;
}

public Object getLegacyPackageObject(String ClassName, Object... Objects) {
try {
Class<?> mcvClass = Class.forName(GPM.getClass().getPackage().getName() + ".mcv.v1_17_1." + ClassName);
if(Objects.length == 0) return mcvClass.getConstructor().newInstance();
Class<?>[] classes = Arrays.stream(Objects).map(Object::getClass).toArray(Class<?>[]::new);
return mcvClass.getConstructor(classes).newInstance(Objects);
} catch (Throwable e) { e.printStackTrace(); }
return null;
}

public Object getPackageObject(String ClassName, Object... Objects) {
try {
Class<?> mcvClass = Class.forName(PACKAGE_PATH + "." + ClassName);
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/dev/geco/gsit/util/EntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public boolean isPlayerSitLocationValid(Entity Holder) {
org.bukkit.util.Consumer<AreaEffectCloud> consumer = (areaEffectCloud) -> {

try { areaEffectCloud.setRadius(0); } catch (Throwable ignored) { }
try { areaEffectCloud.setParticle(Particle.BLOCK_CRACK, Material.AIR.createBlockData()); } catch (Throwable ignored) { }
try { areaEffectCloud.setWaitTime(0); } catch (Throwable ignored) { }
};

Expand Down Expand Up @@ -150,7 +149,6 @@ public UUID createPlayerSeatEntity(Entity Holder, Entity Rider) {
try { areaEffectCloud.setGravity(false); } catch (Throwable ignored) { }
try { areaEffectCloud.setInvulnerable(true); } catch (Throwable ignored) { }
try { areaEffectCloud.setDuration(Integer.MAX_VALUE); } catch (Throwable ignored) { }
try { areaEffectCloud.setParticle(Particle.BLOCK_CRACK, Material.AIR.createBlockData()); } catch (Throwable ignored) { }
try { areaEffectCloud.setWaitTime(0); } catch (Throwable ignored) { }
areaEffectCloud.addScoreboardTag(GPM.NAME + "_PlayerSeatEntity");
finalLastEntity.addPassenger(areaEffectCloud);
Expand Down
2 changes: 1 addition & 1 deletion dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<build>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_17/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.geco.gsit.events.deprecated;
package dev.geco.gsit.mcv.x.events;

import org.bukkit.*;
import org.bukkit.entity.*;
Expand Down
2 changes: 1 addition & 1 deletion mcv1_17_1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_18/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_18_R1.*;

import net.minecraft.core.particles.*;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.block.*;

public class PlayerSeatEntity extends AreaEffectCloud {

Expand All @@ -19,7 +17,6 @@ public PlayerSeatEntity(Location Location) {
setNoGravity(true);
setInvulnerable(true);
setDuration(Integer.MAX_VALUE);
setParticle(new BlockParticleOption(ParticleTypes.BLOCK, Blocks.AIR.defaultBlockState()));
setWaitTime(0);
addTag("GSit_PlayerSeatEntity");
}
Expand Down
2 changes: 1 addition & 1 deletion mcv1_18_2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_19/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_19_1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_19_R1.*;

import net.minecraft.core.particles.*;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.block.*;

public class PlayerSeatEntity extends AreaEffectCloud {

Expand All @@ -19,7 +17,6 @@ public PlayerSeatEntity(Location Location) {
setNoGravity(true);
setInvulnerable(true);
setDuration(Integer.MAX_VALUE);
setParticle(new BlockParticleOption(ParticleTypes.BLOCK, Blocks.AIR.defaultBlockState()));
setWaitTime(0);
addTag("GSit_PlayerSeatEntity");
}
Expand Down
2 changes: 1 addition & 1 deletion mcv1_19_3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_19_4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_19_R3.*;

import net.minecraft.core.particles.*;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.block.*;

public class PlayerSeatEntity extends AreaEffectCloud {

Expand All @@ -19,7 +17,6 @@ public PlayerSeatEntity(Location Location) {
setNoGravity(true);
setInvulnerable(true);
setDuration(Integer.MAX_VALUE);
setParticle(new BlockParticleOption(ParticleTypes.BLOCK, Blocks.AIR.defaultBlockState()));
setWaitTime(0);
addTag("GSit_PlayerSeatEntity");
}
Expand Down
2 changes: 1 addition & 1 deletion mcv1_20/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_20_2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion mcv1_20_3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions mcv1_20_5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<parent>
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>

<properties>
<maven.compiler.release>21</maven.compiler.release>
<spigot.version>1.20.5-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.6-R0.1-SNAPSHOT</spigot.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.geco.gsit.events;
package dev.geco.gsit.mcv.x.events;

import org.bukkit.*;
import org.bukkit.entity.*;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>dev.geco.gsit</groupId>
<artifactId>GSit</artifactId>
<name>GSit</name>
<version>1.9.0</version>
<version>1.9.1</version>
<description>Relax with other players on nice seats!</description>
<url>https://www.spigotmc.org/resources/62325</url>
<inceptionYear>2018</inceptionYear>
Expand Down
Loading

0 comments on commit 2d305f3

Please sign in to comment.