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 Jan 19, 2024
2 parents 9cbfbaf + 4096c46 commit f64f35f
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 86 deletions.
45 changes: 29 additions & 16 deletions core/src/main/java/dev/geco/gsit/GSitMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ public class GSitMain extends JavaPlugin {
private WorldGuardLink worldGuardLink;
public WorldGuardLink getWorldGuardLink() { return worldGuardLink; }

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

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

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

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

public final String NAME = "GSit";

Expand Down Expand Up @@ -147,7 +150,7 @@ public void onLoad() {

preloadPluginDependencies();

mManager = isBasicPaperBased() && getSVManager().isNewerOrVersion(18, 2) ? new MPaperManager(getInstance()) : new MSpigotManager(getInstance());
mManager = supportsPaperFeature() && getSVManager().isNewerOrVersion(18, 2) ? new MPaperManager(getInstance()) : new MSpigotManager(getInstance());
}

public void onEnable() {
Expand Down Expand Up @@ -213,26 +216,32 @@ 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());

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

private void preloadPluginDependencies() {

try {
Class.forName("org.spigotmc.event.entity.EntityDismountEvent");
spigotBased = true;
} catch (ClassNotFoundException ignored) { }
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");
basicPaperBased = true;
} catch (ClassNotFoundException ignored) { }
supportsPaperFeature = true;
} catch (ClassNotFoundException ignored) { supportsPaperFeature = false; }

try {
Class.forName("io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler");
paperBased = true;
} catch (ClassNotFoundException ignored) { }
supportsTaskFeature = true;
} catch (ClassNotFoundException ignored) { supportsTaskFeature = false; }

