Coded File IO

This commit is contained in:
alisolarflare 2016-08-21 13:23:59 -04:00
parent 8421e2799f
commit 8967e39084
12 changed files with 156 additions and 54 deletions

View file

@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/Alisolarflare/Personal/Hobbies/The Button Rebirth/Button Plugin/Minecraft Test Server/craftbukkit-1.9.2.jar"/>
<classpathentry kind="lib" path="C:/Users/Alisolarflare/Personal/Hobbies/The Button Rebirth/Button Plugin/Minecraft Test Server/spigot-1.9.2.jar"/>
<classpathentry kind="lib" path="C:/Users/Alisolarflare/Personal/Hobbies/The Button Rebirth/Dependencies/gson-2.7.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -1,11 +1,11 @@
main: alisolarflare.MainPlugin
main: alisolarflare.AliPresents
name: AliPresents
version: 1.0.0
version: 2.0.0
commands:
alishulker:
description: Spawns a shulker at player location. /Alishulker <health> <withereffect> <invisibility=true> <experiencedrops>
description: Spawns a shulker at player location Alishulker health withereffect invisibility true experiencedrops
pressalilink:
description: Presses an Ali Link. /pressalilink |frequency|
description: Presses an Ali Link pressalilink frequency
setalilink:
description: Creates an Ali Link. /setalilink |frequency|
description: Creates an Ali Link setalilink frequency

View file

@ -0,0 +1,32 @@
package alisolarflare;
import java.util.logging.Logger;
import org.bukkit.plugin.PluginDescriptionFile;
import alisolarflare.links.AliLinkSubPlug;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.shulker.AliShulker;
public class AliPresents extends JavaPlugin{
public void onEnable(){
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ").");
registerSubPlugins();
registerCommands();
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");
}
public void registerSubPlugins(){
AliLinkSubPlug alilinksubplugin = new AliLinkSubPlug(this);
alilinksubplugin.register();
}
public void registerCommands(){
getCommand("alishulker").setExecutor(new AliShulker());
}
}

View file

@ -1,20 +0,0 @@
package alisolarflare;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.links.AliLinkSubPlugin;
import alisolarflare.shulker.AliShulker;
public class MainPlugin extends JavaPlugin{
public void onEnable(){
registerSubPlugins();
registerCommands();
}
public void registerSubPlugins(){
AliLinkSubPlugin alilinksubplugin = new AliLinkSubPlugin(this);
alilinksubplugin.register();
}
public void registerCommands(){
getCommand("alishulker").setExecutor(new AliShulker());
}
}

View file

@ -0,0 +1,31 @@
package alisolarflare.links;
import java.util.ArrayList;
import java.util.List;
import alisolarflare.AliPresents;
public class AliLinkSubPlug{
public List<Link> linkList;
public AliPresents plugin;
public Serializer serializer;
public Deserializer deserializer;
public AliLinkSubPlug(AliPresents plugin){
this.plugin = plugin;
this.serializer = new Serializer();
this.deserializer = new Deserializer();
try{
this.linkList = deserializer.loadLinkList();
}catch(Exception e){
linkList = new ArrayList<Link>();
}
}
public void register(){
plugin.getCommand("pressalilink").setExecutor(new PressAliLink(this));
plugin.getCommand("setalilink").setExecutor(new SetAliLink(this));
}
}

View file

@ -1,20 +0,0 @@
package alisolarflare.links;
import java.util.ArrayList;
import java.util.List;
import alisolarflare.MainPlugin;
public class AliLinkSubPlugin{
public List<Link> linkList = new ArrayList<Link>();
public MainPlugin plugin;
public AliLinkSubPlugin(MainPlugin plugin){
this.plugin = plugin;
}
public void register(){
plugin.getCommand("pressalilink").setExecutor(new PressAliLink(this));
plugin.getCommand("setalilink").setExecutor(new SetAliLink(this));
}
}

View file

@ -0,0 +1,34 @@
package alisolarflare.links;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.List;
public class Deserializer{
public static void main (String args[]) {
//Deserializer deserializer = new Deserializer();
//List<Link> aliLink = deserializer.loadLink(aliLink);
//System.out.println(aliLink);
}
@SuppressWarnings("unchecked")
public List<Link> loadLinkList(){
List<Link> aliLinkList;
try{
FileInputStream fin = new FileInputStream("AliLinkList.ser");
ObjectInputStream ois = new ObjectInputStream(fin);
aliLinkList = (List<Link>) ois.readObject();
ois.close();
return aliLinkList;
}catch(Exception ex){
ex.printStackTrace();
return null;
}
}
}

View file

@ -1,20 +1,28 @@
package alisolarflare.links;
import java.io.Serializable;
import org.bukkit.Location;
import org.bukkit.Material;
public class Link {
static AliLinkSubPlugin plugin;
public class Link implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
AliLinkSubPlug subplugin;
String frequency;
Location location;
public Link(AliLinkSubPlugin plugin, String frequency, Location location){
public Link(AliLinkSubPlug plugin, String frequency, Location location){
this.frequency = frequency;
this.location = location;
this.subplugin = plugin;
plugin.plugin.getConfig().set("frequency", 10);
}
public void press() {
location.getBlock().setType(Material.REDSTONE_BLOCK);
UnpressTask unPressTask = new UnpressTask(location);
unPressTask.runTaskTimer(plugin.plugin, 2, 1);
unPressTask.runTaskTimer(subplugin.plugin, 2, 1);
}
}

View file

@ -5,8 +5,8 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class PressAliLink implements CommandExecutor{
private AliLinkSubPlugin subplugin;
public PressAliLink(AliLinkSubPlugin subplugin){
private AliLinkSubPlug subplugin;
public PressAliLink(AliLinkSubPlug subplugin){
this.subplugin = subplugin;
}
@Override

View file

@ -0,0 +1,31 @@
package alisolarflare.links;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.List;
public class Serializer {
public static void main (String args[]) {
//Serializer serializer = new Serializer();
//serializer.saveLink(plugin, frequency, location)
}
public void saveLinkList(List<Link> aliLinkList){
//saves link
try{
FileOutputStream fout = new FileOutputStream("AliLinkList.ser");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(aliLinkList);
oos.close();
System.out.println("Done");
}catch(Exception ex){
ex.printStackTrace();
}
}
}

View file

@ -8,8 +8,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SetAliLink implements CommandExecutor{
AliLinkSubPlugin subplugin;
public SetAliLink(AliLinkSubPlugin plugin){
AliLinkSubPlug subplugin;
public SetAliLink(AliLinkSubPlug plugin){
this.subplugin = plugin;
}
@Override
@ -22,11 +22,15 @@ public class SetAliLink implements CommandExecutor{
sender.sendMessage("You must be a player to use this command!");
}
Player player = (Player) sender;
if (args[1] == null || args[2] == null || args[3] == null){
if (args.length < 4){
subplugin.linkList.add(new Link(subplugin, args[0], player.getLocation()));
return false;
}
if (StringUtils.isNumericSpace(args[1]) && StringUtils.isNumericSpace(args[2]) && StringUtils.isNumericSpace(args[3])){
subplugin.linkList.add(new Link(subplugin, args[0],new Location(player.getWorld(), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]))));
}else{
subplugin.linkList.add(new Link(subplugin, args[0], player.getLocation()));
return false;
}
return false;
}

View file

@ -15,6 +15,7 @@ public class UnpressTask extends BukkitRunnable {
public void run() {
location.getBlock().setType(Material.STAINED_CLAY);
location.getBlock().setData((byte) 14);
this.cancel();
}
}