-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f6dadc
commit b058538
Showing
47 changed files
with
1,229 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
common/src/main/java/com/aviatorrob06/disx/DisxServerAudioPlayerDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.aviatorrob06.disx; | ||
|
||
import com.aviatorrob06.disx.client_only.DisxAudioPlayer; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.UUID; | ||
|
||
public class DisxServerAudioPlayerDetails { | ||
private BlockPos blockPos; | ||
private ResourceLocation dimension; | ||
private UUID audioPlayerOwner; | ||
private boolean serverOwned; | ||
private String videoId; | ||
|
||
private DisxServerVideoTimer videoTimer; | ||
public DisxServerAudioPlayerDetails(BlockPos blockPos, ResourceLocation dimension, | ||
UUID audioPlayerOwner, boolean fromServer, String videoId, boolean timerEnabled){ | ||
this.blockPos = blockPos; | ||
this.dimension = dimension; | ||
this.serverOwned = fromServer; | ||
this.videoId = videoId; | ||
if (timerEnabled){ | ||
this.videoTimer = new DisxServerVideoTimer(videoId, this); | ||
} | ||
if (!fromServer){ | ||
this.audioPlayerOwner = audioPlayerOwner; | ||
} else { | ||
this.audioPlayerOwner = UUID.randomUUID(); | ||
} | ||
} | ||
|
||
public UUID getAudioPlayerOwner() { | ||
return audioPlayerOwner; | ||
} | ||
|
||
public BlockPos getBlockPos() { | ||
return blockPos; | ||
} | ||
|
||
public ResourceLocation getDimension() { | ||
return dimension; | ||
} | ||
|
||
public boolean isServerOwned() { | ||
return serverOwned; | ||
} | ||
|
||
public DisxServerVideoTimer getVideoTimer() { | ||
return videoTimer; | ||
} | ||
|
||
public String getVideoId() { | ||
return videoId; | ||
} | ||
|
||
public void clearDetails(){ | ||
this.blockPos = null; | ||
this.dimension = null; | ||
this.audioPlayerOwner = null; | ||
this.serverOwned = false; | ||
this.videoTimer = null; | ||
this.videoId = null; | ||
} | ||
} |
88 changes: 35 additions & 53 deletions
88
common/src/main/java/com/aviatorrob06/disx/DisxServerAudioPlayerRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,69 @@ | ||
package com.aviatorrob06.disx; | ||
|
||
import com.aviatorrob06.disx.client_only.DisxAudioPlayerDetails; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import org.apache.logging.log4j.core.jmx.Server; | ||
|
||
import javax.management.timer.Timer; | ||
import java.lang.reflect.Array; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.*; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.aviatorrob06.disx.DisxMain.debug; | ||
|
||
public class DisxServerAudioPlayerRegistry { | ||
|
||
public static List players = new ArrayList(); | ||
public static Map<BlockPos, String> registry = new HashMap<BlockPos, String>(); | ||
|
||
public static Map<BlockPos, videoTimer> timerRegistry = new HashMap<BlockPos, videoTimer>(); | ||
|
||
public static void sendPlayerRegistryEvent(BlockPos pos, String videoId, boolean fromSoundCommand, Player player) { | ||
public static ArrayList<Player> players = new ArrayList<>(); | ||
public static ArrayList<DisxServerAudioPlayerDetails> registry = new ArrayList<>(); | ||
|
||
public static void addToRegistry(BlockPos pos, String videoId, boolean serverOwned, Player player, ResourceKey<Level> dimension){ | ||
ResourceLocation dimensionLocation = dimension.location(); | ||
boolean timerEnabled = true; | ||
if (player.getServer().isSingleplayer()){ | ||
timerEnabled = false; | ||
} | ||
DisxServerAudioPlayerDetails serverAudioPlayerDetails = new DisxServerAudioPlayerDetails(pos, dimensionLocation, player.getUUID(), serverOwned, videoId, timerEnabled); | ||
registry.add(serverAudioPlayerDetails); | ||
players.forEach(plr -> { | ||
DisxServerPacketIndex.ServerPackets.playerRegistryEvent("add", (Player) plr, pos, videoId, serverOwned, 0, dimensionLocation, player.getUUID()); | ||
}); | ||
} | ||
|
||
public static void addToRegistry(BlockPos pos, String videoId, boolean fromSoundCommand, Player player){ | ||
registry.put(pos, videoId); | ||
public static void removeFromRegistry(DisxServerAudioPlayerDetails audioPlayerDetails){ | ||
BlockPos pos = audioPlayerDetails.getBlockPos(); | ||
ResourceLocation dimensionLocation = audioPlayerDetails.getDimension(); | ||
players.forEach(plr -> { | ||
if (plr.equals(player) && fromSoundCommand){ | ||
DisxServerPacketIndex.ServerPackets.playerRegistryEvent("add", (Player) plr, pos, videoId, fromSoundCommand, 0); | ||
} else { | ||
DisxServerPacketIndex.ServerPackets.playerRegistryEvent("add", (Player) plr, pos, videoId, false, 0); | ||
} | ||
DisxServerPacketIndex.ServerPackets.playerRegistryEvent("remove", (Player) plr, pos, null, false, 0, dimensionLocation, null); | ||
}); | ||
if (!player.getServer().isSingleplayer()){ | ||
videoTimer timer = new videoTimer(); | ||
timerRegistry.put(pos, timer); | ||
Runnable run = new Runnable() { | ||
@Override | ||
public void run() { | ||
timer.videoTimer(pos, videoId); | ||
} | ||
}; | ||
CompletableFuture.runAsync(run); | ||
} | ||
registry.remove(audioPlayerDetails); | ||
audioPlayerDetails.clearDetails(); | ||
} | ||
|
||
public static void removeFromRegistry(BlockPos pos, String videoId){ | ||
public static void removeFromRegistry(BlockPos pos, ResourceKey<Level> dimension){ | ||
ResourceLocation dimensionLocation = dimension.location(); | ||
players.forEach(plr -> { | ||
DisxServerPacketIndex.ServerPackets.playerRegistryEvent("remove", (Player) plr, pos, videoId, false, 0); | ||
DisxServerPacketIndex.ServerPackets.playerRegistryEvent("remove", (Player) plr, pos, "", false, 0, dimensionLocation, UUID.randomUUID()); | ||
}); | ||
registry.remove(pos); | ||
if (timerRegistry.containsKey(pos)){ | ||
timerRegistry.remove(pos); | ||
ArrayList<DisxServerAudioPlayerDetails> toRemove = new ArrayList<>(); | ||
for (DisxServerAudioPlayerDetails details : registry){ | ||
if (details.getBlockPos().equals(pos) && details.getDimension().equals(dimensionLocation)){ | ||
toRemove.add(details); | ||
} | ||
} | ||
for (DisxServerAudioPlayerDetails details : toRemove){ | ||
registry.remove(details); | ||
} | ||
} | ||
|
||
public static void onServerClose(){ | ||
registry.clear(); | ||
} | ||
|
||
public static class videoTimer{ | ||
long startTime = 0; | ||
long elapsedSeconds = 0; | ||
|
||
boolean forceStop = false; | ||
public void videoTimer(BlockPos pos, String videoId){ | ||
if (debug) System.out.println("initializing timer"); | ||
int length = DisxYoutubeLengthScraper.getYoutubeVideoLength(videoId); | ||
if (debug) System.out.println(length); | ||
startTime = System.currentTimeMillis(); | ||
while (elapsedSeconds <= (length * 1000) && forceStop == false){ | ||
int test = 0; | ||
elapsedSeconds = (System.currentTimeMillis() - startTime); | ||
} | ||
if (timerRegistry.containsValue(this)) { | ||
removeFromRegistry(pos, videoId); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
common/src/main/java/com/aviatorrob06/disx/DisxServerVideoTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.aviatorrob06.disx; | ||
|
||
import net.minecraft.core.BlockPos; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.aviatorrob06.disx.DisxMain.debug; | ||
|
||
public class DisxServerVideoTimer { | ||
long startTime = 0; | ||
long elapsedSeconds = 0; | ||
|
||
boolean forceStop = false; | ||
|
||
String videoId; | ||
DisxServerAudioPlayerDetails parent; | ||
|
||
public DisxServerVideoTimer(String videoId, DisxServerAudioPlayerDetails parent){ | ||
this.videoId = videoId; | ||
this.parent = parent; | ||
CompletableFuture.runAsync(this::commenceTimer); | ||
} | ||
|
||
public void setForceStop(){ | ||
this.forceStop = true; | ||
} | ||
public void commenceTimer(){ | ||
if (debug) System.out.println("initializing timer"); | ||
int length = DisxYoutubeLengthScraper.getYoutubeVideoLength(videoId); | ||
if (debug) System.out.println(length); | ||
startTime = System.currentTimeMillis(); | ||
while (elapsedSeconds <= (length * 1000L) && !forceStop){ | ||
int test = 0; | ||
elapsedSeconds = (System.currentTimeMillis() - startTime); | ||
} | ||
if (parent.getVideoTimer().equals(this)){ | ||
DisxServerAudioPlayerRegistry.removeFromRegistry(this.parent); | ||
} | ||
} | ||
} |
Oops, something went wrong.