Coded File IO
This commit is contained in:
parent
8421e2799f
commit
8967e39084
12 changed files with 156 additions and 54 deletions
|
@ -4,5 +4,6 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<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/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/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"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
10
plugin.yml
10
plugin.yml
|
@ -1,11 +1,11 @@
|
||||||
main: alisolarflare.MainPlugin
|
main: alisolarflare.AliPresents
|
||||||
name: AliPresents
|
name: AliPresents
|
||||||
version: 1.0.0
|
version: 2.0.0
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
alishulker:
|
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:
|
pressalilink:
|
||||||
description: Presses an Ali Link. /pressalilink |frequency|
|
description: Presses an Ali Link pressalilink frequency
|
||||||
setalilink:
|
setalilink:
|
||||||
description: Creates an Ali Link. /setalilink |frequency|
|
description: Creates an Ali Link setalilink frequency
|
32
src/alisolarflare/AliPresents.java
Normal file
32
src/alisolarflare/AliPresents.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
31
src/alisolarflare/links/AliLinkSubPlug.java
Normal file
31
src/alisolarflare/links/AliLinkSubPlug.java
Normal 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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
34
src/alisolarflare/links/Deserializer.java
Normal file
34
src/alisolarflare/links/Deserializer.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,28 @@
|
||||||
package alisolarflare.links;
|
package alisolarflare.links;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
public class Link {
|
public class Link implements Serializable{
|
||||||
static AliLinkSubPlugin plugin;
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
AliLinkSubPlug subplugin;
|
||||||
String frequency;
|
String frequency;
|
||||||
Location location;
|
Location location;
|
||||||
|
|
||||||
public Link(AliLinkSubPlugin plugin, String frequency, Location location){
|
public Link(AliLinkSubPlug plugin, String frequency, Location location){
|
||||||
this.frequency = frequency;
|
this.frequency = frequency;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
this.subplugin = plugin;
|
||||||
|
plugin.plugin.getConfig().set("frequency", 10);
|
||||||
}
|
}
|
||||||
public void press() {
|
public void press() {
|
||||||
location.getBlock().setType(Material.REDSTONE_BLOCK);
|
location.getBlock().setType(Material.REDSTONE_BLOCK);
|
||||||
UnpressTask unPressTask = new UnpressTask(location);
|
UnpressTask unPressTask = new UnpressTask(location);
|
||||||
unPressTask.runTaskTimer(plugin.plugin, 2, 1);
|
unPressTask.runTaskTimer(subplugin.plugin, 2, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class PressAliLink implements CommandExecutor{
|
public class PressAliLink implements CommandExecutor{
|
||||||
private AliLinkSubPlugin subplugin;
|
private AliLinkSubPlug subplugin;
|
||||||
public PressAliLink(AliLinkSubPlugin subplugin){
|
public PressAliLink(AliLinkSubPlug subplugin){
|
||||||
this.subplugin = subplugin;
|
this.subplugin = subplugin;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
31
src/alisolarflare/links/Serializer.java
Normal file
31
src/alisolarflare/links/Serializer.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,8 +8,8 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class SetAliLink implements CommandExecutor{
|
public class SetAliLink implements CommandExecutor{
|
||||||
AliLinkSubPlugin subplugin;
|
AliLinkSubPlug subplugin;
|
||||||
public SetAliLink(AliLinkSubPlugin plugin){
|
public SetAliLink(AliLinkSubPlug plugin){
|
||||||
this.subplugin = plugin;
|
this.subplugin = plugin;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,11 +22,15 @@ public class SetAliLink implements CommandExecutor{
|
||||||
sender.sendMessage("You must be a player to use this command!");
|
sender.sendMessage("You must be a player to use this command!");
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
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()));
|
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])){
|
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]))));
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ public class UnpressTask extends BukkitRunnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
location.getBlock().setType(Material.STAINED_CLAY);
|
location.getBlock().setType(Material.STAINED_CLAY);
|
||||||
location.getBlock().setData((byte) 14);
|
location.getBlock().setData((byte) 14);
|
||||||
|
this.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue