Turned Links into pure Strings

This commit is contained in:
alisolarflare 2016-09-02 20:22:34 -04:00
parent 1053249962
commit b9c0c59371
13 changed files with 137 additions and 97 deletions

Binary file not shown.

0
config.yml Normal file
View file

View file

@ -6,6 +6,8 @@ import org.bukkit.plugin.PluginDescriptionFile;
import alisolarflare.flairdoors.PortalListener;
import alisolarflare.flairdoors.SetFlairDoorColour;
import alisolarflare.links.AliLinkSubPlug;
//import alisolarflare.links.AliLinkSubPlug;
import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.shulker.AliShulker;
@ -18,7 +20,7 @@ public class AliPresents extends JavaPlugin{
logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ").");
//registerSubPlugins();
registerSubPlugins();
registerCommands();
registerEvents();
@ -31,8 +33,8 @@ public class AliPresents extends JavaPlugin{
}
public void registerSubPlugins(){
//AliLinkSubPlug alilinksubplugin = new AliLinkSubPlug(this);
//alilinksubplugin.register();
AliLinkSubPlug alilinksubplugin = new AliLinkSubPlug(this);
alilinksubplugin.register();
}
public void registerCommands(){
getCommand("alishulker").setExecutor(new AliShulker());

View file

@ -7,6 +7,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.PortalCreateEvent;
@ -22,6 +23,7 @@ public class PortalListener implements Listener{
public PortalListener(AliPresents plugin) {
this.plugin = plugin;
}
@EventHandler
public void onAliRightClick(PlayerInteractEvent event){
if (event.getPlayer().getName() != "alisolarflare"){
@ -33,6 +35,9 @@ public class PortalListener implements Listener{
if(event.getItem().getType() != Material.FLINT_AND_STEEL && event.getItem().getType() != Material.FIREBALL){
return;
}
if(event.getAction() != Action.RIGHT_CLICK_BLOCK){
return;
}
plugin.getServer().broadcastMessage("RIIIIGHTCLICK");
}

View file

@ -1,29 +1,22 @@
package alisolarflare.links;
import java.util.ArrayList;
import java.util.List;
import alisolarflare.AliPresents;
import alisolarflare.links.commands.PressAliLink;
import alisolarflare.links.commands.SetAliLink;
import alisolarflare.links.entities.Link;
public class AliLinkSubPlug{
public List<Link> linkList;
public List<Link> linkList = new ArrayList<Link>();
public AliPresents plugin;
public Serializer serializer;
public Deserializer deserializer;
@SuppressWarnings("unchecked")
public AliLinkSubPlug(AliPresents plugin){
this.plugin = plugin;
this.serializer = new Serializer();
this.deserializer = new Deserializer();
try{
this.linkList = deserializer.loadLinkList();
if(this.linkList == null){
this.linkList = new ArrayList<Link>();
serializer.saveLinkList(this.linkList);
}
}catch(Exception e){
linkList = (List<Link>) plugin.getConfig().getList("aliLinkList");
if(linkList == null || linkList.isEmpty()){
linkList = new ArrayList<Link>();
serializer.saveLinkList(this.linkList);
}
}

View file

@ -1,33 +0,0 @@
package alisolarflare.links;
import java.io.Serializable;
import org.bukkit.Location;
import org.bukkit.Material;
public class Link implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
AliLinkSubPlug subplugin;
String frequency;
String world;
Location location;
int x;
int y;
int z;
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(subplugin.plugin, 2, 1);
}
}

View file

@ -1,41 +0,0 @@
package alisolarflare.links;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SetAliLink implements CommandExecutor{
AliLinkSubPlug subplugin;
public SetAliLink(AliLinkSubPlug plugin){
this.subplugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args == null){
sender.sendMessage("You must specify a link frequency");
sender.sendMessage("/pressalilink [name]");
}
if (!(sender instanceof Player)){
sender.sendMessage("You must be a player to use this command!");
}
Player player = (Player) sender;
if (args.length < 4){
subplugin.linkList.add(new Link(subplugin, args[0], player.getLocation()));
subplugin.serializer.saveLinkList(subplugin.linkList);
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]))));
subplugin.serializer.saveLinkList(subplugin.linkList);
}else{
subplugin.linkList.add(new Link(subplugin, args[0], player.getLocation()));
subplugin.serializer.saveLinkList(subplugin.linkList);
return false;
}
return false;
}
}

