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.
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)Props to Eric for helping, but you should really learn java before doing spigot.
/*
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..
}
}
why did you use braces on a single liner!!!! i'm calling the java police!!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.
The fuck are you on about? It's formatting.why did you use braces on a single liner!!!! i'm calling the java police!!
