Converted ShopChest to Maven Project

This commit is contained in:
Eric 2016-07-03 20:59:29 +02:00
parent dae00a2013
commit 54a1b637c6
74 changed files with 781 additions and 823 deletions

11
.gitignore vendored
View File

@ -1,7 +1,16 @@
/bin/
/out/
/target/
/ShopChest/target/
/ShopChest NMS-Abstract/target/
/ShopChest NMS-v1_8_R1/target/
/ShopChest NMS-v1_8_R2/target/
/ShopChest NMS-v1_8_R3/target/
/ShopChest NMS-v1_9_R1/target/
/ShopChest NMS-v1_9_R2/target/
/ShopChest NMS-v1_10_R1/target/
/.idea/
/.settings/
.classpath
.project
ShopChest.iml
*.iml

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-Abstract</artifactId>
</project>

View File

@ -1,10 +1,9 @@
package de.epiceric.shopchest.interfaces;
package de.epiceric.shopchest.nms;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
public interface Hologram {
public interface IHologram {
/**
* @return Location of the hologram
@ -35,7 +34,7 @@ public interface Hologram {
/**
* Removes the hologram. <br>
* Hologram will be hidden from all players and will be killed
* IHologram will be hidden from all players and will be killed
*/
void remove();

View File

@ -1,39 +1,26 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
package de.epiceric.shopchest.nms;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import net.minecraft.server.v1_8_R1.ChatSerializer;
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
import com.google.common.collect.ImmutableMap;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public abstract class IJsonBuilder {
public class JsonBuilder_1_8_R1 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
public abstract void sendJson(Player p);
private List<String> extras = new ArrayList<String>();
private ShopChest plugin;
private List<String> extras = new ArrayList<>();
public JsonBuilder_1_8_R1(ShopChest plugin, String... text) {
this.plugin = plugin;
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R1 parse(String text) {
public IJsonBuilder parse(String text, String hoverText, String downloadLink) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, hoverText).withClickEvent(ClickAction.OPEN_URL, downloadLink);
return this;
}
String[] words = text.split(regex);
@ -42,43 +29,37 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder {
for (String word : words) {
try {
if (index != words[0].length())
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
} catch (Exception e) {
}
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, hoverText).withClickEvent(ClickAction.OPEN_URL, downloadLink);
} catch (Exception e) {}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R1 withText(String text) {
private IJsonBuilder withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R1 withColor(ChatColor color) {
private IJsonBuilder withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R1 withColor(String color) {
private IJsonBuilder withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R1 withClickEvent(ClickAction action, String value) {
private IJsonBuilder withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R1 withHoverEvent(HoverAction action, String value) {
private IJsonBuilder withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
@ -92,23 +73,22 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder {
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
private enum ClickAction {
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL
}
}
private enum HoverAction {
SHOW_TEXT
}
}

View File

@ -1,8 +1,8 @@
package de.epiceric.shopchest.interfaces;
package de.epiceric.shopchest.nms;
import org.bukkit.entity.EntityType;
public abstract class SpawnEggMeta {
public abstract class ISpawnEggMeta {
/**
* @return The NBT Tag <i>EntityTag.id</i> of the Spawn Egg

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-v1_10_R1</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,9 @@
package de.epiceric.shopchest.interfaces.hologram;
package de.epiceric.shopchest.nms.v1_10_R1;
import de.epiceric.shopchest.interfaces.Hologram;
import net.minecraft.server.v1_10_R1.*;
import de.epiceric.shopchest.nms.IHologram;
import net.minecraft.server.v1_10_R1.EntityArmorStand;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_10_R1.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
@ -10,7 +12,7 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.List;
public class Hologram_1_10_R1 implements Hologram {
public class Hologram implements IHologram {
private boolean exists = false;
private int count;
@ -19,7 +21,7 @@ public class Hologram_1_10_R1 implements Hologram {
private Location location;
private List<OfflinePlayer> visible = new ArrayList<>();
public Hologram_1_10_R1(String[] text, Location location) {
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();

View File

@ -0,0 +1,20 @@
package de.epiceric.shopchest.nms.v1_10_R1;
import de.epiceric.shopchest.nms.IJsonBuilder;
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class JsonBuilder extends IJsonBuilder {
public JsonBuilder(String text, String hoverText, String downloadLink) {
parse(text, hoverText, downloadLink);
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,16 +1,15 @@
package de.epiceric.shopchest.interfaces.spawneggmeta;
package de.epiceric.shopchest.nms.v1_10_R1;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class SpawnEggMeta_1_10_R1 extends SpawnEggMeta {
public class SpawnEggMeta extends ISpawnEggMeta {
private ItemStack stack;
public SpawnEggMeta_1_10_R1(ItemStack stack) {
public SpawnEggMeta(ItemStack stack) {
this.stack = stack;
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-v1_8_R1</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.interfaces.hologram;
package de.epiceric.shopchest.nms.v1_8_R1;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.nms.IHologram;
import net.minecraft.server.v1_8_R1.EntityArmorStand;
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
@ -12,7 +12,7 @@ import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.List;
public class Hologram_1_8_R1 implements Hologram {
public class Hologram implements IHologram {
private boolean exists = false;
private int count;
@ -21,7 +21,7 @@ public class Hologram_1_8_R1 implements Hologram {
private Location location;
private List<OfflinePlayer> visible = new ArrayList<>();
public Hologram_1_8_R1(String[] text, Location location) {
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();

View File

@ -0,0 +1,20 @@
package de.epiceric.shopchest.nms.v1_8_R1;
import de.epiceric.shopchest.nms.IJsonBuilder;
import net.minecraft.server.v1_8_R1.ChatSerializer;
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class JsonBuilder extends IJsonBuilder {
public JsonBuilder(String text, String hoverText, String downloadLink) {
parse(text, hoverText, downloadLink);
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,16 +1,15 @@
package de.epiceric.shopchest.interfaces.spawneggmeta;
package de.epiceric.shopchest.nms.v1_8_R1;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class SpawnEggMeta_1_8_R1 extends SpawnEggMeta {
public class SpawnEggMeta extends ISpawnEggMeta {
private ItemStack stack;
public SpawnEggMeta_1_8_R1(ItemStack stack) {
public SpawnEggMeta(ItemStack stack) {
this.stack = stack;
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-v1_8_R2</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.interfaces.hologram;
package de.epiceric.shopchest.nms.v1_8_R2;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.nms.IHologram;
import net.minecraft.server.v1_8_R2.EntityArmorStand;
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving;
@ -10,10 +10,9 @@ import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_8_R2 implements Hologram {
public class Hologram implements IHologram {
private boolean exists = false;
private int count;
@ -22,7 +21,7 @@ public class Hologram_1_8_R2 implements Hologram {
private Location location;
private List<OfflinePlayer> visible = new ArrayList<>();
public Hologram_1_8_R2(String[] text, Location location) {
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();

View File

@ -0,0 +1,20 @@
package de.epiceric.shopchest.nms.v1_8_R2;
import de.epiceric.shopchest.nms.IJsonBuilder;
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class JsonBuilder extends IJsonBuilder {
public JsonBuilder(String text, String hoverText, String downloadLink) {
parse(text, hoverText, downloadLink);
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,16 +1,15 @@
package de.epiceric.shopchest.interfaces.spawneggmeta;
package de.epiceric.shopchest.nms.v1_8_R2;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class SpawnEggMeta_1_8_R2 extends SpawnEggMeta {
public class SpawnEggMeta extends ISpawnEggMeta {
private ItemStack stack;
public SpawnEggMeta_1_8_R2(ItemStack stack) {
public SpawnEggMeta(ItemStack stack) {
this.stack = stack;
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-v1_8_R3</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.interfaces.hologram;
package de.epiceric.shopchest.nms.v1_8_R3;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.nms.IHologram;
import net.minecraft.server.v1_8_R3.EntityArmorStand;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
@ -10,10 +10,9 @@ import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_8_R3 implements Hologram {
public class Hologram implements IHologram {
private boolean exists = false;
private int count;
@ -22,7 +21,7 @@ public class Hologram_1_8_R3 implements Hologram {
private Location location;
private List<OfflinePlayer> visible = new ArrayList<>();
public Hologram_1_8_R3(String[] text, Location location) {
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();

View File

@ -0,0 +1,20 @@
package de.epiceric.shopchest.nms.v1_8_R3;
import de.epiceric.shopchest.nms.IJsonBuilder;
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class JsonBuilder extends IJsonBuilder {
public JsonBuilder(String text, String hoverText, String downloadLink) {
parse(text, hoverText, downloadLink);
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,16 +1,15 @@
package de.epiceric.shopchest.interfaces.spawneggmeta;
package de.epiceric.shopchest.nms.v1_8_R3;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class SpawnEggMeta_1_8_R3 extends SpawnEggMeta {
public class SpawnEggMeta extends ISpawnEggMeta {
private ItemStack stack;
public SpawnEggMeta_1_8_R3(ItemStack stack) {
public SpawnEggMeta(ItemStack stack) {
this.stack = stack;
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-v1_9_R1</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.9.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.interfaces.hologram;
package de.epiceric.shopchest.nms.v1_9_R1;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.nms.IHologram;
import net.minecraft.server.v1_9_R1.EntityArmorStand;
import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving;
@ -10,10 +10,9 @@ import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Hologram_1_9_R1 implements Hologram {
public class Hologram implements IHologram {
private boolean exists = false;
private int count;
@ -22,7 +21,7 @@ public class Hologram_1_9_R1 implements Hologram {
private Location location;
private List<OfflinePlayer> visible = new ArrayList<>();
public Hologram_1_9_R1(String[] text, Location location) {
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();

View File

@ -0,0 +1,20 @@
package de.epiceric.shopchest.nms.v1_9_R1;
import de.epiceric.shopchest.nms.IJsonBuilder;
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class JsonBuilder extends IJsonBuilder {
public JsonBuilder(String text, String hoverText, String downloadLink) {
parse(text, hoverText, downloadLink);
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,16 +1,15 @@
package de.epiceric.shopchest.interfaces.spawneggmeta;
package de.epiceric.shopchest.nms.v1_9_R1;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import net.minecraft.server.v1_9_R1.NBTTagCompound;
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class SpawnEggMeta_1_9_R1 extends SpawnEggMeta {
public class SpawnEggMeta extends ISpawnEggMeta {
private ItemStack stack;
public SpawnEggMeta_1_9_R1(ItemStack stack) {
public SpawnEggMeta(ItemStack stack) {
this.stack = stack;
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest_NMS-v1_9_R2</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.9.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.interfaces.hologram;
package de.epiceric.shopchest.nms.v1_9_R2;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.nms.IHologram;
import net.minecraft.server.v1_9_R2.EntityArmorStand;
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_9_R2.PacketPlayOutSpawnEntityLiving;
@ -12,7 +12,7 @@ import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import java.util.ArrayList;
import java.util.List;
public class Hologram_1_9_R2 implements Hologram {
public class Hologram implements IHologram {
private boolean exists = false;
private int count;
@ -21,7 +21,7 @@ public class Hologram_1_9_R2 implements Hologram {
private Location location;
private List<OfflinePlayer> visible = new ArrayList<>();
public Hologram_1_9_R2(String[] text, Location location) {
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();

View File

@ -0,0 +1,20 @@
package de.epiceric.shopchest.nms.v1_9_R2;
import de.epiceric.shopchest.nms.IJsonBuilder;
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class JsonBuilder extends IJsonBuilder {
public JsonBuilder(String text, String hoverText, String downloadLink) {
parse(text, hoverText, downloadLink);
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,16 +1,15 @@
package de.epiceric.shopchest.interfaces.spawneggmeta;
package de.epiceric.shopchest.nms.v1_9_R2;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import net.minecraft.server.v1_9_R2.NBTTagCompound;
import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class SpawnEggMeta_1_9_R2 extends SpawnEggMeta {
public class SpawnEggMeta extends ISpawnEggMeta {
private ItemStack stack;
public SpawnEggMeta_1_9_R2(ItemStack stack) {
public SpawnEggMeta(ItemStack stack) {
this.stack = stack;
}

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>json-simple</artifactId>
<groupId>com.googlecode.json-simple</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>ebean</artifactId>
<groupId>org.avaje</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>json-simple</artifactId>
<groupId>com.googlecode.json-simple</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>ebean</artifactId>
<groupId>org.avaje</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.yi.acru.bukkit</groupId>
<artifactId>lockette</artifactId>
<version>1.8.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.minebuilders</groupId>
<artifactId>clearlag</artifactId>
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.griefcraft.lwc</groupId>
<artifactId>lwc-entity-locking</artifactId>
<version>1.7.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

59
ShopChest/pom.xml Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ShopChest-Root</artifactId>
<groupId>de.epiceric</groupId>
<version>1.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ShopChest</artifactId>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-Abstract</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-v1_8_R1</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-v1_8_R2</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-v1_8_R3</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-v1_9_R1</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-v1_9_R2</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest_NMS-v1_10_R1</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
</project>

View File

@ -2,10 +2,9 @@ package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.nms.IJsonBuilder;
import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.utils.ClickType;
import de.epiceric.shopchest.utils.ClickType.EnumClickType;
@ -152,25 +151,25 @@ public class Commands extends BukkitCommand {
plugin.setDownloadLink(uc.getLink());
plugin.setUpdateNeeded(true);
JsonBuilder jb;
IJsonBuilder jb;
switch (Utils.getServerVersion()) {
case "v1_8_R1":
jb = new JsonBuilder_1_8_R1(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
jb = new de.epiceric.shopchest.nms.v1_8_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
break;
case "v1_8_R2":
jb = new JsonBuilder_1_8_R2(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
jb = new de.epiceric.shopchest.nms.v1_8_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
break;
case "v1_8_R3":
jb = new JsonBuilder_1_8_R3(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
jb = new de.epiceric.shopchest.nms.v1_8_R3.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
break;
case "v1_9_R1":
jb = new JsonBuilder_1_9_R1(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
jb = new de.epiceric.shopchest.nms.v1_9_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
break;
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
jb = new de.epiceric.shopchest.nms.v1_9_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
break;
case "v1_10_R1":
jb = new JsonBuilder_1_10_R1(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
jb = new de.epiceric.shopchest.nms.v1_10_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
break;
default:
return;

View File

@ -3,11 +3,10 @@ package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.LanguageConfiguration;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.listeners.*;
import de.epiceric.shopchest.nms.IJsonBuilder;
import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.sql.Database;
@ -274,25 +273,25 @@ public class ShopChest extends JavaPlugin {
for (Player p : getServer().getOnlinePlayers()) {
if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb;
IJsonBuilder jb;
switch (Utils.getServerVersion()) {
case "v1_8_R1":
jb = new JsonBuilder_1_8_R1(this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
jb = new de.epiceric.shopchest.nms.v1_8_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
break;
case "v1_8_R2":
jb = new JsonBuilder_1_8_R2(this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
jb = new de.epiceric.shopchest.nms.v1_8_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
break;
case "v1_8_R3":
jb = new JsonBuilder_1_8_R3(this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
jb = new de.epiceric.shopchest.nms.v1_8_R3.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
break;
case "v1_9_R1":
jb = new JsonBuilder_1_9_R1(this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
jb = new de.epiceric.shopchest.nms.v1_9_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
break;
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
jb = new de.epiceric.shopchest.nms.v1_9_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
break;
case "v1_10_R1":
jb = new JsonBuilder_1_10_R1(this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
jb = new de.epiceric.shopchest.nms.v1_10_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
break;
default:
return;

View File

@ -3,8 +3,7 @@ package de.epiceric.shopchest.language;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.LanguageConfiguration;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.interfaces.SpawnEggMeta;
import de.epiceric.shopchest.interfaces.spawneggmeta.*;
import de.epiceric.shopchest.nms.ISpawnEggMeta;
import de.epiceric.shopchest.utils.Utils;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
@ -960,26 +959,26 @@ public class LanguageUtils {
for (ItemName itemName : itemNames) {
if (itemName.getMaterial() == Material.MONSTER_EGG && material == Material.MONSTER_EGG) {
SpawnEggMeta spawnEggMeta;
ISpawnEggMeta spawnEggMeta;
switch (Utils.getServerVersion()) {
case "v1_8_R1":
spawnEggMeta = new SpawnEggMeta_1_8_R1(stack);
spawnEggMeta = new de.epiceric.shopchest.nms.v1_8_R1.SpawnEggMeta(stack);
break;
case "v1_8_R2":
spawnEggMeta = new SpawnEggMeta_1_8_R2(stack);
spawnEggMeta = new de.epiceric.shopchest.nms.v1_8_R2.SpawnEggMeta(stack);
break;
case "v1_8_R3":
spawnEggMeta = new SpawnEggMeta_1_8_R3(stack);
spawnEggMeta = new de.epiceric.shopchest.nms.v1_8_R3.SpawnEggMeta(stack);
break;
case "v1_9_R1":
spawnEggMeta = new SpawnEggMeta_1_9_R1(stack);
spawnEggMeta = new de.epiceric.shopchest.nms.v1_9_R1.SpawnEggMeta(stack);
break;
case "v1_9_R2":
spawnEggMeta = new SpawnEggMeta_1_9_R2(stack);
spawnEggMeta = new de.epiceric.shopchest.nms.v1_9_R2.SpawnEggMeta(stack);
break;
case "v1_10_R1":
spawnEggMeta = new SpawnEggMeta_1_10_R1(stack);
spawnEggMeta = new de.epiceric.shopchest.nms.v1_10_R1.SpawnEggMeta(stack);
break;
default:
return itemName.getLocalizedName();

View File

@ -0,0 +1,70 @@
package de.epiceric.shopchest.listeners;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.nms.IJsonBuilder;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class NotifyUpdateOnJoinListener implements Listener {
private ShopChest plugin;
private Permission perm;
public NotifyUpdateOnJoinListener(ShopChest plugin) {
this.plugin = plugin;
perm = plugin.getPermission();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (plugin.isUpdateNeeded()) {
if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
IJsonBuilder jb;
switch (Utils.getServerVersion()) {
case "v1_8_R1":
jb = new de.epiceric.shopchest.nms.v1_8_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
break;
case "v1_8_R2":
jb = new de.epiceric.shopchest.nms.v1_8_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
break;
case "v1_8_R3":
jb = new de.epiceric.shopchest.nms.v1_8_R3.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
break;
case "v1_9_R1":
jb = new de.epiceric.shopchest.nms.v1_9_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
break;
case "v1_9_R2":
jb = new de.epiceric.shopchest.nms.v1_9_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
break;
case "v1_10_R1":
jb = new de.epiceric.shopchest.nms.v1_10_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
break;
default:
return;
}
jb.sendJson(p);
}
}
if (perm.has(p, "shopchest.broadcast")) {
if (plugin.getBroadcast() != null) {
for (String message : plugin.getBroadcast()) {
p.sendMessage(message);
}
}
}
}
}

View File

@ -2,10 +2,9 @@ package de.epiceric.shopchest.shop;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.interfaces.Hologram;
import de.epiceric.shopchest.interfaces.hologram.*;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.nms.IHologram;
import de.epiceric.shopchest.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -31,7 +30,7 @@ public class Shop {
private OfflinePlayer vendor;
private ItemStack product;
private Location location;
private Hologram hologram;
private IHologram hologram;
private Item item;
private double buyPrice;
private double sellPrice;
@ -179,22 +178,22 @@ public class Shop {
switch (Utils.getServerVersion()) {
case "v1_8_R1":
hologram = new Hologram_1_8_R1(holoText, holoLocation);
hologram = new de.epiceric.shopchest.nms.v1_8_R1.Hologram(holoText, holoLocation);
break;
case "v1_8_R2":
hologram = new Hologram_1_8_R2(holoText, holoLocation);
hologram = new de.epiceric.shopchest.nms.v1_8_R2.Hologram(holoText, holoLocation);
break;
case "v1_8_R3":
hologram = new Hologram_1_8_R3(holoText, holoLocation);
hologram = new de.epiceric.shopchest.nms.v1_8_R3.Hologram(holoText, holoLocation);
break;
case "v1_9_R1":
hologram = new Hologram_1_9_R1(holoText, holoLocation);
hologram = new de.epiceric.shopchest.nms.v1_9_R1.Hologram(holoText, holoLocation);
break;
case "v1_9_R2":
hologram = new Hologram_1_9_R2(holoText, holoLocation);
hologram = new de.epiceric.shopchest.nms.v1_9_R2.Hologram(holoText, holoLocation);
break;
case "v1_10_R1":
hologram = new Hologram_1_10_R1(holoText, holoLocation);
hologram = new de.epiceric.shopchest.nms.v1_10_R1.Hologram(holoText, holoLocation);
break;
}
@ -250,9 +249,9 @@ public class Shop {
}
/**
* @return Hologram of the shop
* @return IHologram of the shop
*/
public Hologram getHologram() {
public IHologram getHologram() {
return hologram;
}

View File

@ -372,7 +372,7 @@ public class Metrics {
/**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
*
* @throws java.io.IOException
* @throws IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
@ -393,7 +393,7 @@ public class Metrics {
/**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
*
* @throws java.io.IOException
* @throws IOException
*/
public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task.
@ -677,7 +677,7 @@ public class Metrics {
/**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
*
* @return an unmodifiable {@link java.util.Set} of the plotter objects
* @return an unmodifiable {@link Set} of the plotter objects
*/
public Set<Plotter> getPlotters() {
return Collections.unmodifiableSet(plotters);

View File

@ -1,7 +1,7 @@
# Do not change anything in here unless you know what you're doing!
name: ShopChest
main: de.epiceric.shopchest.ShopChest
main: de.epiceric.ShopChest
version: 1.8.0
author: EpicEric
website: https://www.spigotmc.org/resources/shopchest.11431/

103
pom.xml Normal file
View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.epiceric</groupId>
<artifactId>ShopChest-Root</artifactId>
<packaging>pom</packaging>
<version>1.8.0</version>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<modules>
<module>ShopChest</module>
<module>ShopChest NMS-Abstract</module>
<module>ShopChest NMS-v1_8_R1</module>
<module>ShopChest NMS-v1_8_R2</module>
<module>ShopChest NMS-v1_8_R3</module>
<module>ShopChest NMS-v1_9_R1</module>
<module>ShopChest NMS-v1_9_R2</module>
<module>ShopChest NMS-v1_10_R1</module>
</modules>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>shopchest-repo</id>
<url>https://epicericee.github.io/ShopChest/maven/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.yi.acru.bukkit</groupId>
<artifactId>lockette</artifactId>
<version>1.8.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.minebuilders</groupId>
<artifactId>clearlag</artifactId>
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.griefcraft.lwc</groupId>
<artifactId>lwc-entity-locking</artifactId>
<version>1.7.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>.</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,32 +0,0 @@
package de.epiceric.shopchest.interfaces;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public interface JsonBuilder {
JsonBuilder parse(String text);
JsonBuilder withText(String text);
JsonBuilder withColor(ChatColor color);
JsonBuilder withColor(String color);
JsonBuilder withClickEvent(ClickAction action, String value);
JsonBuilder withHoverEvent(HoverAction action, String value);
String toString();
void sendJson(Player p);
enum ClickAction {
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL
}
enum HoverAction {
SHOW_TEXT
}
}

View File

@ -1,113 +0,0 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_10_R1 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
private ShopChest plugin;
public JsonBuilder_1_10_R1(ShopChest plugin, String... text) {
this.plugin = plugin;
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_10_R1 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
} catch (Exception e) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_10_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_10_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_10_R1 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_10_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_10_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,114 +0,0 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_8_R2 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
private ShopChest plugin;
public JsonBuilder_1_8_R2(ShopChest plugin, String... text) {
this.plugin = plugin;
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R2 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
} catch (Exception e) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R2 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R2 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R2 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R2 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R2 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,114 +0,0 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_8_R3 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
private ShopChest plugin;
public JsonBuilder_1_8_R3(ShopChest plugin, String... text) {
this.plugin = plugin;
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_8_R3 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
} catch (Exception e) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_8_R3 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R3 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_8_R3 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_8_R3 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_8_R3 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,114 +0,0 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_9_R1 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
private ShopChest plugin;
public JsonBuilder_1_9_R1(ShopChest plugin, String... text) {
this.plugin = plugin;
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_9_R1 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
} catch (Exception e) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_9_R1 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R1 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_9_R1 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_9_R1 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R1 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,114 +0,0 @@
package de.epiceric.shopchest.interfaces.jsonbuilder;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class JsonBuilder_1_9_R2 implements JsonBuilder {
/* JsonBuilder by FisheyLP */
private List<String> extras = new ArrayList<String>();
private ShopChest plugin;
public JsonBuilder_1_9_R2(ShopChest plugin, String... text) {
this.plugin = plugin;
for (String extra : text)
parse(extra);
}
@Override
public JsonBuilder_1_9_R2 parse(String text) {
String regex = "[&<26>]{1}([a-fA-Fl-oL-O0-9]){1}";
text = text.replaceAll(regex, "<EFBFBD>$1");
if (!Pattern.compile(regex).matcher(text).find()) {
withText(text).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length())
withText(word).withColor("<EFBFBD>" + text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD)).withClickEvent(ClickAction.OPEN_URL, plugin.getDownloadLink());
} catch (Exception e) {
}
index += word.length() + 2;
}
return this;
}
@Override
public JsonBuilder_1_9_R2 withText(String text) {
extras.add("{\"text\":\"" + text + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R2 withColor(ChatColor color) {
String c = color.name().toLowerCase();
addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true");
return this;
}
@Override
public JsonBuilder_1_9_R2 withColor(String color) {
while (color.length() != 1) color = color.substring(1).trim();
withColor(ChatColor.getByChar(color));
return this;
}
@Override
public JsonBuilder_1_9_R2 withClickEvent(ClickAction action, String value) {
addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
@Override
public JsonBuilder_1_9_R2 withHoverEvent(HoverAction action, String value) {
addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase()
+ "\",\"value\":\"" + value + "\"}");
return this;
}
private void addSegment(String segment) {
String lastText = extras.get(extras.size() - 1);
lastText = lastText.substring(0, lastText.length() - 1)
+ "," + segment + "}";
extras.remove(extras.size() - 1);
extras.add(lastText);
}
@Override
public String toString() {
if (extras.size() <= 1) return extras.size() == 0 ? "{\"text\":\"\"}" : extras.get(0);
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",\"extra\":[";
extras.remove(0);
;
for (String extra : extras)
text = text + extra + ",";
text = text.substring(0, text.length() - 1) + "]}";
return text;
}
@Override
public void sendJson(Player p) {
((CraftPlayer) p).getHandle().playerConnection.sendPacket(
new PacketPlayOutChat(ChatSerializer.a(toString())));
}
}

View File

@ -1,71 +0,0 @@
package de.epiceric.shopchest.listeners;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.interfaces.JsonBuilder;
import de.epiceric.shopchest.interfaces.jsonbuilder.*;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class NotifyUpdateOnJoinListener implements Listener {
private ShopChest plugin;
private Permission perm;
public NotifyUpdateOnJoinListener(ShopChest plugin) {
this.plugin = plugin;
perm = plugin.getPermission();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (plugin.isUpdateNeeded()) {
if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb;
switch (Utils.getServerVersion()) {
case "v1_8_R1":
jb = new JsonBuilder_1_8_R1(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())));
break;
case "v1_8_R2":
jb = new JsonBuilder_1_8_R2(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())));
break;
case "v1_8_R3":
jb = new JsonBuilder_1_8_R3(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())));
break;
case "v1_9_R1":
jb = new JsonBuilder_1_9_R1(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())));
break;
case "v1_9_R2":
jb = new JsonBuilder_1_9_R2(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())));
break;
case "v1_10_R1":
jb = new JsonBuilder_1_10_R1(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())));
break;
default:
return;
}
jb.sendJson(p);
}
}
if (perm.has(p, "shopchest.broadcast")) {
if (plugin.getBroadcast() != null) {
for (String message : plugin.getBroadcast()) {
p.sendMessage(message);
}
}
}
}
}