Skip to content

Commit

Permalink
add WorldGuard support
Browse files Browse the repository at this point in the history
  • Loading branch information
WegFetZ committed Dec 18, 2014
1 parent 730fba9 commit d468faa
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void run() {
if (location != null && App.audioManager.isMusicActive()) {
HashMap<Short, Double> boxesInRange = IntersectionDetection.getBoxesInRange(location);
HashMap<Short, Double> areasInRange = IntersectionDetection.getAreasInRange(location);
List<Short> wgRegionsInRange = IntersectionDetection.getWGRegionsInRange(location);
List<Short> biomesInRange = IntersectionDetection.getBiomeInRange(location);
List<Short> worldsInRange = IntersectionDetection.getWorldInRange(location);

Expand Down Expand Up @@ -64,6 +65,18 @@ public void run() {
App.audioManager.updatePlayer(GlobalConstants.TYPE_AREA, id, dist);
}

/* update wgRegion players */
for (Entry<Short, PlayerController> entry : App.audioManager.wgRegionPlayers.entrySet()) {
id = entry.getKey();

if (!wgRegionsInRange.contains(id)) {
App.audioManager.stopPlayer(GlobalConstants.TYPE_WGREGION, id, false);
}
}
for (short wgRegionId : wgRegionsInRange) {
App.audioManager.updatePlayer(GlobalConstants.TYPE_WGREGION, wgRegionId, 0);
}

/* update biome players */
for (Entry<Short, PlayerController> entry : App.audioManager.biomePlayers.entrySet()) {
id = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class AudioManager {
public ConcurrentHashMap<Short, PlayerController> boxPlayers = new ConcurrentHashMap<Short, PlayerController>();
public ConcurrentHashMap<Short, PlayerController> biomePlayers = new ConcurrentHashMap<Short, PlayerController>();
public ConcurrentHashMap<Short, PlayerController> worldPlayers = new ConcurrentHashMap<Short, PlayerController>();
public ConcurrentHashMap<Short, PlayerController> wgRegionPlayers = new ConcurrentHashMap<Short, PlayerController>();
public ConcurrentHashMap<Short, PlayerController> voicePlayers = new ConcurrentHashMap<Short, PlayerController>();
public PlayerController globalPlayer = null;

Expand Down Expand Up @@ -95,7 +96,7 @@ public void updatePlayer(byte type, short id, double dist) {
} else {
volumeManager.setPlayerVolume(controller, (byte) 100);
}
} else if (type == GlobalConstants.TYPE_WORLD || type == GlobalConstants.TYPE_BIOME) {
} else if (type == GlobalConstants.TYPE_WORLD || type == GlobalConstants.TYPE_BIOME || type == GlobalConstants.TYPE_WGREGION) {
volumeManager.setPlayerVolume(controller, (byte) 100);
}
}
Expand Down Expand Up @@ -137,7 +138,7 @@ public boolean isPlayingGlobally() {

public boolean playersOverlap() {
//ceck if there is more than one player (excluding speex players)
int players = (areaPlayers.size() + boxPlayers.size() + biomePlayers.size() + worldPlayers.size());
int players = (areaPlayers.size() + boxPlayers.size() + biomePlayers.size() + worldPlayers.size() + wgRegionPlayers.size());
return players > 1 || (players == 1 && globalPlayer != null);
}

Expand Down Expand Up @@ -270,6 +271,10 @@ public void run() {
PlayerController controller = entry.getValue();
controller.close(true);
}
for (Entry<Short, PlayerController> entry : wgRegionPlayers.entrySet()) {
PlayerController controller = entry.getValue();
controller.close(true);
}

if (globalPlayer != null) {
globalPlayer.close(true);
Expand All @@ -279,6 +284,7 @@ public void run() {
boxPlayers.clear();
biomePlayers.clear();
worldPlayers.clear();
wgRegionPlayers.clear();
globalPlayer = null;
if (App.gui != null) {
App.gui.controller.setPlayButtonText("Play Globally");
Expand All @@ -305,6 +311,8 @@ private ConcurrentHashMap<Short, PlayerController> getPlayerMap(byte type) {
return biomePlayers;
case GlobalConstants.TYPE_WORLD:
return worldPlayers;
case GlobalConstants.TYPE_WGREGION:
return wgRegionPlayers;
case GlobalConstants.TYPE_VOICE:
return voicePlayers;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;

import com.soundcenter.soundcenter.client.App;
import com.soundcenter.soundcenter.client.Client;
import com.soundcenter.soundcenter.lib.data.GlobalConstants;
Expand All @@ -28,12 +29,14 @@ public class Database implements Serializable{
public ConcurrentHashMap<Short, Station> boxes = new ConcurrentHashMap<Short, Station>();
public ConcurrentHashMap<Short, Station> biomes = new ConcurrentHashMap<Short, Station>();
public ConcurrentHashMap<Short, Station> worlds = new ConcurrentHashMap<Short, Station>();
public ConcurrentHashMap<Short, Station> wgRegions = new ConcurrentHashMap<Short, Station>();
public ConcurrentHashMap<String, Song> songs = new ConcurrentHashMap<String, Song>();

private ConcurrentHashMap<String, DefaultListModel> areaModels = new ConcurrentHashMap<String, DefaultListModel>();
private ConcurrentHashMap<String, DefaultListModel> boxModels = new ConcurrentHashMap<String, DefaultListModel>();
private ConcurrentHashMap<String, DefaultListModel> biomeModels = new ConcurrentHashMap<String, DefaultListModel>();
private ConcurrentHashMap<String, DefaultListModel> worldModels = new ConcurrentHashMap<String, DefaultListModel>();
private ConcurrentHashMap<String, DefaultListModel> wgRegionModels = new ConcurrentHashMap<String, DefaultListModel>();
private ConcurrentHashMap<String, DefaultListModel> songModels = new ConcurrentHashMap<String, DefaultListModel>();

private DefaultListModel availableBiomesModel = new DefaultListModel();
Expand All @@ -45,6 +48,7 @@ public class Database implements Serializable{
public List<Short> mutedBoxes = new ArrayList<Short>();
public List<Short> mutedBiomes = new ArrayList<Short>();
public List<Short> mutedWorlds = new ArrayList<Short>();
public List<Short> mutedWGRegions = new ArrayList<Short>();

private List<String> permissions = new ArrayList<String>();

Expand Down Expand Up @@ -83,6 +87,9 @@ public void addStation(Station station) {
case GlobalConstants.TYPE_WORLD:
item = "Worlds";
removeAvailableWorld(station.getName());
break;
case GlobalConstants.TYPE_WGREGION:
item = "WorldGuard Regions";
}
updateStationsTab(station.getOwner(), item, model);
}
Expand Down Expand Up @@ -115,10 +122,12 @@ public Station removeStation(byte type, short id, boolean updateAvailables) {
public void removeStation(Station station, boolean updateAvailables) {
ConcurrentHashMap<Short, Station> stationMap = getStationMap(station.getType());
ConcurrentHashMap<String, DefaultListModel> modelMap = getModelMap(station.getType());

if (stationMap != null && modelMap != null) {
stationMap.remove(station);


if (stationMap != null) {
stationMap.remove(station.getId());

}
if (modelMap != null) {
DefaultListModel model = null;
if (modelMap.containsKey(station.getOwner())) {
model = modelMap.get(station.getOwner());
Expand All @@ -133,6 +142,9 @@ public void removeStation(Station station, boolean updateAvailables) {
case GlobalConstants.TYPE_BOX:
item = "Boxes";
break;
case GlobalConstants.TYPE_WGREGION:
item = "WorldGuard Regions";
break;
case GlobalConstants.TYPE_BIOME:
item = "Biomes";
if (updateAvailables) {
Expand All @@ -159,6 +171,8 @@ private ConcurrentHashMap<Short, Station> getStationMap(byte type) {
return biomes;
case GlobalConstants.TYPE_WORLD:
return worlds;
case GlobalConstants.TYPE_WGREGION:
return wgRegions;
default:
return null;
}
Expand All @@ -174,6 +188,8 @@ private ConcurrentHashMap<String, DefaultListModel> getModelMap(byte type) {
return biomeModels;
case GlobalConstants.TYPE_WORLD:
return worldModels;
case GlobalConstants.TYPE_WGREGION:
return wgRegionModels;
default:
return null;
}
Expand All @@ -191,6 +207,12 @@ public DefaultListModel getBoxModel(String player) {
}


/* --------------------------- WGREGIONS -------------------------- */
public DefaultListModel getWGRegionModel(String player) {
return wgRegionModels.get(player);
}


/* --------------------------- BIOMES -------------------------- */
public DefaultListModel getBiomeModel(String player) {
return biomeModels.get(player);
Expand Down Expand Up @@ -289,6 +311,9 @@ public void removeSongFromStations(String path) {
for (Entry<Short, Station> entry : worlds.entrySet()) {
entry.getValue().removeSong(path);
}
for (Entry<Short, Station> entry : wgRegions.entrySet()) {
entry.getValue().removeSong(path);
}
}

public void addSongToUpload(File song) {
Expand Down Expand Up @@ -347,6 +372,8 @@ public List<Short> getMutedList(byte type) {
return mutedBiomes;
case GlobalConstants.TYPE_WORLD:
return mutedWorlds;
case GlobalConstants.TYPE_WGREGION:
return mutedWGRegions;
default:
return null;
}
Expand Down Expand Up @@ -424,6 +451,10 @@ public void reset() {
DefaultListModel model = entry.getValue();
model.removeAllElements();
}
for (Entry<String, DefaultListModel> entry : wgRegionModels.entrySet()) {
DefaultListModel model = entry.getValue();
model.removeAllElements();
}
for (Entry<String, DefaultListModel> entry : songModels.entrySet()) {
DefaultListModel model = entry.getValue();
model.removeAllElements();
Expand All @@ -442,6 +473,7 @@ public void reset() {
boxModels.clear();
biomeModels.clear();
worldModels.clear();
wgRegionModels.clear();
songModels.clear();
permissions.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.soundcenter.soundcenter.lib.data.Region;
import com.soundcenter.soundcenter.lib.data.Song;
import com.soundcenter.soundcenter.lib.data.Station;
import com.soundcenter.soundcenter.lib.data.WGRegion;
import com.soundcenter.soundcenter.lib.tcp.TcpOpcodes;

public class StationsTabActions {
Expand Down Expand Up @@ -56,6 +57,10 @@ public static void stationChooserSelected() {
renderer = new RegionListCellRenderer();
if (Client.database.permissionGranted("sc.set.world"))
addButtonEnabled = true;

} else if(type.equals("WorldGuard Regions")) {
model = Client.database.getWGRegionModel(player);
renderer = new RegionListCellRenderer();
}

if (model != null && renderer != null) {
Expand Down Expand Up @@ -164,10 +169,13 @@ public static void editStationDialogApplyButtonPressed(EditStationDialog dialog)

} else if (type == GlobalConstants.TYPE_WORLD) {
station = new Region(oldStation.getId(), oldStation.getOwner(), oldStation.getName(), type);

} else if (type == GlobalConstants.TYPE_WGREGION) {
station = new WGRegion(oldStation.getId(), oldStation.getOwner(), oldStation.getName(), oldStation.getMin(), oldStation.getMax(), oldStation.getPoints());
}

try {
if (type != GlobalConstants.TYPE_WORLD && type != GlobalConstants.TYPE_BIOME) {
if (type == GlobalConstants.TYPE_AREA || type == GlobalConstants.TYPE_BOX) {
int range = Integer.parseInt(dialog.rangeField.getText());
station.setRange(range);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void stateChanged(ChangeEvent e) {
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
pane.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10)));

if (type == GlobalConstants.TYPE_BIOME || type == GlobalConstants.TYPE_WORLD) {
if (type == GlobalConstants.TYPE_BIOME || type == GlobalConstants.TYPE_WORLD || type == GlobalConstants.TYPE_WGREGION) {
Box nameBox = Box.createHorizontalBox();
JLabel nameTitleLabel = new JLabel("Name: ");
nameTitleLabel.setPreferredSize(new Dimension(100, 20));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;

import com.soundcenter.soundcenter.lib.data.Region;
import com.soundcenter.soundcenter.lib.data.Station;

public class RegionListCellRenderer extends JPanel implements ListCellRenderer {

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {

Region region = (Region) value;
Station region = (Station) value;

this.removeAll();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class StationsTab extends JPanel {

public JComboBox playerComboBox = new JComboBox();
public JComboBox typeComboBox = new JComboBox(new String[]{"Areas", "Boxes", "Biomes", "Worlds"});
public JComboBox typeComboBox = new JComboBox(new String[]{"Areas", "Boxes", "Biomes", "Worlds", "WorldGuard Regions"});

public JList stationList = new JList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public static boolean processPacket(TcpPacket packet) {

App.audioManager.stopPlayer(type, id, true);
Client.database.removeStation(type, id, true);

return true;

} else if (cmd == TcpOpcodes.CL_DATA_CMD_DELETE_SONG) {
Expand Down
Loading

0 comments on commit d468faa

Please sign in to comment.