Created
January 22, 2017 02:01
-
-
Save TheMasteredPanda/e2b9b1f531c0a2e61314e40ff2fe47cf to your computer and use it in GitHub Desktop.
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
package me.tmp.test; | |
import com.google.common.collect.Lists; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import org.bukkit.Material; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.PlayerJoinEvent; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.util.List; | |
import java.util.UUID; | |
/** | |
* Created by TheMasteredPanda on 21/01/2017. | |
*/ | |
public class Main extends JavaPlugin implements CommandExecutor, Listener | |
{ | |
private Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |
private List<Listing> listings = Lists.newArrayList(); | |
private AHPlayer player; | |
@Override | |
public void onEnable() | |
{ | |
if (!this.getDataFolder().exists()) { | |
this.getDataFolder().mkdir(); | |
} | |
for (int i = 0; i < 10; i++) { | |
listings.add(new Listing(i, new ItemStack(Material.APPLE), UUID.randomUUID(), UUID.randomUUID(), 100L, 1000L, 10L, 9000000000F, false)); | |
Listing listing = listings.get(i); | |
File f = new File(this.getDataFolder(), i + ".txt"); | |
if (!f.exists()) { | |
f.mkdir(); | |
} | |
try { | |
FileWriter writer = new FileWriter(f); | |
writer.write(gson.toJson(listing)); | |
writer.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
@EventHandler | |
public void onPlayerJoin(PlayerJoinEvent e) | |
{ | |
this.player = new AHPlayer(e.getPlayer().getUniqueId(), Lists.newLinkedList(listings), Lists.newArrayList(new UUID[]{UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()}), listings, 10000L, 20, 10, false); | |
File f = new File(this.getDataFolder(), this.player.getPlayerUUID() + ".json"); | |
if (!f.exists()) { | |
f.mkdir(); | |
} | |
try { | |
FileWriter writer = new FileWriter(f); | |
writer.write(gson.toJson(this.player)); | |
writer.close(); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment