Solved Objects

Discussion in 'Plugin Development' started by Chr0mosom3, Mar 23, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Chr0mosom3

    Hey there,

    I am having a problem with objects. I have a object named ServerPlayer and I will make it so each player in the server is part of a list of ServerPlayer in the main class. Now I have a method to check if the players is inside something and I take ServerPlayer as an argument.
    Code:
    public static boolean isInside(ServerPlayer sp) {
            int x1 = Math.min(loc1.getBlockX(), loc2.getBlockX());
            int y1 = Math.min(loc1.getBlockY(), loc2.getBlockY());
            int z1 = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
            int x2 = Math.max(loc1.getBlockX(), loc2.getBlockX());
            int y2 = Math.max(loc1.getBlockY(), loc2.getBlockY());
            int z2 = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
    
            return x >= x1 && x <= x2 && y >= y1 && y <= y2 && z >= z1 && z <= z2;
    }
    But when I do sp.getIdentity() I get this error
    Code:
     The method getIdentity() from the type ServerPlayer is not visible
    and it tells me to set the method to public.


    This is my ServerPlayer class:
    ServerPlayer (open)

    Code:
    package AluminiumProject.Objects.ServerPlayer;
    
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    
    public class ServerPlayer {
        private Identity identity;
        private ModeratorRank modrank;
       
        public ServerPlayer(Player p) {
            this.identity.setUUID(p.getUniqueId());
            this.identity.setName(p.getName());
        }
       
        ModeratorRank getModeratorRank() { return this.modrank; }
        void setModeratorRank(ModeratorRank arg) { this.modrank = arg; }
       
        Identity getIdentity() { return identity; }
       
        private class Identity {
            private UUID uuid; // Required
            private String name; // Required
            private String nick;
           
            Player getPlayer() { return Bukkit.getPlayer(uuid); }
           
           
            UUID getUUID() { return this.uuid; }
            void setUUID(UUID arg) { this.uuid = arg; }
           
            String getName() { return this.name; }
            void setName(String arg) { this.name = arg; }
           
            String getNick() { return nick; }
            void setNick(String arg) { this.nick = arg; }
            boolean isNicked() { return this.nick != null; }
        }
    }


    This is the class that uses the method
    KitPvPArena (open)
    Code:
    package AluminiumProject.Objects.Locations.KitPvP;
    
    
    
    import org.bukkit.Location;
    
    
    
    import AluminiumProject.Objects.ServerPlayer.ServerPlayer;
    
    
    
    public class KitPvPArena {
    
    private static Location loc1;
    
    private static Location loc2;
    
    
    public KitPvPArena(Location arg, Location arg2) {
    
    loc1 = arg;
    
    loc2 = arg2;
    
    }
    
    
    public static boolean isInside(ServerPlayer sp) {
    
            int x1 = Math.min(loc1.getBlockX(), loc2.getBlockX());
    
            int y1 = Math.min(loc1.getBlockY(), loc2.getBlockY());
    
            int z1 = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
    
            int x2 = Math.max(loc1.getBlockX(), loc2.getBlockX());
    
            int y2 = Math.max(loc1.getBlockY(), loc2.getBlockY());
    
            int z2 = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
    
           
    
            return x >= x1 && x <= x2 && y >= y1 && y <= y2 && z >= z1 && z <= z2;
    
            }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @MrDaniel Put public in front of it, always put, private, public or protected in front of it.
     
  3. Offline

    Chr0mosom3

    @timtower, but I only want it to be accessed with new ServerPlayer().getIdentity(); so it will return a different identity for each object of ServerPlayer
     
  4. Offline

    timtower Administrator Administrator Moderator

    @MrDaniel Why not just make a new Identity object then?
     
  5. Offline

    Chr0mosom3

    @timtower, Well, because I also want to access the methods in the class, not only the identity class.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @MrDaniel Then you need to make an instance of the class.
    And you need to make the getIdentity method public.
     
Thread Status:
Not open for further replies.

Share This Page