forked from dentych/EnchantGUI
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from sarhatabaot/feature/toggle-right-click
Feature/toggle right click
- Loading branch information
Showing
13 changed files
with
216 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package me.tychsen.enchantgui.config; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* @author sarhatabaot | ||
*/ | ||
public abstract class AConfig { | ||
@Setter | ||
@Getter (AccessLevel.PROTECTED) | ||
private String fileName; | ||
private File configFile; | ||
private JavaPlugin plugin; | ||
private FileConfiguration config; | ||
|
||
/** | ||
* | ||
* @param fileName file name including the type. | ||
* @param plugin plugin instance. | ||
*/ | ||
public AConfig(final String fileName, final JavaPlugin plugin) { | ||
this.fileName = fileName; | ||
this.plugin = plugin; | ||
} | ||
|
||
/** | ||
* Reloads the file | ||
*/ | ||
protected void reloadConfig(){ | ||
if (configFile == null) { | ||
configFile = new File(plugin.getDataFolder(), getFileName()); | ||
} | ||
config = YamlConfiguration.loadConfiguration(configFile); | ||
|
||
// Look for defaults in the jar | ||
Reader defaultConfigStream; | ||
InputStream defaultConfigInputStream = plugin.getResource(getFileName()); | ||
if (defaultConfigInputStream != null) { | ||
defaultConfigStream = new InputStreamReader(defaultConfigInputStream, StandardCharsets.UTF_8); | ||
YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigStream); | ||
config.setDefaults(defaultConfig); | ||
} | ||
|
||
plugin.getLogger().info(getFileName()+" reloaded."); | ||
} | ||
|
||
/** | ||
* Saves the default configuration from the jar. | ||
*/ | ||
protected void saveDefaultConfiguration(){ | ||
if (configFile == null) { | ||
configFile = new File(plugin.getDataFolder(), getFileName()); | ||
} | ||
if (!configFile.exists()) { | ||
plugin.saveResource(getFileName(), false); | ||
} | ||
} | ||
|
||
/** | ||
* @return FileConfiguration config. | ||
*/ | ||
protected FileConfiguration getConfig() { | ||
if (config == null) { | ||
reloadConfig(); | ||
} | ||
return config; | ||
} | ||
|
||
public abstract String getString(String path); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.