Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.cadiducho.cservidoresMC; | ||
|
||
import com.cadiducho.cservidoresMC.cmd.UpdateCMD; | ||
import com.cadiducho.cservidoresMC.cmd.VoteCMD; | ||
import com.cadiducho.cservidoresMC.util.Inventario; | ||
import com.cadiducho.cservidoresMC.util.Metodos; | ||
import com.cadiducho.cservidoresMC.util.Version; | ||
import java.io.File; | ||
import java.util.logging.Level; | ||
import org.bukkit.plugin.PluginDescriptionFile; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
/** | ||
* | ||
* @author Cadiducho | ||
*/ | ||
|
||
public class Main extends JavaPlugin { | ||
|
||
private final Metodos met = new Metodos(this); | ||
private Version updater; | ||
private final Inventario inv = new Inventario(this); | ||
|
||
private final VoteCMD voteCMD = new VoteCMD(this); | ||
private final UpdateCMD updateCMD = new UpdateCMD(this); | ||
|
||
private final String tag = "&8[&b40ServidoresMC&8]"; | ||
|
||
@Override | ||
public void onEnable() { | ||
debugLog("Modo Debug activado en el plugin"); | ||
/* | ||
* Generar y cargar Config.yml | ||
*/ | ||
debugLog("Cargando configuración..."); | ||
File file = new File(getDataFolder() + File.separator + "config.yml"); | ||
if (!file.exists()) { | ||
try { | ||
getConfig().options().copyDefaults(true); | ||
saveConfig(); | ||
log("Generando archivo config.yml correctamente"); | ||
} catch (Exception e) { | ||
this.getLogger().info("Fallo al generar el config.yml!"); | ||
debugLog("Causa: "+e.toString()); | ||
} | ||
} | ||
/* | ||
* Comandos y eventos | ||
*/ | ||
PluginManager pluginManager = this.getServer().getPluginManager(); | ||
debugLog("Registrando comandos y eventos..."); | ||
|
||
this.getCommand("vote40").setExecutor(voteCMD); | ||
this.getCommand("update40").setExecutor(updateCMD); | ||
|
||
/* | ||
* Finalizar... | ||
*/ | ||
updater = new Version(this, this.getVersion()); | ||
debugLog("Checkeando nuevas versiones..."); | ||
String actualizacion = updater.checkearVersion(); | ||
if (actualizacion != null) { | ||
if (!actualizacion.equalsIgnoreCase("version actualizada")) { | ||
log(actualizacion); | ||
} | ||
} | ||
log("Plugin 40ServidoresMC v"+this.getVersion()+" cargado completamente"); | ||
} | ||
|
||
|
||
public boolean isDebug() { | ||
return this.getConfig().getBoolean("debug"); | ||
} | ||
|
||
public void debugLog(String s) { | ||
if (isDebug()){ | ||
getLogger().log(Level.INFO, "[Debug] {0}", s); | ||
} | ||
} | ||
|
||
public void log(String s) { | ||
getLogger().log(Level.INFO, s); | ||
} | ||
|
||
public Metodos getMetodos() { | ||
return this.met; | ||
} | ||
|
||
public String getVersion(){ | ||
PluginDescriptionFile f = this.getDescription(); | ||
return f.getVersion(); | ||
} | ||
|
||
public String getTag() { | ||
return this.tag; | ||
} | ||
|
||
public Version getUpdater() { | ||
return this.updater; | ||
} | ||
|
||
public Inventario getInv() { | ||
return this.inv; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.cadiducho.cservidoresMC.cmd; | ||
|
||
import com.cadiducho.cservidoresMC.Main; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
/** | ||
* | ||
* @author Cadiducho | ||
*/ | ||
|
||
public class UpdateCMD implements CommandExecutor { | ||
|
||
public static Main plugin; | ||
|
||
public UpdateCMD(Main instance) { | ||
plugin = instance; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
if (!sender.hasPermission("40servidores.actualizar")) { return true;} | ||
String act = plugin.getUpdater().checkearVersion(); | ||
if (act != null) { | ||
sender.sendMessage(plugin.getMetodos().colorizar(plugin.getTag()+"&a"+act)); | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.cadiducho.cservidoresMC.cmd; | ||
|
||
import com.cadiducho.cservidoresMC.Main; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* | ||
* @author Cadiducho | ||
*/ | ||
|
||
public class VoteCMD implements CommandExecutor { | ||
|
||
public static Main plugin; | ||
|
||
public VoteCMD(Main instance) { | ||
plugin = instance; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
if (sender.hasPermission("40servidores.voto")) { | ||
if (sender instanceof Player) { | ||
Player player = (Player)sender; | ||
switch (plugin.getMetodos().getVoto(player, plugin.getConfig().getString("clave"))) { | ||
case 0: | ||
String msg0 = plugin.getTag()+"&6No has votado hoy! Puedes hacerlo en &ahttp://www.40servidoresmc.es/"; | ||
sender.sendMessage(plugin.getMetodos().colorizar(msg0)); | ||
//No ha votado | ||
break; | ||
case 2: | ||
if (plugin.getConfig().getBoolean("broadcast.activado")) { | ||
String bc = plugin.getTag()+plugin.getConfig().getString("broadcast.mensajeBroadcast").replace("{0}", player.getDisplayName()); | ||
Bukkit.broadcastMessage(plugin.getMetodos().colorizar(bc)); | ||
} | ||
String msg1 = plugin.getTag()+plugin.getConfig().getString("mensaje"); | ||
sender.sendMessage(plugin.getMetodos().colorizar(msg1)); | ||
//Ha votado | ||
break; | ||
case 1: | ||
String msg2 = plugin.getTag()+"&aGracias por votar, pero ya has obtenido tu premio!"; | ||
sender.sendMessage(plugin.getMetodos().colorizar(msg2)); | ||
plugin.getInv().darPremio(player); //ToDO PREMIOS KIT | ||
break; | ||
default: | ||
String msg3 = plugin.getTag()+"&7Ha ocurrido un error. Prueba más tarde o avisa a un adminsitrador"; | ||
sender.sendMessage(plugin.getMetodos().colorizar(msg3)); | ||
//Fallo | ||
break; | ||
} | ||
|
||
} else { | ||
String msg = plugin.getTag()+"&cNo puedes usar este comando si no eres un jugador"; | ||
sender.sendMessage(plugin.getMetodos().colorizar(msg)); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.cadiducho.cservidoresMC.util; | ||
|
||
import com.cadiducho.cservidoresMC.Main; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
/** | ||
* | ||
* @author Cadiducho | ||
*/ | ||
public class Inventario { | ||
|
||
public static Main plugin; | ||
public Inventory[] premioInv = new Inventory[9999999]; | ||
|
||
public Inventario(Main instance) { | ||
plugin = instance; | ||
} | ||
|
||
public Inventory getKit(Player player) { | ||
premioInv[player.getEntityId()] = Bukkit.createInventory(player, 36); | ||
|
||
@SuppressWarnings("unchecked") | ||
List<String> kitlist = (List<String>) plugin.getConfig().getList("premio"); | ||
Iterator<String> iterator = kitlist.iterator(); | ||
while (iterator.hasNext()) { | ||
ItemStack is = Metodos.setItemStack(iterator.next()); | ||
premioInv[player.getEntityId()].addItem(is); | ||
} | ||
return premioInv[player.getEntityId()]; | ||
} | ||
|
||
public void darPremio(Player player) { | ||
player.getInventory().setContents(getKit(player).getContents()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.cadiducho.cservidoresMC.util; | ||
|
||
import com.cadiducho.cservidoresMC.Main; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Scanner; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
/** | ||
* | ||
* @author Cadiducho | ||
*/ | ||
public class Metodos { | ||
|
||
public static Main plugin; | ||
|
||
public Metodos(Main instance) { | ||
plugin = instance; | ||
} | ||
##public int getVoto(Player p, String clave); //Censurado a petición de la web oficial | ||
|
||
public static ItemStack setItemStack(String string) { | ||
ItemStack is; | ||
try { | ||
String values[] = string.split(","); | ||
if (values.length > 2) { | ||
if (values.length > 8) { | ||
is = new ItemStack(Integer.parseInt(values[0]), Integer.parseInt(values[1]), Short.parseShort(values[2])); | ||
is = addEnchantment(is, values[3], values[4]); | ||
is = addEnchantment(is, values[5], values[6]); | ||
is = addEnchantment(is, values[7], values[8]); | ||
} else if (values.length > 6) { | ||
is = new ItemStack(Integer.parseInt(values[0]), Integer.parseInt(values[1]), Short.parseShort(values[2])); | ||
is = addEnchantment(is, values[3], values[4]); | ||
is = addEnchantment(is, values[5], values[6]); | ||
} else if (values.length > 4) { | ||
is = new ItemStack(Integer.parseInt(values[0]), Integer.parseInt(values[1]), Short.parseShort(values[2])); | ||
is = addEnchantment(is, values[3], values[4]); | ||
} else { | ||
is = new ItemStack(Integer.parseInt(values[0]), Integer.parseInt(values[1]), Short.parseShort(values[2])); | ||
} | ||
} else { | ||
is = new ItemStack(Integer.parseInt(values[0]), Integer.parseInt(values[1])); | ||
} | ||
} catch (NumberFormatException e) { | ||
is = new ItemStack(0, 1); | ||
System.out.println("No se ha podido parsear un ItemStack! con.cadiducho.cservidoresMC.util.Metodos.setItemStack(String string)"); | ||
} | ||
return is; | ||
} | ||
|
||
public static ItemStack addEnchantment(ItemStack is, String name, String level) { | ||
switch (name.toLowerCase()) { | ||
case "power": | ||
is.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, Integer.parseInt(level)); break; | ||
case "flame": | ||
is.addUnsafeEnchantment(Enchantment.ARROW_FIRE, Integer.parseInt(level)); break; | ||
case "infinity": | ||
is.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, Integer.parseInt(level)); break; | ||
case "punch": | ||
is.addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, Integer.parseInt(level)); break; | ||
case "sharpness": | ||
is.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, Integer.parseInt(level)); break; | ||
case "arthropods": | ||
is.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, Integer.parseInt(level)); break; | ||
case "smite": | ||
is.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, Integer.parseInt(level)); break; | ||
case "efficiency": | ||
is.addUnsafeEnchantment(Enchantment.DIG_SPEED, Integer.parseInt(level)); break; | ||
case "unbreaking": | ||
is.addUnsafeEnchantment(Enchantment.DURABILITY, Integer.parseInt(level)); break; | ||
case "fireaspect": | ||
is.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, Integer.parseInt(level)); break; | ||
case "knockback": | ||
is.addUnsafeEnchantment(Enchantment.KNOCKBACK, Integer.parseInt(level)); break; | ||
case "fortune": | ||
is.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, Integer.parseInt(level)); break; | ||
case "looting": | ||
is.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, Integer.parseInt(level)); break; | ||
case "respiration": | ||
is.addUnsafeEnchantment(Enchantment.OXYGEN, Integer.parseInt(level)); break; | ||
case "protection": | ||
is.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, Integer.parseInt(level)); break; | ||
case "blastresistance": | ||
is.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, Integer.parseInt(level)); break; | ||
case "featherfalling": | ||
is.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, Integer.parseInt(level)); break; | ||
case "fireprotection": | ||
is.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, Integer.parseInt(level)); break; | ||
case "projectileprotection": | ||
is.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, Integer.parseInt(level)); break; | ||
case "silktouch": | ||
is.addUnsafeEnchantment(Enchantment.SILK_TOUCH, Integer.parseInt(level)); break; | ||
case "thorns": | ||
is.addUnsafeEnchantment(Enchantment.THORNS, Integer.parseInt(level)); break; | ||
case "aquaaffinity": | ||
is.addUnsafeEnchantment(Enchantment.WATER_WORKER, Integer.parseInt(level)); break; | ||
} | ||
return is; | ||
} | ||
|
||
public String colorizar(String s) { | ||
return s. | ||
replace("&0", ChatColor.BLACK + ""). | ||
replace("&1", ChatColor.DARK_BLUE + ""). | ||
replace("&2", ChatColor.DARK_GREEN + ""). | ||
replace("&3", ChatColor.DARK_AQUA + ""). | ||
replace("&4", ChatColor.DARK_RED + ""). | ||
replace("&5", ChatColor.DARK_PURPLE + ""). | ||
replace("&6", ChatColor.GOLD + ""). | ||
replace("&7", ChatColor.GRAY + ""). | ||
replace("&8", ChatColor.DARK_GRAY + ""). | ||
replace("&9", ChatColor.BLUE + ""). | ||
replace("&a", ChatColor.GREEN + ""). | ||
replace("&b", ChatColor.AQUA + ""). | ||
replace("&c", ChatColor.RED + ""). | ||
replace("&d", ChatColor.LIGHT_PURPLE + ""). | ||
replace("&e", ChatColor.YELLOW + ""). | ||
replace("&f", ChatColor.WHITE + ""). | ||
replace("&k", ChatColor.MAGIC + ""). | ||
replace("&l", ChatColor.BOLD + ""). | ||
replace("&m", ChatColor.STRIKETHROUGH + ""). | ||
replace("&n", ChatColor.UNDERLINE + ""). | ||
replace("&o", ChatColor.ITALIC + ""). | ||
replace("&r", ChatColor.RESET + ""); | ||
} | ||
|
||
} |
Oops, something went wrong.