Skip to content

Commit

Permalink
Fix SpawnDim Features Events firing when not suppose to fire
Browse files Browse the repository at this point in the history
fixed #18
  • Loading branch information
ROMVoid95 committed Nov 10, 2020
1 parent 6058bf4 commit 7f8e732
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mcp=snapshot_20171003
## Mod Versioning
versionMajor=1
versionMinor=4
versionRev=0
versionRev=1

## Cureforge Upload Configs
cf_project_id=359766
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

public class SpawnDimension extends Feature {

private static boolean enableSpawnDimension, firstJoinOnly, everyDeath, useCoord;
private static int spawnDimId;
private static String spawnPos;
private static boolean enableSpawnDimension, firstJoinOnly, everyDeath, useCoord;
private static int spawnDimId;
private static String spawnPos;

@Override
public String category() {
Expand All @@ -35,15 +35,17 @@ public String comment() {
@Override
public void syncConfig(String category) {
enableSpawnDimension = set(category, "enableFeature", false);
useCoord = set(category, "useCoord", false);
useCoord = set(category, "useCoord", "If \"true\" custom spawn will use the coordinates set in \"spawnCoords\" below\n [default: false]", false);

firstJoinOnly = set(category, "firstJoinOnly",
"If \"true\" players are only sent to the spawn dimension"
+ " on their first time joining.\nIf \"false\" players are sent every join\n [default: false]", true);
everyDeath = set(category, "everyRespawn", "If \"true\" players are sent to the spawn dimension"
+ "every death respawn.\n [default: false]", false);
spawnDimId = set(category, "dimensionId",
"Set the Dimension ID of the planet/moon you want players join on\n"
+ "see file under `config\\GalacticTweaks\\ValidDimensions.txt` for valid dimension ID's\n", 0);
+ " on their first time joining.\nIf \"false\" players are sent every join\n [default: false]",
true);
everyDeath = set(category, "everyRespawn",
"If \"true\" players are sent to the spawn dimension" + "every death respawn.\n [default: false]",
false);
spawnDimId = set(category, "dimensionId", "Set the Dimension ID of the planet/moon you want players join on\n"
+ "see file under `config\\GalacticTweaks\\ValidDimensions.txt` for valid dimension ID's\n", 0);
spawnPos = set(category, "spawnCoords", "Set the spawn position for players to spawn at", "128,64,128");

}
Expand All @@ -55,39 +57,54 @@ public boolean usesEvents() {

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerLoggedInEvent event) {
if (enableSpawnDimension) {
handleLoggingEvent(event);
}
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
if (enableSpawnDimension) {
handleRespawnEvent(event);
}
}

private void handleLoggingEvent(PlayerLoggedInEvent event) {
if (event.player instanceof EntityPlayer) {
if (enableSpawnDimension) {
final EntityPlayer player = event.player;
final EntityPlayer player = event.player;
if (firstJoinOnly) {
final NBTTagCompound entityData = player.getEntityData();
final NBTTagCompound persistedData = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
entityData.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistedData);
final String key = Ref.MOD_ID + ":" + "FirstSpawn";
if (!persistedData.getBoolean(key)) {
teleport((EntityPlayerMP) event.player, spawnDimId);
teleport((EntityPlayerMP) player, spawnDimId);
persistedData.setBoolean(key, true);
}
} else if (firstJoinOnly) {
teleport((EntityPlayerMP) event.player, spawnDimId);
} else if (!firstJoinOnly) {
teleport((EntityPlayerMP) player, spawnDimId);
}
}
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
if (event.player instanceof EntityPlayer) {
if (everyDeath) {
teleport((EntityPlayerMP) event.player, spawnDimId);
private void handleRespawnEvent(PlayerRespawnEvent event) {
if (everyDeath) {
if (event.player instanceof EntityPlayer) {
final EntityPlayer player = event.player;
teleport((EntityPlayerMP) player, spawnDimId);
}
}
}

private void teleport(EntityPlayerMP player, int dimId) {
BlockPos pos;;
BlockPos pos;
;
MinecraftServer mcServer = player.getServer();
final WorldServer world = mcServer.getWorld(dimId);
String[] spawnString = spawnPos.split(",");
if(useCoord) {
pos = new BlockPos(Integer.valueOf(spawnString[0]), Integer.valueOf(spawnString[1]), Integer.valueOf(spawnString[2]));
if (useCoord) {
pos = new BlockPos(Integer.valueOf(spawnString[0]), Integer.valueOf(spawnString[1]),
Integer.valueOf(spawnString[2]));
} else {
int y = world.getChunkFromBlockCoords(world.getSpawnPoint()).getHeight(world.getSpawnPoint());
pos = new BlockPos(world.getSpawnPoint().getX(), y, world.getSpawnPoint().getZ());
Expand Down

0 comments on commit 7f8e732

Please sign in to comment.