-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d2f9a14
Showing
9 changed files
with
501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Eclipse stuff | ||
/.classpath | ||
/.project | ||
/.settings | ||
|
||
# netbeans | ||
/nbproject | ||
|
||
# we use maven! | ||
/build.xml | ||
|
||
# maven | ||
/target | ||
|
||
# vim | ||
.*.sw[a-p] | ||
|
||
# various other potential build files | ||
/build | ||
/bin | ||
/dist | ||
/manifest.mf | ||
|
||
/world | ||
|
||
# Mac filesystem dust | ||
*.DS_Store | ||
|
||
# intellij | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# Project Stuff | ||
/src/main/resources/mcMMO-Towny | ||
|
||
# Other Libraries | ||
*.jar | ||
|
||
# Atlassian Stuff | ||
/atlassian-ide-plugin.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.mcmmo</groupId> | ||
<artifactId>mcMMO-Towny</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<name>mcMMO-Towny</name> | ||
<url>https://github.com/mcMMO-Dev/mcMMO-Towny</url> | ||
<issueManagement> | ||
<system>GitHub</system> | ||
<url>https://github.com/mcMMO-Dev/mcMMO-Towny/issues</url> | ||
</issueManagement> | ||
<build> | ||
<finalName>mcMMO-Towny</finalName> | ||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<targetPath>.</targetPath> | ||
<filtering>true</filtering> | ||
<directory>${basedir}/src/main/resources/</directory> | ||
<includes> | ||
<include>*.yml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<descriptors> | ||
<descriptor>src/main/assembly/package.xml</descriptor> | ||
</descriptors> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>build</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>1.5</version> | ||
<configuration> | ||
<artifactSet> | ||
<includes> | ||
<include>com.gmail.nossr50.mcMMO:mcMMO</include> | ||
<include>org.mcstats.bukkit:metrics</include> | ||
</includes> | ||
</artifactSet> | ||
<relocations> | ||
<relocation> | ||
<pattern>org.mcstats</pattern> | ||
<shadedPattern>org.mcmmo.mcmmotowny.mcstats</shadedPattern> | ||
</relocation> | ||
</relocations> | ||
<filters> | ||
<filter> | ||
<artifact>com.gmail.nossr50.mcMMO:mcMMO</artifact> | ||
<includes> | ||
<include>com/gmail/nossr50/events/experience*</include> | ||
</includes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.wagon</groupId> | ||
<artifactId>wagon-file</artifactId> | ||
<version>2.2</version> | ||
</extension> | ||
</extensions> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<id>bukkit-repo</id> | ||
<url>http://repo.bukkit.org/content/groups/public/</url> | ||
</repository> | ||
<repository> | ||
<id>md_5-repo</id> | ||
<url>http://repo.md-5.net/</url> | ||
</repository> | ||
<repository> | ||
<id>Plugin Metrics</id> | ||
<url>http://repo.mcstats.org/content/repositories/public</url> | ||
</repository> | ||
</repositories> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bukkit</groupId> | ||
<artifactId>bukkit</artifactId> | ||
<version>LATEST</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.gmail.nossr50.mcMMO</groupId> | ||
<artifactId>mcMMO</artifactId> | ||
<version>RELEASE</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mcstats.bukkit</groupId> | ||
<artifactId>metrics</artifactId> | ||
<version>R6</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.palmergames.bukkit.towny</groupId> | ||
<artifactId>Towny</artifactId> | ||
<version>0.86.0.0</version> | ||
<scope>system</scope> | ||
<systemPath>${project.basedir}/lib/Towny.jar</systemPath> | ||
</dependency> | ||
</dependencies> | ||
<distributionManagement> | ||
<repository> | ||
<id>mcmmo-repo</id> | ||
<url>file:///var/lib/jenkins/repo</url> | ||
</repository> | ||
</distributionManagement> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
35 changes: 35 additions & 0 deletions
35
mcMMO-Towny/src/main/java/org/mcmmo/mcmmotowny/config/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.mcmmo.mcmmotowny.config; | ||
|
||
public class Config extends ConfigLoader { | ||
private static Config instance; | ||
|
||
private Config() { | ||
super("config.yml"); | ||
validate(); | ||
} | ||
|
||
public static Config getInstance() { | ||
if (instance == null) { | ||
instance = new Config(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
@Override | ||
protected boolean validateKeys() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void loadKeys() {} | ||
|
||
/* GENERAL */ | ||
public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); } | ||
public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); } | ||
public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); } | ||
|
||
/* TOWNY */ | ||
public double getExperienceModifierGlobal() { return config.getDouble("Experience.Global_Modifier", 1.0); } | ||
public double getExperienceModifierTown(String townName) { return config.getDouble("Experience.Towns." + townName, 1.0); } | ||
} |
89 changes: 89 additions & 0 deletions
89
mcMMO-Towny/src/main/java/org/mcmmo/mcmmotowny/config/ConfigLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.mcmmo.mcmmotowny.config; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
|
||
import org.mcmmo.mcmmotowny.mcMMOTowny; | ||
|
||
public abstract class ConfigLoader { | ||
protected static final mcMMOTowny plugin = mcMMOTowny.p; | ||
protected String fileName; | ||
private File configFile; | ||
protected FileConfiguration config; | ||
|
||
public ConfigLoader(String relativePath, String fileName) { | ||
this.fileName = fileName; | ||
configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName); | ||
loadFile(); | ||
} | ||
|
||
public ConfigLoader(String fileName) { | ||
this.fileName = fileName; | ||
configFile = new File(plugin.getDataFolder(), fileName); | ||
loadFile(); | ||
} | ||
|
||
protected void loadFile() { | ||
if (!configFile.exists()) { | ||
plugin.debug("Creating mcMMOTowny " + fileName + " File..."); | ||
|
||
try { | ||
plugin.saveResource(fileName, false); // Normal files | ||
} | ||
catch (IllegalArgumentException ex) { | ||
plugin.saveResource(configFile.getParentFile().getName() + File.separator + fileName, false); // Mod files | ||
} | ||
} | ||
else { | ||
plugin.debug("Loading mcMMOTowny " + fileName + " File..."); | ||
} | ||
|
||
config = YamlConfiguration.loadConfiguration(configFile); | ||
} | ||
|
||
protected abstract void loadKeys(); | ||
|
||
protected boolean validateKeys() { | ||
return true; | ||
} | ||
|
||
protected boolean noErrorsInConfig(List<String> issues) { | ||
for (String issue : issues) { | ||
plugin.getLogger().warning(issue); | ||
} | ||
|
||
return issues.isEmpty(); | ||
} | ||
|
||
protected void validate() { | ||
if (validateKeys()) { | ||
plugin.debug("No errors found in " + fileName + "!"); | ||
} | ||
else { | ||
plugin.getLogger().warning("Errors were found in " + fileName + "! mcMMOTowny was disabled!"); | ||
plugin.getServer().getPluginManager().disablePlugin(plugin); | ||
} | ||
} | ||
|
||
public File getFile() { | ||
return configFile; | ||
} | ||
|
||
public void backup() { | ||
plugin.getLogger().warning("You are using an old version of the " + fileName + " file."); | ||
plugin.getLogger().warning("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version."); | ||
|
||
configFile.renameTo(new File(configFile.getPath() + ".old")); | ||
|
||
if (plugin.getResource(fileName) != null) { | ||
plugin.saveResource(fileName, true); | ||
} | ||
|
||
plugin.getLogger().warning("Reloading " + fileName + " with new values..."); | ||
loadFile(); | ||
loadKeys(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
mcMMO-Towny/src/main/java/org/mcmmo/mcmmotowny/listeners/ExperienceListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.mcmmo.mcmmotowny.listeners; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; | ||
|
||
import com.palmergames.bukkit.towny.object.TownyUniverse; | ||
import org.mcmmo.mcmmotowny.config.Config; | ||
|
||
public class ExperienceListener implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
public void onPlayerXpGainEvent(McMMOPlayerXpGainEvent event) { | ||
Player player = event.getPlayer(); | ||
float experienceGained = event.getRawXpGained(); | ||
String townName = TownyUniverse.getTownName(player.getLocation()); | ||
|
||
if (townName == null) { | ||
return; | ||
} | ||
|
||
experienceGained *= Config.getInstance().getExperienceModifierGlobal(); | ||
experienceGained *= Config.getInstance().getExperienceModifierTown(townName); | ||
|
||
event.setRawXpGained(experienceGained); | ||
} | ||
} |
Oops, something went wrong.