if(Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
worldGuardLink = new WorldGuardLink(getInstance());
Expand Down Expand Up @@ -312,11 +321,15 @@ private boolean connectDatabase(CommandSender Sender) {

private boolean versionCheck() {

if(!isSpigotBased() || !getSVManager().isNewerOrVersion(13, 0) || (getSVManager().isNewerOrVersion(17, 0) && !getSVManager().hasPackageClass("objects.SeatEntity"))) {
boolean baseMissing = !supportsSpigotMountFeature() && !supportsBukkitMountFeature();

if(getCManager().DEBUG) getMManager().sendMessage(Bukkit.getConsoleSender(), supportsSpigotMountFeature() + " " + supportsBukkitMountFeature() + " " + supportsPaperFeature() + " " + supportsTaskFeature());

if(baseMissing || !getSVManager().isNewerOrVersion(13, 0) || (getSVManager().isNewerOrVersion(17, 0) && !getSVManager().hasPackageClass("objects.SeatEntity"))) {

String version = Bukkit.getServer().getClass().getPackage().getName();

getMManager().sendMessage(Bukkit.getConsoleSender(), "Plugin.plugin-version", "%Version%", !isSpigotBased() ? "bukkit-based" : version.substring(version.lastIndexOf('.') + 1));
getMManager().sendMessage(Bukkit.getConsoleSender(), "Plugin.plugin-version", "%Version%", baseMissing ? "outdated-server" : version.substring(version.lastIndexOf('.') + 1));

getUManager().checkForUpdates();

Expand Down
75 changes: 75 additions & 0 deletions core/src/main/java/dev/geco/gsit/events/EntityEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package dev.geco.gsit.events;

import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.entity.*;

import dev.geco.gsit.GSitMain;
import dev.geco.gsit.api.event.*;
import dev.geco.gsit.objects.*;

public class EntityEvents implements Listener {

private final GSitMain GPM;

public EntityEvents(GSitMain GPluginMain) { GPM = GPluginMain; }

@EventHandler(priority = EventPriority.HIGHEST)
public void EMouE(EntityMountEvent Event) { if(Event.isCancelled() && (Event.getMount().getScoreboardTags().contains(GPM.NAME + "_SeatEntity") || Event.getMount().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity"))) Event.setCancelled(false); }

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void EDisE(EntityDismountEvent Event) {

if(Event.getEntity() instanceof Player) {

Player player = (Player) Event.getEntity();

if (GPM.getSitManager().isSitting(player) && (!GPM.getCManager().GET_UP_SNEAK || (!GPM.getSitManager().removeSeat(player, GetUpReason.GET_UP, true)))) {

Event.setCancelled(true);
return;
}

if (GPM.getPoseManager().isPosing(player) && (!GPM.getCManager().GET_UP_SNEAK || !GPM.getPoseManager().removePose(player, GetUpReason.GET_UP, true))) {

Event.setCancelled(true);
return;
}
}

if(!Event.getDismounted().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity") && !(Event.getDismounted() instanceof Player)) return;

if(Event.getEntity() instanceof Player) {

Player player = (Player) Event.getEntity();

PrePlayerGetUpPlayerSitEvent preEvent = new PrePlayerGetUpPlayerSitEvent(player, GetUpReason.GET_UP);

Bukkit.getPluginManager().callEvent(preEvent);

if(preEvent.isCancelled()) {

Event.setCancelled(true);
return;
}

GPM.getPlayerSitManager().WAIT_EJECT.add(player);

GPM.getTManager().runDelayed(() -> {
GPM.getPlayerSitManager().WAIT_EJECT.remove(player);
}, 2);
}

Entity bottom = GPM.getPassengerUtil().getBottomEntity(Event.getDismounted());

if(GPM.getCManager().PS_BOTTOM_RETURN && Event.getEntity().isValid() && Event.getEntity() instanceof Player && GPM.getPackageUtil() != null) GPM.getEntityUtil().posEntity(Event.getEntity(), bottom.getLocation());

if(Event.getDismounted().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity") && GPM.getPackageUtil() == null) GPM.getEntityUtil().posEntity(Event.getDismounted(), bottom.getLocation());

GPM.getPlayerSitManager().stopPlayerSit(Event.getDismounted(), GetUpReason.GET_UP);

if(Event.getEntity() instanceof Player) Bukkit.getPluginManager().callEvent(new PlayerGetUpPlayerSitEvent((Player) Event.getEntity(), GetUpReason.GET_UP));
}

}
16 changes: 0 additions & 16 deletions core/src/main/java/dev/geco/gsit/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.bukkit.event.entity.*;
import org.bukkit.event.player.*;

import org.spigotmc.event.entity.*;

import dev.geco.gsit.GSitMain;
import dev.geco.gsit.objects.*;

Expand Down Expand Up @@ -64,20 +62,6 @@ public void PTelE(PlayerTeleportEvent Event) {
if(!GPM.getCrawlManager().stopCrawl(player, GetUpReason.TELEPORT)) Event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void EDisE(EntityDismountEvent Event) {

Entity entity = Event.getEntity();

if(!(entity instanceof Player)) return;

Player player = (Player) entity;

if(GPM.getSitManager().isSitting(player) && (!GPM.getCManager().GET_UP_SNEAK || (!GPM.getSitManager().removeSeat(player, GetUpReason.GET_UP, true)))) Event.setCancelled(true);

if(GPM.getPoseManager().isPosing(player) && (!GPM.getCManager().GET_UP_SNEAK || !GPM.getPoseManager().removePose(player, GetUpReason.GET_UP, true))) Event.setCancelled(true);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EDamE(EntityDamageEvent Event) {

Expand Down
49 changes: 1 addition & 48 deletions core/src/main/java/dev/geco/gsit/events/PlayerSitEvents.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package dev.geco.gsit.events;

import java.util.*;

import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.*;

import org.spigotmc.event.entity.*;

import dev.geco.gsit.GSitMain;
import dev.geco.gsit.api.event.*;
import dev.geco.gsit.objects.*;

public class PlayerSitEvents implements Listener {
Expand All @@ -21,14 +16,12 @@ public class PlayerSitEvents implements Listener {

public PlayerSitEvents(GSitMain GPluginMain) { GPM = GPluginMain; }

private final List<Player> wait_eject = new ArrayList<>();

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void PTogSE(PlayerToggleSneakEvent Event) {

Player player = Event.getPlayer();

if(!GPM.getCManager().PS_SNEAK_EJECTS || !Event.isSneaking() || player.isFlying() || player.getVehicle() != null || wait_eject.contains(player) || player.getPassengers().isEmpty()) return;
if(!GPM.getCManager().PS_SNEAK_EJECTS || !Event.isSneaking() || player.isFlying() || player.getVehicle() != null || GPM.getPlayerSitManager().WAIT_EJECT.contains(player) || player.getPassengers().isEmpty()) return;

GPM.getPlayerSitManager().stopPlayerSit(player, GetUpReason.KICKED);
}
Expand All @@ -45,46 +38,6 @@ public void PTogSE(PlayerToggleSneakEvent Event) {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void EDamE(EntityDamageEvent Event) { if(Event.getCause() == EntityDamageEvent.DamageCause.FALL && Event.getEntity() instanceof LivingEntity && Event.getEntity().getVehicle() != null && Event.getEntity().getVehicle().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity")) Event.setCancelled(true); }

@EventHandler(priority = EventPriority.HIGHEST)
public void EMouE(EntityMountEvent Event) { if(Event.isCancelled() && (Event.getMount().getScoreboardTags().contains(GPM.NAME + "_SeatEntity") || Event.getMount().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity"))) Event.setCancelled(false); }

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void EDisE(EntityDismountEvent Event) {

if(!Event.getDismounted().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity") && !(Event.getDismounted() instanceof Player)) return;

if(Event.getEntity() instanceof Player) {

Player player = (Player) Event.getEntity();

PrePlayerGetUpPlayerSitEvent preEvent = new PrePlayerGetUpPlayerSitEvent(player, GetUpReason.GET_UP);

Bukkit.getPluginManager().callEvent(preEvent);

if(preEvent.isCancelled()) {

Event.setCancelled(true);
return;
}

wait_eject.add(player);

GPM.getTManager().runDelayed(() -> {
wait_eject.remove(player);
}, 2);
}

Entity bottom = GPM.getPassengerUtil().getBottomEntity(Event.getDismounted());

if(GPM.getCManager().PS_BOTTOM_RETURN && Event.getEntity().isValid() && Event.getEntity() instanceof Player && GPM.getPackageUtil() != null) Bukkit.getPlayer(Event.getEntity().getUniqueId()).teleportAsync(bottom.getLocation());

if(Event.getDismounted().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity") && GPM.getPackageUtil() == null) Bukkit.getPlayer(Event.getDismounted().getUniqueId()).teleportAsync(bottom.getLocation());

GPM.getPlayerSitManager().stopPlayerSit(Event.getDismounted(), GetUpReason.GET_UP);

if(Event.getEntity() instanceof Player) Bukkit.getPluginManager().callEvent(new PlayerGetUpPlayerSitEvent((Player) Event.getEntity(), GetUpReason.GET_UP));
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void PIntAEE(PlayerInteractAtEntityEvent Event) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package dev.geco.gsit.events.deprecated;

import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.*;

import org.spigotmc.event.entity.*;

import dev.geco.gsit.GSitMain;
import dev.geco.gsit.api.event.*;
import dev.geco.gsit.objects.*;

public class EntityEvents implements Listener {

private final GSitMain GPM;

public EntityEvents(GSitMain GPluginMain) { GPM = GPluginMain; }

@EventHandler(priority = EventPriority.HIGHEST)
public void EMouE(EntityMountEvent Event) { if(Event.isCancelled() && (Event.getMount().getScoreboardTags().contains(GPM.NAME + "_SeatEntity") || Event.getMount().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity"))) Event.setCancelled(false); }

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void EDisE(EntityDismountEvent Event) {

if(Event.getEntity() instanceof Player) {

Player player = (Player) Event.getEntity();

if (GPM.getSitManager().isSitting(player) && (!GPM.getCManager().GET_UP_SNEAK || (!GPM.getSitManager().removeSeat(player, GetUpReason.GET_UP, true)))) {

Event.setCancelled(true);
return;
}

if (GPM.getPoseManager().isPosing(player) && (!GPM.getCManager().GET_UP_SNEAK || !GPM.getPoseManager().removePose(player, GetUpReason.GET_UP, true))) {

Event.setCancelled(true);
return;
}
}

if(!Event.getDismounted().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity") && !(Event.getDismounted() instanceof Player)) return;

if(Event.getEntity() instanceof Player) {

Player player = (Player) Event.getEntity();

PrePlayerGetUpPlayerSitEvent preEvent = new PrePlayerGetUpPlayerSitEvent(player, GetUpReason.GET_UP);

Bukkit.getPluginManager().callEvent(preEvent);

if(preEvent.isCancelled()) {

Event.setCancelled(true);
return;
}

GPM.getPlayerSitManager().WAIT_EJECT.add(player);

GPM.getTManager().runDelayed(() -> {
GPM.getPlayerSitManager().WAIT_EJECT.remove(player);
}, 2);
}

Entity bottom = GPM.getPassengerUtil().getBottomEntity(Event.getDismounted());

if(GPM.getCManager().PS_BOTTOM_RETURN && Event.getEntity().isValid() && Event.getEntity() instanceof Player && GPM.getPackageUtil() != null) GPM.getEntityUtil().posEntity(Event.getEntity(), bottom.getLocation());

if(Event.getDismounted().getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity") && GPM.getPackageUtil() == null) GPM.getEntityUtil().posEntity(Event.getDismounted(), bottom.getLocation());

GPM.getPlayerSitManager().stopPlayerSit(Event.getDismounted(), GetUpReason.GET_UP);

if(Event.getEntity() instanceof Player) Bukkit.getPluginManager().callEvent(new PlayerGetUpPlayerSitEvent((Player) Event.getEntity(), GetUpReason.GET_UP));
}

}
3 changes: 3 additions & 0 deletions core/src/main/java/dev/geco/gsit/manager/CManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class CManager {

public boolean CHECK_FOR_UPDATE;

public boolean DEBUG;

public boolean GET_UP_DAMAGE;

public boolean GET_UP_SNEAK;
Expand Down Expand Up @@ -136,6 +138,7 @@ public void reload() {
L_CLIENT_LANG = GPM.getConfig().getBoolean("Lang.client-lang", true);

CHECK_FOR_UPDATE = GPM.getConfig().getBoolean("Options.check-for-update", true);
DEBUG = GPM.getConfig().getBoolean("Options.debug", false);
GET_UP_DAMAGE = GPM.getConfig().getBoolean("Options.get-up-damage", false);
GET_UP_SNEAK = GPM.getConfig().getBoolean("Options.get-up-sneak", true);
GET_UP_RETURN = GPM.getConfig().getBoolean("Options.get-up-return", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class PlayerSitManager {

private final HashMap<UUID, Long> spawnTimes = new HashMap<>();

public final List<Player> WAIT_EJECT = new ArrayList<>();

public PlayerSitManager(GSitMain GPluginMain) {
GPM = GPluginMain;
seat_entity_count = GPM.getSVManager().isNewerOrVersion(20, 2) ? 1 : 2;
Expand All @@ -36,7 +38,11 @@ public void resetFeatureUsedCount() {
public int getSeatEntityCount() { return seat_entity_count; }

public void clearSeats() {
for(World world : Bukkit.getWorlds()) for(Entity entity : world.getEntities()) if(entity.getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity")) entity.remove();
for(World world : Bukkit.getWorlds()) for(Entity entity : world.getEntities()) {
try {
if(entity.getScoreboardTags().contains(GPM.NAME + "_PlayerSeatEntity")) entity.remove();
} catch (Throwable ignored) { }
}
spawnTimes.clear();
}

Expand Down
Loading

0 comments on commit f64f35f

Please sign in to comment.