-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.0.3 $ Fixed OPC System Bug & Added SVC & Discord Webhook System
- Loading branch information
1 parent
a51f527
commit df05313
Showing
13 changed files
with
407 additions
and
9 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
24 changes: 24 additions & 0 deletions
24
Elecration-Server/src/main/java/eu/mixeration/Elecration/Elecration.java
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 |
---|---|---|
@@ -1,6 +1,30 @@ | ||
package eu.mixeration.Elecration; | ||
|
||
import com.google.common.collect.Sets; | ||
import dev.cobblesword.nachospigot.Nacho; | ||
import dev.cobblesword.nachospigot.hitdetection.LagCompensator; | ||
import dev.cobblesword.nachospigot.protocol.MovementListener; | ||
import dev.cobblesword.nachospigot.protocol.PacketListener; | ||
import eu.mixeration.Elecration.utils.WebhookUtils; | ||
import me.elier.nachospigot.config.NachoConfig; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import xyz.sculas.nacho.anticrash.AntiCrash; | ||
import xyz.sculas.nacho.async.AsyncExplosions; | ||
|
||
import java.util.Set; | ||
|
||
public class Elecration { | ||
|
||
public static final Logger LOGGER = LogManager.getLogger(Elecration.class); | ||
private static Elecration INSTANCE; | ||
|
||
public Elecration() { | ||
INSTANCE = this; | ||
} | ||
|
||
public static Elecration get() { | ||
return INSTANCE == null ? new Elecration() : INSTANCE; | ||
} | ||
|
||
} |
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
154 changes: 154 additions & 0 deletions
154
Elecration-Server/src/main/java/eu/mixeration/Elecration/commands/Management_SVC.java
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,154 @@ | ||
package eu.mixeration.Elecration.commands; | ||
|
||
import eu.mixeration.Elecration.Elecration; | ||
import eu.mixeration.Elecration.ElecrationConfig; | ||
import eu.mixeration.Elecration.utils.IntegerUtils; | ||
import eu.mixeration.Elecration.utils.StringUtils; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.World; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.craftbukkit.CraftServer; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.io.File; | ||
import java.text.Format; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import static eu.mixeration.Elecration.ElecrationConfig.getMessage; | ||
import static eu.mixeration.Elecration.utils.StringUtils.doColor; | ||
import static eu.mixeration.Elecration.utils.WorldUtils.copyWorld; | ||
import static org.bukkit.Bukkit.getServer; | ||
|
||
public class Management_SVC extends Command { | ||
public String right = doColor("&8&l»"); | ||
public String name = doColor("&9&lElecration"); | ||
|
||
public Management_SVC(String name) { | ||
super(name); | ||
this.description = "Server Control Command."; | ||
this.usageMessage = "/svc"; | ||
this.setPermission("elecration.management.server"); | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public boolean execute(CommandSender sender, String currentAlias, String[] args) { | ||
if (testPermission(sender)) { | ||
if (sender instanceof Player) { | ||
Player player = ((Player) sender).getPlayer(); | ||
if (player.isOp()) { | ||
if(args.length == 0 || args[0].equalsIgnoreCase("help")) { | ||
help(player); | ||
} else if (args.length == 2) { | ||
if(args[0].equalsIgnoreCase("reload")) { | ||
if(args[1].equalsIgnoreCase("motd")) { | ||
player.sendMessage(getMessage("server.motd-changed")); | ||
for(String motd : ElecrationConfig.config.getStringList("elecration.settings.motd")) { | ||
CraftServer.console.setMotd(doColor(motd.replace("<line>", "\n").replace("<online>", String.valueOf(getServer().getOnlinePlayers())))); | ||
} | ||
} else { | ||
help(player); | ||
} | ||
} else if (args[0].equalsIgnoreCase("pvp")) { | ||
if(args[1].equalsIgnoreCase("deny")) { | ||
CraftServer.console.setPVP(false); | ||
player.sendMessage(getMessage("server.pvp.deny")); | ||
} else if (args[1].equalsIgnoreCase("allow")) { | ||
CraftServer.console.setPVP(true); | ||
player.sendMessage(getMessage("server.pvp.allow")); | ||
} else { | ||
player.sendMessage(String.format(getMessage("server.unknow-value"), "deny/allow")); | ||
} | ||
} else if (args[0].equalsIgnoreCase("flight")) { | ||
if(args[1].equalsIgnoreCase("deny")) { | ||
CraftServer.console.setAllowFlight(false); | ||
player.sendMessage(getMessage("server.flight.deny")); | ||
} else if (args[1].equalsIgnoreCase("allow")) { | ||
CraftServer.console.setAllowFlight(true); | ||
player.sendMessage(getMessage("server.flight.allow")); | ||
} else { | ||
player.sendMessage(String.format(getMessage("server.unknow-value"), "deny/allow")); | ||
} | ||
} else if (args[0].equalsIgnoreCase("lmt-ambient")) { | ||
if (IntegerUtils.isInt(args[1])) { | ||
player.sendMessage(String.format(getMessage("server.spawn-limit-changed"), args[1], "TYPE-OF: Ambient", player.getWorld().getName())); | ||
Bukkit.getWorld(player.getWorld().getName()).setAmbientSpawnLimit(Integer.parseInt(args[1])); | ||
} else { | ||
player.sendMessage(getMessage("server.must-be-int")); | ||
} | ||
} else if (args[0].equalsIgnoreCase("lmt-monster")) { | ||
if (IntegerUtils.isInt(args[1])) { | ||
player.sendMessage(String.format(getMessage("server.spawn-limit-changed"), args[1], "TYPE-OF: Monster", player.getWorld().getName())); | ||
Bukkit.getWorld(player.getWorld().getName()).setMonsterSpawnLimit(Integer.parseInt(args[1])); | ||
} else { | ||
player.sendMessage(getMessage("server.must-be-int")); | ||
} | ||
} else if (args[0].equalsIgnoreCase("lmt-animal")) { | ||
if (IntegerUtils.isInt(args[1])) { | ||
player.sendMessage(String.format(getMessage("server.spawn-limit-changed"), args[1], "TYPE-OF: Animal", player.getWorld().getName())); | ||
Bukkit.getWorld(player.getWorld().getName()).setAnimalSpawnLimit(Integer.parseInt(args[1])); | ||
} else { | ||
player.sendMessage(getMessage("server.must-be-int")); | ||
} | ||
} else if (args[0].equalsIgnoreCase("lmt-wateranimal")) { | ||
if (IntegerUtils.isInt(args[1])) { | ||
player.sendMessage(String.format(getMessage("server.spawn-limit-changed"), args[1], "TYPE-OF: Water Animal", player.getWorld().getName())); | ||
Bukkit.getWorld(player.getWorld().getName()).setWaterAnimalSpawnLimit(Integer.parseInt(args[1])); | ||
} else { | ||
player.sendMessage(getMessage("server.must-be-int")); | ||
} | ||
} else if (args[0].equalsIgnoreCase("create-world-backup")) { | ||
World world = Bukkit.getWorld(args[1]); | ||
if (world == null) { | ||
player.sendMessage(getMessage("server.world-not-found")); | ||
} else { | ||
Format dayName = new SimpleDateFormat("EEEE"); | ||
String str = dayName.format(new Date()); | ||
String backupName = args[1] + " " + str + "$" + StringUtils.random(4); | ||
File worldFolder = Bukkit.getWorld(args[1]).getWorldFolder(); | ||
File folder = new File(getServer().getWorldContainer().getAbsolutePath(), File.separator + "backup-worlds" + File.separator + backupName); | ||
if (!folder.exists()) { | ||
try { | ||
folder.mkdir(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
copyWorld(worldFolder, folder); | ||
player.sendMessage(String.format(getMessage("server.backup-done"), world.getName())); | ||
player.sendMessage(String.format(getMessage("server.backup-name"), backupName)); | ||
} | ||
} else { | ||
help(player); | ||
} | ||
} else { | ||
help(player); | ||
} | ||
} else { | ||
player.sendMessage(getMessage("no-permission")); | ||
} | ||
} else { | ||
Elecration.LOGGER.warn("Hey ! I am sorry but you cannot use that command from console..."); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public void help(CommandSender sender) { | ||
if (sender instanceof Player) { | ||
Player player = ((Player) sender).getPlayer(); | ||
for (String help : ElecrationConfig.config.getStringList("elecration.messages.help.server")) { | ||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', help)); | ||
} | ||
} else { | ||
for (String help : ElecrationConfig.config.getStringList("elecration.messages.help.server")) { | ||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', help)); | ||
} | ||
} | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Elecration-Server/src/main/java/eu/mixeration/Elecration/utils/IntegerUtils.java
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,14 @@ | ||
package eu.mixeration.Elecration.utils; | ||
|
||
public class IntegerUtils { | ||
|
||
public static boolean isInt(String s) { | ||
try { | ||
Integer.parseInt(s); | ||
} catch (NumberFormatException nfe) { | ||
return false; | ||
} | ||
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
34 changes: 34 additions & 0 deletions
34
Elecration-Server/src/main/java/eu/mixeration/Elecration/utils/WebhookUtils.java
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,34 @@ | ||
package eu.mixeration.Elecration.utils; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
import java.io.OutputStream; | ||
import java.net.URL; | ||
|
||
public class WebhookUtils { | ||
|
||
public static void sendMessageToDiscord(String token, String title, String message) { | ||
String jsonBrut = ""; | ||
jsonBrut += "{\"embeds\": [{" | ||
+ "\"title\": \""+ title +"\"," | ||
+ "\"description\": \""+ message +"\"," | ||
+ "\"color\": 15258703" | ||
+ "}]}"; | ||
try { | ||
URL url = new URL(token); | ||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); | ||
con.addRequestProperty("Content-Type", "application/json"); | ||
con.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); | ||
con.setDoOutput(true); | ||
con.setRequestMethod("POST"); | ||
OutputStream stream = con.getOutputStream(); | ||
stream.write(jsonBrut.getBytes()); | ||
stream.flush(); | ||
stream.close(); | ||
con.getInputStream().close(); | ||
con.disconnect(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.