Skip to content

Commit

Permalink
Works towards closing #1
Browse files Browse the repository at this point in the history
Adds version check to original Mak code.
Still need to add command to toggle and configuration option.
  • Loading branch information
JustBru00 committed Mar 29, 2024
1 parent 1535be1 commit 33b65e3
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 10 deletions.
46 changes: 44 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.makkuusen.timing.system</groupId>
<artifactId>TimingSystem</artifactId>
<version>2.1.1</version>
<version>2.2-SNAPSHOT</version>


<properties>
Expand All @@ -25,14 +25,48 @@
</resources>

<plugins>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</configuration>
</plugin>

<plugin>
Expand Down Expand Up @@ -94,6 +128,14 @@
<version>3.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.decentsoftware-eu</groupId>
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/me/makkuusen/timing/system/ApiUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sk89q.worldedit.regions.Region;
import me.makkuusen.timing.system.api.TimingSystemAPI;
import me.makkuusen.timing.system.api.events.BoatSpawnEvent;
import me.makkuusen.timing.system.boat.v1_20_R1.BoatSpawner;
import me.makkuusen.timing.system.boatutils.BoatUtilsManager;
import me.makkuusen.timing.system.boatutils.BoatUtilsMode;
import me.makkuusen.timing.system.database.TSDatabase;
Expand Down Expand Up @@ -409,17 +410,35 @@ public static Boat spawnBoat(Location location, Boat.Type type, boolean isChestB
if (!location.isWorldLoaded()) {
return null;
}

Boat boat;

if (isChestBoat) {
boat = (Boat) location.getWorld().spawnEntity(location, EntityType.CHEST_BOAT);
if (isServerVersion1_20_1()) { // TODO add option to turn off boat lag prevention
boat = BoatSpawner.spawnChestBoat(location);
} else {
boat = (Boat) location.getWorld().spawnEntity(location, EntityType.CHEST_BOAT);

}
} else {
boat = (Boat) location.getWorld().spawnEntity(location, EntityType.BOAT);
}
boat.getPersistentDataContainer().set(Objects.requireNonNull(NamespacedKey.fromString("spawned", TimingSystem.getPlugin())), PersistentDataType.INTEGER, 1);
Bukkit.getScheduler().runTaskLater(TimingSystem.getPlugin(), () -> boat.setBoatType(type), 2);
if (isServerVersion1_20_1()) { // TODO add option to turn off boat lag prevention
boat = BoatSpawner.spawnBoat(location);
} else {
boat = (Boat) location.getWorld().spawnEntity(location, EntityType.BOAT);
}
}

Bukkit.getScheduler().runTaskLater(TimingSystem.getPlugin(), ()-> {
boat.setBoatType(type);
boat.getPersistentDataContainer().set(Objects.requireNonNull(NamespacedKey.fromString("spawned", TimingSystem.getPlugin())), PersistentDataType.INTEGER, 1);
}, 3);

return boat;
}

private static boolean isServerVersion1_20_1() {
return Bukkit.getVersion().contains("1.20.1");
}

public static Optional<Region> getSelection(Player player) {
BukkitPlayer bPlayer = BukkitAdapter.adapt(player);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/me/makkuusen/timing/system/TSListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
Expand Down Expand Up @@ -167,7 +168,7 @@ public void onVehicleEnter(VehicleEnterEvent e) {

@EventHandler
public void onVehicleExit(VehicleExitEvent event) {
if (event.getVehicle() instanceof Boat boat && boat.getPersistentDataContainer().has(Objects.requireNonNull(NamespacedKey.fromString("spawned", plugin)))) {
if (event.getVehicle() instanceof Boat boat && (boat.getPersistentDataContainer().has(Objects.requireNonNull(NamespacedKey.fromString("spawned", plugin))) || boat.getEntitySpawnReason().equals(CreatureSpawnEvent.SpawnReason.COMMAND))) {
if (event.getExited() instanceof Player player) {
var maybeDriver = EventDatabase.getDriverFromRunningHeat(player.getUniqueId());
if (maybeDriver.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.makkuusen.timing.system.boat.v1_20_R1;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftBoat;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftChestBoat;
import org.bukkit.event.entity.CreatureSpawnEvent;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.vehicle.Boat;

public class BoatSpawner {

public static org.bukkit.entity.Boat spawnBoat(Location location) {
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
CollisionlessBoat boat = new CollisionlessBoat(level, location.getX(), location.getY(), location.getZ());
float yaw = Location.normalizeYaw(location.getYaw());
boat.setYRot(yaw);
boat.yRotO = yaw;
boat.setYHeadRot(yaw);
level.addFreshEntity(boat, CreatureSpawnEvent.SpawnReason.COMMAND);
boat.setVariant(Boat.Type.OAK);
var craftBoat = new CraftBoat((CraftServer) Bukkit.getServer(), boat);
return craftBoat;
}

public static org.bukkit.entity.ChestBoat spawnChestBoat(Location location) {
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
CollisionlessChestBoat boat = new CollisionlessChestBoat(level, location.getX(), location.getY(), location.getZ());
float yaw = Location.normalizeYaw(location.getYaw());
boat.setYRot(yaw);
boat.yRotO = yaw;
boat.setYHeadRot(yaw);
level.addFreshEntity(boat, CreatureSpawnEvent.SpawnReason.COMMAND);
boat.setVariant(Boat.Type.OAK);
var craftBoat = new CraftChestBoat((CraftServer) Bukkit.getServer(), boat);
return craftBoat;
}

public boolean isCollisionless(org.bukkit.entity.Boat boat) {
return ((CraftBoat) boat).getHandle() instanceof CollisionlessBoat;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.makkuusen.timing.system.boat.v1_20_R1;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.Level;

public class CollisionlessBoat extends Boat {

public CollisionlessBoat(Level world, double d0, double d1, double d2) {
super(world, d0, d1, d2);
}

@Override
public boolean canCollideWith(Entity entity) {
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.makkuusen.timing.system.boat.v1_20_R1;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.vehicle.ChestBoat;
import net.minecraft.world.level.Level;

public class CollisionlessChestBoat extends ChestBoat {

public CollisionlessChestBoat(Level world, double d0, double d1, double d2) {
super(world, d0, d1, d2);
}

public CollisionlessChestBoat(EntityType<? extends ChestBoat> entitytypes, Level world) {
super(entitytypes, world);
}

@Override
public boolean canCollideWith(Entity entity) {
return false;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: TimingSystem
main: me.makkuusen.timing.system.TimingSystem
version: '2.1.1'
authors: [Makkuusen, Pigalala, GitHub Repository Contributors]
version: '2.2-SNAPSHOT'
authors: [Makkuusen, Pigalala, JustBru00, GitHub Repository Contributors]
depend: [WorldEdit]
softdepend: [HolographicDisplays, DecentHolograms, Multiverse-Core, GSit, PlaceholderAPI]
api-version: '1.20'
Expand Down

0 comments on commit 33b65e3

Please sign in to comment.