2011-09-12 01:47:57 -07:00
|
|
|
/*
|
|
|
|
This file is part of mcMMO.
|
|
|
|
|
|
|
|
mcMMO is free software: you can redistribute it and/or modify
|
|
|
|
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.
|
|
|
|
|
|
|
|
mcMMO is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2011-07-16 00:12:26 -07:00
|
|
|
package com.gmail.nossr50;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2011-07-19 07:17:14 -07:00
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2011-08-08 19:25:52 -07:00
|
|
|
import com.gmail.nossr50.command.Commands;
|
2011-07-16 00:12:26 -07:00
|
|
|
import com.gmail.nossr50.config.*;
|
2011-09-12 00:19:15 -07:00
|
|
|
import com.gmail.nossr50.runnables.mcTimer;
|
2011-08-14 01:37:03 -07:00
|
|
|
import com.gmail.nossr50.spout.SpoutStuff;
|
2011-07-16 00:12:26 -07:00
|
|
|
import com.gmail.nossr50.listeners.mcBlockListener;
|
|
|
|
import com.gmail.nossr50.listeners.mcEntityListener;
|
|
|
|
import com.gmail.nossr50.listeners.mcPlayerListener;
|
|
|
|
import com.gmail.nossr50.party.Party;
|
|
|
|
import com.gmail.nossr50.skills.*;
|
|
|
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
|
|
|
|
2011-08-02 18:54:14 -07:00
|
|
|
import org.bukkit.Bukkit;
|
2011-07-21 20:53:16 -04:00
|
|
|
import java.io.BufferedInputStream;
|
2011-07-16 00:12:26 -07:00
|
|
|
import java.io.BufferedReader;
|
2011-07-21 20:53:16 -04:00
|
|
|
import java.io.BufferedWriter;
|
2011-07-16 00:12:26 -07:00
|
|
|
import java.io.File;
|
2011-07-21 20:53:16 -04:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
2011-07-16 00:12:26 -07:00
|
|
|
import java.io.FileReader;
|
2011-07-21 20:53:16 -04:00
|
|
|
import java.io.FileWriter;
|
2011-07-20 10:25:40 -07:00
|
|
|
import java.io.IOException;
|
2011-07-16 00:12:26 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.event.Event.Priority;
|
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-08-28 17:57:19 -07:00
|
|
|
import org.getspout.spoutapi.SpoutManager;
|
|
|
|
import org.getspout.spoutapi.player.FileManager;
|
2011-07-16 00:12:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
public class mcMMO extends JavaPlugin
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* I never expected mcMMO to get so popular!
|
|
|
|
* Thanks for all the support for the mod
|
|
|
|
* Thanks to the people who have worked on the code
|
|
|
|
* Thanks to the donators who helped me out financially
|
|
|
|
* Thanks to the server admins who use my mod :)
|
|
|
|
*
|
|
|
|
* This mod is open source, and its going to stay that way >:3
|
|
|
|
*
|
|
|
|
* Donate via paypal to nossr50@gmail.com (A million thanks to anyone that does!)
|
|
|
|
*/
|
|
|
|
|
2011-07-18 13:35:56 -05:00
|
|
|
public static String maindirectory = "plugins" + File.separator + "mcMMO";
|
2011-07-16 00:12:26 -07:00
|
|
|
File file = new File(maindirectory + File.separator + "config.yml");
|
2011-07-21 20:53:16 -04:00
|
|
|
static File versionFile = new File(maindirectory + File.separator + "VERSION");
|
2011-07-16 00:12:26 -07:00
|
|
|
public static final Logger log = Logger.getLogger("Minecraft");
|
2011-08-03 17:59:34 -07:00
|
|
|
|
2011-07-16 00:12:26 -07:00
|
|
|
private final mcPlayerListener playerListener = new mcPlayerListener(this);
|
|
|
|
private final mcBlockListener blockListener = new mcBlockListener(this);
|
|
|
|
private final mcEntityListener entityListener = new mcEntityListener(this);
|
2011-08-03 17:59:34 -07:00
|
|
|
|
2011-07-17 23:08:28 -04:00
|
|
|
public static mcPermissions permissionHandler = new mcPermissions();
|
2011-07-16 00:12:26 -07:00
|
|
|
private Permissions permissions;
|
|
|
|
|
2011-08-05 19:53:33 -07:00
|
|
|
private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION
|
2011-07-16 00:12:26 -07:00
|
|
|
//private Timer mcMMO_SpellTimer = new Timer(true);
|
|
|
|
|
|
|
|
public static Database database = null;
|
|
|
|
public Misc misc = new Misc(this);
|
|
|
|
|
|
|
|
//Config file stuff
|
|
|
|
LoadProperties config = new LoadProperties();
|
2011-09-02 18:49:13 -07:00
|
|
|
//Jar stuff
|
|
|
|
public static File mcmmo;
|
2011-07-16 00:12:26 -07:00
|
|
|
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2011-09-02 18:49:13 -07:00
|
|
|
mcmmo = this.getFile();
|
2011-07-17 23:08:28 -04:00
|
|
|
new File(maindirectory).mkdir();
|
2011-07-16 00:12:26 -07:00
|
|
|
|
2011-07-23 13:23:38 -07:00
|
|
|
if(!versionFile.exists())
|
|
|
|
{
|
2011-07-21 20:53:16 -04:00
|
|
|
updateVersion();
|
2011-07-23 13:23:38 -07:00
|
|
|
} else
|
|
|
|
{
|
2011-07-21 20:53:16 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:08:28 -04:00
|
|
|
mcPermissions.initialize(getServer());
|
2011-07-23 13:23:38 -07:00
|
|
|
|
2011-07-16 00:12:26 -07:00
|
|
|
config.configCheck();
|
2011-07-23 13:23:38 -07:00
|
|
|
|
Party changes
First player to join a party is the owner.
/party lock (useable by party owner)
/party unlock (useable by party owner)
/party password <password> (useable by party owner, party must be locked)
/party password "" (useable by party owner, party must be locked, disables password)
/party kick <player> (useable by party owner, party must be locked, cannot kick a user with mcmmo.admin without having mcmmo.admin)
/party owner <player> (useable by party owner, transfers ownership)
/party <party> <password> (useable by any, to join a password protected and locked party)
/party ? (extended help)
/invite and /accept work with new system
Parties delete themselves if no members (online and offline) are in the party.
From old versions:
Old parties will give owner to first person to use /party command in it. Users will be "added" into parties as they use /party
Note, all new messages will need a locale/color treatment. I was not sure how to properly do this, so I instead marked all messages with a //TODO
Also included, commented out in code, but can be uncommented to compile+use:
/party dump (dumps everything from the hashtables to chat)
2011-07-22 19:37:54 -04:00
|
|
|
Party.getInstance().loadParties();
|
|
|
|
new Party(this);
|
2011-07-16 00:12:26 -07:00
|
|
|
|
|
|
|
if(!LoadProperties.useMySQL)
|
|
|
|
Users.getInstance().loadUsers(); //Load Users file
|
|
|
|
/*
|
|
|
|
* REGISTER EVENTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
PluginManager pm = getServer().getPluginManager();
|
2011-07-20 14:27:59 -07:00
|
|
|
|
2011-08-02 16:48:55 -07:00
|
|
|
if(pm.getPlugin("Spout") != null)
|
|
|
|
LoadProperties.spoutEnabled = true;
|
2011-07-20 14:27:59 -07:00
|
|
|
else
|
2011-08-02 16:48:55 -07:00
|
|
|
LoadProperties.spoutEnabled = false;
|
2011-07-16 00:12:26 -07:00
|
|
|
|
|
|
|
//Player Stuff
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
|
2011-09-02 18:49:13 -07:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Lowest, this);
|
2011-07-16 00:12:26 -07:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Monitor, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this);
|
2011-07-19 13:57:08 -07:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, playerListener, Priority.Normal, this);
|
2011-11-28 05:17:01 -08:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_FISH, playerListener, Priority.Normal, this);
|
2011-07-16 00:12:26 -07:00
|
|
|
|
|
|
|
//Block Stuff
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_DAMAGE, blockListener, Priority.Highest, this);
|
2011-08-25 16:44:10 -04:00
|
|
|
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Monitor, this);
|
2011-07-16 00:12:26 -07:00
|
|
|
pm.registerEvent(Event.Type.BLOCK_FROMTO, blockListener, Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
|
|
|
|
|
|
|
|
//Entity Stuff
|
|
|
|
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
|
2011-09-05 17:02:11 -07:00
|
|
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Monitor, this);
|
2011-07-16 00:12:26 -07:00
|
|
|
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this);
|
2011-12-02 01:14:18 -08:00
|
|
|
|
|
|
|
PluginDescriptionFile pdfFile = this.getDescription();
|
|
|
|
mcPermissions.initialize(getServer());
|
|
|
|
|
|
|
|
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!" );
|
|
|
|
|
|
|
|
Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, mcMMO_Timer, 0, 20);
|
2011-08-03 17:59:34 -07:00
|
|
|
|
|
|
|
//Spout Stuff
|
|
|
|
if(LoadProperties.spoutEnabled)
|
|
|
|
{
|
2011-08-20 22:58:25 -07:00
|
|
|
SpoutStuff.setupSpoutConfigs();
|
2011-08-08 19:25:52 -07:00
|
|
|
SpoutStuff.registerCustomEvent();
|
2011-09-02 18:49:13 -07:00
|
|
|
SpoutStuff.extractFiles(); //Extract source materials
|
2011-08-28 17:57:19 -07:00
|
|
|
|
|
|
|
FileManager FM = SpoutManager.getFileManager();
|
|
|
|
FM.addToPreLoginCache(this, SpoutStuff.getFiles());
|
|
|
|
|
2011-09-12 03:36:26 -07:00
|
|
|
/*
|
2011-08-28 17:57:19 -07:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this,
|
|
|
|
new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
mmoHelper.updateAll();
|
|
|
|
}
|
|
|
|
}, 20, 20);
|
2011-09-12 03:36:26 -07:00
|
|
|
*/
|
2011-08-03 17:59:34 -07:00
|
|
|
}
|
2011-07-16 00:12:26 -07:00
|
|
|
}
|
|
|
|
|
2011-07-19 07:17:14 -07:00
|
|
|
public PlayerProfile getPlayerProfile(Player player)
|
|
|
|
{
|
|
|
|
return Users.getProfile(player);
|
|
|
|
}
|
|
|
|
|
2011-07-20 10:25:40 -07:00
|
|
|
public void checkXp(Player player, SkillType skillType)
|
|
|
|
{
|
|
|
|
if(skillType == SkillType.ALL)
|
|
|
|
Skills.XpCheckAll(player);
|
|
|
|
else
|
|
|
|
Skills.XpCheckSkill(skillType, player);
|
|
|
|
}
|
|
|
|
|
2011-07-19 07:17:14 -07:00
|
|
|
public boolean inSameParty(Player playera, Player playerb)
|
|
|
|
{
|
2011-07-16 00:12:26 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
public Permissions getPermissions() {
|
|
|
|
return permissions;
|
|
|
|
}
|
|
|
|
public void onDisable() {
|
2011-08-22 18:22:16 -07:00
|
|
|
Bukkit.getServer().getScheduler().cancelTasks(this);
|
2011-07-16 00:12:26 -07:00
|
|
|
System.out.println("mcMMO was disabled.");
|
|
|
|
}
|
|
|
|
|
2011-08-08 19:25:52 -07:00
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
|
|
|
{
|
|
|
|
return Commands.processCommands(sender, command, label, args);
|
2011-07-16 00:12:26 -07:00
|
|
|
}
|
|
|
|
|
2011-07-21 20:53:16 -04: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-03 23:24:08 -07:00
|
|
|
}
|