Skip to content

Commit

Permalink
Add a gui setting to disable pickup per region
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Jan 2, 2024
1 parent fa59d3d commit e1add98
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public RegionEditGui(IRegion region) {
super(ChatColor.BLUE + "Updating Region", 3 * 9);

// 2, 4, 6 context / setting slots
setItem(2, new Item(Material.ITEM_FRAME)
setItem(1, new Item(Material.ITEM_FRAME)
.setName(ChatColor.YELLOW + "Playing: " + ChatColor.AQUA + region.getMedia().getSource()));

setItem(4, getVoicechatToggleItem(region));

setItem(3, getVoicechatToggleItem(region));

setItem(5, getSyncItem(region));

// something fun for slot 6? think of something mats
setItem(6, getPlayOnceItem(region)); // you thought of something, nice
setItem(7, getPlayOnceItem(region)); // you thought of something, nice

// second row, volume fuckery
setItem(9, getVolumeItem(region, 5));
Expand All @@ -53,6 +55,42 @@ public RegionEditGui(IRegion region) {
setItem(26, getFadeItem(region, 15000));
}

public Item getSyncItem(IRegion region) {
return new Item(Material.LEVER)
.setName(ChatColor.YELLOW + "Syncronization " + (region.getProperties().getDoSync() ?
ChatColor.GREEN + "ENABLED"
:
ChatColor.RED + "DISABLED"))
.setLore(new String[]{
ChatColor.GREEN + "Enabled" + ChatColor.GRAY + ": The music will synchronize between sessions/players",
ChatColor.RED + "DISABLED" + ChatColor.GRAY + ": The music will always play from the beginning"
})
.onClick((player, item) -> {
region.getProperties().setDoSync(!region.getProperties().getDoSync());

if (region.getProperties().getDoSync()) {
player.sendMessage(MagicValue.COMMAND_PREFIX.get(String.class) + ChatColor.GREEN + "Music will now synchronize between players. Leave this region and come back to see the difference.");
} else {
player.sendMessage(MagicValue.COMMAND_PREFIX.get(String.class) + ChatColor.RED + "Music will now always play from the beginning when someone enters or connects.");
}


// reset the media cache for this region
Media oldMedia = region.getMedia();
OpenAudioMcSpigot.getInstance().getRegionModule().getWorld(player.getWorld().getName()).unregisterRegionMedia(region.getMedia().getSource());
Media newMedia = region.getMedia();

// send destroy packets to all players in the region
for (SpigotConnection spigotConnection : OpenAudioMcSpigot.getInstance().getRegionModule().findPlayersInRegion(region.getProperties().getRegionName())) {
spigotConnection.getClientConnection().sendPacket(new PacketClientDestroyMedia(oldMedia.getMediaId()));
// start new media
spigotConnection.getClientConnection().sendMedia(newMedia);
}

new RegionEditGui(region).openFor(player);
});
}

private Item getPlayOnceItem(IRegion region) {
return new Item(Material.BONE_MEAL)
.setName(ChatColor.YELLOW + "Looping " + (region.getProperties().getLoop() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface IRegion {
*/
String getId();


/**
* Set the volume of the region
* @param volume Volume (1 to 100)
Expand All @@ -48,6 +47,12 @@ public interface IRegion {
*/
int getFadeTime();

/**
* Weather the attached media should have its keepup flag enabled
* @return if syncing is enabled
*/
boolean syncEnabled();

public class EmptyRegion implements IRegion {

@Override
Expand Down Expand Up @@ -84,5 +89,10 @@ public void setFadeTime(int fadeTime) {
public int getFadeTime() {
return 0;
}

@Override
public boolean syncEnabled() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ public int getFadeTime() {
return regionProperties.getFadeTimeMs();
}

@Override
public boolean syncEnabled() {
return regionProperties.getDoSync();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class RegionProperties extends DataStore {
private Integer volume;
@Column private Integer fadeTimeMs;
@Column private Boolean allowsVoiceChat = true;
// setting this to true will pull the config value instead
@Column private Boolean doSync = true;
@Column private String regionName;
@Column(storeAsBlob = true) private String[] worlds;

Expand All @@ -41,7 +43,9 @@ public RegionProperties(String source, int volume, int fadeTimeMs, boolean allow

public Media getMediaForWorld(WorldRegionManager worldRegionManager) {
if (loop == null) loop = true;
return worldRegionManager.getRegionMedia(source, volume, fadeTimeMs, loop);
Media media = worldRegionManager.getRegionMedia(source, volume, fadeTimeMs, loop);
media.setDoPickup(this.doSync);
return media;
}

public boolean hasWorlds() {
Expand Down

0 comments on commit e1add98

Please sign in to comment.