Skip to content

Commit

Permalink
Merge branch 'citizens-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
Haarolean committed Jan 4, 2018
2 parents d0ac59c + 438051d commit 382c7de
Show file tree
Hide file tree
Showing 17 changed files with 494 additions and 184 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Simple!

* Multiworld support.

* [Citizens](https://www.spigotmc.org/resources/citizens.13811/) support.

* Mod items support!

* Repairing does not clear enchantments on enchanted items!
Expand Down Expand Up @@ -128,6 +130,19 @@ If you want to change sound that NPC are making on interact – you can use inga

All other config parameters are configurable in-game, so you don't have to bother about them. But if you want – they are quite self-explanatory.

### Citizens integration

You can add traits to your npcs to act like respective Griswold NPC types.

Following traits can be added:
- griswold_tools
- griswold_armor
- griswold_both
- griswold_enchant
- griswold_all

Please don't add multiple traits at once, lol.

### How to add a custom item

You have to create a new entry in config with name CustomItems. This entry will contain two more entries: Tools and Armor. Under those you add your items in "'id': name" format.
Expand Down Expand Up @@ -166,10 +181,11 @@ You can copy-paste this snippet to the end of your config.
## Support links

* [Plugin page on dev.bukkit.org](http://dev.bukkit.org/bukkit-plugins/griswold/)
* [Plugin page on spigotmc.org](http://spigotmc.org/resources/griswold.49036/)
* [Russian discussion and support](http://rubukkit.org/threads/15343/)
* Feel free to suggest something or report bugs in Issues
* Your pull-requests are always welcome!

## Stats:

![Griswold stats](http://mcstats.org/signature/griswold.png)
![Griswold stats](http://mcstats.org/signature/griswold.png)
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ permissions:
description: Allows you to add enchantments
default: op

softdepend: [Vault]
softdepend: [Vault, Citizens]
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<VaultVersion>1.5.6</VaultVersion>
<BukkitVersion>1.12.2-R0.1-SNAPSHOT</BukkitVersion>
<CitizensApiVersion>2.0.16-SNAPSHOT</CitizensApiVersion>
</properties>

<dependencies>
Expand All @@ -26,6 +27,12 @@
<version>${VaultVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>${CitizensApiVersion}</version>
</dependency>
</dependencies>

<repositories>
Expand All @@ -37,6 +44,10 @@
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>citizens-repo</id>
<url>http://repo.citizensnpcs.co</url>
</repository>
</repositories>

<build>
Expand Down
4 changes: 2 additions & 2 deletions src/com/github/toxuin/griswold/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ else if (args[0].equalsIgnoreCase("hide")) {
return true;
}
try {
Repairer.getByName(args[1]).despawn();
GriswoldNPC.getByName(args[1]).despawn();
sender.sendMessage(Lang.chat_hidden);
} catch (IllegalArgumentException ignored) {
sender.sendMessage(Lang.error_remove);
Expand All @@ -139,7 +139,7 @@ else if (args[0].equalsIgnoreCase("unhide")) {
return true;
}
try {
Repairer.getByName(args[1]).spawn();
GriswoldNPC.getByName(args[1]).spawn();
sender.sendMessage(Lang.chat_unhidden);
} catch (IllegalArgumentException ignored) {
sender.sendMessage(Lang.chat_error);
Expand Down
12 changes: 6 additions & 6 deletions src/com/github/toxuin/griswold/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class EventListener implements Listener {

private final Griswold plugin;
private final Map<Repairer, Pair> npcChunks;
private final Map<GriswoldNPC, Pair> npcChunks;

EventListener(final Griswold plugin) {
this.plugin = plugin;
Expand All @@ -28,7 +28,7 @@ public class EventListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
if (npcChunks.isEmpty()) return;
Set<Repairer> npcs = npcChunks.keySet();
Set<GriswoldNPC> npcs = npcChunks.keySet();
for (Repairer rep : npcs) {
if (event.getEntity().equals(rep.getEntity())) {
event.setDamage(0d);
Expand All @@ -46,7 +46,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
return;
}

Set<Repairer> npcs = npcChunks.keySet();
Set<GriswoldNPC> npcs = npcChunks.keySet();
for (Repairer rep : npcs) {
if (event.getRightClicked().equals(rep.getEntity())) {
plugin.interactor.interact(event.getPlayer(), rep);
Expand All @@ -59,7 +59,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
@EventHandler
public void onZombieTarget(EntityTargetLivingEntityEvent event) {
if (event.getEntity() instanceof Zombie) {
Set<Repairer> npcs = npcChunks.keySet();
Set<GriswoldNPC> npcs = npcChunks.keySet();
for (Repairer rep : npcs) {
if (rep.getEntity().equals(event.getTarget())) {
event.setCancelled(true);
Expand All @@ -76,7 +76,7 @@ public void onChunkLoad(ChunkLoadEvent event) {

for (Pair pair : npcChunks.values()) {
if (pair.equals(coords)) {
for (Repairer rep : npcChunks.keySet()) {
for (GriswoldNPC rep : npcChunks.keySet()) {
if (npcChunks.get(rep).equals(coords)) {
rep.spawn();
if (Griswold.debug) Griswold.log.info("SPAWNED NPC " + rep.getName() + ", HIS CHUNK LOADED");
Expand All @@ -93,7 +93,7 @@ public void onChunkUnload(ChunkUnloadEvent event) {

for (Pair pair : npcChunks.values()) {
if (pair.equals(coords)) {
for (Repairer rep : npcChunks.keySet()) {
for (GriswoldNPC rep : npcChunks.keySet()) {
if (npcChunks.get(rep).equals(coords)) {
rep.despawn();
if (Griswold.debug) Griswold.log.info("DESPAWNED NPC " + rep.getName() + ", HIS CHUNK GOT UNLOADED");
Expand Down
43 changes: 33 additions & 10 deletions src/com/github/toxuin/griswold/Griswold.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.toxuin.griswold;

import com.github.toxuin.griswold.Metrics.Graph;
import com.github.toxuin.griswold.adapters.citizens.CitizensAdapter;
import com.github.toxuin.griswold.util.Pair;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
Expand All @@ -10,6 +11,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -22,14 +24,15 @@
import java.util.logging.Logger;

public class Griswold extends JavaPlugin implements Listener {
public static final String PLUGIN_NAME = "Griswold";
static File directory;
static boolean debug = false;
public static int timeout = 5000;
public static Logger log;

static FileConfiguration config = null;
private static File configFile = null;
static Map<Repairer, Pair> npcChunks = new HashMap<>();
static Map<GriswoldNPC, Pair> npcChunks = new HashMap<>();
Interactor interactor;

static Economy economy = null;
Expand All @@ -42,6 +45,8 @@ public class Griswold extends JavaPlugin implements Listener {
static boolean findDuplicates = false;
static int duplicateFinderRadius = 5;

CitizensAdapter citizensAdapter;

public void onEnable() {
log = this.getLogger();
directory = this.getDataFolder();
Expand Down Expand Up @@ -84,10 +89,24 @@ public void onEnable() {
if (Lang.chat_agreed.startsWith("ERROR:")) reloadPlugin(); // this is fucking gold
}, 20);

Plugin citizens = getServer().getPluginManager().getPlugin("Citizens");
if (citizens != null && citizens.isEnabled()) {
citizensAdapter = new CitizensAdapter();
log.info("Registered Griswold traits with Citizens");
}

try {
Metrics metrics = new Metrics(this);
Graph graph = metrics.createGraph("Number of NPCs");
graph.addPlotter(new Metrics.Plotter("Total") {
Graph citizensGraph = metrics.createGraph("Using Citizens2");
citizensGraph.addPlotter(new Metrics.Plotter() {
@Override
public int getValue() {
return citizensAdapter == null ? 0 : 1;
}
});

Graph numberOfNpcGraph = metrics.createGraph("Number of NPCs");
numberOfNpcGraph.addPlotter(new Metrics.Plotter("Total") {
@Override
public int getValue() {
return npcChunks.keySet().size();
Expand All @@ -105,6 +124,7 @@ public void onDisable() {
interactor = null;
getCommand("blacksmith").setExecutor(null);
despawnAll();
if (citizensAdapter != null) citizensAdapter.deregisterTraits();
log.info("Disabled.");
}

Expand All @@ -123,7 +143,7 @@ void createRepairman(String name, Location loc, String type) {

void createRepairman(String name, Location loc, String type, String cost) {
boolean found = false;
Set<Repairer> npcs = npcChunks.keySet();
Set<GriswoldNPC> npcs = npcChunks.keySet();
for (Repairer rep : npcs) {
if (rep.getName().equalsIgnoreCase(name)) found = true;
}
Expand All @@ -147,8 +167,7 @@ void createRepairman(String name, Location loc, String type, String cost) {
e.printStackTrace();
}

Repairer meGusta = new Repairer(name, loc, Repairer.getDefaultSound(), type, Double.parseDouble(cost));

GriswoldNPC meGusta = new GriswoldNPC(name, loc, Repairer.getDefaultSound(), type, Double.parseDouble(cost));
meGusta.spawn();
}

Expand Down Expand Up @@ -177,7 +196,7 @@ void listRepairmen(CommandSender sender) {
}

void despawnAll() {
Griswold.npcChunks.keySet().forEach(Repairer::despawn);
Griswold.npcChunks.keySet().forEach(GriswoldNPC::despawn);
npcChunks.clear();
}

Expand All @@ -195,7 +214,7 @@ void toggleNames() {
}

void setSound(String name, String sound) {
Set<Repairer> npcs = npcChunks.keySet();
Set<GriswoldNPC> npcs = npcChunks.keySet();
for (Repairer rep : npcs) {
if (rep.getName().equals(name)) {
rep.setSound(sound);
Expand All @@ -204,7 +223,7 @@ void setSound(String name, String sound) {
}
}

Map<Repairer, Pair> getNpcChunks() {
Map<GriswoldNPC, Pair> getNpcChunks() {
return npcChunks;
}

Expand Down Expand Up @@ -258,7 +277,7 @@ private void readConfig() {
String type = config.getString("repairmen." + repairman + ".type");
double cost = config.getDouble("repairmen." + repairman + ".cost");

Repairer squidward = new Repairer(repairman, loc, sound, type, cost);
GriswoldNPC squidward = new GriswoldNPC(repairman, loc, sound, type, cost);

squidward.loadChunk();
squidward.spawn();
Expand Down Expand Up @@ -381,4 +400,8 @@ private boolean setupEconomy() {
}
return (economy != null);
}

public Interactor getInteractor() {
return interactor;
}
}
Loading

0 comments on commit 382c7de

Please sign in to comment.