Skip to content

Commit

Permalink
Changed BroadcastPlayer to MPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
TTTheKing committed Oct 14, 2013
1 parent 5a79d3d commit 6600766
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/com/dre/managerxl/Broadcast.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.bukkit.entity.Player;

import com.dre.managerxl.broadcaster.BroadcastMsg;
import com.dre.managerxl.broadcaster.player.BroadcastPlayer;
import com.dre.managerxl.broadcaster.player.BroadcastPlayerMsg;

public class Broadcast {
Expand Down Expand Up @@ -116,7 +115,7 @@ private void deleteOldMessages() {
}

private void deleteOldPlayerData() {
for(BroadcastPlayer bPlayer : BroadcastPlayer.list){
for(MPlayer bPlayer : MPlayer.get()){
for (Iterator<Map.Entry<Integer,BroadcastPlayerMsg>> it = bPlayer.playerMsgs.entrySet().iterator(); it.hasNext();) {
Map.Entry<Integer,BroadcastPlayerMsg> entry = it.next();
if (entry.getValue().getBroadcastMsg() == null) {
Expand All @@ -130,7 +129,7 @@ private void deleteOldPlayerData() {

public static void broadcastMsg(Player player, BroadcastMsg msg){

BroadcastPlayer bPlayer = BroadcastPlayer.getBroadcastPlayer(player.getName());
MPlayer bPlayer = MPlayer.getOrCreate(player.getName());
BroadcastPlayerMsg bMsg = bPlayer.getBMsg(msg.getId());

bMsg.setSendCount(bMsg.getSendCount()+1);
Expand All @@ -153,7 +152,7 @@ public static void broadcastMsg(Player player, BroadcastMsg msg){
}

public static long getNextSendTime(Player player, BroadcastMsg msg){
BroadcastPlayer bPlayer = BroadcastPlayer.getBroadcastPlayer(player.getName());
MPlayer bPlayer = MPlayer.getOrCreate(player.getName());
BroadcastPlayerMsg bMsg = bPlayer.getBMsg(msg.getId());
long lastSend = bMsg.getLastSend();
int playerLevel = bMsg.getPlayerLevel();
Expand Down Expand Up @@ -207,7 +206,7 @@ public void saveMessages(){
public void saveData(){
FileConfiguration file = new YamlConfiguration();

for(BroadcastPlayer bPlayer: BroadcastPlayer.list){
for(MPlayer bPlayer: MPlayer.get()){
for(Integer id: bPlayer.playerMsgs.keySet()){
BroadcastPlayerMsg bpMsg = bPlayer.playerMsgs.get(id);
file.set(bPlayer.getPlayer()+"."+id+".playerLevel", bpMsg.getPlayerLevel());
Expand Down Expand Up @@ -240,13 +239,13 @@ public void loadMessages(){

public void loadData(){
FileConfiguration file = YamlConfiguration.loadConfiguration(broadcastDataFile);
BroadcastPlayer bPlayer;
MPlayer bPlayer;
int playerLevel;
int sendCount;
long lastSend;

for(String name: file.getKeys(false)){
bPlayer = BroadcastPlayer.getBroadcastPlayer(name);
bPlayer = MPlayer.getOrCreate(name);
ConfigurationSection section = file.getConfigurationSection(name);
for(String id: section.getKeys(false)){
playerLevel = file.getInt(name+"."+id+".playerLevel");
Expand Down
17 changes: 17 additions & 0 deletions src/com/dre/managerxl/MPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -12,6 +13,8 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import com.dre.managerxl.broadcaster.player.BroadcastPlayerMsg;

public class MPlayer {
private static Set<MPlayer> mPlayers = new HashSet<MPlayer>();

Expand All @@ -25,6 +28,20 @@ public class MPlayer {
private Location home;
private int gameMode = 0;
private long lastTeleport;

/* BroadcasterPlayer */
public HashMap<Integer,BroadcastPlayerMsg> playerMsgs = new HashMap<Integer,BroadcastPlayerMsg>();

public BroadcastPlayerMsg getBMsg(int id) {
BroadcastPlayerMsg msg = playerMsgs.get(id);

if(msg == null){
msg = new BroadcastPlayerMsg(id, this);
}

return msg;
}


public MPlayer(String name) {
mPlayers.add(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dre.managerxl.broadcaster.player;
/*package com.dre.managerxl.broadcaster.player;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -44,3 +44,4 @@ public BroadcastPlayerMsg getBMsg(int id) {
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.dre.managerxl.broadcaster.player;

import com.dre.managerxl.MPlayer;
import com.dre.managerxl.broadcaster.BroadcastMsg;

public class BroadcastPlayerMsg {

BroadcastMsg msg;

BroadcastPlayer bPlayer;
MPlayer bPlayer;

private int playerLevel;

private int sendCount;

private long lastSend;

public BroadcastPlayerMsg(int id,BroadcastPlayer bPlayer, int playerLevel, int sendCount, long lastSend){
public BroadcastPlayerMsg(int id,MPlayer bPlayer, int playerLevel, int sendCount, long lastSend){
this.msg = BroadcastMsg.messages.get(id);
this.playerLevel = playerLevel;
this.lastSend = lastSend;
Expand All @@ -23,7 +24,7 @@ public BroadcastPlayerMsg(int id,BroadcastPlayer bPlayer, int playerLevel, int s
bPlayer.playerMsgs.put(id, this);
}

public BroadcastPlayerMsg(int id,BroadcastPlayer bPlayer){
public BroadcastPlayerMsg(int id,MPlayer bPlayer){
this(id, bPlayer, 1, 0, 0L);
}

Expand Down

0 comments on commit 6600766

Please sign in to comment.