Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.Writer;
- public class JailSet extends PluginListener{
- Writer writer = null;
- Writer writer2 = null;
- File coords = new File("plugins/config/Jail/FileC.txt");
- File names = new File("plugins/config/Jail/Jailnames.txt");
- String directory = "plugins/config/Jail/Jailes/";
- public boolean onCommand(Player player,String[] split){
- if (split[0].equalsIgnoreCase("/setmainjail")&& player.canUseCommand("/jailadmin")){
- String co = Math.floor(player.getX())+","+Math.floor(player.getY())+","+Math.floor(player.getZ())+","+player.getWorld();
- if (!isInList(co)){
- PropertiesFile mainj = new PropertiesFile(directory+"Mainjail.properties");
- if (!mainj.containsKey("Entrance")){
- try {
- writer = new FileWriter("plugins/config/Jail/FileC.txt", true);
- writer.write(co+"\n");
- writer.close();
- writer2 = new FileWriter("plugins/config/Jail/Jailnames.txt", true);
- writer2.write("Mainjail\n");
- writer2.close();
- mainj.setString("Entrance", co);
- player.sendMessage("§2Mainjail Entrance has been set.");
- } catch (IOException e) {
- }
- return true;
- }else{
- player.sendMessage("§cThe mainjail entrance already has been set.");
- player.sendMessage("§cUse /resetentrance Mainjail to reset the entrance");
- player.sendMessage("§cor /deletejail Mainjail to delete the jail and all its cells");
- return true;
- }
- }else{
- player.sendMessage("§cThere is already a jail/cell with this coördinates.");
- return true;
- }
- }else{
- if(split[0].equalsIgnoreCase("/setjail")&&player.canUseCommand("/jailadmin")){
- if (split.length <2 || split.length >2){
- player.sendMessage("§cThe correct usage is '/setjail <jailname>'");
- return true;
- }else{
- String co = Math.floor(player.getX())+","+Math.floor(player.getY())+","+Math.floor(player.getZ())+","+player.getWorld();
- String name = split[1];
- if (!isInList(co)){
- if (!isInList2(name)){
- PropertiesFile jail = new PropertiesFile(directory+name+".properties");
- jail.setString("Entrance", co);
- try {
- writer2 = new FileWriter("plugins/config/Jail/Jailnames.txt", true);
- writer2.write(name+"\n");
- writer2.close();
- writer = new FileWriter("plugins/config/Jail/FileC.txt", true);
- writer.write(co+"\n");
- writer.close();
- } catch (IOException e) {
- }
- player.sendMessage("§2Jail "+ name+" has been set.");
- return true;
- }else{
- player.sendMessage("§cThere is already a jail with this name.");
- return true;
- }
- }else{
- player.sendMessage("§cThere is already a jail/cell with this coördinates.");
- return true;
- }
- }
- }
- }
- return false;
- }
- public boolean isInList(String s) {
- try {
- BufferedReader in = new BufferedReader(new FileReader(coords));
- String line = in.readLine();
- while (line != null) {
- if (line.equalsIgnoreCase(s)) {
- in.close();
- return true;
- }
- line = in.readLine();
- }
- in.close();
- } catch (IOException localIOException) {
- }
- return false; }
- public boolean isInList2(String s) {
- try {
- BufferedReader in = new BufferedReader(new FileReader(names));
- String line = in.readLine();
- while (line != null) {
- if (line.equalsIgnoreCase(s)) {
- in.close();
- return true;
- }
- line = in.readLine();
- }
- in.close();
- } catch (IOException localIOException) {
- }
- return false; }
- }
Advertisement
Add Comment
Please, Sign In to add comment