1

-=-Code problem-=-

Nebzei's Avatar Nebzei9/1/14 6:55 pm
1 emeralds 185 6
9/1/2014 7:38 pm
Nebzei's Avatar Nebzei
package me.thewisepotato.Broadcast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.logging.Logger;
import java.io.FileReader;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

public class Broadcast extends JavaPlugin {
public static Broadcast plugin;
public final Logger logger = Logger.getLogger("Minecraft");
public static int currentLine = 0;
public static int tid = 0;
public static int running = 1;
public static long interval = 20;

@Override
public void onDisable() {
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now disabled.");

}
@Override
public void onEnable() {
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled."); {

tid = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
try {
broadcastMessage("plugins/Broadcast/messages.txt");
} catch (IOException e) {

}

}
}, 0, interval * 20);
}

}

public static void broadcastMessage(String fileName) throws IOException {
FileInputStream fs;
fs = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fs));
for(int i = 0; i < currentLine; ++i)
br.readLine();
String line = br.readLine();
line = line.replaceAll("&f", ChatColor.DARK_AQUA + "");
line = line.replaceAll("&e", ChatColor.GREEN + "");
line = line.replaceAll("&d", ChatColor.YELLOW + "");
line = line.replaceAll("&a", ChatColor.LIGHT_PURPLE + "");

Bukkit.getServer().broadcastMessage(ChatColor.LIGHT_PURPLE + "[Jinx]" + ChatColor.WHITE + line);
LineNumberReader lnr = new LineNumberReader(new FileReader(new File(fileName)));
lnr.skip(Long.MAX_VALUE);
int lastLine = lnr.getLineNumber();
if(currentLine + 1 == lastLine + 1) {
currentLine = 0;
}else{
currentLine++;
}
}

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if(commandLabel.equalsIgnoreCase("djinx")) {
if(running == 1) {
Bukkit.getServer().getScheduler().cancelTask(tid);
Player player = (Player) sender;
player.sendMessage("Successfully turned Jinx off!");
running = 0;
} else {
Player player = (Player) sender;
player.sendMessage("Jinx is already off!");
}
} else if (commandLabel.equalsIgnoreCase("ejinx")) {
if(running == 1) {
Player player = (Player) sender;
player.sendMessage("Jinx is already on!");
} else {
tid = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
try {
broadcastMessage("plugins/Broadcast/messages.txt");
} catch (IOException e) {

}

}
}, 0, interval * 20);
Player player = (Player) sender;
player.sendMessage("Successfully turned Jinx on!");
running = 1;
}
}
{
} return false;


}

}







-/++++++++++++++++++++++++++++++++\-
Console perspective.
-/++++++++++++++++++++++++++++++++\-

-/++++++++++++++++++++++++++++++++\-
Eclipse Perspective, (Seems There Is Nothing Wrong).
-/++++++++++++++++++++++++++++++++\-

-/++++++++++++++++++++++++++++++++\-
Plugin.yml File
-/++++++++++++++++++++++++++++++++\-
P.S : Problem Is, It's Not Finding The Plugin.yml, Even though I exported it all together.
-/++++++++++++++++++++++++++++++++\-
Posted by Nebzei's Avatar
Nebzei
Level 31 : Artisan Modder
12

Create an account or sign in to comment.

6

info Note: You're viewing a single reply. View all replies
1
09/01/2014 7:38 pm
Level 31 : Artisan Modder
Nebzei
Nebzei's Avatar
SearchndstroyMay I point out that the broadcastMessage method is inefficient.

Z645Move the plugin.yml up a directory and try again. Instead of it being in the me.thewisepotato.Broadcast package.


And this ^


Actually? I never knew that. Add me on skype, Maybe you could show me some things.
(tripplex101) Know this, I started learning 2 days ago

Problem Resolved Z645. I tried that before but it didn't work, Thanks so much!
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome