-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the PlayerPoints Convert command to convert data from PlayerPoint…
…s to OptEco
- Loading branch information
1 parent
5ef86e7
commit 4ab996e
Showing
8 changed files
with
233 additions
and
1 deletion.
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
89 changes: 89 additions & 0 deletions
89
src/main/java/me/playernguyen/opteco/command/PlayerPointToOptEcoCommand.java
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,89 @@ | ||
package me.playernguyen.opteco.command; | ||
|
||
import me.playernguyen.opteco.OptEco; | ||
import me.playernguyen.opteco.permission.OptEcoPermission; | ||
import me.playernguyen.opteco.playerpoints.PlayerPointsAdapter; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
import org.bukkit.command.RemoteConsoleCommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class PlayerPointToOptEcoCommand extends OptEcoAbstractCommand{ | ||
|
||
public PlayerPointToOptEcoCommand() { | ||
super("playerpointtoopteco"); | ||
// Add permissions | ||
addPermissions(OptEcoPermission.EVERYTHING); | ||
addPermissions(OptEcoPermission.ADMIN); | ||
addPermissions(OptEcoPermission.PPTO); | ||
} | ||
|
||
@Override | ||
public boolean onPlayerCommand(Player player, Command command, String s, String[] args) { | ||
return exec(player, args); | ||
} | ||
|
||
@Override | ||
public boolean onConsoleCommand(ConsoleCommandSender sender, Command command, String s, String[] args) { | ||
return exec(sender, args); | ||
} | ||
|
||
@Override | ||
public boolean onRemoteConsole(RemoteConsoleCommandSender sender, Command command, String s, String[] args) { | ||
return exec(sender, args); | ||
} | ||
|
||
@Override | ||
public boolean onAny(CommandSender sender, Command command, String s, String[] args) { | ||
return exec(sender, args); | ||
} | ||
|
||
private boolean exec(CommandSender sender, String[] arguments) { | ||
sender.sendMessage(ChatColor.GOLD + "Trying to convert data..."); | ||
PlayerPointsAdapter adapter = new PlayerPointsAdapter(); | ||
// Checking | ||
if (!adapter.isHasPlugin()) { | ||
sender.sendMessage(ChatColor.RED + "The plugin PlayerPoints not found!"); | ||
return true; | ||
} | ||
if (!adapter.getDataFolder().exists()) { | ||
sender.sendMessage(ChatColor.RED + "The folder plugins/PlayerPoints not found!"); | ||
return true; | ||
} | ||
if (!adapter.getStorageFile().exists()) { | ||
sender.sendMessage(ChatColor.RED + "The storage file (storage.yml) of PlayerPoints not found!"); | ||
return true; | ||
} | ||
// Collect data | ||
List<PlayerPointsAdapter.PlayerPointsObject> collect = adapter.collect(); | ||
// Push data to database | ||
if (collect.size() > 0) { | ||
sender.sendMessage(ChatColor.GRAY + "Pushing data into the database..."); | ||
for (PlayerPointsAdapter.PlayerPointsObject object : collect) { | ||
getLogger().info("---- Import ----"); | ||
getLogger().info("- UUID: " + object.getUUID() + "-"); | ||
getLogger().info("- Points: " + object.getPoint() + "-"); | ||
sender.sendMessage(ChatColor.GRAY + " * " + object.getUUID() + ": " + object.getPoint() + "..."); | ||
getAccountManager().pushNewOne(object.getUUID(), object.getPoint()); | ||
} | ||
} else { | ||
sender.sendMessage(ChatColor.GRAY + " (Nothing changes because the storage is empty)"); | ||
} | ||
sender.sendMessage(ChatColor.GREEN + "Done!"); | ||
sender.sendMessage(ChatColor.GOLD + "Now you can remove the PlayerPoints plugin, reload and use " + | ||
"OptEco instead. Good luck!"); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { | ||
return null; | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
src/main/java/me/playernguyen/opteco/playerpoints/PlayerPointsAdapter.java
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,96 @@ | ||
package me.playernguyen.opteco.playerpoints; | ||
|
||
import com.google.common.base.Preconditions; | ||
import me.playernguyen.opteco.OptEco; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public class PlayerPointsAdapter { | ||
|
||
private static final String PLAYER_POINTS_STORAGE_FILE_NAME = "storage.yml"; | ||
private final File dataFolder; | ||
private final File storageFile; | ||
private final boolean hasPlugin; | ||
private final Plugin playerPointsPlugin; | ||
|
||
public PlayerPointsAdapter() { | ||
// If not found PlayerPoints, throw an exception | ||
this.playerPointsPlugin = Bukkit.getPluginManager().getPlugin("PlayerPoints"); | ||
this.hasPlugin = playerPointsPlugin != null; | ||
// If found, doing the process | ||
this.dataFolder = (playerPointsPlugin != null) ? playerPointsPlugin.getDataFolder(): null; | ||
this.storageFile = new File(getDataFolder(), PLAYER_POINTS_STORAGE_FILE_NAME); | ||
} | ||
|
||
public Plugin getPlayerPointsPlugin() { | ||
return playerPointsPlugin; | ||
} | ||
|
||
public void disable() { | ||
OptEco.getInstance().getPluginLoader().disablePlugin(getPlayerPointsPlugin()); | ||
} | ||
|
||
public boolean isHasPlugin() { | ||
return hasPlugin; | ||
} | ||
|
||
public File getDataFolder() { | ||
return dataFolder; | ||
} | ||
|
||
public List<PlayerPointsObject> collect() { | ||
ArrayList<PlayerPointsObject> playerPointsObjects = new ArrayList<>(); | ||
// Scan the PlayerPoints/storage.yml | ||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(storageFile); | ||
// File configuration loader | ||
if (fileConfiguration.contains("Points")) { | ||
ConfigurationSection points = fileConfiguration.getConfigurationSection("Points"); | ||
// Not null check | ||
Preconditions.checkNotNull(points); | ||
// Collect as set | ||
Set<String> uuids = points.getKeys(false); | ||
// Put set | ||
for (String uuid : uuids) { | ||
playerPointsObjects.add(new PlayerPointsObject(UUID.fromString(uuid), | ||
points.getInt(uuid))); | ||
} | ||
} | ||
|
||
return playerPointsObjects; | ||
} | ||
|
||
public File getStorageFile() { | ||
return storageFile; | ||
} | ||
|
||
public static class PlayerPointsObject { | ||
|
||
private final UUID uuid; | ||
private final int point; | ||
|
||
public PlayerPointsObject(UUID uuid, int point) { | ||
this.uuid = uuid; | ||
this.point = point; | ||
} | ||
|
||
public int getPoint() { | ||
return point; | ||
} | ||
|
||
public UUID getUUID() { | ||
return uuid; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
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