Skip to content

Commit

Permalink
WIP: Fixing Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafe committed Dec 27, 2014
1 parent 88fa405 commit 20a1082
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ManagerXL
version: 0.3
version: 0.4.1
main: com.dre.managerxl.P
authors: [Frank Baumann, Tobias Schmitz, Joscha Schmitz]
softdepend: [Vault]
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.dre</groupId>
<artifactId>managerxl</artifactId>
<version>0.1</version>
<version>0.4.1</version>
<name>ManagerXL</name>

<repositories>
Expand Down
53 changes: 29 additions & 24 deletions src/com/dre/managerxl/MPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class MPlayer {
private static Set<MPlayer> mPlayers = new HashSet<MPlayer>();

private UUID uuid;
private boolean isOnline;
private boolean isBanned;
private boolean isMuted;
private boolean isVisible = true;
Expand All @@ -53,10 +52,6 @@ public MPlayer(UUID uuid) {
mPlayers.add(this);

this.uuid = uuid;

if (Bukkit.getPlayer(uuid) != null) {
this.setOnline(true);
}
}

/* Statics */
Expand Down Expand Up @@ -85,13 +80,17 @@ public static MPlayer getOrCreate(UUID uuid) {
}
}

P.p.log("Player " + uuid + " not recognized, creating a new one!");

return new MPlayer(uuid);
}

/* Save and Load Functions */
public static boolean SaveAsYml(File file) {
FileConfiguration ymlFile = new YamlConfiguration();


P.p.log("Playercount " + MPlayer.get().size());

for (MPlayer player : MPlayer.get()) {
if (player==null)
continue;
Expand Down Expand Up @@ -166,10 +165,20 @@ public static boolean LoadAsYml(File file) {
}
}




for (String uuid : keys) {

if (
!ymlFile.getBoolean(uuid + ".isBanned") &&
ymlFile.getLong(uuid + ".bannedTime") == 0 &&
!ymlFile.getBoolean(uuid + ".isMuted") &&
ymlFile.getString(uuid + ".GameMode").equals("SURVIVAL") &&
!ymlFile.contains(uuid + ".home") &&
ymlFile.getBoolean(uuid + ".isVisible")
) {
P.p.log("SKIP");
continue;
}

MPlayer mPlayer = null;
String uuidString = uuidMapping.get(uuid);

Expand Down Expand Up @@ -224,26 +233,22 @@ public static boolean LoadAsYml(File file) {
}
return true;
}


public boolean isOnline() {
if (this.getPlayer() != null && this.getPlayer().isOnline()) {
return true;
}

return false;
}

/* Getters and Setters */
public UUID getUUID() {
return uuid;
}

public Player getPlayer() {
if (this.isOnline) {
return P.p.getServer().getPlayer(this.uuid);
}

return null;
}

public boolean isOnline() {
return isOnline;
}

public void setOnline(boolean online) {
isOnline = online;
return P.p.getServer().getPlayer(this.uuid);
}

public boolean isBanned() {
Expand Down Expand Up @@ -376,7 +381,7 @@ public static MPlayer getFromName(String name) {

Map <String, UUID> response = null;
try {
response = fetcher.call();
response = fetcher.call();
return getOrCreate(response.get(name));
} catch (Exception e) {
P.p.log("Exception while running UUIDFetcher");
Expand Down
1 change: 0 additions & 1 deletion src/com/dre/managerxl/broadcaster/Broadcaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private void deleteOldPlayerData() {
}

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

MPlayer mPlayer = MPlayer.getOrCreate(player.getUniqueId());
BroadcasterPlayerMsg bMsg = mPlayer.getBMsg(msg.getId());

Expand Down
2 changes: 1 addition & 1 deletion src/com/dre/managerxl/commands/player/CMDInvisible.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onExecute(String[] args, CommandSender sender) {
if (args.length < 1) {
if (sender instanceof Player) {
Player player = (Player) sender;

MPlayer mPlayer = MPlayer.getOrCreate(player.getUniqueId());

if (mPlayer.isVisible()) {
Expand Down
1 change: 1 addition & 0 deletions src/com/dre/managerxl/commands/player/CMDSetHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public CMDSetHome() {
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;

MPlayer mPlayer = MPlayer.getOrCreate(player.getUniqueId());

if (args.length < 1) {
Expand Down
35 changes: 14 additions & 21 deletions src/com/dre/managerxl/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;

Expand Down Expand Up @@ -43,7 +42,6 @@ public void onPlayerLogin(PlayerLoginEvent event) {
public void onPlayerJoin(PlayerJoinEvent event) {
MPlayer player = MPlayer.getOrCreate(event.getPlayer().getUniqueId());

player.setOnline(true);
player.setGameMode(player.getGameMode(), false);

// Set invisible Players
Expand All @@ -64,27 +62,20 @@ public void onPlayerJoin(PlayerJoinEvent event) {

}

@EventHandler()
public void onPlayerQuit(PlayerQuitEvent event) {
MPlayer player = MPlayer.getOrCreate(event.getPlayer().getUniqueId());

player.setOnline(false);
}

@EventHandler()
public void onPlayerRespawn(PlayerRespawnEvent event) {
MPlayer player = MPlayer.getOrCreate(event.getPlayer().getUniqueId());
MPlayer player = MPlayer.get(event.getPlayer().getUniqueId());

if (player.getHome() != null) {
if (player != null && player.getHome() != null) {
event.setRespawnLocation(player.getHome());
}
}

@EventHandler()
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
MPlayer mPlayer = MPlayer.getOrCreate(event.getPlayer().getUniqueId());
MPlayer player = MPlayer.get(event.getPlayer().getUniqueId());

if (mPlayer.isMuted()) {
if (player != null && player.isMuted()) {
P.p.msg(event.getPlayer(), P.p.getLanguageReader().get("Player_Muted"));
event.setCancelled(true);
}
Expand Down Expand Up @@ -124,21 +115,23 @@ public void onPlayerInteract(PlayerInteractEvent event) {

@EventHandler()
public void onPlayerTeleport(PlayerTeleportEvent event) {
MPlayer mPlayer = MPlayer.getOrCreate(event.getPlayer().getUniqueId());

mPlayer.setLastTeleport(System.currentTimeMillis());
MPlayer player = MPlayer.get(event.getPlayer().getUniqueId());

if (player != null) {
player.setLastTeleport(System.currentTimeMillis());
}
}

@EventHandler()
public void onPlayerDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
MPlayer mPlayer = MPlayer.getOrCreate(player.getUniqueId());
MPlayer mPlayer = MPlayer.get(player.getUniqueId());

if (event.getCause() == DamageCause.SUFFOCATION) {
if (mPlayer.getLastTeleport() + 5000 > System.currentTimeMillis()) {
player.teleport(MUtility.getNearestFreePosition(player.getLocation()));
}
if (mPlayer != null
&& event.getCause() == DamageCause.SUFFOCATION
&& mPlayer.getLastTeleport() + 5000 > System.currentTimeMillis()) {
player.teleport(MUtility.getNearestFreePosition(player.getLocation()));
}
}
}
Expand Down

0 comments on commit 20a1082

Please sign in to comment.