Created
January 22, 2017 10:35
-
-
Save TheMasteredPanda/abe05476cd264871e65b89be1bcc9c1f 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 lombok.Getter; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.UUID; | |
/** | |
* Created by TheMasteredPanda on 18/01/2017. | |
*/ | |
public class AHPlayer | |
{ | |
private @Getter UUID playerUUID; | |
private @Getter LinkedList<Listing> listings; | |
private @Getter List<UUID> watchedAuctioneers; | |
private @Getter long totalProfitMade; | |
private @Getter int itemsSold; | |
private @Getter int itemsBrought; | |
private @Getter int rating; | |
private Player player; | |
protected AHPlayer(UUID playerUUID, LinkedList<Listing> listings, List<UUID> watchedAuctioneers, List<Listing> watchedItems, long totalProfitMade, int itemsSold, int itemsBrought, boolean blackListed) | |
{ | |
this.playerUUID = playerUUID; | |
this.listings = listings; | |
this.watchedAuctioneers = watchedAuctioneers; | |
this.totalProfitMade = totalProfitMade; | |
this.itemsSold = itemsSold; | |
this.itemsBrought = itemsBrought; | |
this.rating = rating; | |
this.player = Bukkit.getPlayer(playerUUID); | |
} | |
} |
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 org.bukkit.Bukkit; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
/** | |
* Created by TheMasteredPanda on 22/01/2017. | |
*/ | |
public class CommandGive implements CommandExecutor | |
{ | |
private JsonTest instance = JsonTest.getInstance(); | |
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) | |
{ | |
if (command.getName().equalsIgnoreCase("givelistingitems")) { | |
for (int i = 0; i < this.instance.listings.size(); i++) { | |
Listing listing = this.instance.listings.get(i); | |
Bukkit.getPlayer(commandSender.getName()).getInventory().addItem(listing.getItem()); | |
commandSender.sendMessage("Added Item "+ listing.getItem()); | |
} | |
} | |
return true; | |
} | |
} |
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 lombok.Getter; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.PlayerJoinEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import java.io.*; | |
import java.util.List; | |
import java.util.UUID; | |
/** | |
* Created by TheMasteredPanda on 21/01/2017. | |
*/ | |
public class JsonTest extends JavaPlugin implements Listener | |
{ | |
private static @Getter JsonTest instance; | |
private Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |
public List<Listing> listings = Lists.newArrayList(); | |
private AHPlayer player; | |
@Override | |
public void onLoad() | |
{ | |
instance = this; | |
try { | |
getCommand("givelistingitems").setExecutor(new CommandGive()); | |
} catch (NullPointerException npe) { | |
npe.printStackTrace(); | |
} | |
} | |
@Override | |
public void onEnable() | |
{ | |
File[] files = new File(this.getDataFolder(), "JsonTest").listFiles(); | |
if (files != null) { | |
for (int i = 0; i < files.length; i++) { | |
try { | |
listings.add(gson.fromJson(new FileReader(files[i]), Listing.class)); | |
} catch (FileNotFoundException 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()) { | |
try { | |
f.createNewFile(); | |
FileWriter writer = new FileWriter(f); | |
writer.write(gson.toJson(this.player)); | |
writer.close(); | |
} catch (IOException ioe) { | |
ioe.printStackTrace(); | |
} | |
} | |
} | |
} |
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 lombok.Getter; | |
import lombok.Setter; | |
import org.bukkit.inventory.ItemStack; | |
import java.util.UUID; | |
/** | |
* Created by TheMasteredPanda on 22/01/2017. | |
*/ | |
public class Listing | |
{ | |
private @Getter | |
int listingID; | |
private @Getter UUID auctioneer; | |
private @Getter @Setter | |
UUID highestCurrentBidder; | |
private @Getter long startPrice; | |
private @Getter @Setter long currentPrice; | |
private @Getter long lowestPossibleBid; | |
private @Getter | |
ItemStack item; | |
private @Getter float listingDuration; | |
private @Getter boolean expired; | |
public Listing(int listingID, ItemStack item, UUID auctioneer, UUID highestCurrentBidder, long startPrice, long currentPrice, long lowestPossibleBid, float listingDuration, boolean expired) | |
{ | |
this.listingID = listingID; | |
this.auctioneer = auctioneer; | |
this.startPrice = startPrice; | |
this.currentPrice = currentPrice; | |
this.lowestPossibleBid = lowestPossibleBid; | |
this.listingDuration = listingDuration; | |
this.expired = expired; | |
this.item = item; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment