Something

Status
This thread has been locked.
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Fluddershy

Feedback score
2
Posts
277
Reactions
133
Resources
0
Oh I would help but I don't know what vanishCommand(probably command instance) is, vanished(probably array list), or even what the error IS!
 

felldownstairs

Gypsy Boy | Java Developer
Supreme
Feedback score
4
Posts
783
Reactions
144
Resources
0
Oh I would help but I don't know what vanishCommand(probably command instance) is, vanished(probably array list), or even what the error IS!
vanishCommand is the instance for my VanishCommand class
vanished is an arraylist
error:
 

Hunting_Potato

Developer
Deactivated
Feedback score
11
Posts
745
Reactions
425
Resources
0
The arraylist is equal to null, make sure you initialised it properly.
 

kampai

Feedback score
8
Posts
361
Reactions
187
Resources
0
Code:
vanishCommand.vanished
Things to check
  • Make a getter
  • Is object vanishCommand initalized?
  • Are you trying to access this object before it is initalized
Getting the full class would help too
 

Lockett

Supreme
Feedback score
9
Posts
434
Reactions
158
Resources
0
ArrayList should be:
Code:
public ArrayList<Player> vanished = new ArrayList<>();
However this will also work, but not necceasary with the newer versions.:
Code:
public ArrayList<Player> vanished = new ArrayList<Player>();
Booleans must be a true or false value, you have set it to none.
Code:
boolean vanished;
        if (vanished.contains(player)) {
            vanished = true;
        } else {
            vanished = false;
        }
Note: Would get in the practice of using UUIDS instead. Also im not sure but wrong section?
 
Last edited:

kampai

Feedback score
8
Posts
361
Reactions
187
Resources
0
ArrayList should be:
Code:
public ArrayList<Player> vanished = new ArrayList<>();
However this will also work, but not necceasary with the newer versions.:
Code:
public ArrayList<Player> vanished = new ArrayList<Player>();
Booleans must be a true or false value, you have set it to none.
Code:
boolean vanished;
        if (vanished.contains(player)) {
            vanished = true;
        } else {
            vanished = false;
        }
Note: Would get in the practice of using UUIDS instead. Also im not sure but wrong section?
I just wanted to point a few things out with your post.
  • Doesn't matter if you use a UUID or Player as long as you remove the player
  • vanish.contains() this method IS a boolean so you can do boolean vanished = this.vanished.contains(player)
  • Use List<Player> vanished = new ArrayList<>();
As for the user I recommend using a set for performance.

Annd as for when using a UUID or Player doesnt matter, it does NOT affect performance which is what some people thing. You store object references in collections not an instance of the object. Reason being is because Player classes have a runtime of O(1)
 

felldownstairs

Gypsy Boy | Java Developer
Supreme
Feedback score
4
Posts
783
Reactions
144
Resources
0
I just wanted to point a few things out with your post.
  • Doesn't matter if you use a UUID or Player as long as you remove the player
  • vanish.contains() this method IS a boolean so you can do boolean vanished = this.vanished.contains(player)
  • Use List<Player> vanished = new ArrayList<>();
As for the user I recommend using a set for performance.

Annd as for when using a UUID or Player doesnt matter, it does NOT affect performance which is what some people thing. You store object references in collections not an instance of the object. Reason being is because Player classes have a runtime of O(1)
scoreboard class:
package me.p3i.vanishscoreboard;

import java.util.ArrayList;
import java.util.logging.Level;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.scoreboard.DisplaySlot;
import commands.VanishCommand;
import net.md_5.bungee.api.ChatColor;
import subside.plugins.koth.events.KothInitializeEvent;

public class SPlayer {

private static final MainClass plugin = MainClass.getPlugin(MainClass.class);
private static SPlayer instance;
private String player;
public ScoreB sb;
private final VanishCommand vanishCommand = VanishCommand.getInstance();

public SPlayer(String player) {
instance = this;
this.player = player;
sb = new ScoreB();
sb.setSlot(DisplaySlot.SIDEBAR);
sb.setName(ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("scoreboard-title")));
sb.addLine(15, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("scoreboard-lines")));
sb.addLine(14, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("online")) + Bukkit.getOnlinePlayers().length);
sb.addLine(13, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("kills")) + "0");
sb.addLine(12, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("deaths"))+ "0");
sb.addLine(11, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("gamemode")));
sb.addLine(9, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("scoreboard-lines")));
}

