2012-01-09 20:00:13 +01:00
|
|
|
/*
|
2012-02-10 12:05:09 +01:00
|
|
|
Copyright (C) 2012 Matt 'The Yeti' Burnett & mcMMO Development
|
|
|
|
Copyright (C) 2010-2011 'nossr50'
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-02-10 12:05:09 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
2012-01-09 20:00:13 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2012-02-10 12:05:09 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
2012-01-09 20:00:13 +01:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2012-02-10 12:05:09 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-01-09 20:00:13 +01:00
|
|
|
*/
|
|
|
|
package com.gmail.nossr50;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
|
|
|
import com.gmail.nossr50.commands.skills.*;
|
|
|
|
import com.gmail.nossr50.commands.spout.*;
|
|
|
|
import com.gmail.nossr50.commands.mc.*;
|
|
|
|
import com.gmail.nossr50.commands.party.*;
|
|
|
|
import com.gmail.nossr50.commands.general.*;
|
|
|
|
import com.gmail.nossr50.config.*;
|
2012-01-30 16:09:45 +01:00
|
|
|
import com.gmail.nossr50.runnables.*;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutStuff;
|
|
|
|
import com.gmail.nossr50.listeners.mcBlockListener;
|
|
|
|
import com.gmail.nossr50.listeners.mcEntityListener;
|
|
|
|
import com.gmail.nossr50.listeners.mcPlayerListener;
|
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
|
|
|
import com.gmail.nossr50.party.Party;
|
|
|
|
import com.gmail.nossr50.skills.*;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2012-01-30 16:09:45 +01:00
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
2012-01-30 16:09:45 +01:00
|
|
|
import java.util.ArrayDeque;
|
2012-01-09 20:00:13 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2012-02-11 21:12:50 +01:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
2012-01-30 16:09:45 +01:00
|
|
|
import org.bukkit.block.Block;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.getspout.spoutapi.SpoutManager;
|
|
|
|
import org.getspout.spoutapi.player.FileManager;
|
|
|
|
|
|
|
|
|
|
|
|
public class mcMMO extends JavaPlugin
|
|
|
|
{
|
|
|
|
|
|
|
|
public static String maindirectory = "plugins" + File.separator + "mcMMO";
|
|
|
|
File file = new File(maindirectory + File.separator + "config.yml");
|
|
|
|
static File versionFile = new File(maindirectory + File.separator + "VERSION");
|
|
|
|
public static final Logger log = Logger.getLogger("Minecraft");
|
|
|
|
|
|
|
|
private final mcPlayerListener playerListener = new mcPlayerListener(this);
|
|
|
|
private final mcBlockListener blockListener = new mcBlockListener(this);
|
|
|
|
private final mcEntityListener entityListener = new mcEntityListener(this);
|
2012-02-17 05:37:14 +01:00
|
|
|
|
|
|
|
//Queue for block data change for R2+ fix
|
|
|
|
public ArrayDeque<Block> changeQueue = new ArrayDeque<Block>();
|
|
|
|
public ArrayDeque<Block> fastChangeQueue = new ArrayDeque<Block>();
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION
|
2012-02-09 12:11:18 +01:00
|
|
|
private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data
|
2012-02-17 05:37:14 +01:00
|
|
|
private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(changeQueue); //R2 block place workaround
|
|
|
|
private Runnable FastChangeDataValueTimer = new ChangeDataValueTimer(fastChangeQueue);
|
2012-01-09 20:00:13 +01:00
|
|
|
//private Timer mcMMO_SpellTimer = new Timer(true);
|
|
|
|
|
|
|
|
//Alias - Command
|
|
|
|
public HashMap<String, String> aliasMap = new HashMap<String, String>();
|
|
|
|
|
|
|
|
public static Database database = null;
|
|
|
|
public Misc misc = new Misc(this);
|
|
|
|
|
|
|
|
//Config file stuff
|
2012-01-31 08:59:46 +01:00
|
|
|
LoadProperties config;
|
2012-01-09 20:00:13 +01:00
|
|
|
//Jar stuff
|
|
|
|
public static File mcmmo;
|
|
|
|
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2012-02-11 21:12:50 +01:00
|
|
|
final Plugin thisPlugin = this;
|
2012-01-09 20:00:13 +01:00
|
|
|
mcmmo = this.getFile();
|
|
|
|
new File(maindirectory).mkdir();
|
|
|
|
|
|
|
|
if(!versionFile.exists())
|
|
|
|
{
|
|
|
|
updateVersion();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
String vnum = readVersion();
|
|
|
|
//This will be changed to whatever version preceded when we actually need updater code.
|
|
|
|
//Version 1.0.48 is the first to implement this, no checking before that version can be done.
|
|
|
|
if(vnum.equalsIgnoreCase("1.0.48")) {
|
|
|
|
updateFrom(1);
|
|
|
|
}
|
|
|
|
//Just add in more else if blocks for versions that need updater code. Increment the updateFrom age int as we do so.
|
|
|
|
//Catch all for versions not matching and no specific code being needed
|
|
|
|
else if(!vnum.equalsIgnoreCase(this.getDescription().getVersion())) updateFrom(-1);
|
|
|
|
}
|
|
|
|
|
2012-01-31 08:59:46 +01:00
|
|
|
this.config = new LoadProperties(this);
|
|
|
|
this.config.load();
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
Party.getInstance().loadParties();
|
|
|
|
new Party(this);
|
|
|
|
|
|
|
|
if(!LoadProperties.useMySQL)
|
|
|
|
Users.getInstance().loadUsers(); //Load Users file
|
|
|
|
/*
|
|
|
|
* REGISTER EVENTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
PluginManager pm = getServer().getPluginManager();
|
2012-02-05 07:57:43 +01:00
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
if(pm.getPlugin("Spout") != null)
|
|
|
|
LoadProperties.spoutEnabled = true;
|
|
|
|
else
|
|
|
|
LoadProperties.spoutEnabled = false;
|
2012-01-27 00:42:46 +01:00
|
|
|
|
|
|
|
//Register events
|
|
|
|
pm.registerEvents(playerListener, this);
|
|
|
|
pm.registerEvents(blockListener, this);
|
|
|
|
pm.registerEvents(entityListener, this);
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
PluginDescriptionFile pdfFile = this.getDescription();
|
|
|
|
|
|
|
|
if(LoadProperties.useMySQL)
|
|
|
|
{
|
|
|
|
database = new Database(this);
|
|
|
|
database.createStructure();
|
|
|
|
} else
|
|
|
|
Leaderboard.makeLeaderboards(); //Make the leaderboards
|
|
|
|
|
|
|
|
for(Player player : getServer().getOnlinePlayers()){Users.addUser(player);} //In case of reload add all users back into PlayerProfile
|
|
|
|
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
|
|
|
|
|
2012-02-09 12:11:18 +01:00
|
|
|
//Periodic save timer (Saves every 10 minutes)
|
2012-02-09 17:26:57 +01:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_SaveTimer, 0, LoadProperties.saveInterval * 1200);
|
2012-02-09 12:11:18 +01:00
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20);
|
2012-01-30 16:47:01 +01:00
|
|
|
//R2+ block place fix
|
2012-01-30 16:09:45 +01:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10);
|
2012-02-17 05:37:14 +01:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, FastChangeDataValueTimer, 0, 1);
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
registerCommands();
|
|
|
|
|
|
|
|
//Spout Stuff
|
|
|
|
if(LoadProperties.spoutEnabled)
|
|
|
|
{
|
|
|
|
SpoutStuff.setupSpoutConfigs();
|
|
|
|
SpoutStuff.registerCustomEvent();
|
|
|
|
SpoutStuff.extractFiles(); //Extract source materials
|
|
|
|
|
|
|
|
FileManager FM = SpoutManager.getFileManager();
|
|
|
|
FM.addToPreLoginCache(this, SpoutStuff.getFiles());
|
|
|
|
}
|
2012-02-11 21:12:50 +01:00
|
|
|
|
2012-02-11 22:11:04 +01:00
|
|
|
if(LoadProperties.statsTracking) {
|
|
|
|
//Plugin Metrics running in a new thread
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
// create a new metrics object
|
|
|
|
Metrics metrics = new Metrics();
|
|
|
|
|
|
|
|
// 'this' in this context is the Plugin object
|
|
|
|
metrics.beginMeasuringPlugin(thisPlugin);
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Failed to submit the stats :-(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerProfile getPlayerProfile(Player player)
|
|
|
|
{
|
|
|
|
return Users.getProfile(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void checkXp(Player player, SkillType skillType)
|
|
|
|
{
|
|
|
|
if(skillType == SkillType.ALL)
|
|
|
|
Skills.XpCheckAll(player);
|
|
|
|
else
|
|
|
|
Skills.XpCheckSkill(skillType, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean inSameParty(Player playera, Player playerb)
|
|
|
|
{
|
|
|
|
if(Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()){
|
|
|
|
if(Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())){
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public ArrayList<String> getParties(){
|
|
|
|
String location = "plugins/mcMMO/mcmmo.users";
|
|
|
|
ArrayList<String> parties = new ArrayList<String>();
|
|
|
|
try {
|
|
|
|
//Open the users file
|
|
|
|
FileReader file = new FileReader(location);
|
|
|
|
BufferedReader in = new BufferedReader(file);
|
|
|
|
String line = "";
|
|
|
|
while((line = in.readLine()) != null)
|
|
|
|
{
|
|
|
|
String[] character = line.split(":");
|
|
|
|
String theparty = null;
|
|
|
|
//Party
|
|
|
|
if(character.length > 3)
|
|
|
|
theparty = character[3];
|
|
|
|
if(!parties.contains(theparty))
|
|
|
|
parties.add(theparty);
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.log(Level.SEVERE, "Exception while reading "
|
|
|
|
+ location + " (Are you sure you formatted it correctly?)", e);
|
|
|
|
}
|
|
|
|
return parties;
|
|
|
|
}
|
|
|
|
public static String getPartyName(Player player){
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
return PP.getParty();
|
|
|
|
}
|
|
|
|
public static boolean inParty(Player player){
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
return PP.inParty();
|
|
|
|
}
|
2012-02-06 19:48:02 +01:00
|
|
|
|
2012-02-11 19:21:36 +01:00
|
|
|
public void onDisable()
|
|
|
|
{
|
|
|
|
//Make sure to save player information if the server shuts down
|
|
|
|
for(Player x : Bukkit.getServer().getOnlinePlayers())
|
|
|
|
{
|
|
|
|
Users.getProfile(x).save();
|
|
|
|
}
|
|
|
|
|
|
|
|
Bukkit.getServer().getScheduler().cancelTasks(this); //This removes our tasks
|
|
|
|
|
|
|
|
System.out.println("mcMMO was disabled."); //How informative!
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void registerCommands() {
|
|
|
|
//Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands)
|
|
|
|
//Skills commands
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillAcrobatics").toLowerCase(), "acrobatics");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillArchery").toLowerCase(), "archery");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillAxes").toLowerCase(), "axes");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillExcavation").toLowerCase(), "excavation");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillFishing").toLowerCase(), "fishing");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillHerbalism").toLowerCase(), "herbalism");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillMining").toLowerCase(), "mining");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillRepair").toLowerCase(), "repair");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillSwords").toLowerCase(), "swords");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillTaming").toLowerCase(), "taming");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillUnarmed").toLowerCase(), "unarmed");
|
|
|
|
aliasMap.put(mcLocale.getString("m.SkillWoodCutting").toLowerCase(), "woodcutting");
|
|
|
|
|
|
|
|
|
|
|
|
//Register commands
|
|
|
|
//Skills commands
|
|
|
|
getCommand("acrobatics").setExecutor(new AcrobaticsCommand());
|
|
|
|
getCommand("archery").setExecutor(new ArcheryCommand());
|
|
|
|
getCommand("axes").setExecutor(new AxesCommand());
|
|
|
|
getCommand("excavation").setExecutor(new ExcavationCommand());
|
|
|
|
getCommand("fishing").setExecutor(new FishingCommand());
|
|
|
|
getCommand("herbalism").setExecutor(new HerbalismCommand());
|
|
|
|
getCommand("mining").setExecutor(new MiningCommand());
|
|
|
|
getCommand("repair").setExecutor(new RepairCommand());
|
|
|
|
getCommand("swords").setExecutor(new SwordsCommand());
|
|
|
|
getCommand("taming").setExecutor(new TamingCommand());
|
|
|
|
getCommand("unarmed").setExecutor(new UnarmedCommand());
|
|
|
|
getCommand("woodcutting").setExecutor(new WoodcuttingCommand());
|
|
|
|
|
|
|
|
//Mc* commands
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.mcabilityEnable) getCommand("mcability").setExecutor(new McabilityCommand());
|
|
|
|
if(LoadProperties.mccEnable) getCommand("mcc").setExecutor(new MccCommand());
|
|
|
|
if(LoadProperties.mcgodEnable) getCommand("mcgod").setExecutor(new McgodCommand());
|
|
|
|
if(LoadProperties.mcmmoEnable) getCommand("mcmmo").setExecutor(new McmmoCommand());
|
|
|
|
if(LoadProperties.mcrefreshEnable) getCommand("mcrefresh").setExecutor(new McrefreshCommand(this));
|
|
|
|
if(LoadProperties.mctopEnable) getCommand("mctop").setExecutor(new MctopCommand());
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
//Party commands
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.acceptEnable) getCommand("accept").setExecutor(new AcceptCommand());
|
2012-02-02 06:24:07 +01:00
|
|
|
if(LoadProperties.aEnable) getCommand("a").setExecutor(new ACommand());
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.inviteEnable) getCommand("invite").setExecutor(new InviteCommand(this));
|
|
|
|
if(LoadProperties.partyEnable) getCommand("party").setExecutor(new PartyCommand());
|
2012-02-02 06:24:07 +01:00
|
|
|
if(LoadProperties.pEnable) getCommand("p").setExecutor(new PCommand());
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.ptpEnable) getCommand("ptp").setExecutor(new PtpCommand(this));
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
//Other commands
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.addxpEnable) getCommand("addxp").setExecutor(new AddxpCommand(this));
|
2012-02-25 03:05:01 +01:00
|
|
|
if(LoadProperties.addlevelsEnable) getCommand("addlevels").setExecutor(new AddlevelsCommand(this));
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.clearmyspawnEnable) getCommand("clearmyspawn").setExecutor(new ClearmyspawnCommand());
|
|
|
|
if(LoadProperties.mmoeditEnable) getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
|
2012-01-09 20:00:13 +01:00
|
|
|
getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.myspawnEnable) getCommand("myspawn").setExecutor(new MyspawnCommand());
|
2012-02-22 16:27:16 +01:00
|
|
|
if(LoadProperties.mcstatsEnable) getCommand("mcstats").setExecutor(new McstatsCommand(this));
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.whoisEnable) getCommand("whois").setExecutor(new WhoisCommand(this));
|
|
|
|
if(LoadProperties.xprateEnable) getCommand("xprate").setExecutor(new XprateCommand());
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
//Spout commands
|
|
|
|
getCommand("mchud").setExecutor(new MchudCommand());
|
2012-01-31 10:10:39 +01:00
|
|
|
if(LoadProperties.xplockEnable) getCommand("xplock").setExecutor(new XplockCommand());
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is important to always assume that you are updating from the lowest possible version.
|
|
|
|
* Thus, every block of updater code should be complete and self-contained; finishing all
|
|
|
|
* SQL transactions and closing all file handlers, such that the next block of updater code
|
|
|
|
* if called will handle updating as expected.
|
|
|
|
*/
|
|
|
|
public void updateFrom(int age) {
|
|
|
|
//No updater code needed, just update the version.
|
|
|
|
if(age == -1) {
|
|
|
|
updateVersion();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//Updater code from age 1 goes here
|
|
|
|
if(age <= 1) {
|
|
|
|
//Since age 1 is an example for now, we will just let it do nothing.
|
|
|
|
|
|
|
|
}
|
|
|
|
//If we are updating from age 1 but we need more to reach age 2, this will run too.
|
|
|
|
if(age <= 2) {
|
|
|
|
|
|
|
|
}
|
|
|
|
updateVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateVersion() {
|
|
|
|
try {
|
|
|
|
versionFile.createNewFile();
|
|
|
|
BufferedWriter vout = new BufferedWriter(new FileWriter(versionFile));
|
|
|
|
vout.write(this.getDescription().getVersion());
|
|
|
|
vout.close();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch (SecurityException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String readVersion() {
|
|
|
|
byte[] buffer = new byte[(int) versionFile.length()];
|
|
|
|
BufferedInputStream f = null;
|
|
|
|
try {
|
|
|
|
f = new BufferedInputStream(new FileInputStream(versionFile));
|
|
|
|
f.read(buffer);
|
|
|
|
} catch (FileNotFoundException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
if (f != null) try { f.close(); } catch (IOException ignored) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
return new String(buffer);
|
|
|
|
}
|
2011-05-04 08:24:08 +02:00
|
|
|
}
|