2 changed files with 199 additions and 0 deletions
@ -0,0 +1,58 @@ |
|||
package Config; |
|||
|
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import org.bukkit.Bukkit; |
|||
import org.bukkit.Location; |
|||
import org.bukkit.configuration.ConfigurationSection; |
|||
import org.bukkit.configuration.file.YamlConfiguration; |
|||
|
|||
public class Config { |
|||
|
|||
public static void check() { |
|||
File folder = new File("plugins/ChestLock"); |
|||
File file = new File("plugins/ChestLock", "config.yml"); |
|||
|
|||
folder.mkdirs(); |
|||
if(!file.exists()) { |
|||
try { |
|||
file.createNewFile(); |
|||
} catch (IOException e) { |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static void create() { |
|||
File file = new File("plugins/ChestLock", "config.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
cfg.options().copyDefaults(true); |
|||
cfg.addDefault("Permissions", "§8» §7Du hast nicht die §cbenötigten §7Berechtigungen dafür!"); |
|||
cfg.addDefault("Chest-Locked", "§8» §7Die Kiste wurde §aabgeschlossen§7!"); |
|||
cfg.addDefault("Chest-Unlocked", "§8» §7Die Kiste wurde §caufgeschlossen§7!"); |
|||
cfg.addDefault("Chest-is-locked", "§8» §7Diese Kiste ist §cabgeschossen"); |
|||
cfg.addDefault("Chest-is-already-locked", "§8» §7Diese Kiste ist bereits §cabgeschossen"); |
|||
cfg.addDefault("Chest-lockingprocess", "§8» §7Mache Rechtsklick §7auf die Kiste, die du §cabschließen §7möchtest!"); |
|||
cfg.addDefault("Chest-unlockingprocess", "§8» §7Mache Rechtsklick §7auf die Kiste, die du §aaufschließen §7möchtest!"); |
|||
cfg.addDefault("Player-Offline", "§8» §7Dieser Spieler ist §cnicht §7online!"); |
|||
cfg.addDefault("Chest-not-yours", "§8» §7Das ist §cnicht §7deine Kiste!"); |
|||
cfg.addDefault("Chest-not-locked", "§8» §7Diese Kiste ist §cnicht §7abgeschlossen!"); |
|||
cfg.addDefault("Not-A-Chest", "§8» §7Das ist §ckeine §7Kiste!"); |
|||
try { |
|||
cfg.save(file); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
public static String getString(String varchane) { |
|||
File file = new File("plugins/ChestLock", "config.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
return cfg.getString(varchane); |
|||
|
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,141 @@ |
|||
package Config; |
|||
|
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import org.bukkit.Bukkit; |
|||
import org.bukkit.Location; |
|||
import org.bukkit.configuration.ConfigurationSection; |
|||
import org.bukkit.configuration.file.YamlConfiguration; |
|||
import org.bukkit.entity.Player; |
|||
|
|||
public class UserConfig { |
|||
|
|||
public static void check() { |
|||
File folder = new File("plugins/ChestLock"); |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
|
|||
folder.mkdirs(); |
|||
if(!file.exists()) { |
|||
try { |
|||
file.createNewFile(); |
|||
} catch (IOException e) { |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static void addChest(Location loc, Player p) { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
int x = loc.getBlockX(); |
|||
int y = loc.getBlockY(); |
|||
int z = loc.getBlockZ(); |
|||
|
|||
cfg.set(y+"-"+loc.getBlockX()+".x", x); |
|||
cfg.set(y+"-"+loc.getBlockX()+".y", y); |
|||
cfg.set(y+"-"+loc.getBlockX()+".z", z); |
|||
cfg.set(y+"-"+loc.getBlockX()+".owner", p.getUniqueId().toString()); |
|||
try { |
|||
cfg.save(file); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
public static void remove(Location loc) { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".x", null); |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".y", null); |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".z", null); |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".owner", null); |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".allowed", null); |
|||
|
|||
try { |
|||
cfg.save(file); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
public static void addAllowed(Location loc, Player p) { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
if(cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".allowed") == null) { |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".allowed", p.getUniqueId().toString()); |
|||
} else { |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".allowed", cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".allowed")+","+p.getUniqueId().toString()); |
|||
} |
|||
|
|||
try { |
|||
cfg.save(file); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
public static void removeAllowed(Location loc, Player p) { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
if(!cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".allowed").contains(",")) { |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".allowed", null); |
|||
} else { |
|||
String pd = cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".allowed"); |
|||
pd.replace(p.getUniqueId().toString()+",", ""); |
|||
cfg.set(loc.getBlockY()+"-"+loc.getBlockX()+".allowed", pd); |
|||
} |
|||
|
|||
try { |
|||
cfg.save(file); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
|
|||
public static boolean isAllowed(Location loc, Player p) { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
if(cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".owner").equals(p.getUniqueId().toString())) { |
|||
return true; |
|||
} else if(cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".allowed") != null) { |
|||
if(cfg.getString(loc.getBlockY()+"-"+loc.getBlockX()+".allowed").contains(p.getUniqueId().toString())) { |
|||
return true; |
|||
|
|||
} else { |
|||
return false; |
|||
} |
|||
} else { |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
|
|||
public static List<String> locks() { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
ConfigurationSection cs = cfg.getConfigurationSection(""); |
|||
|
|||
List<String> fl = new ArrayList<>(); |
|||
for(String flippers : cs.getKeys(false)) { |
|||
fl.add(flippers); |
|||
} |
|||
|
|||
return fl; |
|||
} |
|||
|
|||
public static Location flipLocation(String name) { |
|||
File file = new File("plugins/ChestLock", "userconfig.yml"); |
|||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); |
|||
|
|||
int x = cfg.getInt(name+".x"); |
|||
int y = cfg.getInt(name+".y"); |
|||
int z = cfg.getInt(name+".z"); |
|||
|
|||
Location loc = new Location(Bukkit.getWorld("world"), x, y, z); |
|||
return loc; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue