Skip to content

Commit

Permalink
McMMO 2.1.2 support with backwards compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zrips committed Jan 30, 2019
1 parent 1f1b9ee commit af4d6ce
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
10 changes: 5 additions & 5 deletions .classpath
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_161"/>
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_161"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,2 +1,3 @@
/bin/
/target/
/bin/
/target/
/pom.xml
Binary file removed libs/mcMMO.jar
Binary file not shown.
Binary file added libs/mcMMO2.1.2.jar
Binary file not shown.
46 changes: 24 additions & 22 deletions src/main/java/com/gamingmesh/jobs/listeners/McMMOlistener.java
@@ -1,6 +1,7 @@
package com.gamingmesh.jobs.listeners;

import java.util.HashMap;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
Expand All @@ -15,7 +16,6 @@
import com.gamingmesh.jobs.actions.ItemActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
Expand All @@ -25,7 +25,7 @@ public class McMMOlistener implements Listener {
private Jobs plugin;
public boolean mcMMOPresent = false;

HashMap<String, HashMap<AbilityType, Long>> map = new HashMap<>();
HashMap<UUID, HashMap<String, Long>> map = new HashMap<>();

public McMMOlistener(Jobs plugin) {
this.plugin = plugin;
Expand Down Expand Up @@ -63,20 +63,21 @@ public void OnItemrepair(McMMOPlayerRepairCheckEvent event) {

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void OnAbilityOn(McMMOPlayerAbilityActivateEvent event) {
HashMap<AbilityType, Long> InfoMap = new HashMap<>();
if (map.containsKey(event.getPlayer().getName()))
InfoMap = map.get(event.getPlayer().getName());
InfoMap.put(event.getAbility(), System.currentTimeMillis() + (event.getAbility().getMaxLength() * 1000));
map.put(event.getPlayer().getName(), InfoMap);
HashMap<String, Long> InfoMap = map.get(event.getPlayer().getUniqueId());
if (InfoMap == null) {
InfoMap = new HashMap<>();
map.put(event.getPlayer().getUniqueId(), InfoMap);
}
InfoMap.put(event.getAbility().toString(), System.currentTimeMillis() + (event.getAbility().getMaxLength() * 1000));
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void OnAbilityOff(McMMOPlayerAbilityDeactivateEvent event) {
if (map.containsKey(event.getPlayer().getName())) {
HashMap<AbilityType, Long> InfoMap = map.get(event.getPlayer().getName());
InfoMap.remove(event.getAbility());
HashMap<String, Long> InfoMap = map.get(event.getPlayer().getUniqueId());
if (InfoMap != null) {
InfoMap.remove(event.getAbility().toString());
if (InfoMap.isEmpty())
map.remove(event.getPlayer().getName());
map.remove(event.getPlayer().getUniqueId());
}
}

Expand All @@ -85,29 +86,29 @@ public double getMultiplier(Player player) {
if (player == null)
return 0D;

HashMap<AbilityType, Long> InfoMap = map.get(player.getName());
HashMap<String, Long> InfoMap = map.get(player.getUniqueId());
if (InfoMap == null)
return 0D;

Long t = InfoMap.get(AbilityType.TREE_FELLER);
Long t = InfoMap.get("TREE_FELLER");
if (t != null) {
if (t < System.currentTimeMillis())
return -(1-Jobs.getGCManager().TreeFellerMultiplier);
map.remove(AbilityType.TREE_FELLER);
return -(1 - Jobs.getGCManager().TreeFellerMultiplier);
InfoMap.remove("TREE_FELLER");
}

t = InfoMap.get(AbilityType.GIGA_DRILL_BREAKER);
t = InfoMap.get("GIGA_DRILL_BREAKER");
if (t != null) {
if (t < System.currentTimeMillis())
return -(1-Jobs.getGCManager().gigaDrillMultiplier);
map.remove(AbilityType.GIGA_DRILL_BREAKER);
return -(1 - Jobs.getGCManager().gigaDrillMultiplier);
InfoMap.remove("GIGA_DRILL_BREAKER");
}

t = InfoMap.get(AbilityType.SUPER_BREAKER);
t = InfoMap.get("SUPER_BREAKER");
if (t != null) {
if (t < System.currentTimeMillis())
return -(1-Jobs.getGCManager().superBreakerMultiplier);
map.remove(AbilityType.SUPER_BREAKER);
return -(1 - Jobs.getGCManager().superBreakerMultiplier);
InfoMap.remove("SUPER_BREAKER");
}

return 0D;
Expand All @@ -125,8 +126,9 @@ public boolean CheckmcMMO() {
// Still enabling event listener for repair
return true;
}

mcMMOPresent = true;
Jobs.consoleMsg("&e[Jobs] &6mcMMO was found - Enabling capabilities.");
Jobs.consoleMsg("&e[Jobs] &6mcMMO" + McMMO.getDescription().getVersion() + " was found - Enabling capabilities.");
return true;
}
return false;
Expand Down

0 comments on commit af4d6ce

Please sign in to comment.