Bukkit Coding Config

Status
This thread has been locked.

HuskyGG

Banned
Feedback score
3
Posts
79
Reactions
16
Resources
0
So as ive said multiple times im new to coding and would like some help on getting a basic config setup and was wondering the best way to implement one into my code.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Eric

Software Engineer
Supreme
Feedback score
14
Posts
1,760
Reactions
1,648
Resources
1
Props to Eric for helping, but you should really learn java before doing spigot.
I'm at work and bored as shit... lmfao[DOUBLEPOST=1503322015][/DOUBLEPOST]Just for the sake of showing how this should work (this will not 100% work because it was written in pastebin with no Bukkit implementation)

Code:
/*
WRITTEN IN PASTEBIN, SHOULD WORK, MIGHT NOT.
*/
public ArrayList<UUID> frozen = new ArrayList<UUID>();
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
    if(e.getCurrentItem() == null){ return; } // Making sure there won't be any null pointers if you click outside the inventory or anywhere without an item.
    if(e.getCurrentItem().getItemMeta() == null) {
        // Only if you're actually setting item meta for the player head
        return;
    }
    String playerName = e.getCurrentItem().getDisplayName(); // Not sure how you're formatting the player's name for the displayname, probably not best to do this...
    if(Bukkit.getServer().getPlayer(playerName) == null){ // Checking if the player is online
        e.getWhoClicked().sendMessage("Not online...");
        return;
    }
    Player clicked = Bukkit.getServer().getPlayer(playerName); // Getting their player instance from their name.
    frozen.add(clicked.getUniqueId()); // Adding them to the list.
    e.getWhoClicked().sendMessage("Player frozen...");
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e){
   
    if(frozen.contains(e.getPlayer().getUniqueId()){ // Checking if the player is in the frozen list
        e.setTo(e.getFrom()); // Setting their location to where they came from, stopping them moving..
    }
}

Try that, should give you a good idea.
 
Last edited:

Turtle

turtle#1989
Supreme
Feedback score
17
Posts
751
Reactions
419
Resources
0
I'm at work and bored as shit... lmfao[DOUBLEPOST=1503322015][/DOUBLEPOST]Just for the sake of showing how this should work (this will not 100% work because it was written in pastebin with no Bukkit implementation)

Code:
/*
WRITTEN IN PASTEBIN, SHOULD WORK, MIGHT NOT.
*/
public ArrayList<UUID> frozen = new ArrayList<UUID>();
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
    if(e.getCurrentItem() == null){ return; } // Making sure there won't be any null pointers if you click outside the inventory or anywhere without an item.
    if(e.getCurrentItem().getItemMeta() == null) {
        // Only if you're actually setting item meta for the player head
        return;
    }
    String playerName = e.getCurrentItem().getDisplayName(); // Not sure how you're formatting the player's name for the displayname, probably not best to do this...
    if(Bukkit.getServer().getPlayer(playerName) == null){ // Checking if the player is online
        e.getWhoClicked().sendMessage("Not online...");
        return;
    }
    Player clicked = Bukkit.getServer().getPlayer(playerName); // Getting their player instance from their name.
    frozen.add(clicked.getUniqueId()); // Adding them to the list.
    e.getWhoClicked().sendMessage("Player frozen...");
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e){
  
    if(frozen.contains(e.getPlayer().getUniqueId()){ // Checking if the player is in the frozen list
        e.setTo(e.getFrom()); // Setting their location to where they came from, stopping them moving..
    }
}

Try that, should give you a good idea.
why did you use braces on a single liner!!!! i'm calling the java police!!
 
Status
This thread has been locked.
Top