Skip to content

Commit

Permalink
fixed everything
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccoystephenson committed Aug 14, 2020
1 parent c7138e6 commit 25c93a0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
34 changes: 32 additions & 2 deletions src/main/java/economysystem/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import economysystem.Subsystems.ConfigSubsystem;
import economysystem.Subsystems.StorageSubsystem;
import economysystem.Subsystems.UtilitySubsystem;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
Expand All @@ -19,6 +21,9 @@
import java.util.ArrayList;
import java.util.UUID;

import static org.bukkit.Bukkit.getOfflinePlayers;
import static org.bukkit.Bukkit.getOnlinePlayers;

public final class Main extends JavaPlugin implements Listener {

// version
Expand Down Expand Up @@ -52,7 +57,13 @@ public void onEnable() {
}

this.getServer().getPluginManager().registerEvents(this, this);
storage.load();
if (new File("./plugins/MedievalEconomy/config.yml").exists()) {
storage.load();
}
else {
storage.legacyLoadCoinpurses();
}

System.out.println(getConfig().getString("enablingText"));
}

Expand All @@ -79,7 +90,26 @@ public void onDeath(PlayerDeathEvent event) {
handler.handle(event);
}

public UUID findUUIDBasedOnPlayerName(String playerName) {
// Pasarus wrote this
public static UUID findUUIDBasedOnPlayerName(String playerName){
// Check online
for (Player player : getOnlinePlayers()){
if (player.getName().equals(playerName)){
return player.getUniqueId();
}
}

// Check offline
for (OfflinePlayer player : getOfflinePlayers()){
try {
if (player.getName().equals(playerName)){
return player.getUniqueId();
}
} catch (NullPointerException e) {
// Fail silently as quit possibly common.
}

}

return null;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/economysystem/Objects/Coinpurse.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ public boolean containsAtLeast(int num) {

public void save() {
try {
File saveFolder = new File("./plugins/Medieval-Economy/");
File saveFolder = new File("./plugins/MedievalEconomy/");
if (!saveFolder.exists()) {
saveFolder.mkdir();
}
File saveFolder2 = new File("./plugins/Medieval-Economy/Coinpurse-Records/");
File saveFolder2 = new File("./plugins/MedievalEconomy/Coinpurse-Records/");
if (!saveFolder2.exists()) {
saveFolder2.mkdir();
}
File saveFile = new File("./plugins/Medieval-Economy/Coinpurse-Records/" + uuid + ".txt");
File saveFile = new File("./plugins/MedievalEconomy/Coinpurse-Records/" + uuid + ".txt");
saveFile.createNewFile();

FileWriter saveWriter = new FileWriter("./plugins/Medieval-Economy/Coinpurse-Records/" + uuid + ".txt");
FileWriter saveWriter = new FileWriter("./plugins/MedievalEconomy/Coinpurse-Records/" + uuid + ".txt");

// actual saving takes place here
saveWriter.write(uuid.toString() + "\n");
Expand All @@ -83,7 +83,7 @@ public void save() {

public void load(String filename) {
try {
File loadFile = new File("./plugins/Medieval-Economy/Coinpurse-Records/" + filename);
File loadFile = new File("./plugins/MedievalEconomy/Coinpurse-Records/" + filename);
Scanner loadReader = new Scanner(loadFile);

// actual loading
Expand Down Expand Up @@ -119,6 +119,7 @@ public void legacyLoad(String filename) {
}

loadReader.close();
loadFile.delete();
} catch (FileNotFoundException e) {
System.out.println(main.getConfig().getString("coinpurseLoadErrorText") + filename);
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/economysystem/Subsystems/StorageSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void saveCoinpurses() {
public void loadCoinpurses() {
try {
System.out.println("Attempting to load coinpurse records...");
File loadFile = new File("./plugins/Medieval-Economy/" + "coinpurse-record-filenames.txt");
File loadFile = new File("./plugins/MedievalEconomy/" + "coinpurse-record-filenames.txt");
Scanner loadReader = new Scanner(loadFile);

// actual loading
Expand All @@ -83,7 +83,8 @@ public void loadCoinpurses() {
loadReader.close();
System.out.println("Coinpurse records successfully loaded.");
} catch (FileNotFoundException e) {
System.out.println("Error loading the coinpurse records!");
System.out.println(main.getConfig().getString("storageLoadError"));
e.printStackTrace();
}
}

Expand All @@ -104,7 +105,10 @@ public void legacyLoadCoinpurses() {
loadReader.close();
} catch (FileNotFoundException e) {
System.out.println(main.getConfig().getString("storageLoadError"));
e.printStackTrace();
}

save();
}

}

0 comments on commit 25c93a0

Please sign in to comment.