public synchronized void updateScoreboard() {
if(!(sb.hasBoard(getPlayer()))) {
sb.setForPlayer(getPlayer());
sb.removeLine(10);
}
sb.updateLine(13, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("kills") + getPlayer().getStatistic(Statistic.PLAYER_KILLS)));
sb.updateLine(12, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("deaths") + getPlayer().getStatistic(Statistic.DEATHS)));
if(getPlayer().hasPermission("empirehcf.staffboard")) {
GameMode gameMode = getPlayer().getGameMode();
if(gameMode == GameMode.SURVIVAL) {
sb.updateLine(11, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("gamemode") + ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("scoreboard-survival"))));
}
else if (gameMode == GameMode.CREATIVE) {
sb.updateLine(11, ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("gamemode") + ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("scoreboard-creative"))));
}
}
}

public static SPlayer getInstance() {
return instance;
}

public Player getPlayer() {
return Bukkit.getPlayer(this.player);
}
@EventHandler
public void onKothInitialize(KothInitializeEvent event){
sb.updateLine(10, ChatColor.BLUE + event.getRunningKoth().getKoth().getName() + ChatColor.WHITE + event.getRunningKoth().getTimeObject().getTimeLeftFormatted());
}
}

vanishcommand class:
package commands;

import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.RegisteredServiceProvider;

import me.p3i.vanishscoreboard.MainClass;
import me.p3i.vanishscoreboard.SPlayer;

public class VanishCommand implements CommandExecutor {

private static VanishCommand instance;

public void onEnable() {
instance = this;
}

public static VanishCommand getInstance() {
return instance;
}


public ArrayList<Player> vanished = new ArrayList<Player>();

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
if(cmd.getName().equalsIgnoreCase("vanish") || cmd.getName().equalsIgnoreCase("v")) {
if(!p.hasPermission("hcf.command.vanish")) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("noperm-message")));
return false;
}
for (Player o : Bukkit.getServer().getOnlinePlayers()) {
if(vanished.contains(p)) {
vanished.remove(p);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("vanish-disabled")));
o.showPlayer(p);
return false;
}
if(!vanished.contains(p)) {
vanished.add(p);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', MainClass.getInstance().config.getString("vanish-enabled")));
o.hidePlayer(p);
return false;
}
}
}
}
return true;
}
}

also if possible could you help out with getting koths to show (subsides koth) and possibly an sotw timer?
 

kampai

Feedback score
8
Posts
361
Reactions
187
Resources
0
Put vanish.getInstance in ur splayer constructor and change arraylist to this:
Code:
List<Player> vanished = new ArrayList<>();
 

felldownstairs

Gypsy Boy | Java Developer
Supreme
Feedback score
4
Posts
783
Reactions
144
Resources
0
Put vanish.getInstance in ur splayer constructor and change arraylist to this:
Code:
List<Player> vanished = new ArrayList<>();
done that and it still wont work[DOUBLEPOST=1501265576][/DOUBLEPOST]
Put vanish.getInstance in ur splayer constructor and change arraylist to this:
Code:
List<Player> vanished = new ArrayList<>();
wait, wheres the splayer constructor?
 

Edvio

Feedback score
8
Posts
351
Reactions
113
Resources
0
This won't fix your specific problem, but these lines should be the other way around:
Code:
for (Player o : Bukkit.getServer().getOnlinePlayers()) {
if(vanished.contains(p)) {
[DOUBLEPOST=1501270744][/DOUBLEPOST]
also if possible could you help out with getting koths to show (subsides koth) and possibly an sotw timer?
Go learn java & spigot
 
Last edited:

Fle

Top tier Random.
Supreme
Feedback score
11
Posts
1,025
Reactions
425
Resources
0
Edvio You're so toxic.
 
Status
This thread has been locked.
Top