Replaces use of old org.bukkit.util.config.Configuration API.
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -9,7 +9,7 @@
|
|||||||
- [x] Ensure plugin.yml is present in src/main/resources and update for PaperMC compatibility (api-version, commands, required fields).
|
- [x] Ensure plugin.yml is present in src/main/resources and update for PaperMC compatibility (api-version, commands, required fields).
|
||||||
- [ ] Refactor all logger usage to use getLogger() from JavaPlugin.
|
- [ ] Refactor all logger usage to use getLogger() from JavaPlugin.
|
||||||
- [ ] Refactor all event listeners to use the modern event system (Listener interface, @EventHandler, registerEvents).
|
- [ ] Refactor all event listeners to use the modern event system (Listener interface, @EventHandler, registerEvents).
|
||||||
- [ ] Replace use of org.bukkit.util.config.Configuration with the modern configuration API (getConfig(), saveConfig(), etc.).
|
- [x] Replace use of org.bukkit.util.config.Configuration with the modern configuration API (getConfig(), saveConfig(), etc.).
|
||||||
- [ ] Update score table to use Bukkit entity types or enums instead of CraftBukkit class names.
|
- [ ] Update score table to use Bukkit entity types or enums instead of CraftBukkit class names.
|
||||||
- [ ] If storing player scores, refactor to use UUID as the key instead of Player or String.
|
- [ ] If storing player scores, refactor to use UUID as the key instead of Player or String.
|
||||||
- [ ] Build the plugin with Gradle (./gradlew build) and test on a modern Paper server using the provided bash scripts. _(Depends on: all refactors and plugin.yml update)_
|
- [ ] Build the plugin with Gradle (./gradlew build) and test on a modern Paper server using the provided bash scripts. _(Depends on: all refactors and plugin.yml update)_
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.mobscores.listeners.MobDeathListener;
|
import com.majinnaibu.minecraft.plugins.mobscores.listeners.MobDeathListener;
|
||||||
import com.majinnaibu.minecraft.plugins.mobscores.listeners.PlayerConnectListener;
|
import com.majinnaibu.minecraft.plugins.mobscores.listeners.PlayerConnectListener;
|
||||||
@@ -40,10 +39,9 @@ import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
|||||||
public class MobScoresPlugin extends JavaPlugin {
|
public class MobScoresPlugin extends JavaPlugin {
|
||||||
private final MobDeathListener _mobDeathListener = new MobDeathListener(this);
|
private final MobDeathListener _mobDeathListener = new MobDeathListener(this);
|
||||||
private final PlayerConnectListener _playerConnectListener = new PlayerConnectListener(this);
|
private final PlayerConnectListener _playerConnectListener = new PlayerConnectListener(this);
|
||||||
private HashMap<Entity, Player> _claimedMobs = new HashMap<Entity, Player>();
|
private Map<Entity, Player> _claimedMobs = new HashMap<Entity, Player>();
|
||||||
private HashMap<String, Integer> _scoreTable = new HashMap<String, Integer>();
|
private Map<String, Integer> _scoreTable = new HashMap<String, Integer>();
|
||||||
private ScoreKeeperPlugin _scoreKeeper = null;
|
private ScoreKeeperPlugin _scoreKeeper = null;
|
||||||
private Configuration _configuration = null;
|
|
||||||
|
|
||||||
private final String _logStart = "[" + ChatColor.AQUA + "MobScores" + ChatColor.WHITE + "] ";
|
private final String _logStart = "[" + ChatColor.AQUA + "MobScores" + ChatColor.WHITE + "] ";
|
||||||
|
|
||||||
@@ -51,30 +49,30 @@ public class MobScoresPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
_configuration.setProperty("ScoreTable", _scoreTable);
|
getConfig().set("ScoreTable", _scoreTable);
|
||||||
_configuration.save();
|
saveConfig();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
_configuration = getConfiguration();
|
// Create the default config if it doesn't exist.
|
||||||
try{
|
saveDefaultConfig();
|
||||||
_scoreTable = (HashMap<String, Integer>)_configuration.getProperty("ScoreTable");
|
|
||||||
}catch (Exception ex){
|
// Load our score table from config or set defaults.
|
||||||
|
if (getConfig().contains("ScoreTable")) {
|
||||||
|
Object rawValue = getConfig().get("ScoreTable");
|
||||||
|
if (rawValue instanceof Map) {
|
||||||
|
_scoreTable = new HashMap<>((Map<String, Integer>) rawValue);
|
||||||
|
} else {
|
||||||
|
_scoreTable = getDefaultScoreTable();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
_scoreTable = getDefaultScoreTable();
|
_scoreTable = getDefaultScoreTable();
|
||||||
|
getConfig().set("ScoreTable", _scoreTable);
|
||||||
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_scoreTable == null){
|
|
||||||
_scoreTable = getDefaultScoreTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
_configuration.setProperty("ScoreTable", _scoreTable);
|
|
||||||
|
|
||||||
|
|
||||||
_configuration.save();
|
|
||||||
|
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
_scoreKeeper = (ScoreKeeperPlugin)pm.getPlugin("ScoreKeeper");
|
_scoreKeeper = (ScoreKeeperPlugin)pm.getPlugin("ScoreKeeper");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user