mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-12-23 01:21:47 +00:00
Merged all versions of ShopChest to one jar file
This commit is contained in:
parent
06e1d20576
commit
5e54d4c356
17
src/de/epiceric/shopchest/interfaces/Hologram.java
Normal file
17
src/de/epiceric/shopchest/interfaces/Hologram.java
Normal file
@ -0,0 +1,17 @@
|
||||
package de.epiceric.shopchest.interfaces;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public interface Hologram {
|
||||
|
||||
public Location getLocation();
|
||||
public List<?> getEntities();
|
||||
public void showPlayer(OfflinePlayer p);
|
||||
public void hidePlayer(OfflinePlayer p);
|
||||
public boolean isVisible(OfflinePlayer p);
|
||||
|
||||
}
|
25
src/de/epiceric/shopchest/interfaces/JsonBuilder.java
Normal file
25
src/de/epiceric/shopchest/interfaces/JsonBuilder.java
Normal file
@ -0,0 +1,25 @@
|
||||
package de.epiceric.shopchest.interfaces;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface JsonBuilder {
|
||||
|
||||
public enum ClickAction {
|
||||
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL
|
||||
}
|
||||
|
||||
public enum HoverAction {
|
||||
SHOW_TEXT
|
||||
}
|
||||
|
||||
public JsonBuilder parse(String text);
|
||||
public JsonBuilder withText(String text);
|
||||
public JsonBuilder withColor(ChatColor color);
|
||||
public JsonBuilder withColor(String color);
|
||||
public JsonBuilder withClickEvent(ClickAction action, String value);
|
||||
public JsonBuilder withHoverEvent(HoverAction action, String value);
|
||||
public String toString();
|
||||
public void sendJson(Player p);
|
||||
|
||||
}
|
32
src/de/epiceric/shopchest/interfaces/Utils.java
Normal file
32
src/de/epiceric/shopchest/interfaces/Utils.java
Normal file
@ -0,0 +1,32 @@
|
||||
package de.epiceric.shopchest.interfaces;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class Utils {
|
||||
|
||||
public abstract void reload();
|
||||
|
||||
public abstract void removeShops();
|
||||
|
||||
public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) {
|
||||
ItemStack[] items = inventory.getContents();
|
||||
int amount = 0;
|
||||
for (ItemStack item : items) {
|
||||
if ((item != null) && (item.getType().equals(type)) && (item.getDurability() == damage) && (item.getAmount() > 0) && (item.getItemMeta().equals(itemMeta))) {
|
||||
amount += item.getAmount();
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static String getVersion(Server server) {
|
||||
String packageName = server.getClass().getPackage().getName();
|
||||
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package de.epiceric.shopchest.interfaces.hologram;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import net.minecraft.server.v1_8_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
public class Hologram_R1 implements Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_R1(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_R1(String text, Location location) {
|
||||
this.text = new String[] {text};
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, true);
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
public boolean isVisible(OfflinePlayer p) {
|
||||
if (visible.containsKey(p)) return visible.get(p); else return false;
|
||||
}
|
||||
|
||||
private void create() {
|
||||
for (String text : this.text) {
|
||||
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
|
||||
entity.setCustomName(text);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setInvisible(true);
|
||||
entity.setGravity(false);
|
||||
entitylist.add(entity);
|
||||
this.location.subtract(0, this.DISTANCE, 0);
|
||||
count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package de.epiceric.shopchest.interfaces.hologram;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import net.minecraft.server.v1_8_R2.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
public class Hologram_R2 implements Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_R2(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_R2(String text, Location location) {
|
||||
this.text = new String[] {text};
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, true);
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
public boolean isVisible(OfflinePlayer p) {
|
||||
if (visible.containsKey(p)) return visible.get(p); else return false;
|
||||
}
|
||||
|
||||
private void create() {
|
||||
for (String text : this.text) {
|
||||
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
|
||||
entity.setCustomName(text);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setInvisible(true);
|
||||
entity.setGravity(false);
|
||||
entitylist.add(entity);
|
||||
this.location.subtract(0, this.DISTANCE, 0);
|
||||
count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package de.epiceric.shopchest.interfaces.hologram;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
public class Hologram_R3 implements Hologram {
|
||||
|
||||
private List<EntityArmorStand> entitylist = new ArrayList<EntityArmorStand>();
|
||||
private String[] text;
|
||||
private Location location;
|
||||
private double DISTANCE = 0.25D;
|
||||
int count;
|
||||
|
||||
private HashMap<OfflinePlayer, Boolean> visible = new HashMap<OfflinePlayer, Boolean>();
|
||||
|
||||
public Hologram_R3(String[] text, Location location) {
|
||||
this.text = text;
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Hologram_R3(String text, Location location) {
|
||||
this.text = new String[] {text};
|
||||
this.location = location;
|
||||
create();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public List<EntityArmorStand> getEntities() {
|
||||
return entitylist;
|
||||
}
|
||||
|
||||
public void showPlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, true);
|
||||
}
|
||||
|
||||
public void hidePlayer(OfflinePlayer p) {
|
||||
for (Object o : entitylist) {
|
||||
EntityArmorStand armor = (EntityArmorStand) o;
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
visible.put(p, false);
|
||||
}
|
||||
|
||||
public boolean isVisible(OfflinePlayer p) {
|
||||
if (visible.containsKey(p)) return visible.get(p); else return false;
|
||||
}
|
||||
|
||||
private void create() {
|
||||
for (String text : this.text) {
|
||||
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
|
||||
entity.setCustomName(text);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setInvisible(true);
|
||||
entity.setGravity(false);
|
||||
entitylist.add(entity);
|
||||
this.location.subtract(0, this.DISTANCE, 0);
|
||||
count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
this.location.add(0, this.DISTANCE, 0);
|
||||
}
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package de.epiceric.shopchest.interfaces.jsonbuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_8_R1.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
|
||||
|
||||
|
||||
public class JsonBuilder_R1 implements JsonBuilder {
|
||||
|
||||
/* JsonBuilder by FisheyLP */
|
||||
|
||||
private List<String> extras = new ArrayList<String>();
|
||||
|
||||
|
||||
public JsonBuilder_R1(String... text) {
|
||||
for(String extra : text)
|
||||
parse(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 parse(String text) {
|
||||
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
|
||||
text = text.replaceAll(regex, "§$1");
|
||||
if(!Pattern.compile(regex).matcher(text).find()) {
|
||||
withText(text);
|
||||
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("§"+text.charAt(index - 1));
|
||||
} catch(Exception e){}
|
||||
index += word.length() + 2;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withText(String text) {
|
||||
extras.add("{text:\"" + text + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withColor(ChatColor color) {
|
||||
String c = color.name().toLowerCase();
|
||||
addSegment(color.isColor() ? "color:" + c : c + ":true");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withColor(String color) {
|
||||
while(color.length() != 1) color = color.substring(1).trim();
|
||||
withColor(ChatColor.getByChar(color));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R1 withClickEvent(ClickAction action, String value) {
|
||||
addSegment("clickEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package de.epiceric.shopchest.interfaces.jsonbuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
|
||||
|
||||
|
||||
public class JsonBuilder_R2 implements JsonBuilder {
|
||||
|
||||
/* JsonBuilder by FisheyLP */
|
||||
|
||||
private List<String> extras = new ArrayList<String>();
|
||||
|
||||
|
||||
public JsonBuilder_R2(String... text) {
|
||||
for(String extra : text)
|
||||
parse(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 parse(String text) {
|
||||
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
|
||||
text = text.replaceAll(regex, "§$1");
|
||||
if(!Pattern.compile(regex).matcher(text).find()) {
|
||||
withText(text);
|
||||
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("§"+text.charAt(index - 1));
|
||||
} catch(Exception e){}
|
||||
index += word.length() + 2;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withText(String text) {
|
||||
extras.add("{text:\"" + text + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withColor(ChatColor color) {
|
||||
String c = color.name().toLowerCase();
|
||||
addSegment(color.isColor() ? "color:" + c : c + ":true");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withColor(String color) {
|
||||
while(color.length() != 1) color = color.substring(1).trim();
|
||||
withColor(ChatColor.getByChar(color));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R2 withClickEvent(ClickAction action, String value) {
|
||||
addSegment("clickEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package de.epiceric.shopchest.interfaces.jsonbuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.epiceric.shopchest.interfaces.JsonBuilder;
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
|
||||
|
||||
public class JsonBuilder_R3 implements JsonBuilder {
|
||||
|
||||
/* JsonBuilder by FisheyLP */
|
||||
|
||||
private List<String> extras = new ArrayList<String>();
|
||||
|
||||
|
||||
public JsonBuilder_R3(String... text) {
|
||||
for(String extra : text)
|
||||
parse(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 parse(String text) {
|
||||
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}";
|
||||
text = text.replaceAll(regex, "§$1");
|
||||
if(!Pattern.compile(regex).matcher(text).find()) {
|
||||
withText(text);
|
||||
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("§"+text.charAt(index - 1));
|
||||
} catch(Exception e){}
|
||||
index += word.length() + 2;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withText(String text) {
|
||||
extras.add("{text:\"" + text + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withColor(ChatColor color) {
|
||||
String c = color.name().toLowerCase();
|
||||
addSegment(color.isColor() ? "color:" + c : c + ":true");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withColor(String color) {
|
||||
while(color.length() != 1) color = color.substring(1).trim();
|
||||
withColor(ChatColor.getByChar(color));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_R3 withClickEvent(ClickAction action, String value) {
|
||||
addSegment("clickEvent:{action:" + action.toString().toLowerCase()
|
||||
+ ",value:\"" + value + "\"}");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonBuilder_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())));
|
||||
|
||||
|
||||
}
|
||||
}
|
86
src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java
Normal file
86
src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java
Normal file
@ -0,0 +1,86 @@
|
||||
package de.epiceric.shopchest.interfaces.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_8_R1.EntityArmorStand;
|
||||
|
||||
public class Utils_R1 extends Utils {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
EntityArmorStand e = (EntityArmorStand) o;
|
||||
e.getWorld().removeEntity(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (String key : ShopChest.getInstance().shopChests.getKeys(false)) {
|
||||
|
||||
OfflinePlayer vendor = ShopChest.getInstance().shopChests.getOfflinePlayer(key + ".vendor");
|
||||
int locationX = ShopChest.getInstance().shopChests.getInt(key + ".location.x");
|
||||
int locationY = ShopChest.getInstance().shopChests.getInt(key + ".location.y");
|
||||
int locationZ = ShopChest.getInstance().shopChests.getInt(key + ".location.z");
|
||||
World locationWorld = ShopChest.getInstance().getServer().getWorld(ShopChest.getInstance().shopChests.getString(key + ".location.world"));
|
||||
Location location = new Location(locationWorld, locationX, locationY, locationZ);
|
||||
ItemStack product = ShopChest.getInstance().shopChests.getItemStack(key + ".product");
|
||||
double buyPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.buy");
|
||||
double sellPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.sell");
|
||||
boolean infinite = ShopChest.getInstance().shopChests.getBoolean(key + ".infinite");
|
||||
|
||||
ShopUtils.addShop(new Shop(ShopChest.getInstance(), vendor, product, location, buyPrice, sellPrice, infinite));
|
||||
|
||||
}
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShops() {
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
EntityArmorStand e = (EntityArmorStand) o;
|
||||
e.getWorld().removeEntity(e);
|
||||
}
|
||||
|
||||
|
||||
shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
88
src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java
Normal file
88
src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java
Normal file
@ -0,0 +1,88 @@
|
||||
package de.epiceric.shopchest.interfaces.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_8_R2.EntityArmorStand;
|
||||
|
||||
public class Utils_R2 extends Utils {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
EntityArmorStand e = (EntityArmorStand) o;
|
||||
e.getWorld().removeEntity(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (String key : ShopChest.getInstance().shopChests.getKeys(false)) {
|
||||
|
||||
OfflinePlayer vendor = ShopChest.getInstance().shopChests.getOfflinePlayer(key + ".vendor");
|
||||
int locationX = ShopChest.getInstance().shopChests.getInt(key + ".location.x");
|
||||
int locationY = ShopChest.getInstance().shopChests.getInt(key + ".location.y");
|
||||
int locationZ = ShopChest.getInstance().shopChests.getInt(key + ".location.z");
|
||||
World locationWorld = ShopChest.getInstance().getServer().getWorld(ShopChest.getInstance().shopChests.getString(key + ".location.world"));
|
||||
Location location = new Location(locationWorld, locationX, locationY, locationZ);
|
||||
ItemStack product = ShopChest.getInstance().shopChests.getItemStack(key + ".product");
|
||||
double buyPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.buy");
|
||||
double sellPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.sell");
|
||||
boolean infinite = ShopChest.getInstance().shopChests.getBoolean(key + ".infinite");
|
||||
|
||||
ShopUtils.addShop(new Shop(ShopChest.getInstance(), vendor, product, location, buyPrice, sellPrice, infinite));
|
||||
|
||||
}
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeShops() {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
EntityArmorStand e = (EntityArmorStand) o;
|
||||
e.getWorld().removeEntity(e);
|
||||
}
|
||||
|
||||
|
||||
shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
87
src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java
Normal file
87
src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java
Normal file
@ -0,0 +1,87 @@
|
||||
package de.epiceric.shopchest.interfaces.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.interfaces.Utils;
|
||||
import de.epiceric.shopchest.interfaces.Hologram;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.ShopUtils;
|
||||
import net.minecraft.server.v1_8_R3.EntityArmorStand;
|
||||
|
||||
public class Utils_R3 extends Utils {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
shop.getItem().remove();
|
||||
ShopUtils.removeShop(shop);
|
||||
|
||||
for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
EntityArmorStand e = (EntityArmorStand) o;
|
||||
e.getWorld().removeEntity(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (String key : ShopChest.getInstance().shopChests.getKeys(false)) {
|
||||
|
||||
OfflinePlayer vendor = ShopChest.getInstance().shopChests.getOfflinePlayer(key + ".vendor");
|
||||
int locationX = ShopChest.getInstance().shopChests.getInt(key + ".location.x");
|
||||
int locationY = ShopChest.getInstance().shopChests.getInt(key + ".location.y");
|
||||
int locationZ = ShopChest.getInstance().shopChests.getInt(key + ".location.z");
|
||||
World locationWorld = ShopChest.getInstance().getServer().getWorld(ShopChest.getInstance().shopChests.getString(key + ".location.world"));
|
||||
Location location = new Location(locationWorld, locationX, locationY, locationZ);
|
||||
ItemStack product = ShopChest.getInstance().shopChests.getItemStack(key + ".product");
|
||||
double buyPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.buy");
|
||||
double sellPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.sell");
|
||||
boolean infinite = ShopChest.getInstance().shopChests.getBoolean(key + ".infinite");
|
||||
|
||||
ShopUtils.addShop(new Shop(ShopChest.getInstance(), vendor, product, location, buyPrice, sellPrice, infinite));
|
||||
|
||||
}
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeShops() {
|
||||
for (Shop shop : ShopUtils.getShops()) {
|
||||
Hologram hologram = shop.getHologram();
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
hologram.hidePlayer(p);
|
||||
}
|
||||
|
||||
for (Object o : hologram.getEntities()) {
|
||||
EntityArmorStand e = (EntityArmorStand) o;
|
||||
e.getWorld().removeEntity(e);
|
||||
}
|
||||
|
||||
|
||||
shop.getItem().remove();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user