├── bin
├── readme
├── net
│ └── gamerservices
│ │ ├── npcx
│ │ ├── Tick.class
│ │ ├── myNPC.class
│ │ ├── npcx.class
│ │ ├── myHint.class
│ │ ├── myWorld.class
│ │ ├── myZone.class
│ │ ├── LongTick.class
│ │ ├── myFaction.class
│ │ ├── myMerchant.class
│ │ ├── myPlayer.class
│ │ ├── myResearch.class
│ │ ├── myShopItem.class
│ │ ├── myUniverse.class
│ │ ├── myLoottable.class
│ │ ├── myPathgroup.class
│ │ ├── mySpawngroup.class
│ │ ├── myZoneMember.class
│ │ ├── PluginListener.class
│ │ ├── myFactionEntry.class
│ │ ├── myMerchantItem.class
│ │ ├── myNpc_faction.class
│ │ ├── myTriggerword.class
│ │ ├── npcxBListener.class
│ │ ├── npcxEListener.class
│ │ ├── npcxPListener.class
│ │ ├── npcxSListener.class
│ │ ├── npcxWListener.class
│ │ ├── myCommandHandler.class
│ │ ├── myLoottable_entry.class
│ │ ├── myMerchant_entry.class
│ │ ├── myPathgroup_entry.class
│ │ └── myPlayer_factionentry.class
│ │ └── npclibfork
│ │ ├── BasicNpc.class
│ │ ├── CHumanNpc.class
│ │ ├── NpcSocket.class
│ │ ├── CHumanNpc$1.class
│ │ ├── NpcSpawner.class
│ │ ├── BasicHumanNpc.class
│ │ ├── NpcNetHandler.class
│ │ ├── BasicHumanNpcList.class
│ │ ├── NpcNetworkManager.class
│ │ ├── NpcEntityTargetEvent.class
│ │ └── NpcEntityTargetEvent$NpcTargetReason.class
└── plugin.yml
├── dist
└── readme
├── npcx.jar
├── MANIFEST.MF
├── src
├── net
│ └── gamerservices
│ │ ├── npcx
│ │ ├── myWorld.java
│ │ ├── myCommandHandler.java
│ │ ├── PluginListener.java
│ │ ├── myHint.java
│ │ ├── myFaction.java
│ │ ├── myTriggerword.java
│ │ ├── myZoneMember.java
│ │ ├── myPlayer_factionentry.java
│ │ ├── myFactionEntry.java
│ │ ├── myLoottable_entry.java
│ │ ├── myShopItem.java
│ │ ├── myMerchantItem.java
│ │ ├── myPathgroup.java
│ │ ├── myNpc_faction.java
│ │ ├── Tick.java
│ │ ├── LongTick.java
│ │ ├── myLoottable.java
│ │ ├── myResearch.java
│ │ ├── myMerchant.java
│ │ ├── myPathgroup_entry.java
│ │ ├── npcxBListener.java
│ │ ├── myMerchant_entry.java
│ │ ├── npcxSListener.java
│ │ ├── myZone.java
│ │ ├── npcxWListener.java
│ │ ├── mySpawngroup.java
│ │ ├── npcxEListener.java
│ │ ├── myPlayer.java
│ │ ├── npcxPListener.java
│ │ └── myNPC.java
│ │ └── npclibfork
│ │ ├── BasicNpc.java
│ │ ├── NpcSocket.java
│ │ ├── NpcEntityTargetEvent.java
│ │ ├── BasicHumanNpcList.java
│ │ ├── NpcNetworkManager.java
│ │ ├── NpcNetHandler.java
│ │ ├── CHumanNpc.java
│ │ ├── NpcSpawner.java
│ │ └── BasicHumanNpc.java
└── plugin.yml
├── README.txt
├── README
├── CHANGELOG.txt
├── .project
├── .classpath
├── .settings
└── org.eclipse.jdt.core.prefs
└── LICENSE.txt
/bin/readme:
--------------------------------------------------------------------------------
1 | ignore this folder
2 |
--------------------------------------------------------------------------------
/dist/readme:
--------------------------------------------------------------------------------
1 | ignore this folder
2 |
--------------------------------------------------------------------------------
/npcx.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/npcx.jar
--------------------------------------------------------------------------------
/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path: ../lib/mysql-connector-java-5.1.6-bin.jar
3 |
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/Tick.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/Tick.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myNPC.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myNPC.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/npcx.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/npcx.class
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myWorld.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myWorld {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myHint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myHint.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myWorld.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myWorld.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myZone.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myZone.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/LongTick.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/LongTick.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myFaction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myFaction.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myMerchant.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myMerchant.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myPlayer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myPlayer.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myResearch.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myResearch.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myShopItem.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myShopItem.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myUniverse.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myUniverse.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myLoottable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myLoottable.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myPathgroup.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myPathgroup.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/mySpawngroup.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/mySpawngroup.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myZoneMember.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myZoneMember.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/BasicNpc.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/BasicNpc.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/CHumanNpc.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/CHumanNpc.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/NpcSocket.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/NpcSocket.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/PluginListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/PluginListener.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myFactionEntry.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myFactionEntry.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myMerchantItem.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myMerchantItem.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myNpc_faction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myNpc_faction.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myTriggerword.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myTriggerword.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/npcxBListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/npcxBListener.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/npcxEListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/npcxEListener.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/npcxPListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/npcxPListener.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/npcxSListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/npcxSListener.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/npcxWListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/npcxWListener.class
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myCommandHandler.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myCommandHandler {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | NPCX
2 | =========================
3 |
4 | Please see http://www.soliniaonline.com/plugins/npcx for the latest documentation
5 |
6 |
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/CHumanNpc$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/CHumanNpc$1.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/NpcSpawner.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/NpcSpawner.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myCommandHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myCommandHandler.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myLoottable_entry.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myLoottable_entry.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myMerchant_entry.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myMerchant_entry.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myPathgroup_entry.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myPathgroup_entry.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/BasicHumanNpc.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/BasicHumanNpc.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/NpcNetHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/NpcNetHandler.class
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | NPCX
2 | =========================
3 |
4 | Please see http://soliniaonlinemc.wordpress.com/2011/09/24/npcx/ for the latest documentation
5 |
6 |
--------------------------------------------------------------------------------
/bin/net/gamerservices/npcx/myPlayer_factionentry.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npcx/myPlayer_factionentry.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/BasicHumanNpcList.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/BasicHumanNpcList.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/NpcNetworkManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/NpcNetworkManager.class
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/NpcEntityTargetEvent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/NpcEntityTargetEvent.class
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/PluginListener.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class PluginListener {
4 | private npcx parent;
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myHint.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myHint {
4 | int id = 0;
5 | int price = 0;
6 | public int age;
7 | }
8 |
--------------------------------------------------------------------------------
/bin/net/gamerservices/npclibfork/NpcEntityTargetEvent$NpcTargetReason.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mixxit/npcx/HEAD/bin/net/gamerservices/npclibfork/NpcEntityTargetEvent$NpcTargetReason.class
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myFaction.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myFaction {
4 | public int id;
5 | String name;
6 | public int base = 0; // neutral
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/CHANGELOG.txt:
--------------------------------------------------------------------------------
1 | 0.0.3
2 | - Updated for CraftBukkit 937
3 |
4 | 0.0.2
5 | - Updated for MC 1.6.
6 |
7 | 0.0.1
8 | - Updated for MC 1.5.
9 | - Began the rewrite of everything.
10 | - Began a real changelog (this :D)
11 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myTriggerword.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myTriggerword {
4 |
5 | public int id;
6 | public String word;
7 | public String response;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myZoneMember.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myZoneMember {
4 |
5 | public int id;
6 | public String playename;
7 | public int zoneid;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myPlayer_factionentry.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myPlayer_factionentry {
4 | int id;
5 | String playername;
6 | int factionid = 0;
7 | int amount = 0;
8 | }
9 |
--------------------------------------------------------------------------------
/bin/plugin.yml:
--------------------------------------------------------------------------------
1 | name: npcx
2 | main: net.gamerservices.npcx.npcx
3 | version: 0.031
4 | author: mixxit
5 | website: http://www.gamerservices.net
6 | description: >
7 | NPCExtender
8 | commands:
9 | npcx:
10 | description: npc extender
11 |
--------------------------------------------------------------------------------
/src/plugin.yml:
--------------------------------------------------------------------------------
1 | name: npcx
2 | main: net.gamerservices.npcx.npcx
3 | version: 0.031
4 | author: mixxit
5 | website: http://www.gamerservices.net
6 | description: >
7 | NPCExtender
8 | commands:
9 | npcx:
10 | description: npc extender
11 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myFactionEntry.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myFactionEntry {
4 | public int id;
5 | public int factionid;
6 | public int targetfactionid;
7 | public int amount;
8 | public int arg;
9 | }
10 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myLoottable_entry.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myLoottable_entry {
4 | public int id;
5 | public myLoottable parent;
6 | public int loottable_id;
7 | public int itemid;
8 | public int amount;
9 | }
10 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myShopItem.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import org.bukkit.inventory.ItemStack;
4 |
5 | public class myShopItem {
6 | public ItemStack item = new ItemStack(0);
7 |
8 | public double price = 0;
9 |
10 | myShopItem() {
11 | item.setAmount(1);
12 | item.setTypeId(1);
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myMerchantItem.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import org.bukkit.inventory.ItemStack;
4 |
5 | public class myMerchantItem {
6 | public ItemStack item = new ItemStack(1, 1);
7 |
8 | public double price = 0;
9 |
10 | myMerchantItem() {
11 | item.setAmount(1);
12 | item.setTypeId(1);
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | npcx
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myPathgroup.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.List;
4 | import java.util.concurrent.CopyOnWriteArrayList;
5 |
6 | import org.bukkit.World;
7 |
8 | public class myPathgroup {
9 | public int id;
10 | String name;
11 | public List pathgroupentries = new CopyOnWriteArrayList();
12 | public int category;
13 | public World world;
14 | }
15 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myNpc_faction.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myNpc_faction {
4 | npcx parent;
5 | int id;
6 | int npcid;
7 | int factionid;
8 | int amount;
9 |
10 | public myNpc_faction(int id, int npcid, int factionid, int amount) {
11 | this.id = id;
12 | this.npcid = npcid;
13 | this.factionid = factionid;
14 | this.amount = amount;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/Tick.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.TimerTask;
4 |
5 | public class Tick extends TimerTask {
6 |
7 | private npcx parent;
8 |
9 | public Tick(npcx owner) {
10 | parent = owner;
11 | }
12 |
13 | @Override
14 | public void run() {
15 | // TODO Auto-generated method stub
16 | parent.think();
17 |
18 | cancel();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/LongTick.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.TimerTask;
4 |
5 | public class LongTick extends TimerTask {
6 |
7 | private npcx parent;
8 |
9 | public LongTick(npcx owner) {
10 | parent = owner;
11 | }
12 |
13 | @Override
14 | public void run() {
15 | // TODO Auto-generated method stub
16 | parent.longCheck();
17 |
18 | cancel();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myLoottable.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.List;
4 | import java.util.concurrent.CopyOnWriteArrayList;
5 |
6 | import org.bukkit.entity.Monster;
7 |
8 | public class myLoottable {
9 |
10 | public int id;
11 | public String name;
12 | public List loottable_entries = new CopyOnWriteArrayList();
13 |
14 | myLoottable(int id, String name) {
15 | this.id = id;
16 | this.name = name;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myResearch.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | public class myResearch {
4 |
5 | int id;
6 | String name;
7 | String prereq;
8 | String time;
9 | public int cost;
10 |
11 | public myResearch(int id, String name, String prereq, String time, String cost) {
12 | // TODO Auto-generated constructor stub
13 | this.id = id;
14 | this.name = name;
15 | this.prereq = prereq;
16 | this.time = time;
17 | this.cost = Integer.parseInt(cost);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/BasicNpc.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | public class BasicNpc {
4 |
5 | private String uniqueId;
6 | private String name;
7 |
8 | public BasicNpc(String uniqueId, String name) {
9 | this.uniqueId = uniqueId;
10 | this.name = name;
11 | }
12 |
13 | public void setName(String newName) {
14 | this.name = newName;
15 | }
16 |
17 | public String getName() {
18 | return this.name;
19 | }
20 |
21 | public String getUniqueId() {
22 | return this.uniqueId;
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/NpcSocket.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.InputStream;
6 | import java.io.OutputStream;
7 | import java.net.Socket;
8 |
9 | public class NpcSocket extends Socket {
10 |
11 | @Override
12 | public InputStream getInputStream() {
13 | byte[] buf = new byte[1];
14 | return new ByteArrayInputStream(buf);
15 | }
16 |
17 | @Override
18 | public OutputStream getOutputStream() {
19 | return new ByteArrayOutputStream();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myMerchant.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.concurrent.CopyOnWriteArrayList;
6 |
7 | public class myMerchant {
8 | public int id;
9 | public String name;
10 | npcx parent;
11 | public List merchantentries = new ArrayList();
12 | public String category = "default";
13 |
14 | public myMerchant(npcx parent, int id, String name) {
15 | this.parent = parent;
16 | this.id = id;
17 | this.name = name;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Thu Mar 10 00:06:00 GMT 2011
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myPathgroup_entry.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import org.bukkit.Location;
4 | import org.bukkit.entity.LivingEntity;
5 |
6 | public class myPathgroup_entry {
7 | public int id;
8 | public String name;
9 | public Location location;
10 | public int pathgroupid;
11 | public int spot;
12 | public myPathgroup parent;
13 |
14 | myPathgroup_entry(Location location, int pathgroupid, myPathgroup pathgroup, int spot, String name) {
15 | this.name = name;
16 | this.location = location;
17 | this.pathgroupid = pathgroupid;
18 | this.spot = spot;
19 | this.parent = pathgroup;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/NpcEntityTargetEvent.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import org.bukkit.entity.Entity;
4 | import org.bukkit.event.entity.EntityTargetEvent;
5 |
6 | public class NpcEntityTargetEvent extends EntityTargetEvent {
7 |
8 | public static enum NpcTargetReason {
9 | CLOSEST_PLAYER, NPC_RIGHTCLICKED, NPC_BOUNCED
10 | }
11 |
12 | private NpcTargetReason reason;
13 |
14 | public NpcEntityTargetEvent(Entity entity, Entity target, NpcTargetReason reason) {
15 | super(entity, target, TargetReason.CUSTOM);
16 | this.reason = reason;
17 | }
18 |
19 | public NpcTargetReason getNpcReason() {
20 | return this.reason;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/BasicHumanNpcList.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import java.util.HashMap;
4 | import org.bukkit.entity.Entity;
5 |
6 | public class BasicHumanNpcList extends HashMap {
7 |
8 | public boolean containsBukkitEntity(Entity entity) {
9 | for (BasicHumanNpc bnpc : this.values()) {
10 | if (bnpc.getBukkitEntity().getEntityId() == entity.getEntityId()) return true;
11 | }
12 |
13 | return false;
14 | }
15 |
16 | public BasicHumanNpc getBasicHumanNpc(Entity entity) {
17 | for (BasicHumanNpc bnpc : this.values()) {
18 | if (bnpc.getBukkitEntity().getEntityId() == entity.getEntityId()) return bnpc;
19 | }
20 |
21 | return null;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/npcxBListener.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import org.bukkit.event.block.BlockIgniteEvent;
4 | import org.bukkit.event.block.BlockListener;
5 |
6 | public class npcxBListener extends BlockListener {
7 | private npcx parent;
8 |
9 | public npcxBListener(npcx parent) {
10 | this.parent = parent;
11 | }
12 |
13 | public void onBlockIgnite(BlockIgniteEvent event) {
14 | if (event.isCancelled()) { return; }
15 | if (this.parent.universe.nospread.equals("true")) {
16 |
17 | String cause = event.getCause().toString();
18 | if (cause.equals("SPREAD")) {
19 | event.setCancelled(true);
20 | }
21 | if (cause.equals("FLINT_AND_STEEL")) {
22 | event.setCancelled(true);
23 | }
24 |
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myMerchant_entry.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.List;
4 | import java.util.concurrent.CopyOnWriteArrayList;
5 |
6 | import org.bukkit.Location;
7 |
8 | public class myMerchant_entry {
9 |
10 | public int merchantid;
11 | public int itemid;
12 | public int amount;
13 | public int pricebuy;
14 | public int pricesell;
15 | public myMerchant parent;
16 | public int id;
17 |
18 | public myMerchant_entry(myMerchant parent, int merchantid, int itemid, int amount, int pricebuy, int pricesell) {
19 | // TODO Auto-generated constructor stub
20 |
21 | this.parent = parent;
22 | this.merchantid = merchantid;
23 | this.itemid = itemid;
24 | this.amount = amount;
25 | this.pricebuy = pricebuy;
26 | this.pricesell = pricesell;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/NpcNetworkManager.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import java.lang.reflect.Field;
4 | import java.net.Socket;
5 | import java.net.SocketAddress;
6 |
7 | import net.minecraft.server.NetHandler;
8 | import net.minecraft.server.NetworkManager;
9 | import net.minecraft.server.Packet;
10 |
11 | public class NpcNetworkManager extends NetworkManager {
12 |
13 | public NpcNetworkManager(Socket paramSocket, String paramString, NetHandler paramNetHandler) {
14 | super(paramSocket, paramString, paramNetHandler);
15 |
16 | try {
17 | Field f = NetworkManager.class.getDeclaredField("l");
18 | f.setAccessible(true);
19 | f.set(this, false);
20 | } catch (Exception e) {
21 |
22 | }
23 | }
24 |
25 | @Override
26 | public void a(NetHandler paramNetHandler) {
27 | super.a(paramNetHandler);
28 | }
29 |
30 | @Override
31 | public void queue(Packet paramPacket) {
32 | }
33 |
34 | @Override
35 | public void a(String paramString, Object... paramArrayOfObject) {
36 | }
37 |
38 | @Override
39 | public void a() {
40 | }
41 |
42 | @Override
43 | public SocketAddress getSocketAddress() {
44 | return super.getSocketAddress();
45 | }
46 |
47 | @Override
48 | public void d() {
49 | }
50 |
51 | @Override
52 | public int e() {
53 | return 0;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/npcxSListener.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import org.bukkit.event.server.PluginEnableEvent;
4 | import org.bukkit.event.server.PluginDisableEvent;
5 | import org.bukkit.event.server.ServerListener;
6 | import org.bukkit.plugin.Plugin;
7 |
8 | import com.iConomy.iConomy;
9 |
10 | public class npcxSListener extends ServerListener {
11 | private npcx parent;
12 |
13 | public npcxSListener(npcx parent) {
14 | this.parent = parent;
15 | }
16 |
17 | @Override
18 | public void onPluginEnable(PluginEnableEvent event) {
19 | if (parent.iConomy == null && parent.useiConomy) {
20 | Plugin iConomy = parent.getServer().getPluginManager().getPlugin("iConomy");
21 |
22 | if (iConomy != null) {
23 | if (iConomy.isEnabled() && iConomy.getClass().getName().equals("com.iConomy.iConomy")) {
24 | parent.iConomy = (iConomy) iConomy;
25 | System.out.println("[npcx] hooked into iConomy.");
26 | }
27 | }
28 | }
29 | }
30 |
31 | @Override
32 | public void onPluginDisable(PluginDisableEvent event) {
33 | if (parent.iConomy != null && parent.useiConomy) {
34 | if (event.getPlugin().getDescription().getName().equals("iConomy")) {
35 | parent.iConomy = null;
36 | System.out.println("[npcx] un-hooked from iConomy.");
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myZone.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.sql.PreparedStatement;
4 |
5 | import org.bukkit.Chunk;
6 |
7 | public class myZone {
8 | public myUniverse parent;
9 | public String name = "The Wild";
10 | public String ownername = "";
11 | public boolean wild = true;
12 | public Chunk chunk;
13 | public int x;
14 | public int z;
15 | public int id;
16 |
17 | public myZone(myUniverse universe, int id, Chunk chunk, int x, int z) {
18 | this.id = id;
19 | this.parent = universe;
20 | this.chunk = chunk;
21 | this.x = x;
22 | this.z = z;
23 | }
24 |
25 | public void setOwner(String name2) {
26 | // TODO Auto-generated method stub
27 |
28 | try {
29 | // System.out.println("npcx :myZone:setOwner:"+name2+":"+this.id);
30 | PreparedStatement stmt = this.parent.parent.universe.conn.prepareStatement("UPDATE zone set name=?,ownername=? WHERE id = ?");
31 | stmt.setString(1, name2 + "s land");
32 | stmt.setString(2, name2);
33 | stmt.setInt(3, this.id);
34 |
35 | stmt.executeUpdate();
36 | stmt.close();
37 |
38 | this.ownername = name2;
39 | this.name = name2 + "s land";
40 | } catch (Exception e) {
41 | e.printStackTrace();
42 | }
43 | }
44 |
45 | public void setName(String string) {
46 | // TODO Auto-generated method stub
47 | try {
48 | // System.out.println("npcx :myZone:setOwner:"+name2+":"+this.id);
49 | PreparedStatement stmt = this.parent.parent.universe.conn.prepareStatement("UPDATE zone set name=? WHERE id = ?");
50 | stmt.setString(1, string);
51 | stmt.setInt(2, this.id);
52 |
53 | stmt.executeUpdate();
54 | stmt.close();
55 |
56 | this.name = string;
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/npcxWListener.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.HashMap;
4 |
5 | import org.bukkit.event.world.ChunkLoadEvent;
6 | import org.bukkit.event.world.ChunkUnloadEvent;
7 | import org.bukkit.event.world.WorldListener;
8 |
9 | // Citizens Mod: http://forums.bukkit.org/threads/7173/
10 |
11 | public class npcxWListener extends WorldListener {
12 | private npcx parent;
13 |
14 | public npcxWListener(npcx parent) {
15 | this.parent = parent;
16 | }
17 |
18 | @Override
19 | public void onChunkUnload(ChunkUnloadEvent e) {
20 | parent.deregisterChunk(e.getChunk());
21 | try {
22 | // System.out.println("debug : closing chunk " + e.getChunk());
23 | for (myNPC npc : parent.universe.npcs.values()) {
24 | if (parent.universe.npcs != null) {
25 | if (npc.npc != null) {
26 | if (e.getChunk().getWorld().getChunkAt(npc.npc.getBukkitEntity().getLocation()).equals(e.getChunk())) {
27 | npc.npc.chunkinactive(npc.npc.getBukkitEntity().getLocation());
28 | }
29 | }
30 | }
31 | }
32 | } catch (Exception e2) {
33 | // looks like a table was locked, we need to mark this to try again
34 | this.parent.checkchunks = true;
35 | }
36 | }
37 |
38 | @Override
39 | public void onChunkLoad(ChunkLoadEvent e) {
40 |
41 | parent.registerChunk(e.getChunk());
42 | try {
43 | // System.out.println("debug : loading chunk " + e.getChunk());
44 | for (myNPC npc : parent.universe.npcs.values()) {
45 | if (parent.universe.npcs != null) {
46 | if (npc.npc != null) {
47 | if (e.getChunk().getWorld().getChunkAt(npc.npc.getBukkitEntity().getLocation()).equals(e.getChunk())) {
48 | npc.npc.chunkactive(npc.npc.getBukkitEntity().getLocation());
49 | }
50 | }
51 | }
52 | }
53 | } catch (Exception e2) {
54 | // looks like a table was locked, we need to mark this to try again
55 | this.parent.checkchunks = true;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/NpcNetHandler.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import net.minecraft.server.*;
4 |
5 | import org.bukkit.craftbukkit.entity.CraftPlayer;
6 |
7 | public class NpcNetHandler extends NetServerHandler {
8 |
9 | public NpcNetHandler(MinecraftServer minecraftserver, EntityPlayer entityplayer, NetworkManager netMgr) {
10 | super(minecraftserver, netMgr, entityplayer);
11 | netMgr.a(this);
12 | }
13 |
14 | @Override
15 | public CraftPlayer getPlayer() {
16 | return null;
17 | }
18 |
19 | @Override
20 | public void a() {
21 | }
22 |
23 | @Override
24 | public void disconnect(String s) {
25 | }
26 |
27 | @Override
28 | public void a(Packet10Flying packet10flying) {
29 | }
30 |
31 | @Override
32 | public void a(double d0, double d1, double d2, float f, float f1) {
33 | }
34 |
35 | @Override
36 | public void a(Packet14BlockDig packet14blockdig) {
37 | }
38 |
39 | @Override
40 | public void a(Packet15Place packet15place) {
41 | }
42 |
43 | @Override
44 | public void a(String s, Object[] aobject) {
45 | }
46 |
47 | @Override
48 | public void a(Packet packet) {
49 | }
50 |
51 | @Override
52 | public void sendPacket(Packet packet) {
53 | }
54 |
55 | @Override
56 | public void a(Packet16BlockItemSwitch packet16blockitemswitch) {
57 | }
58 |
59 | @Override
60 | public void a(Packet3Chat packet3chat) {
61 | }
62 |
63 | @Override
64 | public void a(Packet18ArmAnimation packet18armanimation) {
65 | }
66 |
67 | @Override
68 | public void a(Packet19EntityAction packet19entityaction) {
69 | }
70 |
71 | @Override
72 | public void a(Packet255KickDisconnect packet255kickdisconnect) {
73 | }
74 |
75 | @Override
76 | public int b() {
77 | return 0;
78 | }
79 |
80 | @Override
81 | public void sendMessage(String s) {
82 | }
83 |
84 | @Override
85 | public String getName() {
86 | return "";
87 | }
88 |
89 | @Override
90 | public void a(Packet7UseEntity packet7useentity) {
91 | }
92 |
93 | @Override
94 | public void a(Packet9Respawn packet9respawn) {
95 | }
96 |
97 | @Override
98 | public void a(Packet101CloseWindow packet101closewindow) {
99 | }
100 |
101 | @Override
102 | public void a(Packet102WindowClick packet102windowclick) {
103 | }
104 |
105 | @Override
106 | public void a(Packet106Transaction packet106transaction) {
107 | }
108 |
109 | @Override
110 | public void a(Packet130UpdateSign packet130updatesign) {
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/mySpawngroup.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.sql.PreparedStatement;
4 | import java.sql.SQLException;
5 | import java.sql.Statement;
6 | import java.util.HashMap;
7 |
8 | import net.gamerservices.npclibfork.NpcSpawner;
9 |
10 | import org.bukkit.World;
11 |
12 | public class mySpawngroup {
13 | public int id;
14 | public String name;
15 | public String category;
16 | public double x;
17 | public double y;
18 | public double z;
19 | public npcx parent;
20 | public boolean active = false;
21 | public World world;
22 | public HashMap npcs = new HashMap();
23 | public int activecountdown = 0;
24 | public float pitch;
25 | public float yaw;
26 | public myPathgroup pathgroup;
27 | public boolean chunkactive = true;
28 |
29 | public mySpawngroup(npcx parent) {
30 | this.parent = parent;
31 | }
32 |
33 | public boolean DBDelete() {
34 | // Go through my children
35 |
36 | try {
37 | for (myNPC npc : npcs.values()) {
38 | // Deleting npc
39 | sqlDeleteEntry(Integer.parseInt(npc.id));
40 | // Remove npcs from world
41 | if (npc.npc != null) {
42 | NpcSpawner.RemoveBasicHumanNpc(npc.npc);
43 | npc.npc = null;
44 | }
45 | }
46 |
47 | // Ok removed the instances of those npcs from the game, cleared
48 | // their SQL entries
49 | // Lets remove the entire npc cache
50 | npcs = null;
51 | sqlDelete();
52 |
53 | return true;
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | return false;
57 | }
58 |
59 | }
60 |
61 | private void sqlDeleteEntry(int id2) {
62 | // TODO Auto-generated method stub
63 | PreparedStatement s2;
64 | try {
65 | s2 = this.parent.universe.conn.prepareStatement("DELETE FROM spawngroup_entries WHERE spawngroupid = ? AND id = ?;");
66 | s2.setInt(1, this.id);
67 | s2.setInt(2, id2);
68 |
69 | s2.executeUpdate();
70 | } catch (SQLException e) {
71 | // TODO Auto-generated catch block
72 | e.printStackTrace();
73 | }
74 | }
75 |
76 | public void sqlDelete() {
77 | PreparedStatement s2;
78 | try {
79 | s2 = this.parent.universe.conn.prepareStatement("DELETE FROM spawngroup WHERE id = ?;");
80 | s2.setInt(1, this.id);
81 |
82 | s2.executeUpdate();
83 | } catch (SQLException e) {
84 | // TODO Auto-generated catch block
85 | e.printStackTrace();
86 | }
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/CHumanNpc.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import java.util.logging.Logger;
4 |
5 | import net.minecraft.server.Entity;
6 | import net.minecraft.server.EntityHuman;
7 | import net.minecraft.server.EntityPlayer;
8 | import net.minecraft.server.ItemInWorldManager;
9 | import net.minecraft.server.MinecraftServer;
10 | import net.minecraft.server.NetworkManager;
11 | import net.minecraft.server.NetHandler;
12 | import net.minecraft.server.Packet18ArmAnimation;
13 | import net.minecraft.server.World;
14 | import net.minecraft.server.WorldServer;
15 |
16 | import org.bukkit.craftbukkit.CraftServer;
17 | import org.bukkit.event.entity.EntityTargetEvent;
18 |
19 | public class CHumanNpc extends EntityPlayer {
20 |
21 | private static final Logger logger = Logger.getLogger("Minecraft");
22 | private int lastTargetId;
23 | private long lastBounceTick;
24 | private int lastBounceId;
25 |
26 | public CHumanNpc(MinecraftServer minecraftserver, World world, String s, ItemInWorldManager iteminworldmanager) {
27 | super(minecraftserver, world, s, iteminworldmanager);
28 |
29 | NetworkManager netMgr = new NpcNetworkManager(new NpcSocket(), "npc mgr", new NetHandler() {
30 | @Override
31 | public boolean c() {
32 | return false;
33 | }
34 | });
35 | this.netServerHandler = new NpcNetHandler(minecraftserver, this, netMgr);
36 | netMgr.a(this.netServerHandler);
37 |
38 | this.lastTargetId = -1;
39 | this.lastBounceId = -1;
40 | this.lastBounceTick = 0;
41 | }
42 |
43 | public void animateArmSwing() {
44 | this.b.getTracker(this.dimension).a(this, new Packet18ArmAnimation(this, 1));
45 | }
46 |
47 | public void forceSetName(String n) {
48 | this.displayName = n;
49 | }
50 |
51 | @Override
52 | public boolean b(EntityHuman entity) {
53 |
54 | EntityTargetEvent event = new NpcEntityTargetEvent(getBukkitEntity(), entity.getBukkitEntity(), NpcEntityTargetEvent.NpcTargetReason.NPC_RIGHTCLICKED);
55 | CraftServer server = ((WorldServer) this.world).getServer();
56 | server.getPluginManager().callEvent(event);
57 |
58 | return super.b(entity);
59 | }
60 |
61 | @Override
62 | public void a_(EntityHuman entity) {
63 | if (lastTargetId == -1 || lastTargetId != entity.id) {
64 | EntityTargetEvent event = new NpcEntityTargetEvent(getBukkitEntity(), entity.getBukkitEntity(), NpcEntityTargetEvent.NpcTargetReason.CLOSEST_PLAYER);
65 | CraftServer server = ((WorldServer) this.world).getServer();
66 | server.getPluginManager().callEvent(event);
67 | }
68 | lastTargetId = entity.id;
69 |
70 | super.a_(entity);
71 | }
72 |
73 | @Override
74 | public void c(Entity entity) {
75 | if (lastBounceId != entity.id || System.currentTimeMillis() - lastBounceTick > 1000) {
76 | EntityTargetEvent event = new NpcEntityTargetEvent(getBukkitEntity(), entity.getBukkitEntity(), NpcEntityTargetEvent.NpcTargetReason.NPC_BOUNCED);
77 | CraftServer server = ((WorldServer) this.world).getServer();
78 | server.getPluginManager().callEvent(event);
79 |
80 | lastBounceTick = System.currentTimeMillis();
81 | }
82 |
83 | lastBounceId = entity.id;
84 |
85 | super.c(entity);
86 | }
87 | }
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/NpcSpawner.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.Method;
5 |
6 | import net.gamerservices.npcx.myNPC;
7 | import net.gamerservices.npcx.npcx;
8 | import net.minecraft.server.Entity;
9 | import net.minecraft.server.EntityTypes;
10 | import net.minecraft.server.ItemInWorldManager;
11 | import net.minecraft.server.MathHelper;
12 | import net.minecraft.server.MinecraftServer;
13 | import net.minecraft.server.WorldServer;
14 | import org.bukkit.Server;
15 | import org.bukkit.World;
16 | import org.bukkit.craftbukkit.CraftServer;
17 | import org.bukkit.craftbukkit.CraftWorld;
18 | import org.bukkit.entity.LivingEntity;
19 | import org.bukkit.entity.CreatureType;
20 |
21 | public class NpcSpawner {
22 |
23 | protected static WorldServer GetWorldServer(World world) {
24 | try {
25 | CraftWorld w = (CraftWorld) world;
26 | Field f;
27 | f = CraftWorld.class.getDeclaredField("world");
28 |
29 | f.setAccessible(true);
30 | return (WorldServer) f.get(w);
31 |
32 | } catch (Exception e) {
33 | e.printStackTrace();
34 | }
35 |
36 | return null;
37 | }
38 |
39 | private static MinecraftServer GetMinecraftServer(Server server) {
40 |
41 | if (server instanceof CraftServer) {
42 | CraftServer cs = (CraftServer) server;
43 | Field f;
44 | try {
45 | f = CraftServer.class.getDeclaredField("console");
46 | } catch (NoSuchFieldException ex) {
47 | return null;
48 | } catch (SecurityException ex) {
49 | return null;
50 | }
51 | MinecraftServer ms;
52 | try {
53 | f.setAccessible(true);
54 | ms = (MinecraftServer) f.get(cs);
55 | } catch (IllegalArgumentException ex) {
56 | return null;
57 | } catch (IllegalAccessException ex) {
58 | return null;
59 | }
60 | return ms;
61 | }
62 | return null;
63 | }
64 |
65 | public static BasicHumanNpc SpawnBasicHumanNpc(myNPC parent, String uniqueId, String name, World world, double x, double y, double z, double yaw, double pitch) {
66 | try {
67 | WorldServer ws = GetWorldServer(world);
68 | MinecraftServer ms = GetMinecraftServer(ws.getServer());
69 |
70 | CHumanNpc eh = new CHumanNpc(ms, ws, name, new ItemInWorldManager(ws));
71 | eh.forceSetName(name);
72 | Float yaw2 = new Float(yaw);
73 | Float pitch2 = new Float(pitch);
74 |
75 | eh.setLocation(x, y, z, yaw2.floatValue(), pitch2.floatValue());
76 |
77 | int m = MathHelper.floor(eh.locX / 16.0D);
78 | int n = MathHelper.floor(eh.locZ / 16.0D);
79 |
80 | ws.getChunkAt(m, n).a(eh);
81 | ws.entityList.add(eh);
82 |
83 | // ws.b(eh);
84 | Class params[] = new Class[1];
85 | params[0] = Entity.class;
86 |
87 | Method method;
88 | method = net.minecraft.server.World.class.getDeclaredMethod("c", params);
89 | method.setAccessible(true);
90 | Object margs[] = new Object[1];
91 | margs[0] = eh;
92 | method.invoke(ws, margs);
93 |
94 | return new BasicHumanNpc(parent, eh, uniqueId, name, x, y, z, yaw2, pitch2);
95 |
96 | } catch (Exception e) {
97 | e.printStackTrace();
98 | }
99 |
100 | return null;
101 | }
102 |
103 | public static void RemoveBasicHumanNpc(BasicHumanNpc npc) {
104 | try {
105 | npc.getMCEntity().world.removeEntity(npc.getMCEntity());
106 | } catch (Exception e) {
107 | e.printStackTrace();
108 | }
109 |
110 | }
111 |
112 | public static LivingEntity SpawnMob(CreatureType type, World world, double x, double y, double z) {
113 | return world.spawnCreature(new org.bukkit.Location(world, x, y, z), type);
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/npcxEListener.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.logging.Logger;
6 |
7 | import net.gamerservices.npclibfork.BasicHumanNpc;
8 | import net.gamerservices.npclibfork.NpcEntityTargetEvent;
9 | import net.gamerservices.npclibfork.NpcSpawner;
10 | import net.gamerservices.npclibfork.NpcEntityTargetEvent.NpcTargetReason;
11 |
12 | import org.bukkit.craftbukkit.CraftServer;
13 | import org.bukkit.event.entity.*;
14 | import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
15 | import org.bukkit.entity.Entity;
16 | import org.bukkit.entity.LivingEntity;
17 | import org.bukkit.entity.Monster;
18 | import org.bukkit.entity.Player;
19 | import org.bukkit.entity.HumanEntity;
20 | import org.bukkit.entity.Zombie;
21 |
22 | public class npcxEListener extends EntityListener {
23 |
24 | private final npcx parent;
25 |
26 | public npcxEListener(npcx parent) {
27 | this.parent = parent;
28 | }
29 |
30 | @Override
31 | public void onEntityDamage(EntityDamageEvent event) {
32 | if (event.isCancelled()) { return; }
33 | if (event.getEntity() instanceof HumanEntity) {
34 |
35 | BasicHumanNpc npc = parent.npclist.getBasicHumanNpc(event.getEntity());
36 |
37 | if (npc != null) {
38 | npc.onDamage(event);
39 | }
40 |
41 | }
42 | }
43 |
44 | @Override
45 | public void onEntityDeath(EntityDeathEvent event) {
46 |
47 | if (event.getEntity() instanceof Monster) {
48 |
49 | // System.out.println("npcx : deregistered monster");
50 | this.parent.universe.monsters.remove((Monster) event.getEntity());
51 |
52 | }
53 | }
54 |
55 | @Override
56 | public void onEntityExplode(EntityExplodeEvent event) {
57 | if (event.isCancelled()) { return; }
58 |
59 | if (event.getEntity() instanceof Monster) {
60 |
61 | // System.out.println("npcx : deregistered monster");
62 |
63 | this.parent.universe.monsters.remove((Monster) event.getEntity());
64 |
65 | }
66 | if (this.parent.universe.nocreeper != null) {
67 | // creeper protection is on
68 | if (this.parent.universe.nocreeper.matches("true")) {
69 | // creeper events are bad
70 | event.setCancelled(true);
71 | }
72 | }
73 |
74 | }
75 |
76 | @Override
77 | public void onCreatureSpawn(CreatureSpawnEvent event) {
78 | if (event.isCancelled()) { return; }
79 | if (event.getEntity() instanceof Monster) {
80 | // System.out.println("npcx : registered monster");
81 | this.parent.universe.monsters.add((Monster) event.getEntity());
82 | }
83 | }
84 |
85 | @Override
86 | public void onEntityTarget(EntityTargetEvent event) {
87 |
88 | if (event.isCancelled()) { return; }
89 | // System.out.println("npcx : target onentityevent");
90 |
91 | if (event instanceof NpcEntityTargetEvent) {
92 | NpcEntityTargetEvent nevent = (NpcEntityTargetEvent) event;
93 |
94 | BasicHumanNpc npc = parent.npclist.getBasicHumanNpc(event.getEntity());
95 |
96 | // Targets player
97 | if (npc == null) {
98 |
99 | event.setCancelled(true);
100 | }
101 |
102 | if (npc != null && event.getTarget() instanceof Player) {
103 |
104 | if (nevent.getNpcReason() == NpcTargetReason.CLOSEST_PLAYER) {
105 |
106 | Player p = (Player) event.getTarget();
107 | npc.onClosestPlayer(p);
108 | event.setCancelled(true);
109 |
110 | } else if (nevent.getNpcReason() == NpcTargetReason.NPC_RIGHTCLICKED) {
111 | // System.out.println("npcx : reason of event was rightclicked");
112 |
113 | Player p = (Player) event.getTarget();
114 | npc.onRightClick(p);
115 |
116 | event.setCancelled(true);
117 |
118 | } else if (nevent.getNpcReason() == NpcTargetReason.NPC_BOUNCED) {
119 | Player p = (Player) event.getTarget();
120 | // do something here
121 | // p.sendMessage("<" + npc.getName() +
122 | // "> Stop bouncing on me!");
123 | npc.onBounce(p);
124 | event.setCancelled(true);
125 | }
126 | }
127 | }
128 |
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myPlayer.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.sql.PreparedStatement;
4 | import java.sql.ResultSet;
5 | import java.sql.Statement;
6 |
7 | import net.gamerservices.npclibfork.BasicHumanNpc;
8 |
9 | import org.bukkit.ChatColor;
10 | import org.bukkit.entity.Player;
11 |
12 | import com.iConomy.iConomy;
13 | import com.iConomy.system.Account;
14 |
15 | public class myPlayer {
16 |
17 | public npcx parent;
18 | public Player player;
19 | public BasicHumanNpc target;
20 | public boolean dead = false;
21 | public String name;
22 | public int zomgcount = 0;
23 | public myZone lastmyzone;
24 | public int lastchunkx;
25 | public int lastchunkz;
26 | public String lastchunkname;
27 | public boolean toggle = true;
28 | public boolean respawned = true;
29 | public int id;
30 |
31 | myPlayer(npcx parent, Player player, String name) {
32 | this.parent = parent;
33 | this.player = player;
34 | this.name = name;
35 | }
36 |
37 | public int getPlayerBalance(Player player) {
38 |
39 | try
40 | {
41 | if (parent.useiConomy && iConomy.getAccount(player.getName()) != null) {
42 | return (int) iConomy.getAccount(player.getName()).getHoldings().balance();
43 | }
44 | } catch (NoClassDefFoundError err)
45 | {
46 | return this.getNPCXBalance();
47 | }
48 | return this.getNPCXBalance();
49 | }
50 |
51 | public void subtractPlayerBalance(Player player, int totalcost) {
52 | try {
53 | Account account = iConomy.getAccount(player.getName());
54 | if (account != null && parent.useiConomy) {
55 | account.getHoldings().subtract(totalcost);
56 | } else {
57 | this.setNPCXBalance(this.getNPCXBalance() - totalcost);
58 | }
59 | } catch (NoClassDefFoundError e) {
60 | this.setNPCXBalance(this.getNPCXBalance() - totalcost);
61 | }
62 | }
63 |
64 | public void addPlayerBalance(Player player, int totalcost) {
65 | try {
66 | Account account = iConomy.getAccount(player.getName());
67 | if (account != null && parent.useiConomy) {
68 | account.getHoldings().add(totalcost);
69 | } else {
70 | this.setNPCXBalance(this.getNPCXBalance() + totalcost);
71 | }
72 | } catch (NoClassDefFoundError e) {
73 | // We don't have iConomy
74 | this.setNPCXBalance(this.getNPCXBalance() + totalcost);
75 | }
76 | }
77 |
78 | public boolean hasPlayerEnoughPlayerBalance(Player player, float totalcost) {
79 | try {
80 | if (parent.useiConomy) {
81 | Account account = iConomy.getAccount(player.getName());
82 | return account.getHoldings().hasEnough(totalcost);
83 | } else {
84 | if (this.getNPCXBalance() >= totalcost) {
85 | return true;
86 | } else {
87 | return false;
88 | }
89 | }
90 | } catch (NoClassDefFoundError e) {
91 | if (this.getNPCXBalance() >= totalcost) {
92 | return true;
93 | } else {
94 | return false;
95 | }
96 | }
97 | }
98 |
99 | public int getNPCXBalance() {
100 | try {
101 | PreparedStatement stmtNPC = this.parent.universe.conn.prepareStatement("SELECT coin FROM player WHERE name = ? LIMIT 1;");
102 | stmtNPC.setString(1, this.player.getName());
103 | stmtNPC.executeQuery();
104 | ResultSet rsNPC = stmtNPC.getResultSet();
105 | while (rsNPC.next()) {
106 | return rsNPC.getInt("coin");
107 | }
108 | rsNPC.close();
109 | stmtNPC.close();
110 |
111 | return 0;
112 | } catch (Exception e) {
113 | e.printStackTrace();
114 | return 0;
115 | }
116 |
117 | }
118 |
119 | public boolean setNPCXBalance(int amount) {
120 | try {
121 | PreparedStatement stmt = this.parent.universe.conn.prepareStatement("INSERT INTO player (coin,name) VALUES (?,?) ON DUPLICATE KEY UPDATE coin=VALUES(coin) ", Statement.RETURN_GENERATED_KEYS);
122 | stmt.setInt(1, amount);
123 | stmt.setString(2, this.player.getName());
124 |
125 | stmt.executeUpdate();
126 | ResultSet keyset = stmt.getGeneratedKeys();
127 | int key = 0;
128 | if (keyset.next()) {
129 | // Retrieve the auto generated key(s).
130 | key = keyset.getInt(1);
131 |
132 | }
133 | stmt.close();
134 | } catch (Exception e) {
135 | e.printStackTrace();
136 | return false;
137 | }
138 |
139 | return false;
140 | }
141 |
142 | public boolean updateFactionNegative(myFaction faction) {
143 | try {
144 | for (myPlayer_factionentry f : this.parent.universe.playerfactions.values()) {
145 | if (f.factionid == faction.id && f.playername.equals(this.player.getName())) {
146 | f.amount = f.amount - 1;
147 | return true;
148 | }
149 | }
150 |
151 | // Doesn't exist so lets make a new one
152 | myPlayer_factionentry fe = createFactionEntry(faction.id, faction.name, this.player.getName(), -1);
153 |
154 | if (fe != null) {
155 | this.parent.universe.playerfactions.put(Integer.toString(fe.id), fe);
156 | return true;
157 | } else {
158 | // didn't find an entry
159 | return false;
160 | }
161 | } catch (Exception e) {
162 | e.printStackTrace();
163 | return false;
164 | }
165 | }
166 |
167 | private myPlayer_factionentry createFactionEntry(int factionid, String factionname, String playername, int amount) {
168 | try {
169 | PreparedStatement stmt = this.parent.universe.conn.prepareStatement("INSERT INTO player_faction (player_name,faction_id,amount) VALUES (?,?,?) ON DUPLICATE KEY UPDATE amount=amount+VALUES(amount) ", Statement.RETURN_GENERATED_KEYS);
170 | stmt.setString(1, this.player.getName());
171 | stmt.setInt(2, factionid);
172 | stmt.setInt(3, amount);
173 | stmt.executeUpdate();
174 | ResultSet keyset = stmt.getGeneratedKeys();
175 | int key = 0;
176 | if (keyset.next()) {
177 | // Retrieve the auto generated key(s).
178 | key = keyset.getInt(1);
179 | }
180 | myPlayer_factionentry m = new myPlayer_factionentry();
181 | m.id = key;
182 | m.playername = playername;
183 | m.factionid = factionid;
184 | m.amount = amount;
185 | return m;
186 | } catch (Exception e) {
187 | e.printStackTrace();
188 | return null;
189 | }
190 | }
191 |
192 | public int getPlayerFactionStandingWithBase(myFaction faction) {
193 | try {
194 | for (myPlayer_factionentry e : this.parent.universe.playerfactions.values()) {
195 | if (e.playername.equals(this.player.getName()) && e.factionid == faction.id) {
196 | if (e.factionid == faction.id) { return e.amount + faction.base; }
197 | }
198 | }
199 | // cant find any specific entries lets just return their base
200 | return faction.base;
201 | } catch (Exception e) {
202 | // cant find any specific entries lets just return their base
203 | e.printStackTrace();
204 | return faction.base;
205 | }
206 |
207 | }
208 |
209 | public void updateFactionPositive(myPlayer player, myNPC npc) {
210 | for (myFactionEntry n : this.parent.universe.factionentries.values()) {
211 | if (n.targetfactionid == npc.faction.id) {
212 | if (n.amount < 0) {
213 | // found a faction that hates this npcs faction, lets give
214 | // the player positive faction with them
215 | myFaction faction = this.parent.getFactionByID(n.factionid);
216 |
217 | try {
218 | int count = 0;
219 | for (myPlayer_factionentry f : this.parent.universe.playerfactions.values()) {
220 | if (f.factionid == n.factionid && f.playername.equals(this.player.getName())) {
221 | f.amount = f.amount + 1;
222 | player.player.sendMessage(ChatColor.YELLOW + "* Your standing with " + faction.name + " has gotten better!");
223 | count++;
224 | }
225 | }
226 |
227 | if (count == 0) {
228 | // Doesn't exist so lets make a new one
229 | myPlayer_factionentry fe = createFactionEntry(n.factionid, faction.name, this.player.getName(), 1);
230 |
231 | if (fe != null) {
232 | // created entry
233 | count++;
234 | this.parent.universe.playerfactions.put(Integer.toString(fe.id), fe);
235 | player.player.sendMessage(ChatColor.YELLOW + "* Your standing with " + faction.name + " has gotten better!");
236 | } else {
237 | // didn't find an entry
238 |
239 | }
240 | }
241 | } catch (Exception e) {
242 | e.printStackTrace();
243 | }
244 | }
245 | }
246 | }
247 | }
248 | }
249 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/npcxPListener.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.util.logging.Logger;
4 |
5 | import net.gamerservices.npclibfork.BasicHumanNpc;
6 | import net.gamerservices.npclibfork.NpcEntityTargetEvent;
7 | import net.gamerservices.npclibfork.NpcSpawner;
8 | import net.gamerservices.npclibfork.NpcEntityTargetEvent.NpcTargetReason;
9 |
10 | import org.bukkit.ChatColor;
11 | import org.bukkit.Chunk;
12 | import org.bukkit.Location;
13 | import org.bukkit.craftbukkit.CraftServer;
14 | import org.bukkit.event.block.Action;
15 | import org.bukkit.event.entity.*;
16 | import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
17 | import org.bukkit.event.player.PlayerChatEvent;
18 | import org.bukkit.event.player.PlayerEvent;
19 | import org.bukkit.event.player.PlayerInteractEvent;
20 | import org.bukkit.event.player.PlayerJoinEvent;
21 | import org.bukkit.event.player.PlayerListener;
22 | import org.bukkit.event.player.PlayerLoginEvent;
23 | import org.bukkit.event.player.PlayerMoveEvent;
24 | import org.bukkit.event.player.PlayerQuitEvent;
25 | import org.bukkit.event.player.PlayerRespawnEvent;
26 | import org.bukkit.event.player.PlayerTeleportEvent;
27 | import org.bukkit.entity.Player;
28 | import org.bukkit.entity.HumanEntity;
29 |
30 | public class npcxPListener extends PlayerListener {
31 |
32 | private final npcx parent;
33 |
34 | public npcxPListener(npcx parent) {
35 | this.parent = parent;
36 | }
37 |
38 | public void onPlayerMove(PlayerMoveEvent event) {
39 | if (event.isCancelled()) { return; }
40 | if (this.parent.universe.nations.matches("true")) {
41 |
42 | // natiosn chunk checking
43 | // Area Coordinate = round down ( ( position / areasize ) + 0.9375 )
44 | int xchunkloc = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getX());
45 | int zchunkloc = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getZ());
46 | // event.getPlayer().sendMessage(xchunkloc+":"+zchunkloc);
47 |
48 | int lastx = this.parent.universe.getPlayerLastChunkX(event.getPlayer());
49 | int lastz = this.parent.universe.getPlayerLastChunkZ(event.getPlayer());
50 | String lastname = this.parent.universe.getPlayerLastChunkName(event.getPlayer());
51 | // event.getPlayer().sendMessage("Zone: "+xchunkloc+":"+zchunkloc+" - from:"+
52 | // lastx + ":" + lastz);
53 | if (lastx != xchunkloc || lastz != zchunkloc) {
54 | // new position!
55 | int x = xchunkloc;
56 | int z = zchunkloc;
57 | myZone zone = this.parent.universe.getZoneFromLoc(x, z, event.getPlayer().getWorld());
58 | if (zone != null) {
59 | if (lastname != null) {
60 | if (!zone.name.equals(lastname)) {
61 | if (this.parent.universe.getPlayerToggle(event.getPlayer()).equals("true")) {
62 |
63 | if (zone.ownername.equals("")) {
64 | event.getPlayer().sendMessage("Zone: [" + ChatColor.LIGHT_PURPLE + "" + xchunkloc + ":" + zchunkloc + "" + ChatColor.WHITE + "] - " + ChatColor.YELLOW + "for sale" + " toggle with /civ");
65 |
66 | } else {
67 | event.getPlayer().sendMessage("[" + ChatColor.LIGHT_PURPLE + "" + xchunkloc + ":" + zchunkloc + "" + ChatColor.WHITE + "] " + ChatColor.LIGHT_PURPLE + "" + zone.name + "" + ChatColor.WHITE + " Owner: " + ChatColor.YELLOW + "" + zone.ownername + " toggle this with /civ");
68 | }
69 |
70 | }
71 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
72 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
73 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), zone.name);
74 |
75 | } else {
76 | // skip we've been here recently
77 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
78 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
79 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), zone.name);
80 | }
81 | } else {
82 | // dont provide them info, just update them
83 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
84 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
85 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), zone.name);
86 | }
87 | }
88 | } else {
89 | // Already this value
90 | }
91 | }
92 | }
93 |
94 | public void onPlayerTeleport(PlayerTeleportEvent event) {
95 | if (event.isCancelled()) { return; }
96 | if (this.parent.universe.nations.matches("true")) {
97 |
98 | // natiosn chunk checking
99 | // Area Coordinate = round down ( ( position / areasize ) + 0.9375 )
100 | int xchunkloc = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getX());
101 | int zchunkloc = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getZ());
102 | // event.getPlayer().sendMessage(xchunkloc+":"+zchunkloc);
103 |
104 | int lastx = this.parent.universe.getPlayerLastChunkX(event.getPlayer());
105 | int lastz = this.parent.universe.getPlayerLastChunkZ(event.getPlayer());
106 | String lastname = this.parent.universe.getPlayerLastChunkName(event.getPlayer());
107 | // event.getPlayer().sendMessage("Zone: "+xchunkloc+":"+zchunkloc+" - from:"+
108 | // lastx + ":" + lastz);
109 | if (lastx != xchunkloc || lastz != zchunkloc) {
110 | // new position!
111 | int x = xchunkloc;
112 | int z = zchunkloc;
113 | myZone zone = this.parent.universe.getZoneFromLoc(x, z, event.getPlayer().getWorld());
114 | if (zone != null) {
115 | if (lastname != null) {
116 | if (!zone.name.matches(lastname)) {
117 | if (zone.ownername.matches("")) {
118 | event.getPlayer().sendMessage("Zone: [" + ChatColor.LIGHT_PURPLE + "" + xchunkloc + ":" + zchunkloc + "" + ChatColor.WHITE + "] - " + ChatColor.YELLOW + "for sale");
119 |
120 | } else {
121 | event.getPlayer().sendMessage("[" + ChatColor.LIGHT_PURPLE + "" + xchunkloc + ":" + zchunkloc + "" + ChatColor.WHITE + "] " + ChatColor.LIGHT_PURPLE + "" + zone.name + "" + ChatColor.WHITE + " Owner: " + ChatColor.YELLOW + "" + zone.ownername);
122 | }
123 |
124 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
125 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
126 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), zone.name);
127 |
128 | } else {
129 | // skip we've been here recently
130 | }
131 | } else {
132 | // dont provide them info, just update them
133 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
134 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
135 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), zone.name);
136 | }
137 | }
138 | } else {
139 |
140 | }
141 | }
142 | }
143 |
144 | public void onPlayerInteract(PlayerInteractEvent event) {
145 | if (event.isCancelled()) { return; }
146 | if (this.parent.universe.nations != null) {
147 | if (this.parent.universe.nations.equals("true")) {
148 |
149 | if (!this.parent.isAdmin(event.getPlayer())) {
150 | if (this.parent.universe.nowild != null) {
151 | if (this.parent.universe.nowild.matches("true")) {
152 | try {
153 | for (myPlayer player : parent.universe.players.values()) {
154 | if (player.player == event.getPlayer()) {
155 |
156 | Location loc = event.getClickedBlock().getLocation();
157 | Chunk chunk = loc.getWorld().getChunkAt(loc);
158 | int x = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getX());
159 | int z = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getZ());
160 | String owner = "";
161 | int zoneid = 0;
162 | for (myZone zone : this.parent.universe.zones) {
163 | if (zone.x == x && zone.z == z) {
164 | owner = zone.ownername;
165 | zoneid = zone.id;
166 | }
167 | }
168 |
169 | if (player.player.getName().matches(owner)) {
170 | return;
171 | } else {
172 | // Are they a member?
173 | if (zoneid != 0) {
174 | if (this.parent.universe.isZoneMember(zoneid, event.getPlayer().getName())) { return; }
175 | }
176 | event.getPlayer().sendMessage(ChatColor.RED + "You are not in the wild or in an area you own (" + x + ":" + z + ")!");
177 | event.setCancelled(true);
178 | }
179 | }
180 | }
181 | } catch (Exception e) {
182 | // locked table
183 | event.setCancelled(true);
184 | }
185 |
186 | } else {
187 | // False - we dont want to our wild areas or are
188 | // using some other system
189 |
190 | try {
191 | for (myPlayer player : parent.universe.players.values()) {
192 | if (player.player == event.getPlayer()) {
193 |
194 | Location loc = event.getClickedBlock().getLocation();
195 | Chunk chunk = loc.getWorld().getChunkAt(loc);
196 | int x = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getX());
197 | int zoneid = 0;
198 |
199 | int z = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getZ());
200 | String owner = "";
201 | for (myZone zone : this.parent.universe.zones) {
202 | if (zone.x == x && zone.z == z) {
203 | owner = zone.ownername;
204 | zoneid = zone.id;
205 | }
206 | }
207 |
208 | if (player.player.getName().matches(owner)) {
209 | return;
210 | } else {
211 | if (owner.matches("")) {
212 | // wild is ok
213 | // event.getPlayer().sendMessage(ChatColor.RED+"You are not in the wild or in an area you own ("+x+":"+z+")!");
214 | return;
215 | } else {
216 | // Are they a member?
217 | if (zoneid != 0) {
218 | if (this.parent.universe.isZoneMember(zoneid, event.getPlayer().getName())) { return; }
219 | }
220 | event.getPlayer().sendMessage(ChatColor.RED + "You are not in the wild or in an area you own (" + x + ":" + z + ")!");
221 | event.setCancelled(true);
222 | return;
223 | }
224 | }
225 | }
226 | }
227 |
228 | // Can't find player so assume they cant change
229 | event.getPlayer().sendMessage(ChatColor.RED + "No player located, you have been denied");
230 | this.parent.fixDead();
231 | event.setCancelled(true);
232 | return;
233 |
234 | } catch (Exception e) {
235 | // locked table
236 | event.setCancelled(true);
237 | }
238 | }
239 |
240 | } else {
241 | // No setting NOWILD found, assume we dont want to
242 | // protect or are using some other system
243 | try {
244 | for (myPlayer player : parent.universe.players.values()) {
245 | if (player.player == event.getPlayer()) {
246 |
247 | Location loc = event.getClickedBlock().getLocation();
248 | Chunk chunk = loc.getWorld().getChunkAt(loc);
249 | int x = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getX());
250 | int z = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getZ());
251 | String owner = "";
252 | int zoneid = 0;
253 | for (myZone zone : this.parent.universe.zones) {
254 | if (zone.x == x && zone.z == z) {
255 | owner = zone.ownername;
256 | zoneid = zone.id;
257 | }
258 | }
259 |
260 | if (player.player.getName().matches(owner)) {
261 | return;
262 | } else {
263 | if (owner.matches("")) {
264 | // wild is ok
265 | return;
266 | } else {
267 | // Are they a member?
268 | if (zoneid != 0) {
269 | if (this.parent.universe.isZoneMember(zoneid, event.getPlayer().getName())) {
270 | // member is ok
271 | return;
272 | }
273 | }
274 | // not member is denied
275 | event.getPlayer().sendMessage(ChatColor.RED + "You are not in the wild or in an area you own (" + x + ":" + z + ")!");
276 | event.setCancelled(true);
277 | }
278 | }
279 | }
280 | }
281 |
282 | // Can't find player so assume they cant change
283 | this.parent.fixDead();
284 | event.getPlayer().sendMessage(ChatColor.RED + "No player located, you have been denied");
285 | event.setCancelled(true);
286 | return;
287 |
288 | } catch (Exception e) {
289 | // locked table
290 | event.setCancelled(true);
291 | return;
292 | }
293 | }
294 | } else {
295 | // Is an Operator
296 | return;
297 | }
298 | }
299 | // is not running Nations
300 | // event.setCancelled(true);
301 | return;
302 |
303 | }
304 | return;
305 |
306 | // is not running Nations
307 | // event.setCancelled(true);
308 |
309 | }
310 |
311 | public void onPlayerJoin(PlayerJoinEvent event) {
312 |
313 | myPlayer player = new myPlayer(this.parent, event.getPlayer(), event.getPlayer().getName());
314 |
315 | int count = 0;
316 | for (myPlayer p : this.parent.universe.players.values()) {
317 | // System.out.println("Testing " + p.name +
318 | // " against actual player: " + event.getPlayer().getName());
319 | if (p.name.equals(event.getPlayer().getName())) {
320 | // attach them
321 | // System.out.println("Attaching player");
322 | p.player = event.getPlayer();
323 | count++;
324 | }
325 | }
326 |
327 | // this player wasnt matched up
328 | if (count == 0) {
329 | // System.out.println("npcx : added new player ("+
330 | // event.getPlayer().getName()+")");
331 | parent.universe.players.put(player.name, player);
332 |
333 | parent.universe.dbCreatePlayer(player);
334 |
335 | }
336 |
337 | // check nation stuff
338 |
339 | if (this.parent.universe.nations.matches("true")) {
340 | // Area Coordinate = round down ( ( position / areasize ) + 0.9375 )
341 | int xchunkloc = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getX());
342 | int zchunkloc = this.parent.universe.getZoneCoord(event.getPlayer().getLocation().getZ());
343 | // event.getPlayer().sendMessage(xchunkloc+":"+zchunkloc);
344 |
345 | // new position!
346 | int x = xchunkloc;
347 | int z = zchunkloc;
348 |
349 | myZone zone = this.parent.universe.getZoneFromLoc(x, z, event.getPlayer().getWorld());
350 | if (zone != null) {
351 |
352 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
353 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
354 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), zone.name);
355 |
356 | } else {
357 | // dont provide them info, just update them
358 | this.parent.universe.setPlayerLastChunkX(event.getPlayer(), xchunkloc);
359 | this.parent.universe.setPlayerLastChunkZ(event.getPlayer(), zchunkloc);
360 | this.parent.universe.setPlayerLastChunkName(event.getPlayer(), "Unknown Zone");
361 |
362 | }
363 |
364 | event.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE + "This server runs " + ChatColor.YELLOW + "NPCX" + ChatColor.LIGHT_PURPLE + " with Civilizations enabled!");
365 | event.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE + "To claim your own piece of paradise use /civ buy!");
366 | }
367 |
368 | }
369 |
370 | public void onPlayerChat(PlayerChatEvent event) {
371 | if (event.isCancelled()) { return; }
372 | for (myPlayer player : parent.universe.players.values()) {
373 | if (player.player == event.getPlayer()) {
374 | if (player.target != null) {
375 |
376 | // System.out.println("npcx : player chat event ("+
377 | // player.player.getName()+")");
378 | player.player.sendMessage("You say to " + player.target.getName() + ", '" + event.getMessage() + "'");
379 |
380 | if (player.target.parent != null) {
381 | // this is not a temporary spawn
382 |
383 | // does it have a category set?
384 | if (player.target.parent.category != null) {
385 |
386 | // check what type of category it is
387 | if (player.target.parent.category.matches("merchant")) {
388 | // merchant
389 | player.target.parent.onPlayerChat(player, event.getMessage(), "merchant");
390 |
391 | } else {
392 | // normal chat event / unknown category
393 | player.target.parent.onPlayerChat(player, event.getMessage(), "");
394 | }
395 | } else {
396 | // normal chat event
397 | player.target.parent.onPlayerChat(player, event.getMessage(), "");
398 | }
399 | } else {
400 | player.player.sendMessage("You cannot talk to temporary spawns");
401 | }
402 | event.setCancelled(true);
403 | }
404 | }
405 | }
406 | }
407 |
408 | public void onPlayerRespawn(PlayerRespawnEvent event) {
409 |
410 | for (myPlayer player : parent.universe.players.values()) {
411 | if (player.player == event.getPlayer()) {
412 |
413 | player.respawned = true;
414 | }
415 | }
416 |
417 | }
418 |
419 | public void onPlayerQuit(PlayerQuitEvent event) {
420 |
421 | for (myPlayer player : parent.universe.players.values()) {
422 | if (player.player == event.getPlayer()) {
423 |
424 | player.dead = true;
425 | player.respawned = false;
426 | this.parent.informNpcDeadPlayer(event.getPlayer());
427 |
428 | // System.out.println("npcx : removed player ("+
429 | // player.player.getName()+")");
430 | // not needed
431 | // parent.universe.players.remove(player);
432 | }
433 | }
434 |
435 | }
436 | }
437 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | npcx License
2 | -----------------
3 | GNU GENERAL PUBLIC LICENSE
4 |
5 | Version 3, 29 June 2007
6 |
7 | Copyright © 2007 Free Software Foundation, Inc.
8 |
9 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
10 |
11 | Preamble
12 |
13 | The GNU General Public License is a free, copyleft license for software and other kinds of works.
14 |
15 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
16 |
17 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
18 |
19 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
20 |
21 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
22 |
23 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
24 |
25 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
26 |
27 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
28 |
29 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
30 |
31 | The precise terms and conditions for copying, distribution and modification follow.
32 |
33 | TERMS AND CONDITIONS
34 |
35 | 0. Definitions.
36 |
37 | “This License” refers to version 3 of the GNU General Public License.
38 |
39 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
40 |
41 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
42 |
43 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
44 |
45 | A “covered work” means either the unmodified Program or a work based on the Program.
46 |
47 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
48 |
49 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
50 |
51 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
52 |
53 | 1. Source Code.
54 |
55 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
56 |
57 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
58 |
59 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
60 |
61 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
62 |
63 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
64 |
65 | The Corresponding Source for a work in source code form is that same work.
66 |
67 | 2. Basic Permissions.
68 |
69 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
70 |
71 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
72 |
73 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
74 |
75 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
76 |
77 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
78 |
79 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
80 |
81 | 4. Conveying Verbatim Copies.
82 |
83 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
84 |
85 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
86 |
87 | 5. Conveying Modified Source Versions.
88 |
89 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
90 |
91 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
92 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
93 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
94 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
95 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
96 |
97 | 6. Conveying Non-Source Forms.
98 |
99 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
100 |
101 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
102 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
103 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
104 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
105 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
106 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
107 |
108 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
109 |
110 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
111 |
112 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
113 |
114 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
115 |
116 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
117 |
118 | 7. Additional Terms.
119 |
120 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
121 |
122 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
123 |
124 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
125 |
126 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
127 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
128 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
129 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
130 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
131 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
132 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
133 |
134 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
135 |
136 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
137 |
138 | 8. Termination.
139 |
140 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
141 |
142 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
143 |
144 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
145 |
146 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
147 |
148 | 9. Acceptance Not Required for Having Copies.
149 |
150 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
151 |
152 | 10. Automatic Licensing of Downstream Recipients.
153 |
154 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
155 |
156 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
157 |
158 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
159 |
160 | 11. Patents.
161 |
162 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
163 |
164 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
165 |
166 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
167 |
168 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
169 |
170 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
171 |
172 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
173 |
174 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
175 |
176 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
177 |
178 | 12. No Surrender of Others' Freedom.
179 |
180 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
181 |
182 | 13. Use with the GNU Affero General Public License.
183 |
184 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
185 |
186 | 14. Revised Versions of this License.
187 |
188 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
189 |
190 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
191 |
192 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
193 |
194 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
195 |
196 | 15. Disclaimer of Warranty.
197 |
198 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
199 |
200 | 16. Limitation of Liability.
201 |
202 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
203 |
204 | 17. Interpretation of Sections 15 and 16.
205 |
206 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
--------------------------------------------------------------------------------
/src/net/gamerservices/npclibfork/BasicHumanNpc.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npclibfork;
2 |
3 | import net.gamerservices.npcx.*;
4 |
5 | import java.io.Console;
6 | import java.lang.reflect.Field;
7 | import java.util.ArrayList;
8 | import java.util.Iterator;
9 | import java.util.List;
10 | import java.util.logging.Logger;
11 | import net.minecraft.server.EntityLiving;
12 |
13 | import org.bukkit.Location;
14 | import org.bukkit.Material;
15 | import org.bukkit.block.Block;
16 | import org.bukkit.craftbukkit.entity.CraftLivingEntity;
17 | import org.bukkit.entity.Entity;
18 | import org.bukkit.entity.HumanEntity;
19 | import org.bukkit.entity.LivingEntity;
20 | import org.bukkit.entity.Monster;
21 | import org.bukkit.entity.Player;
22 | import org.bukkit.entity.Skeleton;
23 | import org.bukkit.entity.Spider;
24 | import org.bukkit.entity.Zombie;
25 | import org.bukkit.event.entity.EntityDamageByEntityEvent;
26 | import org.bukkit.event.entity.EntityDamageEvent;
27 | import org.bukkit.util.BlockIterator;
28 | import org.bukkit.util.Vector;
29 |
30 | public class BasicHumanNpc extends BasicNpc {
31 |
32 | private LivingEntity mFollow;
33 | public LivingEntity mAggro;
34 | public int hp = 200;
35 | public int dmg = 3;
36 | public double spawnx;
37 | public double spawny;
38 | public double spawnz;
39 | public float spawnyaw;
40 | public float spawnpitch;
41 |
42 | public double seekx;
43 | public double seeky;
44 | public double seekz;
45 | public double seekyaw;
46 | public double seekpitch;
47 | public Block lastloc;
48 | public int stuck;
49 | public CHumanNpc mcEntity;
50 | private static final Logger logger = Logger.getLogger("Minecraft");
51 | public myNPC parent;
52 | private boolean dead = false;
53 |
54 | public BasicHumanNpc(myNPC parent, CHumanNpc entity, String uniqueId, String name, double spawnx, double spawny, double spawnz, float spawnyaw, float spawnpitch) {
55 | super(uniqueId, name);
56 | this.parent = parent;
57 | this.spawnx = spawnx;
58 | this.spawny = spawny;
59 | this.spawnz = spawnz;
60 | this.spawnyaw = spawnyaw;
61 | this.spawnpitch = spawnpitch;
62 | this.mcEntity = entity;
63 | }
64 |
65 | public HumanEntity getBukkitEntity() {
66 | return (HumanEntity) this.mcEntity.getBukkitEntity();
67 | }
68 |
69 | public LivingEntity getAggro() {
70 | return this.mAggro;
71 |
72 | }
73 |
74 | public LivingEntity getFollow() {
75 | return this.mFollow;
76 |
77 | }
78 |
79 | public void setAggro(LivingEntity aggro) {
80 | if (this.stuck == 0) {
81 | // Start my stuck check timer
82 | this.stuck = 1;
83 | }
84 |
85 | this.mAggro = aggro;
86 |
87 | }
88 |
89 | public void setFollow(LivingEntity aggro) {
90 | if (this.stuck == 0) {
91 | // Start my stuck check timer
92 | this.stuck = 1;
93 | }
94 |
95 | this.mFollow = aggro;
96 |
97 | }
98 |
99 | protected CHumanNpc getMCEntity() {
100 | return this.mcEntity;
101 | }
102 |
103 | public void checkNotStuck() {
104 | if (stuck > 350) {
105 | this.setFollow(null);
106 | this.setAggro(null);
107 | this.stuck = 0;
108 | Location loc = new Location(this.getBukkitEntity().getWorld(), spawnx, spawny, spawnz, spawnyaw, spawnpitch);
109 | this.forceMove(loc);
110 |
111 | } else {
112 | if (stuck == 0) {
113 | // do nothing im fine
114 | } else {
115 | // am i away from spawn?
116 | double x = this.getBukkitEntity().getLocation().getX();
117 | double y = this.getBukkitEntity().getLocation().getY();
118 | double z = this.getBukkitEntity().getLocation().getZ();
119 |
120 | if (x != spawnx || y != spawny || z != spawnz) {
121 | stuck++;
122 | }
123 |
124 | }
125 |
126 | }
127 | }
128 |
129 | public void doThinkGreater() {
130 | if (this.hp > 0) {
131 | // System.out.println("npcx : think");
132 | if (this.parent != null) {
133 | //
134 | // PLAYER TARGET DISTANCE
135 | //
136 | for (myPlayer p : this.parent.parent.universe.players.values()) {
137 | if (p.target == this) {
138 | double x1 = p.player.getLocation().getX();
139 | double y1 = p.player.getLocation().getY();
140 | double z1 = p.player.getLocation().getZ();
141 |
142 | double x2 = this.getBukkitEntity().getLocation().getX();
143 | double y2 = this.getBukkitEntity().getLocation().getY();
144 | double z2 = this.getBukkitEntity().getLocation().getZ();
145 | int xdist = (int) (x1 - x2);
146 | int ydist = (int) (y1 - y2);
147 | int zdist = (int) (z1 - z2);
148 |
149 | if ((xdist < -3 || xdist > 3) || (ydist < -3 || ydist > 3) || (zdist < -3 || zdist > 3)) {
150 | Debug(1, "player out of range, removing target");
151 | p.target = null;
152 | p.player.sendMessage("You have lost your target");
153 | }
154 | // remove target
155 | }
156 | }
157 |
158 | // END PLAYER TARGET DISTANCE
159 | }
160 | // NPC RETURN TO SPAWN IDLE
161 | if (this.parent.pathgroup != null) {
162 | // let them carry on for guard sequences
163 |
164 | // return;
165 | } else {
166 |
167 | if (getFollow() == null && getAggro() == null) {
168 | // System.out.println("npcx : moving ["+ spawnx + "] ["+
169 | // spawny + "] ["+ spawnz + "]");
170 | // Requip my armour
171 | this.parent.requipArmour();
172 |
173 | // not aggrod or following, time to go home :)
174 | double x2 = this.getBukkitEntity().getLocation().getX();
175 | double y2 = this.getBukkitEntity().getLocation().getY();
176 | double z2 = this.getBukkitEntity().getLocation().getZ();
177 |
178 | if (!(x2 == spawnx && y2 == spawny && z2 == spawnz)) {
179 |
180 | // System.out.println("Going home");
181 |
182 | Double yaw2 = new Double(spawnyaw);
183 | Double pitch2 = new Double(spawnpitch);
184 |
185 | Location loc = new Location(this.getBukkitEntity().getWorld(), spawnx, spawny, spawnz, yaw2.floatValue(), pitch2.floatValue());
186 |
187 | moveCloserToLocation(loc);
188 |
189 | }
190 | }
191 | }
192 |
193 | //
194 | // NPC FOLLOW
195 | //
196 |
197 | if (getFollow() instanceof LivingEntity) {
198 | if (this.getFollow() != null) {
199 | Debug(1, this.getName() + ":follow:" + getFollow().toString() + ":" + getFollow().getHealth());
200 | // lets follow this entity
201 | if (this.hp == 0 || this.getFollow().getHealth() == 0) {
202 |
203 | // they're dead, stop following
204 | this.setFollow(null);
205 | this.setAggro(null);
206 |
207 | } else {
208 | Location locforface = this.getFaceLocationFromMe(getFollow().getLocation());
209 | Location modifiedloc = new Location(getBukkitEntity().getWorld(), getBukkitEntity().getLocation().getX(), getBukkitEntity().getLocation().getY(), getBukkitEntity().getLocation().getZ(), locforface.getYaw(), locforface.getPitch());
210 | forceMove(modifiedloc);
211 |
212 | Debug(1, this.getName() + ":follow:" + getFollow().toString() + ":" + getFollow().getHealth());
213 |
214 | // they're alive lets check distance
215 | double x1 = this.getFollow().getLocation().getX();
216 | double y1 = this.getFollow().getLocation().getY();
217 | double z1 = this.getFollow().getLocation().getZ();
218 |
219 | double x2 = this.getBukkitEntity().getLocation().getX();
220 | double y2 = this.getBukkitEntity().getLocation().getY();
221 | double z2 = this.getBukkitEntity().getLocation().getZ();
222 | int xdist = (int) (x1 - x2);
223 | int ydist = (int) (y1 - y2);
224 | int zdist = (int) (z1 - z2);
225 |
226 | if (xdist > -30 && xdist < 30 && ydist > -30 && ydist < 30 && zdist > -30 && zdist < 30) {
227 | // face target
228 | // this.getFaceLocationFromMe(this.getFollow().getLocation());
229 |
230 | if (isLineOfSight(this.getFollow())) {
231 | Debug(1, this.getName() + ":Following Entity near to me");
232 | this.moveCloserToLocation(this.getFollow().getLocation());
233 |
234 | } else {
235 | Debug(1, this.getName() + ":Stopped following near to me (no line of sight)");
236 | this.setFollow(null);
237 | this.setAggro(null);
238 | }
239 | } else {
240 | // too far for me
241 | Debug(1, this.getName() + ":Stopped following near to me (too far)");
242 | this.setFollow(null);
243 | this.setAggro(null);
244 | }
245 | }
246 | }
247 | }
248 |
249 | //
250 | // NPC ATTACK
251 | //
252 |
253 | if (getAggro() instanceof LivingEntity) {
254 | // lets follow this entity
255 | if (this.getAggro() != null) {
256 | if (this.hp == 0) {
257 | this.setFollow(null);
258 | this.setAggro(null);
259 | } else {
260 | attackLivingEntity(getAggro());
261 | }
262 | }
263 | }
264 | }
265 | }
266 |
267 | public boolean isLineOfSight(LivingEntity follow) {
268 | // Are they in a line of sight?
269 |
270 | if (this.getBukkitEntity() != null) {
271 | Location higherloc = this.getFollow().getLocation();
272 | higherloc.setY(higherloc.getY() + 1);
273 | Block h = this.getBukkitEntity().getWorld().getBlockAt(higherloc);
274 |
275 | try {
276 |
277 | List list = this.getBukkitEntity().getLineOfSight(null, 8);
278 | if (list != null) {
279 | for (Block b : list) {
280 | if (b == h) { return true; }
281 | }
282 | }
283 | } catch (IllegalStateException e) {
284 | return false;
285 | } catch (NullPointerException e) {
286 | return false;
287 | }
288 | }
289 |
290 | return false;
291 |
292 | }
293 |
294 | public Location getFaceLocationFromMe(Location location) {
295 | try {
296 | // citizens - https://github.com/fullwall/Citizens
297 | Location loc = this.getBukkitEntity().getLocation();
298 | double xDiff = location.getX() - loc.getX();
299 | double yDiff = location.getY() - loc.getY();
300 | double zDiff = location.getZ() - loc.getZ();
301 |
302 | double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
303 | double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
304 | double yaw = (Math.acos(xDiff / DistanceXZ) * 180 / Math.PI);
305 | double pitch = (Math.acos(yDiff / DistanceY) * 180 / Math.PI) - 90;
306 | if (zDiff < 0.0) {
307 | yaw = yaw + (Math.abs(180 - yaw) * 2);
308 | }
309 | Location finalloc = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), (float) yaw - 90, (float) pitch);
310 | return finalloc;
311 |
312 | } catch (Exception e) {
313 | e.printStackTrace();
314 | return null;
315 | }
316 | }
317 |
318 | public void doThinkLesser() {
319 |
320 | if (this.parent != null) {
321 | Debug(1, "doThinkLesser:Checking if pathgroup is not null");
322 |
323 | if (this.parent.pathgroup != null) {
324 | Debug(1, "doThinkLesser:Path group was NOT null");
325 | doPathgroups();
326 | }
327 | }
328 |
329 | // How long have i been away from spawn?
330 | checkNotStuck();
331 | }
332 |
333 | //
334 | // PATHGROUPS
335 | //
336 |
337 | private void doPathgroups() {
338 |
339 | Debug(1, "doPathgroups:Begun:Countdown: " + this.parent.movecountdown);
340 | if (this.parent.movecountdown == 0) {
341 | // It's time to execute
342 |
343 | // Are they on a pathspot?
344 | if (this.parent.currentpathspot < 1) {
345 | // In a pathgroup but not in a pathspot! Fix it
346 | this.parent.currentpathspot = 1;
347 | }
348 | Debug(1, "doPathgroups:Checking entries");
349 |
350 | // Lets look at all the pathgroup entries and get the one we're on
351 | for (myPathgroup_entry entry : this.parent.pathgroup.pathgroupentries) {
352 | Debug(1, "doPathgroups:Cycling entries");
353 |
354 | // This is the entry the npc is on
355 | if (entry.spot == this.parent.currentpathspot) {
356 | Debug(1, "Does " + entry.location + " match " + this.getBukkitEntity().getLocation() + " : " + this.parent.currentpathspot);
357 | // Ignore yaw and pitch
358 | Location loca = new Location(entry.location.getWorld(), entry.location.getX(), entry.location.getY(), entry.location.getZ(), 0, 0);
359 | Location locb = new Location(this.getBukkitEntity().getWorld(), this.getBukkitEntity().getLocation().getX(), this.getBukkitEntity().getLocation().getY(), this.getBukkitEntity().getLocation().getZ(), 0, 0);
360 |
361 | if (loca.equals(locb)) {
362 | Panic(1, "Already reached: " + this.getBukkitEntity().getLocation() + " spot: " + this.parent.currentpathspot);
363 |
364 | // Move to net location
365 | this.parent.movecountdown = 10;
366 | iteratePathspot();
367 |
368 | } else {
369 | // Lets convert it into a Location
370 | Location loc = new Location(this.getBukkitEntity().getWorld(), entry.location.getX(), entry.location.getY(), entry.location.getZ(), entry.location.getYaw(), entry.location.getPitch());
371 | // We should try to move closer to it
372 | this.moveCloserToLocation(loc);
373 | }
374 |
375 | }
376 | }
377 |
378 | } else {
379 | if (this.parent.movecountdown < 0) {
380 | // why is the countdown less than 0, reset it (executes)
381 | this.parent.movecountdown = 0;
382 | } else {
383 | // move the countdown closer to execution
384 | this.parent.movecountdown--;
385 | }
386 | }
387 | }
388 |
389 | private void Debug(int i, String string) {
390 | if (i > 1) {
391 | Debug(string);
392 | }
393 | }
394 |
395 | private void Panic(int i, String string) {
396 | if (i > 1) {
397 | Panic(string);
398 | }
399 | }
400 |
401 | private void iteratePathspot() {
402 |
403 | if (this.parent.moveforward) {
404 | if (this.parent.currentpathspot < this.parent.pathgroup.pathgroupentries.size()) {
405 |
406 | this.parent.currentpathspot++;
407 | Debug(1, "Iterated Pathspot Forwards (" + this.parent.currentpathspot + ")");
408 | } else {
409 | Debug(1, "CHANGEDIRECTION Moving Backward");
410 | this.parent.moveforward = false;
411 | }
412 |
413 | } else {
414 |
415 | if (this.parent.currentpathspot > 1) {
416 |
417 | this.parent.currentpathspot--;
418 | Debug(1, "Iterated Pathspot Backwards (" + this.parent.currentpathspot + ")");
419 | } else {
420 | Debug(1, "CHANGEDIRECTION Moving Forward");
421 | this.parent.moveforward = true;
422 | }
423 | }
424 |
425 | }
426 |
427 | private void moveCloserToLocation(Location loc) {
428 | Location newloc = getTransformCloserToLocation(this.getBukkitEntity().getLocation(), loc);
429 | if (this.parent != null) {
430 | Debug(1, "moveCloserToLocation Moving towards: " + this.parent.currentpathspot + newloc);
431 | }
432 |
433 | Location locforface = getFaceLocationFromMe(loc);
434 | Location modifiedloc = new Location(newloc.getWorld(), newloc.getX(), newloc.getY(), newloc.getZ(), locforface.getYaw(), locforface.getPitch());
435 |
436 | forceMove(modifiedloc);
437 |
438 | }
439 |
440 | public Location getTransformCloserToLocation(Location from, Location to) {
441 | Debug(1, "transformCloserToLocation:Called!!");
442 | Debug(1, "transformCloserToLocation:TO: (" + to.getX() + "," + to.getY() + "," + to.getZ() + ")");
443 | Debug(1, "transformCloserToLocation:FROM:" + from.getX() + "," + from.getY() + "," + from.getZ() + ")");
444 | double diffx = to.getX() - from.getX();
445 | double diffy = to.getY() - from.getY();
446 | double diffz = to.getZ() - from.getZ();
447 | Debug(1, "transformCloserToLocation:DIFF: (" + diffx + "," + diffy + "," + diffz + ")");
448 | if (diffx <= 1 && diffx >= -1 && diffy <= 1 && diffy >= -1 && diffz <= 1 && diffz >= -1) {
449 | // Close enough, return it
450 | Debug(1, "transformCloserToLocation:Close (within 1), i'm gonna go with it");
451 | return to;
452 | }
453 |
454 | Location loc = new Location(this.getBukkitEntity().getWorld(), from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch());
455 | if (diffx > 1) {
456 | // move on pos-x axis
457 | loc.setX(loc.getX() + 1);
458 | }
459 | if (diffy > 1) {
460 | // move on pos-x axis
461 | loc.setY(loc.getY() + 1);
462 | }
463 | if (diffz > 1) {
464 | // move on pos-x axis
465 | loc.setZ(loc.getZ() + 1);
466 | }
467 | //
468 | if (diffx < -1) {
469 | // move on pos-x axis
470 | loc.setX(loc.getX() - 1);
471 | }
472 | if (diffy < -1) {
473 | // move on pos-x axis
474 | loc.setY(loc.getY() - 1);
475 | }
476 | if (diffz < -1) {
477 | // move on pos-x axis
478 | loc.setZ(loc.getZ() - 1);
479 | }
480 |
481 | Block block = this.getBukkitEntity().getWorld().getBlockAt(loc);
482 | if (block.getType() == Material.AIR && !isBlockOccupied(block) && !isBlockFloatingAir(block) && !isBlockWall(block) && !isLastBlock(block)) {
483 | Debug(1, "transformCloserToLocation:Initial location was not a wall or last block");
484 | return loc;
485 | }
486 |
487 | // Go round but dont go to our previous location
488 | Location location = getNextBestLocation(this.getBukkitEntity().getLocation(), loc);
489 |
490 | if (location != null) { return location; }
491 |
492 | Debug(1, "transformCloserToLocation:failed to find a location - going home");
493 | return from;
494 |
495 | }
496 |
497 | private boolean isBlockOccupied(Block block) {
498 | int count = 0;
499 | for (Entity e : this.getBukkitEntity().getWorld().getEntities()) {
500 | if (e.getLocation() == block.getLocation()) {
501 | count++;
502 | }
503 | }
504 | if (count == 0) {
505 | return false;
506 | } else {
507 | return true;
508 | }
509 | }
510 |
511 | private boolean isLastBlock(Block block) {
512 | if (this.lastloc != null) {
513 | if (block == this.lastloc) {
514 | Debug(1, "isLastBlock=true");
515 | return true;
516 | }
517 | }
518 | return false;
519 | }
520 |
521 | private boolean isBlockWall(Block block) {
522 | Location above = new Location(block.getWorld(), block.getLocation().getX(), block.getLocation().getY() + 1, block.getLocation().getZ(), block.getLocation().getYaw(), block.getLocation().getPitch());
523 | Block babove = block.getWorld().getBlockAt(above);
524 | if (babove.getType() == Material.AIR) { return false; }
525 | // assume the worse
526 | Debug(1, "isBlockWall=true");
527 |
528 | return true;
529 | }
530 |
531 | private Location getNextBestLocation(Location from, Location loc) {
532 | // Using our from location, find the next best block to move to from loc
533 |
534 | int minx = -1;
535 | int miny = -1;
536 | int minz = -1;
537 | double x = minx;
538 | double y = miny;
539 | double z = minz;
540 | int maxx = 1;
541 | int maxy = 1;
542 | int maxz = 1;
543 |
544 | double myx = this.getBukkitEntity().getLocation().getX();
545 | double myy = this.getBukkitEntity().getLocation().getY();
546 | double myz = this.getBukkitEntity().getLocation().getZ();
547 |
548 | double tx = loc.getX();
549 | double ty = loc.getY();
550 | double tz = loc.getZ();
551 |
552 | double diffx = myx - tx;
553 | double diffy = myy - ty;
554 | double diffz = myz - tz;
555 |
556 | if (diffx <= -1) {
557 | minx = -1;
558 | x = minx;
559 | maxx = 0;
560 | }
561 |
562 | if (diffy <= -1) {
563 | miny = -1;
564 | y = miny;
565 | maxy = 0;
566 | }
567 |
568 | if (diffz <= -1) {
569 | minz = -1;
570 | z = minz;
571 | maxz = 0;
572 | }
573 |
574 | if (diffx >= 1) {
575 | minx = 0;
576 | x = minx;
577 | maxx = 1;
578 | }
579 |
580 | if (diffy >= 1) {
581 | miny = 0;
582 | y = miny;
583 | maxy = 1;
584 | }
585 |
586 | if (diffz >= 1) {
587 | minz = 0;
588 | z = minz;
589 | maxz = 1;
590 | }
591 |
592 | while (x <= maxx) {
593 | while (y <= maxy) {
594 | while (z <= maxz) {
595 | Panic(1, "getNextBestLocation:" + x + "," + y + "," + z);
596 | Location targetloc = new Location(this.getBukkitEntity().getWorld(), from.getX() - x, from.getY() - y, from.getZ() - z, loc.getYaw(), loc.getPitch());
597 | Block block = this.getBukkitEntity().getWorld().getBlockAt(targetloc);
598 |
599 | if (x == 0 && y == 0 && z == 0) {
600 | // Skip here, we're already there!
601 | } else {
602 | if (block.getType() == Material.AIR && !isBlockOccupied(block) && !isBlockFloatingAir(block) && !isBlockWall(block) && !isLastBlock(block)) {
603 | Debug(1, "getNextBestLocation:GOINGTOMOVE:" + x + "," + y + "," + z);
604 | return targetloc;
605 | }
606 | }
607 | z++;
608 | }
609 | y++;
610 | z = minz;
611 |
612 | }
613 | x++;
614 | y = miny;
615 | z = minz;
616 | }
617 |
618 | Panic(1, "getNextBestLocation:Failed to find a better target");
619 | return null;
620 | }
621 |
622 | private boolean isBlockFloatingAir(Block block) {
623 | Location locbelow = new Location(block.getLocation().getWorld(), block.getLocation().getX(), block.getLocation().getY() - 1, block.getLocation().getZ(), block.getLocation().getYaw(), block.getLocation().getPitch());
624 | Block blockbelow = block.getWorld().getBlockAt(locbelow);
625 |
626 | if (block.getType() == Material.AIR && blockbelow.getType() != Material.AIR) return false;
627 | // assume worse
628 | return true;
629 | }
630 |
631 | private Location findPlatformDown(Location belowloc) {
632 | int max = 200;
633 | int current = 1;
634 | while (current < max) {
635 | Location newloc = new Location(belowloc.getWorld(), belowloc.getX(), belowloc.getY() - current, belowloc.getZ(), belowloc.getYaw(), belowloc.getPitch());
636 | if (this.getBukkitEntity().getWorld().getBlockAt(newloc).getType() != Material.AIR) { return newloc;
637 |
638 | }
639 | current++;
640 | }
641 | Panic("findPlatformDown - Failed to find a better platform below");
642 | return null;
643 | }
644 |
645 | private void Debug(String string) {
646 |
647 | if (this.parent.parent != null) {
648 | this.parent.parent.dbg("BasicHumanNpc:" + string);
649 | }
650 | }
651 |
652 | public void forceMove(Location loc) {
653 |
654 | Debug(1, "forceMove Called (" + loc.getX() + "," + loc.getY() + "," + loc.getZ() + ") from (" + this.mcEntity.getBukkitEntity().getLocation().getX() + "," + this.mcEntity.getBukkitEntity().getLocation().getY() + "," + this.mcEntity.getBukkitEntity().getLocation().getZ() + ")");
655 |
656 | double myx = this.getBukkitEntity().getLocation().getX();
657 | double myy = this.getBukkitEntity().getLocation().getY();
658 | double myz = this.getBukkitEntity().getLocation().getZ();
659 |
660 | double tx = loc.getX();
661 | double ty = loc.getY();
662 | double tz = loc.getZ();
663 |
664 | double diffx = myx - tx;
665 | double diffy = myy - ty;
666 | double diffz = myz - tz;
667 | Debug(1, "forceMove:GOINGTOMOVE:" + diffx + "," + diffy + "," + diffz);
668 |
669 | // Save last co-ordinate
670 | this.lastloc = this.getBukkitEntity().getLocation().getBlock();
671 |
672 | this.mcEntity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
673 | }
674 |
675 | public void Panic(String type) {
676 | Debug("npcx : ***" + this.getBukkitEntity().getName() + " paniced! : " + type + " ***");
677 | }
678 |
679 | public void attackLivingEntity(LivingEntity ent) {
680 | try {
681 | // check the ent has some health at least
682 |
683 | if (ent.getHealth() > 0) {
684 | if ((ent.getHealth() - dmg) <= 0) {
685 | ent.damage(200);
686 | setFollow(null);
687 | setAggro(null);
688 | if (ent instanceof Player) {
689 | // ((Player) ent).getServer().broadcastMessage(((Player)
690 | // ent).getName() + " was slaughtered by " + getName() +
691 | // ".");
692 | ((Player) ent).sendMessage("You have been slaughtered by " + getName());
693 | this.onKilled(ent);
694 |
695 | // mark player dead
696 | for (myPlayer player : this.parent.parent.universe.players.values()) {
697 | // deal with player death changes
698 | if (player.player == ent) {
699 | // System.out.println("npcx : player about to respawn, assigning them to the dead list");
700 | player.dead = true;
701 | player.respawned = false;
702 | ((Player) ent).sendMessage("You have been slaughtered by " + getName());
703 |
704 | }
705 |
706 | }
707 |
708 | }
709 | } else {
710 | if (ent instanceof Monster) {
711 |
712 | double myx = this.getBukkitEntity().getLocation().getX();
713 | double myy = this.getBukkitEntity().getLocation().getY();
714 | double myz = this.getBukkitEntity().getLocation().getZ();
715 |
716 | double tx = ent.getLocation().getX();
717 | double ty = ent.getLocation().getY();
718 | double tz = ent.getLocation().getZ();
719 |
720 | double diffx = myx - tx;
721 | double diffy = myy - ty;
722 | double diffz = myz - tz;
723 |
724 | if (diffx < 2 && diffx > -2 && diffy < 2 && diffy > -2 && diffz < 2 && diffz > -2) {
725 |
726 | // System.out.println("Gahh! ");
727 | this.mcEntity.animateArmSwing();
728 | ent.damage(dmg);
729 |
730 | }
731 |
732 | } else {
733 | if (ent instanceof Player) {
734 |
735 | double myx = this.getBukkitEntity().getLocation().getX();
736 | double myy = this.getBukkitEntity().getLocation().getY();
737 | double myz = this.getBukkitEntity().getLocation().getZ();
738 |
739 | double tx = ent.getLocation().getX();
740 | double ty = ent.getLocation().getY();
741 | double tz = ent.getLocation().getZ();
742 |
743 | double diffx = myx - tx;
744 | double diffy = myy - ty;
745 | double diffz = myz - tz;
746 |
747 | if (diffx < 2 && diffx > -2 && diffy < 2 && diffy > -2 && diffz < 2 && diffz > -2) {
748 | // System.out.println("Processed this as a player "+ent.getClass().toString());
749 | this.mcEntity.animateArmSwing();
750 | ent.damage(dmg);
751 |
752 | }
753 | }
754 | }
755 | }
756 | } else {
757 | // no health, not worth the effort
758 | setFollow(null);
759 | setAggro(null);
760 | }
761 | } catch (Exception e) {
762 | e.printStackTrace();
763 | }
764 | }
765 |
766 | private void onKilled(LivingEntity ent) {
767 | this.parent.onKilled(ent);
768 | }
769 |
770 | public void animateArmSwing() {
771 | this.mcEntity.animateArmSwing();
772 | }
773 |
774 | public void onBounce(Player p) {
775 | this.parent.onBounce(p);
776 | }
777 |
778 | public void onRightClick(Player p) {
779 | this.parent.onRightClick(p);
780 | }
781 |
782 | public void onClosestPlayer(Player p) {
783 | this.parent.onClosestPlayer(p);
784 | }
785 |
786 | public void onDeathFromPlayer(LivingEntity p) {
787 | if (this.dead != true) {
788 | this.dead = true;
789 | this.parent.onDeathFromPlayer(p);
790 | }
791 |
792 | }
793 |
794 | public void chunkactive(Location location) {
795 | if (this.parent.spawngroup != null) {
796 | // System.out.println("ncpx : Chunkactive for spawngroup:"+this.parent.spawngroup.name);
797 | this.parent.spawngroup.chunkactive = true;
798 | }
799 |
800 | }
801 |
802 | public void chunkinactive(Location location) {
803 | if (this.parent.spawngroup != null) {
804 | // System.out.println("npcx : DBG : ChunkInactive for spawngroup:"+this.parent.spawngroup.name);
805 | this.parent.spawngroup.chunkactive = false;
806 | }
807 |
808 | }
809 |
810 | public void onNpcVsNpcDamage(myNPC anpc) {
811 |
812 | this.setFollow(anpc.npc.getBukkitEntity());
813 | this.setAggro(anpc.npc.getBukkitEntity());
814 |
815 | try {
816 | // default npcvsnpc dmg
817 | int dmgdone = 30;
818 | this.hp = this.hp - dmgdone;
819 | this.parent.requipArmour();
820 |
821 | if (this.hp < 1) {
822 | anpc.npc.setFollow(null);
823 | anpc.npc.setAggro(null);
824 |
825 | // System.out.println("I just died!!");
826 | this.onDeathFromNPC(anpc.npc.getBukkitEntity());
827 | this.parent.parent.onNPCDeath(this);
828 |
829 | }
830 | } catch (Exception e) {
831 | this.setFollow(null);
832 | this.setAggro(null);
833 | e.printStackTrace();
834 | }
835 | }
836 |
837 | private void onDeathFromNPC(HumanEntity bukkitEntity) {
838 | if (this.dead != true) {
839 | this.dead = true;
840 | this.parent.onDeath();
841 | }
842 | }
843 |
844 | public void onDamage(EntityDamageEvent event) {
845 | // System.out.println("onDamage called for entity"+event.getEntity().getEntityId());
846 |
847 | if (event instanceof EntityDamageByEntityEvent) {
848 | EntityDamageByEntityEvent edee = (EntityDamageByEntityEvent) event;
849 |
850 | if (this != null && edee.getDamager() instanceof LivingEntity) {
851 |
852 | Entity p = edee.getDamager();
853 | if (this.parent != null) {
854 | for (myPlayer player : this.parent.parent.universe.players.values()) {
855 | if (player.player == edee.getDamager()) {
856 | if (this.getAggro() == null) {
857 | // First time sent an event
858 | this.parent.onPlayerAggroChange(player);
859 |
860 | }
861 | }
862 | }
863 | }
864 | this.setFollow((LivingEntity) p);
865 | this.setAggro((LivingEntity) p);
866 |
867 | try {
868 |
869 | int dmgdone = this.parent.getDamageDone(this, (Player) p);
870 | this.hp = this.hp - dmgdone;
871 |
872 | this.parent.requipArmour();
873 |
874 | if (this.hp < 1) {
875 |
876 | // System.out.println("I just died!!");
877 | this.onDeathFromPlayer((LivingEntity) p);
878 | this.parent.parent.onNPCDeathWithLoot(this);
879 |
880 | }
881 | } catch (Exception e) {
882 | this.setFollow(null);
883 | this.setAggro(null);
884 |
885 | }
886 | }
887 |
888 | }
889 | }
890 |
891 | public void despawn() {
892 |
893 | for (myPlayer player : this.parent.parent.universe.players.values()) {
894 | if (player.target == this) {
895 | player.target = null;
896 |
897 | }
898 | }
899 | this.parent.parent.onNPCDeath(this);
900 | }
901 |
902 | }
903 |
--------------------------------------------------------------------------------
/src/net/gamerservices/npcx/myNPC.java:
--------------------------------------------------------------------------------
1 | package net.gamerservices.npcx;
2 |
3 | import java.awt.PageAttributes.ColorType;
4 | import java.sql.DriverManager;
5 | import java.sql.ResultSet;
6 | import java.sql.Statement;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Random;
10 | import java.util.concurrent.CopyOnWriteArrayList;
11 | import java.util.regex.Matcher;
12 | import java.util.regex.Pattern;
13 |
14 | import net.gamerservices.npclibfork.BasicHumanNpc;
15 | import net.gamerservices.npclibfork.CHumanNpc;
16 | import net.gamerservices.npclibfork.NpcSpawner;
17 |
18 | import org.bukkit.ChatColor;
19 | import org.bukkit.Location;
20 | import org.bukkit.Material;
21 | import org.bukkit.World;
22 | import org.bukkit.entity.CreatureType;
23 | import org.bukkit.entity.LivingEntity;
24 | import org.bukkit.entity.Player;
25 | import org.bukkit.inventory.ItemStack;
26 |
27 | import com.iConomy.iConomy;
28 | import com.iConomy.system.Account;
29 |
30 | public class myNPC {
31 | public npcx parent;
32 | public String name = "dummy";
33 | public String id = "0";
34 | String category = "container";
35 | public BasicHumanNpc npc;
36 | public myFaction faction;
37 | public mySpawngroup spawngroup;
38 | public myLoottable loottable;
39 | public myMerchant merchant;
40 | public int coin = 250000;
41 | public HashMap triggerwords = new HashMap();
42 | public int chest = 0;
43 | public int legs = 0;
44 | public int helmet = 0;
45 | public int weapon = 0;
46 | public int boots = 0;
47 | public List hints = new CopyOnWriteArrayList();
48 | public myPathgroup pathgroup;
49 | public int currentpathspot = 0;
50 | public int movecountdown = 0;
51 | public boolean moveforward = true;
52 |
53 | myNPC(npcx parent, HashMap triggerwords, Location location, String name) {
54 | this.name = name;
55 |
56 | this.parent = parent;
57 |
58 | this.triggerwords = triggerwords;
59 |
60 | }
61 |
62 | public void onPlayerAggroChange(myPlayer myplayer) {
63 | int count = 0;
64 |
65 | // do i already ahve aggro?
66 | for (myTriggerword tw : triggerwords.values()) {
67 |
68 | if (tw.word.toLowerCase().contains("attack")) {
69 | String send = variablise(tw.response, myplayer.player);
70 | say(myplayer, send);
71 | count++;
72 | return;
73 | }
74 |
75 | }
76 | }
77 |
78 | private void say(myPlayer myplayer, String string) {
79 | // TODO Auto-generated method stub
80 | if (npc != null) {
81 | if (myplayer.player != null) {
82 | myplayer.player.sendMessage(npc.getName() + " says to you, '" + string + "'");
83 | }
84 | }
85 | }
86 |
87 | public void parseChat(myPlayer myplayer, String message) {
88 | // System.out.println("Parsing: "+message);
89 | int count = 0;
90 | int size = 0;
91 | // myplayer.player.sendMessage("Parsing:" + message + ":" +
92 | // Integer.toString(this.triggerwords.size()));
93 | String message2 = message + " ";
94 | for (String word : message2.split(" ")) {
95 | // this needs to be removed
96 | if (count == 0) {
97 | if (triggerwords != null) {
98 | for (myTriggerword tw : triggerwords.values()) {
99 | // myplayer.player.sendMessage("Test:" + word + ":"+
100 | // tw.word);
101 | if (word.toLowerCase().contains(tw.word.toLowerCase())) {
102 | String npcattack = "NPCATTACK";
103 | String summonplayer = "NPCSUMMONPLAYER";
104 | String npcsummonzombie = "NPCSUMMONZOMBIE";
105 | String npcsummonwolf = "NPCSUMMONWOLF";
106 |
107 | // NPCATTACK variable
108 | if (tw.response.toLowerCase().contains(npcattack.toLowerCase())) {
109 | say(myplayer, "You will regret that");
110 | npc.setAggro(myplayer.player);
111 | npc.setFollow(myplayer.player);
112 | return;
113 |
114 | }
115 |
116 | // NPCSUMMONPLAYER
117 | if (tw.response.toLowerCase().contains(summonplayer.toLowerCase())) {
118 | say(myplayer, "Come here");
119 | double x = npc.getBukkitEntity().getLocation().getX();
120 | double y = npc.getBukkitEntity().getLocation().getY();
121 | double z = npc.getBukkitEntity().getLocation().getZ();
122 | Location location = new Location(npc.getBukkitEntity().getLocation().getWorld(), x, y, z);
123 |
124 | myplayer.player.teleport(location);
125 | return;
126 |
127 | }
128 |
129 | // NPCSUMMONMOB
130 | if (tw.response.toLowerCase().contains(npcsummonzombie.toLowerCase())) {
131 |
132 | npc.getBukkitEntity().getWorld().spawnCreature(this.npc.getBukkitEntity().getLocation(), CreatureType.ZOMBIE);
133 |
134 | say(myplayer, "Look out");
135 | return;
136 | }
137 |
138 | // NPCSUMMONWOLF
139 | if (tw.response.toLowerCase().contains(npcsummonwolf.toLowerCase())) {
140 |
141 | npc.getBukkitEntity().getWorld().spawnCreature(this.npc.getBukkitEntity().getLocation(), CreatureType.WOLF);
142 |
143 | say(myplayer, "It's a wolf!");
144 | return;
145 | }
146 |
147 | String send = variablise(tw.response, myplayer.player);
148 | say(myplayer, send);
149 | count++;
150 | return;
151 |
152 | }
153 |
154 | size++;
155 | }
156 |
157 | }
158 | }
159 | }
160 | if (count == 0 && size == 0) {
161 | // too spammy
162 | // say(myplayer,"I'm sorry. I'm rather busy right now.");
163 |
164 |
165 |
166 |
167 | } else {
168 | int count2 = 0;
169 | for (myTriggerword tw : triggerwords.values()) {
170 | // myplayer.player.sendMessage("Test:" + word + ":"+ tw.word);
171 | if (tw.word.toLowerCase().contains("default") && size > 0 && count == 0) {
172 | String send = variablise(tw.response, myplayer.player);
173 |
174 | say(myplayer, send);
175 | count2++;
176 | return;
177 | }
178 |
179 | }
180 | if (count2 == 0) {
181 | // too spammy
182 | // say(myplayer,"I'm sorry. I'm rather busy right now.");
183 |
184 |
185 |
186 | }
187 |
188 | }
189 | }
190 |
191 | private void parseChatGlobalCommands(myPlayer myplayer, String message) {
192 | // TODO Auto-generated method stub
193 | // Checks a message for any global commands
194 | // These are commands all npcs can support
195 |
196 | // myplayer.player.sendMessage("Parsing:" + message + ":" +
197 | // Integer.toString(this.triggerwords.size()));
198 | String message2 = message + " ";
199 | String arg1 = "";
200 | String arg2 = "";
201 | String arg3 = "";
202 |
203 | int ocount = 0;
204 | String words2 = "";
205 | for (String word : message2.split(" ")) {
206 | if (ocount == 0) {
207 | arg1 = word;
208 | words2 += "[" + word + "]";
209 | }
210 | if (ocount == 1) {
211 | arg2 = word;
212 | words2 += "[" + word + "]";
213 |
214 | }
215 |
216 | if (ocount == 2) {
217 | arg3 = word;
218 | words2 += "[" + word + "]";
219 |
220 | }
221 | ocount++;
222 | }
223 | myplayer.player.sendMessage(words2);
224 |
225 | //
226 | // Give command
227 | //
228 | if (arg1.matches("give")) {
229 |
230 | if (arg2.matches("") || arg3.matches("")) {
231 | say(myplayer, "give [itemid] [amount]");
232 | return;
233 | }
234 |
235 | int amount = 0;
236 | try {
237 | amount = Integer.parseInt(arg3);
238 |
239 | } catch (NumberFormatException e) {
240 | say(myplayer, "That is not a valid amount.");
241 | return;
242 | }
243 |
244 | if (amount < 1) {
245 | say(myplayer, "Hmm that's not enough.");
246 | // e.printStackTrace();
247 | return;
248 | }
249 |
250 | ItemStack item = new ItemStack(1, 1);
251 |
252 | try {
253 | // System.out.println("Finding material: " + arg2);
254 | item.setTypeId(Material.matchMaterial(arg2).getId());
255 | } catch (NullPointerException e) {
256 | say(myplayer, "Hmm try another item similar named to " + arg2 + " and i might be interested.");
257 | // e.printStackTrace();
258 | return;
259 |
260 | } catch (Exception e) {
261 | say(myplayer, "Hmm try another item similar named to " + arg2 + " and i might be interested.");
262 | // e.printStackTrace();
263 | return;
264 | }
265 |
266 | try {
267 | item.setAmount(Integer.parseInt(arg3));
268 |
269 | } catch (NumberFormatException e) {
270 | say(myplayer, "That is not a valid amount.");
271 | return;
272 | }
273 |
274 | // check if the item type is null incase it didnt find the material
275 | // type
276 |
277 | int count = 0;
278 |
279 | for (ItemStack curitem : myplayer.player.getInventory().getContents()) {
280 |
281 | try {
282 |
283 | if (curitem.getTypeId() == item.getTypeId()) {
284 | count = count + curitem.getAmount();
285 | // player.player.sendMessage(npc.getName() +
286 | // " says to you, '"+ curitem.getTypeId()
287 | // +"/"+curitem.getAmount() +"'");
288 | }
289 | } catch (NullPointerException e) {
290 | // empty slot
291 | // skip this item
292 | }
293 |
294 | }
295 |
296 | if (count >= item.getAmount()) {
297 | say(myplayer, "Hmm! " + item.getAmount() + " " + item.getType().name() + "! Thanks!");
298 | myplayer.player.getInventory().removeItem(item);
299 | this.onReceiveItem(myplayer, item);
300 | // Fire event
301 |
302 | return;
303 | } else {
304 | say(myplayer, "Sorry, you only have: " + count + " !");
305 | return;
306 | }
307 |
308 | } else {
309 | // global help?
310 | }
311 |
312 | //
313 | // End Give command
314 | //
315 |
316 | }
317 |
318 | private void onReceiveItem(myPlayer p, ItemStack item) {
319 | // TODO Auto-generated method stub
320 |
321 | if (triggerwords != null) {
322 | int count2 = 0;
323 | for (myTriggerword tw : triggerwords.values()) {
324 | if (tw.word.toLowerCase().matches("event_receive" + item.getType().getId())) {
325 | String npcattack = "NPCATTACK";
326 | String summonplayer = "NPCSUMMONPLAYER";
327 | String npcsummonzombie = "NPCSUMMONZOMBIE";
328 | String npcsummonwolf = "NPCSUMMONWOLF";
329 |
330 | // NPCATTACK variable
331 | if (tw.response.toLowerCase().contains(npcattack.toLowerCase())) {
332 | say(p, "You will regret that");
333 | npc.setAggro(p.player);
334 | npc.setFollow(p.player);
335 | return;
336 |
337 | }
338 |
339 | // NPCSUMMONPLAYER
340 | if (tw.response.toLowerCase().contains(summonplayer.toLowerCase())) {
341 | say(p, "Come here");
342 | double x = npc.getBukkitEntity().getLocation().getX();
343 | double y = npc.getBukkitEntity().getLocation().getY();
344 | double z = npc.getBukkitEntity().getLocation().getZ();
345 | Location location = new Location(npc.getBukkitEntity().getLocation().getWorld(), x, y, z);
346 |
347 | p.player.teleport(location);
348 | return;
349 |
350 | }
351 |
352 | // NPCSUMMONMOB
353 | if (tw.response.toLowerCase().contains(npcsummonzombie.toLowerCase())) {
354 |
355 | npc.getBukkitEntity().getWorld().spawnCreature(this.npc.getBukkitEntity().getLocation(), CreatureType.ZOMBIE);
356 |
357 | say(p, "Look out");
358 | return;
359 | }
360 |
361 | // NPCSUMMONWOLF
362 | if (tw.response.toLowerCase().contains(npcsummonwolf.toLowerCase())) {
363 |
364 | npc.getBukkitEntity().getWorld().spawnCreature(this.npc.getBukkitEntity().getLocation(), CreatureType.WOLF);
365 |
366 | say(p, "It's a wolf!");
367 | return;
368 | }
369 |
370 | String send = variablise(tw.response, p.player);
371 |
372 | say(p, send);
373 |
374 | count2++;
375 |
376 | }
377 | }
378 | if (count2 == 0) {
379 | // If i dont have a triggerword tell them thanks
380 | p.player.sendMessage(npc.getName() + " says to you, 'Thanks! I'll find some use for that.'");
381 | }
382 | } else {
383 | // Either a standard spawn or has no triggers!
384 | }
385 |
386 | }
387 |
388 | public void onPlayerChat(myPlayer myplayer, String message, String category) {
389 | parseChatGlobalCommands(myplayer, message);
390 | if (category.matches("merchant")) {
391 | parseMerchant(myplayer, message);
392 | parseChat(myplayer, message);
393 |
394 | } else {
395 | parseChat(myplayer, message);
396 | }
397 |
398 | }
399 |
400 | public void parseMerchant(myPlayer player, String message) {
401 | // TODO Auto-generated method stub
402 | // myplayer.player.sendMessage("Parsing:" + message + ":" +
403 | // Integer.toString(this.triggerwords.size()));
404 | String message2 = message + " ";
405 | String[] aMsg = message.split(" ");
406 | int size = aMsg.length;
407 |
408 | // Help Command
409 |
410 | // player.player.sendMessage("DEBUG: " + size);
411 | if (aMsg[0].toLowerCase().matches("help")) {
412 |
413 | say(player, "What do you need? " + ChatColor.LIGHT_PURPLE + "[list], [sell]" + ChatColor.WHITE + " or " + ChatColor.LIGHT_PURPLE + "[buy]");
414 | return;
415 | }
416 |
417 | // List Command
418 |
419 | if (aMsg[0].toLowerCase().matches("list")) {
420 | if (this.merchant != null) {
421 | int mysize = this.merchant.merchantentries.size();
422 | say(player, "Checking my list of: " + ChatColor.LIGHT_PURPLE + mysize);
423 | boolean match = false;
424 |
425 | if (size == 2) {
426 | match = true;
427 | }
428 |
429 | int count = 0;
430 | if (this.merchant != null) {
431 | if (this.merchant.merchantentries != null) {
432 | for (myMerchant_entry item : this.merchant.merchantentries) {
433 | count++;
434 | if (match == true) {
435 | try {
436 | if (Material.matchMaterial(aMsg[1]).getId() == item.itemid) {
437 | if (!this.merchant.category.equals("nolimit")) {
438 | player.player.sendMessage(ChatColor.LIGHT_PURPLE + "" + Material.matchMaterial(aMsg[1]) + ChatColor.WHITE + " x " + item.amount + " S: " + ChatColor.YELLOW + "$" + item.pricesell + ChatColor.WHITE + " B: $" + ChatColor.YELLOW + "$" + item.pricebuy);
439 | } else {
440 | player.player.sendMessage(ChatColor.LIGHT_PURPLE + "" + Material.matchMaterial(aMsg[1]) + ChatColor.WHITE + " S:" + ChatColor.YELLOW + "$" + item.pricesell + ChatColor.WHITE + " B:" + ChatColor.YELLOW + "$" + item.pricebuy);
441 |
442 | }
443 | }
444 | } catch (NullPointerException e) {
445 | say(player, "Couldn't find any items matching the name you requested");
446 | }
447 | } else {
448 | if (this.merchant != null) {
449 | if (this.merchant.category != null) {
450 | if (!this.merchant.category.equals("nolimit")) {
451 | player.player.sendMessage(item.itemid + "(" + ChatColor.LIGHT_PURPLE + "" + Material.matchMaterial(Integer.toString(item.itemid)).toString() + ChatColor.WHITE + ") x " + item.amount + " S: " + ChatColor.YELLOW + "$" + item.pricesell + ChatColor.WHITE + " B: " + ChatColor.YELLOW + "$" + item.pricebuy);
452 | } else {
453 | player.player.sendMessage(item.itemid + "(" + ChatColor.LIGHT_PURPLE + "" + Material.matchMaterial(Integer.toString(item.itemid)).toString() + ChatColor.WHITE + ") S:" + ChatColor.YELLOW + "$" + item.pricesell + ChatColor.WHITE + " B:" + ChatColor.YELLOW + "$" + item.pricebuy);
454 | }
455 | } else {
456 | player.player.sendMessage(item.itemid + "(" + ChatColor.LIGHT_PURPLE + "" + Material.matchMaterial(Integer.toString(item.itemid)).toString() + ChatColor.WHITE + ") x " + item.amount + " S:" + ChatColor.YELLOW + "$" + item.pricesell + ChatColor.WHITE + " B:" + ChatColor.YELLOW + "$" + item.pricebuy);
457 | }
458 | }
459 | }
460 | }
461 |
462 | }
463 | }
464 | player.player.sendMessage(ChatColor.LIGHT_PURPLE + "" + count + ChatColor.WHITE + " items in the Merchant.");
465 |
466 | return;
467 | }
468 |
469 | }
470 |
471 | // Sell Command
472 |
473 | if (aMsg[0].toLowerCase().matches("sell")) {
474 | if (aMsg.length < 3) {
475 | say(player, "sell " + ChatColor.LIGHT_PURPLE + "[itemid] [amount]");
476 | return;
477 | } else {
478 |
479 | myMerchantItem Merchantitem = new myMerchantItem();
480 | ItemStack item = new ItemStack(1, 1);
481 | Merchantitem.item = item;
482 | // todo price
483 | int amount = 0;
484 | try {
485 | amount = Integer.parseInt(aMsg[2]);
486 |
487 | } catch (NumberFormatException e) {
488 | say(player, "That is not a valid amount.");
489 | return;
490 | }
491 | if (amount < 1) {
492 | say(player, "Hmm that's not enough.");
493 | // e.printStackTrace();
494 | return;
495 | }
496 |
497 | try {
498 | item.setTypeId(Material.matchMaterial(aMsg[1]).getId());
499 | } catch (NullPointerException e) {
500 | // lol
501 | say(player, "Hmm try another item similar named to " + ChatColor.LIGHT_PURPLE + aMsg[1] + ChatColor.WHITE + " and i might be interested.");
502 |
503 | say(player, "Hmm try another item similar named to " + ChatColor.LIGHT_PURPLE + aMsg[1] + ChatColor.WHITE + " and i might be interested.");
504 | // e.printStackTrace();
505 | return;
506 |
507 | } catch (Exception e) {
508 | this.parent.sendPlayerItemList(player.player);
509 | say(player, "Hmm try another item similar named to " + ChatColor.LIGHT_PURPLE + aMsg[1] + ChatColor.WHITE + " and i might be interested.");
510 | // e.printStackTrace();
511 | return;
512 |
513 | }
514 |
515 | try {
516 | item.setAmount(Integer.parseInt(aMsg[2]));
517 |
518 | } catch (NumberFormatException e) {
519 | say(player, "That is not a valid amount.");
520 | return;
521 | }
522 |
523 | int count = 0;
524 | for (ItemStack curitem : player.player.getInventory().getContents()) {
525 | try {
526 |
527 | if (curitem.getTypeId() == item.getTypeId()) {
528 | count = count + curitem.getAmount();
529 | // player.player.sendMessage(npc.getName() +
530 | // " says to you, '"+ curitem.getTypeId()
531 | // +"/"+curitem.getAmount() +"'");
532 | }
533 | } catch (NullPointerException e) {
534 | // skip its an empty slot
535 | }
536 |
537 | }
538 |
539 | if (count >= item.getAmount()) {
540 |
541 | say(player, "Ok thats " + ChatColor.YELLOW + item.getAmount() + ChatColor.WHITE + " out of your " + ChatColor.YELLOW + count + ChatColor.WHITE + ".");
542 | int totalcoins = 0;
543 | int buysat = getMerchantPriceBuyAt(Merchantitem.item.getTypeId());
544 | if (buysat == 0) {
545 | say(player, "Sorry, I am just not interested in that!");
546 | return;
547 | }
548 | totalcoins = (item.getAmount() * buysat);
549 | if (this.merchant.category != null && !this.merchant.category.matches("nolimit")) {
550 |
551 | if (this.coin >= totalcoins) {
552 |
553 | for (myMerchant_entry entry : merchant.merchantentries) {
554 | if (entry.itemid == Material.matchMaterial(aMsg[1]).getId()) {
555 | player.player.getInventory().removeItem(item);
556 | entry.amount = entry.amount + item.getAmount();
557 | say(player, "Thanks! Heres your " + ChatColor.YELLOW + totalcoins + ChatColor.WHITE + " coins.");
558 |
559 | this.coin = this.coin - totalcoins;
560 | player.addPlayerBalance(player.player, totalcoins);
561 | return;
562 | }
563 | }
564 |
565 | say(player, "Sorry looks like I no longer need that item.");
566 | return;
567 |
568 | } else {
569 | say(player, "Sorry, I only have: " + ChatColor.YELLOW + this.coin + ChatColor.WHITE + " and thats worth " + ChatColor.YELLOW + totalcoins + ChatColor.WHITE + "!");
570 | return;
571 | }
572 | } else {
573 |
574 | // unlimited coin and amounts on this merchant
575 | for (myMerchant_entry entry : merchant.merchantentries) {
576 | if (entry.itemid == Material.matchMaterial(aMsg[1]).getId()) {
577 | player.player.getInventory().removeItem(item);
578 | entry.amount = entry.amount + item.getAmount();
579 | say(player, "Thanks! Heres your " + ChatColor.YELLOW + totalcoins + ChatColor.WHITE + " coins.");
580 |
581 | this.coin = this.coin - totalcoins;
582 | player.addPlayerBalance(player.player, totalcoins);
583 | return;
584 | }
585 | }
586 |
587 | say(player, "Sorry looks like I no longer need that item.");
588 | return;
589 |
590 | }
591 |
592 | } else {
593 |
594 | say(player, "Sorry, you only have: " + ChatColor.YELLOW + count + ChatColor.WHITE + " !");
595 | return;
596 | }
597 | }
598 |
599 | }
600 |
601 | // Buy Command
602 |
603 | if (aMsg[0].toLowerCase().matches("buy")) {
604 | if (aMsg.length < 3) {
605 | say(player, "buy " + ChatColor.LIGHT_PURPLE + "[itemid] [amount]");
606 | return;
607 | } else {
608 |
609 | try {
610 | int a = Integer.parseInt(aMsg[2]);
611 | } catch (NumberFormatException e) {
612 | say(player, "That is not a valid amount.");
613 | return;
614 | }
615 |
616 | if (Integer.parseInt(aMsg[2]) > 0) {
617 | int amount = Integer.parseInt(aMsg[2]);
618 | int itemid = Material.matchMaterial(aMsg[1]).getId();
619 |
620 | if (this.merchant.category != null) {
621 |
622 | }
623 |
624 | if (this.merchant.category == null) {
625 | if (getMerchantAmount(itemid) >= Integer.parseInt(aMsg[2])) {
626 | for (myMerchant_entry entry : merchant.merchantentries) {
627 | if (entry.itemid == itemid) {
628 | ItemStack i = sellMerchantItem(entry.itemid, amount);
629 |
630 | if (i != null) {
631 |
632 | int cost = entry.pricesell * amount;
633 | if (cost <= player.getPlayerBalance(player.player)) {
634 | player.player.getInventory().addItem(i);
635 | say(player, "Thanks! That's " + ChatColor.YELLOW + cost + ChatColor.WHITE + " total coins!");
636 | player.subtractPlayerBalance(player.player, cost);
637 | return;
638 | } else {
639 | say(player, "You don't have enough!!");
640 |
641 | return;
642 | }
643 |
644 | } else {
645 | // hmm, didnt get an item back
646 | say(player, "Sorry, looks like that item just sold!");
647 | return;
648 | }
649 | }
650 | }
651 |
652 | } else {
653 | say(player, "Sorry, out of stock in that item. Have you tried our " + ChatColor.LIGHT_PURPLE + "[list]" + ChatColor.WHITE + "?");
654 | return;
655 | }
656 | } else {
657 |
658 | if (this.merchant.category.equals("nolimit")) {
659 |
660 | for (myMerchant_entry entry : merchant.merchantentries) {
661 | if (entry.itemid == itemid) {
662 | ItemStack i = sellMerchantItem(entry.itemid, amount);
663 |
664 | if (i != null) {
665 |
666 | int cost = entry.pricesell * amount;
667 | if (cost <= player.getPlayerBalance(player.player)) {
668 | player.player.getInventory().addItem(i);
669 | say(player, "Thanks! That's " + ChatColor.YELLOW + cost + ChatColor.WHITE + " total coins!");
670 | player.subtractPlayerBalance(player.player, cost);
671 | return;
672 | } else {
673 | say(player, "You don't have enough!!");
674 |
675 | return;
676 | }
677 |
678 | } else {
679 | // hmm, didnt get an item back
680 | say(player, "Sorry, looks like that item just sold!");
681 | return;
682 | }
683 | }
684 | }
685 | } else {
686 | // Do above
687 |
688 | // TODO This needs to move into a seperate function
689 | if (getMerchantAmount(itemid) >= Integer.parseInt(aMsg[2])) {
690 | for (myMerchant_entry entry : merchant.merchantentries) {
691 | if (entry.itemid == itemid) {
692 | ItemStack i = sellMerchantItem(entry.itemid, amount);
693 |
694 | if (i != null) {
695 |
696 | int cost = entry.pricesell * amount;
697 | if (cost <= player.getPlayerBalance(player.player)) {
698 | player.player.getInventory().addItem(i);
699 | say(player, "Thanks! That's " + ChatColor.YELLOW + cost + ChatColor.WHITE + " total coins!");
700 | player.subtractPlayerBalance(player.player, cost);
701 | return;
702 | } else {
703 | say(player, "You don't have enough!!");
704 |
705 | return;
706 | }
707 |
708 | } else {
709 | // hmm, didnt get an item back
710 | say(player, "Sorry, looks like that item just sold!");
711 | return;
712 | }
713 | }
714 | }
715 |
716 | } else {
717 | say(player, "Sorry, out of stock in that item. Have you tried our " + ChatColor.LIGHT_PURPLE + "[list]" + ChatColor.WHITE + "?");
718 | return;
719 | }
720 |
721 | }
722 | }
723 | } else {
724 | say(player, "Sorry that's not enough.");
725 | }
726 | }
727 | }
728 |
729 | // Unknown command
730 | say(player, "Sorry, can i " + ChatColor.LIGHT_PURPLE + "[help]" + ChatColor.WHITE + " you?");
731 |
732 | return;
733 |
734 | }
735 |
736 | private ItemStack sellNolimitMerchantItem(int itemid, int amount) {
737 | // TODO Auto-generated method stub
738 | // find item
739 | if (merchant != null) {
740 | if (merchant.merchantentries != null) {
741 | // System.out.println("Found entries!");
742 | for (myMerchant_entry entry : merchant.merchantentries) {
743 | if (entry.itemid == itemid) {
744 | // System.out.println("Item matched!");
745 |
746 | ItemStack i = new ItemStack(itemid, 1);
747 | i.setAmount(amount);
748 | // Update cache
749 | entry.amount = entry.amount;
750 | // System.out.println("About to sell: " +
751 | // i.getType().name() + ":"+ entry.amount);
752 | return i;
753 |
754 | }
755 | }
756 | } else {
757 | // System.out.println("This merchant has no entries");
758 |
759 | }
760 |
761 | } else {
762 | // System.out.println("This isnt a mechant");
763 | }
764 |
765 | return null;
766 | }
767 |
768 | private ItemStack sellMerchantItem(int itemid, int amount) {
769 | // TODO Auto-generated method stub
770 | // find item
771 | if (merchant != null) {
772 | if (merchant.merchantentries != null) {
773 | // System.out.println("Found entries!");
774 | for (myMerchant_entry entry : merchant.merchantentries) {
775 | if (entry.itemid == itemid) {
776 | // System.out.println("Item matched!");
777 | if (merchant.category == null) {
778 | if (entry.amount >= amount) {
779 | ItemStack i = new ItemStack(itemid, 1);
780 | i.setAmount(amount);
781 | // Update cache
782 |
783 | entry.amount = entry.amount - amount;
784 | // System.out.println("About to sell: " +
785 | // i.getType().name() + ":"+ entry.amount);
786 | return i;
787 | } else {
788 | // System.out.println("Not enough ["+entry.amount+"] compared to your ["+amount+"]!");
789 | return null;
790 | }
791 | } else {
792 |
793 | if (!merchant.category.equals("nolimit")) {
794 | // TODO - NEEDS TO MOVE
795 | if (entry.amount >= amount) {
796 | ItemStack i = new ItemStack(itemid, 1);
797 | i.setAmount(amount);
798 | // Update cache
799 |
800 | entry.amount = entry.amount - amount;
801 | // System.out.println("About to sell: " +
802 | // i.getType().name() + ":"+ entry.amount);
803 | return i;
804 | } else {
805 | // System.out.println("Not enough ["+entry.amount+"] compared to your ["+amount+"]!");
806 | return null;
807 | }
808 | } else {
809 |
810 | // UNLIMITED
811 | ItemStack i = new ItemStack(itemid, 1);
812 | i.setAmount(amount);
813 | // Update cache
814 |
815 | // System.out.println("About to sell: " +
816 | // i.getType().name() + ":"+ amount);
817 | return i;
818 | }
819 | }
820 | }
821 | }
822 | } else {
823 | // System.out.println("This merchant has no entries");
824 |
825 | }
826 |
827 | } else {
828 | // System.out.println("This isnt a mechant");
829 | }
830 |
831 | return null;
832 | }
833 |
834 | private int getMerchantPriceBuyAt(int typeId) {
835 | // TODO Auto-generated method stub
836 | int amount = 0;
837 |
838 | if (merchant != null) {
839 | if (merchant.merchantentries != null) {
840 | for (myMerchant_entry entry : merchant.merchantentries) {
841 | if (entry.itemid == typeId) { return entry.pricebuy; }
842 | }
843 | }
844 | }
845 | return amount;
846 | }
847 |
848 | private int getMerchantPriceSellAt(int typeId) {
849 | // TODO Auto-generated method stub
850 | int amount = 0;
851 |
852 | if (merchant != null) {
853 | if (merchant.merchantentries != null) {
854 | for (myMerchant_entry entry : merchant.merchantentries) {
855 | if (entry.itemid == typeId) { return entry.pricesell; }
856 | }
857 | }
858 | }
859 | return amount;
860 | }
861 |
862 | private int getMerchantAmount(int itemid) {
863 | // TODO Auto-generated method stub
864 | int amount = 0;
865 |
866 | if (merchant != null) {
867 | if (merchant.merchantentries != null) {
868 | for (myMerchant_entry entry : merchant.merchantentries) {
869 | if (entry.itemid == itemid) {
870 | amount = +entry.amount;
871 | }
872 | }
873 | }
874 | }
875 | return amount;
876 | }
877 |
878 | @SuppressWarnings("static-access")
879 | private String variablise(String response, Player player) {
880 | // TODO Auto-generated method stub
881 |
882 | myPlayer mp = this.parent.universe.getmyPlayer(player);
883 |
884 | int balance = 0;
885 | if (mp != null) {
886 | balance = mp.getPlayerBalance(player);
887 | } else {
888 | System.out.println("npcx : Can't find " + player.getName() + " in the directory");
889 |
890 | }
891 |
892 | if (response.contains("[")) {
893 |
894 | // we have at least one bracket in this message, lets colour it!
895 |
896 | // grab all of them individually
897 |
898 | for (String command : response.split(" ")) {
899 | Pattern p = Pattern.compile("\\[\\w+\\]");
900 | Matcher m = p.matcher(command);
901 | if (m.matches()) {
902 | response = response.replaceAll(p.quote(command), ChatColor.LIGHT_PURPLE + command + ChatColor.WHITE);
903 | }
904 | }
905 | }
906 |
907 | if (response.contains("bankbalance")) {
908 | response = response.replaceAll("bankbalance", ChatColor.YELLOW + Integer.toString(balance) + ChatColor.WHITE);
909 | }
910 |
911 | if (response.contains("playerbalance")) {
912 | response = response.replaceAll("playerbalance", ChatColor.YELLOW + Integer.toString(balance) + ChatColor.WHITE);
913 | }
914 |
915 | if (response.contains("playerhealth")) {
916 | response = response.replaceAll("playerhealth", Integer.toString(player.getHealth()));
917 | }
918 |
919 | if (response.contains("playername")) {
920 | response = response.replaceAll("playername", player.getName());
921 | }
922 |
923 | return response;
924 | }
925 |
926 | public int checkHints(int id) {
927 | for (myHint hint : hints) {
928 | if (hint.id == id) {
929 | hint.age++;
930 | return hint.price;
931 |
932 | }
933 | }
934 | // return basic price
935 | return 1;
936 |
937 | }
938 |
939 | private void updateHints(int parseInt, int each) {
940 | // TODO Auto-generated method stub
941 |
942 | // is it old?
943 | int age = 0;
944 |
945 | for (myHint hint : this.hints) {
946 | if (hint.id == parseInt) {
947 | age = hint.age;
948 | hints.remove(hint);
949 | }
950 | }
951 |
952 | myHint h = new myHint();
953 | h.id = parseInt;
954 | h.price = each;
955 | h.age = 0;
956 | this.hints.add(h);
957 | }
958 |
959 | public BasicHumanNpc Spawn(String id2, String name2, World world, double x, double y, double z, Double yaw, Double pitch) {
960 | // TODO Auto-generated method stub
961 | BasicHumanNpc hnpc = NpcSpawner.SpawnBasicHumanNpc(this, id2, name2, world, x, y, z, yaw, pitch);
962 | this.npc = hnpc;
963 | this.npc.getBukkitEntity().setHealth(this.npc.hp);
964 |
965 | return hnpc;
966 | }
967 |
968 | public void Delete() {
969 | // TODO Auto-generated method stub
970 |
971 | }
972 |
973 | public void onRightClick(Player p) {
974 | // TODO Auto-generated method stub
975 | myPlayer player = this.parent.universe.getmyPlayer(p);
976 |
977 | if (player != null) {
978 | if (player.player == p) {
979 |
980 | double x1 = p.getLocation().getX();
981 | double y1 = p.getLocation().getY();
982 | double z1 = p.getLocation().getZ();
983 |
984 | double x2 = this.npc.getBukkitEntity().getLocation().getX();
985 | double y2 = this.npc.getBukkitEntity().getLocation().getY();
986 | double z2 = this.npc.getBukkitEntity().getLocation().getZ();
987 | int xdist = (int) (x1 - x2);
988 | int ydist = (int) (y1 - y2);
989 | int zdist = (int) (z1 - z2);
990 |
991 | if ((xdist < -3 || xdist > 2) || (ydist < -3 || ydist > 3) || (zdist < -3 || zdist > 3)) {
992 | // out of range to do this
993 |
994 | p.sendMessage("You are too far away from this npc");
995 | player.target = null;
996 | return;
997 | }
998 |
999 | if (player.target != null) {
1000 | p.sendMessage("* Target cleared!");
1001 | player.target = null;
1002 |
1003 | } else {
1004 | player.target = this.npc;
1005 |
1006 | int tNPCID = 0;
1007 | int tGPID = 0;
1008 | int tFID = 0;
1009 | int tPGID = 0;
1010 | int tLTID = 0;
1011 | int tMID = 0;
1012 | if (this.parent != null) {
1013 | tNPCID = Integer.parseInt(this.id);
1014 |
1015 | if (this.spawngroup != null) tGPID = this.spawngroup.id;
1016 | if (this.faction != null) tFID = this.faction.id;
1017 | if (this.pathgroup != null) tPGID = this.pathgroup.id;
1018 | if (this.loottable != null) tLTID = this.loottable.id;
1019 | if (this.merchant != null) tMID = this.merchant.id;
1020 |
1021 | }
1022 |
1023 | if (this.parent.isAdmin(p)) {
1024 | p.sendMessage("NPCID (" + tNPCID + "):SG (" + tGPID + "):F (" + tFID + "):PG (" + tPGID + "):L (" + tLTID + "):M (" + tMID + ")");
1025 | }
1026 | p.sendMessage("* You are now chatting to: " + ChatColor.YELLOW + name + ChatColor.WHITE + ". Right Click to cancel.");
1027 | p.sendMessage("* Words in " + ChatColor.LIGHT_PURPLE + "[brackets]" + ChatColor.WHITE + " you should type! " + ChatColor.YELLOW + "Type a word to begin" + ChatColor.WHITE);
1028 | if (player.target != null && player.target.parent != null && player.target.parent.category != null) {
1029 | // check what type (category) of npc this is
1030 |
1031 | if (player.target.parent.category.matches("merchant")) {
1032 | // merchant
1033 | onPlayerChat(player, "Hello!", "merchant");
1034 | } else {
1035 | // normal
1036 | onPlayerChat(player, "Hello!", "");
1037 | }
1038 |
1039 | } else {
1040 | onPlayerChat(player, "Hello!", "");
1041 | }
1042 |
1043 | }
1044 |
1045 | } else {
1046 | if (player.name.equals(p.getName())) {
1047 | this.parent.fixDead();
1048 |
1049 | // just drop the event
1050 | // p.sendMessage("Error, your player is out of sync");
1051 |
1052 | }
1053 |
1054 | }
1055 | } else {
1056 | // just drop the event
1057 | // p.sendMessage("Error, your player is out of sync");
1058 | this.parent.fixDead();
1059 | }
1060 | this.npc.forceMove(this.npc.getFaceLocationFromMe(p.getLocation()));
1061 |
1062 | }
1063 |
1064 | public void onClosestPlayer(Player p) {
1065 | // TODO Auto-generated method stub
1066 |
1067 | if (this.parent.universe.isLivingEntityAnNPC(p)) {
1068 | // ignroe other npcs
1069 | return;
1070 | }
1071 |
1072 | if (triggerwords != null) {
1073 | int count2 = 0;
1074 | for (myTriggerword tw : triggerwords.values()) {
1075 | // myplayer.player.sendMessage("Test:" + word + ":"+ tw.word);
1076 | if (tw.word.toLowerCase().contains("event_close")) {
1077 | String send = variablise(tw.response, p);
1078 |
1079 | for (myPlayer player : this.parent.universe.players.values()) {
1080 | if (p == player.player) {
1081 | onPlayerChat(player, "event_close", "");
1082 |
1083 | }
1084 | }
1085 |
1086 | count2++;
1087 |
1088 | }
1089 | }
1090 | if (count2 == 0) {
1091 | // If i dont have a triggerword, dont respond
1092 | // p.sendMessage(npc.getName() +
1093 | // " says to you, 'Watch your back.'");
1094 | }
1095 |
1096 | // face target
1097 | // this.npc.forceMove(this.npc.getFaceLocationFromMe(p.getLocation(),true));
1098 |
1099 | } else {
1100 | // Either a standard spawn or has no triggers!
1101 | }
1102 | }
1103 |
1104 | public void onBounce(Player p) {
1105 | // TODO Auto-generated method stub
1106 | // TODO Auto-generated method stub
1107 |
1108 | if (this.parent.universe.isLivingEntityAnNPC(p)) {
1109 | // ignroe other npcs
1110 | return;
1111 | }
1112 |
1113 | int count2 = 0;
1114 | for (myTriggerword tw : triggerwords.values()) {
1115 | // myplayer.player.sendMessage("Test:" + word + ":"+ tw.word);
1116 | if (tw.word.toLowerCase().contains("event_bounce")) {
1117 | String send = variablise(tw.response, p);
1118 |
1119 | for (myPlayer player : this.parent.universe.players.values()) {
1120 | if (p == player.player) {
1121 | onPlayerChat(player, "event_bounce", "");
1122 |
1123 | }
1124 | }
1125 |
1126 | count2++;
1127 |
1128 | }
1129 | }
1130 | if (count2 == 0) {
1131 | // If i dont have a triggerword, dont respond
1132 | p.sendMessage(npc.getName() + " says to you, 'Hey! Watch where you are going!'");
1133 | }
1134 |
1135 | this.npc.forceMove(this.npc.getFaceLocationFromMe(p.getLocation()));
1136 | }
1137 |
1138 | public void onDeathFromPlayer(LivingEntity p) {
1139 | // TODO Auto-generated method stub
1140 |
1141 | if (this.parent.universe.isLivingEntityAnNPC(p)) {
1142 | // Killed by an npc
1143 | return;
1144 | }
1145 |
1146 | // above is to
1147 | // make sure this is just for a HUMAN player
1148 | if (p instanceof Player) {
1149 | int count2 = 0;
1150 | for (myTriggerword tw : triggerwords.values()) {
1151 | // myplayer.player.sendMessage("Test:" + word + ":"+ tw.word);
1152 | if (tw.word.toLowerCase().contains("event_death")) {
1153 | String send = variablise(tw.response, (Player) p);
1154 |
1155 | for (myPlayer player : this.parent.universe.players.values()) {
1156 | if (p == player.player) {
1157 | say(player, send + "'");
1158 | }
1159 | }
1160 | count2++;
1161 | }
1162 | }
1163 | if (count2 == 0) {
1164 | // If i dont have a triggerword, respond with
1165 | ((Player) p).sendMessage(npc.getName() + " says to you, 'I will be avenged for this!'");
1166 | }
1167 |
1168 | ((Player) p).sendMessage("You have slain " + this.name + "!");
1169 |
1170 | if (this.faction != null) {
1171 | try {
1172 | myPlayer player = this.parent.universe.findmyPlayer(((Player) p));
1173 |
1174 | this.parent.universe.giveFactionHit(player, this.faction, this);
1175 |
1176 | } catch (NullPointerException e) {}
1177 | }
1178 |
1179 | }
1180 |
1181 | }
1182 |
1183 | public void onKilled(LivingEntity ent) {
1184 | // TODO Auto-generated method stub
1185 |
1186 | if (this.parent.universe.isLivingEntityAnNPC(ent)) {
1187 | // dont want to generate stuff for player npcs atm
1188 | return;
1189 | }
1190 |
1191 | // make sure above is returned since a chumannpc can be a player
1192 |
1193 | if (ent instanceof Player) {
1194 | int count2 = 0;
1195 | for (myTriggerword tw : triggerwords.values()) {
1196 | // myplayer.player.sendMessage("Test:" + word + ":"+ tw.word);
1197 | if (tw.word.toLowerCase().contains("event_killed")) {
1198 | String send = variablise(tw.response, (Player) ent);
1199 |
1200 | for (myPlayer player : this.parent.universe.players.values()) {
1201 | if (ent == player.player) {
1202 | say(player, send);
1203 | }
1204 | }
1205 | count2++;
1206 | }
1207 | }
1208 | if (count2 == 0) {
1209 | // If i dont have a triggerword, respond with
1210 | ((Player) ent).sendMessage(npc.getName() + " says to you, 'Not as strong as I thought'");
1211 | }
1212 |
1213 | }
1214 | }
1215 |
1216 | public BasicHumanNpc Spawn(String id, String name, Location loc) {
1217 | // TODO Auto-generated method stub
1218 | World world = loc.getWorld();
1219 | double x = loc.getX();
1220 | double y = loc.getY();
1221 | double z = loc.getZ();
1222 | double yaw = loc.getYaw();
1223 | double pitch = loc.getPitch();
1224 |
1225 | BasicHumanNpc hnpc = Spawn(id, name, world, x, y, z, yaw, pitch);
1226 | return hnpc;
1227 | }
1228 |
1229 | public int getDamageDone(BasicHumanNpc npc, Player player) {
1230 | // TODO Auto-generated method stub
1231 | // get weapon
1232 | int damage = 1;
1233 | if (player instanceof Player) {
1234 | int itemid = ((Player) player).getInventory().getItemInHand().getTypeId();
1235 |
1236 | // SWORDS!
1237 | if (itemid == 268) {
1238 | damage = damage + 5;
1239 | }
1240 |
1241 | if (itemid == 272) {
1242 | damage = damage + 8;
1243 | }
1244 |
1245 | if (itemid == 267) {
1246 | damage = damage + 12;
1247 | }
1248 |
1249 | if (itemid == 276) {
1250 | damage = damage + 20;
1251 | }
1252 |
1253 | if (itemid == 283) {
1254 | damage = damage + 30;
1255 | }
1256 |
1257 | Random rn = new Random();
1258 | int n = damage - (damage / 2) + 1;
1259 | int i = rn.nextInt() % n;
1260 | int randomNum = (damage / 2) + i;
1261 |
1262 | Random rn2 = new Random();
1263 | int n2 = 1000 - 1 + 1;
1264 | int i2 = rn.nextInt() % n;
1265 | int randomNum2 = 1 + i2;
1266 |
1267 | if (randomNum2 > 950) {
1268 | player.getServer().broadcastMessage(ChatColor.YELLOW + player.getName() + " did critical damage against " + npc.getName() + "! For " + (randomNum2 + randomNum) + "!");
1269 | return randomNum2 + randomNum;
1270 | }
1271 |
1272 | return randomNum;
1273 |
1274 | }
1275 | return damage;
1276 |
1277 | }
1278 |
1279 | public void onDeath() {
1280 | // TODO Auto-generated method stub
1281 |
1282 | }
1283 |
1284 | public void requipArmour() {
1285 | // TODO Auto-generated method stub
1286 | ItemStack iprimary = new ItemStack(weapon, 1);
1287 | ItemStack ihelmet = new ItemStack(helmet, 1);
1288 | ItemStack ichest = new ItemStack(chest, 1);
1289 | ItemStack ilegs = new ItemStack(legs, 1);
1290 | ItemStack iboots = new ItemStack(boots, 1);
1291 | npc.getBukkitEntity().getInventory().setItemInHand(iprimary);
1292 | npc.getBukkitEntity().getInventory().setHelmet(ihelmet);
1293 | npc.getBukkitEntity().getInventory().setChestplate(ichest);
1294 | npc.getBukkitEntity().getInventory().setLeggings(ilegs);
1295 | npc.getBukkitEntity().getInventory().setBoots(iboots);
1296 | }
1297 | }
1298 |
--------------------------------------------------------------------------------