Skip to content

Commit

Permalink
Added IFPlayer.isNull method for checking if player instance is null
Browse files Browse the repository at this point in the history
Fixed a bug causing a null pointer exception when instantiating
  • Loading branch information
Fernthedev committed Dec 12, 2019
1 parent 748edc2 commit 200d687
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 99 deletions.
13 changes: 0 additions & 13 deletions .idea/modules/com.github.fernthedev.FernAPI.iml

This file was deleted.

70 changes: 36 additions & 34 deletions .idea/modules/com.github.fernthedev.FernAPI.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions .idea/modules/com.github.fernthedev.FernAPI.test.iml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.github.fernthedev.fernapi.server.bungee.player;

import com.github.fernthedev.fernapi.universal.data.chat.BaseMessage;
import com.github.fernthedev.fernapi.universal.api.IFPlayer;
import lombok.Getter;
import com.github.fernthedev.fernapi.universal.data.chat.BaseMessage;
import lombok.NonNull;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.*;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.net.InetSocketAddress;
import java.util.Collection;

public class BungeeFPlayer extends IFPlayer {
@Getter
private ProxiedPlayer player;
public class BungeeFPlayer extends IFPlayer<ProxiedPlayer> {

public BungeeFPlayer(ProxiedPlayer player) {
super(player.getName(),player.getUniqueId());
this.player = player;
super(player == null ? null : player.getName(),player == null ? null : player.getUniqueId(), player);
}

/**
Expand Down Expand Up @@ -53,8 +50,12 @@ public Collection<String> getPermissions() {
}

@Override
public void sendMessage(BaseMessage baseMessage) {
TextComponent fullMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&',baseMessage.getParentText()));
public void sendMessage(@NonNull BaseMessage baseMessage) {
String text = baseMessage.getParentText();

if (text == null) text = "";

TextComponent fullMessage = new TextComponent(ChatColor.translateAlternateColorCodes('&', baseMessage.getParentText()));

if (baseMessage.getExtra() != null) {
for(BaseMessage be : baseMessage.getExtra()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.github.fernthedev.fernapi.server.spigot.pluginhandlers.VaultHandler;
import com.github.fernthedev.fernapi.universal.Universal;
import com.github.fernthedev.fernapi.universal.data.chat.BaseMessage;
import com.github.fernthedev.fernapi.universal.api.IFPlayer;
import lombok.Getter;
import com.github.fernthedev.fernapi.universal.data.chat.BaseMessage;
import net.md_5.bungee.api.chat.*;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand All @@ -18,13 +17,10 @@
import java.util.HashMap;
import java.util.UUID;

public class SpigotFPlayer extends IFPlayer {
@Getter
private Player player;
public class SpigotFPlayer extends IFPlayer<Player> {

public SpigotFPlayer(Player player) {
super(player.getName(),player.getUniqueId());
this.player = player;
super(player == null ? null : player.getName(),player == null ? null : player.getUniqueId(), player);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import java.net.URL;
import java.util.Collection;

public class SpongeFPlayer extends IFPlayer {
private Player player;
public class SpongeFPlayer extends IFPlayer<Player> {

public SpongeFPlayer(Player player) {
this.player = player;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package com.github.fernthedev.fernapi.server.velocity.player;

import com.github.fernthedev.fernapi.universal.api.IFPlayer;
import com.github.fernthedev.fernapi.universal.data.chat.BaseMessage;
import com.github.fernthedev.fernapi.universal.data.chat.ChatColor;
import com.github.fernthedev.fernapi.universal.api.IFPlayer;
import com.velocitypowered.api.proxy.Player;
import lombok.Getter;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;

import java.net.InetSocketAddress;
import java.util.Collection;

public class VelocityFPlayer extends IFPlayer{
@Getter
private Player player;
public class VelocityFPlayer extends IFPlayer<Player> {

public VelocityFPlayer(Player player) {
super(player.getUsername(), player.getUniqueId());
this.player = player;
super(player == null ? null : player.getUsername(),player == null ? null : player.getUniqueId(), player);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

@AllArgsConstructor
@Getter
public abstract class IFPlayer implements CommandSender {
public abstract class IFPlayer<T> implements CommandSender {
@Getter
String name = null;
protected String name = null;

@Getter
UUID uuid = null;
protected UUID uuid = null;

@Getter
protected T player;

public IFPlayer() {}

Expand All @@ -25,4 +28,16 @@ public IFPlayer() {}
public abstract long getPing();

public abstract String getCurrentServerName();

/**
* Returns true if all data is null
* If player is null but name and uuid aren't, this returns false
* @return
*/
public boolean isNull() {
boolean isPlayer = player == null; // Player must be null
boolean isDataNull = name == null || uuid == null; // Name and UUID both must be null

return isPlayer && isDataNull;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

@Getter
@NoArgsConstructor
public class JSONPlayer extends IFPlayer {
public class JSONPlayer extends IFPlayer<Object> {

public JSONPlayer(String name, UUID uuid) {
super(name,uuid);
super(name, uuid, null);
}

/**
Expand Down

0 comments on commit 200d687

Please sign in to comment.