use of gg.projecteden.nexus.models.radio.RadioUserService in project Nexus by ProjectEdenGG.
the class RadioHeads method onClickRadio.
@EventHandler
public void onClickRadio(PlayerInteractEvent event) {
if (BearFair21.isNotAtBearFair(event))
return;
if (WorldGuardEditCommand.canWorldGuardEdit(event.getPlayer()))
return;
Block block = event.getClickedBlock();
if (isNullOrAir(block) || !block.getType().equals(Material.PLAYER_HEAD))
return;
Location radioHeadLoc = new Location(BearFair21.getWorld(), 16, 119, -19);
ItemStack item = ItemUtils.getItem(block);
// item.equals(Nexus.getHeadAPI().getItemHead("17150"))
if (item.equals(ItemUtils.getItem(radioHeadLoc.getBlock()))) {
event.setCancelled(true);
RadioUserService userService = new RadioUserService();
RadioUser radioUser = userService.get(event.getPlayer());
Radio radio = radioUser.getServerRadio();
if (radioUser.getVolume() == 100) {
radioUser.setVolume((byte) 25);
userService.save(radioUser);
}
if (radio == null || !radio.getId().equalsIgnoreCase("bearfair"))
PlayerUtils.runCommand(event.getPlayer(), "radio join bearfair");
else if (radio.getId().equalsIgnoreCase("bearfair"))
PlayerUtils.runCommand(event.getPlayer(), "radio leave");
}
}
use of gg.projecteden.nexus.models.radio.RadioUserService in project Nexus by ProjectEdenGG.
the class RadioFeature method onStop.
@Override
public void onStop() {
RadioConfigService configService = new RadioConfigService();
RadioConfig radioConfig = configService.get0();
RadioUserService userService = new RadioUserService();
RadioUser user;
for (Radio radio : radioConfig.getRadios()) {
if (radio.getSongPlayer() != null) {
SongPlayer songPlayer = radio.getSongPlayer();
for (UUID uuid : songPlayer.getPlayerUUIDs()) {
user = userService.get(uuid);
user.setServerRadioId(radio.getId());
userService.save(user);
}
removeSongPlayer(radio.getSongPlayer());
}
}
configService.save(radioConfig);
}
use of gg.projecteden.nexus.models.radio.RadioUserService in project Nexus by ProjectEdenGG.
the class Listeners method onPlayerJoin.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
RadioUserService userService = new RadioUserService();
RadioUser user = userService.get(event.getPlayer());
Radio radio = user.getLastServerRadio();
if (radio != null)
addPlayer(user.getOnlinePlayer(), radio);
user.getLeftRadiusRadios().clear();
}
use of gg.projecteden.nexus.models.radio.RadioUserService in project Nexus by ProjectEdenGG.
the class RadioFeature method onStart.
@Override
public void onStart() {
allSongs = new ArrayList<>();
new Listeners();
Tasks.async(() -> {
File[] songs = songsDirectory.listFiles();
if (songs != null) {
for (File file : songs) allSongs.add(new RadioSong(file.getName(), file));
}
setupRadios();
// Rejoin radios
for (Player player : OnlinePlayers.getAll()) {
RadioUser user = userService.get(player);
if (user.getLastServerRadio() != null)
RadioUtils.addPlayer(player, user.getLastServerRadio());
}
// Radio Particles Task
Tasks.repeat(0, TickTime.TICK.x(5), () -> {
for (Radio radio : getRadios()) {
if (!radio.getType().equals(RadioType.RADIUS))
continue;
if (!radio.isEnabled())
continue;
if (!radio.isParticles())
continue;
if (radio.getLocation() == null)
continue;
new ParticleBuilder(Particle.NOTE).count(RandomUtils.randomInt(1, 3)).offset(0.25, 0.25, 0.25).location(radio.getLocation().add(0, RandomUtils.randomDouble(0.45, 0.75), 0)).spawn();
}
});
// Radius Radio User Task
RadioUserService service = new RadioUserService();
Tasks.repeat(0, TickTime.SECOND.x(2), () -> {
for (Radio radio : getRadios()) {
if (!(radio.getSongPlayer() instanceof PositionSongPlayer))
continue;
for (Player player : OnlinePlayers.getAll()) {
RadioUser user = service.get(player);
if (user.isMute())
continue;
if (user.getLeftRadiusRadios().contains(radio.getId()))
continue;
boolean isInRange = isInRangeOfRadiusRadio(player, radio);
boolean isListening = isListening(player, radio);
if (isInRange && !isListening) {
if (user.getServerRadio() != null)
removePlayer(player, user.getServerRadio());
addPlayer(player, radio);
} else if (!isInRange && isListening) {
removePlayer(player, radio);
if (user.getLastServerRadio() != null)
addPlayer(player, user.getLastServerRadio());
}
}
}
});
});
}
Aggregations