Dateien nach "src/main/java/com/viper/PlaceholderSIGN" hochladen
This commit is contained in:
49
src/main/java/com/viper/PlaceholderSIGN/FileUtil.java
Normal file
49
src/main/java/com/viper/PlaceholderSIGN/FileUtil.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package com.viper.PlaceholderSIGN;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
public class FileUtil {
|
||||||
|
public void updateConfig(String file) {
|
||||||
|
HashMap<String, Object> newConfig = getConfigVals(file);
|
||||||
|
File configFile = new File(Main.getInstance().getDataFolder(), file);
|
||||||
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
for (String var : yamlConfiguration.getKeys(false)) {
|
||||||
|
newConfig.remove(var);
|
||||||
|
}
|
||||||
|
if (!newConfig.isEmpty()) {
|
||||||
|
for (String key : newConfig.keySet()) {
|
||||||
|
yamlConfiguration.set(key, newConfig.get(key));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
yamlConfiguration.set("version", Main.getInstance().getVersion());
|
||||||
|
yamlConfiguration.save(configFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Main.getInstance().getLogger().severe("Fehler beim Speichern der Konfigurationsdatei: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> getConfigVals(String file) {
|
||||||
|
HashMap<String, Object> var = new HashMap<>();
|
||||||
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
|
try {
|
||||||
|
config.loadFromString(stringFromInputStream(Main.getInstance().getResource(file)));
|
||||||
|
} catch (InvalidConfigurationException e) {
|
||||||
|
Main.getInstance().getLogger().severe("Fehler beim Laden der Standardkonfiguration: " + e.getMessage());
|
||||||
|
}
|
||||||
|
for (String key : config.getKeys(false)) {
|
||||||
|
var.put(key, config.get(key));
|
||||||
|
}
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String stringFromInputStream(InputStream in) {
|
||||||
|
return new Scanner(in).useDelimiter("\\A").next();
|
||||||
|
}
|
||||||
|
}
|
88
src/main/java/com/viper/PlaceholderSIGN/Main.java
Normal file
88
src/main/java/com/viper/PlaceholderSIGN/Main.java
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package com.viper.PlaceholderSIGN;
|
||||||
|
|
||||||
|
import com.viper.PlaceholderSIGN.command.SignCommand;
|
||||||
|
import com.viper.PlaceholderSIGN.handler.SignListener;
|
||||||
|
import com.viper.PlaceholderSIGN.sign.SignManager;
|
||||||
|
import java.util.Objects;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class Main extends JavaPlugin {
|
||||||
|
public static String noperm;
|
||||||
|
public static String click;
|
||||||
|
public static String abort;
|
||||||
|
public static String numbers;
|
||||||
|
public static String usage;
|
||||||
|
public static String update;
|
||||||
|
private static Main instance;
|
||||||
|
private static SignManager sm;
|
||||||
|
private boolean papi = false;
|
||||||
|
private boolean rgb = true;
|
||||||
|
private int signMinimumDistance;
|
||||||
|
private int scrollSign;
|
||||||
|
private int updateInterval;
|
||||||
|
|
||||||
|
public static Main getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SignManager getPSManager() {
|
||||||
|
return sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return "3.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPAPI() {
|
||||||
|
return this.papi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRGB() {
|
||||||
|
return this.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSignMinimumDistance() {
|
||||||
|
return this.signMinimumDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScrollSign() {
|
||||||
|
return this.scrollSign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUpdateInterval() {
|
||||||
|
return this.updateInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
getConfig().options().copyDefaults(true);
|
||||||
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
if (!Objects.requireNonNull(getConfig().getString("version")).equals("3.0.0")) {
|
||||||
|
(new FileUtil()).updateConfig("config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
noperm = getConfig().getString("no_permission");
|
||||||
|
usage = getConfig().getString("usage_correct");
|
||||||
|
numbers = getConfig().getString("invalid_number");
|
||||||
|
abort = getConfig().getString("aborted_action");
|
||||||
|
click = getConfig().getString("click_to_edit");
|
||||||
|
update = getConfig().getString("update_message");
|
||||||
|
|
||||||
|
this.papi = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||||
|
this.signMinimumDistance = getConfig().getInt("sign-minimum-distance");
|
||||||
|
this.scrollSign = getConfig().getInt("scroll-time");
|
||||||
|
this.updateInterval = getConfig().getInt("update-interval", 1);
|
||||||
|
|
||||||
|
sm = new SignManager();
|
||||||
|
new SignCommand();
|
||||||
|
new SignListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
sm.saveAll();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user