Skip to content

Commit

Permalink
Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyanoure committed May 20, 2020
1 parent de5991a commit 94e35b4
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="C:/Users/kozel/Desktop/MC_DEV_1_12_2/spigot-1.12.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CyanAccelSprint</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
7 changes: 7 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prefix: "&8[&3CyanAccelSprint&8] "
sprint: # delay:speedlevel
1: 1
2: 2
3: 4
4: 8
5: 16
10 changes: 10 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: CyanAccelSprint
version: 1.0
author: Cyanoure
main: ga.cyanoure.cyanaccelsprint.Main
website: http://www.cyanoure.ga/
description: Gyorsulo Sprint Rendszer
commands:
casreload:
description: Config ujratoltese
permission: cyanaccelsprint.admin
145 changes: 145 additions & 0 deletions src/ga/cyanoure/cyanaccelsprint/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package ga.cyanoure.cyanaccelsprint;

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

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class Main extends JavaPlugin implements Listener, CommandExecutor{
public FileConfiguration config;

class SprintUser {
public Player Player;
public double SprintSince;
public int PotionStrength = 0;
}

List<SprintUser> SprintList;

private void pluginMessage(String msg) {
String prefix = this.config.getString("prefix");
getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&',prefix+msg));
}

private void LoadConfig() {
this.saveDefaultConfig();
//this.getConfig().addDefault("", "");
//this.getConfig().options().copyDefaults(true);
this.config = this.getConfig();
}

private void ReloadConfig() {
this.reloadConfig();
this.config = this.getConfig();
}

@Override
public void onEnable() {
LoadConfig();
SprintList = new ArrayList<SprintUser>();
getServer().getPluginManager().registerEvents(this, this);
this.getCommand("casreload").setExecutor(this);

pluginMessage("&2Plugin és konfigurációja betöltve.");

new UpdateChecker(this,79042).getLatestVersion(version -> {
pluginMessage("Jelenlegi verzió: "+this.getDescription().getVersion());
pluginMessage("Legújabb verzió a spigotmc.org-on: "+version);
pluginMessage("Link: https://www.spigotmc.org/resources/cyanaccelsprint.79042/");
});;
}

@Override
public void onDisable() {
pluginMessage("&2Plugin letiltva.");
}

@EventHandler
public void onSprint(PlayerToggleSprintEvent event) {
Player p = event.getPlayer();

// Az ellenõrzés fordítva mûködik, mert ha nem sprintelt, akkor sprintelni fog, ha sprintel, akkor nem fog.
if(!p.isSprinting()) {
SprintUser newItem = new SprintUser();
newItem.Player = p;
newItem.SprintSince = System.currentTimeMillis();
SprintList.add(newItem);
}else {
for(int i = 0; i < SprintList.size(); i++) {
if(SprintList.get(i).Player.getName() == p.getName()) {
SprintList.remove(i);
p.removePotionEffect(PotionEffectType.SPEED);
break;
}
}
}
}

@EventHandler
public void onQuit(PlayerQuitEvent e) {
Player p = e.getPlayer();
for(int i = 0; i < SprintList.size(); i++) {
if(SprintList.get(i).Player.getName() == p.getName()) {
SprintList.remove(i);
p.removePotionEffect(PotionEffectType.SPEED);
break;
}
}
}

@EventHandler
public void onMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
for(int i = 0; i < SprintList.size(); i++) {
if(SprintList.get(i).Player.getName() == p.getName()) {
double SprintSince = SprintList.get(i).SprintSince;
double TimeNow = System.currentTimeMillis();
int ElteltIdo = (int) ((TimeNow - SprintSince)/1000);
int speedLevel = 0;
Object[] SprintDurations = this.config.getConfigurationSection("sprint").getKeys(false).toArray();
for(int j = 0; j < SprintDurations.length; j++) {
int ido = Integer.parseInt(SprintDurations[j].toString());
if(ElteltIdo >= ido) {
speedLevel = this.config.getInt("sprint."+String.valueOf(ido));
}
}
if(speedLevel > 0 && SprintList.get(i).PotionStrength != speedLevel) {
p.removePotionEffect(PotionEffectType.SPEED);
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,speedLevel));
}
SprintList.get(i).PotionStrength = speedLevel;
break;
}
}
}

@EventHandler
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player)sender;
if(!p.hasPermission("cyanaccelsprint.admin")) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&',this.config.getString("prefix")+"&cEhhez nincs jogod!"));
return true;
}
}

this.reloadConfig();
this.config = this.getConfig();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',this.config.getString("prefix")+"&2Konfiguráció újratöltve."));

return true;
}
}
33 changes: 33 additions & 0 deletions src/ga/cyanoure/cyanaccelsprint/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ga.cyanoure.cyanaccelsprint;

import org.bukkit.Bukkit;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
import java.util.function.Consumer;

public class UpdateChecker {

private Main plugin;
private int resourceId;

public UpdateChecker(Main plugin, int resourceId) {
this.plugin = plugin;
this.resourceId = resourceId;
}

public void getLatestVersion(Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream();
Scanner scanner = new Scanner(inputStream)) {
if (scanner.hasNext()) {
consumer.accept(scanner.next());
}
} catch (IOException exception) {
plugin.getLogger().info("Update checker is broken, can't find an update!" + exception.getMessage());
}
});
}
}

0 comments on commit 94e35b4

Please sign in to comment.