Skip to content

Commit

Permalink
Version 1.3.6 (Language and PlayerOptions)
Browse files Browse the repository at this point in the history
  • Loading branch information
Draww committed Feb 11, 2018
1 parent 57565e3 commit fe8337a
Show file tree
Hide file tree
Showing 27 changed files with 913 additions and 353 deletions.
490 changes: 249 additions & 241 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.drawwdev</groupId>
<artifactId>Raffle</artifactId>
<version>1.3.5.1</version>
<version>1.3.6</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/drawwdev/raffle/CustomRaffle.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.drawwdev.raffle;

import com.drawwdev.raffle.utils.Config;
import com.drawwdev.raffle.utils.StringUtil;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CustomRaffle extends Raffle {
Expand All @@ -18,7 +13,7 @@ public class CustomRaffle extends Raffle {
private String name;

public CustomRaffle(String id) {
super(Main.getInstance().getConfigs().get("custom").getConfig().getInt("CustomRaffles." + id + ".time"), null, null, Main.getInstance().getConfigs().get("custom").getConfig().getString("CustomRaffles." + id + ".datatype", ""), RaffleType.CUSTOM);
super(Main.getInstance().getConfigs().get("custom").getConfig().getInt("CustomRaffles." + id + ".time"), null, null, Main.getInstance().getConfigs().get("custom").getConfig().getStringList("CustomRaffles." + id + ".disabledGroups"), Main.getInstance().getConfigs().get("custom").getConfig().getString("CustomRaffles." + id + ".datatype", ""), RaffleType.CUSTOM);
config = Main.getInstance().getConfigs().get("custom");
actions = config.getConfig().getStringList("CustomRaffles." + id + ".actions");
predicate = config.getConfig().getStringList("CustomRaffles." + id + ".predicate");
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/com/drawwdev/raffle/Language.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.drawwdev.raffle;

import com.drawwdev.raffle.utils.Config;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.regex.Pattern;

public class Language {

private Main plugin;
private Config config;

private YamlConfiguration defYaml;

public Language(Main plugin, Config config) {
this.plugin = plugin;
this.config = config;
try {
InputStreamReader defaultConfigStream = new InputStreamReader(plugin.getResource("language.yml"), "UTF8"); /* Get the config.yml from jar */
defYaml = new YamlConfiguration().loadConfiguration(defaultConfigStream);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

public void reload(){
config.load();
try {
InputStreamReader defaultConfigStream = new InputStreamReader(plugin.getResource("language.yml"), "UTF8"); /* Get the config.yml from jar */
defYaml = new YamlConfiguration().loadConfiguration(defaultConfigStream);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

public String tl(final String path, final Object... objects){
return format(path, objects);
}

private String translate(final String path) {
if (getConfig().getConfig().isString(path)){
return getConfig().getConfig().getString(path);
} else {
return defYaml.getString(path);
}
}

public String format(final String path, final Object... objects){
String format = translate(path);
format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]");
MessageFormat messageFormat = new MessageFormat(format);
return messageFormat.format(objects);
}


public Main getPlugin() {
return plugin;
}

public Config getConfig() {
return config;
}

public String getFormat(String l, Object... format){
String get = getConfig().getConfig().getString(l);
get = String.format(get, format);
return get;
}

public String get(String l){
return getConfig().getConfig().getString(l);
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/drawwdev/raffle/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.drawwdev.raffle.depend.PermissionsExDepend;
import com.drawwdev.raffle.nms.*;
import com.drawwdev.raffle.utils.Config;
import com.drawwdev.raffle.utils.Logger;
import com.drawwdev.raffle.utils.ScriptSystem;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -14,10 +13,10 @@ public class Main extends JavaPlugin {
public static Main instance;
private EconomyDepend economyDepend;
private PermissionsExDepend permissionsExDepend;
private Logger logger;
private Configs configs;
private CompatabilityManager compatabilityManager;
private ScriptSystem scriptSystem;
private Language language;

@Override
public void onEnable() {
Expand All @@ -30,11 +29,11 @@ public void onEnable() {
return;
}
scriptSystem = new ScriptSystem(this);
logger = new Logger(this);
instance = this;
saveDefaultConfig();
configs = new Configs(this);
loadConfigs();
language = new Language(this, getConfigs().get("language"));
economyDepend = new EconomyDepend(this, DependType.NORMAL);
permissionsExDepend = new PermissionsExDepend(this, DependType.NORMAL);
new RaffleCommand(this);
Expand All @@ -47,6 +46,7 @@ public void onDisable() {

public void loadConfigs(){
getConfigs().add("custom", new Config(this, "custom.yml", true));
getConfigs().add("language", new Config(this, "language.yml", true));
}

private CompatabilityManager setupCompatabilityNMS(String version) {
Expand Down Expand Up @@ -83,10 +83,6 @@ public PermissionsExDepend getPermissionsExDepend() {
return permissionsExDepend;
}

public Logger getLog() {
return logger;
}

public Configs getConfigs() {
return configs;
}
Expand All @@ -98,4 +94,8 @@ public CompatabilityManager getCompatabilityManager() {
public ScriptSystem getScriptSystem() {
return scriptSystem;
}

public Language getLanguage() {
return language;
}
}
14 changes: 13 additions & 1 deletion src/main/java/com/drawwdev/raffle/Raffle.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.drawwdev.raffle;

import java.util.List;

public class Raffle {

private Integer time;
private RaffleConsumer consumer;
private RafflePredicate predicate;
private List<String> disabledGroups;
private String datatype;
private RaffleType raffleType;

public Raffle(){

}

public Raffle(Integer time, RaffleConsumer consumer, RafflePredicate predicate, String datatype, RaffleType raffleType){
public Raffle(Integer time, RaffleConsumer consumer, RafflePredicate predicate, List<String> disabledGroups, String datatype, RaffleType raffleType){
this.time = time;
this.consumer = consumer;
this.predicate = predicate;
this.disabledGroups = disabledGroups;
this.datatype = datatype;
this.raffleType = raffleType;
}
Expand Down Expand Up @@ -59,4 +63,12 @@ public RaffleType getRaffleType() {
public void setRaffleType(RaffleType raffleType) {
this.raffleType = raffleType;
}

public List<String> getDisabledGroups() {
return disabledGroups;
}

public void setDisabledGroups(List<String> disabledGroups) {
this.disabledGroups = disabledGroups;
}
}
24 changes: 23 additions & 1 deletion src/main/java/com/drawwdev/raffle/RaffleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class RaffleBuilder {
private String raffleName = null;
private RaffleConsumer raffleConsumer = null;
private RafflePredicate rafflePredicate = null;
private List<String> disabledGroups;
private Integer time = null;
private String datatype = "";
private RaffleType raffleType;
Expand All @@ -23,6 +24,7 @@ public RaffleBuilder(RaffleStorage raffle, String raffleName){
this.raffle = raffle;
this.raffleName = raffleName;
this.raffleType = RaffleType.NORMAL;
this.disabledGroups = new ArrayList<>();
}

public RaffleBuilder setRaffleMain(RaffleStorage raffleMain){
Expand Down Expand Up @@ -60,6 +62,26 @@ public RaffleBuilder setType(RaffleType raffleType) {
return this;
}

public RaffleBuilder setDisabledGroups(List<String> list){
this.disabledGroups = list;
return this;
}

public RaffleBuilder deleteDisabledGroups(List<String> list){
this.disabledGroups.removeAll(list);
return this;
}

public RaffleBuilder addDisabledGroups(String string){
this.disabledGroups.add(string);
return this;
}

public RaffleBuilder removeDisabledGroups(String string){
this.disabledGroups.remove(string);
return this;
}

public RaffleBuilder addDepend(Depend depend) {
if (!depends.containsKey(depend.getClass())){
this.depends.put(depend.getClass(), depend);
Expand All @@ -83,7 +105,7 @@ public void build() throws RaffleException{
}
}
}
raffle.create(raffleName, raffleConsumer, rafflePredicate, time, datatype, raffleType);
raffle.create(raffleName, raffleConsumer, rafflePredicate, disabledGroups, time, datatype, raffleType);
} else {
throw new RaffleException("Missing data");
}
Expand Down
58 changes: 40 additions & 18 deletions src/main/java/com/drawwdev/raffle/RaffleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,82 @@ public RaffleCommand(Main plugin) {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7you can only do it from the game."));
sender.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("only-game-command")));
return true;
}
Player player = (Player) sender;
if (!player.hasPermission("raffle.*")){
sender.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7you are not authorized to perform this command."));
return true;
}
if (args.length < 1) {
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7Command was entered missing."));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("missing-command")));
return true;
}
if (args[0].equalsIgnoreCase("start")) {
if (!player.hasPermission("raffle.start")){
sender.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("not-authorized-command")));
return true;
}
if (args.length < 2){
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7Command was entered missing."));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("missing-command")));
return true;
}
String rType = args[1].toUpperCase();
Boolean typeExist = Arrays.stream(getRaffleManager().getRaffleStorage().getAllKey().toArray(new String[0])).anyMatch(p -> p.equals(args[1].toUpperCase()));
if (!typeExist){
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7No such raffle type."));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("no-such-raffletype")));
return true;
}
if (raffleManager.getStatus()){
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7There's a raffle going on!"));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("already-continue")));
return true;
}
Raffle raffle = getRaffleManager().getRaffleStorage().getOraffle().get(rType);
if (raffle == null){
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7This raffle is disabled!"));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("disabled-raffle")));
return true;
}
if (raffle.getConsumer() == null && raffle.getPredicate() == null){
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7This raffle is disabled!"));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("disabled-raffle")));
return true;
}
RaffleData raffleData = new RaffleData().set(Arrays.asList(args).subList(2, Arrays.asList(args).size()));
if (getRaffleManager().getRaffleStorage().getPredicate(rType).check(player, raffleData)){
try {
if (!plugin.getConfig().getStringList("disabledGroup").isEmpty()) {
getRaffleManager().start(player, rType, raffleData, plugin.getConfig().getStringList("disabledGroup").toArray(new String[0]));
if (!getRaffleManager().getRaffleStorage().getDisabledGroups(rType).isEmpty()) {
if (plugin.getPermissionsExDepend().dependent()){
getRaffleManager().start(player, rType, raffleData, getRaffleManager().getRaffleStorage().getDisabledGroups(rType).toArray(new String[0]));
} else {
player.sendMessage(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("permissionsex-not-depend"));
return true;
}
} else {
getRaffleManager().start(player, rType, raffleData);
}
} catch (RaffleException e) {
player.sendMessage(cc(plugin.getConfig().getString("prefix") + e.getMessage()));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + e.getMessage()));
return true;
}
} else {
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7You don't meet the conditions"));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("not-met-conditions")));
}
} else if (args[0].equalsIgnoreCase("stop")) {
if (!player.hasPermission("raffle.stop")){
sender.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("not-authorized-command")));
return true;
}
if (!raffleManager.getStatus()){
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " There's no Raffles right now!"));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("no-ongoing")));
return true;
}
try {
getRaffleManager().stop(player);
} catch (RaffleException e) {
player.sendMessage(cc(plugin.getConfig().getString("prefix") + e.getMessage()));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + e.getMessage()));
return true;
}
} else if (args[0].equalsIgnoreCase("types")) {
if (!player.hasPermission("raffle.types")){
sender.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("not-authorized-command")));
return true;
}
player.sendMessage(cc("&6o0=======&c[&eRaffle Types&c]&6========0o"));
String[] raffleTypes = getRaffleManager().getRaffleStorage().getAllKey().toArray(new String[0]);
for (String r : raffleTypes){
Expand All @@ -102,11 +115,20 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
}
} else if (args[0].equalsIgnoreCase("reload")){
if (!player.hasPermission("raffle.reload")){
sender.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("not-authorized-command")));
return true;
}
plugin.reloadConfig();
plugin.getLanguage().reload();
Main.getInstance().getConfigs().get("custom").load();
getRaffleManager().reload();
player.sendMessage(cc(plugin.getConfig().getString("prefix") + " &7All systems reloaded and restored!"));
player.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("reload")));
} else if (args[0].equalsIgnoreCase("help")) {
if (!player.hasPermission("raffle.help")){
sender.sendMessage(cc(plugin.getLanguage().tl("prefix") + plugin.getLanguage().tl("not-authorized-command")));
return true;
}
player.sendMessage(cc("&6o0=======&c[&eRaffle Help&c]&6========0o"));
player.sendMessage(cc("&b/" + label + " start <type> <data> &f- &e" + "Starting a raffle"));
player.sendMessage(cc("&b/" + label + " stop &f- &e" + "Stop the raffle"));
Expand Down
Loading

0 comments on commit fe8337a

Please sign in to comment.