Change the way we hook to Jobs.

This commit is contained in:
cnaude 2015-03-09 16:56:17 -07:00
parent 3fea73a9ac
commit 9c5e2a2ab9
5 changed files with 41 additions and 129 deletions

View File

@ -133,13 +133,13 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8</version>
<version>1.8.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot</artifactId>
<version>1.8</version>
<version>1.8.3</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -186,12 +186,6 @@
<version>5.6.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.cnaude.mineversechat</groupId>
<artifactId>MineverseChat</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.cnaude.jobs</groupId>
<artifactId>Jobs</artifactId>
@ -362,7 +356,7 @@
<properties>
<build.number>SNAPSHOT</build.number>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.8</bukkit.version>
<bukkit.version>1.8.3</bukkit.version>
</properties>
</project>

View File

@ -18,9 +18,6 @@ package com.cnaude.purpleirc.Hooks;
import com.cnaude.purpleirc.TemplateName;
import com.cnaude.purpleirc.PurpleIRC;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.PlayerManager;
import com.gamingmesh.jobs.container.Job;
import com.google.common.base.Joiner;
import java.util.ArrayList;
import org.bukkit.entity.Player;
@ -32,7 +29,6 @@ import org.bukkit.entity.Player;
public class JobsHook {
private final PurpleIRC plugin;
private PlayerManager playerManager = null;
/**
*
@ -40,21 +36,20 @@ public class JobsHook {
*/
public JobsHook(PurpleIRC plugin) {
this.plugin = plugin;
try {
this.playerManager = Jobs.getPlayerManager();
} catch (Exception ex) {
plugin.logError("Jobs: " + ex.getMessage());
}
}
public String getPlayerJob(Player player, boolean shortName) {
if (player != null) {
try {
if (plugin.isPluginEnabled("Jobs")) {
ArrayList<String> j = new ArrayList<>();
String m = plugin.getServer().getPluginManager().getPlugin("Jobs").getDescription().getMain();
if (m.contains("me.zford")) {
me.zford.jobs.PlayerManager playerManager = me.zford.jobs.Jobs.getPlayerManager();
if (playerManager == null) {
return "";
}
if (player != null) {
ArrayList<String> j = new ArrayList<>();
if (plugin.isPluginEnabled("Jobs")) {
for (Job job : Jobs.getJobs()) {
for (me.zford.jobs.container.Job job : me.zford.jobs.Jobs.getJobs()) {
if (playerManager.getJobsPlayer(player).isInJob(job)) {
if (shortName) {
j.add(job.getShortName());
@ -63,10 +58,28 @@ public class JobsHook {
}
}
}
} else if (m.contains("com.gamingmesh")) {
com.gamingmesh.jobs.PlayerManager playerManager = com.gamingmesh.jobs.Jobs.getPlayerManager();
if (playerManager == null) {
return "";
}
for (com.gamingmesh.jobs.container.Job job : com.gamingmesh.jobs.Jobs.getJobs()) {
if (playerManager.getJobsPlayer(player).isInJob(job)) {
if (shortName) {
j.add(job.getShortName());
} else {
j.add(job.getName());
}
}
}
}
if (!j.isEmpty()) {
return Joiner.on(plugin.getMsgTemplate(TemplateName.JOBS_SEPARATOR)).join(j);
}
}
} catch (Exception ex) {
plugin.logError("getPlayerJob: " + ex.getMessage());
}
}
return "";
}

View File

@ -1,73 +0,0 @@
/*
* Copyright (C) 2014 cnaude
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc.Hooks;
import com.cnaude.purpleirc.TemplateName;
import com.cnaude.purpleirc.PurpleIRC;
import com.google.common.base.Joiner;
import java.util.ArrayList;
import me.zford.jobs.Jobs;
import me.zford.jobs.PlayerManager;
import me.zford.jobs.container.Job;
import org.bukkit.entity.Player;
/**
*
* @author cnaude
*/
public class JobsHookOld {
private final PurpleIRC plugin;
private PlayerManager playerManager = null;
/**
*
* @param plugin
*/
public JobsHookOld(PurpleIRC plugin) {
this.plugin = plugin;
try {
this.playerManager = Jobs.getPlayerManager();
} catch (Exception ex) {
plugin.logError("Jobs: " + ex.getMessage());
}
}
public String getPlayerJob(Player player, boolean shortName) {
if (playerManager == null) {
return "";
}
if (player != null) {
ArrayList<String> j = new ArrayList<>();
if (plugin.isPluginEnabled("Jobs")) {
for (Job job : Jobs.getJobs()) {
if (playerManager.getJobsPlayer(player).isInJob(job)) {
if (shortName) {
j.add(job.getShortName());
} else {
j.add(job.getName());
}
}
}
if (!j.isEmpty()) {
return Joiner.on(plugin.getMsgTemplate(TemplateName.JOBS_SEPARATOR)).join(j);
}
}
}
return "";
}
}

View File

@ -44,7 +44,6 @@ import com.cnaude.purpleirc.Hooks.CommandBookHook;
import com.cnaude.purpleirc.Hooks.DynmapHook;
import com.cnaude.purpleirc.Hooks.FactionChatHook;
import com.cnaude.purpleirc.Hooks.JobsHook;
import com.cnaude.purpleirc.Hooks.JobsHookOld;
import com.cnaude.purpleirc.Hooks.ReportRTSHook;
import com.cnaude.purpleirc.Hooks.ShortifyHook;
import com.cnaude.purpleirc.Hooks.SuperVanishHook;
@ -169,7 +168,6 @@ public class PurpleIRC extends JavaPlugin {
public TownyChatHook tcHook;
public DynmapHook dynmapHook;
public JobsHook jobsHook;
public JobsHookOld jobsHookOld;
public AdminPrivateChatHook adminPrivateChatHook;
public ShortifyHook shortifyHook;
public ReportRTSHook reportRTSHook;
@ -329,17 +327,8 @@ public class PurpleIRC extends JavaPlugin {
logInfo("CommandBook not detected.");
}
if (isPluginEnabled("Jobs")) {
String m = getServer().getPluginManager().getPlugin("Jobs").getDescription().getMain();
String jobsVersion = getServer().getPluginManager().getPlugin("Jobs").getDescription().getVersion();
if (m.contains("me.zford")) {
logInfo("Enabling legacy Jobs support: " + jobsVersion);
jobsHookOld = new JobsHookOld(this);
} else if (m.contains("com.gamingmesh")) {
logInfo("Enabling new Jobs support: " + jobsVersion);
logInfo("Enabling new Jobs support.");
jobsHook = new JobsHook(this);
} else {
logError("Unable to hook into Jobs: " + m);
}
} else {
logInfo("Jobs not detected.");
}

View File

@ -596,10 +596,6 @@ public class ChatTokenizer {
job = plugin.jobsHook.getPlayerJob(player, false);
jobShort = plugin.jobsHook.getPlayerJob(player, true);
}
if (plugin.jobsHookOld != null) {
job = plugin.jobsHookOld.getPlayerJob(player, false);
jobShort = plugin.jobsHookOld.getPlayerJob(player, true);
}
plugin.logDebug("[P]Raw message: " + message);
return message.replace("%DISPLAYNAME%", displayName)
.replace("%JOBS%", job)
@ -670,13 +666,6 @@ public class ChatTokenizer {
jobShort = plugin.jobsHook.getPlayerJob(player, true);
}
}
plugin.logDebug("playerTokenizer: 15 ");
if (player != null) {
if (plugin.jobsHookOld != null) {
job = plugin.jobsHookOld.getPlayerJob(player, false);
jobShort = plugin.jobsHookOld.getPlayerJob(player, true);
}
}
plugin.logDebug("[S]Raw message: " + message);
return message.replace("%DISPLAYNAME%", displayName)
.replace("%JOBS%", job)