View file

@ -1,9 +1,12 @@
package alisolarflare.links;
package alisolarflare.links.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import alisolarflare.links.AliLinkSubPlug;
import alisolarflare.links.entities.Link;
public class PressAliLink implements CommandExecutor{
private AliLinkSubPlug subplugin;
public PressAliLink(AliLinkSubPlug subplugin){
@ -11,14 +14,17 @@ public class PressAliLink implements CommandExecutor{
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args == null){
subplugin.plugin.getServer().broadcastMessage(subplugin.linkList.toString() + "over.");
if (args.length < 1){
sender.sendMessage("You must specify a link frequency");
sender.sendMessage("/pressalilink [frequency]");
}
for (Link link: subplugin.linkList){
for (String inputlink: args){
if(inputlink.equals(link.frequency)){
link.press();
link.press(subplugin);
}
}
}

View file

@ -0,0 +1,67 @@
package alisolarflare.links.commands;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.links.AliLinkSubPlug;
import alisolarflare.links.entities.Link;
public class SetAliLink implements CommandExecutor{
AliLinkSubPlug subplugin;
public SetAliLink(AliLinkSubPlug plugin){
this.subplugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage("you pressed shit");
if (args == null || args.length < 1){
sender.sendMessage("You must specify a link frequency");
sender.sendMessage("/pressalilink [name]");
return false;
}
if (!(sender instanceof Player)){
sender.sendMessage("You must be a player to use this command!");
}
Player player = (Player) sender;
if (args.length < 4){
player.sendMessage("short");
subplugin.linkList.add(new Link(args[0], player.getLocation()));
save(player);
player.sendMessage("end");
return false;
}
if (StringUtils.isNumericSpace(args[1]) && StringUtils.isNumericSpace(args[2]) && StringUtils.isNumericSpace(args[3])){
player.sendMessage("CUUUSTOM");
subplugin.linkList.add(new Link(args[0],new Location(player.getWorld(), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]))));
save(player);
player.sendMessage("FINISHED");
}else{
player.sendMessage("UNCUSTOOM");
subplugin.linkList.add(new Link(args[0], player.getLocation()));
save(player);
player.sendMessage("UNFINISHED");
return false;
}
return false;
}
private void save(Player player){
player.sendMessage("SAAAVING");
subplugin.plugin.getConfig().set("aliLinkList", subplugin.linkList);
try {
player.sendMessage("SAVIN");
subplugin.plugin.getConfig().save("aliLinkList");
player.sendMessage("GOOD SAVE");
} catch (IOException e) {
player.sendMessage("YOU FUCKED STUFF UP");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,37 @@
package alisolarflare.links.entities;
import java.io.Serializable;
import org.bukkit.Location;
import org.bukkit.Material;
import alisolarflare.links.AliLinkSubPlug;
import alisolarflare.links.tasks.UnpressTask;
public class Link implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public String frequency;
String world;
String x;
String y;
String z;
public Link(String frequency, Location location){
this.frequency = frequency;
this.world = location.getWorld().getName();
this.x = "" + location.getBlockX();
this.y = "" + location.getBlockY();
this.z = "" + location.getBlockZ();
//plugin.plugin.getConfig().set("frequency", 10);
}
public void press(AliLinkSubPlug plugin) {
Location location = new Location(plugin.plugin.getServer().getWorld(world), Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z));
location.getBlock().setType(Material.REDSTONE_BLOCK);
UnpressTask unPressTask = new UnpressTask(location);
unPressTask.runTaskTimer(plugin.plugin, 2, 1);
}
}

View file

@ -1,10 +1,12 @@
package alisolarflare.links;
package alisolarflare.links.serializer;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.List;
import alisolarflare.links.entities.Link;
public class Deserializer{
public static void main (String args[]) {

View file

@ -1,10 +1,12 @@
package alisolarflare.links;
package alisolarflare.links.serializer;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import alisolarflare.links.entities.Link;
public class Serializer {
public static void main (String args[]) {

View file

@ -1,4 +1,4 @@
package alisolarflare.links;
package alisolarflare.links.tasks;
import org.bukkit.Location;
import org.bukkit.Material;